2 * Copyright (c) 2013 Contextream, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.lispflowmapping.implementation.lisp;
11 import static org.junit.Assert.assertEquals;
13 import java.util.HashMap;
16 import junitx.framework.ArrayAssert;
18 import org.junit.Before;
19 import org.junit.Test;
20 import org.opendaylight.lispflowmapping.implementation.serializer.MapRegisterSerializer;
21 import org.opendaylight.lispflowmapping.interfaces.dao.ILispDAO;
22 import org.opendaylight.lispflowmapping.interfaces.dao.IMappingServiceKey;
23 import org.opendaylight.lispflowmapping.interfaces.dao.MappingEntry;
24 import org.opendaylight.lispflowmapping.interfaces.dao.MappingServiceKeyUtil;
25 import org.opendaylight.lispflowmapping.interfaces.dao.MappingServiceValue;
26 import org.opendaylight.lispflowmapping.tools.junit.BaseTestCase;
27 import org.opendaylight.lispflowmapping.type.lisp.EidToLocatorRecord;
28 import org.opendaylight.lispflowmapping.type.lisp.LocatorRecord;
29 import org.opendaylight.lispflowmapping.type.lisp.MapNotify;
30 import org.opendaylight.lispflowmapping.type.lisp.MapRegister;
31 import org.opendaylight.lispflowmapping.type.lisp.address.IMaskable;
32 import org.opendaylight.lispflowmapping.type.lisp.address.LispAddress;
33 import org.opendaylight.lispflowmapping.type.lisp.address.LispIpv4Address;
34 import org.opendaylight.lispflowmapping.type.lisp.address.LispIpv6Address;
35 import org.opendaylight.lispflowmapping.type.lisp.address.LispMACAddress;
36 import org.opendaylight.lispflowmapping.type.lisp.address.LispNoAddress;
38 public class MapServerTest extends BaseTestCase {
40 private MapServer testedMapServer;
41 private ILispDAO lispDAO;
42 private MapRegister mapRegister;
43 private LispIpv4Address eid;
44 private LispIpv4Address rloc;
45 private ValueSaverAction<MappingEntry<?>[]> mappingEntriesSaver;
46 private MapRegister mapRegisterWithAuthentication;
50 public void before() throws Exception {
52 lispDAO = context.mock(ILispDAO.class);
53 testedMapServer = new MapServer(lispDAO);
54 mapRegister = new MapRegister();
55 eid = new LispIpv4Address("10.31.0.5");
56 rloc = new LispIpv4Address(0xC0A8880A);
57 EidToLocatorRecord record = new EidToLocatorRecord();
58 record.setPrefix(eid).setMaskLength(32);
59 record.addLocator(new LocatorRecord().setLocator(rloc));
60 mapRegister.addEidToLocator(record);
61 mapRegisterWithAuthentication = MapRegisterSerializer.getInstance().deserialize(hexToByteBuffer("38 00 01 01 FF BB " //
62 + "00 00 00 00 00 00 00 01 00 14 2c 61 b9 c9 9a 20 " //
63 + "ba d8 f5 40 d3 55 6f 5f 6e 5a b2 0a bf b5 00 00 " //
64 + "00 0a 01 20 10 00 00 00 00 01 99 10 fe 01 01 64 " //
65 + "ff 00 00 05 00 01 c0 a8 88 0a"));
67 mappingEntriesSaver = new ValueSaverAction<MappingEntry<?>[]>();
71 public void handleMapRegister__NonSetMBit() throws Exception {
72 mapRegister.setWantMapNotify(false);
74 addDefaultPutAndGetExpectations(eid, 32);
75 assertNull(testedMapServer.handleMapRegister(mapRegister));
77 MappingEntry<?>[] entries = mappingEntriesSaver.lastValue;
78 assertEquals(1, entries.length);
80 assertEquals("value", entries[0].getKey());
81 assertEquals(rloc, ((MappingServiceValue) entries[0].getValue()).getRlocs().get(0).getRecord().getLocator());
85 public void handleMapRegisterIpv4__ValidNotifyEchoesRegister() throws Exception {
86 mapRegister.addEidToLocator(new EidToLocatorRecord().setPrefix(new LispNoAddress()));
87 mapRegister.setWantMapNotify(true);
89 addDefaultPutAndGetExpectations(eid, 32);
90 addDefaultPutAndGetExpectations(new LispNoAddress(), 32);
91 MapNotify mapNotify = testedMapServer.handleMapRegister(mapRegister);
92 assertEquals(mapRegister.getEidToLocatorRecords(), mapNotify.getEidToLocatorRecords());
93 ArrayAssert.assertEquals(mapRegister.getAuthenticationData(), mapNotify.getAuthenticationData());
94 assertEquals(mapRegister.getKeyId(), mapNotify.getKeyId());
95 assertEquals(mapRegister.getNonce(), mapNotify.getNonce());
99 public void handleMapRegisterIpv4__CloneNotOwnYouClown() throws Exception {
100 mapRegister = new MapRegister();
101 mapRegister.setKeyId((byte) 0);
102 mapRegister.setWantMapNotify(true);
103 EidToLocatorRecord eidToLocator = new EidToLocatorRecord();
104 eidToLocator.setMaskLength(32);
105 eid = new LispIpv4Address(1);
106 eidToLocator.setPrefix(eid);
108 LocatorRecord locator = new LocatorRecord();
109 locator.setLocator(new LispIpv4Address(2));
110 locator.setPriority((byte) 55);
111 eidToLocator.addLocator(locator);
113 mapRegister.addEidToLocator(eidToLocator);
115 addDefaultPutAndGetExpectations(eid, 32);
117 MapNotify mapNotify = testedMapServer.handleMapRegister(mapRegister);
119 mapRegister.getEidToLocatorRecords().get(0).setPrefix(new LispIpv4Address(55));
120 mapRegister.getEidToLocatorRecords().get(0).getLocators().get(0).setPriority((byte) 1);
122 EidToLocatorRecord actualEidToLocator = mapNotify.getEidToLocatorRecords().get(0);
123 assertEquals(new LispIpv4Address(1), actualEidToLocator.getPrefix());
124 assertEquals((byte) 55, actualEidToLocator.getLocators().get(0).getPriority());
129 public void handleMapRegisterIpv4__ValidMask() throws Exception {
131 mapRegister = new MapRegister();
132 EidToLocatorRecord record = new EidToLocatorRecord();
133 record.setPrefix(eid).setMaskLength(mask);
134 record.addLocator(new LocatorRecord().setLocator(rloc));
135 mapRegister.addEidToLocator(record);
136 mapRegister.setWantMapNotify(true);
138 addDefaultPutAndGetExpectations(eid, mask);
140 MapNotify mapNotify = testedMapServer.handleMapRegister(mapRegister);
141 assertEquals(new LispIpv4Address("10.31.0.0"), mapNotify.getEidToLocatorRecords().get(0).getPrefix());
142 ArrayAssert.assertEquals(mapRegister.getAuthenticationData(), mapNotify.getAuthenticationData());
143 assertEquals(mapRegister.getEidToLocatorRecords(), mapNotify.getEidToLocatorRecords());
144 assertEquals(mapRegister.getKeyId(), mapNotify.getKeyId());
145 assertEquals(mapRegister.getNonce(), mapNotify.getNonce());
149 public void handleMapRegister__NonMaskable() throws Exception {
151 mapRegister = new MapRegister();
152 EidToLocatorRecord record = new EidToLocatorRecord();
153 LispMACAddress addr = new LispMACAddress(new byte[] { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 });
154 record.setPrefix(addr).setMaskLength(mask);
155 record.addLocator(new LocatorRecord().setLocator(rloc));
156 mapRegister.addEidToLocator(record);
157 mapRegister.setWantMapNotify(true);
159 addDefaultPutAndGetExpectations(addr, mask);
161 MapNotify mapNotify = testedMapServer.handleMapRegister(mapRegister);
162 assertEquals(addr, mapNotify.getEidToLocatorRecords().get(0).getPrefix());
163 ArrayAssert.assertEquals(mapRegister.getAuthenticationData(), mapNotify.getAuthenticationData());
164 assertEquals(mapRegister.getEidToLocatorRecords(), mapNotify.getEidToLocatorRecords());
165 assertEquals(mapRegister.getKeyId(), mapNotify.getKeyId());
166 assertEquals(mapRegister.getNonce(), mapNotify.getNonce());
169 private void addDefaultPutAndGetExpectations(LispAddress addr, int mask) {
170 addPutExpectations(addr, mask);
171 addGetExpectations(addr, mask);
175 public void handleMapRegister__ZeroMask() throws Exception {
177 mapRegister = new MapRegister();
178 EidToLocatorRecord record = new EidToLocatorRecord();
179 LispMACAddress addr = new LispMACAddress(new byte[] { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 });
180 record.setPrefix(addr).setMaskLength(mask);
181 record.addLocator(new LocatorRecord().setLocator(rloc));
182 mapRegister.addEidToLocator(record);
183 mapRegister.setWantMapNotify(true);
185 addDefaultPutAndGetExpectations(addr, mask);
187 MapNotify mapNotify = testedMapServer.handleMapRegister(mapRegister);
188 assertEquals(addr, mapNotify.getEidToLocatorRecords().get(0).getPrefix());
189 ArrayAssert.assertEquals(mapRegister.getAuthenticationData(), mapNotify.getAuthenticationData());
190 assertEquals(mapRegister.getEidToLocatorRecords(), mapNotify.getEidToLocatorRecords());
191 assertEquals(mapRegister.getKeyId(), mapNotify.getKeyId());
192 assertEquals(mapRegister.getNonce(), mapNotify.getNonce());
196 public void handleMapRegisterIPv4__ZeroMask() throws Exception {
198 mapRegister = new MapRegister();
199 EidToLocatorRecord record = new EidToLocatorRecord();
200 record.setPrefix(eid).setMaskLength(mask);
201 record.addLocator(new LocatorRecord().setLocator(rloc));
202 mapRegister.addEidToLocator(record);
203 mapRegister.setWantMapNotify(true);
205 addDefaultPutAndGetExpectations(eid, mask);
207 MapNotify mapNotify = testedMapServer.handleMapRegister(mapRegister);
208 assertEquals(new LispIpv4Address("0.0.0.0"), mapNotify.getEidToLocatorRecords().get(0).getPrefix());
209 ArrayAssert.assertEquals(mapRegister.getAuthenticationData(), mapNotify.getAuthenticationData());
210 assertEquals(mapRegister.getEidToLocatorRecords(), mapNotify.getEidToLocatorRecords());
211 assertEquals(mapRegister.getKeyId(), mapNotify.getKeyId());
212 assertEquals(mapRegister.getNonce(), mapNotify.getNonce());
216 public void handleMapRegisterIpv4__ValidMask32() throws Exception {
218 mapRegister = new MapRegister();
219 EidToLocatorRecord record = new EidToLocatorRecord();
220 record.setPrefix(new LispIpv4Address("10.31.0.5")).setMaskLength(mask);
221 record.addLocator(new LocatorRecord().setLocator(rloc));
222 mapRegister.addEidToLocator(record);
223 mapRegister.setWantMapNotify(true);
225 addDefaultPutAndGetExpectations(eid, mask);
227 MapNotify mapNotify = testedMapServer.handleMapRegister(mapRegister);
228 assertEquals(new LispIpv4Address("10.31.0.5"), mapNotify.getEidToLocatorRecords().get(0).getPrefix());
229 assertEquals(mapRegister.getEidToLocatorRecords(), mapNotify.getEidToLocatorRecords());
230 ArrayAssert.assertEquals(mapRegister.getAuthenticationData(), mapNotify.getAuthenticationData());
231 assertEquals(mapRegister.getKeyId(), mapNotify.getKeyId());
232 assertEquals(mapRegister.getNonce(), mapNotify.getNonce());
236 public void handleMapRegisterIpv6__ValidMask96() throws Exception {
238 mapRegister = new MapRegister();
239 EidToLocatorRecord record = new EidToLocatorRecord();
240 LispIpv6Address addr = new LispIpv6Address("1:1:1:1:1:1:1:0");
241 record.setPrefix(addr).setMaskLength(mask);
242 record.addLocator(new LocatorRecord().setLocator(rloc));
243 mapRegister.addEidToLocator(record);
244 mapRegister.setWantMapNotify(true);
246 addDefaultPutAndGetExpectations(addr, mask);
248 MapNotify mapNotify = testedMapServer.handleMapRegister(mapRegister);
249 assertEquals(new LispIpv6Address("1:1:1:1:1:1:0:0"), mapNotify.getEidToLocatorRecords().get(0).getPrefix());
250 assertEquals(mapRegister.getEidToLocatorRecords(), mapNotify.getEidToLocatorRecords());
251 ArrayAssert.assertEquals(mapRegister.getAuthenticationData(), mapNotify.getAuthenticationData());
252 assertEquals(mapRegister.getKeyId(), mapNotify.getKeyId());
253 assertEquals(mapRegister.getNonce(), mapNotify.getNonce());
257 public void handleMapRegisterIpv6__ZeroMask() throws Exception {
259 mapRegister = new MapRegister();
260 EidToLocatorRecord record = new EidToLocatorRecord();
261 LispIpv6Address addr = new LispIpv6Address("1:1:1:1:1:1:1:0");
262 record.setPrefix(addr).setMaskLength(mask);
263 record.addLocator(new LocatorRecord().setLocator(rloc));
264 mapRegister.addEidToLocator(record);
265 mapRegister.setWantMapNotify(true);
267 addDefaultPutAndGetExpectations(addr, mask);
269 MapNotify mapNotify = testedMapServer.handleMapRegister(mapRegister);
270 assertEquals(new LispIpv6Address("0:0:0:0:0:0:0:0"), mapNotify.getEidToLocatorRecords().get(0).getPrefix());
271 assertEquals(mapRegister.getEidToLocatorRecords(), mapNotify.getEidToLocatorRecords());
272 ArrayAssert.assertEquals(mapRegister.getAuthenticationData(), mapNotify.getAuthenticationData());
273 assertEquals(mapRegister.getKeyId(), mapNotify.getKeyId());
274 assertEquals(mapRegister.getNonce(), mapNotify.getNonce());
278 public void handleMapRegisterIPV4AndIpv6__ValidMask96() throws Exception {
280 EidToLocatorRecord record = new EidToLocatorRecord();
281 LispIpv6Address addr = new LispIpv6Address("1:1:1:1:1:1:1:0");
282 record.setPrefix(addr).setMaskLength(mask);
283 record.addLocator(new LocatorRecord().setLocator(rloc));
284 mapRegister.addEidToLocator(record);
285 mapRegister.setWantMapNotify(true);
287 addDefaultPutAndGetExpectations(eid, 32);
288 addDefaultPutAndGetExpectations(addr, mask);
290 MapNotify mapNotify = testedMapServer.handleMapRegister(mapRegister);
291 assertEquals(new LispIpv6Address("1:1:1:1:1:1:0:0"), mapNotify.getEidToLocatorRecords().get(1).getPrefix());
292 assertEquals(eid, mapNotify.getEidToLocatorRecords().get(0).getPrefix());
293 assertEquals(mapRegister.getEidToLocatorRecords(), mapNotify.getEidToLocatorRecords());
294 ArrayAssert.assertEquals(mapRegister.getAuthenticationData(), mapNotify.getAuthenticationData());
295 assertEquals(mapRegister.getKeyId(), mapNotify.getKeyId());
296 assertEquals(mapRegister.getNonce(), mapNotify.getNonce());
300 public void handleMapRegisterIpv6__ValidMask32() throws Exception {
302 mapRegister = new MapRegister();
303 EidToLocatorRecord record = new EidToLocatorRecord();
304 LispIpv6Address addr = new LispIpv6Address("1:1:1:1:0:0:0:0");
305 record.setPrefix(addr).setMaskLength(mask);
306 record.addLocator(new LocatorRecord().setLocator(rloc));
307 mapRegister.addEidToLocator(record);
308 mapRegister.setWantMapNotify(true);
310 addDefaultPutAndGetExpectations(addr, mask);
312 MapNotify mapNotify = testedMapServer.handleMapRegister(mapRegister);
313 assertEquals(new LispIpv6Address("1:1:1:0:0:0:0:0"), mapNotify.getEidToLocatorRecords().get(0).getPrefix());
314 assertEquals(mask, mapNotify.getEidToLocatorRecords().get(0).getMaskLength());
315 assertEquals(mapRegister.getEidToLocatorRecords(), mapNotify.getEidToLocatorRecords());
316 ArrayAssert.assertEquals(mapRegister.getAuthenticationData(), mapNotify.getAuthenticationData());
317 assertEquals(mapRegister.getKeyId(), mapNotify.getKeyId());
318 assertEquals(mapRegister.getNonce(), mapNotify.getNonce());
322 public void handleMapRegisterIpv6__ValidMask128() throws Exception {
324 mapRegister = new MapRegister();
325 EidToLocatorRecord record = new EidToLocatorRecord();
326 LispIpv6Address addr = new LispIpv6Address("1:1:1:1:1:1:1:2");
327 record.setPrefix(addr).setMaskLength(mask);
328 record.addLocator(new LocatorRecord().setLocator(rloc));
329 mapRegister.addEidToLocator(record);
330 mapRegister.setWantMapNotify(true);
332 addPutExpectations(addr, mask);
334 MapNotify mapNotify = testedMapServer.handleMapRegister(mapRegister);
335 assertEquals(new LispIpv6Address("1:1:1:1:1:1:1:2"), mapNotify.getEidToLocatorRecords().get(0).getPrefix());
336 assertEquals(mapRegister.getEidToLocatorRecords(), mapNotify.getEidToLocatorRecords());
337 ArrayAssert.assertEquals(mapRegister.getAuthenticationData(), mapNotify.getAuthenticationData());
338 assertEquals(mapRegister.getKeyId(), mapNotify.getKeyId());
339 assertEquals(mapRegister.getNonce(), mapNotify.getNonce());
343 public void handleMapRegister__MultipleRLOCs() throws Exception {
344 addDefaultPutAndGetExpectations(eid, 32);
346 LispIpv4Address rloc0 = rloc;
347 LispIpv6Address rloc1 = new LispIpv6Address("::7");
348 mapRegister.getEidToLocatorRecords().get(0).addLocator(new LocatorRecord().setLocator(rloc1));
350 testedMapServer.handleMapRegister(mapRegister);
352 MappingEntry<?>[] entries = mappingEntriesSaver.lastValue;
353 assertEquals(1, entries.length);
355 assertEquals("value", entries[0].getKey());
356 assertEquals(rloc0, ((MappingServiceValue) entries[0].getValue()).getRlocs().get(0).getRecord().getLocator());
357 assertEquals(rloc1, ((MappingServiceValue) entries[0].getValue()).getRlocs().get(1).getRecord().getLocator());
362 public void handleMapRegister__MultipleEIDs() throws Exception {
363 addDefaultPutAndGetExpectations(eid, 32);
365 LispIpv4Address rloc0 = rloc;
366 LispIpv6Address rloc1 = new LispIpv6Address("::7");
367 mapRegister.getEidToLocatorRecords().get(0).addLocator(new LocatorRecord().setLocator(rloc1));
368 mapRegister.setWantMapNotify(true);
370 EidToLocatorRecord etlr = new EidToLocatorRecord();
371 LispIpv4Address address = new LispIpv4Address("1.1.1.1");
372 etlr.setPrefix(address);
373 etlr.setMaskLength(32);
375 etlr.setRecordTtl(recordTtl);
376 etlr.addLocator(new LocatorRecord().setLocator(new LispIpv4Address("2.2.2.2")).setPriority((byte) 10));
377 mapRegister.addEidToLocator(etlr);
378 addPutExpectations(address, 32);
379 addGetExpectations(address, 32);
380 MapNotify mapNotify = testedMapServer.handleMapRegister(mapRegister);
382 assertEquals(rloc0, mapNotify.getEidToLocatorRecords().get(0).getLocators().get(0).getLocator());
383 assertEquals(rloc1, mapNotify.getEidToLocatorRecords().get(0).getLocators().get(1).getLocator());
384 assertEquals(new LispIpv4Address("2.2.2.2"), mapNotify.getEidToLocatorRecords().get(1).getLocators().get(0).getLocator());
385 assertEquals(recordTtl, mapNotify.getEidToLocatorRecords().get(1).getRecordTtl());
390 public void handleMapRegisterIpv4__ChekWrongPassword() throws Exception {
392 addGetExpectations(new LispIpv4Address("153.16.254.1"), 32, 0, 31, "bla");
393 MapNotify mapNotify = testedMapServer.handleMapRegister(mapRegisterWithAuthentication);
394 assertEquals(null, mapNotify);
398 public void handleMapRegisterIpv4__ChcekNoPasswordAndThenPassword() throws Exception {
400 addGetExpectations(new LispIpv4Address("153.16.254.1"), 32, 30, 25, "password");
401 addPutExpectations(new LispIpv4Address("153.16.254.1"), 32);
402 MapNotify mapNotify = testedMapServer.handleMapRegister(mapRegisterWithAuthentication);
403 assertEquals(mapRegisterWithAuthentication.getEidToLocatorRecords(), mapNotify.getEidToLocatorRecords());
404 assertEquals(mapRegisterWithAuthentication.getKeyId(), mapNotify.getKeyId());
405 assertEquals(mapRegisterWithAuthentication.getNonce(), mapNotify.getNonce());
409 public void handleMapRegisterIpv4__ChcekNoPassword() throws Exception {
411 addGetExpectations(new LispIpv4Address("153.16.254.1"), 32, 30, 0, "password");
412 MapNotify mapNotify = testedMapServer.handleMapRegister(mapRegisterWithAuthentication);
413 assertEquals(null, mapNotify);
417 public void handleMapRegisterIpv4__ChcekNoreturn() throws Exception {
419 addGetExpectations(new LispIpv4Address("153.16.254.1"), 32);
420 MapNotify mapNotify = testedMapServer.handleMapRegister(mapRegisterWithAuthentication);
421 assertEquals(mapNotify, null);
425 public void handleAddAuthenticationKey() throws Exception {
426 IMappingServiceKey key = getDefualtKey();
427 MappingServiceValue value = getDefualtValue();
428 MappingEntry<MappingServiceValue> mappingEntry = new MappingEntry<MappingServiceValue>("value", value);
429 oneOf(lispDAO).get(weq(key));
430 oneOf(lispDAO).put(weq(key), weq(convertToArray(mappingEntry)));
431 assertEquals(true, testedMapServer.addAuthenticationKey(eid, key.getMask(), value.getKey()));
435 public void handleGetAuthenticationKey() throws Exception {
436 IMappingServiceKey key = getDefualtKey();
437 MappingServiceValue value = getDefualtValue();
438 Map<String, MappingServiceValue> map = new HashMap<String, MappingServiceValue>();
439 map.put("value", value);
440 atLeast(1).of(lispDAO).get(weq(key));
442 assertEquals(value.getKey(), testedMapServer.getAuthenticationKey(eid, key.getMask()));
446 public void handleGetAuthenticationKeyNoIteration() throws Exception {
447 testedMapServer.setShouldIterateMask(false);
448 IMappingServiceKey key = getDefualtKey();
449 IMappingServiceKey passKey = getKey(30);
450 MappingServiceValue value = getDefualtValue();
451 Map<String, MappingServiceValue> map = new HashMap<String, MappingServiceValue>();
452 map.put("value", value);
453 oneOf(lispDAO).get(weq(key));
454 allowing(lispDAO).get(weq(passKey));
456 assertEquals(null, testedMapServer.getAuthenticationKey(eid, key.getMask()));
460 public void handleRemoveAuthenticationKey() throws Exception {
461 IMappingServiceKey key = getDefualtKey();
462 MappingServiceValue value = new MappingServiceValue();
463 Map<String, MappingServiceValue> map = new HashMap<String, MappingServiceValue>();
464 map.put("value", value);
465 oneOf(lispDAO).get(weq(key));
467 oneOf(lispDAO).remove(weq(key));
468 assertEquals(true, testedMapServer.removeAuthenticationKey(eid, key.getMask()));
472 public void handleRemoveAuthenticationKeyWhereKeyDosntExist() throws Exception {
473 IMappingServiceKey key = getDefualtKey();
474 MappingServiceValue value = new MappingServiceValue();
475 Map<String, MappingServiceValue> map = new HashMap<String, MappingServiceValue>();
476 map.put("value", value);
477 oneOf(lispDAO).get(weq(key));
478 assertEquals(false, testedMapServer.removeAuthenticationKey(eid, key.getMask()));
481 @SuppressWarnings("rawtypes")
482 private MappingEntry[] convertToArray(MappingEntry<MappingServiceValue> entry) {
483 MappingEntry[] arr = new MappingEntry[1];
488 private void addGetExpectations(LispAddress address, int mask) {
489 addGetExpectations(address, mask, 0, 0, "password");
492 private void addPutExpectations(LispAddress address, int mask) {
493 LispAddress clonedAddress = address;
494 if (address instanceof IMaskable) {
495 clonedAddress = (LispAddress) ((IMaskable) address).clone();
497 oneOf(lispDAO).put(weq(MappingServiceKeyUtil.generateMappingServiceKey(clonedAddress, (byte) mask)), with(mappingEntriesSaver));
500 private void addGetExpectations(LispAddress address, int mask, int withoutPassword, int withPassword, String password) {
501 LispAddress clonedAddress = address;
502 if (address instanceof IMaskable) {
503 clonedAddress = (LispAddress) ((IMaskable) address).clone();
506 if (withoutPassword > 0) {
507 Map<String, MappingServiceValue> result = new HashMap<String, MappingServiceValue>();
508 result.put("value", new MappingServiceValue());
510 .getSpecific(with(MappingServiceKeyUtil.generateMappingServiceKey(clonedAddress, (byte) withoutPassword)), with("value"));
513 if (address instanceof IMaskable) {
514 clonedAddress = (LispAddress) ((IMaskable) address).clone();
516 if (withPassword > 0) {
517 Map<String, MappingServiceValue> result = new HashMap<String, MappingServiceValue>();
518 result.put("value", new MappingServiceValue());
519 result.get("value").setKey(password);
520 allowing(lispDAO).get(with(MappingServiceKeyUtil.generateMappingServiceKey(clonedAddress, (byte) withPassword)));
523 for (int i = mask; i >= 0; i--) {
524 if (address instanceof IMaskable) {
525 clonedAddress = (LispAddress) ((IMaskable) address).clone();
527 allowing(lispDAO).get(with(MappingServiceKeyUtil.generateMappingServiceKey(clonedAddress, (byte) i)));
528 ret(new HashMap<String, MappingServiceValue>());
532 private IMappingServiceKey getDefualtKey() {
536 private IMappingServiceKey getKey(int mask) {
537 IMappingServiceKey key = MappingServiceKeyUtil.generateMappingServiceKey(eid, mask);
541 private MappingServiceValue getDefualtValue() {
542 MappingServiceValue value = new MappingServiceValue();
543 String password = "pass";
544 value.setKey(password);