2 * Copyright (c) 2016 Cisco Systems, 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
8 package org.opendaylight.lispflowmapping.implementation.lisp;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNull;
13 import java.util.ArrayList;
14 import java.util.concurrent.ExecutionException;
15 import java.util.concurrent.Future;
16 import org.junit.Test;
17 import org.junit.runner.RunWith;
18 import org.mockito.InjectMocks;
19 import org.mockito.Mock;
20 import org.mockito.Mockito;
21 import org.mockito.runners.MockitoJUnitRunner;
22 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
23 import org.opendaylight.lispflowmapping.implementation.MappingService;
24 import org.opendaylight.lispflowmapping.implementation.MappingSystem;
25 import org.opendaylight.lispflowmapping.implementation.mdsal.AuthenticationKeyDataListener;
26 import org.opendaylight.lispflowmapping.implementation.mdsal.DataStoreBackEnd;
27 import org.opendaylight.lispflowmapping.implementation.mdsal.MappingDataListener;
28 import org.opendaylight.lispflowmapping.implementation.util.DSBEInputUtil;
29 import org.opendaylight.lispflowmapping.implementation.util.RPCInputConvertorUtil;
30 import org.opendaylight.lispflowmapping.interfaces.dao.SubKeys;
31 import org.opendaylight.lispflowmapping.lisp.util.LispAddressUtil;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.SiteId;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.XtrId;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecord;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container
37 .MappingRecordBuilder;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.AddKeyInput;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.AddKeyInputBuilder;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.AddKeysInput;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.AddMappingInput;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.AddMappingInputBuilder;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.AddMappingsInput;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.GetKeyInput;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.GetKeyInputBuilder;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.GetKeyOutput;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.GetKeyOutputBuilder;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.GetKeysInput;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.GetMappingInput;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.GetMappingInputBuilder;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.GetMappingOutput;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.GetMappingOutputBuilder;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.MappingOrigin;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.OdlMappingserviceService;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.RemoveKeyInput;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.RemoveKeyInputBuilder;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.RemoveKeysInput;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.RemoveMappingInput;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.RemoveMappingInputBuilder;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.RemoveMappingsInput;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.UpdateKeyInput;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.UpdateKeyInputBuilder;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.UpdateKeysInput;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.UpdateMappingInput;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.UpdateMappingInputBuilder;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.UpdateMappingsInput;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.mapping.authkey.container
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.mapping.authkey.container
70 .MappingAuthkeyBuilder;
71 import org.opendaylight.yangtools.yang.common.RpcError;
72 import org.opendaylight.yangtools.yang.common.RpcResult;
73 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
75 @RunWith(MockitoJUnitRunner.class)
76 public class MappingServiceTest {
78 @InjectMocks private static MappingService mappingService;
79 @Mock(name = "mappingSystem") private static MappingSystem mappingSystem;
80 @Mock(name = "dsbe") private static DataStoreBackEnd dsbe;
81 @Mock(name = "mappingServiceRpc") private static BindingAwareBroker
82 .RpcRegistration<OdlMappingserviceService> mappingServiceRpc;
83 @Mock(name = "keyListener") private static AuthenticationKeyDataListener keyListener;
84 @Mock(name = "mappingListener") private static MappingDataListener mappingListener;
86 private static final String IPV4_STRING = "1.2.3.0";
87 private static final Eid IPV4_EID = LispAddressUtil.asIpv4Eid(IPV4_STRING);
89 private static final RpcResult<Object> RPC_RESULT_SUCCESS = RpcResultBuilder.success().build();
90 private static final MappingAuthkey MAPPING_AUTHKEY = new MappingAuthkeyBuilder()
91 .setKeyString("password")
92 .setKeyType(1).build();
93 private static final SiteId SITE_ID = new SiteId(new byte[] {0, 1, 2, 3, 4, 5, 6, 7});
94 private static final XtrId XTR_ID = new XtrId(new byte[] {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15});
95 private static final Object DUMMY_OBJECT = "dummy_object";
98 * Tests {@link MappingService#addKey} method.
100 * @throws ExecutionException
101 * @throws InterruptedException
104 public void addKeyTest() throws ExecutionException, InterruptedException {
105 final MappingAuthkey mappingAuthkey = new MappingAuthkeyBuilder()
106 .setKeyString("dummy-password")
107 .setKeyType(2).build();
108 final AddKeyInput addKeyInput = new AddKeyInputBuilder()
109 .setMappingAuthkey(mappingAuthkey)
110 .setEid(IPV4_EID).build();
111 Mockito.when(mappingSystem.getAuthenticationKey(IPV4_EID)).thenReturn(MAPPING_AUTHKEY);
114 final RpcResult<Object> rpc = RpcResultBuilder.failed().withError(RpcError.ErrorType.PROTOCOL, "data-exists",
115 "Key already exists! Please use update-key if you want to change it.").build();
116 final RpcError error = rpc.getErrors().iterator().next(); // equals() not implemented int RpcError
119 final Future<RpcResult<Void>> result = mappingService.addKey(addKeyInput);
120 final RpcError errorResult = result.get().getErrors().iterator().next();
122 assertEquals(1, result.get().getErrors().size());
123 assertEquals(error.getMessage(), errorResult.getMessage());
124 assertEquals(error.getApplicationTag(), errorResult.getApplicationTag());
125 assertEquals(error.getCause(), errorResult.getCause());
126 assertEquals(error.getErrorType(), errorResult.getErrorType());
127 assertEquals(error.getInfo(), errorResult.getInfo());
128 assertEquals(error.getTag(), errorResult.getTag());
129 assertEquals(error.getSeverity(), errorResult.getSeverity());
130 assertEquals(rpc.getResult(), result.get().getResult());
131 assertEquals(rpc.isSuccessful(), result.get().isSuccessful());
135 * Tests {@link MappingService#addKey} method with null MappingAuthkey.
137 * @throws ExecutionException
138 * @throws InterruptedException
141 public void addKeyTest_withNullMapAuthkey() throws ExecutionException, InterruptedException {
142 final AddKeyInput addKeyInput = new AddKeyInputBuilder().setEid(IPV4_EID).build();
143 Mockito.when(mappingSystem.getAuthenticationKey(IPV4_EID)).thenReturn(null);
145 final Future<RpcResult<Void>> result = mappingService.addKey(addKeyInput);
146 Mockito.verify(dsbe).addAuthenticationKey(Mockito.any());
148 assertEquals(RPC_RESULT_SUCCESS.getErrors(), result.get().getErrors());
149 assertEquals(RPC_RESULT_SUCCESS.getResult(), result.get().getResult());
150 assertEquals(RPC_RESULT_SUCCESS.isSuccessful(), result.get().isSuccessful());
154 * Tests {@link MappingService#addMapping} method.
156 * @throws ExecutionException
157 * @throws InterruptedException
160 public void addMappingTest() throws ExecutionException, InterruptedException {
161 final MappingRecordBuilder mappingRecordBuilder = getDefaultMappingRecordBuilder();
162 final AddMappingInput addMappingInput = new AddMappingInputBuilder()
163 .setMappingRecord(mappingRecordBuilder.build()).build();
165 final Future<RpcResult<Void>> result = mappingService.addMapping(addMappingInput);
166 Mockito.verify(dsbe).addMapping(RPCInputConvertorUtil.toMapping(addMappingInput));
168 assertEquals(RPC_RESULT_SUCCESS.getErrors(), result.get().getErrors());
169 assertEquals(RPC_RESULT_SUCCESS.getResult(), result.get().getResult());
170 assertEquals(RPC_RESULT_SUCCESS.isSuccessful(), result.get().isSuccessful());
174 * Tests {@link MappingService#getKey} method.
176 * @throws ExecutionException
177 * @throws InterruptedException
180 public void getKeyTest() throws ExecutionException, InterruptedException {
181 final GetKeyInput getKeyInput = new GetKeyInputBuilder().setEid(IPV4_EID).build();
182 final RpcResult<GetKeyOutput> rpcResult = RpcResultBuilder
183 .success(new GetKeyOutputBuilder().setMappingAuthkey(MAPPING_AUTHKEY).build()).build();
185 Mockito.when(mappingSystem.getAuthenticationKey(getKeyInput.getEid())).thenReturn(MAPPING_AUTHKEY);
187 final Future<RpcResult<GetKeyOutput>> result = mappingService.getKey(getKeyInput);
188 assertEquals(rpcResult.getErrors(), result.get().getErrors());
189 assertEquals(rpcResult.getResult(), result.get().getResult());
190 assertEquals(rpcResult.isSuccessful(), result.get().isSuccessful());
194 * Tests {@link MappingService#getKey} method with null MappingAuthkey.
196 * @throws ExecutionException
197 * @throws InterruptedException
200 public void getKeyTest_withNullMappingAuthkey() throws ExecutionException, InterruptedException {
202 final GetKeyInput getKeyInput = new GetKeyInputBuilder().setEid(IPV4_EID).build();
203 Mockito.when(mappingSystem.getAuthenticationKey(getKeyInput.getEid())).thenReturn(null);
205 final RpcResult<Object> rpc = RpcResultBuilder.failed()
206 .withError(RpcError.ErrorType.APPLICATION, "data-missing", "Key was not found in the mapping database")
208 final RpcError error = rpc.getErrors().iterator().next();
211 final Future<RpcResult<GetKeyOutput>> result = mappingService.getKey(getKeyInput);
212 final RpcError errorResult = result.get().getErrors().iterator().next();
214 assertEquals(1, result.get().getErrors().size());
215 assertEquals(error.getMessage(), errorResult.getMessage());
216 assertEquals(error.getApplicationTag(), errorResult.getApplicationTag());
217 assertEquals(error.getCause(), errorResult.getCause());
218 assertEquals(error.getErrorType(), errorResult.getErrorType());
219 assertEquals(error.getInfo(), errorResult.getInfo());
220 assertEquals(error.getTag(), errorResult.getTag());
221 assertEquals(error.getSeverity(), errorResult.getSeverity());
222 assertEquals(rpc.getResult(), result.get().getResult());
223 assertEquals(rpc.isSuccessful(), result.get().isSuccessful());
227 * Tests {@link MappingService#getMapping} method.
229 * @throws ExecutionException
230 * @throws InterruptedException
233 public void getMappingTest() throws ExecutionException, InterruptedException {
235 final GetMappingInput getMappingInput = new GetMappingInputBuilder().setEid(IPV4_EID).build();
236 final MappingRecord mappingRecord = getDefaultMappingRecordBuilder().build();
238 Mockito.when(mappingSystem.getMapping(getMappingInput.getEid())).thenReturn(mappingRecord);
240 final RpcResult<GetMappingOutput> rpc = RpcResultBuilder
241 .success(new GetMappingOutputBuilder().setMappingRecord(mappingRecord)).build();
244 final Future<RpcResult<GetMappingOutput>> result = (mappingService.getMapping(getMappingInput));
245 final RpcResult<GetMappingOutput> rpcResult = result.get();
247 assertEquals(rpc.getResult(), rpcResult.getResult());
248 assertEquals(rpc.getErrors(), rpcResult.getErrors());
249 assertEquals(rpc.isSuccessful(), rpcResult.isSuccessful());
253 * Tests {@link MappingService#getMapping} method with null MappingRecord.
255 * @throws ExecutionException
256 * @throws InterruptedException
259 public void getMappingTest_withNullMapRecord() throws ExecutionException, InterruptedException {
261 final GetMappingInput getMappingInput = new GetMappingInputBuilder().setEid(IPV4_EID).build();
262 Mockito.when(mappingSystem.getMapping(getMappingInput.getEid())).thenReturn(null);
264 final RpcResult<Object> rpc = RpcResultBuilder.failed().withError(RpcError.ErrorType.APPLICATION,
265 "data-missing", "No mapping was found in the mapping database").build();
266 final RpcError error = rpc.getErrors().iterator().next();
269 final Future<RpcResult<GetMappingOutput>> result = (mappingService.getMapping(getMappingInput));
270 final RpcError errorResult = result.get().getErrors().iterator().next();
272 assertEquals(1, result.get().getErrors().size());
273 assertEquals(error.getMessage(), errorResult.getMessage());
274 assertEquals(error.getApplicationTag(), errorResult.getApplicationTag());
275 assertEquals(error.getCause(), errorResult.getCause());
276 assertEquals(error.getErrorType(), errorResult.getErrorType());
277 assertEquals(error.getInfo(), errorResult.getInfo());
278 assertEquals(error.getTag(), errorResult.getTag());
279 assertEquals(error.getSeverity(), errorResult.getSeverity());
280 assertEquals(rpc.getResult(), result.get().getResult());
281 assertEquals(rpc.isSuccessful(), result.get().isSuccessful());
285 * Tests {@link MappingService#removeKey} method.
287 * @throws ExecutionException
288 * @throws InterruptedException
291 public void removeKeyTest() throws ExecutionException, InterruptedException {
292 final RemoveKeyInput removeKeyInput = new RemoveKeyInputBuilder().setEid(IPV4_EID).build();
294 final Future<RpcResult<Void>> result = mappingService.removeKey(removeKeyInput);
295 Mockito.verify(dsbe).removeAuthenticationKey(RPCInputConvertorUtil.toAuthenticationKey(removeKeyInput));
297 assertEquals(RPC_RESULT_SUCCESS.getErrors(), result.get().getErrors());
298 assertEquals(RPC_RESULT_SUCCESS.getResult(), result.get().getResult());
299 assertEquals(RPC_RESULT_SUCCESS.isSuccessful(), result.get().isSuccessful());
303 * Tests {@link MappingService#removeMapping} method.
305 * @throws ExecutionException
306 * @throws InterruptedException
309 public void removeMappingTest() throws ExecutionException, InterruptedException {
310 final RemoveMappingInput removeMappingInput = new RemoveMappingInputBuilder().setEid(IPV4_EID).build();
312 final Future<RpcResult<Void>> result = mappingService.removeMapping(removeMappingInput);
313 Mockito.verify(dsbe).removeMapping(RPCInputConvertorUtil.toMapping(removeMappingInput));
315 assertEquals(RPC_RESULT_SUCCESS.getErrors(), result.get().getErrors());
316 assertEquals(RPC_RESULT_SUCCESS.getResult(), result.get().getResult());
317 assertEquals(RPC_RESULT_SUCCESS.isSuccessful(), result.get().isSuccessful());
321 * Tests {@link MappingService#updateKey} method.
323 * @throws ExecutionException
324 * @throws InterruptedException
327 public void updateKeyTest() throws ExecutionException, InterruptedException {
328 final UpdateKeyInput updateKeyInput = new UpdateKeyInputBuilder().setEid(IPV4_EID).build();
329 Mockito.when(mappingSystem.getAuthenticationKey(IPV4_EID)).thenReturn(MAPPING_AUTHKEY);
331 final Future<RpcResult<Void>> result = mappingService.updateKey(updateKeyInput);
332 Mockito.verify(dsbe).updateAuthenticationKey(RPCInputConvertorUtil.toAuthenticationKey(updateKeyInput));
334 assertEquals(RPC_RESULT_SUCCESS.getErrors(), result.get().getErrors());
335 assertEquals(RPC_RESULT_SUCCESS.getResult(), result.get().getResult());
336 assertEquals(RPC_RESULT_SUCCESS.isSuccessful(), result.get().isSuccessful());
340 * Tests {@link MappingService#updateKey} method with null MappingAuthkey.
342 * @throws ExecutionException
343 * @throws InterruptedException
346 public void updateKeyTest_withNullMapAuthkey() throws ExecutionException, InterruptedException {
347 final UpdateKeyInput updateKeyInput = new UpdateKeyInputBuilder().setEid(IPV4_EID).build();
348 Mockito.when(mappingSystem.getAuthenticationKey(IPV4_EID)).thenReturn(null);
351 final RpcResult<Object> rpc = RpcResultBuilder.failed().withError(RpcError.ErrorType.PROTOCOL, "data-missing",
352 "Key doesn't exist! Please use add-key if you want to create a new authentication key.").build();
353 final RpcError error = rpc.getErrors().iterator().next();
356 final Future<RpcResult<Void>> result = mappingService.updateKey(updateKeyInput);
357 final RpcError errorResult = result.get().getErrors().iterator().next();
359 assertEquals(1, result.get().getErrors().size());
360 assertEquals(error.getMessage(), errorResult.getMessage());
361 assertEquals(error.getApplicationTag(), errorResult.getApplicationTag());
362 assertEquals(error.getCause(), errorResult.getCause());
363 assertEquals(error.getErrorType(), errorResult.getErrorType());
364 assertEquals(error.getInfo(), errorResult.getInfo());
365 assertEquals(error.getTag(), errorResult.getTag());
366 assertEquals(error.getSeverity(), errorResult.getSeverity());
367 assertEquals(rpc.getResult(), result.get().getResult());
368 assertEquals(rpc.isSuccessful(), result.get().isSuccessful());
372 * Tests {@link MappingService#updateMapping} method.
374 * @throws ExecutionException
375 * @throws InterruptedException
378 public void updateMappingTest() throws ExecutionException, InterruptedException {
379 final MappingRecord mappingRecord = getDefaultMappingRecordBuilder().build();
380 final UpdateMappingInput updateMappingInput = new UpdateMappingInputBuilder()
381 .setMappingRecord(mappingRecord).build();
383 final Future<RpcResult<Void>> result = mappingService.updateMapping(updateMappingInput);
384 Mockito.verify(dsbe).updateMapping(RPCInputConvertorUtil.toMapping(updateMappingInput));
386 assertEquals(RPC_RESULT_SUCCESS.getErrors(), result.get().getErrors());
387 assertEquals(RPC_RESULT_SUCCESS.getResult(), result.get().getResult());
388 assertEquals(RPC_RESULT_SUCCESS.isSuccessful(), result.get().isSuccessful());
392 * Tests {@link MappingService#addMapping} method from southbound.
394 * @throws ExecutionException
395 * @throws InterruptedException
398 public void addMappingTest_fromSouthbound() throws ExecutionException, InterruptedException {
400 final MappingRecord data = getDefaultMappingRecordBuilder()
401 .setXtrId(XTR_ID).build();
403 mappingService.addMapping(MappingOrigin.Southbound, IPV4_EID, SITE_ID, data);
405 Mockito.verify(mappingSystem).addMapping(MappingOrigin.Southbound, IPV4_EID, data);
406 Mockito.verify(dsbe).addMapping(DSBEInputUtil.toMapping(MappingOrigin.Southbound, IPV4_EID, SITE_ID, data));
407 Mockito.verify(dsbe).addXtrIdMapping(DSBEInputUtil.toXtrIdMapping(data));
411 * Tests {@link MappingService#addMapping} method from northbound.
413 * @throws ExecutionException
414 * @throws InterruptedException
417 public void addMappingTest_fromNorthbound() throws ExecutionException, InterruptedException {
419 final MappingOrigin origin = MappingOrigin.Northbound;
420 final MappingRecord data = getDefaultMappingRecordBuilder()
421 .setXtrId(XTR_ID).build();
423 mappingService.addMapping(origin, IPV4_EID, SITE_ID, data);
424 Mockito.verify(dsbe).addMapping(DSBEInputUtil.toMapping(origin, IPV4_EID, SITE_ID, data));
425 Mockito.verifyZeroInteractions(mappingSystem);
426 Mockito.verifyNoMoreInteractions(dsbe);
430 * Tests {@link MappingService#getMapping(MappingOrigin, Eid)} method.
433 public void getMappingTest_withOriginAndEid() {
434 Mockito.when(mappingSystem.getMapping(Mockito.any(MappingOrigin.class), Mockito.any(Eid.class)))
435 .thenReturn(DUMMY_OBJECT);
436 assertEquals(DUMMY_OBJECT, mappingService.getMapping(MappingOrigin.Northbound, IPV4_EID));
440 * Tests {@link MappingService#getMapping(Eid)} method.
443 public void getMappingTest_withEid() {
444 Mockito.when(mappingSystem.getMapping(Mockito.any(Eid.class))).thenReturn(DUMMY_OBJECT);
445 assertEquals(DUMMY_OBJECT, mappingService.getMapping(IPV4_EID));
449 * Tests {@link MappingService#getMapping(Eid)} method.
452 public void getMappingTest_withSrcAndDstEid() {
453 Mockito.when(mappingSystem.getMapping(Mockito.any(Eid.class), Mockito.any(Eid.class))).thenReturn(DUMMY_OBJECT);
454 assertEquals(DUMMY_OBJECT, mappingService.getMapping(IPV4_EID, IPV4_EID));
458 * Tests {@link MappingService#removeMapping} method.
461 public void removeMappingTest_withMapOrginAndEid() {
462 mappingService.removeMapping(MappingOrigin.Northbound, IPV4_EID);
463 Mockito.verify(dsbe).removeMapping(DSBEInputUtil.toMapping(MappingOrigin.Northbound, IPV4_EID));
467 * Tests {@link MappingService#addAuthenticationKey} method.
470 public void addAuthenticationKeyTest() {
471 mappingService.addAuthenticationKey(IPV4_EID, MAPPING_AUTHKEY);
472 Mockito.verify(dsbe).addAuthenticationKey(DSBEInputUtil.toAuthenticationKey(IPV4_EID, MAPPING_AUTHKEY));
476 * Tests {@link MappingService#getAuthenticationKey(Eid)} method.
479 public void getAuthenticationKeyTest() {
480 Mockito.when(mappingSystem.getAuthenticationKey(IPV4_EID)).thenReturn(MAPPING_AUTHKEY);
481 assertEquals(MAPPING_AUTHKEY, mappingService.getAuthenticationKey(IPV4_EID));
485 * Tests {@link MappingService#removeAuthenticationKey} method.
488 public void removeAuthenticationKeyTest() {
489 mappingService.removeAuthenticationKey(IPV4_EID);
490 Mockito.verify(dsbe).removeAuthenticationKey(DSBEInputUtil.toAuthenticationKey(IPV4_EID, null));
494 * Tests {@link MappingService#addData} method.
497 public void addDataTest() {
498 mappingService.addData(MappingOrigin.Northbound, IPV4_EID, SubKeys.RECORD, DUMMY_OBJECT);
499 Mockito.verify(mappingSystem).addData(MappingOrigin.Northbound, IPV4_EID, SubKeys.RECORD, DUMMY_OBJECT);
503 * Tests {@link MappingService#getData} method.
506 public void getDataTest() {
507 Mockito.when(mappingSystem.getData(MappingOrigin.Northbound, IPV4_EID, SubKeys.RECORD))
508 .thenReturn(DUMMY_OBJECT);
509 assertEquals(DUMMY_OBJECT, mappingService.getData(MappingOrigin.Northbound, IPV4_EID, SubKeys.RECORD));
513 * Tests {@link MappingService#removeData} method.
516 public void removeDataTest() {
517 mappingService.removeData(MappingOrigin.Northbound, IPV4_EID, SubKeys.RECORD);
518 Mockito.verify(mappingSystem).removeData(MappingOrigin.Northbound, IPV4_EID, SubKeys.RECORD);
522 * Tests {@link MappingService#printMappings} method.
525 public void printMappingsTest() {
526 mappingService.printMappings();
527 Mockito.verify(mappingSystem).printMappings();
531 * Tests {@link MappingService#close} method.
534 public void close() throws Exception {
535 mappingService.close();
536 Mockito.verify(mappingServiceRpc).close();
537 Mockito.verify(keyListener).closeDataChangeListener();
538 Mockito.verify(mappingListener).closeDataChangeListener();
542 * Tests {@link MappingService#cleanCachedMappings} method.
545 public void cleanCachedMappingsTest() throws Exception {
546 mappingService.cleanCachedMappings();
547 Mockito.verify(mappingSystem).cleanCaches();
548 Mockito.verify(dsbe).removeAllDatastoreContent();
552 * Tests {@link MappingService} not implemented methods.
555 public void nullReturnMethodTest() throws ExecutionException, InterruptedException {
556 assertNull(mappingService.removeKeys(Mockito.mock(RemoveKeysInput.class)));
557 assertNull(mappingService.removeMappings(Mockito.mock(RemoveMappingsInput.class)));
558 assertNull(mappingService.getKeys(Mockito.mock(GetKeysInput.class)));
559 assertNull(mappingService.addMappings(Mockito.mock(AddMappingsInput.class)));
560 assertNull(mappingService.updateKeys(Mockito.mock(UpdateKeysInput.class)));
561 assertNull(mappingService.removeAllMappings());
562 assertNull(mappingService.getAllKeys());
563 assertNull(mappingService.updateMappings(Mockito.mock(UpdateMappingsInput.class)));
564 assertNull(mappingService.addKeys(Mockito.mock(AddKeysInput.class)));
565 assertNull(mappingService.getAllMappings());
568 private static MappingRecordBuilder getDefaultMappingRecordBuilder() {
569 return new MappingRecordBuilder()
570 .setAction(MappingRecord.Action.NoAction)
571 .setAuthoritative(false)
572 .setLocatorRecord(new ArrayList<>())
573 .setMapVersion((short) 0)