d_cfg_mgr_unittests.cc 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582
  1. // Copyright (C) 2013-2017 Internet Systems Consortium, Inc. ("ISC")
  2. //
  3. // This Source Code Form is subject to the terms of the Mozilla Public
  4. // License, v. 2.0. If a copy of the MPL was not distributed with this
  5. // file, You can obtain one at http://mozilla.org/MPL/2.0/.
  6. #include <config.h>
  7. #include <cc/command_interpreter.h>
  8. #include <config/module_spec.h>
  9. #include <exceptions/exceptions.h>
  10. #include <dhcpsrv/parsers/dhcp_parsers.h>
  11. #include <process/testutils/d_test_stubs.h>
  12. #include <process/d_cfg_mgr.h>
  13. #include <boost/foreach.hpp>
  14. #include <boost/date_time/posix_time/posix_time.hpp>
  15. #include <gtest/gtest.h>
  16. #include <sstream>
  17. using namespace std;
  18. using namespace isc;
  19. using namespace isc::config;
  20. using namespace isc::process;
  21. using namespace isc::data;
  22. using namespace boost::posix_time;
  23. namespace {
  24. /// @brief Test Class for verifying that configuration context cannot be null
  25. /// during construction.
  26. class DCtorTestCfgMgr : public DCfgMgrBase {
  27. public:
  28. /// @brief Constructor - Note that is passes in an empty configuration
  29. /// pointer to the base class constructor.
  30. DCtorTestCfgMgr() : DCfgMgrBase(DCfgContextBasePtr()) {
  31. }
  32. /// @brief Destructor
  33. virtual ~DCtorTestCfgMgr() {
  34. }
  35. /// @brief Dummy implementation as this method is abstract.
  36. virtual DCfgContextBasePtr createNewContext() {
  37. return (DCfgContextBasePtr());
  38. }
  39. /// @brief Returns summary of configuration in the textual format.
  40. virtual std::string getConfigSummary(const uint32_t) {
  41. return ("");
  42. }
  43. };
  44. /// @brief Test fixture class for testing DCfgMgrBase class.
  45. /// It maintains an member instance of DStubCfgMgr and derives from
  46. /// ConfigParseTest fixture, thus providing methods for converting JSON
  47. /// strings to configuration element sets, checking parse results,
  48. /// accessing the configuration context and trying to unparse.
  49. class DStubCfgMgrTest : public ConfigParseTest {
  50. public:
  51. /// @brief Constructor
  52. DStubCfgMgrTest():cfg_mgr_(new DStubCfgMgr) {
  53. }
  54. /// @brief Destructor
  55. ~DStubCfgMgrTest() {
  56. }
  57. /// @brief Convenience method which returns a DStubContextPtr to the
  58. /// configuration context.
  59. ///
  60. /// @return returns a DStubContextPtr.
  61. DStubContextPtr getStubContext() {
  62. return (boost::dynamic_pointer_cast<DStubContext>
  63. (cfg_mgr_->getContext()));
  64. }
  65. /// @brief Configuration manager instance.
  66. DStubCfgMgrPtr cfg_mgr_;
  67. };
  68. ///@brief Tests basic construction/destruction of configuration manager.
  69. /// Verifies that:
  70. /// 1. Proper construction succeeds.
  71. /// 2. Configuration context is initialized by construction.
  72. /// 3. Destruction works properly.
  73. /// 4. Construction with a null context is not allowed.
  74. TEST(DCfgMgrBase, construction) {
  75. DCfgMgrBasePtr cfg_mgr;
  76. // Verify that configuration manager constructions without error.
  77. ASSERT_NO_THROW(cfg_mgr.reset(new DStubCfgMgr()));
  78. // Verify that the context can be retrieved and is not null.
  79. DCfgContextBasePtr context = cfg_mgr->getContext();
  80. EXPECT_TRUE(context);
  81. // Verify that the manager can be destructed without error.
  82. EXPECT_NO_THROW(cfg_mgr.reset());
  83. // Verify that an attempt to construct a manger with a null context fails.
  84. ASSERT_THROW(DCtorTestCfgMgr(), DCfgMgrBaseError);
  85. }
  86. ///@brief Tests fundamental aspects of configuration parsing.
  87. /// Verifies that:
  88. /// 1. A correctly formed simple configuration parses without error.
  89. /// 2. An error building the element is handled.
  90. /// 3. An error committing the element is handled.
  91. /// 4. An unknown element error is handled.
  92. TEST_F(DStubCfgMgrTest, basicParseTest) {
  93. // Create a simple configuration.
  94. string config = "{ \"test-value\": [] } ";
  95. ASSERT_TRUE(fromJSON(config));
  96. // Verify that we can parse a simple configuration.
  97. answer_ = cfg_mgr_->parseConfig(config_set_, false);
  98. EXPECT_TRUE(checkAnswer(0));
  99. // Verify that we can check a simple configuration.
  100. answer_ = cfg_mgr_->parseConfig(config_set_, true);
  101. EXPECT_TRUE(checkAnswer(0));
  102. // Verify that an unknown element error is caught and returns a failed
  103. // parse result.
  104. SimFailure::set(SimFailure::ftElementUnknown);
  105. answer_ = cfg_mgr_->parseConfig(config_set_, false);
  106. EXPECT_TRUE(checkAnswer(1));
  107. // Verify that an error is caught too when the config is checked for.
  108. SimFailure::set(SimFailure::ftElementUnknown);
  109. answer_ = cfg_mgr_->parseConfig(config_set_, true);
  110. EXPECT_TRUE(checkAnswer(1));
  111. }
  112. ///@brief Tests ordered and non-ordered element parsing
  113. /// This test verifies that:
  114. /// 1. Non-ordered parsing parses elements in the order they are presented
  115. /// by the configuration set (as-they-come).
  116. /// 2. A parse order list with too few elements is detected.
  117. /// 3. Ordered parsing parses the elements in the order specified by the
  118. /// configuration manager's parse order list.
  119. /// 4. A parse order list with too many elements is detected.
  120. TEST_F(DStubCfgMgrTest, parseOrderTest) {
  121. // Element ids used for test.
  122. std::string charlie("charlie");
  123. std::string bravo("bravo");
  124. std::string alpha("alpha");
  125. std::string string_test("string_test");
  126. std::string uint32_test("uint32_test");
  127. std::string bool_test("bool_test");
  128. // Create the test configuration with the elements in "random" order.
  129. // NOTE that element sets produced by isc::data::Element::fromJSON(),
  130. // are in lexical order by element_id. This means that iterating over
  131. // such an element set, will present the elements in lexical order. Should
  132. // this change, this test will need to be modified accordingly.
  133. string config = "{"
  134. " \"string_test\": \"hoopla\", "
  135. " \"bravo\": [], "
  136. " \"uint32_test\": 55, "
  137. " \"alpha\": {}, "
  138. " \"charlie\": [], "
  139. " \"bool_test\": true "
  140. "} ";
  141. ASSERT_TRUE(fromJSON(config));
  142. // Verify that non-ordered parsing, results in an as-they-come parse order.
  143. // Create an expected parse order.
  144. // (NOTE that iterating over Element sets produced by fromJSON() will
  145. // present the elements in lexical order. Should this change, the expected
  146. // order list below would need to be changed accordingly).
  147. ElementIdList order_expected;
  148. // scalar params should be first and lexically
  149. order_expected.push_back(bool_test);
  150. order_expected.push_back(string_test);
  151. order_expected.push_back(uint32_test);
  152. // objects second and lexically
  153. order_expected.push_back(alpha);
  154. order_expected.push_back(bravo);
  155. order_expected.push_back(charlie);
  156. // Verify that the manager has an EMPTY parse order list. (Empty list
  157. // instructs the manager to parse them as-they-come.)
  158. EXPECT_EQ(0, cfg_mgr_->getParseOrder().size());
  159. // Parse the configuration, verify it parses without error.
  160. answer_ = cfg_mgr_->parseConfig(config_set_, false);
  161. EXPECT_TRUE(checkAnswer(0));
  162. // Verify that the parsed order matches what we expected.
  163. EXPECT_TRUE(cfg_mgr_->parsed_order_ == order_expected);
  164. // Clear the manager's parse order "memory".
  165. cfg_mgr_->parsed_order_.clear();
  166. // Create a parse order list that has too few entries. Verify that
  167. // when parsing the test config, it fails.
  168. cfg_mgr_->addToParseOrder(charlie);
  169. // Verify the parse order list is the size we expect.
  170. EXPECT_EQ(1, cfg_mgr_->getParseOrder().size());
  171. // Verify the configuration fails.
  172. answer_ = cfg_mgr_->parseConfig(config_set_, false);
  173. EXPECT_TRUE(checkAnswer(1));
  174. // Verify that the configuration parses correctly, when the parse order
  175. // is correct. Add the needed entries to the parse order
  176. cfg_mgr_->addToParseOrder(bravo);
  177. cfg_mgr_->addToParseOrder(alpha);
  178. // Verify the parse order list is the size we expect.
  179. EXPECT_EQ(3, cfg_mgr_->getParseOrder().size());
  180. // Clear the manager's parse order "memory".
  181. cfg_mgr_->parsed_order_.clear();
  182. // Verify the configuration parses without error.
  183. answer_ = cfg_mgr_->parseConfig(config_set_, false);
  184. EXPECT_TRUE(checkAnswer(0));
  185. // Build expected order
  186. // primitives should be first and lexically
  187. order_expected.clear();
  188. order_expected.push_back(bool_test);
  189. order_expected.push_back(string_test);
  190. order_expected.push_back(uint32_test);
  191. // objects second and by the parse order
  192. order_expected.push_back(charlie);
  193. order_expected.push_back(bravo);
  194. order_expected.push_back(alpha);
  195. // Verify that the parsed order is the order we configured.
  196. EXPECT_TRUE(cfg_mgr_->parsed_order_ == order_expected);
  197. // Create a parse order list that has too many entries. Verify that
  198. // when parsing the test config, it fails.
  199. cfg_mgr_->addToParseOrder("delta");
  200. // Verify the parse order list is the size we expect.
  201. EXPECT_EQ(4, cfg_mgr_->getParseOrder().size());
  202. // Verify the configuration fails.
  203. answer_ = cfg_mgr_->parseConfig(config_set_, false);
  204. EXPECT_TRUE(checkAnswer(1));
  205. }
  206. /// @brief Tests that element ids supported by the base class as well as those
  207. /// added by the derived class function properly.
  208. /// This test verifies that:
  209. /// 1. Boolean parameters can be parsed and retrieved.
  210. /// 2. Uint32 parameters can be parsed and retrieved.
  211. /// 3. String parameters can be parsed and retrieved.
  212. /// 4. Map elements can be parsed and retrieved.
  213. /// 5. List elements can be parsed and retrieved.
  214. /// 6. Parsing a second configuration, updates the existing context values
  215. /// correctly.
  216. TEST_F(DStubCfgMgrTest, simpleTypesTest) {
  217. // Create a configuration with all of the parameters.
  218. string config = "{ \"bool_test\": true , "
  219. " \"uint32_test\": 77 , "
  220. " \"string_test\": \"hmmm chewy\" , "
  221. " \"map_test\" : {} , "
  222. " \"list_test\": [] }";
  223. ASSERT_TRUE(fromJSON(config));
  224. // Verify that the configuration parses without error.
  225. answer_ = cfg_mgr_->parseConfig(config_set_, false);
  226. ASSERT_TRUE(checkAnswer(0));
  227. DStubContextPtr context = getStubContext();
  228. ASSERT_TRUE(context);
  229. // Verify that the boolean parameter was parsed correctly by retrieving
  230. // its value from the context.
  231. bool actual_bool = false;
  232. EXPECT_NO_THROW(context->getParam("bool_test", actual_bool));
  233. EXPECT_EQ(true, actual_bool);
  234. // Verify that the uint32 parameter was parsed correctly by retrieving
  235. // its value from the context.
  236. uint32_t actual_uint32 = 0;
  237. EXPECT_NO_THROW(context->getParam("uint32_test", actual_uint32));
  238. EXPECT_EQ(77, actual_uint32);
  239. // Verify that the string parameter was parsed correctly by retrieving
  240. // its value from the context.
  241. std::string actual_string = "";
  242. EXPECT_NO_THROW(context->getParam("string_test", actual_string));
  243. EXPECT_EQ("hmmm chewy", actual_string);
  244. isc::data::ConstElementPtr object;
  245. EXPECT_NO_THROW(context->getObjectParam("map_test", object));
  246. EXPECT_TRUE(object);
  247. EXPECT_NO_THROW(context->getObjectParam("list_test", object));
  248. EXPECT_TRUE(object);
  249. // Create a configuration which "updates" all of the parameter values.
  250. string config2 = "{ \"bool_test\": false , "
  251. " \"uint32_test\": 88 , "
  252. " \"string_test\": \"ewww yuk!\" , "
  253. " \"map_test2\" : {} , "
  254. " \"list_test2\": [] }";
  255. ASSERT_TRUE(fromJSON(config2));
  256. // Verify that the configuration parses without error.
  257. answer_ = cfg_mgr_->parseConfig(config_set_, false);
  258. EXPECT_TRUE(checkAnswer(0));
  259. context = getStubContext();
  260. ASSERT_TRUE(context);
  261. // Verify that the boolean parameter was updated correctly by retrieving
  262. // its value from the context.
  263. actual_bool = true;
  264. EXPECT_NO_THROW(context->getParam("bool_test", actual_bool));
  265. EXPECT_FALSE(actual_bool);
  266. // Verify that the uint32 parameter was updated correctly by retrieving
  267. // its value from the context.
  268. actual_uint32 = 0;
  269. EXPECT_NO_THROW(context->getParam("uint32_test", actual_uint32));
  270. EXPECT_EQ(88, actual_uint32);
  271. // Verify that the string parameter was updated correctly by retrieving
  272. // its value from the context.
  273. actual_string = "";
  274. EXPECT_NO_THROW(context->getParam("string_test", actual_string));
  275. EXPECT_EQ("ewww yuk!", actual_string);
  276. // Verify previous objects are not there.
  277. EXPECT_THROW(context->getObjectParam("map_test", object),
  278. isc::dhcp::DhcpConfigError);
  279. EXPECT_THROW(context->getObjectParam("list_test", object),
  280. isc::dhcp::DhcpConfigError);
  281. // Verify new map object is there.
  282. EXPECT_NO_THROW(context->getObjectParam("map_test2", object));
  283. EXPECT_TRUE(object);
  284. // Verify new list object is there.
  285. EXPECT_NO_THROW(context->getObjectParam("list_test2", object));
  286. EXPECT_TRUE(object);
  287. }
  288. /// @brief Tests that the configuration context is preserved after failure
  289. /// during parsing causes a rollback.
  290. /// 1. Verifies configuration context rollback.
  291. TEST_F(DStubCfgMgrTest, rollBackTest) {
  292. // Create a configuration with all of the parameters.
  293. string config = "{ \"bool_test\": true , "
  294. " \"uint32_test\": 77 , "
  295. " \"string_test\": \"hmmm chewy\" , "
  296. " \"map_test\" : {} , "
  297. " \"list_test\": [] }";
  298. ASSERT_TRUE(fromJSON(config));
  299. // Verify that the configuration parses without error.
  300. answer_ = cfg_mgr_->parseConfig(config_set_, false);
  301. EXPECT_TRUE(checkAnswer(0));
  302. DStubContextPtr context = getStubContext();
  303. ASSERT_TRUE(context);
  304. // Verify that all of parameters have the expected values.
  305. bool actual_bool = false;
  306. EXPECT_NO_THROW(context->getParam("bool_test", actual_bool));
  307. EXPECT_EQ(true, actual_bool);
  308. uint32_t actual_uint32 = 0;
  309. EXPECT_NO_THROW(context->getParam("uint32_test", actual_uint32));
  310. EXPECT_EQ(77, actual_uint32);
  311. std::string actual_string = "";
  312. EXPECT_NO_THROW(context->getParam("string_test", actual_string));
  313. EXPECT_EQ("hmmm chewy", actual_string);
  314. isc::data::ConstElementPtr object;
  315. EXPECT_NO_THROW(context->getObjectParam("map_test", object));
  316. EXPECT_TRUE(object);
  317. EXPECT_NO_THROW(context->getObjectParam("list_test", object));
  318. EXPECT_TRUE(object);
  319. // Create a configuration which "updates" all of the parameter values
  320. // plus one unknown at the end.
  321. string config2 = "{ \"bool_test\": false , "
  322. " \"uint32_test\": 88 , "
  323. " \"string_test\": \"ewww yuk!\" , "
  324. " \"map_test2\" : {} , "
  325. " \"list_test2\": [] , "
  326. " \"zeta_unknown\": 33 } ";
  327. ASSERT_TRUE(fromJSON(config2));
  328. // Force a failure on the last element
  329. SimFailure::set(SimFailure::ftElementUnknown);
  330. answer_ = cfg_mgr_->parseConfig(config_set_, false);
  331. EXPECT_TRUE(checkAnswer(1));
  332. context = getStubContext();
  333. ASSERT_TRUE(context);
  334. // Verify that all of parameters have the original values.
  335. actual_bool = false;
  336. EXPECT_NO_THROW(context->getParam("bool_test", actual_bool));
  337. EXPECT_EQ(true, actual_bool);
  338. actual_uint32 = 0;
  339. EXPECT_NO_THROW(context->getParam("uint32_test", actual_uint32));
  340. EXPECT_EQ(77, actual_uint32);
  341. actual_string = "";
  342. EXPECT_NO_THROW(context->getParam("string_test", actual_string));
  343. EXPECT_EQ("hmmm chewy", actual_string);
  344. EXPECT_NO_THROW(context->getObjectParam("map_test", object));
  345. EXPECT_TRUE(object);
  346. EXPECT_NO_THROW(context->getObjectParam("list_test", object));
  347. EXPECT_TRUE(object);
  348. }
  349. /// @brief Tests that the configuration context is preserved during
  350. /// check only parsing.
  351. TEST_F(DStubCfgMgrTest, checkOnly) {
  352. // Create a configuration with all of the parameters.
  353. string config = "{ \"bool_test\": true , "
  354. " \"uint32_test\": 77 , "
  355. " \"string_test\": \"hmmm chewy\" , "
  356. " \"map_test\" : {} , "
  357. " \"list_test\": [] }";
  358. ASSERT_TRUE(fromJSON(config));
  359. // Verify that the configuration parses without error.
  360. answer_ = cfg_mgr_->parseConfig(config_set_, false);
  361. EXPECT_TRUE(checkAnswer(0));
  362. DStubContextPtr context = getStubContext();
  363. ASSERT_TRUE(context);
  364. // Verify that all of parameters have the expected values.
  365. bool actual_bool = false;
  366. EXPECT_NO_THROW(context->getParam("bool_test", actual_bool));
  367. EXPECT_EQ(true, actual_bool);
  368. uint32_t actual_uint32 = 0;
  369. EXPECT_NO_THROW(context->getParam("uint32_test", actual_uint32));
  370. EXPECT_EQ(77, actual_uint32);
  371. std::string actual_string = "";
  372. EXPECT_NO_THROW(context->getParam("string_test", actual_string));
  373. EXPECT_EQ("hmmm chewy", actual_string);
  374. isc::data::ConstElementPtr object;
  375. EXPECT_NO_THROW(context->getObjectParam("map_test", object));
  376. EXPECT_TRUE(object);
  377. EXPECT_NO_THROW(context->getObjectParam("list_test", object));
  378. EXPECT_TRUE(object);
  379. // Create a configuration which "updates" all of the parameter values.
  380. string config2 = "{ \"bool_test\": false , "
  381. " \"uint32_test\": 88 , "
  382. " \"string_test\": \"ewww yuk!\" , "
  383. " \"map_test2\" : {} , "
  384. " \"list_test2\": [] }";
  385. ASSERT_TRUE(fromJSON(config2));
  386. answer_ = cfg_mgr_->parseConfig(config_set_, true);
  387. EXPECT_TRUE(checkAnswer(0));
  388. context = getStubContext();
  389. ASSERT_TRUE(context);
  390. // Verify that all of parameters have the original values.
  391. actual_bool = false;
  392. EXPECT_NO_THROW(context->getParam("bool_test", actual_bool));
  393. EXPECT_EQ(true, actual_bool);
  394. actual_uint32 = 0;
  395. EXPECT_NO_THROW(context->getParam("uint32_test", actual_uint32));
  396. EXPECT_EQ(77, actual_uint32);
  397. actual_string = "";
  398. EXPECT_NO_THROW(context->getParam("string_test", actual_string));
  399. EXPECT_EQ("hmmm chewy", actual_string);
  400. EXPECT_NO_THROW(context->getObjectParam("map_test", object));
  401. EXPECT_TRUE(object);
  402. EXPECT_NO_THROW(context->getObjectParam("list_test", object));
  403. EXPECT_TRUE(object);
  404. }
  405. // Tests that configuration element position is returned by getParam variants.
  406. TEST_F(DStubCfgMgrTest, paramPosition) {
  407. // Create a configuration with one of each scalar types. We end them
  408. // with line feeds so we can test position value.
  409. string config = "{ \"bool_test\": true , \n"
  410. " \"uint32_test\": 77 , \n"
  411. " \"string_test\": \"hmmm chewy\" }";
  412. ASSERT_TRUE(fromJSON(config));
  413. // Verify that the configuration parses without error.
  414. answer_ = cfg_mgr_->parseConfig(config_set_, false);
  415. ASSERT_TRUE(checkAnswer(0));
  416. DStubContextPtr context = getStubContext();
  417. ASSERT_TRUE(context);
  418. // Verify that the boolean parameter was parsed correctly by retrieving
  419. // its value from the context.
  420. bool actual_bool = false;
  421. isc::data::Element::Position pos;
  422. EXPECT_NO_THROW(pos = context->getParam("bool_test", actual_bool));
  423. EXPECT_EQ(true, actual_bool);
  424. EXPECT_EQ(1, pos.line_);
  425. // Verify that the uint32 parameter was parsed correctly by retrieving
  426. // its value from the context.
  427. uint32_t actual_uint32 = 0;
  428. EXPECT_NO_THROW(pos = context->getParam("uint32_test", actual_uint32));
  429. EXPECT_EQ(77, actual_uint32);
  430. EXPECT_EQ(2, pos.line_);
  431. // Verify that the string parameter was parsed correctly by retrieving
  432. // its value from the context.
  433. std::string actual_string = "";
  434. EXPECT_NO_THROW(pos = context->getParam("string_test", actual_string));
  435. EXPECT_EQ("hmmm chewy", actual_string);
  436. EXPECT_EQ(3, pos.line_);
  437. // Verify that an optional parameter that is not defined, returns the
  438. // zero position.
  439. pos = isc::data::Element::ZERO_POSITION();
  440. EXPECT_NO_THROW(pos = context->getParam("bogus_value",
  441. actual_string, true));
  442. EXPECT_EQ(pos.file_, isc::data::Element::ZERO_POSITION().file_);
  443. }
  444. // This tests if some aspects of simpleParseConfig are behaving properly.
  445. // Thorough testing is only possible for specific implementations. This
  446. // is done for control agent (see CtrlAgentControllerTest tests in
  447. // src/bin/agent/tests/ctrl_agent_controller_unittest.cc for example).
  448. // Also, shell tests in src/bin/agent/ctrl_agent_process_tests.sh test
  449. // the whole CA process that uses simpleParseConfig. The alternative
  450. // would be to implement whole parser that would set the context
  451. // properly. The ROI for this is not worth the effort.
  452. TEST_F(DStubCfgMgrTest, simpleParseConfig) {
  453. using namespace isc::data;
  454. // Passing just null pointer should result in error return code
  455. answer_ = cfg_mgr_->simpleParseConfig(ConstElementPtr(), false);
  456. EXPECT_TRUE(checkAnswer(1));
  457. // Ok, now try with a dummy, but valid json code
  458. string config = "{ \"bool_test\": true , \n"
  459. " \"uint32_test\": 77 , \n"
  460. " \"string_test\": \"hmmm chewy\" }";
  461. ASSERT_NO_THROW(fromJSON(config));
  462. answer_ = cfg_mgr_->simpleParseConfig(config_set_, false);
  463. EXPECT_TRUE(checkAnswer(0));
  464. }
  465. // This test checks that the post configuration callback function is
  466. // executed by the simpleParseConfig function.
  467. TEST_F(DStubCfgMgrTest, simpleParseConfigWithCallback) {
  468. string config = "{ \"bool_test\": true , \n"
  469. " \"uint32_test\": 77 , \n"
  470. " \"string_test\": \"hmmm chewy\" }";
  471. ASSERT_NO_THROW(fromJSON(config));
  472. answer_ = cfg_mgr_->simpleParseConfig(config_set_, false,
  473. [this]() {
  474. isc_throw(Unexpected, "unexpected configuration error");
  475. });
  476. EXPECT_TRUE(checkAnswer(1));
  477. }
  478. } // end of anonymous namespace