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.mapcache;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNull;
12 import static org.mockito.Matchers.any;
13 import static org.mockito.Matchers.anyString;
14 import static org.mockito.Mockito.mock;
15 import static org.mockito.Mockito.times;
16 import static org.mockito.Mockito.verify;
17 import static org.mockito.Mockito.verifyZeroInteractions;
18 import static org.mockito.Mockito.when;
20 import com.google.common.collect.Maps;
22 import java.lang.reflect.InvocationTargetException;
23 import java.lang.reflect.Method;
24 import java.util.Date;
27 import org.junit.Before;
28 import org.junit.Test;
29 import org.mockito.Mockito;
30 import org.opendaylight.lispflowmapping.interfaces.dao.ILispDAO;
31 import org.opendaylight.lispflowmapping.interfaces.dao.MappingEntry;
32 import org.opendaylight.lispflowmapping.interfaces.dao.SubKeys;
33 import org.opendaylight.lispflowmapping.lisp.util.LispAddressUtil;
34 import org.opendaylight.lispflowmapping.lisp.util.MaskUtil;
35 import org.opendaylight.lispflowmapping.lisp.util.SourceDestKeyHelper;
36 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpPrefix;
37 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
38 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.InstanceIdType;
39 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.SimpleAddress;
40 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address
42 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address
43 .address.Ipv4PrefixBuilder;
44 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
45 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address
47 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address
48 .address.SourceDestKeyBuilder;
49 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.EidBuilder;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.mapping.authkey
53 .container.MappingAuthkey;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.mapping.authkey
55 .container.MappingAuthkeyBuilder;
57 public class MultiTableMapCacheTest {
59 private static MultiTableMapCache multiTableMapCache;
60 private static ILispDAO daoMock;
61 private static ILispDAO srcDstDaoMock;
62 private static ILispDAO tableDaoMock;
63 private static ILispDAO dbMock;
65 private static final String IPV4_STRING_1 = "127.0.0.1/24";
66 private static final String IPV4_STRING_2 = "127.0.0.1/24";
67 private static final Ipv4Prefix IPV_4_PREFIX_SRC = new Ipv4Prefix(IPV4_STRING_1);
68 private static final Ipv4Prefix IPV_4_PREFIX_DST = new Ipv4Prefix(IPV4_STRING_2);
69 private static final long VNI = 100L;
71 private static final Eid EID_TEST = new EidBuilder().setVirtualNetworkId(new InstanceIdType(VNI))
72 .setAddress(new Ipv4Builder().setIpv4(new Ipv4Address("10.0.0.1")).build()).build();
73 private static final Eid EID_SOURCE_DEST_KEY_TYPE = new EidBuilder().setVirtualNetworkId(new InstanceIdType(VNI))
74 .setAddress(new SourceDestKeyBuilder()
75 .setSourceDestKey(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp
76 .address.types.rev151105.lisp.address.address.source.dest.key.SourceDestKeyBuilder()
77 .setSource(new SimpleAddress(new IpPrefix(IPV_4_PREFIX_SRC)))
78 .setDest(new SimpleAddress(new IpPrefix(IPV_4_PREFIX_DST))).build()).build()).build();
79 private static final Eid EID_IPV4_PREFIX_SRC = LispAddressUtil.asIpv4PrefixEid(IPV4_STRING_1);
80 private static final Eid EID_IPV4_PREFIX_DST = new EidBuilder().setVirtualNetworkId(new InstanceIdType(VNI))
81 .setAddress(new Ipv4PrefixBuilder().setIpv4Prefix(IPV_4_PREFIX_DST).build()).build();
82 private static final Eid NORMALIZED_SRCDST_EID = MaskUtil.normalize(EID_SOURCE_DEST_KEY_TYPE);
83 private static final Eid NORMALIZED_PREFIX_SRC_EID = MaskUtil.normalize(EID_IPV4_PREFIX_SRC);
84 private static final Eid EID_MAC = new EidBuilder().setVirtualNetworkId(new InstanceIdType(VNI))
85 .setAddress(new MacBuilder().setMac(new MacAddress("aa:bb:cc:dd:ee:ff")).build()).build();
86 private static final Eid NORMALIZED_EID = MaskUtil.normalize(EID_TEST);
87 private static final Object DUMMY_OBJECT = "dummy_object";
88 private static final Object DUMMY_OBJECT_2 = "mapping_lpm_eid";
89 private static final MappingAuthkey MAPPING_AUTHKEY = new MappingAuthkeyBuilder()
90 .setKeyString("mapping_authkey_test").build();
94 daoMock = mock(ILispDAO.class);
95 tableDaoMock = mock(ILispDAO.class);
96 srcDstDaoMock = mock(ILispDAO.class);
97 multiTableMapCache = new MultiTableMapCache(daoMock);
98 dbMock = mock(ILispDAO.class);
102 * Tests {@link MultiTableMapCache#addMapping} with SourceDestKey address type.
105 public void addMappingTest_withSourceDestKey() {
107 final Eid normalized_Eid = MaskUtil.normalize(EID_SOURCE_DEST_KEY_TYPE);
108 final Eid dstKey = SourceDestKeyHelper.getDst(normalized_Eid);
109 final Eid srcKey = SourceDestKeyHelper.getSrc(normalized_Eid);
111 when(daoMock.getSpecific(VNI, SubKeys.VNI)).thenReturn(tableDaoMock);
112 when(tableDaoMock.getSpecific(dstKey, SubKeys.LCAF_SRCDST)).thenReturn(srcDstDaoMock);
114 multiTableMapCache.addMapping(EID_SOURCE_DEST_KEY_TYPE, DUMMY_OBJECT, true, false);
115 verify(srcDstDaoMock, times(2)).put(srcKey, new MappingEntry<>(anyString(), any(Date.class)));
116 verify(srcDstDaoMock).put(srcKey, new MappingEntry<>(SubKeys.RECORD, DUMMY_OBJECT));
120 * Tests {@link MultiTableMapCache#addMapping} with other than SourceDestKey address type.
123 public void addMappingTest_withoutSourceDestKey() {
124 when(daoMock.getSpecific(0L, SubKeys.VNI)).thenReturn(tableDaoMock);
126 multiTableMapCache.addMapping(EID_IPV4_PREFIX_SRC, DUMMY_OBJECT, true, false);
127 verify(tableDaoMock, times(2)).put(NORMALIZED_PREFIX_SRC_EID, new MappingEntry<>(anyString(), any(Date.class)));
128 verify(tableDaoMock).put(NORMALIZED_PREFIX_SRC_EID, new MappingEntry<>(SubKeys.RECORD, DUMMY_OBJECT));
132 * Tests {@link MultiTableMapCache#getMapping} with SourceDestKey address type.
135 public void getMappingTest_withSourceDestKey() {
136 when(daoMock.getSpecific(VNI, SubKeys.VNI)).thenReturn(tableDaoMock);
138 final Eid dstAddr = SourceDestKeyHelper.getDst(EID_SOURCE_DEST_KEY_TYPE);
139 final Eid normalizedDstAddr = MaskUtil.normalize(dstAddr);
141 final Eid srcAddr = SourceDestKeyHelper.getSrc(EID_SOURCE_DEST_KEY_TYPE);
142 final Eid normalizedSrcAddr = MaskUtil.normalize(srcAddr);
144 final Map<String, Object> entry = getEntry1();
145 final Map<String, Object> entry2 = getEntry2();
147 when(tableDaoMock.get(normalizedDstAddr)).thenReturn(entry);
148 when(srcDstDaoMock.get(normalizedSrcAddr)).thenReturn(entry2);
150 assertEquals(DUMMY_OBJECT_2, multiTableMapCache.getMapping(null, EID_SOURCE_DEST_KEY_TYPE));
151 assertNull(multiTableMapCache.getMapping(null, null));
152 assertNull(multiTableMapCache.getMapping(EID_TEST, null));
156 * Tests {@link MultiTableMapCache#getMapping} with Ipv4 address type.
159 public void getMappingTest_withIpv4() {
160 when(daoMock.getSpecific(VNI, SubKeys.VNI)).thenReturn(tableDaoMock);
161 when(tableDaoMock.get(NORMALIZED_EID)).thenReturn(null);
163 assertNull(multiTableMapCache.getMapping(null, EID_TEST));
167 * Tests {@link MultiTableMapCache#getMapping} with table == null.
170 public void getMappingTest_withNullTable() {
171 when(daoMock.getSpecific(VNI, SubKeys.VNI)).thenReturn(null);
172 assertNull(multiTableMapCache.getMapping(null, EID_TEST));
176 * Tests {@link MultiTableMapCache#getMapping} with Ipv4Prefix address type.
179 public void getMappingTest_withIpv4Prefix() {
180 final Eid key = MaskUtil.normalize(EID_IPV4_PREFIX_DST, (short) 24);
181 final Eid key2 = MaskUtil.normalize(MaskUtil.normalize(EID_IPV4_PREFIX_SRC), (short) 24);
183 final Map<String, Object> entry = getEntry1();
184 final Map<String, Object> entry2 = getEntry2();
186 when(daoMock.getSpecific(VNI, SubKeys.VNI)).thenReturn(tableDaoMock);
187 when(tableDaoMock.get(key)).thenReturn(entry);
188 when(srcDstDaoMock.get(key2)).thenReturn(entry2);
190 assertEquals(DUMMY_OBJECT_2, multiTableMapCache.getMapping(EID_IPV4_PREFIX_SRC, EID_IPV4_PREFIX_DST));
191 assertEquals(DUMMY_OBJECT, multiTableMapCache.getMapping(null, EID_IPV4_PREFIX_DST));
195 * Tests {@link MultiTableMapCache#removeMapping} method with SourceDestKey type address.
198 public void removeMappingTest() {
200 when(daoMock.getSpecific(VNI, SubKeys.VNI)).thenReturn(tableDaoMock);
201 when(tableDaoMock.getSpecific(SourceDestKeyHelper
202 .getDst(NORMALIZED_SRCDST_EID), SubKeys.LCAF_SRCDST)).thenReturn(dbMock);
204 multiTableMapCache.removeMapping(EID_SOURCE_DEST_KEY_TYPE, true);
205 verify(dbMock).removeSpecific(SourceDestKeyHelper.getSrc(NORMALIZED_SRCDST_EID),
210 * Tests {@link MultiTableMapCache#removeMapping} method with Ipv4 type address.
213 public void removeMappingTest_with() {
215 when(daoMock.getSpecific(VNI, SubKeys.VNI)).thenReturn(tableDaoMock);
217 multiTableMapCache.removeMapping(EID_TEST, true);
218 verify(tableDaoMock).removeSpecific(NORMALIZED_EID, SubKeys.RECORD);
222 * Tests {@link MultiTableMapCache#removeMapping} method with table == null.
225 public void removeMappingTest_withNUllTable() {
227 when(daoMock.getSpecific(VNI, SubKeys.VNI)).thenReturn(null);
229 multiTableMapCache.removeMapping(EID_SOURCE_DEST_KEY_TYPE, true);
230 verifyZeroInteractions(tableDaoMock);
231 verifyZeroInteractions(dbMock);
235 * Tests {@link MultiTableMapCache#addAuthenticationKey}.
238 public void addAuthenticationKeyTest() {
239 when(daoMock.getSpecific(VNI, SubKeys.VNI)).thenReturn(tableDaoMock);
240 when(tableDaoMock.putNestedTable(SourceDestKeyHelper.getDst(NORMALIZED_SRCDST_EID), SubKeys.LCAF_SRCDST))
241 .thenReturn(srcDstDaoMock);
243 multiTableMapCache.addAuthenticationKey(EID_SOURCE_DEST_KEY_TYPE, MAPPING_AUTHKEY);
244 verify(srcDstDaoMock).put(SourceDestKeyHelper.getSrc(NORMALIZED_SRCDST_EID),
245 new MappingEntry<>(SubKeys.AUTH_KEY, MAPPING_AUTHKEY));
247 multiTableMapCache.addAuthenticationKey(EID_TEST, MAPPING_AUTHKEY);
248 verify(tableDaoMock).put(NORMALIZED_EID, new MappingEntry<>(SubKeys.AUTH_KEY, MAPPING_AUTHKEY));
252 * Tests {@link MultiTableMapCache#getAuthenticationKey} with Ipv4Prefix address.
255 public void getAuthenticationKeyTest_withIpv4Prefix() {
256 final short maskLength = MaskUtil.getMaskForAddress(EID_IPV4_PREFIX_SRC.getAddress());
257 final Eid key = MaskUtil.normalize(EID_IPV4_PREFIX_SRC, maskLength);
259 when(daoMock.getSpecific(0L, SubKeys.VNI)).thenReturn(tableDaoMock);
260 when(tableDaoMock.getSpecific(key, SubKeys.AUTH_KEY)).thenReturn(MAPPING_AUTHKEY);
262 assertEquals(MAPPING_AUTHKEY, multiTableMapCache.getAuthenticationKey(EID_IPV4_PREFIX_SRC));
266 * Tests {@link MultiTableMapCache#getAuthenticationKey} with SourceDestKey address.
269 public void getAuthenticationKeyTest_withSourceDestKey() {
270 final Eid eidSrc = SourceDestKeyHelper.getSrc(EID_SOURCE_DEST_KEY_TYPE);
271 final Eid eidDst = SourceDestKeyHelper.getDst(EID_SOURCE_DEST_KEY_TYPE);
272 final short maskLength = MaskUtil.getMaskForAddress(eidSrc.getAddress());
273 final Eid key = MaskUtil.normalize(eidSrc, maskLength);
275 when(daoMock.getSpecific(VNI, SubKeys.VNI)).thenReturn(tableDaoMock);
276 when(tableDaoMock.getSpecific(eidDst, SubKeys.LCAF_SRCDST))
277 .thenReturn(srcDstDaoMock);
278 when(srcDstDaoMock.getSpecific(key, SubKeys.AUTH_KEY)).thenReturn(MAPPING_AUTHKEY);
280 assertEquals(MAPPING_AUTHKEY, multiTableMapCache.getAuthenticationKey(EID_SOURCE_DEST_KEY_TYPE));
284 * Tests {@link MultiTableMapCache#getAuthenticationKey} with SourceDestKey address, srcDstDao == null.
287 public void getAuthenticationKeyTest_withSourceDestKey_nullDao() {
288 final Eid eidDst = SourceDestKeyHelper.getDst(EID_SOURCE_DEST_KEY_TYPE);
290 when(daoMock.getSpecific(VNI, SubKeys.VNI)).thenReturn(tableDaoMock);
291 when(tableDaoMock.getSpecific(eidDst, SubKeys.LCAF_SRCDST))
294 assertNull(multiTableMapCache.getAuthenticationKey(EID_SOURCE_DEST_KEY_TYPE));
298 * Tests {@link MultiTableMapCache#getAuthenticationKey} with Mac address.
301 public void getAuthenticationKeyTest_withMac() {
302 final Eid key = MaskUtil.normalize(EID_MAC);
304 when(daoMock.getSpecific(VNI, SubKeys.VNI)).thenReturn(tableDaoMock);
305 when(tableDaoMock.getSpecific(key, SubKeys.AUTH_KEY)).thenReturn(MAPPING_AUTHKEY);
307 assertEquals(MAPPING_AUTHKEY, multiTableMapCache.getAuthenticationKey(EID_MAC));
311 * Tests {@link MultiTableMapCache#getAuthenticationKey} with Mac address, failed authentication.
314 public void getAuthenticationKeyTest_withMac_failedAuthentication() {
315 final Eid key = MaskUtil.normalize(EID_MAC);
317 when(daoMock.getSpecific(VNI, SubKeys.VNI)).thenReturn(tableDaoMock);
318 when(tableDaoMock.getSpecific(key, SubKeys.AUTH_KEY)).thenReturn(null);
320 assertNull(multiTableMapCache.getAuthenticationKey(EID_MAC));
324 * Tests {@link MultiTableMapCache#getAuthenticationKey} with Mac address, table == null.
327 public void getAuthenticationKeyTest_withMac_nullTable() {
328 when(daoMock.getSpecific(VNI, SubKeys.VNI)).thenReturn(null);
329 assertNull(multiTableMapCache.getAuthenticationKey(EID_MAC));
333 * Tests {@link MultiTableMapCache#removeAuthenticationKey} with SourceDestKey address type.
336 public void removeAuthenticationKeyTest_withSourceDestKey() {
337 when(daoMock.getSpecific(VNI, SubKeys.VNI)).thenReturn(tableDaoMock);
338 when(tableDaoMock.getSpecific(SourceDestKeyHelper.getDst(NORMALIZED_SRCDST_EID), SubKeys.LCAF_SRCDST))
339 .thenReturn(srcDstDaoMock);
341 multiTableMapCache.removeAuthenticationKey(EID_SOURCE_DEST_KEY_TYPE);
342 verify(srcDstDaoMock).removeSpecific(NORMALIZED_SRCDST_EID, SubKeys.AUTH_KEY);
346 * Tests {@link MultiTableMapCache#removeAuthenticationKey} with Ipv4 address type.
349 public void removeAuthenticationKeyTest_withIpv4() {
350 when(daoMock.getSpecific(VNI, SubKeys.VNI)).thenReturn(tableDaoMock);
352 multiTableMapCache.removeAuthenticationKey(EID_TEST);
353 verify(tableDaoMock).removeSpecific(NORMALIZED_EID, SubKeys.AUTH_KEY);
357 * Tests {@link MultiTableMapCache#removeAuthenticationKey} with table == null.
360 public void removeAuthenticationKeyTest_withNullTable() {
361 when(daoMock.getSpecific(VNI, SubKeys.VNI)).thenReturn(null);
363 multiTableMapCache.removeAuthenticationKey(EID_TEST);
364 verifyZeroInteractions(tableDaoMock);
368 * Tests {@link MultiTableMapCache#addData} with SourceDestKey address type.
371 public void addDataTest_withSourceDestKey() {
372 when(daoMock.getSpecific(VNI, SubKeys.VNI)).thenReturn(tableDaoMock);
373 when(tableDaoMock.getSpecific(SourceDestKeyHelper.getDst(NORMALIZED_SRCDST_EID), SubKeys.LCAF_SRCDST))
374 .thenReturn(srcDstDaoMock);
376 multiTableMapCache.addData(EID_SOURCE_DEST_KEY_TYPE, SubKeys.RECORD, DUMMY_OBJECT);
377 verify(srcDstDaoMock).put(SourceDestKeyHelper.getSrc(NORMALIZED_SRCDST_EID),
378 new MappingEntry<>(SubKeys.RECORD, DUMMY_OBJECT));
382 * Tests {@link MultiTableMapCache#addData} with other than SourceDestKey address type.
385 public void addDataTest_withIpv4() {
386 when(daoMock.getSpecific(VNI, SubKeys.VNI)).thenReturn(tableDaoMock);
388 multiTableMapCache.addData(EID_TEST, SubKeys.RECORD, DUMMY_OBJECT);
389 verify(tableDaoMock).put(NORMALIZED_EID, new MappingEntry<>(SubKeys.RECORD, DUMMY_OBJECT));
393 * Tests {@link MultiTableMapCache#getData} with SourceDestKey address type.
396 public void getDataTest_withSourceDestKey() {
397 when(daoMock.getSpecific(VNI, SubKeys.VNI)).thenReturn(tableDaoMock);
398 when(tableDaoMock.getSpecific(SourceDestKeyHelper.getDst(NORMALIZED_SRCDST_EID), SubKeys.LCAF_SRCDST))
399 .thenReturn(srcDstDaoMock);
400 when(srcDstDaoMock.getSpecific(SourceDestKeyHelper.getSrc(NORMALIZED_SRCDST_EID), SubKeys.RECORD))
401 .thenReturn(DUMMY_OBJECT);
403 assertEquals(DUMMY_OBJECT, multiTableMapCache.getData(EID_SOURCE_DEST_KEY_TYPE, SubKeys.RECORD));
407 * Tests {@link MultiTableMapCache#getData} with other than SourceDestKey address type.
410 public void getDataTest_withIpv4() {
411 when(daoMock.getSpecific(VNI, SubKeys.VNI)).thenReturn(tableDaoMock);
412 when(tableDaoMock.getSpecific(NORMALIZED_EID, SubKeys.RECORD)).thenReturn(DUMMY_OBJECT);
414 assertEquals(DUMMY_OBJECT, multiTableMapCache.getData(EID_TEST, SubKeys.RECORD));
418 * Tests {@link MultiTableMapCache#getData} with table == null.
421 public void getDataTest_withNullTable() {
422 when(daoMock.getSpecific(VNI, SubKeys.VNI)).thenReturn(null);
423 assertNull(multiTableMapCache.getData(EID_TEST, SubKeys.RECORD));
427 * Tests {@link MultiTableMapCache#removeData} with SourceDestKey address type.
430 public void removeDataTest_withSourceDestKey() {
431 when(daoMock.getSpecific(VNI, SubKeys.VNI)).thenReturn(tableDaoMock);
432 when(tableDaoMock.getSpecific(SourceDestKeyHelper.getDst(NORMALIZED_SRCDST_EID), SubKeys.LCAF_SRCDST))
433 .thenReturn(srcDstDaoMock);
435 multiTableMapCache.removeData(EID_SOURCE_DEST_KEY_TYPE, SubKeys.RECORD);
436 verify(srcDstDaoMock).removeSpecific(SourceDestKeyHelper.getSrc(NORMALIZED_SRCDST_EID), SubKeys.RECORD);
440 * Tests {@link MultiTableMapCache#removeData} with other than SourceDestKey address type.
443 public void removeDataTest_withIpv4() {
444 when(daoMock.getSpecific(VNI, SubKeys.VNI)).thenReturn(tableDaoMock);
446 multiTableMapCache.removeData(EID_TEST, SubKeys.RECORD);
447 verify(tableDaoMock).removeSpecific(NORMALIZED_EID, SubKeys.RECORD);
451 * Tests {@link MultiTableMapCache#removeData} with table == null.
454 public void removeDataTest_withNullTable() {
455 when(daoMock.getSpecific(VNI, SubKeys.VNI)).thenReturn(null);
456 multiTableMapCache.removeData(EID_TEST, SubKeys.RECORD);
458 Mockito.verifyZeroInteractions(tableDaoMock);
462 * Tests {@link MultiTableMapCache#getMappingExactSD} method.
465 public void getMappingExactSDTest() throws NoSuchMethodException, InvocationTargetException,
466 IllegalAccessException {
467 Method getMappingExactSD = MultiTableMapCache.class.getDeclaredMethod("getMappingExactSD", Eid.class, Eid.class,
469 getMappingExactSD.setAccessible(true);
471 when(tableDaoMock.get(EID_IPV4_PREFIX_DST)).thenReturn(getEntry1());
472 when(srcDstDaoMock.getSpecific(EID_IPV4_PREFIX_SRC, SubKeys.RECORD)).thenReturn(DUMMY_OBJECT);
474 Object result = getMappingExactSD.invoke(
475 multiTableMapCache, EID_IPV4_PREFIX_SRC, EID_IPV4_PREFIX_DST, tableDaoMock);
476 assertEquals(DUMMY_OBJECT, result);
480 * Tests {@link MultiTableMapCache#getMappingExactSD} method with null src eid.
483 public void getMappingExactSDTest_withNullSrcEid() throws NoSuchMethodException, InvocationTargetException,
484 IllegalAccessException {
485 Method getMappingExactSD = MultiTableMapCache.class.getDeclaredMethod("getMappingExactSD", Eid.class, Eid.class,
487 getMappingExactSD.setAccessible(true);
489 when(tableDaoMock.get(EID_IPV4_PREFIX_DST)).thenReturn(getEntry1());
491 Object result = getMappingExactSD.invoke(
492 multiTableMapCache, null, EID_IPV4_PREFIX_DST, tableDaoMock);
493 assertEquals(DUMMY_OBJECT, result);
497 * Tests {@link MultiTableMapCache#getMappingExactSD} method with null entry.
500 public void getMappingExactSDTest_withNullEntry() throws NoSuchMethodException, InvocationTargetException,
501 IllegalAccessException {
502 Method getMappingExactSD = MultiTableMapCache.class.getDeclaredMethod("getMappingExactSD", Eid.class, Eid.class,
504 getMappingExactSD.setAccessible(true);
506 when(tableDaoMock.get(EID_IPV4_PREFIX_DST)).thenReturn(null);
508 Object result = getMappingExactSD.invoke(
509 multiTableMapCache, null, EID_IPV4_PREFIX_DST, tableDaoMock);
514 * The following test is for coverage-increase purpose only.
517 public void otherTest() {
518 multiTableMapCache.printMappings();
521 private Map<String, Object> getEntry1() {
522 Map<String, Object> entry = Maps.newConcurrentMap();
523 entry.put(SubKeys.RECORD, DUMMY_OBJECT);
524 entry.put(SubKeys.LCAF_SRCDST, srcDstDaoMock);
529 private Map<String, Object> getEntry2() {
530 Map<String, Object> entry = Maps.newConcurrentMap();
531 entry.put(SubKeys.RECORD, DUMMY_OBJECT_2);