blob: 99d5636a89bc4c0410547ecdcbb93aab8799a132 [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 {
Junxiao Shif3c07812014-03-11 21:48:49 -070053 m_strategyChoice.install(make_shared<DummyStrategy>(boost::ref(m_forwarder), "/localhost/nfd/strategy/test-strategy-a"));
54 m_strategyChoice.insert("ndn:/", "/localhost/nfd/strategy/test-strategy-a");
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -070055 }
56
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -070057 virtual
58 ~StrategyChoiceManagerFixture()
59 {
60
61 }
62
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -070063 void
64 validateControlResponseCommon(const Data& response,
65 const Name& expectedName,
66 uint32_t expectedCode,
67 const std::string& expectedText,
68 ControlResponse& control)
69 {
70 m_callbackFired = true;
71 Block controlRaw = response.getContent().blockFromValue();
72
73 control.wireDecode(controlRaw);
74
75 NFD_LOG_DEBUG("received control response"
76 << " Name: " << response.getName()
77 << " code: " << control.getCode()
78 << " text: " << control.getText());
79
80 BOOST_CHECK_EQUAL(response.getName(), expectedName);
81 BOOST_CHECK_EQUAL(control.getCode(), expectedCode);
82 BOOST_CHECK_EQUAL(control.getText(), expectedText);
83 }
84
85 void
86 validateControlResponse(const Data& response,
87 const Name& expectedName,
88 uint32_t expectedCode,
89 const std::string& expectedText)
90 {
91 ControlResponse control;
92 validateControlResponseCommon(response, expectedName,
93 expectedCode, expectedText, control);
94
95 if (!control.getBody().empty())
96 {
97 BOOST_FAIL("found unexpected control response body");
98 }
99 }
100
101 void
102 validateControlResponse(const Data& response,
103 const Name& expectedName,
104 uint32_t expectedCode,
105 const std::string& expectedText,
106 const Block& expectedBody)
107 {
108 ControlResponse control;
109 validateControlResponseCommon(response, expectedName,
110 expectedCode, expectedText, control);
111
112 BOOST_REQUIRE(!control.getBody().empty());
113 BOOST_REQUIRE(control.getBody().value_size() == expectedBody.value_size());
114
115 BOOST_CHECK(memcmp(control.getBody().value(), expectedBody.value(),
116 expectedBody.value_size()) == 0);
117
118 }
119
120 bool
121 didCallbackFire()
122 {
123 return m_callbackFired;
124 }
125
126 void
127 resetCallbackFired()
128 {
129 m_callbackFired = false;
130 }
131
132 shared_ptr<InternalFace>&
133 getFace()
134 {
135 return m_face;
136 }
137
138 StrategyChoiceManager&
139 getManager()
140 {
141 return m_manager;
142 }
143
144 StrategyChoice&
145 getStrategyChoice()
146 {
147 return m_strategyChoice;
148 }
149
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700150 void
151 addInterestRule(const std::string& regex,
152 ndn::IdentityCertificate& certificate)
153 {
154 m_manager.addInterestRule(regex, certificate);
155 }
156
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700157protected:
158 Forwarder m_forwarder;
Junxiao Shif3c07812014-03-11 21:48:49 -0700159 StrategyChoice& m_strategyChoice;
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700160 shared_ptr<InternalFace> m_face;
161 StrategyChoiceManager m_manager;
162
163private:
164 bool m_callbackFired;
165};
166
167class AllStrategiesFixture : public StrategyChoiceManagerFixture
168{
169public:
170 AllStrategiesFixture()
171 {
Junxiao Shif3c07812014-03-11 21:48:49 -0700172 m_strategyChoice.install(make_shared<DummyStrategy>(boost::ref(m_forwarder), "/localhost/nfd/strategy/test-strategy-b"));
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700173 }
174
175 virtual
176 ~AllStrategiesFixture()
177 {
178
179 }
180};
181
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700182template <typename T> class AuthorizedCommandFixture : public CommandFixture<T>
183{
184public:
185 AuthorizedCommandFixture()
186 {
187 const std::string regex = "^<localhost><nfd><strategy-choice>";
188 T::addInterestRule(regex, *CommandFixture<T>::m_certificate);
189 }
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700190
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700191 virtual
192 ~AuthorizedCommandFixture()
193 {
194
195 }
196};
197
198BOOST_FIXTURE_TEST_SUITE(MgmtStrategyChoiceManager,
199 AuthorizedCommandFixture<AllStrategiesFixture>)
200
201BOOST_FIXTURE_TEST_CASE(TestFireInterestFilter, AllStrategiesFixture)
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700202{
203 shared_ptr<Interest> command(make_shared<Interest>("/localhost/nfd/strategy-choice"));
204
205 getFace()->onReceiveData +=
206 bind(&StrategyChoiceManagerFixture::validateControlResponse, this, _1,
207 command->getName(), 400, "Malformed command");
208
209 getFace()->sendInterest(*command);
Junxiao Shi16d1b7d2014-03-27 21:29:09 -0700210 g_io.run_one();
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700211
212 BOOST_REQUIRE(didCallbackFire());
213}
214
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700215BOOST_FIXTURE_TEST_CASE(MalformedCommmand, AllStrategiesFixture)
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700216{
217 shared_ptr<Interest> command(make_shared<Interest>("/localhost/nfd/strategy-choice"));
218
219 getFace()->onReceiveData +=
220 bind(&StrategyChoiceManagerFixture::validateControlResponse, this, _1,
221 command->getName(), 400, "Malformed command");
222
223 getManager().onStrategyChoiceRequest(*command);
224
225 BOOST_REQUIRE(didCallbackFire());
226}
227
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700228BOOST_FIXTURE_TEST_CASE(UnsignedCommand, AllStrategiesFixture)
229{
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600230 ControlParameters parameters;
231 parameters.setName("/test");
232 parameters.setStrategy("/localhost/nfd/strategy/best-route");
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700233
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600234 Block encodedParameters(parameters.wireEncode());
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700235
236 Name commandName("/localhost/nfd/strategy-choice");
237 commandName.append("set");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600238 commandName.append(encodedParameters);
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700239
240 shared_ptr<Interest> command(make_shared<Interest>(commandName));
241
242 getFace()->onReceiveData +=
243 bind(&StrategyChoiceManagerFixture::validateControlResponse, this, _1,
244 command->getName(), 401, "Signature required");
245
246 getManager().onStrategyChoiceRequest(*command);
247
248 BOOST_REQUIRE(didCallbackFire());
249}
250
251BOOST_FIXTURE_TEST_CASE(UnauthorizedCommand,
252 UnauthorizedCommandFixture<StrategyChoiceManagerFixture>)
253{
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600254 ControlParameters parameters;
255 parameters.setName("/test");
256 parameters.setStrategy("/localhost/nfd/strategy/best-route");
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700257
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600258 Block encodedParameters(parameters.wireEncode());
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700259
260 Name commandName("/localhost/nfd/strategy-choice");
261 commandName.append("set");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600262 commandName.append(encodedParameters);
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700263
264 shared_ptr<Interest> command(make_shared<Interest>(commandName));
265 generateCommand(*command);
266
267 getFace()->onReceiveData +=
268 bind(&StrategyChoiceManagerFixture::validateControlResponse, this, _1,
269 command->getName(), 403, "Unauthorized command");
270
271 getManager().onStrategyChoiceRequest(*command);
272
273 BOOST_REQUIRE(didCallbackFire());
274}
275
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700276BOOST_AUTO_TEST_CASE(UnsupportedVerb)
277{
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600278 ControlParameters parameters;
279 parameters.setName("/test");
280 parameters.setStrategy("/localhost/nfd/strategy/test-strategy-b");
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700281
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600282 Block encodedParameters(parameters.wireEncode());
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700283
284 Name commandName("/localhost/nfd/strategy-choice");
285 commandName.append("unsupported");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600286 commandName.append(encodedParameters);
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700287
288 shared_ptr<Interest> command(make_shared<Interest>(commandName));
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700289 generateCommand(*command);
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700290
291 getFace()->onReceiveData +=
292 bind(&StrategyChoiceManagerFixture::validateControlResponse, this, _1,
293 command->getName(), 501, "Unsupported command");
294
295 getManager().onValidatedStrategyChoiceRequest(command);
296
297 BOOST_REQUIRE(didCallbackFire());
298}
299
300BOOST_AUTO_TEST_CASE(BadOptionParse)
301{
302 Name commandName("/localhost/nfd/strategy-choice");
303 commandName.append("set");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600304 commandName.append("NotReallyParameters");
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700305
306 shared_ptr<Interest> command(make_shared<Interest>(commandName));
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700307 generateCommand(*command);
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700308
309 getFace()->onReceiveData +=
310 bind(&StrategyChoiceManagerFixture::validateControlResponse, this, _1,
311 command->getName(), 400, "Malformed command");
312
313 getManager().onValidatedStrategyChoiceRequest(command);
314
315 BOOST_REQUIRE(didCallbackFire());
316}
317
318BOOST_AUTO_TEST_CASE(SetStrategies)
319{
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600320 ControlParameters parameters;
321 parameters.setName("/test");
322 parameters.setStrategy("/localhost/nfd/strategy/test-strategy-b");
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700323
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600324 Block encodedParameters(parameters.wireEncode());
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700325
326 Name commandName("/localhost/nfd/strategy-choice");
327 commandName.append("set");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600328 commandName.append(encodedParameters);
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700329
330 shared_ptr<Interest> command(make_shared<Interest>(commandName));
331
332 getFace()->onReceiveData +=
333 bind(&StrategyChoiceManagerFixture::validateControlResponse, this, _1,
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600334 command->getName(), 200, "Success", encodedParameters);
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700335
336 getManager().onValidatedStrategyChoiceRequest(command);
337
338 BOOST_REQUIRE(didCallbackFire());
339 fw::Strategy& strategy = getStrategyChoice().findEffectiveStrategy("/test");
340 BOOST_REQUIRE_EQUAL(strategy.getName(), "/localhost/nfd/strategy/test-strategy-b");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600341}
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700342
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600343BOOST_AUTO_TEST_CASE(SetStrategiesMissingName)
344{
345 ControlParameters parameters;
346 parameters.setStrategy("/localhost/nfd/strategy/test-strategy-b");
347
348 Block encodedParameters(parameters.wireEncode());
349
350 Name commandName("/localhost/nfd/strategy-choice");
351 commandName.append("set");
352 commandName.append(encodedParameters);
353
354 shared_ptr<Interest> command(make_shared<Interest>(commandName));
355
356 getFace()->onReceiveData +=
357 bind(&StrategyChoiceManagerFixture::validateControlResponse, this, _1,
358 command->getName(), 400, "Malformed command");
359
360 getManager().onValidatedStrategyChoiceRequest(command);
361
362 BOOST_REQUIRE(didCallbackFire());
363}
364
365BOOST_AUTO_TEST_CASE(SetStrategiesMissingStrategy)
366{
367 ControlParameters parameters;
368 parameters.setName("/test");
369
370 Block encodedParameters(parameters.wireEncode());
371
372 Name commandName("/localhost/nfd/strategy-choice");
373 commandName.append("set");
374 commandName.append(encodedParameters);
375
376 shared_ptr<Interest> command(make_shared<Interest>(commandName));
377
378 getFace()->onReceiveData +=
379 bind(&StrategyChoiceManagerFixture::validateControlResponse, this, _1,
380 command->getName(), 400, "Malformed command");
381
382 getManager().onValidatedStrategyChoiceRequest(command);
383
384 BOOST_REQUIRE(didCallbackFire());
385 fw::Strategy& strategy = getStrategyChoice().findEffectiveStrategy("/test");
386 BOOST_REQUIRE_EQUAL(strategy.getName(), "/localhost/nfd/strategy/test-strategy-a");
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700387}
388
389BOOST_AUTO_TEST_CASE(SetUnsupportedStrategy)
390{
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600391 ControlParameters parameters;
392 parameters.setName("/test");
393 parameters.setStrategy("/localhost/nfd/strategy/unit-test-doesnotexist");
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700394
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600395 Block encodedParameters(parameters.wireEncode());
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700396
397 Name commandName("/localhost/nfd/strategy-choice");
398 commandName.append("set");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600399 commandName.append(encodedParameters);
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700400
401 shared_ptr<Interest> command(make_shared<Interest>(commandName));
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700402 generateCommand(*command);
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700403
404 getFace()->onReceiveData +=
405 bind(&StrategyChoiceManagerFixture::validateControlResponse, this, _1,
406 command->getName(), 504, "Unsupported strategy");
407
408 getManager().onValidatedStrategyChoiceRequest(command);
409
410 BOOST_REQUIRE(didCallbackFire());
411 fw::Strategy& strategy = getStrategyChoice().findEffectiveStrategy("/test");
412 BOOST_CHECK_EQUAL(strategy.getName(), "/localhost/nfd/strategy/test-strategy-a");
413}
414
415class DefaultStrategyOnlyFixture : public StrategyChoiceManagerFixture
416{
417public:
418 DefaultStrategyOnlyFixture()
419 : StrategyChoiceManagerFixture()
420 {
421
422 }
423
424 virtual
425 ~DefaultStrategyOnlyFixture()
426 {
427
428 }
429};
430
431
432/// \todo I'm not sure this code branch (code 405) can happen. The manager tests for the strategy first and will return 504.
433// BOOST_FIXTURE_TEST_CASE(SetNotInstalled, DefaultStrategyOnlyFixture)
434// {
435// BOOST_REQUIRE(!getStrategyChoice().hasStrategy("/localhost/nfd/strategy/test-strategy-b"));
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600436// ControlParameters parameters;
437// parameters.setName("/test");
438// parameters.setStrategy("/localhost/nfd/strategy/test-strategy-b");
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700439
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600440// Block encodedParameters(parameters.wireEncode());
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700441
442// Name commandName("/localhost/nfd/strategy-choice");
443// commandName.append("set");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600444// commandName.append(encodedParameters);
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700445
446// shared_ptr<Interest> command(make_shared<Interest>(commandName));
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700447// generateCommand(*command);
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700448
449// getFace()->onReceiveData +=
450// bind(&StrategyChoiceManagerFixture::validateControlResponse, this, _1,
451// command->getName(), 405, "Strategy not installed");
452
453// getManager().onValidatedStrategyChoiceRequest(command);
454
455// BOOST_REQUIRE(didCallbackFire());
456// fw::Strategy& strategy = getStrategyChoice().findEffectiveStrategy("/test");
457// BOOST_CHECK_EQUAL(strategy.getName(), "/localhost/nfd/strategy/test-strategy-a");
458// }
459
460BOOST_AUTO_TEST_CASE(Unset)
461{
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600462 ControlParameters parameters;
463 parameters.setName("/test");
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700464
465 BOOST_REQUIRE(m_strategyChoice.insert("/test", "/localhost/nfd/strategy/test-strategy-b"));
466 BOOST_REQUIRE_EQUAL(m_strategyChoice.findEffectiveStrategy("/test").getName(),
467 "/localhost/nfd/strategy/test-strategy-b");
468
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600469 Block encodedParameters(parameters.wireEncode());
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700470
471 Name commandName("/localhost/nfd/strategy-choice");
472 commandName.append("unset");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600473 commandName.append(encodedParameters);
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700474
475 shared_ptr<Interest> command(make_shared<Interest>(commandName));
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700476 generateCommand(*command);
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700477
478 getFace()->onReceiveData +=
479 bind(&StrategyChoiceManagerFixture::validateControlResponse, this, _1,
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600480 command->getName(), 200, "Success", encodedParameters);
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700481
482 getManager().onValidatedStrategyChoiceRequest(command);
483
484 BOOST_REQUIRE(didCallbackFire());
485
486 BOOST_CHECK_EQUAL(m_strategyChoice.findEffectiveStrategy("/test").getName(),
487 "/localhost/nfd/strategy/test-strategy-a");
488}
489
490BOOST_AUTO_TEST_CASE(UnsetRoot)
491{
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600492 ControlParameters parameters;
493 parameters.setName("/");
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700494
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600495 Block encodedParameters(parameters.wireEncode());
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700496
497 Name commandName("/localhost/nfd/strategy-choice");
498 commandName.append("unset");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600499 commandName.append(encodedParameters);
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700500
501 shared_ptr<Interest> command(make_shared<Interest>(commandName));
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700502 generateCommand(*command);
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700503
504 getFace()->onReceiveData +=
505 bind(&StrategyChoiceManagerFixture::validateControlResponse, this, _1,
506 command->getName(), 403, "Cannot unset root prefix strategy");
507
508 getManager().onValidatedStrategyChoiceRequest(command);
509
510 BOOST_REQUIRE(didCallbackFire());
511
512 BOOST_CHECK_EQUAL(m_strategyChoice.findEffectiveStrategy("/test").getName(),
513 "/localhost/nfd/strategy/test-strategy-a");
514}
515
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600516BOOST_AUTO_TEST_CASE(UnsetMissingName)
517{
518 ControlParameters parameters;
519
520 BOOST_REQUIRE(m_strategyChoice.insert("/test", "/localhost/nfd/strategy/test-strategy-b"));
521 BOOST_REQUIRE_EQUAL(m_strategyChoice.findEffectiveStrategy("/test").getName(),
522 "/localhost/nfd/strategy/test-strategy-b");
523
524 Block encodedParameters(parameters.wireEncode());
525
526 Name commandName("/localhost/nfd/strategy-choice");
527 commandName.append("unset");
528 commandName.append(encodedParameters);
529
530 shared_ptr<Interest> command(make_shared<Interest>(commandName));
531 generateCommand(*command);
532
533 getFace()->onReceiveData +=
534 bind(&StrategyChoiceManagerFixture::validateControlResponse, this, _1,
535 command->getName(), 400, "Malformed command");
536
537 getManager().onValidatedStrategyChoiceRequest(command);
538
539 BOOST_REQUIRE(didCallbackFire());
540
541 BOOST_CHECK_EQUAL(m_strategyChoice.findEffectiveStrategy("/test").getName(),
542 "/localhost/nfd/strategy/test-strategy-b");
543}
544
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700545BOOST_AUTO_TEST_SUITE_END()
546
547} // namespace tests
548} // namespace nfd