JUnit Test - LispNotificationHelperTest
[lispflowmapping.git] / mappingservice / mapcache / src / test / java / org / opendaylight / lispflowmapping / mapcache / MultiTableMapCacheTest.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.lispflowmapping.mapcache;
9
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;
19
20 import com.google.common.collect.Maps;
21
22 import java.lang.reflect.InvocationTargetException;
23 import java.lang.reflect.Method;
24 import java.util.Date;
25 import java.util.Map;
26
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
41         .address.Ipv4Builder;
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
46         .address.MacBuilder;
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;
56
57 public class MultiTableMapCacheTest {
58
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;
64
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;
70
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();
91
92     @Before
93     public void init() {
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);
99     }
100
101     /**
102      * Tests {@link MultiTableMapCache#addMapping} with SourceDestKey address type.
103      */
104     @Test
105     public void addMappingTest_withSourceDestKey() {
106
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);
110
111         when(daoMock.getSpecific(VNI, SubKeys.VNI)).thenReturn(tableDaoMock);
112         when(tableDaoMock.getSpecific(dstKey, SubKeys.LCAF_SRCDST)).thenReturn(srcDstDaoMock);
113
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));
117     }
118
119     /**
120      * Tests {@link MultiTableMapCache#addMapping} with other than SourceDestKey address type.
121      */
122     @Test
123     public void addMappingTest_withoutSourceDestKey() {
124         when(daoMock.getSpecific(0L, SubKeys.VNI)).thenReturn(tableDaoMock);
125
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));
129     }
130
131     /**
132      * Tests {@link MultiTableMapCache#getMapping} with SourceDestKey address type.
133      */
134     @Test
135     public void getMappingTest_withSourceDestKey() {
136         when(daoMock.getSpecific(VNI, SubKeys.VNI)).thenReturn(tableDaoMock);
137
138         final Eid dstAddr = SourceDestKeyHelper.getDst(EID_SOURCE_DEST_KEY_TYPE);
139         final Eid normalizedDstAddr = MaskUtil.normalize(dstAddr);
140
141         final Eid srcAddr = SourceDestKeyHelper.getSrc(EID_SOURCE_DEST_KEY_TYPE);
142         final Eid normalizedSrcAddr = MaskUtil.normalize(srcAddr);
143
144         final Map<String, Object> entry = getEntry1();
145         final Map<String, Object> entry2 = getEntry2();
146
147         when(tableDaoMock.get(normalizedDstAddr)).thenReturn(entry);
148         when(srcDstDaoMock.get(normalizedSrcAddr)).thenReturn(entry2);
149
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));
153     }
154
155     /**
156      * Tests {@link MultiTableMapCache#getMapping} with Ipv4 address type.
157      */
158     @Test
159     public void getMappingTest_withIpv4() {
160         when(daoMock.getSpecific(VNI, SubKeys.VNI)).thenReturn(tableDaoMock);
161         when(tableDaoMock.get(NORMALIZED_EID)).thenReturn(null);
162
163         assertNull(multiTableMapCache.getMapping(null, EID_TEST));
164     }
165
166     /**
167      * Tests {@link MultiTableMapCache#getMapping} with table == null.
168      */
169     @Test
170     public void getMappingTest_withNullTable() {
171         when(daoMock.getSpecific(VNI, SubKeys.VNI)).thenReturn(null);
172         assertNull(multiTableMapCache.getMapping(null, EID_TEST));
173     }
174
175     /**
176      * Tests {@link MultiTableMapCache#getMapping} with Ipv4Prefix address type.
177      */
178     @Test
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);
182
183         final Map<String, Object> entry = getEntry1();
184         final Map<String, Object> entry2 = getEntry2();
185
186         when(daoMock.getSpecific(VNI, SubKeys.VNI)).thenReturn(tableDaoMock);
187         when(tableDaoMock.get(key)).thenReturn(entry);
188         when(srcDstDaoMock.get(key2)).thenReturn(entry2);
189
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));
192     }
193
194     /**
195      * Tests {@link MultiTableMapCache#removeMapping} method with SourceDestKey type address.
196      */
197     @Test
198     public void removeMappingTest() {
199
200         when(daoMock.getSpecific(VNI, SubKeys.VNI)).thenReturn(tableDaoMock);
201         when(tableDaoMock.getSpecific(SourceDestKeyHelper
202                 .getDst(NORMALIZED_SRCDST_EID), SubKeys.LCAF_SRCDST)).thenReturn(dbMock);
203
204         multiTableMapCache.removeMapping(EID_SOURCE_DEST_KEY_TYPE, true);
205         verify(dbMock).removeSpecific(SourceDestKeyHelper.getSrc(NORMALIZED_SRCDST_EID),
206                 SubKeys.RECORD);
207     }
208
209     /**
210      * Tests {@link MultiTableMapCache#removeMapping} method with Ipv4 type address.
211      */
212     @Test
213     public void removeMappingTest_with() {
214
215         when(daoMock.getSpecific(VNI, SubKeys.VNI)).thenReturn(tableDaoMock);
216
217         multiTableMapCache.removeMapping(EID_TEST, true);
218         verify(tableDaoMock).removeSpecific(NORMALIZED_EID, SubKeys.RECORD);
219     }
220
221     /**
222      * Tests {@link MultiTableMapCache#removeMapping} method with table == null.
223      */
224     @Test
225     public void removeMappingTest_withNUllTable() {
226
227         when(daoMock.getSpecific(VNI, SubKeys.VNI)).thenReturn(null);
228
229         multiTableMapCache.removeMapping(EID_SOURCE_DEST_KEY_TYPE, true);
230         verifyZeroInteractions(tableDaoMock);
231         verifyZeroInteractions(dbMock);
232     }
233
234     /**
235      * Tests {@link MultiTableMapCache#addAuthenticationKey}.
236      */
237     @Test
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);
242
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));
246
247         multiTableMapCache.addAuthenticationKey(EID_TEST, MAPPING_AUTHKEY);
248         verify(tableDaoMock).put(NORMALIZED_EID, new MappingEntry<>(SubKeys.AUTH_KEY, MAPPING_AUTHKEY));
249     }
250
251     /**
252      * Tests {@link MultiTableMapCache#getAuthenticationKey} with Ipv4Prefix address.
253      */
254     @Test
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);
258
259         when(daoMock.getSpecific(0L, SubKeys.VNI)).thenReturn(tableDaoMock);
260         when(tableDaoMock.getSpecific(key, SubKeys.AUTH_KEY)).thenReturn(MAPPING_AUTHKEY);
261
262         assertEquals(MAPPING_AUTHKEY, multiTableMapCache.getAuthenticationKey(EID_IPV4_PREFIX_SRC));
263     }
264
265     /**
266      * Tests {@link MultiTableMapCache#getAuthenticationKey} with SourceDestKey address.
267      */
268     @Test
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);
274
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);
279
280         assertEquals(MAPPING_AUTHKEY, multiTableMapCache.getAuthenticationKey(EID_SOURCE_DEST_KEY_TYPE));
281     }
282
283     /**
284      * Tests {@link MultiTableMapCache#getAuthenticationKey} with SourceDestKey address, srcDstDao == null.
285      */
286     @Test
287     public void getAuthenticationKeyTest_withSourceDestKey_nullDao() {
288         final Eid eidDst = SourceDestKeyHelper.getDst(EID_SOURCE_DEST_KEY_TYPE);
289
290         when(daoMock.getSpecific(VNI, SubKeys.VNI)).thenReturn(tableDaoMock);
291         when(tableDaoMock.getSpecific(eidDst, SubKeys.LCAF_SRCDST))
292                 .thenReturn(null);
293
294         assertNull(multiTableMapCache.getAuthenticationKey(EID_SOURCE_DEST_KEY_TYPE));
295     }
296
297     /**
298      * Tests {@link MultiTableMapCache#getAuthenticationKey} with Mac address.
299      */
300     @Test
301     public void getAuthenticationKeyTest_withMac() {
302         final Eid key = MaskUtil.normalize(EID_MAC);
303
304         when(daoMock.getSpecific(VNI, SubKeys.VNI)).thenReturn(tableDaoMock);
305         when(tableDaoMock.getSpecific(key, SubKeys.AUTH_KEY)).thenReturn(MAPPING_AUTHKEY);
306
307         assertEquals(MAPPING_AUTHKEY, multiTableMapCache.getAuthenticationKey(EID_MAC));
308     }
309
310     /**
311      * Tests {@link MultiTableMapCache#getAuthenticationKey} with Mac address, failed authentication.
312      */
313     @Test
314     public void getAuthenticationKeyTest_withMac_failedAuthentication() {
315         final Eid key = MaskUtil.normalize(EID_MAC);
316
317         when(daoMock.getSpecific(VNI, SubKeys.VNI)).thenReturn(tableDaoMock);
318         when(tableDaoMock.getSpecific(key, SubKeys.AUTH_KEY)).thenReturn(null);
319
320         assertNull(multiTableMapCache.getAuthenticationKey(EID_MAC));
321     }
322
323     /**
324      * Tests {@link MultiTableMapCache#getAuthenticationKey} with Mac address, table == null.
325      */
326     @Test
327     public void getAuthenticationKeyTest_withMac_nullTable() {
328         when(daoMock.getSpecific(VNI, SubKeys.VNI)).thenReturn(null);
329         assertNull(multiTableMapCache.getAuthenticationKey(EID_MAC));
330     }
331
332     /**
333      * Tests {@link MultiTableMapCache#removeAuthenticationKey} with SourceDestKey address type.
334      */
335     @Test
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);
340
341         multiTableMapCache.removeAuthenticationKey(EID_SOURCE_DEST_KEY_TYPE);
342         verify(srcDstDaoMock).removeSpecific(NORMALIZED_SRCDST_EID, SubKeys.AUTH_KEY);
343     }
344
345     /**
346      * Tests {@link MultiTableMapCache#removeAuthenticationKey} with Ipv4 address type.
347      */
348     @Test
349     public void removeAuthenticationKeyTest_withIpv4() {
350         when(daoMock.getSpecific(VNI, SubKeys.VNI)).thenReturn(tableDaoMock);
351
352         multiTableMapCache.removeAuthenticationKey(EID_TEST);
353         verify(tableDaoMock).removeSpecific(NORMALIZED_EID, SubKeys.AUTH_KEY);
354     }
355
356     /**
357      * Tests {@link MultiTableMapCache#removeAuthenticationKey} with table == null.
358      */
359     @Test
360     public void removeAuthenticationKeyTest_withNullTable() {
361         when(daoMock.getSpecific(VNI, SubKeys.VNI)).thenReturn(null);
362
363         multiTableMapCache.removeAuthenticationKey(EID_TEST);
364         verifyZeroInteractions(tableDaoMock);
365     }
366
367     /**
368      * Tests {@link MultiTableMapCache#addData} with SourceDestKey address type.
369      */
370     @Test
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);
375
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));
379     }
380
381     /**
382      * Tests {@link MultiTableMapCache#addData} with other than SourceDestKey address type.
383      */
384     @Test
385     public void addDataTest_withIpv4() {
386         when(daoMock.getSpecific(VNI, SubKeys.VNI)).thenReturn(tableDaoMock);
387
388         multiTableMapCache.addData(EID_TEST, SubKeys.RECORD, DUMMY_OBJECT);
389         verify(tableDaoMock).put(NORMALIZED_EID, new MappingEntry<>(SubKeys.RECORD, DUMMY_OBJECT));
390     }
391
392     /**
393      * Tests {@link MultiTableMapCache#getData} with SourceDestKey address type.
394      */
395     @Test
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);
402
403         assertEquals(DUMMY_OBJECT, multiTableMapCache.getData(EID_SOURCE_DEST_KEY_TYPE, SubKeys.RECORD));
404     }
405
406     /**
407      * Tests {@link MultiTableMapCache#getData} with other than SourceDestKey address type.
408      */
409     @Test
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);
413
414         assertEquals(DUMMY_OBJECT, multiTableMapCache.getData(EID_TEST, SubKeys.RECORD));
415     }
416
417     /**
418      * Tests {@link MultiTableMapCache#getData} with table == null.
419      */
420     @Test
421     public void getDataTest_withNullTable() {
422         when(daoMock.getSpecific(VNI, SubKeys.VNI)).thenReturn(null);
423         assertNull(multiTableMapCache.getData(EID_TEST, SubKeys.RECORD));
424     }
425
426     /**
427      * Tests {@link MultiTableMapCache#removeData} with SourceDestKey address type.
428      */
429     @Test
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);
434
435         multiTableMapCache.removeData(EID_SOURCE_DEST_KEY_TYPE, SubKeys.RECORD);
436         verify(srcDstDaoMock).removeSpecific(SourceDestKeyHelper.getSrc(NORMALIZED_SRCDST_EID), SubKeys.RECORD);
437     }
438
439     /**
440      * Tests {@link MultiTableMapCache#removeData} with other than SourceDestKey address type.
441      */
442     @Test
443     public void removeDataTest_withIpv4() {
444         when(daoMock.getSpecific(VNI, SubKeys.VNI)).thenReturn(tableDaoMock);
445
446         multiTableMapCache.removeData(EID_TEST, SubKeys.RECORD);
447         verify(tableDaoMock).removeSpecific(NORMALIZED_EID, SubKeys.RECORD);
448     }
449
450     /**
451      * Tests {@link MultiTableMapCache#removeData} with table == null.
452      */
453     @Test
454     public void removeDataTest_withNullTable() {
455         when(daoMock.getSpecific(VNI, SubKeys.VNI)).thenReturn(null);
456         multiTableMapCache.removeData(EID_TEST, SubKeys.RECORD);
457
458         Mockito.verifyZeroInteractions(tableDaoMock);
459     }
460
461     /**
462      * Tests {@link MultiTableMapCache#getMappingExactSD} method.
463      */
464     @Test
465     public void getMappingExactSDTest() throws NoSuchMethodException, InvocationTargetException,
466             IllegalAccessException {
467         Method getMappingExactSD = MultiTableMapCache.class.getDeclaredMethod("getMappingExactSD", Eid.class, Eid.class,
468                 ILispDAO.class);
469         getMappingExactSD.setAccessible(true);
470
471         when(tableDaoMock.get(EID_IPV4_PREFIX_DST)).thenReturn(getEntry1());
472         when(srcDstDaoMock.getSpecific(EID_IPV4_PREFIX_SRC, SubKeys.RECORD)).thenReturn(DUMMY_OBJECT);
473
474         Object result = getMappingExactSD.invoke(
475                 multiTableMapCache, EID_IPV4_PREFIX_SRC, EID_IPV4_PREFIX_DST, tableDaoMock);
476         assertEquals(DUMMY_OBJECT, result);
477     }
478
479     /**
480      * Tests {@link MultiTableMapCache#getMappingExactSD} method with null src eid.
481      */
482     @Test
483     public void getMappingExactSDTest_withNullSrcEid() throws NoSuchMethodException, InvocationTargetException,
484             IllegalAccessException {
485         Method getMappingExactSD = MultiTableMapCache.class.getDeclaredMethod("getMappingExactSD", Eid.class, Eid.class,
486                 ILispDAO.class);
487         getMappingExactSD.setAccessible(true);
488
489         when(tableDaoMock.get(EID_IPV4_PREFIX_DST)).thenReturn(getEntry1());
490
491         Object result = getMappingExactSD.invoke(
492                 multiTableMapCache, null, EID_IPV4_PREFIX_DST, tableDaoMock);
493         assertEquals(DUMMY_OBJECT, result);
494     }
495
496     /**
497      * Tests {@link MultiTableMapCache#getMappingExactSD} method with null entry.
498      */
499     @Test
500     public void getMappingExactSDTest_withNullEntry() throws NoSuchMethodException, InvocationTargetException,
501             IllegalAccessException {
502         Method getMappingExactSD = MultiTableMapCache.class.getDeclaredMethod("getMappingExactSD", Eid.class, Eid.class,
503                 ILispDAO.class);
504         getMappingExactSD.setAccessible(true);
505
506         when(tableDaoMock.get(EID_IPV4_PREFIX_DST)).thenReturn(null);
507
508         Object result = getMappingExactSD.invoke(
509                 multiTableMapCache, null, EID_IPV4_PREFIX_DST, tableDaoMock);
510         assertNull(result);
511     }
512
513     /**
514      * The following test is for coverage-increase purpose only.
515      */
516     @Test
517     public void otherTest() {
518         multiTableMapCache.printMappings();
519     }
520
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);
525
526         return entry;
527     }
528
529     private Map<String, Object> getEntry2() {
530         Map<String, Object> entry = Maps.newConcurrentMap();
531         entry.put(SubKeys.RECORD, DUMMY_OBJECT_2);
532
533         return entry;
534     }
535 }