From: Michal 'vorner' Vaner Date: Thu, 5 Sep 2013 12:46:06 +0000 (+0200) Subject: [2932] Tests for the notification reception in C++ X-Git-Tag: bind10-1.2.0beta1-release~102^2~35^2~3 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=617c1d7c950beb8ddceb2ab03f37dca55959deb6;p=thirdparty%2Fkea.git [2932] Tests for the notification reception in C++ --- diff --git a/src/lib/config/tests/ccsession_unittests.cc b/src/lib/config/tests/ccsession_unittests.cc index 4a04412b43..4d987d4590 100644 --- a/src/lib/config/tests/ccsession_unittests.cc +++ b/src/lib/config/tests/ccsession_unittests.cc @@ -87,6 +87,70 @@ protected: const std::string root_name; }; +void +notificationCallback(std::vector* called, + const std::string& id, const std::string& notification, + const ConstElementPtr& params) +{ + called->push_back(id); + EXPECT_EQ("event", notification); + EXPECT_TRUE(el("{\"param\": true}")->equals(*params)); +} + +TEST_F(CCSessionTest, receiveNotification) { + // Not subscribed to the group yet + ModuleCCSession mccs(ccspecfile("spec1.spec"), session, NULL, NULL, + false, false); + EXPECT_FALSE(session.haveSubscription("notifications/group", "*")); + std::vector called; + // Subscribe to the notification. Twice. + const ModuleCCSession::NotificationID& first = + mccs.subscribeNotification("group", boost::bind(¬ificationCallback, + &called, "first", + _1, _2)); + const ModuleCCSession::NotificationID& second = + mccs.subscribeNotification("group", boost::bind(¬ificationCallback, + &called, "second", + _1, _2)); + EXPECT_TRUE(session.haveSubscription("notifications/group", "*")); + EXPECT_TRUE(called.empty()); + // Send the notification + session.getMessages()->add(el("{" + " \"notification\": [" + " \"event\", {" + " \"param\": true" + " }" + " ]" + " }")); + mccs.checkCommand(); + ASSERT_EQ(2, called.size()); + EXPECT_EQ("first", called[0]); + EXPECT_EQ("second", called[1]); + called.clear(); + // Unsubscribe one of them + mccs.unsubscribeNotification(first); + // We are still subscribed to the group and handle the requests + EXPECT_TRUE(session.haveSubscription("notifications/group", "*")); + // Send the notification + session.getMessages()->add(el("{" + " \"notification\": [" + " \"event\", {" + " \"param\": true" + " }" + " ]" + " }")); + mccs.checkCommand(); + ASSERT_EQ(1, called.size()); + EXPECT_EQ("second", called[0]); + // Try to unsubscribe again. That should fail. + EXPECT_THROW(mccs.unsubscribeNotification(first), isc::InvalidParameter); + EXPECT_TRUE(session.haveSubscription("notifications/group", "*")); + // Unsubscribe the other one too. That should cancel the upstream + // subscription + mccs.unsubscribeNotification(second); + EXPECT_FALSE(session.haveSubscription("notifications/group", "*")); +} + // Test we can send an RPC (command) and get an answer. The answer is success // in this case. TEST_F(CCSessionTest, rpcCallSuccess) {