summaryrefslogtreecommitdiffstats
path: root/lisp/lisp2vpp/src/test/java
diff options
context:
space:
mode:
authorJan Srnicek <jsrnicek@cisco.com>2016-11-09 08:55:04 +0100
committerJan Srnicek <jsrnicek@cisco.com>2016-11-09 08:55:04 +0100
commitddb7683677ef0bcc291f686dbed9c95d50c4046b (patch)
tree3315c21c9e4cba0bb6c25c7c5ec0048bb51458e5 /lisp/lisp2vpp/src/test/java
parent64d4c13102024ab8f1e0215c6a6a4894c3306c56 (diff)
HONEYCOMB-254 - Adjacencies dump support
Added mapping context between adjacency id(HC side) and combination of remote and local eids(vpp side) Change-Id: Icbba9130a82b7af51b23e6d6d68fcfbf49e66c99 Signed-off-by: Jan Srnicek <jsrnicek@cisco.com>
Diffstat (limited to 'lisp/lisp2vpp/src/test/java')
-rw-r--r--lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/context/util/AdjacenciesMappingContextTest.java184
-rw-r--r--lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/context/util/EidMappingContextTest.java2
-rw-r--r--lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/AdjacencyData.java59
-rw-r--r--lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/AdjacencyCustomizerTest.java101
-rw-r--r--lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/write/AdjacencyCustomizerTest.java65
-rw-r--r--lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/util/AdjacencyMappingContextTestHelper.java126
-rw-r--r--lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/util/EidMappingContextHelper.java14
7 files changed, 506 insertions, 45 deletions
diff --git a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/context/util/AdjacenciesMappingContextTest.java b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/context/util/AdjacenciesMappingContextTest.java
new file mode 100644
index 000000000..4a5302ba6
--- /dev/null
+++ b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/context/util/AdjacenciesMappingContextTest.java
@@ -0,0 +1,184 @@
+/*
+ * Copyright (c) 2016 Cisco and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.honeycomb.lisp.context.util;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import com.google.common.base.Optional;
+import com.google.common.collect.ImmutableSet;
+import io.fd.honeycomb.test.tools.HoneycombTestRunner;
+import io.fd.honeycomb.test.tools.annotations.InjectTestData;
+import io.fd.honeycomb.test.tools.annotations.InjectablesProcessor;
+import io.fd.honeycomb.test.tools.annotations.SchemaContextProvider;
+import io.fd.honeycomb.translate.MappingContext;
+import io.fd.honeycomb.translate.util.RWUtils;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Captor;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.adjacencies.identification.context.rev160801.$YangModuleInfoImpl;
+import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.adjacencies.identification.context.rev160801.adjacencies.identification.context.attributes.AdjacenciesIdentificationContexts;
+import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.adjacencies.identification.context.rev160801.adjacencies.identification.context.attributes.adjacencies.identification.contexts.AdjacenciesIdentification;
+import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.adjacencies.identification.context.rev160801.adjacencies.identification.context.attributes.adjacencies.identification.contexts.AdjacenciesIdentificationKey;
+import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.adjacencies.identification.context.rev160801.adjacencies.identification.context.attributes.adjacencies.identification.contexts.adjacencies.identification.Mappings;
+import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.adjacencies.identification.context.rev160801.adjacencies.identification.context.attributes.adjacencies.identification.contexts.adjacencies.identification.mappings.Mapping;
+import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.adjacencies.identification.context.rev160801.adjacencies.identification.context.attributes.adjacencies.identification.contexts.adjacencies.identification.mappings.MappingKey;
+import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.adjacencies.identification.context.rev160801.adjacencies.identification.context.attributes.adjacencies.identification.contexts.adjacencies.identification.mappings.mapping.EidIdentificatorPair;
+import org.opendaylight.yangtools.sal.binding.generator.impl.ModuleInfoBackedContext;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
+
+@RunWith(HoneycombTestRunner.class)
+public class AdjacenciesMappingContextTest implements InjectablesProcessor {
+
+ private static final String PARENT_1 = "first";
+ private static final String PARENT_2 = "second";
+ private static final String PARENT_3 = "third";
+ private static final String PARENT_4 = "fourth";
+
+ private static final String LOCAL_EID_ID_1 = "local-eid-1";
+ private static final String LOCAL_EID_ID_2 = "local-eid-2";
+ private static final String LOCAL_EID_ID_3 = "local-eid-3";
+
+ private static final String REMOTE_EID_ID_1 = "remote-eid-1";
+ private static final String REMOTE_EID_ID_2 = "remote-eid-2";
+ private static final String REMOTE_EID_ID_3 = "remote-eid-3";
+
+ @Mock
+ private MappingContext mappingContext;
+
+ @Captor
+ private ArgumentCaptor<Mapping> mappingArgumentCaptor;
+
+ @Captor
+ private ArgumentCaptor<KeyedInstanceIdentifier<Mapping, MappingKey>> keyedInstanceIdentifierArgumentCaptor;
+
+ private AdjacenciesMappingContext adjacenciesMappingContext;
+ private KeyedInstanceIdentifier<AdjacenciesIdentification, AdjacenciesIdentificationKey>
+ adjacenciesMappingContextId;
+
+ @SchemaContextProvider
+ public ModuleInfoBackedContext schemaContext() {
+ return provideSchemaContextFor(ImmutableSet.of($YangModuleInfoImpl.getInstance(),
+ org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.$YangModuleInfoImpl
+ .getInstance()));
+ }
+
+ @InjectTestData(resourcePath = "/adjacencies-identification-context.json", id = "/naming-context:contexts" +
+ "/adjacencies-identification-context:adjacencies-identification-contexts" +
+ "/adjacencies-identification-context:adjacencies-identification[adjacencies-identification-context:name='context']" +
+ "/adjacencies-identification-context:mappings")
+ private Mappings mappings;
+
+ @Before
+ public void init() {
+ MockitoAnnotations.initMocks(this);
+
+ adjacenciesMappingContext = new AdjacenciesMappingContext("context");
+ adjacenciesMappingContextId = InstanceIdentifier.create(AdjacenciesIdentificationContexts.class).child(
+ AdjacenciesIdentification.class, new AdjacenciesIdentificationKey("context"));
+
+ when(mappingContext.read(adjacenciesMappingContextId.child(Mappings.class))).thenReturn(Optional.of(mappings));
+ when(mappingContext.read(parentKey(PARENT_1))).thenReturn(Optional.of(filterForParent(PARENT_1)));
+ when(mappingContext.read(parentKey(PARENT_2))).thenReturn(Optional.of(filterForParent(PARENT_2)));
+ when(mappingContext.read(parentKey(PARENT_3))).thenReturn(Optional.of(filterForParent(PARENT_3)));
+ }
+
+ private Mapping filterForParent(final String parent) {
+ return mappings.getMapping().stream()
+ .filter(mapping -> mapping.getId().equals(parent))
+ .collect(RWUtils.singleItemCollector());
+ }
+
+ private KeyedInstanceIdentifier<Mapping, MappingKey> parentKey(final String parent) {
+ return adjacenciesMappingContextId.child(Mappings.class).child(Mapping.class, new MappingKey(parent));
+ }
+
+ @Test
+ public void getAdjacencyId() throws Exception {
+ assertEquals(PARENT_1,
+ adjacenciesMappingContext.getAdjacencyId(LOCAL_EID_ID_1, REMOTE_EID_ID_1, mappingContext));
+ assertEquals(PARENT_2,
+ adjacenciesMappingContext.getAdjacencyId(LOCAL_EID_ID_2, REMOTE_EID_ID_2, mappingContext));
+ assertEquals(PARENT_3,
+ adjacenciesMappingContext.getAdjacencyId(LOCAL_EID_ID_3, REMOTE_EID_ID_3, mappingContext));
+ }
+
+ @Test
+ public void containsId() throws Exception {
+ assertTrue(adjacenciesMappingContext.containsId(LOCAL_EID_ID_1, REMOTE_EID_ID_1, mappingContext));
+ assertTrue(adjacenciesMappingContext.containsId(LOCAL_EID_ID_2, REMOTE_EID_ID_2, mappingContext));
+ assertTrue(adjacenciesMappingContext.containsId(LOCAL_EID_ID_3, REMOTE_EID_ID_3, mappingContext));
+ }
+
+ @Test
+ public void addEidPair() throws Exception {
+ adjacenciesMappingContext.addEidPair(PARENT_4, LOCAL_EID_ID_1, REMOTE_EID_ID_3, mappingContext);
+ verify(mappingContext, times(1))
+ .put(keyedInstanceIdentifierArgumentCaptor.capture(), mappingArgumentCaptor.capture());
+
+ final KeyedInstanceIdentifier<Mapping, MappingKey> key = keyedInstanceIdentifierArgumentCaptor.getValue();
+ final Mapping mapping = mappingArgumentCaptor.getValue();
+
+ assertEquals(PARENT_4, key.getKey().getId());
+ assertEquals(PARENT_4, mapping.getId());
+ assertEquals(PARENT_4, mapping.getKey().getId());
+
+ final EidIdentificatorPair pair = mapping.getEidIdentificatorPair();
+ assertEquals(LOCAL_EID_ID_1, pair.getLocalEidId().getValue());
+ assertEquals(REMOTE_EID_ID_3, pair.getRemoteEidId().getValue());
+ }
+
+ @Test
+ public void removeForIndex() throws Exception {
+ adjacenciesMappingContext.removeForIndex(PARENT_1, mappingContext);
+ adjacenciesMappingContext.removeForIndex(PARENT_2, mappingContext);
+ adjacenciesMappingContext.removeForIndex(PARENT_3, mappingContext);
+ verify(mappingContext, times(1)).delete(parentKey(PARENT_1));
+ verify(mappingContext, times(1)).delete(parentKey(PARENT_2));
+ verify(mappingContext, times(1)).delete(parentKey(PARENT_3));
+ }
+
+ @Test
+ public void getEidPair() throws Exception {
+ final EidIdentificatorPair pair1 = adjacenciesMappingContext.getEidPair(PARENT_1, mappingContext);
+ final EidIdentificatorPair pair2 = adjacenciesMappingContext.getEidPair(PARENT_2, mappingContext);
+ final EidIdentificatorPair pair3 = adjacenciesMappingContext.getEidPair(PARENT_3, mappingContext);
+
+ assertEquals(LOCAL_EID_ID_1, pair1.getLocalEidId().getValue());
+ assertEquals(REMOTE_EID_ID_1, pair1.getRemoteEidId().getValue());
+ assertEquals(LOCAL_EID_ID_2, pair2.getLocalEidId().getValue());
+ assertEquals(REMOTE_EID_ID_2, pair2.getRemoteEidId().getValue());
+ assertEquals(LOCAL_EID_ID_3, pair3.getLocalEidId().getValue());
+ assertEquals(REMOTE_EID_ID_3, pair3.getRemoteEidId().getValue());
+ }
+
+ @Test
+ public void containsEidPairForIndex() throws Exception {
+ assertTrue(adjacenciesMappingContext.containsEidPairForIndex(PARENT_1, mappingContext));
+ assertTrue(adjacenciesMappingContext.containsEidPairForIndex(PARENT_2, mappingContext));
+ assertTrue(adjacenciesMappingContext.containsEidPairForIndex(PARENT_3, mappingContext));
+ }
+
+} \ No newline at end of file
diff --git a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/context/util/EidMappingContextTest.java b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/context/util/EidMappingContextTest.java
index 0a7dcb1bd..ccd38292e 100644
--- a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/context/util/EidMappingContextTest.java
+++ b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/context/util/EidMappingContextTest.java
@@ -59,7 +59,7 @@ public class EidMappingContextTest implements EidMappingContextHelper {
mappingEid = fromLocalToMappingEid(localEid);
mappingId = new MappingId("mapping");
- defineMapping(mappingContext, mappingEid, mappingId, EID_MAPPING_CONTEXT_NAME);
+ defineEidMapping(mappingContext, mappingEid, mappingId, EID_MAPPING_CONTEXT_NAME);
}
@Test
diff --git a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/AdjacencyData.java b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/AdjacencyData.java
new file mode 100644
index 000000000..2ecfe175f
--- /dev/null
+++ b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/AdjacencyData.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2016 Cisco and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.honeycomb.lisp.translate;
+
+import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.eid.mapping.context.rev160801.contexts.eid.mapping.context.mappings.mapping.Eid;
+import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.eid.mapping.context.rev160801.contexts.eid.mapping.context.mappings.mapping.EidBuilder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.InstanceIdType;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.Ipv4Afi;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv4Builder;
+
+public class AdjacencyData {
+
+ public static final Long VNI = 12L;
+
+ public static final Ipv4Address ADDRESS_ONE = new Ipv4Address("192.168.2.1");
+ public static final Ipv4Address ADDRESS_TWO = new Ipv4Address("192.168.2.2");
+ public static final Ipv4Address ADDRESS_THREE = new Ipv4Address("192.168.2.3");
+ public static final Ipv4Address ADDRESS_FOUR = new Ipv4Address("192.168.2.4");
+
+ public static final Eid LOCAL_EID_ONE = new EidBuilder()
+ .setAddressType(Ipv4Afi.class)
+ .setVirtualNetworkId(new InstanceIdType(VNI))
+ .setAddress(new Ipv4Builder().setIpv4(ADDRESS_ONE).build())
+ .build();
+
+ public static final Eid LOCAL_EID_TWO = new EidBuilder()
+ .setAddressType(Ipv4Afi.class)
+ .setVirtualNetworkId(new InstanceIdType(VNI))
+ .setAddress(new Ipv4Builder().setIpv4(ADDRESS_TWO).build())
+ .build();
+
+ public static final Eid REMOTE_EID_ONE = new EidBuilder()
+ .setAddressType(Ipv4Afi.class)
+ .setVirtualNetworkId(new InstanceIdType(VNI))
+ .setAddress(new Ipv4Builder().setIpv4(ADDRESS_THREE).build())
+ .build();
+ public static final Eid REMOTE_EID_TWO = new EidBuilder()
+ .setAddressType(Ipv4Afi.class)
+ .setVirtualNetworkId(new InstanceIdType(VNI))
+ .setAddress(new Ipv4Builder().setIpv4(ADDRESS_FOUR).build())
+ .build();
+
+
+}
diff --git a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/AdjacencyCustomizerTest.java b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/AdjacencyCustomizerTest.java
index 773c404ca..09d4d27fb 100644
--- a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/AdjacencyCustomizerTest.java
+++ b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/AdjacencyCustomizerTest.java
@@ -16,21 +16,52 @@
package io.fd.honeycomb.lisp.translate.read;
-import static org.junit.Assert.assertTrue;
+import static io.fd.honeycomb.lisp.translate.AdjacencyData.ADDRESS_ONE;
+import static io.fd.honeycomb.lisp.translate.AdjacencyData.ADDRESS_THREE;
+import static io.fd.honeycomb.lisp.translate.AdjacencyData.LOCAL_EID_ONE;
+import static io.fd.honeycomb.lisp.translate.AdjacencyData.LOCAL_EID_TWO;
+import static io.fd.honeycomb.lisp.translate.AdjacencyData.REMOTE_EID_ONE;
+import static io.fd.honeycomb.lisp.translate.AdjacencyData.REMOTE_EID_TWO;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.contains;
+import static org.hamcrest.Matchers.hasSize;
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.when;
-import io.fd.honeycomb.translate.read.ReadFailedException;
+import io.fd.honeycomb.lisp.context.util.AdjacenciesMappingContext;
+import io.fd.honeycomb.lisp.context.util.EidMappingContext;
+import io.fd.honeycomb.lisp.translate.util.EidMetadataProvider;
+import io.fd.honeycomb.lisp.util.AdjacencyMappingContextTestHelper;
+import io.fd.honeycomb.lisp.util.EidMappingContextHelper;
import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
+import io.fd.honeycomb.translate.vpp.util.ByteDataTranslator;
import io.fd.honeycomb.vpp.test.read.ListReaderCustomizerTest;
+import io.fd.vpp.jvpp.core.dto.LispAdjacenciesGetReply;
+import io.fd.vpp.jvpp.core.types.LispAdjacency;
+import java.util.List;
import org.junit.Before;
import org.junit.Test;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv4;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.MappingId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.adjacencies.grouping.Adjacencies;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.adjacencies.grouping.AdjacenciesBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.adjacencies.grouping.adjacencies.Adjacency;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.adjacencies.grouping.adjacencies.AdjacencyBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.adjacencies.grouping.adjacencies.AdjacencyKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.dp.subtable.grouping.RemoteMappings;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.dp.subtable.grouping.remote.mappings.RemoteMapping;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.dp.subtable.grouping.remote.mappings.RemoteMappingKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.eid.table.grouping.EidTable;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.eid.table.grouping.eid.table.VniTable;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.eid.table.grouping.eid.table.VniTableKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.eid.table.grouping.eid.table.vni.table.BridgeDomainSubtable;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-public class AdjacencyCustomizerTest extends ListReaderCustomizerTest<Adjacency, AdjacencyKey, AdjacencyBuilder> {
+public class AdjacencyCustomizerTest
+ extends ListReaderCustomizerTest<Adjacency, AdjacencyKey, AdjacencyBuilder>
+ implements ByteDataTranslator, EidMetadataProvider, EidMappingContextHelper, AdjacencyMappingContextTestHelper {
private InstanceIdentifier<Adjacency> identifier;
@@ -40,21 +71,75 @@ public class AdjacencyCustomizerTest extends ListReaderCustomizerTest<Adjacency,
@Before
public void init() {
- identifier = InstanceIdentifier.create(Adjacency.class);
+ identifier = InstanceIdentifier.create(EidTable.class)
+ .child(VniTable.class, new VniTableKey(2L))
+ .child(BridgeDomainSubtable.class)
+ .child(RemoteMappings.class)
+ .child(RemoteMapping.class, new RemoteMappingKey(new MappingId("remote-mapping")))
+ .child(Adjacencies.class)
+ .child(Adjacency.class, new AdjacencyKey("adj-one"));
+
+
+ mockApi();
+ defineEidMapping(mappingContext, LOCAL_EID_ONE, new MappingId("local-eid-one"), "local-mapping-context");
+ defineEidMapping(mappingContext, LOCAL_EID_TWO, new MappingId("local-eid-two"), "local-mapping-context");
+ defineEidMapping(mappingContext, REMOTE_EID_ONE, new MappingId("remote-eid-one"), "remote-mapping-context");
+ defineEidMapping(mappingContext, REMOTE_EID_TWO, new MappingId("remote-eid-two"), "remote-mapping-context");
+
+ defineAdjacencyMapping(mappingContext, "local-eid-one", "remote-eid-one", "adj-one",
+ "adjacencies-mapping-context");
+ defineAdjacencyMapping(mappingContext, "local-eid-two", "remote-eid-two", "adj-two",
+ "adjacencies-mapping-context");
+ mockApi();
}
@Test
public void getAllIds() throws Exception {
- assertTrue(getCustomizer().getAllIds(identifier, ctx).isEmpty());
+ final List<AdjacencyKey> keys = getCustomizer().getAllIds(identifier, ctx);
+
+ assertThat(keys, hasSize(2));
+ assertThat(keys, contains(new AdjacencyKey("adj-one"), new AdjacencyKey("adj-two")));
}
- @Test(expected = ReadFailedException.class)
+ @Test
public void readCurrentAttributes() throws Exception {
- getCustomizer().readCurrentAttributes(identifier, new AdjacencyBuilder(), ctx);
+ final AdjacencyBuilder builder = new AdjacencyBuilder();
+ getCustomizer().readCurrentAttributes(identifier, builder, ctx);
+
+ assertEquals("adj-one", builder.getId());
+ assertEquals(new AdjacencyKey("adj-one"), builder.getKey());
+ assertEquals(ADDRESS_ONE.getValue(), Ipv4.class.cast(builder.getLocalEid().getAddress()).getIpv4().getValue());
+ assertEquals(ADDRESS_THREE.getValue(),
+ Ipv4.class.cast(builder.getRemoteEid().getAddress()).getIpv4().getValue());
}
@Override
protected ReaderCustomizer<Adjacency, AdjacencyBuilder> initCustomizer() {
- return new AdjacencyCustomizer(api);
+ return new AdjacencyCustomizer(api, new EidMappingContext("local-mapping-context"),
+ new EidMappingContext("remote-mapping-context"),
+ new AdjacenciesMappingContext("adjacencies-mapping-context"));
+ }
+
+
+ private void mockApi() {
+ LispAdjacency adjacencyOne = new LispAdjacency();
+ adjacencyOne.eidType = 0;
+ adjacencyOne.leid = new byte[]{-64, -88, 2, 1};
+ adjacencyOne.leidPrefixLen = 32;
+ adjacencyOne.reid = new byte[]{-64, -88, 2, 3};
+ adjacencyOne.reidPrefixLen = 32;
+
+
+ LispAdjacency adjacencyTwo = new LispAdjacency();
+ adjacencyTwo.eidType = 0;
+ adjacencyTwo.leid = new byte[]{-64, -88, 2, 2};
+ adjacencyTwo.leidPrefixLen = 32;
+ adjacencyTwo.reid = new byte[]{-64, -88, 2, 4};
+ adjacencyTwo.reidPrefixLen = 32;
+
+ LispAdjacenciesGetReply reply = new LispAdjacenciesGetReply();
+ reply.adjacencies = new LispAdjacency[]{adjacencyOne, adjacencyTwo};
+
+ when(api.lispAdjacenciesGet(any())).thenReturn(future(reply));
}
} \ No newline at end of file
diff --git a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/write/AdjacencyCustomizerTest.java b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/write/AdjacencyCustomizerTest.java
index 5be25bfe7..0b2536b85 100644
--- a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/write/AdjacencyCustomizerTest.java
+++ b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/write/AdjacencyCustomizerTest.java
@@ -16,6 +16,10 @@
package io.fd.honeycomb.lisp.translate.write;
+import static io.fd.honeycomb.lisp.translate.AdjacencyData.ADDRESS_ONE;
+import static io.fd.honeycomb.lisp.translate.AdjacencyData.ADDRESS_THREE;
+import static io.fd.honeycomb.lisp.translate.AdjacencyData.LOCAL_EID_ONE;
+import static io.fd.honeycomb.lisp.translate.AdjacencyData.REMOTE_EID_ONE;
import static io.fd.honeycomb.lisp.translate.read.dump.executor.params.MappingsDumpParams.EidType.IPV4;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
@@ -26,8 +30,9 @@ import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+import io.fd.honeycomb.lisp.context.util.AdjacenciesMappingContext;
import io.fd.honeycomb.lisp.context.util.EidMappingContext;
-import io.fd.honeycomb.translate.MappingContext;
+import io.fd.honeycomb.lisp.util.EidMappingContextHelper;
import io.fd.honeycomb.vpp.test.write.WriterCustomizerTest;
import io.fd.vpp.jvpp.core.dto.LispAddDelAdjacency;
import io.fd.vpp.jvpp.core.dto.LispAddDelAdjacencyReply;
@@ -43,30 +48,34 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.addres
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv4Builder;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.MacBuilder;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.MappingId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.adjacencies.grouping.Adjacencies;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.adjacencies.grouping.adjacencies.Adjacency;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.adjacencies.grouping.adjacencies.AdjacencyBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.adjacencies.grouping.adjacencies.AdjacencyKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.adjacencies.grouping.adjacencies.adjacency.LocalEidBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.adjacencies.grouping.adjacencies.adjacency.RemoteEidBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.dp.subtable.grouping.RemoteMappings;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.dp.subtable.grouping.remote.mappings.RemoteMapping;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.dp.subtable.grouping.remote.mappings.RemoteMappingKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.eid.table.grouping.EidTable;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.eid.table.grouping.eid.table.VniTable;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.eid.table.grouping.eid.table.VniTableKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.eid.table.grouping.eid.table.vni.table.BridgeDomainSubtable;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-public class AdjacencyCustomizerTest extends WriterCustomizerTest {
+public class AdjacencyCustomizerTest extends WriterCustomizerTest implements EidMappingContextHelper {
@Captor
private ArgumentCaptor<LispAddDelAdjacency> requestCaptor;
- @Mock
private EidMappingContext localMappingContext;
- @Mock
private EidMappingContext remoteMappingContext;
+ @Mock
+ private AdjacenciesMappingContext adjacenciesMappingContext;
+
private AdjacencyCustomizer customizer;
private InstanceIdentifier<Adjacency> emptyId;
@@ -78,16 +87,18 @@ public class AdjacencyCustomizerTest extends WriterCustomizerTest {
@Before
public void init() {
- customizer = new AdjacencyCustomizer(api, localMappingContext, remoteMappingContext);
+ localMappingContext = new EidMappingContext("local-mapping-context");
+ remoteMappingContext = new EidMappingContext("remote-mapping-context");
+ customizer = new AdjacencyCustomizer(api, localMappingContext, remoteMappingContext, adjacenciesMappingContext);
emptyId = InstanceIdentifier.create(Adjacency.class);
validId = InstanceIdentifier.create(EidTable.class)
.child(VniTable.class, new VniTableKey(2L))
.child(BridgeDomainSubtable.class)
.child(RemoteMappings.class)
- .child(RemoteMapping.class)
+ .child(RemoteMapping.class, new RemoteMappingKey(new MappingId("remote-mapping")))
.child(Adjacencies.class)
- .child(Adjacency.class);
+ .child(Adjacency.class, new AdjacencyKey("adj-one"));
emptyData = new AdjacencyBuilder().build();
@@ -108,12 +119,12 @@ public class AdjacencyCustomizerTest extends WriterCustomizerTest {
new LocalEidBuilder()
.setVirtualNetworkId(new InstanceIdType(12L))
.setAddressType(Ipv4Afi.class)
- .setAddress(new Ipv4Builder().setIpv4(new Ipv4Address("192.168.2.1")).build())
+ .setAddress(new Ipv4Builder().setIpv4(ADDRESS_ONE).build())
.build()).setRemoteEid(
new RemoteEidBuilder()
.setVirtualNetworkId(new InstanceIdType(12L))
.setAddressType(Ipv4Afi.class)
- .setAddress(new Ipv4Builder().setIpv4(new Ipv4Address("192.168.5.2")).build()).build()).build();
+ .setAddress(new Ipv4Builder().setIpv4(ADDRESS_THREE).build()).build()).build();
when(api.lispAddDelAdjacency(any())).thenReturn(future(new LispAddDelAdjacencyReply()));
}
@@ -145,31 +156,20 @@ public class AdjacencyCustomizerTest extends WriterCustomizerTest {
@Test
public void writeCurrentAttributes() throws Exception {
- when(localMappingContext.containsId(
- any(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.dp.subtable.grouping.local.mappings.local.mapping.Eid.class),
- any(
- MappingContext.class))).thenReturn(true);
-
- when(remoteMappingContext.containsId(
- any(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.dp.subtable.grouping.remote.mappings.remote.mapping.Eid.class),
- any(
- MappingContext.class))).thenReturn(true);
-
+ defineEidMapping(mappingContext, LOCAL_EID_ONE, new MappingId("local-eid-one"), "local-mapping-context");
+ defineEidMapping(mappingContext, REMOTE_EID_ONE, new MappingId("remote-eid-one"), "remote-mapping-context");
customizer.writeCurrentAttributes(validId, validData, writeContext);
verify(api, times(1)).lispAddDelAdjacency(requestCaptor.capture());
- verifyRequest(requestCaptor.getValue(), 1, new byte[]{-64, -88, 2, 1}, 32, new byte[]{-64, -88, 5, 2},
+ verifyRequest(requestCaptor.getValue(), 1, new byte[]{-64, -88, 2, 1}, 32, new byte[]{-64, -88, 2, 3},
32, IPV4.getValue(), 2);
+ verify(adjacenciesMappingContext, times(1))
+ .addEidPair("adj-one", "local-eid-one", "remote-eid-one", mappingContext);
}
@Test
public void writeCurrentAttributesNonExistingLocalMapping() throws Exception {
- when(localMappingContext.containsId(
- any(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.dp.subtable.grouping.local.mappings.local.mapping.Eid.class),
- any(MappingContext.class))).thenReturn(false);
-
- when(remoteMappingContext.containsId(
- any(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.dp.subtable.grouping.remote.mappings.remote.mapping.Eid.class),
- any(MappingContext.class))).thenReturn(true);
+ noEidMappingDefined(mappingContext, "local-eid-one", "local-mapping-context");
+ defineEidMapping(mappingContext, REMOTE_EID_ONE, new MappingId("remote-eid-one"), "remote-mapping-context");
try {
customizer.writeCurrentAttributes(validId, validData, writeContext);
} catch (IllegalStateException e) {
@@ -182,13 +182,9 @@ public class AdjacencyCustomizerTest extends WriterCustomizerTest {
@Test
public void writeCurrentAttributesNonExistingRemoteMapping() throws Exception {
- when(localMappingContext.containsId(
- any(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.dp.subtable.grouping.local.mappings.local.mapping.Eid.class),
- any(MappingContext.class))).thenReturn(true);
+ noEidMappingDefined(mappingContext, "remote-eid-one", "remote-mapping-context");
+ defineEidMapping(mappingContext, LOCAL_EID_ONE, new MappingId("local-eid-one"), "local-mapping-context");
- when(remoteMappingContext.containsId(
- any(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.dp.subtable.grouping.remote.mappings.remote.mapping.Eid.class),
- any(MappingContext.class))).thenReturn(false);
try {
customizer.writeCurrentAttributes(validId, validData, writeContext);
} catch (IllegalStateException e) {
@@ -225,8 +221,9 @@ public class AdjacencyCustomizerTest extends WriterCustomizerTest {
public void deleteCurrentAttributes() throws Exception {
customizer.deleteCurrentAttributes(validId, validData, writeContext);
verify(api, times(1)).lispAddDelAdjacency(requestCaptor.capture());
- verifyRequest(requestCaptor.getValue(), 0, new byte[]{-64, -88, 2, 1}, 32, new byte[]{-64, -88, 5, 2},
+ verifyRequest(requestCaptor.getValue(), 0, new byte[]{-64, -88, 2, 1}, 32, new byte[]{-64, -88, 2, 3},
32, IPV4.getValue(), 2);
+ verify(adjacenciesMappingContext, times(1)).removeForIndex("adj-one", mappingContext);
}
private static void verifyRequest(final LispAddDelAdjacency request, final int isAdd, final byte[] leid,
diff --git a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/util/AdjacencyMappingContextTestHelper.java b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/util/AdjacencyMappingContextTestHelper.java
new file mode 100644
index 000000000..1d6615472
--- /dev/null
+++ b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/util/AdjacencyMappingContextTestHelper.java
@@ -0,0 +1,126 @@
+/*
+ * Copyright (c) 2016 Cisco and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.honeycomb.lisp.util;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+import static org.mockito.Mockito.doReturn;
+
+import com.google.common.base.Optional;
+import com.google.common.collect.Lists;
+import io.fd.honeycomb.translate.MappingContext;
+import java.util.List;
+import javax.annotation.Nonnull;
+import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.adjacencies.identification.context.rev160801.adjacencies.identification.context.attributes.AdjacenciesIdentificationContexts;
+import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.adjacencies.identification.context.rev160801.adjacencies.identification.context.attributes.adjacencies.identification.contexts.AdjacenciesIdentification;
+import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.adjacencies.identification.context.rev160801.adjacencies.identification.context.attributes.adjacencies.identification.contexts.AdjacenciesIdentificationKey;
+import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.adjacencies.identification.context.rev160801.adjacencies.identification.context.attributes.adjacencies.identification.contexts.adjacencies.identification.Mappings;
+import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.adjacencies.identification.context.rev160801.adjacencies.identification.context.attributes.adjacencies.identification.contexts.adjacencies.identification.MappingsBuilder;
+import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.adjacencies.identification.context.rev160801.adjacencies.identification.context.attributes.adjacencies.identification.contexts.adjacencies.identification.mappings.Mapping;
+import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.adjacencies.identification.context.rev160801.adjacencies.identification.context.attributes.adjacencies.identification.contexts.adjacencies.identification.mappings.MappingBuilder;
+import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.adjacencies.identification.context.rev160801.adjacencies.identification.context.attributes.adjacencies.identification.contexts.adjacencies.identification.mappings.MappingKey;
+import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.adjacencies.identification.context.rev160801.adjacencies.identification.context.attributes.adjacencies.identification.contexts.adjacencies.identification.mappings.mapping.EidIdentificatorPair;
+import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.adjacencies.identification.context.rev160801.adjacencies.identification.context.attributes.adjacencies.identification.contexts.adjacencies.identification.mappings.mapping.EidIdentificatorPairBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.MappingId;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
+
+/**
+ * Utility for mocking adjacency mappings
+ */
+public interface AdjacencyMappingContextTestHelper {
+
+ /**
+ * Creates {@link Mapping} for given data.
+ *
+ * @param pair to be mapped
+ * @param id to be mapped
+ * @return eid to id mapping
+ */
+ default Optional<Mapping> mapping(@Nonnull final EidIdentificatorPair pair, final String id) {
+ return Optional.of(new MappingBuilder().setEidIdentificatorPair(pair).setId(id).build());
+ }
+
+ /**
+ * Creates {@link KeyedInstanceIdentifier} for {@link Mapping} in {@link AdjacenciesIdentificationContexts}.
+ *
+ * @param id identificator of the mapping
+ * @param mappingContextName identificator of the mapping context
+ * @return identifier for the mapping
+ */
+ static KeyedInstanceIdentifier<Mapping, MappingKey> mappingIid(@Nonnull final String id,
+ @Nonnull final String mappingContextName) {
+ return InstanceIdentifier.create(AdjacenciesIdentificationContexts.class).child(AdjacenciesIdentification.class,
+ new AdjacenciesIdentificationKey(mappingContextName)).child(Mappings.class)
+ .child(Mapping.class, new MappingKey(id));
+ }
+
+ static EidIdentificatorPair pairOf(@Nonnull final String local, @Nonnull final String remote) {
+ return new EidIdentificatorPairBuilder()
+ .setLocalEidId(new MappingId(checkNotNull(local, "Local id cannot be null")))
+ .setRemoteEidId(new MappingId(checkNotNull(remote, "Remote id cannot be null")))
+ .build();
+ }
+
+ /**
+ * Stubs {@link MappingContext#read} to include given mapping in {@link AdjacenciesIdentification}.
+ *
+ * @param mappingContext mock instance of {@link MappingContext}
+ * @param localEidId local id for identification pair
+ * @param remoteEidId remote id for identification pair
+ * @param mappingName index to be mapped
+ * @param namingContextName name of the naming context
+ */
+ default void defineAdjacencyMapping(@Nonnull final MappingContext mappingContext, @Nonnull final String localEidId,
+ @Nonnull final String remoteEidId, @Nonnull final String mappingName,
+ @Nonnull final String namingContextName) {
+ final KeyedInstanceIdentifier<Mapping, MappingKey> mappingIid = mappingIid(mappingName, namingContextName);
+ final InstanceIdentifier<Mappings> mappingsIid = mappingIid.firstIdentifierOf(Mappings.class);
+
+ final Optional<Mapping> singleMapping = mapping(pairOf(localEidId, remoteEidId), mappingName);
+ final List<Mapping> list = Common.getMappingList(mappingContext, mappingsIid);
+ list.add(singleMapping.get());
+
+ doReturn(Optional.of(new MappingsBuilder().setMapping(list).build())).when(mappingContext).read(mappingsIid);
+ doReturn(singleMapping).when(mappingContext).read(mappingIid);
+ }
+
+ default void noAdjacencyMappingDefined(@Nonnull final MappingContext mappingContext, @Nonnull final String name,
+ @Nonnull final String namingContextName) {
+ final InstanceIdentifier<Mappings> iid =
+ mappingIid(name, namingContextName).firstIdentifierOf(Mappings.class);
+ final List<Mapping> list = Common.getMappingList(mappingContext, iid);
+
+ doReturn(Optional.of(new MappingsBuilder().setMapping(list).build())).when(mappingContext).read(iid);
+ doReturn(Optional.absent()).when(mappingContext).read(mappingIid(name, namingContextName));
+ }
+
+ final class Common {
+ private static List<Mapping> getMappingList(@Nonnull final MappingContext mappingContext,
+ @Nonnull final InstanceIdentifier<Mappings> mappingsIid) {
+ final Optional<Mappings> previousMappings = mappingContext.read(mappingsIid);
+ final MappingsBuilder mappingsBuilder;
+ if (previousMappings != null && previousMappings.isPresent()) {
+ mappingsBuilder = new MappingsBuilder(previousMappings.get());
+ } else {
+ mappingsBuilder = new MappingsBuilder();
+ mappingsBuilder.setMapping(Lists.newArrayList());
+ }
+ return mappingsBuilder.getMapping();
+ }
+ }
+
+}
diff --git a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/util/EidMappingContextHelper.java b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/util/EidMappingContextHelper.java
index 296252915..70d536135 100644
--- a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/util/EidMappingContextHelper.java
+++ b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/util/EidMappingContextHelper.java
@@ -76,8 +76,8 @@ public interface EidMappingContextHelper {
* @param mappingName index to be mapped
* @param namingContextName name of the naming context
*/
- default void defineMapping(@Nonnull final MappingContext mappingContext, @Nonnull final Eid eid,
- final MappingId mappingName, @Nonnull final String namingContextName) {
+ default void defineEidMapping(@Nonnull final MappingContext mappingContext, @Nonnull final Eid eid,
+ final MappingId mappingName, @Nonnull final String namingContextName) {
final KeyedInstanceIdentifier<Mapping, MappingKey> mappingIid = mappingIid(mappingName, namingContextName);
final InstanceIdentifier<Mappings> mappingsIid = mappingIid.firstIdentifierOf(Mappings.class);
@@ -89,6 +89,16 @@ public interface EidMappingContextHelper {
doReturn(singleMapping).when(mappingContext).read(mappingIid);
}
+ default void noEidMappingDefined(@Nonnull final MappingContext mappingContext, @Nonnull final String name,
+ @Nonnull final String namingContextName) {
+ final InstanceIdentifier<Mappings> iid =
+ mappingIid(new MappingId(name), namingContextName).firstIdentifierOf(Mappings.class);
+ final List<Mapping> list = Common.getMappingList(mappingContext, iid);
+
+ doReturn(Optional.of(new MappingsBuilder().setMapping(list).build())).when(mappingContext).read(iid);
+ doReturn(Optional.absent()).when(mappingContext).read(mappingIid(new MappingId(name), namingContextName));
+ }
+
final class Common {
private static List<Mapping> getMappingList(@Nonnull final MappingContext mappingContext,
@Nonnull final InstanceIdentifier<Mappings> mappingsIid) {