ccsession_unittests.cc 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435
  1. // Copyright (C) 2009 Internet Systems Consortium, Inc. ("ISC")
  2. //
  3. // Permission to use, copy, modify, and/or distribute this software for any
  4. // purpose with or without fee is hereby granted, provided that the above
  5. // copyright notice and this permission notice appear in all copies.
  6. //
  7. // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
  8. // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  9. // AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
  10. // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  11. // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  12. // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  13. // PERFORMANCE OF THIS SOFTWARE.
  14. #include <config.h>
  15. #include <gtest/gtest.h>
  16. #include <config/tests/fake_session.h>
  17. #include <config/ccsession.h>
  18. #include <fstream>
  19. #include <config/tests/data_def_unittests_config.h>
  20. using namespace isc::data;
  21. using namespace isc::config;
  22. using namespace isc::cc;
  23. using namespace std;
  24. namespace {
  25. std::string
  26. ccspecfile(const std::string& name) {
  27. return (std::string(TEST_DATA_PATH) + "/" + name);
  28. }
  29. ElementPtr
  30. el(const std::string& str) {
  31. return (Element::fromJSON(str));
  32. }
  33. class CCSessionTest : public ::testing::Test {
  34. protected:
  35. CCSessionTest() : session(el("[]"), el("[]"), el("[]")) {
  36. // upon creation of a ModuleCCSession, the class
  37. // sends its specification to the config manager.
  38. // it expects an ok answer back, so everytime we
  39. // create a ModuleCCSession, we must set an initial
  40. // ok answer.
  41. session.getMessages()->add(createAnswer());
  42. }
  43. ~CCSessionTest() {}
  44. FakeSession session;
  45. };
  46. TEST_F(CCSessionTest, createAnswer) {
  47. ConstElementPtr answer;
  48. answer = createAnswer();
  49. EXPECT_EQ("{ \"result\": [ 0 ] }", answer->str());
  50. answer = createAnswer(1, "error");
  51. EXPECT_EQ("{ \"result\": [ 1, \"error\" ] }", answer->str());
  52. EXPECT_THROW(createAnswer(1, ElementPtr()), CCSessionError);
  53. EXPECT_THROW(createAnswer(1, Element::create(1)), CCSessionError);
  54. ConstElementPtr arg = el("[ \"just\", \"some\", \"data\" ]");
  55. answer = createAnswer(0, arg);
  56. EXPECT_EQ("{ \"result\": [ 0, [ \"just\", \"some\", \"data\" ] ] }", answer->str());
  57. }
  58. TEST_F(CCSessionTest, parseAnswer) {
  59. ConstElementPtr answer;
  60. ConstElementPtr arg;
  61. int rcode;
  62. EXPECT_THROW(parseAnswer(rcode, ElementPtr()), CCSessionError);
  63. EXPECT_THROW(parseAnswer(rcode, el("1")), CCSessionError);
  64. EXPECT_THROW(parseAnswer(rcode, el("[]")), CCSessionError);
  65. EXPECT_THROW(parseAnswer(rcode, el("{ }")), CCSessionError);
  66. EXPECT_THROW(parseAnswer(rcode, el("{ \"something\": 1 }")), CCSessionError);
  67. EXPECT_THROW(parseAnswer(rcode, el("{ \"result\": 0 }")), CCSessionError);
  68. EXPECT_THROW(parseAnswer(rcode, el("{ \"result\": 1 }")), CCSessionError);
  69. EXPECT_THROW(parseAnswer(rcode, el("{ \"result\": [ 1 ] }")), CCSessionError);
  70. EXPECT_THROW(parseAnswer(rcode, el("{ \"result\": [ 1, 1 ] }")), CCSessionError);
  71. answer = el("{ \"result\": [ 0 ] }");
  72. arg = parseAnswer(rcode, answer);
  73. EXPECT_EQ(0, rcode);
  74. EXPECT_TRUE(isNull(arg));
  75. answer = el("{ \"result\": [ 1, \"error\"] }");
  76. arg = parseAnswer(rcode, answer);
  77. EXPECT_EQ(1, rcode);
  78. EXPECT_EQ("error", arg->stringValue());
  79. answer = el("{ \"result\": [ 0, [ \"just\", \"some\", \"data\" ] ] }");
  80. arg = parseAnswer(rcode, answer);
  81. EXPECT_EQ(0, rcode);
  82. EXPECT_EQ("[ \"just\", \"some\", \"data\" ]", arg->str());
  83. }
  84. TEST_F(CCSessionTest, createCommand) {
  85. ConstElementPtr command;
  86. ConstElementPtr arg;
  87. command = createCommand("my_command");
  88. ASSERT_EQ("{ \"command\": [ \"my_command\" ] }", command->str());
  89. arg = el("1");
  90. command = createCommand("my_command", arg);
  91. ASSERT_EQ("{ \"command\": [ \"my_command\", 1 ] }", command->str());
  92. arg = el("[ \"a\", \"b\" ]");
  93. command = createCommand("my_cmd", arg);
  94. ASSERT_EQ("{ \"command\": [ \"my_cmd\", [ \"a\", \"b\" ] ] }", command->str());
  95. arg = el("{ \"a\": \"map\" }");
  96. command = createCommand("foo", arg);
  97. ASSERT_EQ("{ \"command\": [ \"foo\", { \"a\": \"map\" } ] }", command->str());
  98. }
  99. TEST_F(CCSessionTest, parseCommand) {
  100. ConstElementPtr arg;
  101. std::string cmd;
  102. // should throw
  103. EXPECT_THROW(parseCommand(arg, ElementPtr()), CCSessionError);
  104. EXPECT_THROW(parseCommand(arg, el("1")), CCSessionError);
  105. EXPECT_THROW(parseCommand(arg, el("{ }")), CCSessionError);
  106. EXPECT_THROW(parseCommand(arg, el("{ \"not a command\": 1 }")), CCSessionError);
  107. EXPECT_THROW(parseCommand(arg, el("{ \"command\": 1 }")), CCSessionError);
  108. EXPECT_THROW(parseCommand(arg, el("{ \"command\": [] }")), CCSessionError);
  109. EXPECT_THROW(parseCommand(arg, el("{ \"command\": [ 1 ] }")), CCSessionError);
  110. cmd = parseCommand(arg, el("{ \"command\": [ \"my_command\" ] }"));
  111. EXPECT_EQ("my_command", cmd);
  112. EXPECT_EQ(*arg, *Element::createMap());
  113. cmd = parseCommand(arg, el("{ \"command\": [ \"my_command\", 1 ] }"));
  114. EXPECT_EQ("my_command", cmd);
  115. EXPECT_EQ("1", arg->str());
  116. parseCommand(arg, el("{ \"command\": [ \"my_command\", [ \"some\", \"argument\", \"list\" ] ] }"));
  117. EXPECT_EQ("my_command", cmd);
  118. EXPECT_EQ("[ \"some\", \"argument\", \"list\" ]", arg->str());
  119. }
  120. TEST_F(CCSessionTest, session1) {
  121. EXPECT_FALSE(session.haveSubscription("Spec1", "*"));
  122. ModuleCCSession mccs(ccspecfile("spec1.spec"), session, NULL, NULL);
  123. EXPECT_TRUE(session.haveSubscription("Spec1", "*"));
  124. EXPECT_EQ(1, session.getMsgQueue()->size());
  125. ConstElementPtr msg;
  126. std::string group, to;
  127. msg = session.getFirstMessage(group, to);
  128. EXPECT_EQ("{ \"command\": [ \"module_spec\", { \"module_name\": \"Spec1\" } ] }", msg->str());
  129. EXPECT_EQ("ConfigManager", group);
  130. EXPECT_EQ("*", to);
  131. EXPECT_EQ(0, session.getMsgQueue()->size());
  132. }
  133. TEST_F(CCSessionTest, session2) {
  134. EXPECT_FALSE(session.haveSubscription("Spec2", "*"));
  135. ModuleCCSession mccs(ccspecfile("spec2.spec"), session, NULL, NULL);
  136. EXPECT_TRUE(session.haveSubscription("Spec2", "*"));
  137. EXPECT_EQ(1, session.getMsgQueue()->size());
  138. ConstElementPtr msg;
  139. std::string group, to;
  140. msg = session.getFirstMessage(group, to);
  141. EXPECT_EQ("{ \"command\": [ \"module_spec\", { \"commands\": [ { \"command_args\": [ { \"item_default\": \"\", \"item_name\": \"message\", \"item_optional\": false, \"item_type\": \"string\" } ], \"command_description\": \"Print the given message to stdout\", \"command_name\": \"print_message\" }, { \"command_args\": [ ], \"command_description\": \"Shut down BIND 10\", \"command_name\": \"shutdown\" } ], \"config_data\": [ { \"item_default\": 1, \"item_name\": \"item1\", \"item_optional\": false, \"item_type\": \"integer\" }, { \"item_default\": 1.1, \"item_name\": \"item2\", \"item_optional\": false, \"item_type\": \"real\" }, { \"item_default\": true, \"item_name\": \"item3\", \"item_optional\": false, \"item_type\": \"boolean\" }, { \"item_default\": \"test\", \"item_name\": \"item4\", \"item_optional\": false, \"item_type\": \"string\" }, { \"item_default\": [ \"a\", \"b\" ], \"item_name\": \"item5\", \"item_optional\": false, \"item_type\": \"list\", \"list_item_spec\": { \"item_default\": \"\", \"item_name\": \"list_element\", \"item_optional\": false, \"item_type\": \"string\" } }, { \"item_default\": { }, \"item_name\": \"item6\", \"item_optional\": false, \"item_type\": \"map\", \"map_item_spec\": [ { \"item_default\": \"default\", \"item_name\": \"value1\", \"item_optional\": true, \"item_type\": \"string\" }, { \"item_name\": \"value2\", \"item_optional\": true, \"item_type\": \"integer\" } ] } ], \"module_name\": \"Spec2\" } ] }", msg->str());
  142. EXPECT_EQ("ConfigManager", group);
  143. EXPECT_EQ("*", to);
  144. EXPECT_EQ(0, session.getMsgQueue()->size());
  145. }
  146. ConstElementPtr my_config_handler(ConstElementPtr new_config) {
  147. if (new_config && new_config->contains("item1") &&
  148. new_config->get("item1")->intValue() == 5) {
  149. return (createAnswer(6, "I do not like the number 5"));
  150. }
  151. return (createAnswer());
  152. }
  153. ConstElementPtr my_command_handler(const std::string& command,
  154. ConstElementPtr arg)
  155. {
  156. if (command == "good_command") {
  157. return (createAnswer());
  158. } else if (command == "command_with_arg") {
  159. if (arg->contains("number")) {
  160. if (arg->get("number")->getType() == Element::integer) {
  161. return (createAnswer(0, el("2")));
  162. } else {
  163. return (createAnswer(1, "arg bad type"));
  164. }
  165. } else {
  166. return (createAnswer(1, "arg missing"));
  167. }
  168. } else {
  169. return (createAnswer(1, "bad command"));
  170. }
  171. }
  172. TEST_F(CCSessionTest, session3) {
  173. // client will ask for config
  174. session.getMessages()->add(createAnswer(0, el("{}")));
  175. EXPECT_FALSE(session.haveSubscription("Spec2", "*"));
  176. ModuleCCSession mccs(ccspecfile("spec2.spec"), session, my_config_handler,
  177. my_command_handler);
  178. EXPECT_TRUE(session.haveSubscription("Spec2", "*"));
  179. EXPECT_EQ(2, session.getMsgQueue()->size());
  180. ConstElementPtr msg;
  181. std::string group, to;
  182. msg = session.getFirstMessage(group, to);
  183. EXPECT_EQ("{ \"command\": [ \"module_spec\", { \"commands\": [ { \"command_args\": [ { \"item_default\": \"\", \"item_name\": \"message\", \"item_optional\": false, \"item_type\": \"string\" } ], \"command_description\": \"Print the given message to stdout\", \"command_name\": \"print_message\" }, { \"command_args\": [ ], \"command_description\": \"Shut down BIND 10\", \"command_name\": \"shutdown\" } ], \"config_data\": [ { \"item_default\": 1, \"item_name\": \"item1\", \"item_optional\": false, \"item_type\": \"integer\" }, { \"item_default\": 1.1, \"item_name\": \"item2\", \"item_optional\": false, \"item_type\": \"real\" }, { \"item_default\": true, \"item_name\": \"item3\", \"item_optional\": false, \"item_type\": \"boolean\" }, { \"item_default\": \"test\", \"item_name\": \"item4\", \"item_optional\": false, \"item_type\": \"string\" }, { \"item_default\": [ \"a\", \"b\" ], \"item_name\": \"item5\", \"item_optional\": false, \"item_type\": \"list\", \"list_item_spec\": { \"item_default\": \"\", \"item_name\": \"list_element\", \"item_optional\": false, \"item_type\": \"string\" } }, { \"item_default\": { }, \"item_name\": \"item6\", \"item_optional\": false, \"item_type\": \"map\", \"map_item_spec\": [ { \"item_default\": \"default\", \"item_name\": \"value1\", \"item_optional\": true, \"item_type\": \"string\" }, { \"item_name\": \"value2\", \"item_optional\": true, \"item_type\": \"integer\" } ] } ], \"module_name\": \"Spec2\" } ] }", msg->str());
  184. EXPECT_EQ("ConfigManager", group);
  185. EXPECT_EQ("*", to);
  186. EXPECT_EQ(1, session.getMsgQueue()->size());
  187. msg = session.getFirstMessage(group, to);
  188. EXPECT_EQ("{ \"command\": [ \"get_config\", { \"module_name\": \"Spec2\" } ] }", msg->str());
  189. EXPECT_EQ("ConfigManager", group);
  190. EXPECT_EQ("*", to);
  191. EXPECT_EQ(0, session.getMsgQueue()->size());
  192. }
  193. TEST_F(CCSessionTest, checkCommand) {
  194. // client will ask for config
  195. session.getMessages()->add(createAnswer(0, el("{}")));
  196. EXPECT_FALSE(session.haveSubscription("Spec29", "*"));
  197. ModuleCCSession mccs(ccspecfile("spec29.spec"), session, my_config_handler,
  198. my_command_handler);
  199. EXPECT_TRUE(session.haveSubscription("Spec29", "*"));
  200. EXPECT_EQ(2, session.getMsgQueue()->size());
  201. ConstElementPtr msg;
  202. std::string group, to;
  203. // checked above, drop em
  204. msg = session.getFirstMessage(group, to);
  205. msg = session.getFirstMessage(group, to);
  206. int result;
  207. result = mccs.checkCommand();
  208. EXPECT_EQ(0, result);
  209. // not a command, should be ignored
  210. session.addMessage(el("1"), "Spec29", "*");
  211. result = mccs.checkCommand();
  212. EXPECT_EQ(0, result);
  213. session.addMessage(el("{ \"command\": [ \"good_command\" ] }"), "Spec29",
  214. "*");
  215. result = mccs.checkCommand();
  216. EXPECT_EQ(1, session.getMsgQueue()->size());
  217. msg = session.getFirstMessage(group, to);
  218. EXPECT_EQ("{ \"result\": [ 0 ] }", msg->str());
  219. EXPECT_EQ(0, result);
  220. session.addMessage(el("{ \"command\": \"bad_command\" }"), "Spec29", "*");
  221. result = mccs.checkCommand();
  222. EXPECT_EQ(1, session.getMsgQueue()->size());
  223. msg = session.getFirstMessage(group, to);
  224. EXPECT_EQ("{ \"result\": [ 1, \"Command part in command message missing, empty, or not a list\" ] }", msg->str());
  225. EXPECT_EQ(0, result);
  226. session.addMessage(el("{ \"command\": [ \"bad_command\" ] }"),
  227. "Spec29", "*");
  228. result = mccs.checkCommand();
  229. EXPECT_EQ(1, session.getMsgQueue()->size());
  230. msg = session.getFirstMessage(group, to);
  231. EXPECT_EQ("{ \"result\": [ 1, \"bad command\" ] }", msg->str());
  232. EXPECT_EQ(0, result);
  233. session.addMessage(el("{ \"command\": [ \"command_with_arg\", {\"number\": 1} ] }"),
  234. "Spec29", "*");
  235. result = mccs.checkCommand();
  236. EXPECT_EQ(1, session.getMsgQueue()->size());
  237. msg = session.getFirstMessage(group, to);
  238. EXPECT_EQ("{ \"result\": [ 0, 2 ] }", msg->str());
  239. EXPECT_EQ(0, result);
  240. session.addMessage(el("{ \"command\": [ \"command_with_arg\" ] }"), "Spec29", "*");
  241. result = mccs.checkCommand();
  242. EXPECT_EQ(1, session.getMsgQueue()->size());
  243. msg = session.getFirstMessage(group, to);
  244. EXPECT_EQ("{ \"result\": [ 1, \"arg missing\" ] }", msg->str());
  245. EXPECT_EQ(0, result);
  246. session.addMessage(el("{ \"command\": [ \"command_with_arg\", \"asdf\" ] }"), "Spec29", "*");
  247. result = mccs.checkCommand();
  248. EXPECT_EQ(1, session.getMsgQueue()->size());
  249. msg = session.getFirstMessage(group, to);
  250. EXPECT_EQ("{ \"result\": [ 3, \"Error in command validation: args for command command_with_arg is not a map\" ] }", msg->str());
  251. EXPECT_EQ(0, result);
  252. mccs.setCommandHandler(NULL);
  253. session.addMessage(el("{ \"command\": [ \"whatever\" ] }"), "Spec29", "*");
  254. result = mccs.checkCommand();
  255. EXPECT_EQ(1, session.getMsgQueue()->size());
  256. msg = session.getFirstMessage(group, to);
  257. EXPECT_EQ("{ \"result\": [ 1, \"Command given but no command handler for module\" ] }", msg->str());
  258. EXPECT_EQ(0, result);
  259. }
  260. // A heuristic workaround for clang++: It doesn't seem to compile the whole
  261. // test, probably due to its length. Dividing the tests into two separate
  262. // test cases seems to work.
  263. TEST_F(CCSessionTest, checkCommand2) {
  264. session.getMessages()->add(createAnswer(0, el("{}")));
  265. EXPECT_FALSE(session.haveSubscription("Spec29", "*"));
  266. ModuleCCSession mccs(ccspecfile("spec29.spec"), session, my_config_handler,
  267. my_command_handler);
  268. EXPECT_TRUE(session.haveSubscription("Spec29", "*"));
  269. ConstElementPtr msg;
  270. std::string group, to;
  271. // checked above, drop em
  272. msg = session.getFirstMessage(group, to);
  273. msg = session.getFirstMessage(group, to);
  274. EXPECT_EQ(1, mccs.getValue("item1")->intValue());
  275. session.addMessage(el("{ \"command\": [ \"config_update\", { \"item1\": 2 } ] }"), "Spec29", "*");
  276. int result = mccs.checkCommand();
  277. EXPECT_EQ(1, session.getMsgQueue()->size());
  278. msg = session.getFirstMessage(group, to);
  279. EXPECT_EQ("{ \"result\": [ 0 ] }", msg->str());
  280. EXPECT_EQ(0, result);
  281. EXPECT_EQ(2, mccs.getValue("item1")->intValue());
  282. session.addMessage(el("{ \"command\": [ \"config_update\", { \"item1\": \"asdf\" } ] }"), "Spec29", "*");
  283. result = mccs.checkCommand();
  284. EXPECT_EQ(1, session.getMsgQueue()->size());
  285. msg = session.getFirstMessage(group, to);
  286. EXPECT_EQ("{ \"result\": [ 2, \"Error in config validation: Type mismatch\" ] }", msg->str());
  287. EXPECT_EQ(0, result);
  288. EXPECT_EQ(2, mccs.getValue("item1")->intValue());
  289. session.addMessage(el("{ \"command\": [ \"config_update\", { \"item1\": 5 } ] }"), "Spec29", "*");
  290. result = mccs.checkCommand();
  291. EXPECT_EQ(1, session.getMsgQueue()->size());
  292. msg = session.getFirstMessage(group, to);
  293. EXPECT_EQ("{ \"result\": [ 6, \"I do not like the number 5\" ] }", msg->str());
  294. EXPECT_EQ(0, result);
  295. EXPECT_EQ(2, mccs.getValue("item1")->intValue());
  296. }
  297. TEST_F(CCSessionTest, remoteConfig) {
  298. std::string module_name;
  299. int item1;
  300. ModuleCCSession mccs(ccspecfile("spec1.spec"), session, NULL, NULL);
  301. EXPECT_TRUE(session.haveSubscription("Spec1", "*"));
  302. // first simply connect, with no config values, and see we get
  303. // the default
  304. session.getMessages()->add(createAnswer(0, el("{}")));
  305. EXPECT_FALSE(session.haveSubscription("Spec2", "*"));
  306. module_name = mccs.addRemoteConfig(ccspecfile("spec2.spec"));
  307. EXPECT_EQ("Spec2", module_name);
  308. EXPECT_TRUE(session.haveSubscription("Spec2", "*"));
  309. item1 = mccs.getRemoteConfigValue(module_name, "item1")->intValue();
  310. EXPECT_EQ(1, item1);
  311. // Remove it and see we get an error asking for a config value
  312. mccs.removeRemoteConfig(module_name);
  313. EXPECT_FALSE(session.haveSubscription("Spec2", "*"));
  314. EXPECT_THROW(mccs.getRemoteConfigValue(module_name, "item1"), CCSessionError);
  315. // Now re-add it, with a specific config value, and see we get that
  316. session.getMessages()->add(createAnswer(0, el("{ \"item1\": 2 }")));
  317. module_name = mccs.addRemoteConfig(ccspecfile("spec2.spec"));
  318. item1 = mccs.getRemoteConfigValue(module_name, "item1")->intValue();
  319. EXPECT_EQ(2, item1);
  320. // Try a config_update command
  321. session.addMessage(el("{ \"command\": [ \"config_update\", { \"item1\": 3 } ] }"), module_name, "*");
  322. mccs.checkCommand();
  323. item1 = mccs.getRemoteConfigValue(module_name, "item1")->intValue();
  324. EXPECT_EQ(3, item1);
  325. // remove, re-add, now with a *bad* config request answer
  326. mccs.removeRemoteConfig(module_name);
  327. session.getMessages()->add(el("{}"));
  328. EXPECT_THROW(mccs.addRemoteConfig(ccspecfile("spec2.spec")), CCSessionError);
  329. session.getMessages()->add(createAnswer(1, "my_error"));
  330. EXPECT_THROW(mccs.addRemoteConfig(ccspecfile("spec2.spec")), CCSessionError);
  331. session.getMessages()->add(createAnswer());
  332. EXPECT_THROW(mccs.addRemoteConfig(ccspecfile("spec2.spec")), CCSessionError);
  333. }
  334. TEST_F(CCSessionTest, ignoreRemoteConfigCommands) {
  335. // client will ask for config
  336. session.getMessages()->add(createAnswer(0, el("{ }")));
  337. EXPECT_FALSE(session.haveSubscription("Spec29", "*"));
  338. ModuleCCSession mccs(ccspecfile("spec29.spec"), session, my_config_handler, my_command_handler);
  339. EXPECT_TRUE(session.haveSubscription("Spec29", "*"));
  340. EXPECT_EQ(2, session.getMsgQueue()->size());
  341. ConstElementPtr msg;
  342. std::string group, to;
  343. // drop the module_spec and config commands
  344. session.getFirstMessage(group, to);
  345. session.getFirstMessage(group, to);
  346. session.getMessages()->add(createAnswer(0, el("{ }")));
  347. mccs.addRemoteConfig(ccspecfile("spec1.spec"));
  348. EXPECT_EQ(1, session.getMsgQueue()->size());
  349. msg = session.getFirstMessage(group, to);
  350. // Check if commands for the module are handled
  351. session.addMessage(el("{ \"command\": [ \"good_command\" ] }"), "Spec29", "*");
  352. int result = mccs.checkCommand();
  353. EXPECT_EQ(1, session.getMsgQueue()->size());
  354. msg = session.getFirstMessage(group, to);
  355. EXPECT_EQ("{ \"result\": [ 0 ] }", msg->str());
  356. EXPECT_EQ(0, result);
  357. // Check if commands for the other module are ignored
  358. session.addMessage(el("{ \"command\": [ \"good_command\" ] }"), "Spec1", "*");
  359. EXPECT_EQ(1, session.getMsgQueue()->size());
  360. result = mccs.checkCommand();
  361. EXPECT_EQ(0, session.getMsgQueue()->size());
  362. }
  363. }