blob: 9b5f2c510ea539f9a68a246a77fc29770926b46c [file] [log] [blame]
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -07003 * Copyright (c) 2014 Regents of the University of California,
4 * Arizona Board of Regents,
5 * Colorado State University,
6 * University Pierre & Marie Curie, Sorbonne University,
7 * Washington University in St. Louis,
8 * Beijing Institute of Technology
9 *
10 * This file is part of NFD (Named Data Networking Forwarding Daemon).
11 * See AUTHORS.md for complete list of NFD authors and contributors.
12 *
13 * NFD is free software: you can redistribute it and/or modify it under the terms
14 * of the GNU General Public License as published by the Free Software Foundation,
15 * either version 3 of the License, or (at your option) any later version.
16 *
17 * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
18 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
19 * PURPOSE. See the GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License along with
22 * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
23 **/
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -070024
25#include "mgmt/strategy-choice-manager.hpp"
26#include "face/face.hpp"
27#include "mgmt/internal-face.hpp"
28#include "table/name-tree.hpp"
29#include "table/strategy-choice.hpp"
30#include "fw/forwarder.hpp"
31#include "fw/strategy.hpp"
Alexander Afanasyev613e2a92014-04-15 13:36:58 -070032#include "tests/daemon/face/dummy-face.hpp"
33#include "tests/daemon/fw/dummy-strategy.hpp"
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -070034
35#include "tests/test-common.hpp"
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -070036#include "validation-common.hpp"
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -070037
38namespace nfd {
39namespace tests {
40
41NFD_LOG_INIT("StrategyChoiceManagerTest");
42
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -070043class StrategyChoiceManagerFixture : protected BaseFixture
44{
45public:
46
47 StrategyChoiceManagerFixture()
Junxiao Shif3c07812014-03-11 21:48:49 -070048 : m_strategyChoice(m_forwarder.getStrategyChoice())
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -070049 , m_face(make_shared<InternalFace>())
50 , m_manager(m_strategyChoice, m_face)
51 , m_callbackFired(false)
52 {
Alexander Afanasyevf6980282014-05-13 18:28:40 -070053 m_strategyChoice.install(make_shared<DummyStrategy>(ref(m_forwarder),
54 "/localhost/nfd/strategy/test-strategy-a"));
Junxiao Shif3c07812014-03-11 21:48:49 -070055 m_strategyChoice.insert("ndn:/", "/localhost/nfd/strategy/test-strategy-a");
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -070056 }
57
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -070058 virtual
59 ~StrategyChoiceManagerFixture()
60 {
61
62 }
63
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -070064 void
65 validateControlResponseCommon(const Data& response,
66 const Name& expectedName,
67 uint32_t expectedCode,
68 const std::string& expectedText,
69 ControlResponse& control)
70 {
71 m_callbackFired = true;
72 Block controlRaw = response.getContent().blockFromValue();
73
74 control.wireDecode(controlRaw);
75
76 NFD_LOG_DEBUG("received control response"
77 << " Name: " << response.getName()
78 << " code: " << control.getCode()
79 << " text: " << control.getText());
80
81 BOOST_CHECK_EQUAL(response.getName(), expectedName);
82 BOOST_CHECK_EQUAL(control.getCode(), expectedCode);
83 BOOST_CHECK_EQUAL(control.getText(), expectedText);
84 }
85
86 void
87 validateControlResponse(const Data& response,
88 const Name& expectedName,
89 uint32_t expectedCode,
90 const std::string& expectedText)
91 {
92 ControlResponse control;
93 validateControlResponseCommon(response, expectedName,
94 expectedCode, expectedText, control);
95
96 if (!control.getBody().empty())
97 {
98 BOOST_FAIL("found unexpected control response body");
99 }
100 }
101
102 void
103 validateControlResponse(const Data& response,
104 const Name& expectedName,
105 uint32_t expectedCode,
106 const std::string& expectedText,
107 const Block& expectedBody)
108 {
109 ControlResponse control;
110 validateControlResponseCommon(response, expectedName,
111 expectedCode, expectedText, control);
112
113 BOOST_REQUIRE(!control.getBody().empty());
114 BOOST_REQUIRE(control.getBody().value_size() == expectedBody.value_size());
115
116 BOOST_CHECK(memcmp(control.getBody().value(), expectedBody.value(),
117 expectedBody.value_size()) == 0);
118
119 }
120
121 bool
122 didCallbackFire()
123 {
124 return m_callbackFired;
125 }
126
127 void
128 resetCallbackFired()
129 {
130 m_callbackFired = false;
131 }
132
133 shared_ptr<InternalFace>&
134 getFace()
135 {
136 return m_face;
137 }
138
139 StrategyChoiceManager&
140 getManager()
141 {
142 return m_manager;
143 }
144
145 StrategyChoice&
146 getStrategyChoice()
147 {
148 return m_strategyChoice;
149 }
150
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700151 void
152 addInterestRule(const std::string& regex,
153 ndn::IdentityCertificate& certificate)
154 {
155 m_manager.addInterestRule(regex, certificate);
156 }
157
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700158protected:
159 Forwarder m_forwarder;
Junxiao Shif3c07812014-03-11 21:48:49 -0700160 StrategyChoice& m_strategyChoice;
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700161 shared_ptr<InternalFace> m_face;
162 StrategyChoiceManager m_manager;
163
164private:
165 bool m_callbackFired;
166};
167
168class AllStrategiesFixture : public StrategyChoiceManagerFixture
169{
170public:
171 AllStrategiesFixture()
172 {
Alexander Afanasyevf6980282014-05-13 18:28:40 -0700173 m_strategyChoice.install(make_shared<DummyStrategy>(ref(m_forwarder),
174 "/localhost/nfd/strategy/test-strategy-b"));
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700175 }
176
177 virtual
178 ~AllStrategiesFixture()
179 {
180
181 }
182};
183
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700184template <typename T> class AuthorizedCommandFixture : public CommandFixture<T>
185{
186public:
187 AuthorizedCommandFixture()
188 {
189 const std::string regex = "^<localhost><nfd><strategy-choice>";
190 T::addInterestRule(regex, *CommandFixture<T>::m_certificate);
191 }
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700192
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700193 virtual
194 ~AuthorizedCommandFixture()
195 {
196
197 }
198};
199
200BOOST_FIXTURE_TEST_SUITE(MgmtStrategyChoiceManager,
201 AuthorizedCommandFixture<AllStrategiesFixture>)
202
203BOOST_FIXTURE_TEST_CASE(TestFireInterestFilter, AllStrategiesFixture)
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700204{
205 shared_ptr<Interest> command(make_shared<Interest>("/localhost/nfd/strategy-choice"));
206
207 getFace()->onReceiveData +=
208 bind(&StrategyChoiceManagerFixture::validateControlResponse, this, _1,
209 command->getName(), 400, "Malformed command");
210
211 getFace()->sendInterest(*command);
Junxiao Shi16d1b7d2014-03-27 21:29:09 -0700212 g_io.run_one();
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700213
214 BOOST_REQUIRE(didCallbackFire());
215}
216
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700217BOOST_FIXTURE_TEST_CASE(MalformedCommmand, AllStrategiesFixture)
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700218{
219 shared_ptr<Interest> command(make_shared<Interest>("/localhost/nfd/strategy-choice"));
220
221 getFace()->onReceiveData +=
222 bind(&StrategyChoiceManagerFixture::validateControlResponse, this, _1,
223 command->getName(), 400, "Malformed command");
224
225 getManager().onStrategyChoiceRequest(*command);
226
227 BOOST_REQUIRE(didCallbackFire());
228}
229
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700230BOOST_FIXTURE_TEST_CASE(UnsignedCommand, AllStrategiesFixture)
231{
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600232 ControlParameters parameters;
233 parameters.setName("/test");
234 parameters.setStrategy("/localhost/nfd/strategy/best-route");
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700235
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600236 Block encodedParameters(parameters.wireEncode());
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700237
238 Name commandName("/localhost/nfd/strategy-choice");
239 commandName.append("set");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600240 commandName.append(encodedParameters);
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700241
242 shared_ptr<Interest> command(make_shared<Interest>(commandName));
243
244 getFace()->onReceiveData +=
245 bind(&StrategyChoiceManagerFixture::validateControlResponse, this, _1,
246 command->getName(), 401, "Signature required");
247
248 getManager().onStrategyChoiceRequest(*command);
249
250 BOOST_REQUIRE(didCallbackFire());
251}
252
253BOOST_FIXTURE_TEST_CASE(UnauthorizedCommand,
254 UnauthorizedCommandFixture<StrategyChoiceManagerFixture>)
255{
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600256 ControlParameters parameters;
257 parameters.setName("/test");
258 parameters.setStrategy("/localhost/nfd/strategy/best-route");
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700259
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600260 Block encodedParameters(parameters.wireEncode());
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700261
262 Name commandName("/localhost/nfd/strategy-choice");
263 commandName.append("set");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600264 commandName.append(encodedParameters);
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700265
266 shared_ptr<Interest> command(make_shared<Interest>(commandName));
267 generateCommand(*command);
268
269 getFace()->onReceiveData +=
270 bind(&StrategyChoiceManagerFixture::validateControlResponse, this, _1,
271 command->getName(), 403, "Unauthorized command");
272
273 getManager().onStrategyChoiceRequest(*command);
274
275 BOOST_REQUIRE(didCallbackFire());
276}
277
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700278BOOST_AUTO_TEST_CASE(UnsupportedVerb)
279{
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600280 ControlParameters parameters;
281 parameters.setName("/test");
282 parameters.setStrategy("/localhost/nfd/strategy/test-strategy-b");
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700283
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600284 Block encodedParameters(parameters.wireEncode());
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700285
286 Name commandName("/localhost/nfd/strategy-choice");
287 commandName.append("unsupported");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600288 commandName.append(encodedParameters);
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700289
290 shared_ptr<Interest> command(make_shared<Interest>(commandName));
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700291 generateCommand(*command);
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700292
293 getFace()->onReceiveData +=
294 bind(&StrategyChoiceManagerFixture::validateControlResponse, this, _1,
295 command->getName(), 501, "Unsupported command");
296
297 getManager().onValidatedStrategyChoiceRequest(command);
298
299 BOOST_REQUIRE(didCallbackFire());
300}
301
302BOOST_AUTO_TEST_CASE(BadOptionParse)
303{
304 Name commandName("/localhost/nfd/strategy-choice");
305 commandName.append("set");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600306 commandName.append("NotReallyParameters");
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700307
308 shared_ptr<Interest> command(make_shared<Interest>(commandName));
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700309 generateCommand(*command);
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700310
311 getFace()->onReceiveData +=
312 bind(&StrategyChoiceManagerFixture::validateControlResponse, this, _1,
313 command->getName(), 400, "Malformed command");
314
315 getManager().onValidatedStrategyChoiceRequest(command);
316
317 BOOST_REQUIRE(didCallbackFire());
318}
319
320BOOST_AUTO_TEST_CASE(SetStrategies)
321{
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600322 ControlParameters parameters;
323 parameters.setName("/test");
324 parameters.setStrategy("/localhost/nfd/strategy/test-strategy-b");
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700325
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600326 Block encodedParameters(parameters.wireEncode());
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700327
328 Name commandName("/localhost/nfd/strategy-choice");
329 commandName.append("set");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600330 commandName.append(encodedParameters);
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700331
332 shared_ptr<Interest> command(make_shared<Interest>(commandName));
333
334 getFace()->onReceiveData +=
335 bind(&StrategyChoiceManagerFixture::validateControlResponse, this, _1,
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600336 command->getName(), 200, "Success", encodedParameters);
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700337
338 getManager().onValidatedStrategyChoiceRequest(command);
339
340 BOOST_REQUIRE(didCallbackFire());
341 fw::Strategy& strategy = getStrategyChoice().findEffectiveStrategy("/test");
342 BOOST_REQUIRE_EQUAL(strategy.getName(), "/localhost/nfd/strategy/test-strategy-b");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600343}
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700344
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600345BOOST_AUTO_TEST_CASE(SetStrategiesMissingName)
346{
347 ControlParameters parameters;
348 parameters.setStrategy("/localhost/nfd/strategy/test-strategy-b");
349
350 Block encodedParameters(parameters.wireEncode());
351
352 Name commandName("/localhost/nfd/strategy-choice");
353 commandName.append("set");
354 commandName.append(encodedParameters);
355
356 shared_ptr<Interest> command(make_shared<Interest>(commandName));
357
358 getFace()->onReceiveData +=
359 bind(&StrategyChoiceManagerFixture::validateControlResponse, this, _1,
360 command->getName(), 400, "Malformed command");
361
362 getManager().onValidatedStrategyChoiceRequest(command);
363
364 BOOST_REQUIRE(didCallbackFire());
365}
366
367BOOST_AUTO_TEST_CASE(SetStrategiesMissingStrategy)
368{
369 ControlParameters parameters;
370 parameters.setName("/test");
371
372 Block encodedParameters(parameters.wireEncode());
373
374 Name commandName("/localhost/nfd/strategy-choice");
375 commandName.append("set");
376 commandName.append(encodedParameters);
377
378 shared_ptr<Interest> command(make_shared<Interest>(commandName));
379
380 getFace()->onReceiveData +=
381 bind(&StrategyChoiceManagerFixture::validateControlResponse, this, _1,
382 command->getName(), 400, "Malformed command");
383
384 getManager().onValidatedStrategyChoiceRequest(command);
385
386 BOOST_REQUIRE(didCallbackFire());
387 fw::Strategy& strategy = getStrategyChoice().findEffectiveStrategy("/test");
388 BOOST_REQUIRE_EQUAL(strategy.getName(), "/localhost/nfd/strategy/test-strategy-a");
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700389}
390
391BOOST_AUTO_TEST_CASE(SetUnsupportedStrategy)
392{
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600393 ControlParameters parameters;
394 parameters.setName("/test");
395 parameters.setStrategy("/localhost/nfd/strategy/unit-test-doesnotexist");
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700396
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600397 Block encodedParameters(parameters.wireEncode());
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700398
399 Name commandName("/localhost/nfd/strategy-choice");
400 commandName.append("set");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600401 commandName.append(encodedParameters);
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700402
403 shared_ptr<Interest> command(make_shared<Interest>(commandName));
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700404 generateCommand(*command);
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700405
406 getFace()->onReceiveData +=
407 bind(&StrategyChoiceManagerFixture::validateControlResponse, this, _1,
408 command->getName(), 504, "Unsupported strategy");
409
410 getManager().onValidatedStrategyChoiceRequest(command);
411
412 BOOST_REQUIRE(didCallbackFire());
413 fw::Strategy& strategy = getStrategyChoice().findEffectiveStrategy("/test");
414 BOOST_CHECK_EQUAL(strategy.getName(), "/localhost/nfd/strategy/test-strategy-a");
415}
416
417class DefaultStrategyOnlyFixture : public StrategyChoiceManagerFixture
418{
419public:
420 DefaultStrategyOnlyFixture()
421 : StrategyChoiceManagerFixture()
422 {
423
424 }
425
426 virtual
427 ~DefaultStrategyOnlyFixture()
428 {
429
430 }
431};
432
433
434/// \todo I'm not sure this code branch (code 405) can happen. The manager tests for the strategy first and will return 504.
435// BOOST_FIXTURE_TEST_CASE(SetNotInstalled, DefaultStrategyOnlyFixture)
436// {
437// BOOST_REQUIRE(!getStrategyChoice().hasStrategy("/localhost/nfd/strategy/test-strategy-b"));
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600438// ControlParameters parameters;
439// parameters.setName("/test");
440// parameters.setStrategy("/localhost/nfd/strategy/test-strategy-b");
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700441
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600442// Block encodedParameters(parameters.wireEncode());
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700443
444// Name commandName("/localhost/nfd/strategy-choice");
445// commandName.append("set");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600446// commandName.append(encodedParameters);
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700447
448// shared_ptr<Interest> command(make_shared<Interest>(commandName));
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700449// generateCommand(*command);
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700450
451// getFace()->onReceiveData +=
452// bind(&StrategyChoiceManagerFixture::validateControlResponse, this, _1,
453// command->getName(), 405, "Strategy not installed");
454
455// getManager().onValidatedStrategyChoiceRequest(command);
456
457// BOOST_REQUIRE(didCallbackFire());
458// fw::Strategy& strategy = getStrategyChoice().findEffectiveStrategy("/test");
459// BOOST_CHECK_EQUAL(strategy.getName(), "/localhost/nfd/strategy/test-strategy-a");
460// }
461
462BOOST_AUTO_TEST_CASE(Unset)
463{
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600464 ControlParameters parameters;
465 parameters.setName("/test");
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700466
467 BOOST_REQUIRE(m_strategyChoice.insert("/test", "/localhost/nfd/strategy/test-strategy-b"));
468 BOOST_REQUIRE_EQUAL(m_strategyChoice.findEffectiveStrategy("/test").getName(),
469 "/localhost/nfd/strategy/test-strategy-b");
470
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600471 Block encodedParameters(parameters.wireEncode());
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700472
473 Name commandName("/localhost/nfd/strategy-choice");
474 commandName.append("unset");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600475 commandName.append(encodedParameters);
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700476
477 shared_ptr<Interest> command(make_shared<Interest>(commandName));
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700478 generateCommand(*command);
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700479
480 getFace()->onReceiveData +=
481 bind(&StrategyChoiceManagerFixture::validateControlResponse, this, _1,
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600482 command->getName(), 200, "Success", encodedParameters);
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700483
484 getManager().onValidatedStrategyChoiceRequest(command);
485
486 BOOST_REQUIRE(didCallbackFire());
487
488 BOOST_CHECK_EQUAL(m_strategyChoice.findEffectiveStrategy("/test").getName(),
489 "/localhost/nfd/strategy/test-strategy-a");
490}
491
492BOOST_AUTO_TEST_CASE(UnsetRoot)
493{
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600494 ControlParameters parameters;
495 parameters.setName("/");
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700496
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600497 Block encodedParameters(parameters.wireEncode());
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700498
499 Name commandName("/localhost/nfd/strategy-choice");
500 commandName.append("unset");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600501 commandName.append(encodedParameters);
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700502
503 shared_ptr<Interest> command(make_shared<Interest>(commandName));
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700504 generateCommand(*command);
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700505
506 getFace()->onReceiveData +=
507 bind(&StrategyChoiceManagerFixture::validateControlResponse, this, _1,
508 command->getName(), 403, "Cannot unset root prefix strategy");
509
510 getManager().onValidatedStrategyChoiceRequest(command);
511
512 BOOST_REQUIRE(didCallbackFire());
513
514 BOOST_CHECK_EQUAL(m_strategyChoice.findEffectiveStrategy("/test").getName(),
515 "/localhost/nfd/strategy/test-strategy-a");
516}
517
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600518BOOST_AUTO_TEST_CASE(UnsetMissingName)
519{
520 ControlParameters parameters;
521
522 BOOST_REQUIRE(m_strategyChoice.insert("/test", "/localhost/nfd/strategy/test-strategy-b"));
523 BOOST_REQUIRE_EQUAL(m_strategyChoice.findEffectiveStrategy("/test").getName(),
524 "/localhost/nfd/strategy/test-strategy-b");
525
526 Block encodedParameters(parameters.wireEncode());
527
528 Name commandName("/localhost/nfd/strategy-choice");
529 commandName.append("unset");
530 commandName.append(encodedParameters);
531
532 shared_ptr<Interest> command(make_shared<Interest>(commandName));
533 generateCommand(*command);
534
535 getFace()->onReceiveData +=
536 bind(&StrategyChoiceManagerFixture::validateControlResponse, this, _1,
537 command->getName(), 400, "Malformed command");
538
539 getManager().onValidatedStrategyChoiceRequest(command);
540
541 BOOST_REQUIRE(didCallbackFire());
542
543 BOOST_CHECK_EQUAL(m_strategyChoice.findEffectiveStrategy("/test").getName(),
544 "/localhost/nfd/strategy/test-strategy-b");
545}
546
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700547BOOST_AUTO_TEST_SUITE_END()
548
549} // namespace tests
550} // namespace nfd