blob: 9f6818e5529ca3fb2887532322b57ba1bb9fb6e6 [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
Steve DiBenedetto3fff5612014-05-30 15:52:56 -060035#include <ndn-cxx/management/nfd-strategy-choice.hpp>
36
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -070037#include "tests/test-common.hpp"
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -070038#include "validation-common.hpp"
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -070039
40namespace nfd {
41namespace tests {
42
43NFD_LOG_INIT("StrategyChoiceManagerTest");
44
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -070045class StrategyChoiceManagerFixture : protected BaseFixture
46{
47public:
48
49 StrategyChoiceManagerFixture()
Junxiao Shif3c07812014-03-11 21:48:49 -070050 : m_strategyChoice(m_forwarder.getStrategyChoice())
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -070051 , m_face(make_shared<InternalFace>())
52 , m_manager(m_strategyChoice, m_face)
53 , m_callbackFired(false)
54 {
Alexander Afanasyevf6980282014-05-13 18:28:40 -070055 m_strategyChoice.install(make_shared<DummyStrategy>(ref(m_forwarder),
56 "/localhost/nfd/strategy/test-strategy-a"));
Junxiao Shif3c07812014-03-11 21:48:49 -070057 m_strategyChoice.insert("ndn:/", "/localhost/nfd/strategy/test-strategy-a");
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -070058 }
59
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -070060 virtual
61 ~StrategyChoiceManagerFixture()
62 {
63
64 }
65
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -070066 void
67 validateControlResponseCommon(const Data& response,
68 const Name& expectedName,
69 uint32_t expectedCode,
70 const std::string& expectedText,
71 ControlResponse& control)
72 {
73 m_callbackFired = true;
74 Block controlRaw = response.getContent().blockFromValue();
75
76 control.wireDecode(controlRaw);
77
78 NFD_LOG_DEBUG("received control response"
79 << " Name: " << response.getName()
80 << " code: " << control.getCode()
81 << " text: " << control.getText());
82
83 BOOST_CHECK_EQUAL(response.getName(), expectedName);
84 BOOST_CHECK_EQUAL(control.getCode(), expectedCode);
85 BOOST_CHECK_EQUAL(control.getText(), expectedText);
86 }
87
88 void
89 validateControlResponse(const Data& response,
90 const Name& expectedName,
91 uint32_t expectedCode,
92 const std::string& expectedText)
93 {
94 ControlResponse control;
95 validateControlResponseCommon(response, expectedName,
96 expectedCode, expectedText, control);
97
98 if (!control.getBody().empty())
99 {
100 BOOST_FAIL("found unexpected control response body");
101 }
102 }
103
104 void
105 validateControlResponse(const Data& response,
106 const Name& expectedName,
107 uint32_t expectedCode,
108 const std::string& expectedText,
109 const Block& expectedBody)
110 {
111 ControlResponse control;
112 validateControlResponseCommon(response, expectedName,
113 expectedCode, expectedText, control);
114
115 BOOST_REQUIRE(!control.getBody().empty());
116 BOOST_REQUIRE(control.getBody().value_size() == expectedBody.value_size());
117
118 BOOST_CHECK(memcmp(control.getBody().value(), expectedBody.value(),
119 expectedBody.value_size()) == 0);
120
121 }
122
Steve DiBenedetto3fff5612014-05-30 15:52:56 -0600123 void
124 validateList(const Data& data, const ndn::nfd::StrategyChoice& expectedChoice)
125 {
126 m_callbackFired = true;
127 ndn::nfd::StrategyChoice choice(data.getContent().blockFromValue());
128 BOOST_CHECK_EQUAL(choice.getStrategy(), expectedChoice.getStrategy());
129 BOOST_CHECK_EQUAL(choice.getName(), expectedChoice.getName());
130 }
131
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700132 bool
133 didCallbackFire()
134 {
135 return m_callbackFired;
136 }
137
138 void
139 resetCallbackFired()
140 {
141 m_callbackFired = false;
142 }
143
144 shared_ptr<InternalFace>&
145 getFace()
146 {
147 return m_face;
148 }
149
150 StrategyChoiceManager&
151 getManager()
152 {
153 return m_manager;
154 }
155
156 StrategyChoice&
157 getStrategyChoice()
158 {
159 return m_strategyChoice;
160 }
161
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700162 void
163 addInterestRule(const std::string& regex,
164 ndn::IdentityCertificate& certificate)
165 {
166 m_manager.addInterestRule(regex, certificate);
167 }
168
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700169protected:
170 Forwarder m_forwarder;
Junxiao Shif3c07812014-03-11 21:48:49 -0700171 StrategyChoice& m_strategyChoice;
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700172 shared_ptr<InternalFace> m_face;
173 StrategyChoiceManager m_manager;
174
175private:
176 bool m_callbackFired;
177};
178
179class AllStrategiesFixture : public StrategyChoiceManagerFixture
180{
181public:
182 AllStrategiesFixture()
183 {
Alexander Afanasyevf6980282014-05-13 18:28:40 -0700184 m_strategyChoice.install(make_shared<DummyStrategy>(ref(m_forwarder),
185 "/localhost/nfd/strategy/test-strategy-b"));
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700186 }
187
188 virtual
189 ~AllStrategiesFixture()
190 {
191
192 }
193};
194
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700195template <typename T> class AuthorizedCommandFixture : public CommandFixture<T>
196{
197public:
198 AuthorizedCommandFixture()
199 {
200 const std::string regex = "^<localhost><nfd><strategy-choice>";
201 T::addInterestRule(regex, *CommandFixture<T>::m_certificate);
202 }
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700203
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700204 virtual
205 ~AuthorizedCommandFixture()
206 {
207
208 }
209};
210
211BOOST_FIXTURE_TEST_SUITE(MgmtStrategyChoiceManager,
212 AuthorizedCommandFixture<AllStrategiesFixture>)
213
214BOOST_FIXTURE_TEST_CASE(TestFireInterestFilter, AllStrategiesFixture)
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700215{
216 shared_ptr<Interest> command(make_shared<Interest>("/localhost/nfd/strategy-choice"));
217
218 getFace()->onReceiveData +=
219 bind(&StrategyChoiceManagerFixture::validateControlResponse, this, _1,
220 command->getName(), 400, "Malformed command");
221
222 getFace()->sendInterest(*command);
Junxiao Shi16d1b7d2014-03-27 21:29:09 -0700223 g_io.run_one();
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700224
225 BOOST_REQUIRE(didCallbackFire());
226}
227
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700228BOOST_FIXTURE_TEST_CASE(MalformedCommmand, AllStrategiesFixture)
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700229{
230 shared_ptr<Interest> command(make_shared<Interest>("/localhost/nfd/strategy-choice"));
231
232 getFace()->onReceiveData +=
233 bind(&StrategyChoiceManagerFixture::validateControlResponse, this, _1,
234 command->getName(), 400, "Malformed command");
235
236 getManager().onStrategyChoiceRequest(*command);
237
238 BOOST_REQUIRE(didCallbackFire());
239}
240
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700241BOOST_FIXTURE_TEST_CASE(UnsignedCommand, AllStrategiesFixture)
242{
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600243 ControlParameters parameters;
244 parameters.setName("/test");
245 parameters.setStrategy("/localhost/nfd/strategy/best-route");
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700246
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600247 Block encodedParameters(parameters.wireEncode());
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700248
249 Name commandName("/localhost/nfd/strategy-choice");
250 commandName.append("set");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600251 commandName.append(encodedParameters);
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700252
253 shared_ptr<Interest> command(make_shared<Interest>(commandName));
254
255 getFace()->onReceiveData +=
256 bind(&StrategyChoiceManagerFixture::validateControlResponse, this, _1,
257 command->getName(), 401, "Signature required");
258
259 getManager().onStrategyChoiceRequest(*command);
260
261 BOOST_REQUIRE(didCallbackFire());
262}
263
264BOOST_FIXTURE_TEST_CASE(UnauthorizedCommand,
265 UnauthorizedCommandFixture<StrategyChoiceManagerFixture>)
266{
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600267 ControlParameters parameters;
268 parameters.setName("/test");
269 parameters.setStrategy("/localhost/nfd/strategy/best-route");
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700270
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600271 Block encodedParameters(parameters.wireEncode());
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700272
273 Name commandName("/localhost/nfd/strategy-choice");
274 commandName.append("set");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600275 commandName.append(encodedParameters);
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700276
277 shared_ptr<Interest> command(make_shared<Interest>(commandName));
278 generateCommand(*command);
279
280 getFace()->onReceiveData +=
281 bind(&StrategyChoiceManagerFixture::validateControlResponse, this, _1,
282 command->getName(), 403, "Unauthorized command");
283
284 getManager().onStrategyChoiceRequest(*command);
285
286 BOOST_REQUIRE(didCallbackFire());
287}
288
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700289BOOST_AUTO_TEST_CASE(UnsupportedVerb)
290{
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600291 ControlParameters parameters;
292 parameters.setName("/test");
293 parameters.setStrategy("/localhost/nfd/strategy/test-strategy-b");
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700294
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600295 Block encodedParameters(parameters.wireEncode());
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700296
297 Name commandName("/localhost/nfd/strategy-choice");
298 commandName.append("unsupported");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600299 commandName.append(encodedParameters);
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700300
301 shared_ptr<Interest> command(make_shared<Interest>(commandName));
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700302 generateCommand(*command);
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700303
304 getFace()->onReceiveData +=
305 bind(&StrategyChoiceManagerFixture::validateControlResponse, this, _1,
306 command->getName(), 501, "Unsupported command");
307
308 getManager().onValidatedStrategyChoiceRequest(command);
309
310 BOOST_REQUIRE(didCallbackFire());
311}
312
313BOOST_AUTO_TEST_CASE(BadOptionParse)
314{
315 Name commandName("/localhost/nfd/strategy-choice");
316 commandName.append("set");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600317 commandName.append("NotReallyParameters");
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700318
319 shared_ptr<Interest> command(make_shared<Interest>(commandName));
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700320 generateCommand(*command);
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700321
322 getFace()->onReceiveData +=
323 bind(&StrategyChoiceManagerFixture::validateControlResponse, this, _1,
324 command->getName(), 400, "Malformed command");
325
326 getManager().onValidatedStrategyChoiceRequest(command);
327
328 BOOST_REQUIRE(didCallbackFire());
329}
330
331BOOST_AUTO_TEST_CASE(SetStrategies)
332{
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600333 ControlParameters parameters;
334 parameters.setName("/test");
335 parameters.setStrategy("/localhost/nfd/strategy/test-strategy-b");
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700336
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600337 Block encodedParameters(parameters.wireEncode());
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700338
339 Name commandName("/localhost/nfd/strategy-choice");
340 commandName.append("set");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600341 commandName.append(encodedParameters);
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700342
343 shared_ptr<Interest> command(make_shared<Interest>(commandName));
344
345 getFace()->onReceiveData +=
346 bind(&StrategyChoiceManagerFixture::validateControlResponse, this, _1,
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600347 command->getName(), 200, "Success", encodedParameters);
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700348
349 getManager().onValidatedStrategyChoiceRequest(command);
350
351 BOOST_REQUIRE(didCallbackFire());
352 fw::Strategy& strategy = getStrategyChoice().findEffectiveStrategy("/test");
353 BOOST_REQUIRE_EQUAL(strategy.getName(), "/localhost/nfd/strategy/test-strategy-b");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600354}
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700355
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600356BOOST_AUTO_TEST_CASE(SetStrategiesMissingName)
357{
358 ControlParameters parameters;
359 parameters.setStrategy("/localhost/nfd/strategy/test-strategy-b");
360
361 Block encodedParameters(parameters.wireEncode());
362
363 Name commandName("/localhost/nfd/strategy-choice");
364 commandName.append("set");
365 commandName.append(encodedParameters);
366
367 shared_ptr<Interest> command(make_shared<Interest>(commandName));
368
369 getFace()->onReceiveData +=
370 bind(&StrategyChoiceManagerFixture::validateControlResponse, this, _1,
371 command->getName(), 400, "Malformed command");
372
373 getManager().onValidatedStrategyChoiceRequest(command);
374
375 BOOST_REQUIRE(didCallbackFire());
376}
377
378BOOST_AUTO_TEST_CASE(SetStrategiesMissingStrategy)
379{
380 ControlParameters parameters;
381 parameters.setName("/test");
382
383 Block encodedParameters(parameters.wireEncode());
384
385 Name commandName("/localhost/nfd/strategy-choice");
386 commandName.append("set");
387 commandName.append(encodedParameters);
388
389 shared_ptr<Interest> command(make_shared<Interest>(commandName));
390
391 getFace()->onReceiveData +=
392 bind(&StrategyChoiceManagerFixture::validateControlResponse, this, _1,
393 command->getName(), 400, "Malformed command");
394
395 getManager().onValidatedStrategyChoiceRequest(command);
396
397 BOOST_REQUIRE(didCallbackFire());
398 fw::Strategy& strategy = getStrategyChoice().findEffectiveStrategy("/test");
399 BOOST_REQUIRE_EQUAL(strategy.getName(), "/localhost/nfd/strategy/test-strategy-a");
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700400}
401
402BOOST_AUTO_TEST_CASE(SetUnsupportedStrategy)
403{
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600404 ControlParameters parameters;
405 parameters.setName("/test");
406 parameters.setStrategy("/localhost/nfd/strategy/unit-test-doesnotexist");
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700407
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600408 Block encodedParameters(parameters.wireEncode());
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700409
410 Name commandName("/localhost/nfd/strategy-choice");
411 commandName.append("set");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600412 commandName.append(encodedParameters);
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700413
414 shared_ptr<Interest> command(make_shared<Interest>(commandName));
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700415 generateCommand(*command);
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700416
417 getFace()->onReceiveData +=
418 bind(&StrategyChoiceManagerFixture::validateControlResponse, this, _1,
419 command->getName(), 504, "Unsupported strategy");
420
421 getManager().onValidatedStrategyChoiceRequest(command);
422
423 BOOST_REQUIRE(didCallbackFire());
424 fw::Strategy& strategy = getStrategyChoice().findEffectiveStrategy("/test");
425 BOOST_CHECK_EQUAL(strategy.getName(), "/localhost/nfd/strategy/test-strategy-a");
426}
427
428class DefaultStrategyOnlyFixture : public StrategyChoiceManagerFixture
429{
430public:
431 DefaultStrategyOnlyFixture()
432 : StrategyChoiceManagerFixture()
433 {
434
435 }
436
437 virtual
438 ~DefaultStrategyOnlyFixture()
439 {
440
441 }
442};
443
444
445/// \todo I'm not sure this code branch (code 405) can happen. The manager tests for the strategy first and will return 504.
446// BOOST_FIXTURE_TEST_CASE(SetNotInstalled, DefaultStrategyOnlyFixture)
447// {
448// BOOST_REQUIRE(!getStrategyChoice().hasStrategy("/localhost/nfd/strategy/test-strategy-b"));
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600449// ControlParameters parameters;
450// parameters.setName("/test");
451// parameters.setStrategy("/localhost/nfd/strategy/test-strategy-b");
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700452
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600453// Block encodedParameters(parameters.wireEncode());
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700454
455// Name commandName("/localhost/nfd/strategy-choice");
456// commandName.append("set");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600457// commandName.append(encodedParameters);
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700458
459// shared_ptr<Interest> command(make_shared<Interest>(commandName));
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700460// generateCommand(*command);
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700461
462// getFace()->onReceiveData +=
463// bind(&StrategyChoiceManagerFixture::validateControlResponse, this, _1,
464// command->getName(), 405, "Strategy not installed");
465
466// getManager().onValidatedStrategyChoiceRequest(command);
467
468// BOOST_REQUIRE(didCallbackFire());
469// fw::Strategy& strategy = getStrategyChoice().findEffectiveStrategy("/test");
470// BOOST_CHECK_EQUAL(strategy.getName(), "/localhost/nfd/strategy/test-strategy-a");
471// }
472
473BOOST_AUTO_TEST_CASE(Unset)
474{
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600475 ControlParameters parameters;
476 parameters.setName("/test");
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700477
478 BOOST_REQUIRE(m_strategyChoice.insert("/test", "/localhost/nfd/strategy/test-strategy-b"));
479 BOOST_REQUIRE_EQUAL(m_strategyChoice.findEffectiveStrategy("/test").getName(),
480 "/localhost/nfd/strategy/test-strategy-b");
481
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600482 Block encodedParameters(parameters.wireEncode());
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700483
484 Name commandName("/localhost/nfd/strategy-choice");
485 commandName.append("unset");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600486 commandName.append(encodedParameters);
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700487
488 shared_ptr<Interest> command(make_shared<Interest>(commandName));
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700489 generateCommand(*command);
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700490
491 getFace()->onReceiveData +=
492 bind(&StrategyChoiceManagerFixture::validateControlResponse, this, _1,
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600493 command->getName(), 200, "Success", encodedParameters);
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700494
495 getManager().onValidatedStrategyChoiceRequest(command);
496
497 BOOST_REQUIRE(didCallbackFire());
498
499 BOOST_CHECK_EQUAL(m_strategyChoice.findEffectiveStrategy("/test").getName(),
500 "/localhost/nfd/strategy/test-strategy-a");
501}
502
503BOOST_AUTO_TEST_CASE(UnsetRoot)
504{
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600505 ControlParameters parameters;
506 parameters.setName("/");
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700507
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600508 Block encodedParameters(parameters.wireEncode());
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700509
510 Name commandName("/localhost/nfd/strategy-choice");
511 commandName.append("unset");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600512 commandName.append(encodedParameters);
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700513
514 shared_ptr<Interest> command(make_shared<Interest>(commandName));
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700515 generateCommand(*command);
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700516
517 getFace()->onReceiveData +=
518 bind(&StrategyChoiceManagerFixture::validateControlResponse, this, _1,
519 command->getName(), 403, "Cannot unset root prefix strategy");
520
521 getManager().onValidatedStrategyChoiceRequest(command);
522
523 BOOST_REQUIRE(didCallbackFire());
524
525 BOOST_CHECK_EQUAL(m_strategyChoice.findEffectiveStrategy("/test").getName(),
526 "/localhost/nfd/strategy/test-strategy-a");
527}
528
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600529BOOST_AUTO_TEST_CASE(UnsetMissingName)
530{
531 ControlParameters parameters;
532
533 BOOST_REQUIRE(m_strategyChoice.insert("/test", "/localhost/nfd/strategy/test-strategy-b"));
534 BOOST_REQUIRE_EQUAL(m_strategyChoice.findEffectiveStrategy("/test").getName(),
535 "/localhost/nfd/strategy/test-strategy-b");
536
537 Block encodedParameters(parameters.wireEncode());
538
539 Name commandName("/localhost/nfd/strategy-choice");
540 commandName.append("unset");
541 commandName.append(encodedParameters);
542
543 shared_ptr<Interest> command(make_shared<Interest>(commandName));
544 generateCommand(*command);
545
546 getFace()->onReceiveData +=
547 bind(&StrategyChoiceManagerFixture::validateControlResponse, this, _1,
548 command->getName(), 400, "Malformed command");
549
550 getManager().onValidatedStrategyChoiceRequest(command);
551
552 BOOST_REQUIRE(didCallbackFire());
553
554 BOOST_CHECK_EQUAL(m_strategyChoice.findEffectiveStrategy("/test").getName(),
555 "/localhost/nfd/strategy/test-strategy-b");
556}
557
Steve DiBenedetto3fff5612014-05-30 15:52:56 -0600558BOOST_AUTO_TEST_CASE(Publish)
559{
560 Name commandName("/localhost/nfd/strategy-choice/list");
561 shared_ptr<Interest> command(make_shared<Interest>(commandName));
562
563 ndn::nfd::StrategyChoice expectedChoice;
564 expectedChoice.setStrategy("/localhost/nfd/strategy/test-strategy-a");
565 expectedChoice.setName("/");
566
567 getFace()->onReceiveData +=
568 bind(&StrategyChoiceManagerFixture::validateList, this, _1, expectedChoice);
569
570 m_manager.onStrategyChoiceRequest(*command);
571 BOOST_REQUIRE(didCallbackFire());
572}
573
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700574BOOST_AUTO_TEST_SUITE_END()
575
576} // namespace tests
577} // namespace nfd