Steve DiBenedetto | 5330e0d | 2014-03-05 21:52:51 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (C) 2014 Named Data Networking Project |
| 4 | * See COPYING for copyright and distribution information. |
| 5 | */ |
| 6 | |
| 7 | #include "mgmt/strategy-choice-manager.hpp" |
| 8 | #include "face/face.hpp" |
| 9 | #include "mgmt/internal-face.hpp" |
| 10 | #include "table/name-tree.hpp" |
| 11 | #include "table/strategy-choice.hpp" |
| 12 | #include "fw/forwarder.hpp" |
| 13 | #include "fw/strategy.hpp" |
| 14 | #include "tests/face/dummy-face.hpp" |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 15 | #include "tests/fw/dummy-strategy.hpp" |
Steve DiBenedetto | 5330e0d | 2014-03-05 21:52:51 -0700 | [diff] [blame] | 16 | |
| 17 | #include "tests/test-common.hpp" |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 18 | #include "validation-common.hpp" |
Steve DiBenedetto | 5330e0d | 2014-03-05 21:52:51 -0700 | [diff] [blame] | 19 | |
| 20 | namespace nfd { |
| 21 | namespace tests { |
| 22 | |
| 23 | NFD_LOG_INIT("StrategyChoiceManagerTest"); |
| 24 | |
Steve DiBenedetto | 5330e0d | 2014-03-05 21:52:51 -0700 | [diff] [blame] | 25 | class StrategyChoiceManagerFixture : protected BaseFixture |
| 26 | { |
| 27 | public: |
| 28 | |
| 29 | StrategyChoiceManagerFixture() |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 30 | : m_strategyChoice(m_forwarder.getStrategyChoice()) |
Steve DiBenedetto | 5330e0d | 2014-03-05 21:52:51 -0700 | [diff] [blame] | 31 | , m_face(make_shared<InternalFace>()) |
| 32 | , m_manager(m_strategyChoice, m_face) |
| 33 | , m_callbackFired(false) |
| 34 | { |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 35 | m_strategyChoice.install(make_shared<DummyStrategy>(boost::ref(m_forwarder), "/localhost/nfd/strategy/test-strategy-a")); |
| 36 | m_strategyChoice.insert("ndn:/", "/localhost/nfd/strategy/test-strategy-a"); |
Steve DiBenedetto | 5330e0d | 2014-03-05 21:52:51 -0700 | [diff] [blame] | 37 | } |
| 38 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 39 | virtual |
| 40 | ~StrategyChoiceManagerFixture() |
| 41 | { |
| 42 | |
| 43 | } |
| 44 | |
Steve DiBenedetto | 5330e0d | 2014-03-05 21:52:51 -0700 | [diff] [blame] | 45 | void |
| 46 | validateControlResponseCommon(const Data& response, |
| 47 | const Name& expectedName, |
| 48 | uint32_t expectedCode, |
| 49 | const std::string& expectedText, |
| 50 | ControlResponse& control) |
| 51 | { |
| 52 | m_callbackFired = true; |
| 53 | Block controlRaw = response.getContent().blockFromValue(); |
| 54 | |
| 55 | control.wireDecode(controlRaw); |
| 56 | |
| 57 | NFD_LOG_DEBUG("received control response" |
| 58 | << " Name: " << response.getName() |
| 59 | << " code: " << control.getCode() |
| 60 | << " text: " << control.getText()); |
| 61 | |
| 62 | BOOST_CHECK_EQUAL(response.getName(), expectedName); |
| 63 | BOOST_CHECK_EQUAL(control.getCode(), expectedCode); |
| 64 | BOOST_CHECK_EQUAL(control.getText(), expectedText); |
| 65 | } |
| 66 | |
| 67 | void |
| 68 | validateControlResponse(const Data& response, |
| 69 | const Name& expectedName, |
| 70 | uint32_t expectedCode, |
| 71 | const std::string& expectedText) |
| 72 | { |
| 73 | ControlResponse control; |
| 74 | validateControlResponseCommon(response, expectedName, |
| 75 | expectedCode, expectedText, control); |
| 76 | |
| 77 | if (!control.getBody().empty()) |
| 78 | { |
| 79 | BOOST_FAIL("found unexpected control response body"); |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | void |
| 84 | validateControlResponse(const Data& response, |
| 85 | const Name& expectedName, |
| 86 | uint32_t expectedCode, |
| 87 | const std::string& expectedText, |
| 88 | const Block& expectedBody) |
| 89 | { |
| 90 | ControlResponse control; |
| 91 | validateControlResponseCommon(response, expectedName, |
| 92 | expectedCode, expectedText, control); |
| 93 | |
| 94 | BOOST_REQUIRE(!control.getBody().empty()); |
| 95 | BOOST_REQUIRE(control.getBody().value_size() == expectedBody.value_size()); |
| 96 | |
| 97 | BOOST_CHECK(memcmp(control.getBody().value(), expectedBody.value(), |
| 98 | expectedBody.value_size()) == 0); |
| 99 | |
| 100 | } |
| 101 | |
| 102 | bool |
| 103 | didCallbackFire() |
| 104 | { |
| 105 | return m_callbackFired; |
| 106 | } |
| 107 | |
| 108 | void |
| 109 | resetCallbackFired() |
| 110 | { |
| 111 | m_callbackFired = false; |
| 112 | } |
| 113 | |
| 114 | shared_ptr<InternalFace>& |
| 115 | getFace() |
| 116 | { |
| 117 | return m_face; |
| 118 | } |
| 119 | |
| 120 | StrategyChoiceManager& |
| 121 | getManager() |
| 122 | { |
| 123 | return m_manager; |
| 124 | } |
| 125 | |
| 126 | StrategyChoice& |
| 127 | getStrategyChoice() |
| 128 | { |
| 129 | return m_strategyChoice; |
| 130 | } |
| 131 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 132 | void |
| 133 | addInterestRule(const std::string& regex, |
| 134 | ndn::IdentityCertificate& certificate) |
| 135 | { |
| 136 | m_manager.addInterestRule(regex, certificate); |
| 137 | } |
| 138 | |
Steve DiBenedetto | 5330e0d | 2014-03-05 21:52:51 -0700 | [diff] [blame] | 139 | protected: |
| 140 | Forwarder m_forwarder; |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 141 | StrategyChoice& m_strategyChoice; |
Steve DiBenedetto | 5330e0d | 2014-03-05 21:52:51 -0700 | [diff] [blame] | 142 | shared_ptr<InternalFace> m_face; |
| 143 | StrategyChoiceManager m_manager; |
| 144 | |
| 145 | private: |
| 146 | bool m_callbackFired; |
| 147 | }; |
| 148 | |
| 149 | class AllStrategiesFixture : public StrategyChoiceManagerFixture |
| 150 | { |
| 151 | public: |
| 152 | AllStrategiesFixture() |
| 153 | { |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 154 | m_strategyChoice.install(make_shared<DummyStrategy>(boost::ref(m_forwarder), "/localhost/nfd/strategy/test-strategy-b")); |
Steve DiBenedetto | 5330e0d | 2014-03-05 21:52:51 -0700 | [diff] [blame] | 155 | } |
| 156 | |
| 157 | virtual |
| 158 | ~AllStrategiesFixture() |
| 159 | { |
| 160 | |
| 161 | } |
| 162 | }; |
| 163 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 164 | template <typename T> class AuthorizedCommandFixture : public CommandFixture<T> |
| 165 | { |
| 166 | public: |
| 167 | AuthorizedCommandFixture() |
| 168 | { |
| 169 | const std::string regex = "^<localhost><nfd><strategy-choice>"; |
| 170 | T::addInterestRule(regex, *CommandFixture<T>::m_certificate); |
| 171 | } |
Steve DiBenedetto | 5330e0d | 2014-03-05 21:52:51 -0700 | [diff] [blame] | 172 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 173 | virtual |
| 174 | ~AuthorizedCommandFixture() |
| 175 | { |
| 176 | |
| 177 | } |
| 178 | }; |
| 179 | |
| 180 | BOOST_FIXTURE_TEST_SUITE(MgmtStrategyChoiceManager, |
| 181 | AuthorizedCommandFixture<AllStrategiesFixture>) |
| 182 | |
| 183 | BOOST_FIXTURE_TEST_CASE(TestFireInterestFilter, AllStrategiesFixture) |
Steve DiBenedetto | 5330e0d | 2014-03-05 21:52:51 -0700 | [diff] [blame] | 184 | { |
| 185 | shared_ptr<Interest> command(make_shared<Interest>("/localhost/nfd/strategy-choice")); |
| 186 | |
| 187 | getFace()->onReceiveData += |
| 188 | bind(&StrategyChoiceManagerFixture::validateControlResponse, this, _1, |
| 189 | command->getName(), 400, "Malformed command"); |
| 190 | |
| 191 | getFace()->sendInterest(*command); |
| 192 | |
| 193 | BOOST_REQUIRE(didCallbackFire()); |
| 194 | } |
| 195 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 196 | BOOST_FIXTURE_TEST_CASE(MalformedCommmand, AllStrategiesFixture) |
Steve DiBenedetto | 5330e0d | 2014-03-05 21:52:51 -0700 | [diff] [blame] | 197 | { |
| 198 | shared_ptr<Interest> command(make_shared<Interest>("/localhost/nfd/strategy-choice")); |
| 199 | |
| 200 | getFace()->onReceiveData += |
| 201 | bind(&StrategyChoiceManagerFixture::validateControlResponse, this, _1, |
| 202 | command->getName(), 400, "Malformed command"); |
| 203 | |
| 204 | getManager().onStrategyChoiceRequest(*command); |
| 205 | |
| 206 | BOOST_REQUIRE(didCallbackFire()); |
| 207 | } |
| 208 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 209 | BOOST_FIXTURE_TEST_CASE(UnsignedCommand, AllStrategiesFixture) |
| 210 | { |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 211 | ControlParameters parameters; |
| 212 | parameters.setName("/test"); |
| 213 | parameters.setStrategy("/localhost/nfd/strategy/best-route"); |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 214 | |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 215 | Block encodedParameters(parameters.wireEncode()); |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 216 | |
| 217 | Name commandName("/localhost/nfd/strategy-choice"); |
| 218 | commandName.append("set"); |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 219 | commandName.append(encodedParameters); |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 220 | |
| 221 | shared_ptr<Interest> command(make_shared<Interest>(commandName)); |
| 222 | |
| 223 | getFace()->onReceiveData += |
| 224 | bind(&StrategyChoiceManagerFixture::validateControlResponse, this, _1, |
| 225 | command->getName(), 401, "Signature required"); |
| 226 | |
| 227 | getManager().onStrategyChoiceRequest(*command); |
| 228 | |
| 229 | BOOST_REQUIRE(didCallbackFire()); |
| 230 | } |
| 231 | |
| 232 | BOOST_FIXTURE_TEST_CASE(UnauthorizedCommand, |
| 233 | UnauthorizedCommandFixture<StrategyChoiceManagerFixture>) |
| 234 | { |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 235 | ControlParameters parameters; |
| 236 | parameters.setName("/test"); |
| 237 | parameters.setStrategy("/localhost/nfd/strategy/best-route"); |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 238 | |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 239 | Block encodedParameters(parameters.wireEncode()); |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 240 | |
| 241 | Name commandName("/localhost/nfd/strategy-choice"); |
| 242 | commandName.append("set"); |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 243 | commandName.append(encodedParameters); |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 244 | |
| 245 | shared_ptr<Interest> command(make_shared<Interest>(commandName)); |
| 246 | generateCommand(*command); |
| 247 | |
| 248 | getFace()->onReceiveData += |
| 249 | bind(&StrategyChoiceManagerFixture::validateControlResponse, this, _1, |
| 250 | command->getName(), 403, "Unauthorized command"); |
| 251 | |
| 252 | getManager().onStrategyChoiceRequest(*command); |
| 253 | |
| 254 | BOOST_REQUIRE(didCallbackFire()); |
| 255 | } |
| 256 | |
Steve DiBenedetto | 5330e0d | 2014-03-05 21:52:51 -0700 | [diff] [blame] | 257 | BOOST_AUTO_TEST_CASE(UnsupportedVerb) |
| 258 | { |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 259 | ControlParameters parameters; |
| 260 | parameters.setName("/test"); |
| 261 | parameters.setStrategy("/localhost/nfd/strategy/test-strategy-b"); |
Steve DiBenedetto | 5330e0d | 2014-03-05 21:52:51 -0700 | [diff] [blame] | 262 | |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 263 | Block encodedParameters(parameters.wireEncode()); |
Steve DiBenedetto | 5330e0d | 2014-03-05 21:52:51 -0700 | [diff] [blame] | 264 | |
| 265 | Name commandName("/localhost/nfd/strategy-choice"); |
| 266 | commandName.append("unsupported"); |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 267 | commandName.append(encodedParameters); |
Steve DiBenedetto | 5330e0d | 2014-03-05 21:52:51 -0700 | [diff] [blame] | 268 | |
| 269 | shared_ptr<Interest> command(make_shared<Interest>(commandName)); |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 270 | generateCommand(*command); |
Steve DiBenedetto | 5330e0d | 2014-03-05 21:52:51 -0700 | [diff] [blame] | 271 | |
| 272 | getFace()->onReceiveData += |
| 273 | bind(&StrategyChoiceManagerFixture::validateControlResponse, this, _1, |
| 274 | command->getName(), 501, "Unsupported command"); |
| 275 | |
| 276 | getManager().onValidatedStrategyChoiceRequest(command); |
| 277 | |
| 278 | BOOST_REQUIRE(didCallbackFire()); |
| 279 | } |
| 280 | |
| 281 | BOOST_AUTO_TEST_CASE(BadOptionParse) |
| 282 | { |
| 283 | Name commandName("/localhost/nfd/strategy-choice"); |
| 284 | commandName.append("set"); |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 285 | commandName.append("NotReallyParameters"); |
Steve DiBenedetto | 5330e0d | 2014-03-05 21:52:51 -0700 | [diff] [blame] | 286 | |
| 287 | shared_ptr<Interest> command(make_shared<Interest>(commandName)); |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 288 | generateCommand(*command); |
Steve DiBenedetto | 5330e0d | 2014-03-05 21:52:51 -0700 | [diff] [blame] | 289 | |
| 290 | getFace()->onReceiveData += |
| 291 | bind(&StrategyChoiceManagerFixture::validateControlResponse, this, _1, |
| 292 | command->getName(), 400, "Malformed command"); |
| 293 | |
| 294 | getManager().onValidatedStrategyChoiceRequest(command); |
| 295 | |
| 296 | BOOST_REQUIRE(didCallbackFire()); |
| 297 | } |
| 298 | |
| 299 | BOOST_AUTO_TEST_CASE(SetStrategies) |
| 300 | { |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 301 | ControlParameters parameters; |
| 302 | parameters.setName("/test"); |
| 303 | parameters.setStrategy("/localhost/nfd/strategy/test-strategy-b"); |
Steve DiBenedetto | 5330e0d | 2014-03-05 21:52:51 -0700 | [diff] [blame] | 304 | |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 305 | Block encodedParameters(parameters.wireEncode()); |
Steve DiBenedetto | 5330e0d | 2014-03-05 21:52:51 -0700 | [diff] [blame] | 306 | |
| 307 | Name commandName("/localhost/nfd/strategy-choice"); |
| 308 | commandName.append("set"); |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 309 | commandName.append(encodedParameters); |
Steve DiBenedetto | 5330e0d | 2014-03-05 21:52:51 -0700 | [diff] [blame] | 310 | |
| 311 | shared_ptr<Interest> command(make_shared<Interest>(commandName)); |
| 312 | |
| 313 | getFace()->onReceiveData += |
| 314 | bind(&StrategyChoiceManagerFixture::validateControlResponse, this, _1, |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 315 | command->getName(), 200, "Success", encodedParameters); |
Steve DiBenedetto | 5330e0d | 2014-03-05 21:52:51 -0700 | [diff] [blame] | 316 | |
| 317 | getManager().onValidatedStrategyChoiceRequest(command); |
| 318 | |
| 319 | BOOST_REQUIRE(didCallbackFire()); |
| 320 | fw::Strategy& strategy = getStrategyChoice().findEffectiveStrategy("/test"); |
| 321 | BOOST_REQUIRE_EQUAL(strategy.getName(), "/localhost/nfd/strategy/test-strategy-b"); |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 322 | } |
Steve DiBenedetto | 5330e0d | 2014-03-05 21:52:51 -0700 | [diff] [blame] | 323 | |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 324 | BOOST_AUTO_TEST_CASE(SetStrategiesMissingName) |
| 325 | { |
| 326 | ControlParameters parameters; |
| 327 | parameters.setStrategy("/localhost/nfd/strategy/test-strategy-b"); |
| 328 | |
| 329 | Block encodedParameters(parameters.wireEncode()); |
| 330 | |
| 331 | Name commandName("/localhost/nfd/strategy-choice"); |
| 332 | commandName.append("set"); |
| 333 | commandName.append(encodedParameters); |
| 334 | |
| 335 | shared_ptr<Interest> command(make_shared<Interest>(commandName)); |
| 336 | |
| 337 | getFace()->onReceiveData += |
| 338 | bind(&StrategyChoiceManagerFixture::validateControlResponse, this, _1, |
| 339 | command->getName(), 400, "Malformed command"); |
| 340 | |
| 341 | getManager().onValidatedStrategyChoiceRequest(command); |
| 342 | |
| 343 | BOOST_REQUIRE(didCallbackFire()); |
| 344 | } |
| 345 | |
| 346 | BOOST_AUTO_TEST_CASE(SetStrategiesMissingStrategy) |
| 347 | { |
| 348 | ControlParameters parameters; |
| 349 | parameters.setName("/test"); |
| 350 | |
| 351 | Block encodedParameters(parameters.wireEncode()); |
| 352 | |
| 353 | Name commandName("/localhost/nfd/strategy-choice"); |
| 354 | commandName.append("set"); |
| 355 | commandName.append(encodedParameters); |
| 356 | |
| 357 | shared_ptr<Interest> command(make_shared<Interest>(commandName)); |
| 358 | |
| 359 | getFace()->onReceiveData += |
| 360 | bind(&StrategyChoiceManagerFixture::validateControlResponse, this, _1, |
| 361 | command->getName(), 400, "Malformed command"); |
| 362 | |
| 363 | getManager().onValidatedStrategyChoiceRequest(command); |
| 364 | |
| 365 | BOOST_REQUIRE(didCallbackFire()); |
| 366 | fw::Strategy& strategy = getStrategyChoice().findEffectiveStrategy("/test"); |
| 367 | BOOST_REQUIRE_EQUAL(strategy.getName(), "/localhost/nfd/strategy/test-strategy-a"); |
Steve DiBenedetto | 5330e0d | 2014-03-05 21:52:51 -0700 | [diff] [blame] | 368 | } |
| 369 | |
| 370 | BOOST_AUTO_TEST_CASE(SetUnsupportedStrategy) |
| 371 | { |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 372 | ControlParameters parameters; |
| 373 | parameters.setName("/test"); |
| 374 | parameters.setStrategy("/localhost/nfd/strategy/unit-test-doesnotexist"); |
Steve DiBenedetto | 5330e0d | 2014-03-05 21:52:51 -0700 | [diff] [blame] | 375 | |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 376 | Block encodedParameters(parameters.wireEncode()); |
Steve DiBenedetto | 5330e0d | 2014-03-05 21:52:51 -0700 | [diff] [blame] | 377 | |
| 378 | Name commandName("/localhost/nfd/strategy-choice"); |
| 379 | commandName.append("set"); |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 380 | commandName.append(encodedParameters); |
Steve DiBenedetto | 5330e0d | 2014-03-05 21:52:51 -0700 | [diff] [blame] | 381 | |
| 382 | shared_ptr<Interest> command(make_shared<Interest>(commandName)); |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 383 | generateCommand(*command); |
Steve DiBenedetto | 5330e0d | 2014-03-05 21:52:51 -0700 | [diff] [blame] | 384 | |
| 385 | getFace()->onReceiveData += |
| 386 | bind(&StrategyChoiceManagerFixture::validateControlResponse, this, _1, |
| 387 | command->getName(), 504, "Unsupported strategy"); |
| 388 | |
| 389 | getManager().onValidatedStrategyChoiceRequest(command); |
| 390 | |
| 391 | BOOST_REQUIRE(didCallbackFire()); |
| 392 | fw::Strategy& strategy = getStrategyChoice().findEffectiveStrategy("/test"); |
| 393 | BOOST_CHECK_EQUAL(strategy.getName(), "/localhost/nfd/strategy/test-strategy-a"); |
| 394 | } |
| 395 | |
| 396 | class DefaultStrategyOnlyFixture : public StrategyChoiceManagerFixture |
| 397 | { |
| 398 | public: |
| 399 | DefaultStrategyOnlyFixture() |
| 400 | : StrategyChoiceManagerFixture() |
| 401 | { |
| 402 | |
| 403 | } |
| 404 | |
| 405 | virtual |
| 406 | ~DefaultStrategyOnlyFixture() |
| 407 | { |
| 408 | |
| 409 | } |
| 410 | }; |
| 411 | |
| 412 | |
| 413 | /// \todo I'm not sure this code branch (code 405) can happen. The manager tests for the strategy first and will return 504. |
| 414 | // BOOST_FIXTURE_TEST_CASE(SetNotInstalled, DefaultStrategyOnlyFixture) |
| 415 | // { |
| 416 | // BOOST_REQUIRE(!getStrategyChoice().hasStrategy("/localhost/nfd/strategy/test-strategy-b")); |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 417 | // ControlParameters parameters; |
| 418 | // parameters.setName("/test"); |
| 419 | // parameters.setStrategy("/localhost/nfd/strategy/test-strategy-b"); |
Steve DiBenedetto | 5330e0d | 2014-03-05 21:52:51 -0700 | [diff] [blame] | 420 | |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 421 | // Block encodedParameters(parameters.wireEncode()); |
Steve DiBenedetto | 5330e0d | 2014-03-05 21:52:51 -0700 | [diff] [blame] | 422 | |
| 423 | // Name commandName("/localhost/nfd/strategy-choice"); |
| 424 | // commandName.append("set"); |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 425 | // commandName.append(encodedParameters); |
Steve DiBenedetto | 5330e0d | 2014-03-05 21:52:51 -0700 | [diff] [blame] | 426 | |
| 427 | // shared_ptr<Interest> command(make_shared<Interest>(commandName)); |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 428 | // generateCommand(*command); |
Steve DiBenedetto | 5330e0d | 2014-03-05 21:52:51 -0700 | [diff] [blame] | 429 | |
| 430 | // getFace()->onReceiveData += |
| 431 | // bind(&StrategyChoiceManagerFixture::validateControlResponse, this, _1, |
| 432 | // command->getName(), 405, "Strategy not installed"); |
| 433 | |
| 434 | // getManager().onValidatedStrategyChoiceRequest(command); |
| 435 | |
| 436 | // BOOST_REQUIRE(didCallbackFire()); |
| 437 | // fw::Strategy& strategy = getStrategyChoice().findEffectiveStrategy("/test"); |
| 438 | // BOOST_CHECK_EQUAL(strategy.getName(), "/localhost/nfd/strategy/test-strategy-a"); |
| 439 | // } |
| 440 | |
| 441 | BOOST_AUTO_TEST_CASE(Unset) |
| 442 | { |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 443 | ControlParameters parameters; |
| 444 | parameters.setName("/test"); |
Steve DiBenedetto | 5330e0d | 2014-03-05 21:52:51 -0700 | [diff] [blame] | 445 | |
| 446 | BOOST_REQUIRE(m_strategyChoice.insert("/test", "/localhost/nfd/strategy/test-strategy-b")); |
| 447 | BOOST_REQUIRE_EQUAL(m_strategyChoice.findEffectiveStrategy("/test").getName(), |
| 448 | "/localhost/nfd/strategy/test-strategy-b"); |
| 449 | |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 450 | Block encodedParameters(parameters.wireEncode()); |
Steve DiBenedetto | 5330e0d | 2014-03-05 21:52:51 -0700 | [diff] [blame] | 451 | |
| 452 | Name commandName("/localhost/nfd/strategy-choice"); |
| 453 | commandName.append("unset"); |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 454 | commandName.append(encodedParameters); |
Steve DiBenedetto | 5330e0d | 2014-03-05 21:52:51 -0700 | [diff] [blame] | 455 | |
| 456 | shared_ptr<Interest> command(make_shared<Interest>(commandName)); |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 457 | generateCommand(*command); |
Steve DiBenedetto | 5330e0d | 2014-03-05 21:52:51 -0700 | [diff] [blame] | 458 | |
| 459 | getFace()->onReceiveData += |
| 460 | bind(&StrategyChoiceManagerFixture::validateControlResponse, this, _1, |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 461 | command->getName(), 200, "Success", encodedParameters); |
Steve DiBenedetto | 5330e0d | 2014-03-05 21:52:51 -0700 | [diff] [blame] | 462 | |
| 463 | getManager().onValidatedStrategyChoiceRequest(command); |
| 464 | |
| 465 | BOOST_REQUIRE(didCallbackFire()); |
| 466 | |
| 467 | BOOST_CHECK_EQUAL(m_strategyChoice.findEffectiveStrategy("/test").getName(), |
| 468 | "/localhost/nfd/strategy/test-strategy-a"); |
| 469 | } |
| 470 | |
| 471 | BOOST_AUTO_TEST_CASE(UnsetRoot) |
| 472 | { |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 473 | ControlParameters parameters; |
| 474 | parameters.setName("/"); |
Steve DiBenedetto | 5330e0d | 2014-03-05 21:52:51 -0700 | [diff] [blame] | 475 | |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 476 | Block encodedParameters(parameters.wireEncode()); |
Steve DiBenedetto | 5330e0d | 2014-03-05 21:52:51 -0700 | [diff] [blame] | 477 | |
| 478 | Name commandName("/localhost/nfd/strategy-choice"); |
| 479 | commandName.append("unset"); |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 480 | commandName.append(encodedParameters); |
Steve DiBenedetto | 5330e0d | 2014-03-05 21:52:51 -0700 | [diff] [blame] | 481 | |
| 482 | shared_ptr<Interest> command(make_shared<Interest>(commandName)); |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 483 | generateCommand(*command); |
Steve DiBenedetto | 5330e0d | 2014-03-05 21:52:51 -0700 | [diff] [blame] | 484 | |
| 485 | getFace()->onReceiveData += |
| 486 | bind(&StrategyChoiceManagerFixture::validateControlResponse, this, _1, |
| 487 | command->getName(), 403, "Cannot unset root prefix strategy"); |
| 488 | |
| 489 | getManager().onValidatedStrategyChoiceRequest(command); |
| 490 | |
| 491 | BOOST_REQUIRE(didCallbackFire()); |
| 492 | |
| 493 | BOOST_CHECK_EQUAL(m_strategyChoice.findEffectiveStrategy("/test").getName(), |
| 494 | "/localhost/nfd/strategy/test-strategy-a"); |
| 495 | } |
| 496 | |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 497 | BOOST_AUTO_TEST_CASE(UnsetMissingName) |
| 498 | { |
| 499 | ControlParameters parameters; |
| 500 | |
| 501 | BOOST_REQUIRE(m_strategyChoice.insert("/test", "/localhost/nfd/strategy/test-strategy-b")); |
| 502 | BOOST_REQUIRE_EQUAL(m_strategyChoice.findEffectiveStrategy("/test").getName(), |
| 503 | "/localhost/nfd/strategy/test-strategy-b"); |
| 504 | |
| 505 | Block encodedParameters(parameters.wireEncode()); |
| 506 | |
| 507 | Name commandName("/localhost/nfd/strategy-choice"); |
| 508 | commandName.append("unset"); |
| 509 | commandName.append(encodedParameters); |
| 510 | |
| 511 | shared_ptr<Interest> command(make_shared<Interest>(commandName)); |
| 512 | generateCommand(*command); |
| 513 | |
| 514 | getFace()->onReceiveData += |
| 515 | bind(&StrategyChoiceManagerFixture::validateControlResponse, this, _1, |
| 516 | command->getName(), 400, "Malformed command"); |
| 517 | |
| 518 | getManager().onValidatedStrategyChoiceRequest(command); |
| 519 | |
| 520 | BOOST_REQUIRE(didCallbackFire()); |
| 521 | |
| 522 | BOOST_CHECK_EQUAL(m_strategyChoice.findEffectiveStrategy("/test").getName(), |
| 523 | "/localhost/nfd/strategy/test-strategy-b"); |
| 524 | } |
| 525 | |
Steve DiBenedetto | 5330e0d | 2014-03-05 21:52:51 -0700 | [diff] [blame] | 526 | BOOST_AUTO_TEST_SUITE_END() |
| 527 | |
| 528 | } // namespace tests |
| 529 | } // namespace nfd |