summaryrefslogtreecommitdiffstats
path: root/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write')
-rw-r--r--lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/AdjacencyCustomizerTest.java243
-rw-r--r--lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/BridgeDomainCustomizerTest.java108
-rwxr-xr-xlisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/InterfaceCustomizerTest.java160
-rw-r--r--lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/ItrRemoteLocatorSetCustomizerTest.java146
-rwxr-xr-xlisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/LispCustomizerTest.java111
-rwxr-xr-xlisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/LocalMappingCustomizerTest.java163
-rwxr-xr-xlisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/LocatorSetCustomizerTest.java148
-rwxr-xr-xlisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/MapResolverCustomizerTest.java103
-rwxr-xr-xlisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/PitrCfgCustomizerTest.java117
-rwxr-xr-xlisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/RemoteMappingCustomizerTest.java155
-rw-r--r--lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/VniTableCustomizerTest.java103
-rw-r--r--lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/VrfSubtableCustomizerTest.java105
-rw-r--r--lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/trait/SubtableWriterTestCase.java59
13 files changed, 1721 insertions, 0 deletions
diff --git a/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/AdjacencyCustomizerTest.java b/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/AdjacencyCustomizerTest.java
new file mode 100644
index 000000000..f263e78c9
--- /dev/null
+++ b/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/AdjacencyCustomizerTest.java
@@ -0,0 +1,243 @@
+/*
+ * 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.hc2vpp.lisp.translate.write;
+
+import static io.fd.hc2vpp.lisp.translate.AdjacencyData.ADDRESS_ONE;
+import static io.fd.hc2vpp.lisp.translate.AdjacencyData.ADDRESS_THREE;
+import static io.fd.hc2vpp.lisp.translate.AdjacencyData.LOCAL_EID_ONE;
+import static io.fd.hc2vpp.lisp.translate.AdjacencyData.REMOTE_EID_ONE;
+import static io.fd.hc2vpp.lisp.translate.read.dump.executor.params.MappingsDumpParams.EidType.IPV4;
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import io.fd.hc2vpp.lisp.context.util.AdjacenciesMappingContext;
+import io.fd.hc2vpp.lisp.context.util.EidMappingContext;
+import io.fd.hc2vpp.lisp.util.EidMappingContextHelper;
+import io.fd.hc2vpp.common.test.write.WriterCustomizerTest;
+import io.fd.vpp.jvpp.core.dto.LispAddDelAdjacency;
+import io.fd.vpp.jvpp.core.dto.LispAddDelAdjacencyReply;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Captor;
+import org.mockito.Mock;
+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.MacAfi;
+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 implements EidMappingContextHelper {
+
+ @Captor
+ private ArgumentCaptor<LispAddDelAdjacency> requestCaptor;
+
+ private EidMappingContext localMappingContext;
+
+ private EidMappingContext remoteMappingContext;
+
+ @Mock
+ private AdjacenciesMappingContext adjacenciesMappingContext;
+
+ private AdjacencyCustomizer customizer;
+
+ private InstanceIdentifier<Adjacency> emptyId;
+ private InstanceIdentifier<Adjacency> validId;
+
+ private Adjacency emptyData;
+ private Adjacency invalidData;
+ private Adjacency validData;
+
+ @Before
+ public void init() {
+ 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, new RemoteMappingKey(new MappingId("remote-mapping")))
+ .child(Adjacencies.class)
+ .child(Adjacency.class, new AdjacencyKey("adj-one"));
+
+ emptyData = new AdjacencyBuilder().build();
+
+ invalidData = new AdjacencyBuilder().setId("ID").setLocalEid(
+ new LocalEidBuilder()
+ .setVirtualNetworkId(new InstanceIdType(12L))
+ .setAddressType(Ipv4Afi.class)
+ .setAddress(new Ipv4Builder().setIpv4(new Ipv4Address("192.168.2.1")).build())
+ .build()).setRemoteEid(
+ new RemoteEidBuilder()
+ .setVirtualNetworkId(new InstanceIdType(12L))
+ .setAddressType(MacAfi.class)
+ .setAddress(new MacBuilder().setMac(new MacAddress("aa:aa:aa:aa:aa:aa")).build())
+ .build())
+ .build();
+
+ validData = new AdjacencyBuilder().setId("ID").setLocalEid(
+ new LocalEidBuilder()
+ .setVirtualNetworkId(new InstanceIdType(12L))
+ .setAddressType(Ipv4Afi.class)
+ .setAddress(new Ipv4Builder().setIpv4(ADDRESS_ONE).build())
+ .build()).setRemoteEid(
+ new RemoteEidBuilder()
+ .setVirtualNetworkId(new InstanceIdType(12L))
+ .setAddressType(Ipv4Afi.class)
+ .setAddress(new Ipv4Builder().setIpv4(ADDRESS_THREE).build()).build()).build();
+
+ when(api.lispAddDelAdjacency(any())).thenReturn(future(new LispAddDelAdjacencyReply()));
+ }
+
+ @Test
+ public void writeCurrentAttributesNoKey() throws Exception {
+ try {
+ customizer.writeCurrentAttributes(emptyId, emptyData, writeContext);
+ } catch (NullPointerException e) {
+ verify(api, times(0)).lispAddDelAdjacency(any());
+ return;
+ }
+
+ fail("Test should have failed while reading parent vni table id");
+ }
+
+ @Test
+ public void writeCurrentAttributesInvalidCombination() throws Exception {
+ try {
+ customizer.writeCurrentAttributes(emptyId, invalidData, writeContext);
+ } catch (NullPointerException e) {
+ verify(api, times(0)).lispAddDelAdjacency(any());
+ return;
+ }
+
+ fail("Test should have failed while reading parent vni table id");
+ }
+
+
+ @Test
+ public void writeCurrentAttributes() throws Exception {
+ 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, 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 {
+ 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) {
+ verify(api, times(0)).lispAddDelAdjacency(any());
+ return;
+ }
+
+ fail("Test should have failed while verifying local eid");
+ }
+
+ @Test
+ public void writeCurrentAttributesNonExistingRemoteMapping() throws Exception {
+ noEidMappingDefined(mappingContext, "remote-eid-one", "remote-mapping-context");
+ defineEidMapping(mappingContext, LOCAL_EID_ONE, new MappingId("local-eid-one"), "local-mapping-context");
+
+ try {
+ customizer.writeCurrentAttributes(validId, validData, writeContext);
+ } catch (IllegalStateException e) {
+ verify(api, times(0)).lispAddDelAdjacency(any());
+ return;
+ }
+
+ fail("Test should have failed while verifying remote eid");
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void updateCurrentAttributes() throws Exception {
+ customizer.updateCurrentAttributes(emptyId, emptyData, emptyData, writeContext);
+ }
+
+ @Test
+ public void deleteCurrentAttributesNoKey() throws Exception {
+ try {
+ customizer.deleteCurrentAttributes(emptyId, emptyData, writeContext);
+ } catch (NullPointerException e) {
+ verify(api, times(0)).lispAddDelAdjacency(any());
+ return;
+ }
+
+ fail("Test should have failed while reading parent vni table id");
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void deleteCurrentAttributesInvalidCombination() throws Exception {
+ customizer.deleteCurrentAttributes(validId, invalidData, writeContext);
+ }
+
+ @Test
+ 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, 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,
+ final int leidLen, final byte[] reid, final int reidLen, final int eidType,
+ final int vni) {
+
+ assertNotNull(request);
+ assertEquals(isAdd, request.isAdd);
+ assertArrayEquals(leid, request.leid);
+ assertEquals(leidLen, request.leidLen);
+ assertArrayEquals(reid, request.reid);
+ assertEquals(reidLen, request.reidLen);
+ assertEquals(eidType, request.eidType);
+ assertEquals(vni, request.vni);
+
+ }
+} \ No newline at end of file
diff --git a/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/BridgeDomainCustomizerTest.java b/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/BridgeDomainCustomizerTest.java
new file mode 100644
index 000000000..982858132
--- /dev/null
+++ b/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/BridgeDomainCustomizerTest.java
@@ -0,0 +1,108 @@
+/*
+ * 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.hc2vpp.lisp.translate.write;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import io.fd.hc2vpp.lisp.translate.write.trait.SubtableWriterTestCase;
+import io.fd.hc2vpp.common.translate.util.NamingContext;
+import io.fd.honeycomb.translate.write.WriteFailedException;
+import io.fd.vpp.jvpp.VppCallbackException;
+import org.junit.Before;
+import org.junit.Test;
+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.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.eid.table.grouping.eid.table.vni.table.BridgeDomainSubtableBuilder;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+public class BridgeDomainCustomizerTest extends SubtableWriterTestCase {
+
+ private BridgeDomainSubtableCustomizer customizer;
+ private InstanceIdentifier<BridgeDomainSubtable> validId;
+ private BridgeDomainSubtable validData;
+ private NamingContext bridgeDomainContext;
+
+ @Before
+ public void init() {
+ bridgeDomainContext = new NamingContext("br", "bridge-domain-context");
+ customizer = new BridgeDomainSubtableCustomizer(api, bridgeDomainContext);
+ validId = InstanceIdentifier.create(EidTable.class).child(VniTable.class, new VniTableKey(12L))
+ .child(BridgeDomainSubtable.class);
+ validData = new BridgeDomainSubtableBuilder().setBridgeDomainRef("br-domain").build();
+ defineMapping(mappingContext, "br-domain", 10, "bridge-domain-context");
+ }
+
+ @Test
+ public void testWriteSuccessfull() throws WriteFailedException {
+ whenAddDelEidTableAddDelMapSuccess();
+ customizer.writeCurrentAttributes(validId, validData, writeContext);
+ verifyAddDelEidTableAddDelMapInvokedCorrectly(1, 12, 10, 1);
+ }
+
+ @Test
+ public void testWriteFailed() throws WriteFailedException {
+ whenAddDelEidTableAddDelMapFail();
+
+ try {
+ customizer.writeCurrentAttributes(validId, validData, writeContext);
+ } catch (Exception e) {
+ assertTrue(e instanceof WriteFailedException);
+
+ final WriteFailedException realException = ((WriteFailedException) e);
+ assertEquals(validId, realException.getFailedId());
+ assertTrue(e.getCause() instanceof VppCallbackException);
+ return;
+ }
+
+ fail("Test should throw exception");
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void testUpdate() throws WriteFailedException {
+ customizer.updateCurrentAttributes(validId, validData, validData, writeContext);
+ }
+
+ @Test
+ public void testDeleteSuccessfull() throws WriteFailedException {
+ whenAddDelEidTableAddDelMapSuccess();
+ customizer.deleteCurrentAttributes(validId, validData, writeContext);
+ verifyAddDelEidTableAddDelMapInvokedCorrectly(0, 12, 10, 1);
+ }
+
+ @Test
+ public void testDeleteFailed() {
+ whenAddDelEidTableAddDelMapFail();
+
+ try {
+ customizer.deleteCurrentAttributes(validId, validData, writeContext);
+ } catch (Exception e) {
+ assertTrue(e instanceof WriteFailedException);
+
+ final WriteFailedException realException = ((WriteFailedException) e);
+ assertEquals(validId, realException.getFailedId());
+ assertTrue(e.getCause() instanceof VppCallbackException);
+ return;
+ }
+
+ fail("Test should throw exception");
+ }
+
+}
diff --git a/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/InterfaceCustomizerTest.java b/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/InterfaceCustomizerTest.java
new file mode 100755
index 000000000..61326ffab
--- /dev/null
+++ b/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/InterfaceCustomizerTest.java
@@ -0,0 +1,160 @@
+/*
+ * 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.hc2vpp.lisp.translate.write;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import io.fd.hc2vpp.common.translate.util.ByteDataTranslator;
+import io.fd.hc2vpp.common.translate.util.NamingContext;
+import io.fd.honeycomb.translate.write.WriteFailedException;
+import io.fd.hc2vpp.common.test.write.WriterCustomizerTest;
+import org.junit.Test;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Captor;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.Lisp;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.lisp.feature.data.grouping.LispFeatureData;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.locator.sets.grouping.LocatorSets;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.locator.sets.grouping.locator.sets.LocatorSet;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.locator.sets.grouping.locator.sets.LocatorSetKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.locator.sets.grouping.locator.sets.locator.set.Interface;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.locator.sets.grouping.locator.sets.locator.set.InterfaceBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.locator.sets.grouping.locator.sets.locator.set.InterfaceKey;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import io.fd.vpp.jvpp.core.dto.LispAddDelLocator;
+import io.fd.vpp.jvpp.core.dto.LispAddDelLocatorReply;
+
+public class InterfaceCustomizerTest extends WriterCustomizerTest implements ByteDataTranslator {
+
+ @Captor
+ private ArgumentCaptor<LispAddDelLocator> intfCaptor;
+
+ private InstanceIdentifier<Interface> id;
+ private Interface intf;
+ private InterfaceCustomizer customizer;
+
+ @Override
+ public void setUp() {
+ final String ifcCtxName = "INInterruptedException, ExecutionException, STANCE";
+ final String interfaceName = "Interface";
+ defineMapping(mappingContext, interfaceName, 5, ifcCtxName);
+
+ id = InstanceIdentifier.builder(Lisp.class)
+ .child(LispFeatureData.class)
+ .child(LocatorSets.class)
+ .child(LocatorSet.class, new LocatorSetKey("Locator"))
+ .child(Interface.class, new InterfaceKey(interfaceName))
+ .build();
+
+ intf = new InterfaceBuilder()
+ .setPriority((short) 1)
+ .setWeight((short) 2)
+ .build();
+
+ customizer = new InterfaceCustomizer(api, new NamingContext("PREFIX", ifcCtxName));
+
+ when(api.lispAddDelLocator(any(LispAddDelLocator.class))).thenReturn(future(new LispAddDelLocatorReply()));
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testWriteCurrentAttributesNullData() throws WriteFailedException {
+ customizer.writeCurrentAttributes(null, null, null);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testWriteCurrentAttributesNullPriority() throws WriteFailedException {
+ Interface intf = mock(Interface.class);
+ when(intf.getWeight()).thenReturn((short) 1);
+ when(intf.getPriority()).thenReturn(null);
+
+ customizer.writeCurrentAttributes(null, intf, null);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testWriteCurrentAttributesNullWeight() throws WriteFailedException {
+ Interface intf = mock(Interface.class);
+ when(intf.getWeight()).thenReturn(null);
+ when(intf.getPriority()).thenReturn((short) 1);
+
+ customizer.writeCurrentAttributes(null, intf, null);
+ }
+
+ @Test
+ public void testWriteCurrentAttributes() throws WriteFailedException {
+ customizer.writeCurrentAttributes(id, intf, writeContext);
+
+ verify(api, times(1)).lispAddDelLocator(intfCaptor.capture());
+
+ LispAddDelLocator request = intfCaptor.getValue();
+
+ assertNotNull(request);
+ assertEquals(1, request.isAdd);
+ assertEquals(2, request.weight);
+ assertEquals(1, request.priority);
+ assertEquals(5, request.swIfIndex);
+ assertEquals("Locator", toString(request.locatorSetName));
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void testUpdateCurrentAttributes() throws WriteFailedException {
+ customizer.updateCurrentAttributes(null, null, null, null);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testDeleteCurrentAttributesNullData() throws WriteFailedException {
+ customizer.deleteCurrentAttributes(null, null, null);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testDeleteCurrentAttributesNullPriority() throws WriteFailedException {
+ Interface interf = mock(Interface.class);
+ when(interf.getWeight()).thenReturn((short) 1);
+ when(interf.getPriority()).thenReturn(null);
+
+ customizer.deleteCurrentAttributes(null, interf, null);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testDeleteCurrentAttributesNullWeight() throws WriteFailedException {
+ Interface interf = mock(Interface.class);
+ when(interf.getWeight()).thenReturn(null);
+ when(interf.getPriority()).thenReturn((short) 1);
+
+ customizer.deleteCurrentAttributes(null, interf, null);
+ }
+
+ @Test
+ public void testDeleteCurrentAttributes() throws WriteFailedException {
+ customizer.deleteCurrentAttributes(id, intf, writeContext);
+
+ verify(api, times(1)).lispAddDelLocator(intfCaptor.capture());
+
+ LispAddDelLocator request = intfCaptor.getValue();
+
+ assertNotNull(request);
+ assertEquals(0, request.isAdd);
+ assertEquals(2, request.weight);
+ assertEquals(1, request.priority);
+ assertEquals(5, request.swIfIndex);
+ assertEquals("Locator", toString(request.locatorSetName));
+ }
+}
diff --git a/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/ItrRemoteLocatorSetCustomizerTest.java b/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/ItrRemoteLocatorSetCustomizerTest.java
new file mode 100644
index 000000000..e86b946be
--- /dev/null
+++ b/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/ItrRemoteLocatorSetCustomizerTest.java
@@ -0,0 +1,146 @@
+/*
+ * 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.hc2vpp.lisp.translate.write;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+import static org.mockito.MockitoAnnotations.initMocks;
+
+import io.fd.hc2vpp.common.translate.util.ByteDataTranslator;
+import io.fd.honeycomb.translate.write.WriteFailedException;
+import io.fd.hc2vpp.common.test.write.WriterCustomizerTest;
+import io.fd.vpp.jvpp.VppCallbackException;
+import io.fd.vpp.jvpp.core.dto.LispAddDelMapRequestItrRlocs;
+import io.fd.vpp.jvpp.core.dto.LispAddDelMapRequestItrRlocsReply;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Captor;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.itr.remote.locator.sets.grouping.ItrRemoteLocatorSet;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.itr.remote.locator.sets.grouping.ItrRemoteLocatorSetBuilder;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+public class ItrRemoteLocatorSetCustomizerTest extends WriterCustomizerTest implements ByteDataTranslator {
+
+ private static final String VALID_NAME = "loc-set";
+
+ @Captor
+ private ArgumentCaptor<LispAddDelMapRequestItrRlocs> requestCaptor;
+
+ private ItrRemoteLocatorSetCustomizer customizer;
+ private InstanceIdentifier<ItrRemoteLocatorSet> validId;
+ private ItrRemoteLocatorSet validData;
+
+ @Before
+ public void setUp() throws Exception {
+ initMocks(this);
+ customizer = new ItrRemoteLocatorSetCustomizer(api);
+ validId = InstanceIdentifier.create(ItrRemoteLocatorSet.class);
+ validData = new ItrRemoteLocatorSetBuilder().setRemoteLocatorSetName(VALID_NAME).build();
+ }
+
+ @Test
+ public void writeCurrentAttributesSuccess() throws Exception {
+ onWriteSuccess();
+ customizer.writeCurrentAttributes(validId, validData, writeContext);
+ verifyWriteInvoked(true, VALID_NAME);
+ }
+
+ @Test
+ public void writeCurrentAttributesFailed() {
+ onWriteThrow();
+
+ try {
+ customizer.writeCurrentAttributes(validId, validData, writeContext);
+ } catch (WriteFailedException e) {
+ assertTrue(e.getCause() instanceof VppCallbackException);
+ verifyWriteInvoked(true, VALID_NAME);
+ return;
+ }
+
+ fail("Test should have thrown exception");
+ }
+
+ @Test
+ public void updateCurrentAttributes() {
+ try {
+ customizer.updateCurrentAttributes(validId, validData, validData, writeContext);
+ } catch (WriteFailedException e) {
+ assertTrue(e.getCause() instanceof UnsupportedOperationException);
+ return;
+ }
+
+ fail("Test should have thrown exception");
+ }
+
+ @Test
+ public void deleteCurrentAttributesSuccess() throws Exception {
+ onWriteSuccess();
+ customizer.deleteCurrentAttributes(validId, validData, writeContext);
+ verifyWriteInvoked(false, VALID_NAME);
+ }
+
+ @Test
+ public void deleteCurrentAttributesFailed() throws Exception {
+ onWriteThrow();
+
+ try {
+ customizer.writeCurrentAttributes(validId, validData, writeContext);
+ } catch (WriteFailedException e) {
+ assertTrue(e.getCause() instanceof VppCallbackException);
+ verifyWriteInvoked(true, VALID_NAME);
+ return;
+ }
+
+ fail("Test should have thrown exception");
+ }
+
+ private void onWriteSuccess() {
+ when(api.lispAddDelMapRequestItrRlocs(any(LispAddDelMapRequestItrRlocs.class)))
+ .thenReturn(CompletableFuture.completedFuture(new LispAddDelMapRequestItrRlocsReply()));
+ }
+
+ private void onWriteThrow() {
+ when(api.lispAddDelMapRequestItrRlocs(any(LispAddDelMapRequestItrRlocs.class)))
+ .thenReturn(new CompletableFuture<LispAddDelMapRequestItrRlocsReply>() {
+ @Override
+ public LispAddDelMapRequestItrRlocsReply get(final long l, final TimeUnit timeUnit)
+ throws InterruptedException, ExecutionException, TimeoutException {
+ throw new ExecutionException(new VppCallbackException("lispAddDelMapRequestItrRlocs", 1, -2));
+ }
+ });
+ }
+
+ private void verifyWriteInvoked(final boolean add, final String name) {
+ verify(api, times(1)).lispAddDelMapRequestItrRlocs(requestCaptor.capture());
+
+ final LispAddDelMapRequestItrRlocs request = requestCaptor.getValue();
+ assertNotNull(request);
+ assertEquals(booleanToByte(add), request.isAdd);
+ assertEquals(name, toString(request.locatorSetName));
+ }
+} \ No newline at end of file
diff --git a/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/LispCustomizerTest.java b/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/LispCustomizerTest.java
new file mode 100755
index 000000000..45e3e005b
--- /dev/null
+++ b/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/LispCustomizerTest.java
@@ -0,0 +1,111 @@
+/*
+ * 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.hc2vpp.lisp.translate.write;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import io.fd.honeycomb.translate.write.WriteFailedException;
+import io.fd.hc2vpp.common.test.write.WriterCustomizerTest;
+import org.junit.Test;
+import org.mockito.ArgumentCaptor;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.Lisp;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.LispBuilder;
+import io.fd.vpp.jvpp.core.dto.LispEnableDisable;
+import io.fd.vpp.jvpp.core.dto.LispEnableDisableReply;
+
+
+public class LispCustomizerTest extends WriterCustomizerTest {
+
+ private LispCustomizer customizer;
+
+ @Override
+ public void setUp() {
+ customizer = new LispCustomizer(api);
+ }
+
+ private void whenlispEnableDisableThenSuccess() {
+ when(api.lispEnableDisable(any(LispEnableDisable.class))).thenReturn(future(new LispEnableDisableReply()));
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testWriteCurrentAttributesNullData() throws WriteFailedException {
+ customizer.writeCurrentAttributes(null, null, null);
+ }
+
+ @Test
+ public void testWriteCurrentAttributes() throws WriteFailedException {
+ Lisp intf = new LispBuilder().setEnable(true).build();
+
+ whenlispEnableDisableThenSuccess();
+ customizer.writeCurrentAttributes(null, intf, null);
+
+ ArgumentCaptor<LispEnableDisable> mappingCaptor = ArgumentCaptor.forClass(LispEnableDisable.class);
+ verify(api, times(1)).lispEnableDisable(mappingCaptor.capture());
+
+ LispEnableDisable request = mappingCaptor.getValue();
+
+ assertNotNull(request);
+ assertEquals(1, request.isEn);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testUpdateCurrentAttributesNullData() throws WriteFailedException {
+ customizer.updateCurrentAttributes(null, null, null, null);
+ }
+
+ @Test
+ public void testUpdateCurrentAttributes() throws WriteFailedException {
+ Lisp lisp = new LispBuilder().setEnable(true).build();
+
+ whenlispEnableDisableThenSuccess();
+ customizer.updateCurrentAttributes(null, null, lisp, null);
+
+ ArgumentCaptor<LispEnableDisable> lispCaptor = ArgumentCaptor.forClass(LispEnableDisable.class);
+ verify(api, times(1)).lispEnableDisable(lispCaptor.capture());
+
+ LispEnableDisable request = lispCaptor.getValue();
+
+ assertNotNull(request);
+ assertEquals(1, request.isEn);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testDeleteCurrentAttributesNullData() throws WriteFailedException {
+ customizer.deleteCurrentAttributes(null, null, null);
+ }
+
+ @Test
+ public void testDeleteCurrentAttributes() throws WriteFailedException {
+ Lisp lisp = new LispBuilder().setEnable(true).build();
+
+ whenlispEnableDisableThenSuccess();
+ customizer.deleteCurrentAttributes(null, lisp, null);
+
+ ArgumentCaptor<LispEnableDisable> lispCaptor = ArgumentCaptor.forClass(LispEnableDisable.class);
+ verify(api, times(1)).lispEnableDisable(lispCaptor.capture());
+
+ LispEnableDisable request = lispCaptor.getValue();
+
+ assertNotNull(request);
+ assertEquals(0, request.isEn);
+ }
+}
diff --git a/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/LocalMappingCustomizerTest.java b/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/LocalMappingCustomizerTest.java
new file mode 100755
index 000000000..e5663ee96
--- /dev/null
+++ b/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/LocalMappingCustomizerTest.java
@@ -0,0 +1,163 @@
+/*
+ * 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.hc2vpp.lisp.translate.write;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import io.fd.hc2vpp.lisp.context.util.EidMappingContext;
+import io.fd.hc2vpp.common.translate.util.ByteDataTranslator;
+import io.fd.hc2vpp.common.translate.util.Ipv4Translator;
+import io.fd.honeycomb.translate.write.WriteFailedException;
+import io.fd.hc2vpp.common.test.write.WriterCustomizerTest;
+import java.util.concurrent.ExecutionException;
+import org.junit.Test;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Captor;
+import org.mockito.Mock;
+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.Ipv4Afi;
+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.opendaylight.params.xml.ns.yang.lisp.rev161214.Lisp;
+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.dp.subtable.grouping.LocalMappings;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.dp.subtable.grouping.local.mappings.LocalMapping;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.dp.subtable.grouping.local.mappings.LocalMappingBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.dp.subtable.grouping.local.mappings.LocalMappingKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.dp.subtable.grouping.local.mappings.local.mapping.Eid;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.dp.subtable.grouping.local.mappings.local.mapping.EidBuilder;
+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.VrfSubtable;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.lisp.feature.data.grouping.LispFeatureData;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import io.fd.vpp.jvpp.core.dto.LispAddDelLocalEid;
+import io.fd.vpp.jvpp.core.dto.LispAddDelLocalEidReply;
+
+public class LocalMappingCustomizerTest extends WriterCustomizerTest implements ByteDataTranslator, Ipv4Translator {
+
+ @Mock
+ private EidMappingContext eidMappingContext;
+ @Captor
+ private ArgumentCaptor<LispAddDelLocalEid> mappingCaptor;
+
+ private InstanceIdentifier<LocalMapping> id;
+ private LocalMapping mapping;
+ private LocalMappingCustomizer customizer;
+
+ @Override
+ public void setUp() {
+ final Eid
+ eid = new EidBuilder()
+ .setAddressType(Ipv4Afi.class)
+ .setAddress(
+ new Ipv4Builder().setIpv4(
+ new Ipv4Address("192.168.2.1"))
+ .build())
+ .build();
+
+ mapping = new LocalMappingBuilder()
+ .setEid(eid)
+ .setLocatorSet("Locator")
+ .build();
+
+ id = InstanceIdentifier.builder(Lisp.class)
+ .child(LispFeatureData.class)
+ .child(EidTable.class)
+ .child(VniTable.class, new VniTableKey(25L))
+ .child(VrfSubtable.class)
+ .child(LocalMappings.class)
+ .child(LocalMapping.class, new LocalMappingKey(new MappingId("local")))
+ .build();
+
+ customizer = new LocalMappingCustomizer(api, eidMappingContext);
+
+ when(api.lispAddDelLocalEid(any(LispAddDelLocalEid.class))).thenReturn(future(new LispAddDelLocalEidReply()));
+ }
+
+
+ @Test(expected = NullPointerException.class)
+ public void testWriteCurrentAttributesNullData() throws WriteFailedException {
+ customizer.writeCurrentAttributes(null, null, writeContext);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testWriteCurrentAttributesNullEid() throws WriteFailedException {
+ LocalMapping mapping = mock(LocalMapping.class);
+ when(mapping.getEid()).thenReturn(null);
+ when(mapping.getLocatorSet()).thenReturn("Locator");
+
+ customizer.writeCurrentAttributes(null, mapping, writeContext);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testWriteCurrentAttributesNullLocator() throws WriteFailedException {
+ LocalMapping mapping = mock(LocalMapping.class);
+ when(mapping.getEid()).thenReturn(mock(Eid.class));
+ when(mapping.getLocatorSet()).thenReturn(null);
+
+ customizer.writeCurrentAttributes(null, mapping, writeContext);
+ }
+
+
+ @Test
+ public void testWriteCurrentAttributes() throws WriteFailedException {
+ customizer.writeCurrentAttributes(id, mapping, writeContext);
+
+ verify(api, times(1)).lispAddDelLocalEid(mappingCaptor.capture());
+
+ LispAddDelLocalEid request = mappingCaptor.getValue();
+
+ assertNotNull(request);
+ assertEquals("Locator", new String(request.locatorSetName));
+ assertEquals("1.2.168.192", arrayToIpv4AddressNoZone(request.eid).getValue());
+ assertEquals(0, request.eidType);
+ assertEquals(1, request.isAdd);
+ assertEquals(25, request.vni);
+ assertEquals("Locator", toString(request.locatorSetName));
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void testUpdateCurrentAttributes() throws WriteFailedException {
+ customizer.updateCurrentAttributes(null, null, null, writeContext);
+ }
+
+ @Test
+ public void testDeleteCurrentAttributes() throws WriteFailedException, InterruptedException, ExecutionException {
+ when(eidMappingContext.containsEid(any(), eq(mappingContext))).thenReturn(true);
+ customizer.deleteCurrentAttributes(id, mapping, writeContext);
+
+ verify(api, times(1)).lispAddDelLocalEid(mappingCaptor.capture());
+
+ LispAddDelLocalEid request = mappingCaptor.getValue();
+
+ assertNotNull(request);
+ assertEquals("Locator", new String(request.locatorSetName));
+ assertEquals("1.2.168.192", arrayToIpv4AddressNoZone(request.eid).getValue());
+ assertEquals(0, request.eidType);
+ assertEquals(0, request.isAdd);
+ assertEquals(25, request.vni);
+ assertEquals("Locator", toString(request.locatorSetName));
+ }
+}
diff --git a/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/LocatorSetCustomizerTest.java b/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/LocatorSetCustomizerTest.java
new file mode 100755
index 000000000..58049d8be
--- /dev/null
+++ b/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/LocatorSetCustomizerTest.java
@@ -0,0 +1,148 @@
+/*
+ * 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.hc2vpp.lisp.translate.write;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.mock;
+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.ImmutableList;
+import io.fd.hc2vpp.common.translate.util.NamingContext;
+import io.fd.honeycomb.translate.write.WriteFailedException;
+import io.fd.hc2vpp.common.test.write.WriterCustomizerTest;
+import io.fd.vpp.jvpp.core.dto.LispAddDelLocatorSet;
+import io.fd.vpp.jvpp.core.dto.LispAddDelLocatorSetReply;
+import io.fd.vpp.jvpp.core.dto.LispLocatorSetDetails;
+import io.fd.vpp.jvpp.core.dto.LispLocatorSetDetailsReplyDump;
+import java.nio.charset.StandardCharsets;
+import java.util.Arrays;
+import java.util.concurrent.ExecutionException;
+import org.junit.Test;
+import org.mockito.ArgumentCaptor;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.locator.sets.grouping.LocatorSets;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.locator.sets.grouping.locator.sets.LocatorSet;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.locator.sets.grouping.locator.sets.LocatorSetBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.locator.sets.grouping.locator.sets.LocatorSetKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.locator.sets.grouping.locator.sets.locator.set.InterfaceBuilder;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+public class LocatorSetCustomizerTest extends WriterCustomizerTest {
+
+ private LocatorSetCustomizer customizer;
+
+ @Override
+ public void setUp() {
+ customizer = new LocatorSetCustomizer(api, new NamingContext("locator-set", "locator-set-context"));
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testWriteCurrentAttributesNullData() throws WriteFailedException {
+ customizer.writeCurrentAttributes(null, null, writeContext);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testWriteCurrentAttributesBadData() throws WriteFailedException {
+ customizer.writeCurrentAttributes(null, mock(LocatorSet.class), writeContext);
+ }
+
+ @Test
+ public void testWriteCurrentAttributes() throws WriteFailedException, InterruptedException, ExecutionException {
+ noMappingDefined(mappingContext, "Locator", "locator-set-context");
+ LocatorSet locatorSet = new LocatorSetBuilder()
+ .setName("Locator")
+ .setInterface(Arrays.asList(new InterfaceBuilder().build()))
+ .build();
+
+ InstanceIdentifier<LocatorSet> validId =
+ InstanceIdentifier.create(LocatorSets.class).child(LocatorSet.class, new LocatorSetKey("Locator"));
+
+
+ ArgumentCaptor<LispAddDelLocatorSet> locatorSetCaptor = ArgumentCaptor.forClass(LispAddDelLocatorSet.class);
+
+ when(api.lispAddDelLocatorSet(any(LispAddDelLocatorSet.class)))
+ .thenReturn(future(new LispAddDelLocatorSetReply()));
+ when(writeContext.readAfter(validId)).thenReturn(Optional.of(locatorSet));
+
+ final LispLocatorSetDetailsReplyDump reply = new LispLocatorSetDetailsReplyDump();
+ LispLocatorSetDetails details = new LispLocatorSetDetails();
+ details.lsName = "Locator".getBytes(StandardCharsets.UTF_8);
+ reply.lispLocatorSetDetails = ImmutableList.of(details);
+
+ customizer.writeCurrentAttributes(validId, locatorSet, writeContext);
+
+ verify(api, times(1)).lispAddDelLocatorSet(locatorSetCaptor.capture());
+
+ LispAddDelLocatorSet request = locatorSetCaptor.getValue();
+
+ assertNotNull(request);
+ assertEquals("Locator", new String(request.locatorSetName));
+ assertEquals(1, request.isAdd);
+ }
+
+ @Test
+ public void testUpdateCurrentAttributes() throws WriteFailedException {
+ final InstanceIdentifier<LocatorSet> identifier = InstanceIdentifier.create(LocatorSet.class);
+ try {
+ customizer
+ .updateCurrentAttributes(identifier, mock(LocatorSet.class), mock(LocatorSet.class), writeContext);
+ } catch (WriteFailedException e) {
+ assertTrue(e.getCause() instanceof UnsupportedOperationException);
+ assertEquals(identifier, e.getFailedId());
+ return;
+ }
+ fail("Test should have failed");
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testDeleteCurrentAttributesNullData() throws WriteFailedException {
+ customizer.deleteCurrentAttributes(null, null, writeContext);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testDeleteCurrentAttributesBadData() throws WriteFailedException {
+ customizer.deleteCurrentAttributes(null, mock(LocatorSet.class), writeContext);
+ }
+
+ @Test
+ public void testDeleteCurrentAttributes() throws InterruptedException, ExecutionException, WriteFailedException {
+ LocatorSet locatorSet = new LocatorSetBuilder()
+ .setName("Locator")
+ .build();
+
+ ArgumentCaptor<LispAddDelLocatorSet> locatorSetCaptor = ArgumentCaptor.forClass(LispAddDelLocatorSet.class);
+
+ when(api.lispAddDelLocatorSet(any(LispAddDelLocatorSet.class)))
+ .thenReturn(future(new LispAddDelLocatorSetReply()));
+
+ customizer.deleteCurrentAttributes(null, locatorSet, writeContext);
+
+ verify(api, times(1)).lispAddDelLocatorSet(locatorSetCaptor.capture());
+
+ LispAddDelLocatorSet request = locatorSetCaptor.getValue();
+
+ assertNotNull(request);
+ assertEquals("Locator", new String(request.locatorSetName));
+ assertEquals(0, request.isAdd);
+ }
+}
diff --git a/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/MapResolverCustomizerTest.java b/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/MapResolverCustomizerTest.java
new file mode 100755
index 000000000..0780c68b4
--- /dev/null
+++ b/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/MapResolverCustomizerTest.java
@@ -0,0 +1,103 @@
+/*
+ * 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.hc2vpp.lisp.translate.write;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import io.fd.hc2vpp.common.translate.util.Ipv4Translator;
+import io.fd.honeycomb.translate.write.WriteFailedException;
+import io.fd.hc2vpp.common.test.write.WriterCustomizerTest;
+import java.util.concurrent.ExecutionException;
+import org.junit.Test;
+import org.mockito.ArgumentCaptor;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.map.resolvers.grouping.map.resolvers.MapResolver;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.map.resolvers.grouping.map.resolvers.MapResolverBuilder;
+import io.fd.vpp.jvpp.core.dto.LispAddDelMapResolver;
+import io.fd.vpp.jvpp.core.dto.LispAddDelMapResolverReply;
+
+
+public class MapResolverCustomizerTest extends WriterCustomizerTest implements Ipv4Translator {
+
+ private MapResolverCustomizer customizer;
+
+ @Override
+ public void setUp() {
+ customizer = new MapResolverCustomizer(api);
+ }
+
+ private void whenLispAddDelMapResolverThenSuccess() {
+ when(api.lispAddDelMapResolver(any(LispAddDelMapResolver.class)))
+ .thenReturn(future(new LispAddDelMapResolverReply()));
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testWriteCurrentAttributesNullData() throws WriteFailedException {
+ customizer.writeCurrentAttributes(null, null, null);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testWriteCurrentAttributesBadData() throws WriteFailedException {
+ customizer.writeCurrentAttributes(null, new MapResolverBuilder().build(), null);
+ }
+
+ @Test
+ public void testWriteCurrentAttributes() throws WriteFailedException {
+ Ipv4Address address = new Ipv4Address("192.168.2.1");
+ MapResolver resolver = new MapResolverBuilder().setIpAddress(new IpAddress(address)).build();
+
+ whenLispAddDelMapResolverThenSuccess();
+
+ customizer.writeCurrentAttributes(null, resolver, null);
+
+ ArgumentCaptor<LispAddDelMapResolver> resolverCaptor = ArgumentCaptor.forClass(LispAddDelMapResolver.class);
+ verify(api, times(1)).lispAddDelMapResolver(resolverCaptor.capture());
+
+ LispAddDelMapResolver request = resolverCaptor.getValue();
+ assertEquals(1, request.isAdd);
+ assertEquals("1.2.168.192", arrayToIpv4AddressNoZone(request.ipAddress).getValue());
+ }
+
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void testUpdateCurrentAttributes() throws WriteFailedException {
+ customizer.updateCurrentAttributes(null, null, null, null);
+ }
+
+ @Test
+ public void testDeleteCurrentAttributes() throws InterruptedException, ExecutionException, WriteFailedException {
+ Ipv4Address address = new Ipv4Address("192.168.2.1");
+ MapResolver resolver = new MapResolverBuilder().setIpAddress(new IpAddress(address)).build();
+
+ whenLispAddDelMapResolverThenSuccess();
+
+ customizer.deleteCurrentAttributes(null, resolver, null);
+
+ ArgumentCaptor<LispAddDelMapResolver> resolverCaptor = ArgumentCaptor.forClass(LispAddDelMapResolver.class);
+ verify(api, times(1)).lispAddDelMapResolver(resolverCaptor.capture());
+
+ LispAddDelMapResolver request = resolverCaptor.getValue();
+ assertEquals(0, request.isAdd);
+ assertEquals("1.2.168.192", arrayToIpv4AddressNoZone(request.ipAddress).getValue());
+ }
+
+}
diff --git a/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/PitrCfgCustomizerTest.java b/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/PitrCfgCustomizerTest.java
new file mode 100755
index 000000000..7a2a8fe4c
--- /dev/null
+++ b/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/PitrCfgCustomizerTest.java
@@ -0,0 +1,117 @@
+/*
+ * 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.hc2vpp.lisp.translate.write;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import io.fd.honeycomb.translate.write.WriteFailedException;
+import io.fd.hc2vpp.common.test.write.WriterCustomizerTest;
+import java.util.concurrent.ExecutionException;
+import org.junit.Test;
+import org.mockito.ArgumentCaptor;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.pitr.cfg.grouping.PitrCfg;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.pitr.cfg.grouping.PitrCfgBuilder;
+import io.fd.vpp.jvpp.core.dto.LispPitrSetLocatorSet;
+import io.fd.vpp.jvpp.core.dto.LispPitrSetLocatorSetReply;
+
+
+public class PitrCfgCustomizerTest extends WriterCustomizerTest {
+
+ private PitrCfgCustomizer customizer;
+
+ @Override
+ public void setUp() {
+ customizer = new PitrCfgCustomizer(api);
+ }
+
+ private void whenLispPitrSetLocatorSetThenSuccess() {
+ when(api.lispPitrSetLocatorSet(any(LispPitrSetLocatorSet.class))).thenReturn(future(new LispPitrSetLocatorSetReply()));
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testWriteCurrentAttributesNullData() throws WriteFailedException {
+ customizer.writeCurrentAttributes(null, null, null);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testWriteCurrentAttributesBadData() throws WriteFailedException {
+ customizer.writeCurrentAttributes(null, mock(PitrCfg.class), null);
+ }
+
+ @Test
+ public void testWriteCurrentAttributes() throws WriteFailedException {
+ PitrCfg cfg = new PitrCfgBuilder().setLocatorSet("Locator").build();
+
+ whenLispPitrSetLocatorSetThenSuccess();
+ customizer.writeCurrentAttributes(null, cfg, null);
+
+ ArgumentCaptor<LispPitrSetLocatorSet> cfgCaptor = ArgumentCaptor.forClass(LispPitrSetLocatorSet.class);
+ verify(api, times(1)).lispPitrSetLocatorSet(cfgCaptor.capture());
+
+ LispPitrSetLocatorSet request = cfgCaptor.getValue();
+ assertEquals(1, request.isAdd);
+ assertEquals("Locator", new String(request.lsName));
+ }
+
+ @Test
+ public void testUpdateCurrentAttributes() throws WriteFailedException {
+ PitrCfg cfg = new PitrCfgBuilder().setLocatorSet("Locator").build();
+
+ whenLispPitrSetLocatorSetThenSuccess();
+
+ customizer.writeCurrentAttributes(null, cfg, null);
+
+ ArgumentCaptor<LispPitrSetLocatorSet> cfgCaptor = ArgumentCaptor.forClass(LispPitrSetLocatorSet.class);
+ verify(api, times(1)).lispPitrSetLocatorSet(cfgCaptor.capture());
+
+ LispPitrSetLocatorSet request = cfgCaptor.getValue();
+ assertEquals(1, request.isAdd);
+ assertEquals("Locator", new String(request.lsName));
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testDeleteCurrentAttributesNullData() throws WriteFailedException {
+ customizer.deleteCurrentAttributes(null, null, null);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testDeleteCurrentAttributesBadData() throws WriteFailedException {
+ customizer.deleteCurrentAttributes(null, mock(PitrCfg.class), null);
+ }
+
+ @Test
+ public void testDeleteCurrentAttributes() throws WriteFailedException, InterruptedException, ExecutionException {
+ PitrCfg cfg = new PitrCfgBuilder().setLocatorSet("Locator").build();
+
+ whenLispPitrSetLocatorSetThenSuccess();
+
+ customizer.deleteCurrentAttributes(null, cfg, null);
+
+ ArgumentCaptor<LispPitrSetLocatorSet> cfgCaptor = ArgumentCaptor.forClass(LispPitrSetLocatorSet.class);
+ verify(api, times(1)).lispPitrSetLocatorSet(cfgCaptor.capture());
+
+ LispPitrSetLocatorSet request = cfgCaptor.getValue();
+ assertEquals(0, request.isAdd);
+ assertEquals("Locator", new String(request.lsName));
+ }
+
+}
diff --git a/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/RemoteMappingCustomizerTest.java b/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/RemoteMappingCustomizerTest.java
new file mode 100755
index 000000000..1645a9c3e
--- /dev/null
+++ b/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/RemoteMappingCustomizerTest.java
@@ -0,0 +1,155 @@
+/*
+ * 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.hc2vpp.lisp.translate.write;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import io.fd.hc2vpp.lisp.context.util.EidMappingContext;
+import io.fd.hc2vpp.common.translate.util.Ipv4Translator;
+import io.fd.honeycomb.translate.write.WriteFailedException;
+import io.fd.hc2vpp.common.test.write.WriterCustomizerTest;
+import io.fd.vpp.jvpp.core.dto.LispAddDelRemoteMapping;
+import io.fd.vpp.jvpp.core.dto.LispAddDelRemoteMappingReply;
+import org.junit.Test;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Captor;
+import org.mockito.Mock;
+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.Ipv4Afi;
+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.opendaylight.params.xml.ns.yang.lisp.rev161214.Lisp;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.MapReplyAction;
+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.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.RemoteMappingBuilder;
+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.dp.subtable.grouping.remote.mappings.remote.mapping.Eid;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.dp.subtable.grouping.remote.mappings.remote.mapping.EidBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.dp.subtable.grouping.remote.mappings.remote.mapping.locator.list.NegativeMappingBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.dp.subtable.grouping.remote.mappings.remote.mapping.locator.list.negative.mapping.MapReplyBuilder;
+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.VrfSubtable;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.lisp.feature.data.grouping.LispFeatureData;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+public class RemoteMappingCustomizerTest extends WriterCustomizerTest implements Ipv4Translator {
+
+ @Captor
+ private ArgumentCaptor<LispAddDelRemoteMapping> mappingCaptor;
+
+ private MappingId mappingId;
+ private RemoteMappingCustomizer customizer;
+ private RemoteMapping intf;
+ private InstanceIdentifier<RemoteMapping> id;
+
+ @Mock
+ private EidMappingContext remoteMappingContext;
+
+ @Override
+ public void setUp() {
+ final Eid eid = new EidBuilder()
+ .setAddressType(Ipv4Afi.class)
+ .setAddress(
+ new Ipv4Builder().setIpv4(
+ new Ipv4Address("192.168.2.1"))
+ .build())
+ .build();
+
+ mappingId = new MappingId("REMOTE");
+ final RemoteMappingKey key = new RemoteMappingKey(mappingId);
+
+ intf = new RemoteMappingBuilder()
+ .setEid(
+ eid)
+ .setLocatorList(new NegativeMappingBuilder()
+ .setMapReply(new MapReplyBuilder().setMapReplyAction(MapReplyAction.Drop).build()).build())
+ .build();
+
+ id = InstanceIdentifier.builder(Lisp.class)
+ .child(LispFeatureData.class)
+ .child(EidTable.class)
+ .child(VniTable.class, new VniTableKey(25L))
+ .child(VrfSubtable.class)
+ .child(RemoteMappings.class)
+ .child(RemoteMapping.class, key).build();
+
+ customizer = new RemoteMappingCustomizer(api, remoteMappingContext);
+
+ when(api.lispAddDelRemoteMapping(any())).thenReturn(future(new LispAddDelRemoteMappingReply()));
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testWriteCurrentAttributesNullData() throws WriteFailedException {
+ customizer.writeCurrentAttributes(null, null, writeContext);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testWriteCurrentAttributesBadData() throws WriteFailedException {
+ customizer
+ .writeCurrentAttributes(null, mock(RemoteMapping.class), writeContext);
+ }
+
+ @Test
+ public void testWriteCurrentAttributes() throws WriteFailedException {
+ customizer.writeCurrentAttributes(id, intf, writeContext);
+
+ verify(api, times(1)).lispAddDelRemoteMapping(mappingCaptor.capture());
+
+ LispAddDelRemoteMapping request = mappingCaptor.getValue();
+
+ assertNotNull(request);
+ assertEquals(1, request.isAdd);
+ assertEquals("1.2.168.192", arrayToIpv4AddressNoZone(request.eid).getValue());
+ assertEquals(25, request.vni);
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void testUpdateCurrentAttributes() throws WriteFailedException {
+ customizer.updateCurrentAttributes(null, null, null, writeContext);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testDeleteCurrentAttributesNullData() throws WriteFailedException {
+ customizer.deleteCurrentAttributes(null, null, writeContext);
+ }
+
+ @Test
+ public void testDeleteCurrentAttributes() throws WriteFailedException {
+ when(remoteMappingContext.containsEid(any(), eq(mappingContext))).thenReturn(true);
+ customizer.deleteCurrentAttributes(id, intf, writeContext);
+
+ verify(api, times(1)).lispAddDelRemoteMapping(mappingCaptor.capture());
+
+ LispAddDelRemoteMapping request = mappingCaptor.getValue();
+
+ assertNotNull(request);
+ assertEquals(0, request.isAdd);
+ assertEquals("1.2.168.192", arrayToIpv4AddressNoZone(request.eid).getValue());
+ assertEquals(25, request.vni);
+ }
+
+}
diff --git a/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/VniTableCustomizerTest.java b/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/VniTableCustomizerTest.java
new file mode 100644
index 000000000..885a6ded7
--- /dev/null
+++ b/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/VniTableCustomizerTest.java
@@ -0,0 +1,103 @@
+/*
+ * 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.hc2vpp.lisp.translate.write;
+
+
+import static org.junit.Assert.fail;
+import static org.mockito.Mockito.when;
+import static org.mockito.MockitoAnnotations.initMocks;
+
+import com.google.common.base.Optional;
+import io.fd.honeycomb.translate.write.WriteFailedException;
+import io.fd.hc2vpp.common.test.write.WriterCustomizerTest;
+import org.junit.Before;
+import org.junit.Test;
+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.VniTableBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.eid.table.grouping.eid.table.vni.table.VrfSubtableBuilder;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+public class VniTableCustomizerTest extends WriterCustomizerTest {
+
+ private VniTableCustomizer customizer;
+ private InstanceIdentifier<VniTable> validId;
+ private VniTable validData;
+
+ @Before
+ public void init() {
+ initMocks(this);
+ customizer = new VniTableCustomizer(api);
+
+ validId = InstanceIdentifier.create(VniTable.class);
+ validData = new VniTableBuilder()
+ .setVrfSubtable(new VrfSubtableBuilder()
+ .build()).build();
+ }
+
+ @Test
+ public void testWriteSuccessfull() {
+ whenReadAfterReturnValid();
+ try {
+ customizer.writeCurrentAttributes(validId, validData, writeContext);
+ } catch (Exception e) {
+ fail("Test should pass without exception");
+ }
+ }
+
+ @Test(expected = IllegalStateException.class)
+ public void testWriteFailed() throws WriteFailedException {
+ whenReadAfterReturnInvalid();
+ customizer.writeCurrentAttributes(validId, validData, writeContext);
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void testUpdate() throws WriteFailedException {
+ customizer.updateCurrentAttributes(validId, validData, validData, writeContext);
+ }
+
+ @Test
+ public void testDeleteSuccessfull() {
+ whenReadBeforeReturnValid();
+ try {
+ customizer.deleteCurrentAttributes(validId, validData, writeContext);
+ } catch (Exception e) {
+ fail("Test should pass without exception");
+ }
+ }
+
+ @Test(expected = IllegalStateException.class)
+ public void testDeleteFailed() throws WriteFailedException {
+ whenReadBeforeReturnInvalid();
+ customizer.deleteCurrentAttributes(validId, validData, writeContext);
+ }
+
+ private void whenReadBeforeReturnValid() {
+ when(writeContext.readBefore(validId)).thenReturn(Optional.of(validData));
+ }
+
+ private void whenReadBeforeReturnInvalid() {
+ when(writeContext.readBefore(validId)).thenReturn(Optional.absent());
+ }
+
+ private void whenReadAfterReturnValid() {
+ when(writeContext.readAfter(validId)).thenReturn(Optional.of(validData));
+ }
+
+ private void whenReadAfterReturnInvalid() {
+ when(writeContext.readAfter(validId)).thenReturn(Optional.absent());
+ }
+} \ No newline at end of file
diff --git a/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/VrfSubtableCustomizerTest.java b/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/VrfSubtableCustomizerTest.java
new file mode 100644
index 000000000..7991cd9a6
--- /dev/null
+++ b/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/VrfSubtableCustomizerTest.java
@@ -0,0 +1,105 @@
+/*
+ * 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.hc2vpp.lisp.translate.write;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import io.fd.hc2vpp.lisp.translate.write.trait.SubtableWriterTestCase;
+import io.fd.honeycomb.translate.write.WriteFailedException;
+import io.fd.vpp.jvpp.VppCallbackException;
+import org.junit.Before;
+import org.junit.Test;
+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.VrfSubtable;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.eid.table.grouping.eid.table.vni.table.VrfSubtableBuilder;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+public class VrfSubtableCustomizerTest extends SubtableWriterTestCase {
+
+ private VrfSubtableCustomizer customizer;
+ private InstanceIdentifier<VrfSubtable> validId;
+ private VrfSubtable validData;
+
+ @Before
+ public void init() {
+ customizer = new VrfSubtableCustomizer(api);
+ validId = InstanceIdentifier.create(EidTable.class).child(VniTable.class, new VniTableKey(12L))
+ .child(VrfSubtable.class);
+ validData = new VrfSubtableBuilder().setTableId(10L).build();
+ }
+
+ @Test
+ public void testWriteSuccessfull() throws WriteFailedException {
+ whenAddDelEidTableAddDelMapSuccess();
+
+ customizer.writeCurrentAttributes(validId, validData, writeContext);
+ verifyAddDelEidTableAddDelMapInvokedCorrectly(1, 12, 10, 0);
+ }
+
+ @Test
+ public void testWriteFailed() {
+ whenAddDelEidTableAddDelMapFail();
+
+ try {
+ customizer.writeCurrentAttributes(validId, validData, writeContext);
+ } catch (Exception e) {
+ assertTrue(e instanceof WriteFailedException);
+
+ final WriteFailedException realException = ((WriteFailedException) e);
+ assertEquals(validId, realException.getFailedId());
+ assertTrue(e.getCause() instanceof VppCallbackException);
+ return;
+ }
+
+ fail("Test should throw exception");
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void testUpdate() throws WriteFailedException {
+ customizer.updateCurrentAttributes(validId, validData, validData, writeContext);
+ }
+
+ @Test
+ public void testDeleteSuccessfull() throws WriteFailedException {
+ whenAddDelEidTableAddDelMapSuccess();
+
+ customizer.deleteCurrentAttributes(validId, validData, writeContext);
+ verifyAddDelEidTableAddDelMapInvokedCorrectly(0, 12, 10, 0);
+ }
+
+ @Test
+ public void testDeleteFailed() {
+ whenAddDelEidTableAddDelMapFail();
+
+ try {
+ customizer.deleteCurrentAttributes(validId, validData, writeContext);
+ } catch (Exception e) {
+ assertTrue(e instanceof WriteFailedException);
+
+ final WriteFailedException realException = ((WriteFailedException) e);
+ assertEquals(validId, realException.getFailedId());
+ assertTrue(e.getCause() instanceof VppCallbackException);
+ return;
+ }
+
+ fail("Test should throw exception");
+ }
+}
diff --git a/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/trait/SubtableWriterTestCase.java b/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/trait/SubtableWriterTestCase.java
new file mode 100644
index 000000000..50186cd2b
--- /dev/null
+++ b/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/trait/SubtableWriterTestCase.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.hc2vpp.lisp.translate.write.trait;
+
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import io.fd.hc2vpp.common.test.write.WriterCustomizerTest;
+import io.fd.vpp.jvpp.core.dto.LispEidTableAddDelMap;
+import io.fd.vpp.jvpp.core.dto.LispEidTableAddDelMapReply;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Captor;
+import org.mockito.Mockito;
+
+public class SubtableWriterTestCase extends WriterCustomizerTest implements SubtableWriter {
+ @Captor
+ protected ArgumentCaptor<LispEidTableAddDelMap> requestCaptor;
+
+
+ protected void verifyAddDelEidTableAddDelMapInvokedCorrectly(final int addDel, final int vni, final int tableId,
+ final int isL2) {
+ verify(api, times(1)).lispEidTableAddDelMap(requestCaptor.capture());
+
+ final LispEidTableAddDelMap request = requestCaptor.getValue();
+ assertNotNull(request);
+ assertEquals(addDel, request.isAdd);
+ assertEquals(vni, request.vni);
+ assertEquals(tableId, request.dpTable);
+ assertEquals(isL2, request.isL2);
+ }
+
+ protected void whenAddDelEidTableAddDelMapSuccess() {
+ when(api.lispEidTableAddDelMap(Mockito.any(LispEidTableAddDelMap.class)))
+ .thenReturn(future(new LispEidTableAddDelMapReply()));
+ }
+
+ protected void whenAddDelEidTableAddDelMapFail() {
+ when(api.lispEidTableAddDelMap(Mockito.any(LispEidTableAddDelMap.class)))
+ .thenReturn(failedFuture());
+ }
+}