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.md.sal.binding.api.DataBroker;
23 import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
24 import org.opendaylight.lispflowmapping.dsbackend.DataStoreBackEnd;
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.implementation.mdsal.MappingDataListener;
29 import org.opendaylight.lispflowmapping.implementation.util.DSBEInputUtil;
30 import org.opendaylight.lispflowmapping.implementation.util.RPCInputConvertorUtil;
31 import org.opendaylight.lispflowmapping.interfaces.dao.ILispDAO;
32 import org.opendaylight.lispflowmapping.interfaces.dao.SubKeys;
33 import org.opendaylight.lispflowmapping.lisp.util.LispAddressUtil;
34 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.SiteId;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.XtrId;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.authkey.container.MappingAuthkey;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.authkey.container.MappingAuthkeyBuilder;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecord;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.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.yangtools.yang.common.RpcError;
71 import org.opendaylight.yangtools.yang.common.RpcResult;
72 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
74 @RunWith(MockitoJUnitRunner.class)
75 public class MappingServiceTest {
77 @Mock(name = "mappingSystem") private static MappingSystem mappingSystem;
78 @Mock(name = "dsbe") private static DataStoreBackEnd dsbe;
79 @Mock(name = "keyListener") private static AuthenticationKeyDataListener keyListener;
80 @Mock(name = "mappingListener") private static MappingDataListener mappingListener;
82 private final DataBroker dataBroker = Mockito.mock(DataBroker.class);
83 private final NotificationPublishService notificationPublishService = Mockito
84 .mock(NotificationPublishService.class);
85 private final ILispDAO lispDAO = Mockito.mock(ILispDAO.class);
88 MappingService mappingService = new MappingService(dataBroker,
89 notificationPublishService, lispDAO);
91 private static final String IPV4_STRING = "1.2.3.0";
92 private static final Eid IPV4_EID = LispAddressUtil.asIpv4Eid(IPV4_STRING);
94 private static final RpcResult<Object> RPC_RESULT_SUCCESS = RpcResultBuilder.success().build();
95 private static final MappingAuthkey MAPPING_AUTHKEY = new MappingAuthkeyBuilder()
96 .setKeyString("password")
97 .setKeyType(1).build();
98 private static final SiteId SITE_ID = new SiteId(new byte[] {0, 1, 2, 3, 4, 5, 6, 7});
99 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});
100 private static final Object DUMMY_OBJECT = "dummy_object";
103 * Tests {@link MappingService#addKey} method.
106 public void addKeyTest() throws ExecutionException, InterruptedException {
107 final MappingAuthkey mappingAuthkey = new MappingAuthkeyBuilder()
108 .setKeyString("dummy-password")
109 .setKeyType(2).build();
110 final AddKeyInput addKeyInput = new AddKeyInputBuilder()
111 .setMappingAuthkey(mappingAuthkey)
112 .setEid(IPV4_EID).build();
113 Mockito.when(mappingSystem.getAuthenticationKey(IPV4_EID)).thenReturn(MAPPING_AUTHKEY);
116 final RpcResult<Object> rpc = RpcResultBuilder.failed().withError(RpcError.ErrorType.PROTOCOL, "data-exists",
117 "Key already exists! Please use update-key if you want to change it.").build();
118 final RpcError error = rpc.getErrors().iterator().next(); // equals() not implemented int RpcError
121 final Future<RpcResult<Void>> result = mappingService.addKey(addKeyInput);
122 final RpcError errorResult = result.get().getErrors().iterator().next();
124 assertEquals(1, result.get().getErrors().size());
125 assertEquals(error.getMessage(), errorResult.getMessage());
126 assertEquals(error.getApplicationTag(), errorResult.getApplicationTag());
127 assertEquals(error.getCause(), errorResult.getCause());
128 assertEquals(error.getErrorType(), errorResult.getErrorType());
129 assertEquals(error.getInfo(), errorResult.getInfo());
130 assertEquals(error.getTag(), errorResult.getTag());
131 assertEquals(error.getSeverity(), errorResult.getSeverity());
132 assertEquals(rpc.getResult(), result.get().getResult());
133 assertEquals(rpc.isSuccessful(), result.get().isSuccessful());
137 * Tests {@link MappingService#addKey} method with null MappingAuthkey.
140 public void addKeyTest_withNullMapAuthkey() throws ExecutionException, InterruptedException {
141 final AddKeyInput addKeyInput = new AddKeyInputBuilder().setEid(IPV4_EID).build();
142 Mockito.when(mappingSystem.getAuthenticationKey(IPV4_EID)).thenReturn(null);
144 final Future<RpcResult<Void>> result = mappingService.addKey(addKeyInput);
145 Mockito.verify(dsbe).addAuthenticationKey(Mockito.any());
147 assertEquals(RPC_RESULT_SUCCESS.getErrors(), result.get().getErrors());
148 assertEquals(RPC_RESULT_SUCCESS.getResult(), result.get().getResult());
149 assertEquals(RPC_RESULT_SUCCESS.isSuccessful(), result.get().isSuccessful());
153 * Tests {@link MappingService#addMapping} method.
156 public void addMappingTest() throws ExecutionException, InterruptedException {
157 final MappingRecordBuilder mappingRecordBuilder = getDefaultMappingRecordBuilder();
158 final AddMappingInput addMappingInput = new AddMappingInputBuilder()
159 .setMappingRecord(mappingRecordBuilder.build()).build();
161 final Future<RpcResult<Void>> result = mappingService.addMapping(addMappingInput);
162 Mockito.verify(dsbe).addMapping(RPCInputConvertorUtil.toMapping(addMappingInput));
164 assertEquals(RPC_RESULT_SUCCESS.getErrors(), result.get().getErrors());
165 assertEquals(RPC_RESULT_SUCCESS.getResult(), result.get().getResult());
166 assertEquals(RPC_RESULT_SUCCESS.isSuccessful(), result.get().isSuccessful());
170 * Tests {@link MappingService#getKey} method.
173 public void getKeyTest() throws ExecutionException, InterruptedException {
174 final GetKeyInput getKeyInput = new GetKeyInputBuilder().setEid(IPV4_EID).build();
175 final RpcResult<GetKeyOutput> rpcResult = RpcResultBuilder
176 .success(new GetKeyOutputBuilder().setMappingAuthkey(MAPPING_AUTHKEY).build()).build();
178 Mockito.when(mappingSystem.getAuthenticationKey(getKeyInput.getEid())).thenReturn(MAPPING_AUTHKEY);
180 final Future<RpcResult<GetKeyOutput>> result = mappingService.getKey(getKeyInput);
181 assertEquals(rpcResult.getErrors(), result.get().getErrors());
182 assertEquals(rpcResult.getResult(), result.get().getResult());
183 assertEquals(rpcResult.isSuccessful(), result.get().isSuccessful());
187 * Tests {@link MappingService#getKey} method with null MappingAuthkey.
190 public void getKeyTest_withNullMappingAuthkey() throws ExecutionException, InterruptedException {
192 final GetKeyInput getKeyInput = new GetKeyInputBuilder().setEid(IPV4_EID).build();
193 Mockito.when(mappingSystem.getAuthenticationKey(getKeyInput.getEid())).thenReturn(null);
195 final RpcResult<Object> rpc = RpcResultBuilder.failed()
196 .withError(RpcError.ErrorType.APPLICATION, "data-missing", "Key was not found in the mapping database")
198 final RpcError error = rpc.getErrors().iterator().next();
201 final Future<RpcResult<GetKeyOutput>> result = mappingService.getKey(getKeyInput);
202 final RpcError errorResult = result.get().getErrors().iterator().next();
204 assertEquals(1, result.get().getErrors().size());
205 assertEquals(error.getMessage(), errorResult.getMessage());
206 assertEquals(error.getApplicationTag(), errorResult.getApplicationTag());
207 assertEquals(error.getCause(), errorResult.getCause());
208 assertEquals(error.getErrorType(), errorResult.getErrorType());
209 assertEquals(error.getInfo(), errorResult.getInfo());
210 assertEquals(error.getTag(), errorResult.getTag());
211 assertEquals(error.getSeverity(), errorResult.getSeverity());
212 assertEquals(rpc.getResult(), result.get().getResult());
213 assertEquals(rpc.isSuccessful(), result.get().isSuccessful());
217 * Tests {@link MappingService#getMapping} method.
220 public void getMappingTest() throws ExecutionException, InterruptedException {
222 final GetMappingInput getMappingInput = new GetMappingInputBuilder().setEid(IPV4_EID).build();
223 final MappingRecord mappingRecord = getDefaultMappingRecordBuilder().build();
224 final MappingRecord nonBinaryMappingRecord = getDefaultMappingRecordBuilder()
225 .setEid(LispAddressUtil.toEid(new Ipv4Address(IPV4_STRING), null)).build();
227 Mockito.when(mappingSystem.getMapping(getMappingInput.getEid())).thenReturn(mappingRecord);
229 final RpcResult<GetMappingOutput> rpc = RpcResultBuilder
230 .success(new GetMappingOutputBuilder().setMappingRecord(nonBinaryMappingRecord)).build();
233 final Future<RpcResult<GetMappingOutput>> result = mappingService.getMapping(getMappingInput);
234 final RpcResult<GetMappingOutput> rpcResult = result.get();
236 assertEquals(rpc.getResult(), rpcResult.getResult());
237 assertEquals(rpc.getErrors(), rpcResult.getErrors());
238 assertEquals(rpc.isSuccessful(), rpcResult.isSuccessful());
242 * Tests {@link MappingService#getMapping} method with null MappingRecord.
245 public void getMappingTest_withNullMapRecord() throws ExecutionException, InterruptedException {
247 final GetMappingInput getMappingInput = new GetMappingInputBuilder().setEid(IPV4_EID).build();
248 Mockito.when(mappingSystem.getMapping(getMappingInput.getEid())).thenReturn(null);
250 final RpcResult<Object> rpc = RpcResultBuilder.failed().withError(RpcError.ErrorType.APPLICATION,
251 "data-missing", "No mapping was found in the mapping database").build();
252 final RpcError error = rpc.getErrors().iterator().next();
255 final Future<RpcResult<GetMappingOutput>> result = (mappingService.getMapping(getMappingInput));
256 final RpcError errorResult = result.get().getErrors().iterator().next();
258 assertEquals(1, result.get().getErrors().size());
259 assertEquals(error.getMessage(), errorResult.getMessage());
260 assertEquals(error.getApplicationTag(), errorResult.getApplicationTag());
261 assertEquals(error.getCause(), errorResult.getCause());
262 assertEquals(error.getErrorType(), errorResult.getErrorType());
263 assertEquals(error.getInfo(), errorResult.getInfo());
264 assertEquals(error.getTag(), errorResult.getTag());
265 assertEquals(error.getSeverity(), errorResult.getSeverity());
266 assertEquals(rpc.getResult(), result.get().getResult());
267 assertEquals(rpc.isSuccessful(), result.get().isSuccessful());
271 * Tests {@link MappingService#removeKey} method.
274 public void removeKeyTest() throws ExecutionException, InterruptedException {
275 final RemoveKeyInput removeKeyInput = new RemoveKeyInputBuilder().setEid(IPV4_EID).build();
277 final Future<RpcResult<Void>> result = mappingService.removeKey(removeKeyInput);
278 Mockito.verify(dsbe).removeAuthenticationKey(RPCInputConvertorUtil.toAuthenticationKey(removeKeyInput));
280 assertEquals(RPC_RESULT_SUCCESS.getErrors(), result.get().getErrors());
281 assertEquals(RPC_RESULT_SUCCESS.getResult(), result.get().getResult());
282 assertEquals(RPC_RESULT_SUCCESS.isSuccessful(), result.get().isSuccessful());
286 * Tests {@link MappingService#removeMapping} method.
289 public void removeMappingTest() throws ExecutionException, InterruptedException {
290 final RemoveMappingInput removeMappingInput = new RemoveMappingInputBuilder().setEid(IPV4_EID).build();
292 final Future<RpcResult<Void>> result = mappingService.removeMapping(removeMappingInput);
293 Mockito.verify(dsbe).removeMapping(RPCInputConvertorUtil.toMapping(removeMappingInput));
295 assertEquals(RPC_RESULT_SUCCESS.getErrors(), result.get().getErrors());
296 assertEquals(RPC_RESULT_SUCCESS.getResult(), result.get().getResult());
297 assertEquals(RPC_RESULT_SUCCESS.isSuccessful(), result.get().isSuccessful());
301 * Tests {@link MappingService#updateKey} method.
304 public void updateKeyTest() throws ExecutionException, InterruptedException {
305 final UpdateKeyInput updateKeyInput = new UpdateKeyInputBuilder().setEid(IPV4_EID).build();
306 Mockito.when(mappingSystem.getAuthenticationKey(IPV4_EID)).thenReturn(MAPPING_AUTHKEY);
308 final Future<RpcResult<Void>> result = mappingService.updateKey(updateKeyInput);
309 Mockito.verify(dsbe).updateAuthenticationKey(RPCInputConvertorUtil.toAuthenticationKey(updateKeyInput));
311 assertEquals(RPC_RESULT_SUCCESS.getErrors(), result.get().getErrors());
312 assertEquals(RPC_RESULT_SUCCESS.getResult(), result.get().getResult());
313 assertEquals(RPC_RESULT_SUCCESS.isSuccessful(), result.get().isSuccessful());
317 * Tests {@link MappingService#updateKey} method with null MappingAuthkey.
320 public void updateKeyTest_withNullMapAuthkey() throws ExecutionException, InterruptedException {
321 final UpdateKeyInput updateKeyInput = new UpdateKeyInputBuilder().setEid(IPV4_EID).build();
322 Mockito.when(mappingSystem.getAuthenticationKey(IPV4_EID)).thenReturn(null);
325 final RpcResult<Object> rpc = RpcResultBuilder.failed().withError(RpcError.ErrorType.PROTOCOL, "data-missing",
326 "Key doesn't exist! Please use add-key if you want to create a new authentication key.").build();
327 final RpcError error = rpc.getErrors().iterator().next();
330 final Future<RpcResult<Void>> result = mappingService.updateKey(updateKeyInput);
331 final RpcError errorResult = result.get().getErrors().iterator().next();
333 assertEquals(1, result.get().getErrors().size());
334 assertEquals(error.getMessage(), errorResult.getMessage());
335 assertEquals(error.getApplicationTag(), errorResult.getApplicationTag());
336 assertEquals(error.getCause(), errorResult.getCause());
337 assertEquals(error.getErrorType(), errorResult.getErrorType());
338 assertEquals(error.getInfo(), errorResult.getInfo());
339 assertEquals(error.getTag(), errorResult.getTag());
340 assertEquals(error.getSeverity(), errorResult.getSeverity());
341 assertEquals(rpc.getResult(), result.get().getResult());
342 assertEquals(rpc.isSuccessful(), result.get().isSuccessful());
346 * Tests {@link MappingService#updateMapping} method.
349 public void updateMappingTest() throws ExecutionException, InterruptedException {
350 final MappingRecord mappingRecord = getDefaultMappingRecordBuilder().build();
351 final UpdateMappingInput updateMappingInput = new UpdateMappingInputBuilder()
352 .setMappingRecord(mappingRecord).build();
354 final Future<RpcResult<Void>> result = mappingService.updateMapping(updateMappingInput);
355 Mockito.verify(dsbe).updateMapping(RPCInputConvertorUtil.toMapping(updateMappingInput));
357 assertEquals(RPC_RESULT_SUCCESS.getErrors(), result.get().getErrors());
358 assertEquals(RPC_RESULT_SUCCESS.getResult(), result.get().getResult());
359 assertEquals(RPC_RESULT_SUCCESS.isSuccessful(), result.get().isSuccessful());
363 * Tests {@link MappingService#addMapping} method from southbound.
366 public void addMappingTest_fromSouthbound() throws ExecutionException, InterruptedException {
368 final MappingRecord data = getDefaultMappingRecordBuilder()
369 .setXtrId(XTR_ID).build();
371 mappingService.addMapping(MappingOrigin.Southbound, IPV4_EID, SITE_ID, data, false);
373 Mockito.verify(mappingSystem).addMapping(MappingOrigin.Southbound, IPV4_EID, data, false);
374 Mockito.verify(dsbe).addMapping(DSBEInputUtil.toMapping(MappingOrigin.Southbound, IPV4_EID, SITE_ID, data));
375 Mockito.verify(dsbe).addXtrIdMapping(DSBEInputUtil.toXtrIdMapping(data));
379 * Tests {@link MappingService#addMapping} method from northbound.
382 public void addMappingTest_fromNorthbound() throws ExecutionException, InterruptedException {
384 final MappingOrigin origin = MappingOrigin.Northbound;
385 final MappingRecord data = getDefaultMappingRecordBuilder()
386 .setXtrId(XTR_ID).build();
388 mappingService.addMapping(origin, IPV4_EID, SITE_ID, data, false);
389 Mockito.verify(dsbe).addMapping(DSBEInputUtil.toMapping(origin, IPV4_EID, SITE_ID, data));
390 Mockito.verifyZeroInteractions(mappingSystem);
391 Mockito.verifyNoMoreInteractions(dsbe);
395 * Tests {@link MappingService#getMapping(MappingOrigin, Eid)} method.
398 public void getMappingTest_withOriginAndEid() {
399 Mockito.when(mappingSystem.getMapping(Mockito.any(MappingOrigin.class), Mockito.any(Eid.class)))
400 .thenReturn(DUMMY_OBJECT);
401 assertEquals(DUMMY_OBJECT, mappingService.getMapping(MappingOrigin.Northbound, IPV4_EID));
405 * Tests {@link MappingService#getMapping(Eid)} method.
408 public void getMappingTest_withEid() {
409 Mockito.when(mappingSystem.getMapping(Mockito.any(Eid.class))).thenReturn(DUMMY_OBJECT);
410 assertEquals(DUMMY_OBJECT, mappingService.getMapping(IPV4_EID));
414 * Tests {@link MappingService#getMapping(Eid)} method.
417 public void getMappingTest_withSrcAndDstEid() {
418 Mockito.when(mappingSystem.getMapping(Mockito.any(Eid.class), Mockito.any(Eid.class))).thenReturn(DUMMY_OBJECT);
419 assertEquals(DUMMY_OBJECT, mappingService.getMapping(IPV4_EID, IPV4_EID));
423 * Tests {@link MappingService#removeMapping} method.
426 public void removeMappingTest_withMapOrginAndEid() {
427 mappingService.removeMapping(MappingOrigin.Northbound, IPV4_EID);
428 Mockito.verify(dsbe).removeMapping(DSBEInputUtil.toMapping(MappingOrigin.Northbound, IPV4_EID));
432 * Tests {@link MappingService#addAuthenticationKey} method.
435 public void addAuthenticationKeyTest() {
436 mappingService.addAuthenticationKey(IPV4_EID, MAPPING_AUTHKEY);
437 Mockito.verify(dsbe).addAuthenticationKey(DSBEInputUtil.toAuthenticationKey(IPV4_EID, MAPPING_AUTHKEY));
441 * Tests {@link MappingService#getAuthenticationKey(Eid)} method.
444 public void getAuthenticationKeyTest() {
445 Mockito.when(mappingSystem.getAuthenticationKey(IPV4_EID)).thenReturn(MAPPING_AUTHKEY);
446 assertEquals(MAPPING_AUTHKEY, mappingService.getAuthenticationKey(IPV4_EID));
450 * Tests {@link MappingService#removeAuthenticationKey} method.
453 public void removeAuthenticationKeyTest() {
454 mappingService.removeAuthenticationKey(IPV4_EID);
455 Mockito.verify(dsbe).removeAuthenticationKey(DSBEInputUtil.toAuthenticationKey(IPV4_EID, null));
459 * Tests {@link MappingService#addData} method.
462 public void addDataTest() {
463 mappingService.addData(MappingOrigin.Northbound, IPV4_EID, SubKeys.RECORD, DUMMY_OBJECT);
464 Mockito.verify(mappingSystem).addData(MappingOrigin.Northbound, IPV4_EID, SubKeys.RECORD, DUMMY_OBJECT);
468 * Tests {@link MappingService#getData} method.
471 public void getDataTest() {
472 Mockito.when(mappingSystem.getData(MappingOrigin.Northbound, IPV4_EID, SubKeys.RECORD))
473 .thenReturn(DUMMY_OBJECT);
474 assertEquals(DUMMY_OBJECT, mappingService.getData(MappingOrigin.Northbound, IPV4_EID, SubKeys.RECORD));
478 * Tests {@link MappingService#removeData} method.
481 public void removeDataTest() {
482 mappingService.removeData(MappingOrigin.Northbound, IPV4_EID, SubKeys.RECORD);
483 Mockito.verify(mappingSystem).removeData(MappingOrigin.Northbound, IPV4_EID, SubKeys.RECORD);
487 * Tests {@link MappingService#printMappings} method.
490 public void printMappingsTest() {
491 mappingService.printMappings();
492 Mockito.verify(mappingSystem).printMappings();
496 * Tests {@link MappingService#close} method.
499 public void close() throws Exception {
500 mappingService.close();
501 Mockito.verify(keyListener).closeDataChangeListener();
502 Mockito.verify(mappingListener).closeDataChangeListener();
506 * Tests {@link MappingService#cleanCachedMappings} method.
509 public void cleanCachedMappingsTest() throws Exception {
510 mappingService.cleanCachedMappings();
511 Mockito.verify(mappingSystem).cleanCaches();
512 Mockito.verify(dsbe).removeAllDatastoreContent();
516 * Tests {@link MappingService} not implemented methods.
519 public void nullReturnMethodTest() throws ExecutionException, InterruptedException {
520 assertNull(mappingService.removeKeys(Mockito.mock(RemoveKeysInput.class)));
521 assertNull(mappingService.removeMappings(Mockito.mock(RemoveMappingsInput.class)));
522 assertNull(mappingService.getKeys(Mockito.mock(GetKeysInput.class)));
523 assertNull(mappingService.addMappings(Mockito.mock(AddMappingsInput.class)));
524 assertNull(mappingService.updateKeys(Mockito.mock(UpdateKeysInput.class)));
525 assertNull(mappingService.removeAllMappings());
526 assertNull(mappingService.getAllKeys());
527 assertNull(mappingService.updateMappings(Mockito.mock(UpdateMappingsInput.class)));
528 assertNull(mappingService.addKeys(Mockito.mock(AddKeysInput.class)));
529 assertNull(mappingService.getAllMappings());
532 private static MappingRecordBuilder getDefaultMappingRecordBuilder() {
533 return new MappingRecordBuilder()
534 .setAction(MappingRecord.Action.NoAction)
535 .setAuthoritative(false)
536 .setLocatorRecord(new ArrayList<>())
537 .setMapVersion((short) 0)