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;
13 import com.google.common.collect.Lists;
14 import java.util.AbstractMap.SimpleImmutableEntry;
15 import java.util.Date;
17 import org.junit.Before;
18 import org.junit.Test;
19 import org.mockito.Mockito;
20 import org.opendaylight.lispflowmapping.interfaces.dao.ILispDAO;
21 import org.opendaylight.lispflowmapping.interfaces.dao.MappingEntry;
22 import org.opendaylight.lispflowmapping.interfaces.dao.SubKeys;
23 import org.opendaylight.lispflowmapping.lisp.type.MappingData;
24 import org.opendaylight.lispflowmapping.lisp.util.LispAddressUtil;
25 import org.opendaylight.lispflowmapping.lisp.util.MaskUtil;
26 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.InstanceIdType;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.inet.binary.types.rev160303.IpAddressBinary;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.inet.binary.types.rev160303.Ipv4AddressBinary;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.XtrId;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.authkey.container.MappingAuthkey;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.authkey.container.MappingAuthkeyBuilder;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecord;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecordBuilder;
36 public class SimpleMapCacheTest {
38 private static ILispDAO tableMock;
39 private static ILispDAO xtrIdDaoMock;
40 private static MappingData mappingDataMock;
41 private static ILispDAO daoMock;
42 private static SimpleMapCache simpleMapCache;
44 private static final String IPV4_STRING_1 = "1.2.3.0";
45 private static final String IPV4_STRING_DST = "192.168.0.1";
46 private static final String IPV4_PREFIX_STRING = "/24";
47 private static final short MASK = 24;
48 private static final long VNI_0 = 0L;
49 private static final long VNI_100 = 100L;
50 private static final byte[] IPV4_RLOC_BINARY = new byte[] {0, 1, 4, 0};
51 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});
53 private static final Eid EID_IPV4_PREFIX_1_VNI = LispAddressUtil
54 .asIpv4PrefixEid(IPV4_STRING_1 + IPV4_PREFIX_STRING, new InstanceIdType(VNI_100));
55 private static final Eid EID_IPV4_PREFIX_2 = LispAddressUtil
56 .asIpv4PrefixEid(IPV4_STRING_1 + IPV4_PREFIX_STRING);
57 private static final Eid EID_IPV4_PREFIX_DST = LispAddressUtil
58 .asIpv4PrefixEid(IPV4_STRING_DST + IPV4_PREFIX_STRING);
59 private static final Eid EID_IPV4 = LispAddressUtil.asIpv4Eid(IPV4_STRING_1);
60 private static final Eid NORMALIZED_EID_1 = MaskUtil.normalize(EID_IPV4_PREFIX_1_VNI);
61 private static final Eid NORMALIZED_EID_2 = MaskUtil.normalize(EID_IPV4_PREFIX_2);
62 private static final Eid NORMALIZED_EID_IPV4 = MaskUtil.normalize(EID_IPV4);
63 private static final Eid NORMALIZED_EID_IPV4_PREFIX_DST = MaskUtil.normalize(EID_IPV4_PREFIX_DST, (short) 24);
65 private static final IpAddressBinary IP_ADDRESS = new IpAddressBinary(new Ipv4AddressBinary(IPV4_RLOC_BINARY));
66 private static final MappingAuthkey MAPPING_AUTHKEY = new MappingAuthkeyBuilder()
68 .setKeyType(1).build();
72 daoMock = Mockito.mock(ILispDAO.class, "dao");
73 tableMock = Mockito.mock(ILispDAO.class);
74 xtrIdDaoMock = Mockito.mock(ILispDAO.class);
75 mappingDataMock = Mockito.mock(MappingData.class);
76 simpleMapCache = new SimpleMapCache(daoMock);
80 * Tests {@link SimpleMapCache#getMapping} method with dstEid == null.
83 public void getMappingTest_withNullDstEid() {
84 assertNull(simpleMapCache.getMapping(null, XTR_ID));
88 * Tests {@link SimpleMapCache#getMapping} method with VNI_100 table == null.
91 public void getMappingTest_withNullVniTable() {
92 Mockito.when(daoMock.getSpecific(VNI_100, SubKeys.VNI)).thenReturn(null);
93 assertNull(simpleMapCache.getMapping(EID_IPV4_PREFIX_1_VNI, XTR_ID));
97 * Tests {@link SimpleMapCache#removeMapping} method with xTR-ID.
100 public void removeMappingTest_withXtrId() {
101 Mockito.when(daoMock.getSpecific(VNI_0, SubKeys.VNI)).thenReturn(tableMock);
102 Mockito.when(tableMock.getSpecific(NORMALIZED_EID_IPV4, SubKeys.XTRID_RECORDS)).thenReturn(xtrIdDaoMock);
104 simpleMapCache.removeMapping(EID_IPV4, XTR_ID);
105 Mockito.verify(xtrIdDaoMock).removeSpecific(XTR_ID, SubKeys.RECORD);
109 * Tests {@link SimpleMapCache#removeMapping} method.
112 public void removeMappingTest() {
113 Mockito.when(daoMock.getSpecific(VNI_0, SubKeys.VNI)).thenReturn(tableMock);
115 simpleMapCache.removeMapping(EID_IPV4);
116 Mockito.verify(tableMock).removeSpecific(MaskUtil.normalize(EID_IPV4), SubKeys.RECORD);
117 Mockito.verify(tableMock).removeSpecific(MaskUtil.normalize(EID_IPV4), SubKeys.SRC_RLOCS);
118 Mockito.verify(tableMock).removeSpecific(MaskUtil.normalize(EID_IPV4), SubKeys.XTRID_RECORDS);
119 Mockito.verifyNoMoreInteractions(tableMock);
123 * Tests {@link SimpleMapCache#removeMapping} method with null VNI_100 table.
126 public void removeMappingTest_withNullVniTable() {
127 Mockito.when(daoMock.getSpecific(VNI_0, SubKeys.VNI)).thenReturn(null);
129 simpleMapCache.removeMapping(EID_IPV4);
130 Mockito.verifyNoMoreInteractions(tableMock);
134 * Tests {@link SimpleMapCache#addAuthenticationKey} method.
137 public void addAuthenticationKeyTest() {
138 Mockito.when(daoMock.getSpecific(VNI_0, SubKeys.VNI)).thenReturn(tableMock);
140 simpleMapCache.addAuthenticationKey(EID_IPV4, MAPPING_AUTHKEY);
141 Mockito.verify(tableMock)
142 .put(MaskUtil.normalize(EID_IPV4), new MappingEntry<>(SubKeys.AUTH_KEY, MAPPING_AUTHKEY));
146 * Tests {@link SimpleMapCache#getAuthenticationKey} method with maskable address.
149 public void getAuthenticationKeyTest_withMaskableAddress() {
150 Mockito.when(daoMock.getSpecific(VNI_100, SubKeys.VNI)).thenReturn(tableMock);
151 Mockito.when(tableMock.getSpecific(MaskUtil.normalize(EID_IPV4_PREFIX_1_VNI, MASK), SubKeys.AUTH_KEY))
152 .thenReturn(MAPPING_AUTHKEY);
154 assertEquals(MAPPING_AUTHKEY, simpleMapCache.getAuthenticationKey(EID_IPV4_PREFIX_1_VNI));
158 * Tests {@link SimpleMapCache#getAuthenticationKey} method with non maskable address.
161 public void addAuthenticationKeyTest_withNonMaskableAddress() {
162 Mockito.when(daoMock.getSpecific(VNI_0, SubKeys.VNI)).thenReturn(tableMock);
163 Mockito.when(tableMock.getSpecific(NORMALIZED_EID_IPV4, SubKeys.AUTH_KEY)).thenReturn(MAPPING_AUTHKEY);
165 assertEquals(MAPPING_AUTHKEY, simpleMapCache.getAuthenticationKey(EID_IPV4));
166 Mockito.verify(tableMock).getSpecific(NORMALIZED_EID_IPV4, SubKeys.AUTH_KEY);
170 * Tests {@link SimpleMapCache#getAuthenticationKey} method with no MappingAuthkey.
173 public void addAuthenticationKeyTest_withNoMappingAuthkey() {
174 Mockito.when(daoMock.getSpecific(VNI_0, SubKeys.VNI)).thenReturn(tableMock);
175 Mockito.when(tableMock.getSpecific(NORMALIZED_EID_IPV4, SubKeys.AUTH_KEY)).thenReturn(null);
177 assertNull(simpleMapCache.getAuthenticationKey(EID_IPV4));
181 * Tests {@link SimpleMapCache#getAuthenticationKey} method with no VNI_100 table.
184 public void addAuthenticationKeyTest_withNullVniTable() {
185 Mockito.when(daoMock.getSpecific(VNI_0, SubKeys.VNI)).thenReturn(null);
187 assertNull(simpleMapCache.getAuthenticationKey(EID_IPV4));
191 * Tests {@link SimpleMapCache#removeAuthenticationKey} method.
194 public void removeAuthenticationKeyTest() {
195 Mockito.when(daoMock.getSpecific(VNI_0, SubKeys.VNI)).thenReturn(tableMock);
197 simpleMapCache.removeAuthenticationKey(EID_IPV4);
198 Mockito.verify(tableMock).removeSpecific(NORMALIZED_EID_IPV4, SubKeys.AUTH_KEY);
202 * Tests {@link SimpleMapCache#removeAuthenticationKey} method with no VNI_100 table.
205 public void removeAuthenticationKeyTest_withNoVniTable() {
206 Mockito.when(daoMock.getSpecific(VNI_0, SubKeys.VNI)).thenReturn(null);
208 simpleMapCache.removeAuthenticationKey(EID_IPV4);
209 Mockito.verify(tableMock, Mockito.never()).removeSpecific(Mockito.any(Eid.class), Mockito.anyString());
213 * Tests {@link SimpleMapCache#getAllXtrIdMappings} method with maskable address.
216 @SuppressWarnings("unchecked")
217 public void getAllXtrIdMappings_withMaskableAddress() {
218 final Eid normalizedKey = MaskUtil.normalize(EID_IPV4_PREFIX_1_VNI, MASK);
219 final Map<String, Object> entryMock = Mockito.mock(Map.class);
220 final ILispDAO xtrIdRecordsMock = Mockito.mock(ILispDAO.class);
222 Mockito.when(daoMock.getSpecific(VNI_100, SubKeys.VNI)).thenReturn(tableMock);
223 Mockito.when(tableMock.getBest(normalizedKey)).thenReturn(entryMock);
224 Mockito.when(entryMock.get(SubKeys.XTRID_RECORDS)).thenReturn(xtrIdRecordsMock);
225 Mockito.when(xtrIdRecordsMock.getSpecific(EID_IPV4_PREFIX_1_VNI, SubKeys.RECORD))
226 .thenReturn(xtrIdDaoMock);
227 simpleMapCache.getAllXtrIdMappings(EID_IPV4_PREFIX_1_VNI);
229 Mockito.verify(tableMock).getBest(Mockito.any(Eid.class));
233 * Tests {@link SimpleMapCache#getAllXtrIdMappings} method with non maskable address.
236 @SuppressWarnings("unchecked")
237 public void getAllXtrIdMappings_withNonMaskableAddress() {
238 final Map<String, Object> entryMock = Mockito.mock(Map.class);
239 final ILispDAO xtrIdRecordsMock = Mockito.mock(ILispDAO.class);
241 Mockito.when(daoMock.getSpecific(VNI_0, SubKeys.VNI)).thenReturn(tableMock);
242 Mockito.when(tableMock.getBest(NORMALIZED_EID_IPV4)).thenReturn(entryMock);
243 Mockito.when(entryMock.get(SubKeys.XTRID_RECORDS)).thenReturn(xtrIdRecordsMock);
244 Mockito.when(xtrIdRecordsMock.getSpecific(EID_IPV4, SubKeys.RECORD))
245 .thenReturn(xtrIdDaoMock);
246 simpleMapCache.getAllXtrIdMappings(EID_IPV4);
248 Mockito.verify(tableMock).getBest(Mockito.any(Eid.class));
252 * Tests {@link SimpleMapCache#getAllXtrIdMappings} method with null daoEntry.
255 public void getAllXtrIdMappings_withNullEntry() {
256 Mockito.when(daoMock.getSpecific(VNI_100, SubKeys.VNI)).thenReturn(tableMock);
257 Mockito.when(tableMock.getBest(Mockito.any(Eid.class))).thenReturn(null);
259 assertNull(simpleMapCache.getAllXtrIdMappings(EID_IPV4_PREFIX_1_VNI));
260 Mockito.verify(tableMock, Mockito.times(1)).getBest(Mockito.any(Eid.class));
264 * Tests {@link SimpleMapCache#getMappingLpmEid} method.
267 @SuppressWarnings("unchecked")
268 public void getMappingLpmEidTest() throws Exception {
269 final Map<String, Object> mapMock = Mockito.mock(Map.class);
270 final SimpleImmutableEntry<Eid, Map<String, ?>> mapPair = new SimpleImmutableEntry<>(
271 NORMALIZED_EID_IPV4_PREFIX_DST, mapMock);
272 final MappingData mappingData = new MappingData(getDefaultMappingRecordBuilder().build());
274 Mockito.when(daoMock.getSpecific(VNI_0, SubKeys.VNI)).thenReturn(tableMock);
275 Mockito.when(tableMock.getBestPair(NORMALIZED_EID_IPV4_PREFIX_DST)).thenReturn(mapPair);
276 Mockito.when(mapMock.get(SubKeys.XTRID_RECORDS)).thenReturn(xtrIdDaoMock);
277 Mockito.when(xtrIdDaoMock.getSpecific(XTR_ID, SubKeys.RECORD))
278 .thenReturn(mappingData); // second invocation
280 // with non-expired mapping record
281 assertEquals(mappingData, simpleMapCache.getMapping(EID_IPV4_PREFIX_DST, XTR_ID));
285 * Tests {@link SimpleMapCache#getMappingLpmEid} method with null XtrId.
288 @SuppressWarnings("unchecked")
289 public void getMappingLpmEidTest_withNullXtrId() throws Exception {
290 final Map<String, Object> mapMock = Mockito.mock(Map.class);
291 final SimpleImmutableEntry<Eid, Map<String, ?>> mapPair = new SimpleImmutableEntry<>(
292 NORMALIZED_EID_IPV4_PREFIX_DST, mapMock);
293 Mockito.when(daoMock.getSpecific(VNI_0, SubKeys.VNI)).thenReturn(tableMock);
294 Mockito.when(tableMock.getBestPair(MaskUtil.normalize(EID_IPV4_PREFIX_DST, (short) 24))).thenReturn(mapPair);
296 simpleMapCache.getMapping(EID_IPV4_PREFIX_DST, (XtrId) null);
297 Mockito.verify(tableMock).getBestPair(NORMALIZED_EID_IPV4_PREFIX_DST);
298 Mockito.verify(mapMock).get(SubKeys.RECORD);
302 * Tests {@link SimpleMapCache#getMapping} method with maskable eid.
305 @SuppressWarnings("unchecked")
306 public void getMappingTest_withMaskableEid() {
307 final Eid ipv4PrefixEid = LispAddressUtil.asIpv4PrefixEid("192.168.0.225" + "/32");
308 final Map<String, Object> entryMock = Mockito.mock(Map.class);
309 final SimpleImmutableEntry<Eid, Map<String, ?>> mapPair = new SimpleImmutableEntry<>(
310 NORMALIZED_EID_IPV4_PREFIX_DST, entryMock);
312 Mockito.when(daoMock.getSpecific(VNI_0, SubKeys.VNI)).thenReturn(tableMock);
313 Mockito.when(tableMock.getBestPair(ipv4PrefixEid)).thenReturn(mapPair);
314 Mockito.when(entryMock.get(SubKeys.XTRID_RECORDS)).thenReturn(xtrIdDaoMock);
315 Mockito.when(xtrIdDaoMock.getSpecific(NORMALIZED_EID_IPV4_PREFIX_DST, SubKeys.XTRID_RECORDS)).thenReturn(null);
317 simpleMapCache.getMapping(ipv4PrefixEid, XTR_ID);
318 Mockito.verify(entryMock).get(SubKeys.XTRID_RECORDS);
322 * Tests {@link SimpleMapCache#getMapping} method with maskable eid and entry not found.
325 public void getMappingTest_withMaskableEid_noEntry() {
326 Mockito.when(daoMock.getSpecific(VNI_0, SubKeys.VNI)).thenReturn(tableMock);
327 Mockito.when(tableMock.get(Mockito.any(Eid.class))).thenReturn(null);
329 assertNull(simpleMapCache.getMapping(EID_IPV4_PREFIX_DST, XTR_ID));
333 * Tests {@link SimpleMapCache#getMapping} method with non-maskable eid.
336 @SuppressWarnings("unchecked")
337 public void getMappingTest_withNonMaskableEid() {
338 final Map<String, Object> entryMock = Mockito.mock(Map.class);
339 final SimpleImmutableEntry<Eid, Map<String, ?>> mapPair = new SimpleImmutableEntry<>(
340 NORMALIZED_EID_IPV4_PREFIX_DST, entryMock);
342 Mockito.when(daoMock.getSpecific(VNI_0, SubKeys.VNI)).thenReturn(tableMock);
343 Mockito.when(tableMock.getBestPair(NORMALIZED_EID_IPV4)).thenReturn(mapPair);
344 Mockito.when(entryMock.get(SubKeys.XTRID_RECORDS)).thenReturn(xtrIdDaoMock);
346 simpleMapCache.getMapping(EID_IPV4, XTR_ID);
347 Mockito.verify(entryMock).get(SubKeys.XTRID_RECORDS);
351 * Tests {@link SimpleMapCache#getMapping} method with non-maskable eid and entry not found.
354 public void getMappingTest_withNonMaskableEid_noEntry() {
355 Mockito.when(daoMock.getSpecific(VNI_0, SubKeys.VNI)).thenReturn(tableMock);
356 Mockito.when(tableMock.get(NORMALIZED_EID_IPV4)).thenReturn(null);
358 assertNull(simpleMapCache.getMapping(EID_IPV4, XTR_ID));
362 * Tests {@link SimpleMapCache#getMapping} method with Eid VNI_100 == null.
365 public void getVniTableTest_withVniNull() {
366 Mockito.when(daoMock.getSpecific(VNI_0, SubKeys.VNI)).thenReturn(null);
368 simpleMapCache.getMapping(EID_IPV4_PREFIX_2, XTR_ID);
369 Mockito.verify(daoMock).getSpecific(VNI_0, SubKeys.VNI);
373 * Tests {@link SimpleMapCache#getVniTable} method with Eid VNI_100 == 100L.
376 public void getVniTableTest_withVniNotNull() {
377 Mockito.when(daoMock.getSpecific(VNI_100, SubKeys.VNI)).thenReturn(null);
379 simpleMapCache.getMapping(EID_IPV4_PREFIX_1_VNI, XTR_ID);
380 Mockito.verify(daoMock).getSpecific(VNI_100, SubKeys.VNI);
384 * Tests {@link SimpleMapCache#addData} method.
387 public void addDataTest() {
388 final Object dummyData = "dummy-data";
389 Mockito.when(daoMock.getSpecific(VNI_0, SubKeys.VNI)).thenReturn(tableMock);
391 simpleMapCache.addData(EID_IPV4, SubKeys.RECORD, dummyData);
392 Mockito.verify(tableMock).put(NORMALIZED_EID_IPV4, new MappingEntry<>(SubKeys.RECORD, dummyData));
396 * Tests {@link SimpleMapCache#getData} method.
399 public void getDataTest() {
400 Mockito.when(daoMock.getSpecific(VNI_0, SubKeys.VNI)).thenReturn(tableMock);
402 simpleMapCache.getData(EID_IPV4, SubKeys.RECORD);
403 Mockito.verify(tableMock).getSpecific(NORMALIZED_EID_IPV4, SubKeys.RECORD);
407 * Tests {@link SimpleMapCache#getData} method with no VNI_100 table.
410 public void getDataTest_withNullVniTable() {
411 Mockito.when(daoMock.getSpecific(VNI_0, SubKeys.VNI)).thenReturn(null);
413 simpleMapCache.getData(EID_IPV4, SubKeys.RECORD);
414 Mockito.verifyNoMoreInteractions(tableMock);
418 * Tests {@link SimpleMapCache#removeData} method.
421 public void removeDataTest() {
422 Mockito.when(daoMock.getSpecific(VNI_0, SubKeys.VNI)).thenReturn(tableMock);
424 simpleMapCache.removeData(EID_IPV4, SubKeys.RECORD);
425 Mockito.verify(tableMock).removeSpecific(NORMALIZED_EID_IPV4, SubKeys.RECORD);
429 * Tests {@link SimpleMapCache#removeData} method with no VNI_100 table.
432 public void removeDataTest_withNullTable() {
433 Mockito.when(daoMock.getSpecific(VNI_0, SubKeys.VNI)).thenReturn(null);
435 simpleMapCache.removeData(EID_IPV4, SubKeys.RECORD);
436 Mockito.verifyNoMoreInteractions(tableMock);
440 * Tests {@link SimpleMapCache#addMapping} method.
443 public void addMappingTest() throws Exception {
444 final Date timestamp = new Date(System.currentTimeMillis());
445 Mockito.when(mappingDataMock.getTimestamp()).thenReturn(timestamp);
446 Mockito.when(daoMock.getSpecific(VNI_100, SubKeys.VNI)).thenReturn(tableMock);
447 Mockito.when(tableMock.getSpecific(NORMALIZED_EID_1, SubKeys.XTRID_RECORDS)).thenReturn(xtrIdDaoMock);
448 Mockito.when(mappingDataMock.getXtrId()).thenReturn(XTR_ID);
450 simpleMapCache.addMapping(EID_IPV4_PREFIX_1_VNI, mappingDataMock);
451 Mockito.verify(tableMock)
452 .put(NORMALIZED_EID_1, new MappingEntry<>(SubKeys.RECORD, mappingDataMock));
456 * Tests {@link SimpleMapCache#getOrInstantiateVniTable} method with vni == null.
459 public void getOrInstantiateVniTableTest_withNullVni() throws Exception {
460 Mockito.when(daoMock.getSpecific(VNI_0, SubKeys.VNI)).thenReturn(tableMock);
461 Mockito.when(tableMock.getSpecific(NORMALIZED_EID_2, SubKeys.XTRID_RECORDS)).thenReturn(xtrIdDaoMock);
463 simpleMapCache.addMapping(EID_IPV4_PREFIX_2, mappingDataMock); // Eid VNI_100 == null
464 Mockito.verify(daoMock).getSpecific(VNI_0, SubKeys.VNI);
465 Mockito.verify(daoMock, Mockito.never()).putNestedTable(VNI_0, SubKeys.VNI);
469 * Tests {@link SimpleMapCache#getOrInstantiateVniTable} method with vni == null, table == null.
472 public void getOrInstantiateVniTableTest_withNullVniAndTable() throws Exception {
473 Mockito.when(daoMock.getSpecific(VNI_0, SubKeys.VNI)).thenReturn(null);
474 Mockito.when(tableMock.getSpecific(NORMALIZED_EID_2, SubKeys.XTRID_RECORDS)).thenReturn(xtrIdDaoMock);
475 Mockito.when(daoMock.putNestedTable(VNI_0, SubKeys.VNI)).thenReturn(tableMock);
477 simpleMapCache.addMapping(EID_IPV4_PREFIX_2, mappingDataMock); // Eid VNI_100 == null
478 Mockito.verify(daoMock).putNestedTable(VNI_0, SubKeys.VNI);
482 * Tests {@link SimpleMapCache#getOrInstantiateVniTable} method with vni == 100L, table == null.
485 public void getOrInstantiateVniTableTest_withNullTable() throws Exception {
486 Mockito.when(daoMock.getSpecific(VNI_100, SubKeys.VNI)).thenReturn(null);
487 Mockito.when(tableMock.getSpecific(NORMALIZED_EID_1, SubKeys.XTRID_RECORDS)).thenReturn(xtrIdDaoMock);
488 Mockito.when(daoMock.putNestedTable(VNI_100, SubKeys.VNI)).thenReturn(tableMock);
490 simpleMapCache.addMapping(EID_IPV4_PREFIX_1_VNI, mappingDataMock); // Eid VNI_100 == null
491 Mockito.verify(daoMock).putNestedTable(VNI_100, SubKeys.VNI);
494 private static MappingRecordBuilder getDefaultMappingRecordBuilder() {
495 return new MappingRecordBuilder()
497 .setLocatorRecord(Lists.newArrayList())
498 .setTimestamp(Long.MAX_VALUE)
500 .setAction(MappingRecord.Action.NativelyForward)
501 .setSourceRloc(IP_ADDRESS);