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); |
Junxiao Shi | 16d1b7d | 2014-03-27 21:29:09 -0700 | [diff] [blame^] | 192 | g_io.run_one(); |
Steve DiBenedetto | 5330e0d | 2014-03-05 21:52:51 -0700 | [diff] [blame] | 193 | |
| 194 | BOOST_REQUIRE(didCallbackFire()); |
| 195 | } |
| 196 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 197 | BOOST_FIXTURE_TEST_CASE(MalformedCommmand, AllStrategiesFixture) |
Steve DiBenedetto | 5330e0d | 2014-03-05 21:52:51 -0700 | [diff] [blame] | 198 | { |
| 199 | shared_ptr<Interest> command(make_shared<Interest>("/localhost/nfd/strategy-choice")); |
| 200 | |
| 201 | getFace()->onReceiveData += |
| 202 | bind(&StrategyChoiceManagerFixture::validateControlResponse, this, _1, |
| 203 | command->getName(), 400, "Malformed command"); |
| 204 | |
| 205 | getManager().onStrategyChoiceRequest(*command); |
| 206 | |
| 207 | BOOST_REQUIRE(didCallbackFire()); |
| 208 | } |
| 209 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 210 | BOOST_FIXTURE_TEST_CASE(UnsignedCommand, AllStrategiesFixture) |
| 211 | { |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 212 | ControlParameters parameters; |
| 213 | parameters.setName("/test"); |
| 214 | parameters.setStrategy("/localhost/nfd/strategy/best-route"); |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 215 | |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 216 | Block encodedParameters(parameters.wireEncode()); |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 217 | |
| 218 | Name commandName("/localhost/nfd/strategy-choice"); |
| 219 | commandName.append("set"); |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 220 | commandName.append(encodedParameters); |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 221 | |
| 222 | shared_ptr<Interest> command(make_shared<Interest>(commandName)); |
| 223 | |
| 224 | getFace()->onReceiveData += |
| 225 | bind(&StrategyChoiceManagerFixture::validateControlResponse, this, _1, |
| 226 | command->getName(), 401, "Signature required"); |
| 227 | |
| 228 | getManager().onStrategyChoiceRequest(*command); |
| 229 | |
| 230 | BOOST_REQUIRE(didCallbackFire()); |
| 231 | } |
| 232 | |
| 233 | BOOST_FIXTURE_TEST_CASE(UnauthorizedCommand, |
| 234 | UnauthorizedCommandFixture<StrategyChoiceManagerFixture>) |
| 235 | { |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 236 | ControlParameters parameters; |
| 237 | parameters.setName("/test"); |
| 238 | parameters.setStrategy("/localhost/nfd/strategy/best-route"); |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 239 | |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 240 | Block encodedParameters(parameters.wireEncode()); |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 241 | |
| 242 | Name commandName("/localhost/nfd/strategy-choice"); |
| 243 | commandName.append("set"); |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 244 | commandName.append(encodedParameters); |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 245 | |
| 246 | shared_ptr<Interest> command(make_shared<Interest>(commandName)); |
| 247 | generateCommand(*command); |
| 248 | |
| 249 | getFace()->onReceiveData += |
| 250 | bind(&StrategyChoiceManagerFixture::validateControlResponse, this, _1, |
| 251 | command->getName(), 403, "Unauthorized command"); |
| 252 | |
| 253 | getManager().onStrategyChoiceRequest(*command); |
| 254 | |
| 255 | BOOST_REQUIRE(didCallbackFire()); |
| 256 | } |
| 257 | |
Steve DiBenedetto | 5330e0d | 2014-03-05 21:52:51 -0700 | [diff] [blame] | 258 | BOOST_AUTO_TEST_CASE(UnsupportedVerb) |
| 259 | { |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 260 | ControlParameters parameters; |
| 261 | parameters.setName("/test"); |
| 262 | parameters.setStrategy("/localhost/nfd/strategy/test-strategy-b"); |
Steve DiBenedetto | 5330e0d | 2014-03-05 21:52:51 -0700 | [diff] [blame] | 263 | |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 264 | Block encodedParameters(parameters.wireEncode()); |
Steve DiBenedetto | 5330e0d | 2014-03-05 21:52:51 -0700 | [diff] [blame] | 265 | |
| 266 | Name commandName("/localhost/nfd/strategy-choice"); |
| 267 | commandName.append("unsupported"); |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 268 | commandName.append(encodedParameters); |
Steve DiBenedetto | 5330e0d | 2014-03-05 21:52:51 -0700 | [diff] [blame] | 269 | |
| 270 | shared_ptr<Interest> command(make_shared<Interest>(commandName)); |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 271 | generateCommand(*command); |
Steve DiBenedetto | 5330e0d | 2014-03-05 21:52:51 -0700 | [diff] [blame] | 272 | |
| 273 | getFace()->onReceiveData += |
| 274 | bind(&StrategyChoiceManagerFixture::validateControlResponse, this, _1, |
| 275 | command->getName(), 501, "Unsupported command"); |
| 276 | |
| 277 | getManager().onValidatedStrategyChoiceRequest(command); |
| 278 | |
| 279 | BOOST_REQUIRE(didCallbackFire()); |
| 280 | } |
| 281 | |
| 282 | BOOST_AUTO_TEST_CASE(BadOptionParse) |
| 283 | { |
| 284 | Name commandName("/localhost/nfd/strategy-choice"); |
| 285 | commandName.append("set"); |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 286 | commandName.append("NotReallyParameters"); |
Steve DiBenedetto | 5330e0d | 2014-03-05 21:52:51 -0700 | [diff] [blame] | 287 | |
| 288 | shared_ptr<Interest> command(make_shared<Interest>(commandName)); |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 289 | generateCommand(*command); |
Steve DiBenedetto | 5330e0d | 2014-03-05 21:52:51 -0700 | [diff] [blame] | 290 | |
| 291 | getFace()->onReceiveData += |
| 292 | bind(&StrategyChoiceManagerFixture::validateControlResponse, this, _1, |
| 293 | command->getName(), 400, "Malformed command"); |
| 294 | |
| 295 | getManager().onValidatedStrategyChoiceRequest(command); |
| 296 | |
| 297 | BOOST_REQUIRE(didCallbackFire()); |
| 298 | } |
| 299 | |
| 300 | BOOST_AUTO_TEST_CASE(SetStrategies) |
| 301 | { |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 302 | ControlParameters parameters; |
| 303 | parameters.setName("/test"); |
| 304 | parameters.setStrategy("/localhost/nfd/strategy/test-strategy-b"); |
Steve DiBenedetto | 5330e0d | 2014-03-05 21:52:51 -0700 | [diff] [blame] | 305 | |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 306 | Block encodedParameters(parameters.wireEncode()); |
Steve DiBenedetto | 5330e0d | 2014-03-05 21:52:51 -0700 | [diff] [blame] | 307 | |
| 308 | Name commandName("/localhost/nfd/strategy-choice"); |
| 309 | commandName.append("set"); |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 310 | commandName.append(encodedParameters); |
Steve DiBenedetto | 5330e0d | 2014-03-05 21:52:51 -0700 | [diff] [blame] | 311 | |
| 312 | shared_ptr<Interest> command(make_shared<Interest>(commandName)); |
| 313 | |
| 314 | getFace()->onReceiveData += |
| 315 | bind(&StrategyChoiceManagerFixture::validateControlResponse, this, _1, |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 316 | command->getName(), 200, "Success", encodedParameters); |
Steve DiBenedetto | 5330e0d | 2014-03-05 21:52:51 -0700 | [diff] [blame] | 317 | |
| 318 | getManager().onValidatedStrategyChoiceRequest(command); |
| 319 | |
| 320 | BOOST_REQUIRE(didCallbackFire()); |
| 321 | fw::Strategy& strategy = getStrategyChoice().findEffectiveStrategy("/test"); |
| 322 | BOOST_REQUIRE_EQUAL(strategy.getName(), "/localhost/nfd/strategy/test-strategy-b"); |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 323 | } |
Steve DiBenedetto | 5330e0d | 2014-03-05 21:52:51 -0700 | [diff] [blame] | 324 | |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 325 | BOOST_AUTO_TEST_CASE(SetStrategiesMissingName) |
| 326 | { |
| 327 | ControlParameters parameters; |
| 328 | parameters.setStrategy("/localhost/nfd/strategy/test-strategy-b"); |
| 329 | |
| 330 | Block encodedParameters(parameters.wireEncode()); |
| 331 | |
| 332 | Name commandName("/localhost/nfd/strategy-choice"); |
| 333 | commandName.append("set"); |
| 334 | commandName.append(encodedParameters); |
| 335 | |
| 336 | shared_ptr<Interest> command(make_shared<Interest>(commandName)); |
| 337 | |
| 338 | getFace()->onReceiveData += |
| 339 | bind(&StrategyChoiceManagerFixture::validateControlResponse, this, _1, |
| 340 | command->getName(), 400, "Malformed command"); |
| 341 | |
| 342 | getManager().onValidatedStrategyChoiceRequest(command); |
| 343 | |
| 344 | BOOST_REQUIRE(didCallbackFire()); |
| 345 | } |
| 346 | |
| 347 | BOOST_AUTO_TEST_CASE(SetStrategiesMissingStrategy) |
| 348 | { |
| 349 | ControlParameters parameters; |
| 350 | parameters.setName("/test"); |
| 351 | |
| 352 | Block encodedParameters(parameters.wireEncode()); |
| 353 | |
| 354 | Name commandName("/localhost/nfd/strategy-choice"); |
| 355 | commandName.append("set"); |
| 356 | commandName.append(encodedParameters); |
| 357 | |
| 358 | shared_ptr<Interest> command(make_shared<Interest>(commandName)); |
| 359 | |
| 360 | getFace()->onReceiveData += |
| 361 | bind(&StrategyChoiceManagerFixture::validateControlResponse, this, _1, |
| 362 | command->getName(), 400, "Malformed command"); |
| 363 | |
| 364 | getManager().onValidatedStrategyChoiceRequest(command); |
| 365 | |
| 366 | BOOST_REQUIRE(didCallbackFire()); |
| 367 | fw::Strategy& strategy = getStrategyChoice().findEffectiveStrategy("/test"); |
| 368 | BOOST_REQUIRE_EQUAL(strategy.getName(), "/localhost/nfd/strategy/test-strategy-a"); |
Steve DiBenedetto | 5330e0d | 2014-03-05 21:52:51 -0700 | [diff] [blame] | 369 | } |
| 370 | |
| 371 | BOOST_AUTO_TEST_CASE(SetUnsupportedStrategy) |
| 372 | { |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 373 | ControlParameters parameters; |
| 374 | parameters.setName("/test"); |
| 375 | parameters.setStrategy("/localhost/nfd/strategy/unit-test-doesnotexist"); |
Steve DiBenedetto | 5330e0d | 2014-03-05 21:52:51 -0700 | [diff] [blame] | 376 | |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 377 | Block encodedParameters(parameters.wireEncode()); |
Steve DiBenedetto | 5330e0d | 2014-03-05 21:52:51 -0700 | [diff] [blame] | 378 | |
| 379 | Name commandName("/localhost/nfd/strategy-choice"); |
| 380 | commandName.append("set"); |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 381 | commandName.append(encodedParameters); |
Steve DiBenedetto | 5330e0d | 2014-03-05 21:52:51 -0700 | [diff] [blame] | 382 | |
| 383 | shared_ptr<Interest> command(make_shared<Interest>(commandName)); |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 384 | generateCommand(*command); |
Steve DiBenedetto | 5330e0d | 2014-03-05 21:52:51 -0700 | [diff] [blame] | 385 | |
| 386 | getFace()->onReceiveData += |
| 387 | bind(&StrategyChoiceManagerFixture::validateControlResponse, this, _1, |
| 388 | command->getName(), 504, "Unsupported strategy"); |
| 389 | |
| 390 | getManager().onValidatedStrategyChoiceRequest(command); |
| 391 | |
| 392 | BOOST_REQUIRE(didCallbackFire()); |
| 393 | fw::Strategy& strategy = getStrategyChoice().findEffectiveStrategy("/test"); |
| 394 | BOOST_CHECK_EQUAL(strategy.getName(), "/localhost/nfd/strategy/test-strategy-a"); |
| 395 | } |
| 396 | |
| 397 | class DefaultStrategyOnlyFixture : public StrategyChoiceManagerFixture |
| 398 | { |
| 399 | public: |
| 400 | DefaultStrategyOnlyFixture() |
| 401 | : StrategyChoiceManagerFixture() |
| 402 | { |
| 403 | |
| 404 | } |
| 405 | |
| 406 | virtual |
| 407 | ~DefaultStrategyOnlyFixture() |
| 408 | { |
| 409 | |
| 410 | } |
| 411 | }; |
| 412 | |
| 413 | |
| 414 | /// \todo I'm not sure this code branch (code 405) can happen. The manager tests for the strategy first and will return 504. |
| 415 | // BOOST_FIXTURE_TEST_CASE(SetNotInstalled, DefaultStrategyOnlyFixture) |
| 416 | // { |
| 417 | // BOOST_REQUIRE(!getStrategyChoice().hasStrategy("/localhost/nfd/strategy/test-strategy-b")); |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 418 | // ControlParameters parameters; |
| 419 | // parameters.setName("/test"); |
| 420 | // parameters.setStrategy("/localhost/nfd/strategy/test-strategy-b"); |
Steve DiBenedetto | 5330e0d | 2014-03-05 21:52:51 -0700 | [diff] [blame] | 421 | |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 422 | // Block encodedParameters(parameters.wireEncode()); |
Steve DiBenedetto | 5330e0d | 2014-03-05 21:52:51 -0700 | [diff] [blame] | 423 | |
| 424 | // Name commandName("/localhost/nfd/strategy-choice"); |
| 425 | // commandName.append("set"); |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 426 | // commandName.append(encodedParameters); |
Steve DiBenedetto | 5330e0d | 2014-03-05 21:52:51 -0700 | [diff] [blame] | 427 | |
| 428 | // shared_ptr<Interest> command(make_shared<Interest>(commandName)); |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 429 | // generateCommand(*command); |
Steve DiBenedetto | 5330e0d | 2014-03-05 21:52:51 -0700 | [diff] [blame] | 430 | |
| 431 | // getFace()->onReceiveData += |
| 432 | // bind(&StrategyChoiceManagerFixture::validateControlResponse, this, _1, |
| 433 | // command->getName(), 405, "Strategy not installed"); |
| 434 | |
| 435 | // getManager().onValidatedStrategyChoiceRequest(command); |
| 436 | |
| 437 | // BOOST_REQUIRE(didCallbackFire()); |
| 438 | // fw::Strategy& strategy = getStrategyChoice().findEffectiveStrategy("/test"); |
| 439 | // BOOST_CHECK_EQUAL(strategy.getName(), "/localhost/nfd/strategy/test-strategy-a"); |
| 440 | // } |
| 441 | |
| 442 | BOOST_AUTO_TEST_CASE(Unset) |
| 443 | { |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 444 | ControlParameters parameters; |
| 445 | parameters.setName("/test"); |
Steve DiBenedetto | 5330e0d | 2014-03-05 21:52:51 -0700 | [diff] [blame] | 446 | |
| 447 | BOOST_REQUIRE(m_strategyChoice.insert("/test", "/localhost/nfd/strategy/test-strategy-b")); |
| 448 | BOOST_REQUIRE_EQUAL(m_strategyChoice.findEffectiveStrategy("/test").getName(), |
| 449 | "/localhost/nfd/strategy/test-strategy-b"); |
| 450 | |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 451 | Block encodedParameters(parameters.wireEncode()); |
Steve DiBenedetto | 5330e0d | 2014-03-05 21:52:51 -0700 | [diff] [blame] | 452 | |
| 453 | Name commandName("/localhost/nfd/strategy-choice"); |
| 454 | commandName.append("unset"); |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 455 | commandName.append(encodedParameters); |
Steve DiBenedetto | 5330e0d | 2014-03-05 21:52:51 -0700 | [diff] [blame] | 456 | |
| 457 | shared_ptr<Interest> command(make_shared<Interest>(commandName)); |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 458 | generateCommand(*command); |
Steve DiBenedetto | 5330e0d | 2014-03-05 21:52:51 -0700 | [diff] [blame] | 459 | |
| 460 | getFace()->onReceiveData += |
| 461 | bind(&StrategyChoiceManagerFixture::validateControlResponse, this, _1, |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 462 | command->getName(), 200, "Success", encodedParameters); |
Steve DiBenedetto | 5330e0d | 2014-03-05 21:52:51 -0700 | [diff] [blame] | 463 | |
| 464 | getManager().onValidatedStrategyChoiceRequest(command); |
| 465 | |
| 466 | BOOST_REQUIRE(didCallbackFire()); |
| 467 | |
| 468 | BOOST_CHECK_EQUAL(m_strategyChoice.findEffectiveStrategy("/test").getName(), |
| 469 | "/localhost/nfd/strategy/test-strategy-a"); |
| 470 | } |
| 471 | |
| 472 | BOOST_AUTO_TEST_CASE(UnsetRoot) |
| 473 | { |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 474 | ControlParameters parameters; |
| 475 | parameters.setName("/"); |
Steve DiBenedetto | 5330e0d | 2014-03-05 21:52:51 -0700 | [diff] [blame] | 476 | |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 477 | Block encodedParameters(parameters.wireEncode()); |
Steve DiBenedetto | 5330e0d | 2014-03-05 21:52:51 -0700 | [diff] [blame] | 478 | |
| 479 | Name commandName("/localhost/nfd/strategy-choice"); |
| 480 | commandName.append("unset"); |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 481 | commandName.append(encodedParameters); |
Steve DiBenedetto | 5330e0d | 2014-03-05 21:52:51 -0700 | [diff] [blame] | 482 | |
| 483 | shared_ptr<Interest> command(make_shared<Interest>(commandName)); |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 484 | generateCommand(*command); |
Steve DiBenedetto | 5330e0d | 2014-03-05 21:52:51 -0700 | [diff] [blame] | 485 | |
| 486 | getFace()->onReceiveData += |
| 487 | bind(&StrategyChoiceManagerFixture::validateControlResponse, this, _1, |
| 488 | command->getName(), 403, "Cannot unset root prefix strategy"); |
| 489 | |
| 490 | getManager().onValidatedStrategyChoiceRequest(command); |
| 491 | |
| 492 | BOOST_REQUIRE(didCallbackFire()); |
| 493 | |
| 494 | BOOST_CHECK_EQUAL(m_strategyChoice.findEffectiveStrategy("/test").getName(), |
| 495 | "/localhost/nfd/strategy/test-strategy-a"); |
| 496 | } |
| 497 | |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 498 | BOOST_AUTO_TEST_CASE(UnsetMissingName) |
| 499 | { |
| 500 | ControlParameters parameters; |
| 501 | |
| 502 | BOOST_REQUIRE(m_strategyChoice.insert("/test", "/localhost/nfd/strategy/test-strategy-b")); |
| 503 | BOOST_REQUIRE_EQUAL(m_strategyChoice.findEffectiveStrategy("/test").getName(), |
| 504 | "/localhost/nfd/strategy/test-strategy-b"); |
| 505 | |
| 506 | Block encodedParameters(parameters.wireEncode()); |
| 507 | |
| 508 | Name commandName("/localhost/nfd/strategy-choice"); |
| 509 | commandName.append("unset"); |
| 510 | commandName.append(encodedParameters); |
| 511 | |
| 512 | shared_ptr<Interest> command(make_shared<Interest>(commandName)); |
| 513 | generateCommand(*command); |
| 514 | |
| 515 | getFace()->onReceiveData += |
| 516 | bind(&StrategyChoiceManagerFixture::validateControlResponse, this, _1, |
| 517 | command->getName(), 400, "Malformed command"); |
| 518 | |
| 519 | getManager().onValidatedStrategyChoiceRequest(command); |
| 520 | |
| 521 | BOOST_REQUIRE(didCallbackFire()); |
| 522 | |
| 523 | BOOST_CHECK_EQUAL(m_strategyChoice.findEffectiveStrategy("/test").getName(), |
| 524 | "/localhost/nfd/strategy/test-strategy-b"); |
| 525 | } |
| 526 | |
Steve DiBenedetto | 5330e0d | 2014-03-05 21:52:51 -0700 | [diff] [blame] | 527 | BOOST_AUTO_TEST_SUITE_END() |
| 528 | |
| 529 | } // namespace tests |
| 530 | } // namespace nfd |