blob: 587c576f3dd77051b034ebdc3832b4cf082d3b0f [file] [log] [blame]
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Vince Lehman5144f822014-07-23 15:12:56 -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 * The University of Memphis
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -070010 *
11 * This file is part of NFD (Named Data Networking Forwarding Daemon).
12 * See AUTHORS.md for complete list of NFD authors and contributors.
13 *
14 * NFD is free software: you can redistribute it and/or modify it under the terms
15 * of the GNU General Public License as published by the Free Software Foundation,
16 * either version 3 of the License, or (at your option) any later version.
17 *
18 * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
19 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
20 * PURPOSE. See the GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License along with
23 * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
Vince Lehman5144f822014-07-23 15:12:56 -070024 */
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -070025
26#include "mgmt/strategy-choice-manager.hpp"
27#include "face/face.hpp"
28#include "mgmt/internal-face.hpp"
29#include "table/name-tree.hpp"
30#include "table/strategy-choice.hpp"
31#include "fw/forwarder.hpp"
32#include "fw/strategy.hpp"
Alexander Afanasyev613e2a92014-04-15 13:36:58 -070033#include "tests/daemon/face/dummy-face.hpp"
34#include "tests/daemon/fw/dummy-strategy.hpp"
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -070035
Steve DiBenedetto3fff5612014-05-30 15:52:56 -060036#include <ndn-cxx/management/nfd-strategy-choice.hpp>
37
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -070038#include "tests/test-common.hpp"
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -070039#include "validation-common.hpp"
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -070040
41namespace nfd {
42namespace tests {
43
44NFD_LOG_INIT("StrategyChoiceManagerTest");
45
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -070046class StrategyChoiceManagerFixture : protected BaseFixture
47{
48public:
49
50 StrategyChoiceManagerFixture()
Junxiao Shif3c07812014-03-11 21:48:49 -070051 : m_strategyChoice(m_forwarder.getStrategyChoice())
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -070052 , m_face(make_shared<InternalFace>())
Vince Lehman5144f822014-07-23 15:12:56 -070053 , m_manager(m_strategyChoice, m_face, m_keyChain)
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -070054 , m_callbackFired(false)
55 {
Alexander Afanasyevf6980282014-05-13 18:28:40 -070056 m_strategyChoice.install(make_shared<DummyStrategy>(ref(m_forwarder),
57 "/localhost/nfd/strategy/test-strategy-a"));
Junxiao Shif3c07812014-03-11 21:48:49 -070058 m_strategyChoice.insert("ndn:/", "/localhost/nfd/strategy/test-strategy-a");
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -070059 }
60
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -070061 virtual
62 ~StrategyChoiceManagerFixture()
63 {
64
65 }
66
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -070067 void
68 validateControlResponseCommon(const Data& response,
69 const Name& expectedName,
70 uint32_t expectedCode,
71 const std::string& expectedText,
72 ControlResponse& control)
73 {
74 m_callbackFired = true;
75 Block controlRaw = response.getContent().blockFromValue();
76
77 control.wireDecode(controlRaw);
78
79 NFD_LOG_DEBUG("received control response"
80 << " Name: " << response.getName()
81 << " code: " << control.getCode()
82 << " text: " << control.getText());
83
84 BOOST_CHECK_EQUAL(response.getName(), expectedName);
85 BOOST_CHECK_EQUAL(control.getCode(), expectedCode);
86 BOOST_CHECK_EQUAL(control.getText(), expectedText);
87 }
88
89 void
90 validateControlResponse(const Data& response,
91 const Name& expectedName,
92 uint32_t expectedCode,
93 const std::string& expectedText)
94 {
95 ControlResponse control;
96 validateControlResponseCommon(response, expectedName,
97 expectedCode, expectedText, control);
98
99 if (!control.getBody().empty())
100 {
101 BOOST_FAIL("found unexpected control response body");
102 }
103 }
104
105 void
106 validateControlResponse(const Data& response,
107 const Name& expectedName,
108 uint32_t expectedCode,
109 const std::string& expectedText,
110 const Block& expectedBody)
111 {
112 ControlResponse control;
113 validateControlResponseCommon(response, expectedName,
114 expectedCode, expectedText, control);
115
116 BOOST_REQUIRE(!control.getBody().empty());
117 BOOST_REQUIRE(control.getBody().value_size() == expectedBody.value_size());
118
119 BOOST_CHECK(memcmp(control.getBody().value(), expectedBody.value(),
120 expectedBody.value_size()) == 0);
121
122 }
123
Steve DiBenedetto3fff5612014-05-30 15:52:56 -0600124 void
125 validateList(const Data& data, const ndn::nfd::StrategyChoice& expectedChoice)
126 {
127 m_callbackFired = true;
128 ndn::nfd::StrategyChoice choice(data.getContent().blockFromValue());
129 BOOST_CHECK_EQUAL(choice.getStrategy(), expectedChoice.getStrategy());
130 BOOST_CHECK_EQUAL(choice.getName(), expectedChoice.getName());
131 }
132
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700133 bool
134 didCallbackFire()
135 {
136 return m_callbackFired;
137 }
138
139 void
140 resetCallbackFired()
141 {
142 m_callbackFired = false;
143 }
144
145 shared_ptr<InternalFace>&
146 getFace()
147 {
148 return m_face;
149 }
150
151 StrategyChoiceManager&
152 getManager()
153 {
154 return m_manager;
155 }
156
157 StrategyChoice&
158 getStrategyChoice()
159 {
160 return m_strategyChoice;
161 }
162
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700163 void
164 addInterestRule(const std::string& regex,
165 ndn::IdentityCertificate& certificate)
166 {
167 m_manager.addInterestRule(regex, certificate);
168 }
169
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700170protected:
171 Forwarder m_forwarder;
Junxiao Shif3c07812014-03-11 21:48:49 -0700172 StrategyChoice& m_strategyChoice;
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700173 shared_ptr<InternalFace> m_face;
174 StrategyChoiceManager m_manager;
Vince Lehman5144f822014-07-23 15:12:56 -0700175 ndn::KeyChain m_keyChain;
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700176
177private:
178 bool m_callbackFired;
179};
180
181class AllStrategiesFixture : public StrategyChoiceManagerFixture
182{
183public:
184 AllStrategiesFixture()
185 {
Alexander Afanasyevf6980282014-05-13 18:28:40 -0700186 m_strategyChoice.install(make_shared<DummyStrategy>(ref(m_forwarder),
187 "/localhost/nfd/strategy/test-strategy-b"));
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700188 }
189
190 virtual
191 ~AllStrategiesFixture()
192 {
193
194 }
195};
196
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700197template <typename T> class AuthorizedCommandFixture : public CommandFixture<T>
198{
199public:
200 AuthorizedCommandFixture()
201 {
202 const std::string regex = "^<localhost><nfd><strategy-choice>";
203 T::addInterestRule(regex, *CommandFixture<T>::m_certificate);
204 }
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700205
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700206 virtual
207 ~AuthorizedCommandFixture()
208 {
209
210 }
211};
212
213BOOST_FIXTURE_TEST_SUITE(MgmtStrategyChoiceManager,
214 AuthorizedCommandFixture<AllStrategiesFixture>)
215
216BOOST_FIXTURE_TEST_CASE(TestFireInterestFilter, AllStrategiesFixture)
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700217{
218 shared_ptr<Interest> command(make_shared<Interest>("/localhost/nfd/strategy-choice"));
219
220 getFace()->onReceiveData +=
221 bind(&StrategyChoiceManagerFixture::validateControlResponse, this, _1,
222 command->getName(), 400, "Malformed command");
223
224 getFace()->sendInterest(*command);
Junxiao Shi16d1b7d2014-03-27 21:29:09 -0700225 g_io.run_one();
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700226
227 BOOST_REQUIRE(didCallbackFire());
228}
229
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700230BOOST_FIXTURE_TEST_CASE(MalformedCommmand, AllStrategiesFixture)
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700231{
232 shared_ptr<Interest> command(make_shared<Interest>("/localhost/nfd/strategy-choice"));
233
234 getFace()->onReceiveData +=
235 bind(&StrategyChoiceManagerFixture::validateControlResponse, this, _1,
236 command->getName(), 400, "Malformed command");
237
238 getManager().onStrategyChoiceRequest(*command);
239
240 BOOST_REQUIRE(didCallbackFire());
241}
242
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700243BOOST_FIXTURE_TEST_CASE(UnsignedCommand, AllStrategiesFixture)
244{
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600245 ControlParameters parameters;
246 parameters.setName("/test");
247 parameters.setStrategy("/localhost/nfd/strategy/best-route");
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700248
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600249 Block encodedParameters(parameters.wireEncode());
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700250
251 Name commandName("/localhost/nfd/strategy-choice");
252 commandName.append("set");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600253 commandName.append(encodedParameters);
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700254
255 shared_ptr<Interest> command(make_shared<Interest>(commandName));
256
257 getFace()->onReceiveData +=
258 bind(&StrategyChoiceManagerFixture::validateControlResponse, this, _1,
259 command->getName(), 401, "Signature required");
260
261 getManager().onStrategyChoiceRequest(*command);
262
263 BOOST_REQUIRE(didCallbackFire());
264}
265
266BOOST_FIXTURE_TEST_CASE(UnauthorizedCommand,
267 UnauthorizedCommandFixture<StrategyChoiceManagerFixture>)
268{
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600269 ControlParameters parameters;
270 parameters.setName("/test");
271 parameters.setStrategy("/localhost/nfd/strategy/best-route");
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700272
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600273 Block encodedParameters(parameters.wireEncode());
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700274
275 Name commandName("/localhost/nfd/strategy-choice");
276 commandName.append("set");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600277 commandName.append(encodedParameters);
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700278
279 shared_ptr<Interest> command(make_shared<Interest>(commandName));
280 generateCommand(*command);
281
282 getFace()->onReceiveData +=
283 bind(&StrategyChoiceManagerFixture::validateControlResponse, this, _1,
284 command->getName(), 403, "Unauthorized command");
285
286 getManager().onStrategyChoiceRequest(*command);
287
288 BOOST_REQUIRE(didCallbackFire());
289}
290
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700291BOOST_AUTO_TEST_CASE(UnsupportedVerb)
292{
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600293 ControlParameters parameters;
294 parameters.setName("/test");
295 parameters.setStrategy("/localhost/nfd/strategy/test-strategy-b");
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700296
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600297 Block encodedParameters(parameters.wireEncode());
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700298
299 Name commandName("/localhost/nfd/strategy-choice");
300 commandName.append("unsupported");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600301 commandName.append(encodedParameters);
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700302
303 shared_ptr<Interest> command(make_shared<Interest>(commandName));
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700304 generateCommand(*command);
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700305
306 getFace()->onReceiveData +=
307 bind(&StrategyChoiceManagerFixture::validateControlResponse, this, _1,
308 command->getName(), 501, "Unsupported command");
309
310 getManager().onValidatedStrategyChoiceRequest(command);
311
312 BOOST_REQUIRE(didCallbackFire());
313}
314
315BOOST_AUTO_TEST_CASE(BadOptionParse)
316{
317 Name commandName("/localhost/nfd/strategy-choice");
318 commandName.append("set");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600319 commandName.append("NotReallyParameters");
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700320
321 shared_ptr<Interest> command(make_shared<Interest>(commandName));
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700322 generateCommand(*command);
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700323
324 getFace()->onReceiveData +=
325 bind(&StrategyChoiceManagerFixture::validateControlResponse, this, _1,
326 command->getName(), 400, "Malformed command");
327
328 getManager().onValidatedStrategyChoiceRequest(command);
329
330 BOOST_REQUIRE(didCallbackFire());
331}
332
333BOOST_AUTO_TEST_CASE(SetStrategies)
334{
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600335 ControlParameters parameters;
336 parameters.setName("/test");
337 parameters.setStrategy("/localhost/nfd/strategy/test-strategy-b");
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700338
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600339 Block encodedParameters(parameters.wireEncode());
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700340
341 Name commandName("/localhost/nfd/strategy-choice");
342 commandName.append("set");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600343 commandName.append(encodedParameters);
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700344
345 shared_ptr<Interest> command(make_shared<Interest>(commandName));
346
347 getFace()->onReceiveData +=
348 bind(&StrategyChoiceManagerFixture::validateControlResponse, this, _1,
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600349 command->getName(), 200, "Success", encodedParameters);
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700350
351 getManager().onValidatedStrategyChoiceRequest(command);
352
353 BOOST_REQUIRE(didCallbackFire());
354 fw::Strategy& strategy = getStrategyChoice().findEffectiveStrategy("/test");
355 BOOST_REQUIRE_EQUAL(strategy.getName(), "/localhost/nfd/strategy/test-strategy-b");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600356}
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700357
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600358BOOST_AUTO_TEST_CASE(SetStrategiesMissingName)
359{
360 ControlParameters parameters;
361 parameters.setStrategy("/localhost/nfd/strategy/test-strategy-b");
362
363 Block encodedParameters(parameters.wireEncode());
364
365 Name commandName("/localhost/nfd/strategy-choice");
366 commandName.append("set");
367 commandName.append(encodedParameters);
368
369 shared_ptr<Interest> command(make_shared<Interest>(commandName));
370
371 getFace()->onReceiveData +=
372 bind(&StrategyChoiceManagerFixture::validateControlResponse, this, _1,
373 command->getName(), 400, "Malformed command");
374
375 getManager().onValidatedStrategyChoiceRequest(command);
376
377 BOOST_REQUIRE(didCallbackFire());
378}
379
380BOOST_AUTO_TEST_CASE(SetStrategiesMissingStrategy)
381{
382 ControlParameters parameters;
383 parameters.setName("/test");
384
385 Block encodedParameters(parameters.wireEncode());
386
387 Name commandName("/localhost/nfd/strategy-choice");
388 commandName.append("set");
389 commandName.append(encodedParameters);
390
391 shared_ptr<Interest> command(make_shared<Interest>(commandName));
392
393 getFace()->onReceiveData +=
394 bind(&StrategyChoiceManagerFixture::validateControlResponse, this, _1,
395 command->getName(), 400, "Malformed command");
396
397 getManager().onValidatedStrategyChoiceRequest(command);
398
399 BOOST_REQUIRE(didCallbackFire());
400 fw::Strategy& strategy = getStrategyChoice().findEffectiveStrategy("/test");
401 BOOST_REQUIRE_EQUAL(strategy.getName(), "/localhost/nfd/strategy/test-strategy-a");
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700402}
403
404BOOST_AUTO_TEST_CASE(SetUnsupportedStrategy)
405{
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600406 ControlParameters parameters;
407 parameters.setName("/test");
408 parameters.setStrategy("/localhost/nfd/strategy/unit-test-doesnotexist");
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700409
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600410 Block encodedParameters(parameters.wireEncode());
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700411
412 Name commandName("/localhost/nfd/strategy-choice");
413 commandName.append("set");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600414 commandName.append(encodedParameters);
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700415
416 shared_ptr<Interest> command(make_shared<Interest>(commandName));
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700417 generateCommand(*command);
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700418
419 getFace()->onReceiveData +=
420 bind(&StrategyChoiceManagerFixture::validateControlResponse, this, _1,
421 command->getName(), 504, "Unsupported strategy");
422
423 getManager().onValidatedStrategyChoiceRequest(command);
424
425 BOOST_REQUIRE(didCallbackFire());
426 fw::Strategy& strategy = getStrategyChoice().findEffectiveStrategy("/test");
427 BOOST_CHECK_EQUAL(strategy.getName(), "/localhost/nfd/strategy/test-strategy-a");
428}
429
430class DefaultStrategyOnlyFixture : public StrategyChoiceManagerFixture
431{
432public:
433 DefaultStrategyOnlyFixture()
434 : StrategyChoiceManagerFixture()
435 {
436
437 }
438
439 virtual
440 ~DefaultStrategyOnlyFixture()
441 {
442
443 }
444};
445
446
447/// \todo I'm not sure this code branch (code 405) can happen. The manager tests for the strategy first and will return 504.
448// BOOST_FIXTURE_TEST_CASE(SetNotInstalled, DefaultStrategyOnlyFixture)
449// {
450// BOOST_REQUIRE(!getStrategyChoice().hasStrategy("/localhost/nfd/strategy/test-strategy-b"));
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600451// ControlParameters parameters;
452// parameters.setName("/test");
453// parameters.setStrategy("/localhost/nfd/strategy/test-strategy-b");
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700454
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600455// Block encodedParameters(parameters.wireEncode());
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700456
457// Name commandName("/localhost/nfd/strategy-choice");
458// commandName.append("set");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600459// commandName.append(encodedParameters);
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700460
461// shared_ptr<Interest> command(make_shared<Interest>(commandName));
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700462// generateCommand(*command);
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700463
464// getFace()->onReceiveData +=
465// bind(&StrategyChoiceManagerFixture::validateControlResponse, this, _1,
466// command->getName(), 405, "Strategy not installed");
467
468// getManager().onValidatedStrategyChoiceRequest(command);
469
470// BOOST_REQUIRE(didCallbackFire());
471// fw::Strategy& strategy = getStrategyChoice().findEffectiveStrategy("/test");
472// BOOST_CHECK_EQUAL(strategy.getName(), "/localhost/nfd/strategy/test-strategy-a");
473// }
474
475BOOST_AUTO_TEST_CASE(Unset)
476{
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600477 ControlParameters parameters;
478 parameters.setName("/test");
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700479
480 BOOST_REQUIRE(m_strategyChoice.insert("/test", "/localhost/nfd/strategy/test-strategy-b"));
481 BOOST_REQUIRE_EQUAL(m_strategyChoice.findEffectiveStrategy("/test").getName(),
482 "/localhost/nfd/strategy/test-strategy-b");
483
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600484 Block encodedParameters(parameters.wireEncode());
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700485
486 Name commandName("/localhost/nfd/strategy-choice");
487 commandName.append("unset");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600488 commandName.append(encodedParameters);
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700489
490 shared_ptr<Interest> command(make_shared<Interest>(commandName));
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700491 generateCommand(*command);
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700492
493 getFace()->onReceiveData +=
494 bind(&StrategyChoiceManagerFixture::validateControlResponse, this, _1,
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600495 command->getName(), 200, "Success", encodedParameters);
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700496
497 getManager().onValidatedStrategyChoiceRequest(command);
498
499 BOOST_REQUIRE(didCallbackFire());
500
501 BOOST_CHECK_EQUAL(m_strategyChoice.findEffectiveStrategy("/test").getName(),
502 "/localhost/nfd/strategy/test-strategy-a");
503}
504
505BOOST_AUTO_TEST_CASE(UnsetRoot)
506{
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600507 ControlParameters parameters;
508 parameters.setName("/");
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700509
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600510 Block encodedParameters(parameters.wireEncode());
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700511
512 Name commandName("/localhost/nfd/strategy-choice");
513 commandName.append("unset");
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600514 commandName.append(encodedParameters);
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700515
516 shared_ptr<Interest> command(make_shared<Interest>(commandName));
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -0700517 generateCommand(*command);
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700518
519 getFace()->onReceiveData +=
520 bind(&StrategyChoiceManagerFixture::validateControlResponse, this, _1,
521 command->getName(), 403, "Cannot unset root prefix strategy");
522
523 getManager().onValidatedStrategyChoiceRequest(command);
524
525 BOOST_REQUIRE(didCallbackFire());
526
527 BOOST_CHECK_EQUAL(m_strategyChoice.findEffectiveStrategy("/test").getName(),
528 "/localhost/nfd/strategy/test-strategy-a");
529}
530
Steve DiBenedetto7564d972014-03-24 14:28:46 -0600531BOOST_AUTO_TEST_CASE(UnsetMissingName)
532{
533 ControlParameters parameters;
534
535 BOOST_REQUIRE(m_strategyChoice.insert("/test", "/localhost/nfd/strategy/test-strategy-b"));
536 BOOST_REQUIRE_EQUAL(m_strategyChoice.findEffectiveStrategy("/test").getName(),
537 "/localhost/nfd/strategy/test-strategy-b");
538
539 Block encodedParameters(parameters.wireEncode());
540
541 Name commandName("/localhost/nfd/strategy-choice");
542 commandName.append("unset");
543 commandName.append(encodedParameters);
544
545 shared_ptr<Interest> command(make_shared<Interest>(commandName));
546 generateCommand(*command);
547
548 getFace()->onReceiveData +=
549 bind(&StrategyChoiceManagerFixture::validateControlResponse, this, _1,
550 command->getName(), 400, "Malformed command");
551
552 getManager().onValidatedStrategyChoiceRequest(command);
553
554 BOOST_REQUIRE(didCallbackFire());
555
556 BOOST_CHECK_EQUAL(m_strategyChoice.findEffectiveStrategy("/test").getName(),
557 "/localhost/nfd/strategy/test-strategy-b");
558}
559
Steve DiBenedetto3fff5612014-05-30 15:52:56 -0600560BOOST_AUTO_TEST_CASE(Publish)
561{
562 Name commandName("/localhost/nfd/strategy-choice/list");
563 shared_ptr<Interest> command(make_shared<Interest>(commandName));
564
565 ndn::nfd::StrategyChoice expectedChoice;
566 expectedChoice.setStrategy("/localhost/nfd/strategy/test-strategy-a");
567 expectedChoice.setName("/");
568
569 getFace()->onReceiveData +=
570 bind(&StrategyChoiceManagerFixture::validateList, this, _1, expectedChoice);
571
572 m_manager.onStrategyChoiceRequest(*command);
573 BOOST_REQUIRE(didCallbackFire());
574}
575
Steve DiBenedetto5330e0d2014-03-05 21:52:51 -0700576BOOST_AUTO_TEST_SUITE_END()
577
578} // namespace tests
579} // namespace nfd