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;
17 import org.junit.Test;
18 import org.junit.runner.RunWith;
19 import org.mockito.InjectMocks;
20 import org.mockito.Mock;
21 import org.mockito.Mockito;
22 import org.mockito.runners.MockitoJUnitRunner;
23 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
24 import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
25 import org.opendaylight.lispflowmapping.implementation.MappingService;
26 import org.opendaylight.lispflowmapping.implementation.MappingSystem;
27 import org.opendaylight.lispflowmapping.implementation.mdsal.AuthenticationKeyDataListener;
28 import org.opendaylight.lispflowmapping.dsbackend.DataStoreBackEnd;
29 import org.opendaylight.lispflowmapping.implementation.mdsal.MappingDataListener;
30 import org.opendaylight.lispflowmapping.implementation.util.DSBEInputUtil;
31 import org.opendaylight.lispflowmapping.implementation.util.RPCInputConvertorUtil;
32 import org.opendaylight.lispflowmapping.interfaces.dao.ILispDAO;
33 import org.opendaylight.lispflowmapping.interfaces.dao.SubKeys;
34 import org.opendaylight.lispflowmapping.lisp.util.LispAddressUtil;
35 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.SiteId;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.XtrId;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecord;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container
41 .MappingRecordBuilder;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.AddKeyInput;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.AddKeyInputBuilder;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.AddKeysInput;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.AddMappingInput;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.AddMappingInputBuilder;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.AddMappingsInput;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.GetKeyInput;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.GetKeyInputBuilder;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.GetKeyOutput;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.GetKeyOutputBuilder;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.GetKeysInput;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.GetMappingInput;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.GetMappingInputBuilder;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.GetMappingOutput;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.GetMappingOutputBuilder;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.MappingOrigin;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.RemoveKeyInput;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.RemoveKeyInputBuilder;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.RemoveKeysInput;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.RemoveMappingInput;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.RemoveMappingInputBuilder;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.RemoveMappingsInput;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.UpdateKeyInput;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.UpdateKeyInputBuilder;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.UpdateKeysInput;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.UpdateMappingInput;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.UpdateMappingInputBuilder;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.UpdateMappingsInput;
70 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.authkey.container
72 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.authkey.container
73 .MappingAuthkeyBuilder;
74 import org.opendaylight.yangtools.yang.common.RpcError;
75 import org.opendaylight.yangtools.yang.common.RpcResult;
76 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
78 @RunWith(MockitoJUnitRunner.class)
79 public class MappingServiceTest {
81 @Mock(name = "mappingSystem") private static MappingSystem mappingSystem;
82 @Mock(name = "dsbe") private static DataStoreBackEnd dsbe;
83 @Mock(name = "keyListener") private static AuthenticationKeyDataListener keyListener;
84 @Mock(name = "mappingListener") private static MappingDataListener mappingListener;
86 private final DataBroker dataBroker = Mockito.mock(DataBroker.class);
87 private final NotificationPublishService notificationPublishService = Mockito
88 .mock(NotificationPublishService.class);
89 private final ILispDAO lispDAO = Mockito.mock(ILispDAO.class);
92 MappingService mappingService = new MappingService(dataBroker,
93 notificationPublishService, lispDAO);
95 private static final String IPV4_STRING = "1.2.3.0";
96 private static final Eid IPV4_EID = LispAddressUtil.asIpv4Eid(IPV4_STRING);
98 private static final RpcResult<Object> RPC_RESULT_SUCCESS = RpcResultBuilder.success().build();
99 private static final MappingAuthkey MAPPING_AUTHKEY = new MappingAuthkeyBuilder()
100 .setKeyString("password")
101 .setKeyType(1).build();
102 private static final SiteId SITE_ID = new SiteId(new byte[] {0, 1, 2, 3, 4, 5, 6, 7});
103 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});
104 private static final Object DUMMY_OBJECT = "dummy_object";
107 * Tests {@link MappingService#addKey} method.
109 * @throws ExecutionException
110 * @throws InterruptedException
113 public void addKeyTest() throws ExecutionException, InterruptedException {
114 final MappingAuthkey mappingAuthkey = new MappingAuthkeyBuilder()
115 .setKeyString("dummy-password")
116 .setKeyType(2).build();
117 final AddKeyInput addKeyInput = new AddKeyInputBuilder()
118 .setMappingAuthkey(mappingAuthkey)
119 .setEid(IPV4_EID).build();
120 Mockito.when(mappingSystem.getAuthenticationKey(IPV4_EID)).thenReturn(MAPPING_AUTHKEY);
123 final RpcResult<Object> rpc = RpcResultBuilder.failed().withError(RpcError.ErrorType.PROTOCOL, "data-exists",
124 "Key already exists! Please use update-key if you want to change it.").build();
125 final RpcError error = rpc.getErrors().iterator().next(); // equals() not implemented int RpcError
128 final Future<RpcResult<Void>> result = mappingService.addKey(addKeyInput);
129 final RpcError errorResult = result.get().getErrors().iterator().next();
131 assertEquals(1, result.get().getErrors().size());
132 assertEquals(error.getMessage(), errorResult.getMessage());
133 assertEquals(error.getApplicationTag(), errorResult.getApplicationTag());
134 assertEquals(error.getCause(), errorResult.getCause());
135 assertEquals(error.getErrorType(), errorResult.getErrorType());
136 assertEquals(error.getInfo(), errorResult.getInfo());
137 assertEquals(error.getTag(), errorResult.getTag());
138 assertEquals(error.getSeverity(), errorResult.getSeverity());
139 assertEquals(rpc.getResult(), result.get().getResult());
140 assertEquals(rpc.isSuccessful(), result.get().isSuccessful());
144 * Tests {@link MappingService#addKey} method with null MappingAuthkey.
146 * @throws ExecutionException
147 * @throws InterruptedException
150 public void addKeyTest_withNullMapAuthkey() throws ExecutionException, InterruptedException {
151 final AddKeyInput addKeyInput = new AddKeyInputBuilder().setEid(IPV4_EID).build();
152 Mockito.when(mappingSystem.getAuthenticationKey(IPV4_EID)).thenReturn(null);
154 final Future<RpcResult<Void>> result = mappingService.addKey(addKeyInput);
155 Mockito.verify(dsbe).addAuthenticationKey(Mockito.any());
157 assertEquals(RPC_RESULT_SUCCESS.getErrors(), result.get().getErrors());
158 assertEquals(RPC_RESULT_SUCCESS.getResult(), result.get().getResult());
159 assertEquals(RPC_RESULT_SUCCESS.isSuccessful(), result.get().isSuccessful());
163 * Tests {@link MappingService#addMapping} method.
165 * @throws ExecutionException
166 * @throws InterruptedException
169 public void addMappingTest() throws ExecutionException, InterruptedException {
170 final MappingRecordBuilder mappingRecordBuilder = getDefaultMappingRecordBuilder();
171 final AddMappingInput addMappingInput = new AddMappingInputBuilder()
172 .setMappingRecord(mappingRecordBuilder.build()).build();
174 final Future<RpcResult<Void>> result = mappingService.addMapping(addMappingInput);
175 Mockito.verify(dsbe).addMapping(RPCInputConvertorUtil.toMapping(addMappingInput));
177 assertEquals(RPC_RESULT_SUCCESS.getErrors(), result.get().getErrors());
178 assertEquals(RPC_RESULT_SUCCESS.getResult(), result.get().getResult());
179 assertEquals(RPC_RESULT_SUCCESS.isSuccessful(), result.get().isSuccessful());
183 * Tests {@link MappingService#getKey} method.
185 * @throws ExecutionException
186 * @throws InterruptedException
189 public void getKeyTest() throws ExecutionException, InterruptedException {
190 final GetKeyInput getKeyInput = new GetKeyInputBuilder().setEid(IPV4_EID).build();
191 final RpcResult<GetKeyOutput> rpcResult = RpcResultBuilder
192 .success(new GetKeyOutputBuilder().setMappingAuthkey(MAPPING_AUTHKEY).build()).build();
194 Mockito.when(mappingSystem.getAuthenticationKey(getKeyInput.getEid())).thenReturn(MAPPING_AUTHKEY);
196 final Future<RpcResult<GetKeyOutput>> result = mappingService.getKey(getKeyInput);
197 assertEquals(rpcResult.getErrors(), result.get().getErrors());
198 assertEquals(rpcResult.getResult(), result.get().getResult());
199 assertEquals(rpcResult.isSuccessful(), result.get().isSuccessful());
203 * Tests {@link MappingService#getKey} method with null MappingAuthkey.
205 * @throws ExecutionException
206 * @throws InterruptedException
209 public void getKeyTest_withNullMappingAuthkey() throws ExecutionException, InterruptedException {
211 final GetKeyInput getKeyInput = new GetKeyInputBuilder().setEid(IPV4_EID).build();
212 Mockito.when(mappingSystem.getAuthenticationKey(getKeyInput.getEid())).thenReturn(null);
214 final RpcResult<Object> rpc = RpcResultBuilder.failed()
215 .withError(RpcError.ErrorType.APPLICATION, "data-missing", "Key was not found in the mapping database")
217 final RpcError error = rpc.getErrors().iterator().next();
220 final Future<RpcResult<GetKeyOutput>> result = mappingService.getKey(getKeyInput);
221 final RpcError errorResult = result.get().getErrors().iterator().next();
223 assertEquals(1, result.get().getErrors().size());
224 assertEquals(error.getMessage(), errorResult.getMessage());
225 assertEquals(error.getApplicationTag(), errorResult.getApplicationTag());
226 assertEquals(error.getCause(), errorResult.getCause());
227 assertEquals(error.getErrorType(), errorResult.getErrorType());
228 assertEquals(error.getInfo(), errorResult.getInfo());
229 assertEquals(error.getTag(), errorResult.getTag());
230 assertEquals(error.getSeverity(), errorResult.getSeverity());
231 assertEquals(rpc.getResult(), result.get().getResult());
232 assertEquals(rpc.isSuccessful(), result.get().isSuccessful());
236 * Tests {@link MappingService#getMapping} method.
238 * @throws ExecutionException
239 * @throws InterruptedException
242 public void getMappingTest() throws ExecutionException, InterruptedException {
244 final GetMappingInput getMappingInput = new GetMappingInputBuilder().setEid(IPV4_EID).build();
245 final MappingRecord mappingRecord = getDefaultMappingRecordBuilder().build();
246 final MappingRecord nonBinaryMappingRecord = getDefaultMappingRecordBuilder()
247 .setEid(LispAddressUtil.toEid(new Ipv4Address(IPV4_STRING), null)).build();
249 Mockito.when(mappingSystem.getMapping(getMappingInput.getEid())).thenReturn(mappingRecord);
251 final RpcResult<GetMappingOutput> rpc = RpcResultBuilder
252 .success(new GetMappingOutputBuilder().setMappingRecord(nonBinaryMappingRecord)).build();
255 final Future<RpcResult<GetMappingOutput>> result = mappingService.getMapping(getMappingInput);
256 final RpcResult<GetMappingOutput> rpcResult = result.get();
258 assertEquals(rpc.getResult(), rpcResult.getResult());
259 assertEquals(rpc.getErrors(), rpcResult.getErrors());
260 assertEquals(rpc.isSuccessful(), rpcResult.isSuccessful());
264 * Tests {@link MappingService#getMapping} method with null MappingRecord.
266 * @throws ExecutionException
267 * @throws InterruptedException
270 public void getMappingTest_withNullMapRecord() throws ExecutionException, InterruptedException {
272 final GetMappingInput getMappingInput = new GetMappingInputBuilder().setEid(IPV4_EID).build();
273 Mockito.when(mappingSystem.getMapping(getMappingInput.getEid())).thenReturn(null);
275 final RpcResult<Object> rpc = RpcResultBuilder.failed().withError(RpcError.ErrorType.APPLICATION,
276 "data-missing", "No mapping was found in the mapping database").build();
277 final RpcError error = rpc.getErrors().iterator().next();
280 final Future<RpcResult<GetMappingOutput>> result = (mappingService.getMapping(getMappingInput));
281 final RpcError errorResult = result.get().getErrors().iterator().next();
283 assertEquals(1, result.get().getErrors().size());
284 assertEquals(error.getMessage(), errorResult.getMessage());
285 assertEquals(error.getApplicationTag(), errorResult.getApplicationTag());
286 assertEquals(error.getCause(), errorResult.getCause());
287 assertEquals(error.getErrorType(), errorResult.getErrorType());
288 assertEquals(error.getInfo(), errorResult.getInfo());
289 assertEquals(error.getTag(), errorResult.getTag());
290 assertEquals(error.getSeverity(), errorResult.getSeverity());
291 assertEquals(rpc.getResult(), result.get().getResult());
292 assertEquals(rpc.isSuccessful(), result.get().isSuccessful());
296 * Tests {@link MappingService#removeKey} method.
298 * @throws ExecutionException
299 * @throws InterruptedException
302 public void removeKeyTest() throws ExecutionException, InterruptedException {
303 final RemoveKeyInput removeKeyInput = new RemoveKeyInputBuilder().setEid(IPV4_EID).build();
305 final Future<RpcResult<Void>> result = mappingService.removeKey(removeKeyInput);
306 Mockito.verify(dsbe).removeAuthenticationKey(RPCInputConvertorUtil.toAuthenticationKey(removeKeyInput));
308 assertEquals(RPC_RESULT_SUCCESS.getErrors(), result.get().getErrors());
309 assertEquals(RPC_RESULT_SUCCESS.getResult(), result.get().getResult());
310 assertEquals(RPC_RESULT_SUCCESS.isSuccessful(), result.get().isSuccessful());
314 * Tests {@link MappingService#removeMapping} method.
316 * @throws ExecutionException
317 * @throws InterruptedException
320 public void removeMappingTest() throws ExecutionException, InterruptedException {
321 final RemoveMappingInput removeMappingInput = new RemoveMappingInputBuilder().setEid(IPV4_EID).build();
323 final Future<RpcResult<Void>> result = mappingService.removeMapping(removeMappingInput);
324 Mockito.verify(dsbe).removeMapping(RPCInputConvertorUtil.toMapping(removeMappingInput));
326 assertEquals(RPC_RESULT_SUCCESS.getErrors(), result.get().getErrors());
327 assertEquals(RPC_RESULT_SUCCESS.getResult(), result.get().getResult());
328 assertEquals(RPC_RESULT_SUCCESS.isSuccessful(), result.get().isSuccessful());
332 * Tests {@link MappingService#updateKey} method.
334 * @throws ExecutionException
335 * @throws InterruptedException
338 public void updateKeyTest() throws ExecutionException, InterruptedException {
339 final UpdateKeyInput updateKeyInput = new UpdateKeyInputBuilder().setEid(IPV4_EID).build();
340 Mockito.when(mappingSystem.getAuthenticationKey(IPV4_EID)).thenReturn(MAPPING_AUTHKEY);
342 final Future<RpcResult<Void>> result = mappingService.updateKey(updateKeyInput);
343 Mockito.verify(dsbe).updateAuthenticationKey(RPCInputConvertorUtil.toAuthenticationKey(updateKeyInput));
345 assertEquals(RPC_RESULT_SUCCESS.getErrors(), result.get().getErrors());
346 assertEquals(RPC_RESULT_SUCCESS.getResult(), result.get().getResult());
347 assertEquals(RPC_RESULT_SUCCESS.isSuccessful(), result.get().isSuccessful());
351 * Tests {@link MappingService#updateKey} method with null MappingAuthkey.
353 * @throws ExecutionException
354 * @throws InterruptedException
357 public void updateKeyTest_withNullMapAuthkey() throws ExecutionException, InterruptedException {
358 final UpdateKeyInput updateKeyInput = new UpdateKeyInputBuilder().setEid(IPV4_EID).build();
359 Mockito.when(mappingSystem.getAuthenticationKey(IPV4_EID)).thenReturn(null);
362 final RpcResult<Object> rpc = RpcResultBuilder.failed().withError(RpcError.ErrorType.PROTOCOL, "data-missing",
363 "Key doesn't exist! Please use add-key if you want to create a new authentication key.").build();
364 final RpcError error = rpc.getErrors().iterator().next();
367 final Future<RpcResult<Void>> result = mappingService.updateKey(updateKeyInput);
368 final RpcError errorResult = result.get().getErrors().iterator().next();
370 assertEquals(1, result.get().getErrors().size());
371 assertEquals(error.getMessage(), errorResult.getMessage());
372 assertEquals(error.getApplicationTag(), errorResult.getApplicationTag());
373 assertEquals(error.getCause(), errorResult.getCause());
374 assertEquals(error.getErrorType(), errorResult.getErrorType());
375 assertEquals(error.getInfo(), errorResult.getInfo());
376 assertEquals(error.getTag(), errorResult.getTag());
377 assertEquals(error.getSeverity(), errorResult.getSeverity());
378 assertEquals(rpc.getResult(), result.get().getResult());
379 assertEquals(rpc.isSuccessful(), result.get().isSuccessful());
383 * Tests {@link MappingService#updateMapping} method.
385 * @throws ExecutionException
386 * @throws InterruptedException
389 public void updateMappingTest() throws ExecutionException, InterruptedException {
390 final MappingRecord mappingRecord = getDefaultMappingRecordBuilder().build();
391 final UpdateMappingInput updateMappingInput = new UpdateMappingInputBuilder()
392 .setMappingRecord(mappingRecord).build();
394 final Future<RpcResult<Void>> result = mappingService.updateMapping(updateMappingInput);
395 Mockito.verify(dsbe).updateMapping(RPCInputConvertorUtil.toMapping(updateMappingInput));
397 assertEquals(RPC_RESULT_SUCCESS.getErrors(), result.get().getErrors());
398 assertEquals(RPC_RESULT_SUCCESS.getResult(), result.get().getResult());
399 assertEquals(RPC_RESULT_SUCCESS.isSuccessful(), result.get().isSuccessful());
403 * Tests {@link MappingService#addMapping} method from southbound.
405 * @throws ExecutionException
406 * @throws InterruptedException
409 public void addMappingTest_fromSouthbound() throws ExecutionException, InterruptedException {
411 final MappingRecord data = getDefaultMappingRecordBuilder()
412 .setXtrId(XTR_ID).build();
414 mappingService.addMapping(MappingOrigin.Southbound, IPV4_EID, SITE_ID, data, false);
416 Mockito.verify(mappingSystem).addMapping(MappingOrigin.Southbound, IPV4_EID, data, false);
417 Mockito.verify(dsbe).addMapping(DSBEInputUtil.toMapping(MappingOrigin.Southbound, IPV4_EID, SITE_ID, data));
418 Mockito.verify(dsbe).addXtrIdMapping(DSBEInputUtil.toXtrIdMapping(data));
422 * Tests {@link MappingService#addMapping} method from northbound.
424 * @throws ExecutionException
425 * @throws InterruptedException
428 public void addMappingTest_fromNorthbound() throws ExecutionException, InterruptedException {
430 final MappingOrigin origin = MappingOrigin.Northbound;
431 final MappingRecord data = getDefaultMappingRecordBuilder()
432 .setXtrId(XTR_ID).build();
434 mappingService.addMapping(origin, IPV4_EID, SITE_ID, data, false);
435 Mockito.verify(dsbe).addMapping(DSBEInputUtil.toMapping(origin, IPV4_EID, SITE_ID, data));
436 Mockito.verifyZeroInteractions(mappingSystem);
437 Mockito.verifyNoMoreInteractions(dsbe);
441 * Tests {@link MappingService#getMapping(MappingOrigin, Eid)} method.
444 public void getMappingTest_withOriginAndEid() {
445 Mockito.when(mappingSystem.getMapping(Mockito.any(MappingOrigin.class), Mockito.any(Eid.class)))
446 .thenReturn(DUMMY_OBJECT);
447 assertEquals(DUMMY_OBJECT, mappingService.getMapping(MappingOrigin.Northbound, IPV4_EID));
451 * Tests {@link MappingService#getMapping(Eid)} method.
454 public void getMappingTest_withEid() {
455 Mockito.when(mappingSystem.getMapping(Mockito.any(Eid.class))).thenReturn(DUMMY_OBJECT);
456 assertEquals(DUMMY_OBJECT, mappingService.getMapping(IPV4_EID));
460 * Tests {@link MappingService#getMapping(Eid)} method.
463 public void getMappingTest_withSrcAndDstEid() {
464 Mockito.when(mappingSystem.getMapping(Mockito.any(Eid.class), Mockito.any(Eid.class))).thenReturn(DUMMY_OBJECT);
465 assertEquals(DUMMY_OBJECT, mappingService.getMapping(IPV4_EID, IPV4_EID));
469 * Tests {@link MappingService#removeMapping} method.
472 public void removeMappingTest_withMapOrginAndEid() {
473 mappingService.removeMapping(MappingOrigin.Northbound, IPV4_EID);
474 Mockito.verify(dsbe).removeMapping(DSBEInputUtil.toMapping(MappingOrigin.Northbound, IPV4_EID));
478 * Tests {@link MappingService#addAuthenticationKey} method.
481 public void addAuthenticationKeyTest() {
482 mappingService.addAuthenticationKey(IPV4_EID, MAPPING_AUTHKEY);
483 Mockito.verify(dsbe).addAuthenticationKey(DSBEInputUtil.toAuthenticationKey(IPV4_EID, MAPPING_AUTHKEY));
487 * Tests {@link MappingService#getAuthenticationKey(Eid)} method.
490 public void getAuthenticationKeyTest() {
491 Mockito.when(mappingSystem.getAuthenticationKey(IPV4_EID)).thenReturn(MAPPING_AUTHKEY);
492 assertEquals(MAPPING_AUTHKEY, mappingService.getAuthenticationKey(IPV4_EID));
496 * Tests {@link MappingService#removeAuthenticationKey} method.
499 public void removeAuthenticationKeyTest() {
500 mappingService.removeAuthenticationKey(IPV4_EID);
501 Mockito.verify(dsbe).removeAuthenticationKey(DSBEInputUtil.toAuthenticationKey(IPV4_EID, null));
505 * Tests {@link MappingService#addData} method.
508 public void addDataTest() {
509 mappingService.addData(MappingOrigin.Northbound, IPV4_EID, SubKeys.RECORD, DUMMY_OBJECT);
510 Mockito.verify(mappingSystem).addData(MappingOrigin.Northbound, IPV4_EID, SubKeys.RECORD, DUMMY_OBJECT);
514 * Tests {@link MappingService#getData} method.
517 public void getDataTest() {
518 Mockito.when(mappingSystem.getData(MappingOrigin.Northbound, IPV4_EID, SubKeys.RECORD))
519 .thenReturn(DUMMY_OBJECT);
520 assertEquals(DUMMY_OBJECT, mappingService.getData(MappingOrigin.Northbound, IPV4_EID, SubKeys.RECORD));
524 * Tests {@link MappingService#removeData} method.
527 public void removeDataTest() {
528 mappingService.removeData(MappingOrigin.Northbound, IPV4_EID, SubKeys.RECORD);
529 Mockito.verify(mappingSystem).removeData(MappingOrigin.Northbound, IPV4_EID, SubKeys.RECORD);
533 * Tests {@link MappingService#printMappings} method.
536 public void printMappingsTest() {
537 mappingService.printMappings();
538 Mockito.verify(mappingSystem).printMappings();
542 * Tests {@link MappingService#close} method.
545 public void close() throws Exception {
546 mappingService.close();
547 Mockito.verify(keyListener).closeDataChangeListener();
548 Mockito.verify(mappingListener).closeDataChangeListener();
552 * Tests {@link MappingService#cleanCachedMappings} method.
555 public void cleanCachedMappingsTest() throws Exception {
556 mappingService.cleanCachedMappings();
557 Mockito.verify(mappingSystem).cleanCaches();
558 Mockito.verify(dsbe).removeAllDatastoreContent();
562 * Tests {@link MappingService} not implemented methods.
565 public void nullReturnMethodTest() throws ExecutionException, InterruptedException {
566 assertNull(mappingService.removeKeys(Mockito.mock(RemoveKeysInput.class)));
567 assertNull(mappingService.removeMappings(Mockito.mock(RemoveMappingsInput.class)));
568 assertNull(mappingService.getKeys(Mockito.mock(GetKeysInput.class)));
569 assertNull(mappingService.addMappings(Mockito.mock(AddMappingsInput.class)));
570 assertNull(mappingService.updateKeys(Mockito.mock(UpdateKeysInput.class)));
571 assertNull(mappingService.removeAllMappings());
572 assertNull(mappingService.getAllKeys());
573 assertNull(mappingService.updateMappings(Mockito.mock(UpdateMappingsInput.class)));
574 assertNull(mappingService.addKeys(Mockito.mock(AddKeysInput.class)));
575 assertNull(mappingService.getAllMappings());
578 private static MappingRecordBuilder getDefaultMappingRecordBuilder() {
579 return new MappingRecordBuilder()
580 .setAction(MappingRecord.Action.NoAction)
581 .setAuthoritative(false)
582 .setLocatorRecord(new ArrayList<>())
583 .setMapVersion((short) 0)