summaryrefslogtreecommitdiffstats
path: root/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/write
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/write')
-rwxr-xr-xlisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/write/InterfaceCustomizerTest.java198
-rwxr-xr-xlisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/write/LispCustomizerTest.java128
-rwxr-xr-xlisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/write/LocalMappingCustomizerTest.java189
-rwxr-xr-xlisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/write/LocatorSetCustomizerTest.java157
-rwxr-xr-xlisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/write/MapResolverCustomizerTest.java111
-rwxr-xr-xlisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/write/PitrCfgCustomizerTest.java132
-rwxr-xr-xlisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/write/RemoteMappingCustomizerTest.java175
7 files changed, 1090 insertions, 0 deletions
diff --git a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/write/InterfaceCustomizerTest.java b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/write/InterfaceCustomizerTest.java
new file mode 100755
index 000000000..6dccdfeab
--- /dev/null
+++ b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/write/InterfaceCustomizerTest.java
@@ -0,0 +1,198 @@
+/*
+ * Copyright (c) 2015 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.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 com.google.common.base.Optional;
+import io.fd.honeycomb.translate.MappingContext;
+import io.fd.honeycomb.translate.v3po.util.NamingContext;
+import io.fd.honeycomb.translate.v3po.util.TranslateUtils;
+import io.fd.honeycomb.translate.write.WriteContext;
+import io.fd.honeycomb.translate.write.WriteFailedException;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Captor;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.contexts.naming.context.mappings.MappingBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.Lisp;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.locator.sets.grouping.LocatorSets;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.locator.sets.grouping.locator.sets.LocatorSet;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.locator.sets.grouping.locator.sets.LocatorSetKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.locator.sets.grouping.locator.sets.locator.set.Interface;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.locator.sets.grouping.locator.sets.locator.set.InterfaceBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.locator.sets.grouping.locator.sets.locator.set.InterfaceKey;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.openvpp.jvpp.core.dto.LispAddDelLocator;
+import org.openvpp.jvpp.core.dto.LispAddDelLocatorReply;
+import org.openvpp.jvpp.core.future.FutureJVppCore;
+
+
+public class InterfaceCustomizerTest {
+
+ @Mock
+ private FutureJVppCore fakeJvpp;
+
+ @Mock
+ private WriteContext writeContext;
+
+ @Mock
+ private MappingContext mappingContext;
+
+ @Captor
+ private ArgumentCaptor<LispAddDelLocator> intfCaptor;
+
+ private NamingContext namingContext;
+ private InstanceIdentifier<Interface> id;
+ private CompletableFuture<LispAddDelLocatorReply> completeFuture;
+ private LispAddDelLocatorReply fakeReply;
+ private Interface intf;
+ private InterfaceCustomizer customizer;
+
+ @Before
+ public void init() {
+ MockitoAnnotations.initMocks(this);
+
+ id = InstanceIdentifier.builder(Lisp.class)
+ .child(LocatorSets.class)
+ .child(LocatorSet.class, new LocatorSetKey("Locator"))
+ .child(Interface.class, new InterfaceKey("Interface"))
+ .build();
+
+ intf = new InterfaceBuilder()
+ .setPriority((short) 1)
+ .setWeight((short) 2)
+ .build();
+
+ namingContext = new NamingContext("PREFIX", "INSTANCE");
+
+ customizer = new InterfaceCustomizer(fakeJvpp, namingContext);
+
+ fakeReply = new LispAddDelLocatorReply();
+
+ completeFuture = new CompletableFuture<>();
+ completeFuture.complete(fakeReply);
+
+ when(writeContext.getMappingContext()).thenReturn(mappingContext);
+ when(mappingContext.read(Mockito.any()))
+ .thenReturn(Optional.of((DataObject) new MappingBuilder().setIndex(5).setName("interface").build()));
+ when(fakeJvpp.lispAddDelLocator(any(LispAddDelLocator.class))).thenReturn(completeFuture);
+
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testWriteCurrentAttributesNullData() throws WriteFailedException {
+ new InterfaceCustomizer(mock(FutureJVppCore.class), new NamingContext("PREFIX", "INSTANCE"))
+ .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);
+
+ new InterfaceCustomizer(mock(FutureJVppCore.class), new NamingContext("PREFIX", "INSTANCE"))
+ .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);
+
+ new InterfaceCustomizer(mock(FutureJVppCore.class), new NamingContext("PREFIX", "INSTANCE"))
+ .writeCurrentAttributes(null, intf, null);
+ }
+
+ @Test
+ public void testWriteCurrentAttributes() throws InterruptedException, ExecutionException, WriteFailedException {
+ customizer.writeCurrentAttributes(id, intf, writeContext);
+
+ verify(fakeJvpp, 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", TranslateUtils.toString(request.locatorSetName));
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void testUpdateCurrentAttributes() throws WriteFailedException {
+ new InterfaceCustomizer(fakeJvpp, namingContext)
+ .updateCurrentAttributes(null, null, null, null);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testDeleteCurrentAttributesNullData() throws WriteFailedException {
+ new InterfaceCustomizer(fakeJvpp, namingContext)
+ .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);
+
+ new InterfaceCustomizer(mock(FutureJVppCore.class), new NamingContext("PREFIX", "INSTANCE"))
+ .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);
+
+ new InterfaceCustomizer(mock(FutureJVppCore.class), new NamingContext("PREFIX", "INSTANCE"))
+ .deleteCurrentAttributes(null, interf, null);
+ }
+
+ @Test
+ public void testDeleteCurrentAttributes() throws InterruptedException, ExecutionException, WriteFailedException {
+ customizer.deleteCurrentAttributes(id, intf, writeContext);
+
+ verify(fakeJvpp, 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", TranslateUtils.toString(request.locatorSetName));
+ }
+}
diff --git a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/write/LispCustomizerTest.java b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/write/LispCustomizerTest.java
new file mode 100755
index 000000000..aaa73303c
--- /dev/null
+++ b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/write/LispCustomizerTest.java
@@ -0,0 +1,128 @@
+/*
+ * Copyright (c) 2015 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.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.honeycomb.translate.write.WriteFailedException;
+import java.util.concurrent.CompletableFuture;
+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.rev160520.Lisp;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.LispBuilder;
+import org.openvpp.jvpp.core.dto.LispEnableDisable;
+import org.openvpp.jvpp.core.dto.LispEnableDisableReply;
+import org.openvpp.jvpp.core.future.FutureJVppCore;
+
+
+public class LispCustomizerTest {
+
+ @Test(expected = NullPointerException.class)
+ public void testWriteCurrentAttributesNullData() throws WriteFailedException {
+ new LispCustomizer(mock(FutureJVppCore.class)).writeCurrentAttributes(null, null, null);
+ }
+
+ @Test
+ public void testWriteCurrentAttributes() throws InterruptedException, ExecutionException, WriteFailedException {
+ FutureJVppCore fakeJvpp = mock(FutureJVppCore.class);
+ Lisp intf = new LispBuilder().setEnable(true).build();
+
+ ArgumentCaptor<LispEnableDisable> mappingCaptor = ArgumentCaptor.forClass(LispEnableDisable.class);
+
+ LispEnableDisableReply fakeReply = new LispEnableDisableReply();
+
+ CompletableFuture<LispEnableDisableReply> completeFuture = new CompletableFuture<>();
+ completeFuture.complete(fakeReply);
+
+ when(fakeJvpp.lispEnableDisable(any(LispEnableDisable.class))).thenReturn(completeFuture);
+
+ new LispCustomizer(fakeJvpp).writeCurrentAttributes(null, intf, null);
+
+ verify(fakeJvpp, times(1)).lispEnableDisable(mappingCaptor.capture());
+
+ LispEnableDisable request = mappingCaptor.getValue();
+
+ assertNotNull(request);
+ assertEquals(1, request.isEn);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testUpdateCurrentAttributesNullData() throws WriteFailedException {
+ new LispCustomizer(mock(FutureJVppCore.class)).updateCurrentAttributes(null, null, null, null);
+ }
+
+ @Test
+ public void testUpdateCurrentAttributes() throws WriteFailedException, InterruptedException, ExecutionException {
+ FutureJVppCore fakeJvpp = mock(FutureJVppCore.class);
+ Lisp lisp = new LispBuilder().setEnable(true).build();
+
+ ArgumentCaptor<LispEnableDisable> lispCaptor = ArgumentCaptor.forClass(LispEnableDisable.class);
+
+ LispEnableDisableReply fakeReply = new LispEnableDisableReply();
+
+ CompletableFuture<LispEnableDisableReply> completeFuture = new CompletableFuture<>();
+ completeFuture.complete(fakeReply);
+
+ when(fakeJvpp.lispEnableDisable(any(LispEnableDisable.class))).thenReturn(completeFuture);
+
+ new LispCustomizer(fakeJvpp).updateCurrentAttributes(null, null, lisp, null);
+
+ verify(fakeJvpp, times(1)).lispEnableDisable(lispCaptor.capture());
+
+ LispEnableDisable request = lispCaptor.getValue();
+
+ assertNotNull(request);
+ assertEquals(1, request.isEn);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testDeleteCurrentAttributesNullData() throws WriteFailedException {
+ new LispCustomizer(mock(FutureJVppCore.class)).deleteCurrentAttributes(null, null, null);
+ }
+
+ @Test
+ public void testDeleteCurrentAttributes() throws WriteFailedException, InterruptedException, ExecutionException {
+ FutureJVppCore fakeJvpp = mock(FutureJVppCore.class);
+ Lisp lisp = new LispBuilder().setEnable(true).build();
+
+ ArgumentCaptor<LispEnableDisable> lispCaptor = ArgumentCaptor.forClass(LispEnableDisable.class);
+
+ LispEnableDisableReply fakeReply = new LispEnableDisableReply();
+
+ CompletableFuture<LispEnableDisableReply> completeFuture = new CompletableFuture<>();
+ completeFuture.complete(fakeReply);
+
+ when(fakeJvpp.lispEnableDisable(any(LispEnableDisable.class))).thenReturn(completeFuture);
+
+ new LispCustomizer(fakeJvpp).deleteCurrentAttributes(null, lisp, null);
+
+ verify(fakeJvpp, 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/honeycomb/lisp/translate/write/LocalMappingCustomizerTest.java b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/write/LocalMappingCustomizerTest.java
new file mode 100755
index 000000000..2b28ce6b9
--- /dev/null
+++ b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/write/LocalMappingCustomizerTest.java
@@ -0,0 +1,189 @@
+/*
+ * Copyright (c) 2015 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.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.honeycomb.lisp.context.util.EidMappingContext;
+import io.fd.honeycomb.translate.MappingContext;
+import io.fd.honeycomb.translate.v3po.util.TranslateUtils;
+import io.fd.honeycomb.translate.write.WriteContext;
+import io.fd.honeycomb.translate.write.WriteFailedException;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Captor;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+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.lisp.address.address.Ipv4Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.Lisp;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.MappingId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.EidTable;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.VniTable;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.VniTableKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.LocalMappings;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.local.mappings.LocalMapping;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.local.mappings.LocalMappingBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.local.mappings.LocalMappingKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.local.mappings.local.mapping.Eid;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.local.mappings.local.mapping.EidBuilder;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.openvpp.jvpp.core.dto.LispAddDelLocalEid;
+import org.openvpp.jvpp.core.dto.LispAddDelLocalEidReply;
+import org.openvpp.jvpp.core.future.FutureJVppCore;
+
+
+public class LocalMappingCustomizerTest {
+
+ @Mock
+ private FutureJVppCore fakeJvpp;
+
+ @Captor
+ private ArgumentCaptor<LispAddDelLocalEid> mappingCaptor;
+
+ private MappingId mappingId;
+ private InstanceIdentifier<LocalMapping> id;
+ private LocalMapping mapping;
+ private LispAddDelLocalEidReply fakeReply;
+ private CompletableFuture<LispAddDelLocalEidReply> completeFuture;
+ private LocalMappingCustomizer customizer;
+ private EidMappingContext localMappingContext;
+ private WriteContext writeContext;
+ private MappingContext mappingCtx;
+
+ @Before
+ public void init() {
+ MockitoAnnotations.initMocks(this);
+
+ final Eid
+ eid = new EidBuilder().setAddress(
+ new Ipv4Builder().setIpv4(
+ new Ipv4Address("192.168.2.1"))
+ .build())
+ .build();
+
+
+ mappingId = new MappingId("REMOTE");
+ final LocalMappingKey key = new LocalMappingKey(mappingId);
+ localMappingContext = new EidMappingContext("local");
+ mappingCtx = mock(MappingContext.class);
+ writeContext = mock(WriteContext.class);
+
+ mapping = new LocalMappingBuilder()
+ .setEid(eid)
+ .setLocatorSet("Locator")
+ .build();
+
+ id = InstanceIdentifier.builder(Lisp.class)
+ .child(EidTable.class)
+ .child(VniTable.class, new VniTableKey(25L))
+ .child(LocalMappings.class)
+ .child(LocalMapping.class, new LocalMappingKey(new MappingId("local")))
+ .build();
+
+ fakeReply = new LispAddDelLocalEidReply();
+ completeFuture = new CompletableFuture<>();
+ completeFuture.complete(fakeReply);
+ customizer = new LocalMappingCustomizer(fakeJvpp, localMappingContext);
+
+ when(fakeJvpp.lispAddDelLocalEid(any(LispAddDelLocalEid.class))).thenReturn(completeFuture);
+ when(writeContext.getMappingContext()).thenReturn(mappingCtx);
+ when(mappingCtx.read(Mockito.any())).thenReturn(com.google.common.base.Optional
+ .of(new LocalMappingBuilder().setKey(key).setId(mappingId).setEid(eid).build()));
+ }
+
+
+ @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");
+
+ new LocalMappingCustomizer(mock(FutureJVppCore.class), localMappingContext)
+ .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, InterruptedException, ExecutionException {
+ //to simulate no mapping
+ when(mappingCtx.read(Mockito.any())).thenReturn(com.google.common.base.Optional.absent());
+
+ customizer.writeCurrentAttributes(id, mapping, writeContext);
+
+ verify(fakeJvpp, times(1)).lispAddDelLocalEid(mappingCaptor.capture());
+
+ LispAddDelLocalEid request = mappingCaptor.getValue();
+
+ assertNotNull(request);
+ assertEquals("Locator", new String(request.locatorSetName));
+ assertEquals("1.2.168.192", TranslateUtils.arrayToIpv4AddressNoZone(request.eid).getValue());
+ assertEquals(0, request.eidType);
+ assertEquals(1, request.isAdd);
+ assertEquals(25, request.vni);
+ assertEquals("Locator", TranslateUtils.toString(request.locatorSetName));
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void testUpdateCurrentAttributes() throws WriteFailedException {
+ new LocalMappingCustomizer(mock(FutureJVppCore.class), localMappingContext)
+ .updateCurrentAttributes(null, null, null, writeContext);
+ }
+
+ @Test
+ public void testDeleteCurrentAttributes() throws WriteFailedException, InterruptedException, ExecutionException {
+ customizer.deleteCurrentAttributes(id, mapping, writeContext);
+
+ verify(fakeJvpp, times(1)).lispAddDelLocalEid(mappingCaptor.capture());
+
+ LispAddDelLocalEid request = mappingCaptor.getValue();
+
+ assertNotNull(request);
+ assertEquals("Locator", new String(request.locatorSetName));
+ assertEquals("1.2.168.192", TranslateUtils.arrayToIpv4AddressNoZone(request.eid).getValue());
+ assertEquals(0, request.eidType);
+ assertEquals(0, request.isAdd);
+ assertEquals(25, request.vni);
+ assertEquals("Locator", TranslateUtils.toString(request.locatorSetName));
+ }
+}
diff --git a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/write/LocatorSetCustomizerTest.java b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/write/LocatorSetCustomizerTest.java
new file mode 100755
index 000000000..e7fb88ae5
--- /dev/null
+++ b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/write/LocatorSetCustomizerTest.java
@@ -0,0 +1,157 @@
+/*
+ * Copyright (c) 2015 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.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 com.google.common.collect.ImmutableList;
+import io.fd.honeycomb.translate.MappingContext;
+import io.fd.honeycomb.translate.ModificationCache;
+import io.fd.honeycomb.translate.v3po.util.NamingContext;
+import io.fd.honeycomb.translate.write.WriteContext;
+import io.fd.honeycomb.translate.write.WriteFailedException;
+import java.nio.charset.StandardCharsets;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.ArgumentCaptor;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.locator.sets.grouping.locator.sets.LocatorSet;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.locator.sets.grouping.locator.sets.LocatorSetBuilder;
+import org.openvpp.jvpp.core.dto.LispAddDelLocatorSet;
+import org.openvpp.jvpp.core.dto.LispAddDelLocatorSetReply;
+import org.openvpp.jvpp.core.dto.LispLocatorSetDetails;
+import org.openvpp.jvpp.core.dto.LispLocatorSetDetailsReplyDump;
+import org.openvpp.jvpp.core.future.FutureJVppCore;
+
+
+public class LocatorSetCustomizerTest {
+
+ private FutureJVppCore fakeJvpp;
+ private NamingContext locatorSetContext;
+ private MappingContext mappingContext;
+ private ModificationCache cache;
+ private WriteContext context;
+
+ @Before
+ public void init() {
+ fakeJvpp = mock(FutureJVppCore.class);
+ locatorSetContext = new NamingContext("locator-set", "instance");
+ context = mock(WriteContext.class);
+ mappingContext = mock(MappingContext.class);
+ cache = new ModificationCache();
+ when(context.getMappingContext()).thenReturn(mappingContext);
+ when(context.getModificationCache()).thenReturn(cache);
+ }
+
+
+ @Test(expected = NullPointerException.class)
+ public void testWriteCurrentAttributesNullData() throws WriteFailedException {
+ new LocatorSetCustomizer(fakeJvpp, locatorSetContext).writeCurrentAttributes(null, null, null);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testWriteCurrentAttributesBadData() throws WriteFailedException {
+ new LocatorSetCustomizer(fakeJvpp, locatorSetContext)
+ .writeCurrentAttributes(null, mock(LocatorSet.class), null);
+ }
+
+ @Test
+ public void testWriteCurrentAttributes() throws WriteFailedException, InterruptedException, ExecutionException {
+
+ LocatorSet locatorSet = new LocatorSetBuilder()
+ .setName("Locator")
+ .build();
+
+ ArgumentCaptor<LispAddDelLocatorSet> locatorSetCaptor = ArgumentCaptor.forClass(LispAddDelLocatorSet.class);
+
+ LispAddDelLocatorSetReply fakeReply = new LispAddDelLocatorSetReply();
+
+ CompletableFuture<LispAddDelLocatorSetReply> completeFuture = new CompletableFuture<>();
+ completeFuture.complete(fakeReply);
+
+ when(fakeJvpp.lispAddDelLocatorSet(any(LispAddDelLocatorSet.class))).thenReturn(completeFuture);
+
+ final LispLocatorSetDetailsReplyDump reply = new LispLocatorSetDetailsReplyDump();
+ LispLocatorSetDetails details = new LispLocatorSetDetails();
+ details.locatorSetName = "Locator".getBytes(StandardCharsets.UTF_8);
+ reply.lispLocatorSetDetails = ImmutableList.of(details);
+
+ cache.put(io.fd.honeycomb.lisp.translate.read.LocatorSetCustomizer.LOCATOR_SETS_CACHE_ID, reply);
+
+ new LocatorSetCustomizer(fakeJvpp, locatorSetContext).writeCurrentAttributes(null, locatorSet, context);
+
+ verify(fakeJvpp, times(1)).lispAddDelLocatorSet(locatorSetCaptor.capture());
+
+ LispAddDelLocatorSet request = locatorSetCaptor.getValue();
+
+ assertNotNull(request);
+ assertEquals("Locator", new String(request.locatorSetName));
+ assertEquals(1, request.isAdd);
+
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void testUpdateCurrentAttributes() throws WriteFailedException {
+ new LocatorSetCustomizer(fakeJvpp, locatorSetContext).updateCurrentAttributes(null, null, null, null);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testDeleteCurrentAttributesNullData() throws WriteFailedException {
+ new LocatorSetCustomizer(fakeJvpp, locatorSetContext).deleteCurrentAttributes(null, null, null);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testDeleteCurrentAttributesBadData() throws WriteFailedException {
+ new LocatorSetCustomizer(fakeJvpp, locatorSetContext)
+ .deleteCurrentAttributes(null, mock(LocatorSet.class), null);
+ }
+
+ @Test
+ public void testDeleteCurrentAttributes() throws InterruptedException, ExecutionException, WriteFailedException {
+
+ LocatorSet locatorSet = new LocatorSetBuilder()
+ .setName("Locator")
+ .build();
+
+ ArgumentCaptor<LispAddDelLocatorSet> locatorSetCaptor = ArgumentCaptor.forClass(LispAddDelLocatorSet.class);
+
+ LispAddDelLocatorSetReply fakeReply = new LispAddDelLocatorSetReply();
+
+ CompletableFuture<LispAddDelLocatorSetReply> completeFuture = new CompletableFuture<>();
+ completeFuture.complete(fakeReply);
+
+ when(fakeJvpp.lispAddDelLocatorSet(any(LispAddDelLocatorSet.class))).thenReturn(completeFuture);
+
+ new LocatorSetCustomizer(fakeJvpp, locatorSetContext).deleteCurrentAttributes(null, locatorSet, context);
+
+ verify(fakeJvpp, 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/honeycomb/lisp/translate/write/MapResolverCustomizerTest.java b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/write/MapResolverCustomizerTest.java
new file mode 100755
index 000000000..63be37a23
--- /dev/null
+++ b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/write/MapResolverCustomizerTest.java
@@ -0,0 +1,111 @@
+/*
+ * Copyright (c) 2015 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.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.v3po.util.TranslateUtils;
+import io.fd.honeycomb.translate.write.WriteFailedException;
+import java.util.concurrent.CompletableFuture;
+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.rev160520.map.resolvers.grouping.map.resolvers.MapResolver;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.map.resolvers.grouping.map.resolvers.MapResolverBuilder;
+import org.openvpp.jvpp.core.dto.LispAddDelMapResolver;
+import org.openvpp.jvpp.core.dto.LispAddDelMapResolverReply;
+import org.openvpp.jvpp.core.future.FutureJVppCore;
+
+
+public class MapResolverCustomizerTest {
+
+ @Test(expected = NullPointerException.class)
+ public void testWriteCurrentAttributesNullData() throws WriteFailedException {
+ new MapResolverCustomizer(mock(FutureJVppCore.class)).writeCurrentAttributes(null, null, null);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testWriteCurrentAttributesBadData() throws WriteFailedException {
+ new MapResolverCustomizer(mock(FutureJVppCore.class))
+ .writeCurrentAttributes(null, new MapResolverBuilder().build(), null);
+ }
+
+ @Test
+ public void testWriteCurrentAttributes() throws WriteFailedException, InterruptedException, ExecutionException {
+ FutureJVppCore fakeJvpp = mock(FutureJVppCore.class);
+
+ MapResolverCustomizer customizer = new MapResolverCustomizer(fakeJvpp);
+ Ipv4Address address = new Ipv4Address("192.168.2.1");
+ MapResolver resolver = new MapResolverBuilder().setIpAddress(new IpAddress(address)).build();
+
+ ArgumentCaptor<LispAddDelMapResolver> resolverCaptor = ArgumentCaptor.forClass(LispAddDelMapResolver.class);
+
+ LispAddDelMapResolverReply fakeReply = new LispAddDelMapResolverReply();
+
+ CompletableFuture<LispAddDelMapResolverReply> finalStage = new CompletableFuture<>();
+ finalStage.complete(fakeReply);
+
+ when(fakeJvpp.lispAddDelMapResolver(any(LispAddDelMapResolver.class))).thenReturn(finalStage);
+
+ customizer.writeCurrentAttributes(null, resolver, null);
+ verify(fakeJvpp, times(1)).lispAddDelMapResolver(resolverCaptor.capture());
+
+ LispAddDelMapResolver request = resolverCaptor.getValue();
+ assertEquals(1, request.isAdd);
+ assertEquals("1.2.168.192", TranslateUtils.arrayToIpv4AddressNoZone(request.ipAddress).getValue());
+ }
+
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void testUpdateCurrentAttributes() throws WriteFailedException {
+ new MapResolverCustomizer(mock(FutureJVppCore.class)).updateCurrentAttributes(null, null, null, null);
+ }
+
+ @Test
+ public void testDeleteCurrentAttributes() throws InterruptedException, ExecutionException, WriteFailedException {
+
+ FutureJVppCore fakeJvpp = mock(FutureJVppCore.class);
+
+ MapResolverCustomizer customizer = new MapResolverCustomizer(fakeJvpp);
+ Ipv4Address address = new Ipv4Address("192.168.2.1");
+ MapResolver resolver = new MapResolverBuilder().setIpAddress(new IpAddress(address)).build();
+
+ ArgumentCaptor<LispAddDelMapResolver> resolverCaptor = ArgumentCaptor.forClass(LispAddDelMapResolver.class);
+
+ LispAddDelMapResolverReply fakeReply = new LispAddDelMapResolverReply();
+
+ CompletableFuture<LispAddDelMapResolverReply> finalStage = new CompletableFuture<>();
+ finalStage.complete(fakeReply);
+
+ when(fakeJvpp.lispAddDelMapResolver(any(LispAddDelMapResolver.class))).thenReturn(finalStage);
+
+ customizer.deleteCurrentAttributes(null, resolver, null);
+ verify(fakeJvpp, times(1)).lispAddDelMapResolver(resolverCaptor.capture());
+
+ LispAddDelMapResolver request = resolverCaptor.getValue();
+ assertEquals(0, request.isAdd);
+ assertEquals("1.2.168.192", TranslateUtils.arrayToIpv4AddressNoZone(request.ipAddress).getValue());
+ }
+
+}
diff --git a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/write/PitrCfgCustomizerTest.java b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/write/PitrCfgCustomizerTest.java
new file mode 100755
index 000000000..5f1ffb888
--- /dev/null
+++ b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/write/PitrCfgCustomizerTest.java
@@ -0,0 +1,132 @@
+/*
+ * Copyright (c) 2015 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.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 java.util.concurrent.CompletableFuture;
+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.rev160520.pitr.cfg.grouping.PitrCfg;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.pitr.cfg.grouping.PitrCfgBuilder;
+import org.openvpp.jvpp.core.dto.LispPitrSetLocatorSet;
+import org.openvpp.jvpp.core.dto.LispPitrSetLocatorSetReply;
+import org.openvpp.jvpp.core.future.FutureJVppCore;
+
+
+public class PitrCfgCustomizerTest {
+
+ @Test(expected = NullPointerException.class)
+ public void testWriteCurrentAttributesNullData() throws WriteFailedException {
+ new PitrCfgCustomizer(mock(FutureJVppCore.class)).writeCurrentAttributes(null, null, null);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testWriteCurrentAttributesBadData() throws WriteFailedException {
+ new PitrCfgCustomizer(mock(FutureJVppCore.class)).writeCurrentAttributes(null, mock(PitrCfg.class), null);
+ }
+
+ @Test
+ public void testWriteCurrentAttributes() throws InterruptedException, ExecutionException, WriteFailedException {
+ FutureJVppCore fakeJvpp = mock(FutureJVppCore.class);
+
+ PitrCfgCustomizer customizer = new PitrCfgCustomizer(fakeJvpp);
+ PitrCfg cfg = new PitrCfgBuilder().setLocatorSet("Locator").build();
+
+ ArgumentCaptor<LispPitrSetLocatorSet> cfgCaptor = ArgumentCaptor.forClass(LispPitrSetLocatorSet.class);
+
+ LispPitrSetLocatorSetReply fakeReply = new LispPitrSetLocatorSetReply();
+
+ CompletableFuture<LispPitrSetLocatorSetReply> finalStage = new CompletableFuture<>();
+ finalStage.complete(fakeReply);
+
+ when(fakeJvpp.lispPitrSetLocatorSet(any(LispPitrSetLocatorSet.class))).thenReturn(finalStage);
+
+ customizer.writeCurrentAttributes(null, cfg, null);
+ verify(fakeJvpp, 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 {
+ FutureJVppCore fakeJvpp = mock(FutureJVppCore.class);
+
+ PitrCfgCustomizer customizer = new PitrCfgCustomizer(fakeJvpp);
+ PitrCfg cfg = new PitrCfgBuilder().setLocatorSet("Locator").build();
+
+ ArgumentCaptor<LispPitrSetLocatorSet> cfgCaptor = ArgumentCaptor.forClass(LispPitrSetLocatorSet.class);
+
+ LispPitrSetLocatorSetReply fakeReply = new LispPitrSetLocatorSetReply();
+
+ CompletableFuture<LispPitrSetLocatorSetReply> finalStage = new CompletableFuture<>();
+ finalStage.complete(fakeReply);
+
+ when(fakeJvpp.lispPitrSetLocatorSet(any(LispPitrSetLocatorSet.class))).thenReturn(finalStage);
+
+ customizer.writeCurrentAttributes(null, cfg, null);
+ verify(fakeJvpp, 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 {
+ new PitrCfgCustomizer(mock(FutureJVppCore.class)).deleteCurrentAttributes(null, null, null);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testDeleteCurrentAttributesBadData() throws WriteFailedException {
+ new PitrCfgCustomizer(mock(FutureJVppCore.class)).deleteCurrentAttributes(null, mock(PitrCfg.class), null);
+ }
+
+ @Test
+ public void testDeleteCurrentAttributes() throws WriteFailedException, InterruptedException, ExecutionException {
+ FutureJVppCore fakeJvpp = mock(FutureJVppCore.class);
+
+ PitrCfgCustomizer customizer = new PitrCfgCustomizer(fakeJvpp);
+ PitrCfg cfg = new PitrCfgBuilder().setLocatorSet("Locator").build();
+
+ ArgumentCaptor<LispPitrSetLocatorSet> cfgCaptor = ArgumentCaptor.forClass(LispPitrSetLocatorSet.class);
+
+ LispPitrSetLocatorSetReply fakeReply = new LispPitrSetLocatorSetReply();
+
+ CompletableFuture<LispPitrSetLocatorSetReply> finalStage = new CompletableFuture<>();
+ finalStage.complete(fakeReply);
+
+ when(fakeJvpp.lispPitrSetLocatorSet(any(LispPitrSetLocatorSet.class))).thenReturn(finalStage);
+
+ customizer.deleteCurrentAttributes(null, cfg, null);
+ verify(fakeJvpp, 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/honeycomb/lisp/translate/write/RemoteMappingCustomizerTest.java b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/write/RemoteMappingCustomizerTest.java
new file mode 100755
index 000000000..7797db1f7
--- /dev/null
+++ b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/write/RemoteMappingCustomizerTest.java
@@ -0,0 +1,175 @@
+/*
+ * Copyright (c) 2015 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.write;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+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.lisp.context.util.EidMappingContext;
+import io.fd.honeycomb.translate.MappingContext;
+import io.fd.honeycomb.translate.v3po.util.TranslateUtils;
+import io.fd.honeycomb.translate.write.WriteContext;
+import io.fd.honeycomb.translate.write.WriteFailedException;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Captor;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+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.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address;
+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.rev160520.Lisp;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.MapReplyAction;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.MappingId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.EidTable;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.VniTable;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.VniTableKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.RemoteMappings;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.remote.mappings.RemoteMapping;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.remote.mappings.RemoteMappingBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.remote.mappings.RemoteMappingKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.remote.mappings.remote.mapping.Eid;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.remote.mappings.remote.mapping.EidBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.remote.mappings.remote.mapping.locator.list.NegativeMappingBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.remote.mappings.remote.mapping.locator.list.positive.mapping.rlocs.Locator;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.remote.mappings.remote.mapping.locator.list.positive.mapping.rlocs.LocatorBuilder;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.openvpp.jvpp.core.dto.LispAddDelRemoteMapping;
+import org.openvpp.jvpp.core.dto.LispAddDelRemoteMappingReply;
+import org.openvpp.jvpp.core.future.FutureJVppCore;
+
+
+public class RemoteMappingCustomizerTest {
+
+ @Mock
+ private FutureJVppCore fakeJvpp;
+
+ @Captor
+ private ArgumentCaptor<LispAddDelRemoteMapping> mappingCaptor;
+
+ private MappingId mappingId;
+ private RemoteMappingCustomizer customizer;
+ private RemoteMapping intf;
+ private LispAddDelRemoteMappingReply fakeReply;
+ private CompletableFuture<LispAddDelRemoteMappingReply> completeFuture;
+ private InstanceIdentifier<RemoteMapping> id;
+ private EidMappingContext remoteMappingContext;
+ private WriteContext writeContext;
+ private MappingContext mapping;
+
+
+ @Before
+ public void init() {
+ MockitoAnnotations.initMocks(this);
+
+ final Eid eid = new EidBuilder().setAddress(
+ new Ipv4Builder().setIpv4(
+ new Ipv4Address("192.168.2.1"))
+ .build())
+ .build();
+
+ mappingId = new MappingId("REMOTE");
+ final RemoteMappingKey key = new RemoteMappingKey(mappingId);
+ remoteMappingContext = new EidMappingContext("remote");
+ mapping = mock(MappingContext.class);
+ writeContext = mock(WriteContext.class);
+
+
+ intf = new RemoteMappingBuilder()
+ .setEid(
+ eid)
+ .setLocatorList(new NegativeMappingBuilder().setMapReplyAction(MapReplyAction.Drop).build())
+ .build();
+
+ id = InstanceIdentifier.builder(Lisp.class).child(EidTable.class)
+ .child(VniTable.class, new VniTableKey(25L))
+ .child(RemoteMappings.class)
+ .child(RemoteMapping.class, key).build();
+
+ fakeReply = new LispAddDelRemoteMappingReply();
+ completeFuture = new CompletableFuture<>();
+ completeFuture.complete(fakeReply);
+ customizer = new RemoteMappingCustomizer(fakeJvpp, remoteMappingContext);
+
+ when(fakeJvpp.lispAddDelRemoteMapping(Mockito.any())).thenReturn(completeFuture);
+ when(writeContext.getMappingContext()).thenReturn(mapping);
+ when(mapping.read(Mockito.any())).thenReturn(com.google.common.base.Optional
+ .of(new RemoteMappingBuilder().setKey(key).setId(mappingId).setEid(eid).build()));
+ }
+
+ @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, InterruptedException, ExecutionException {
+ //to simulate no mapping
+ when(mapping.read(Mockito.any())).thenReturn(com.google.common.base.Optional.absent());
+
+ customizer.writeCurrentAttributes(id, intf, writeContext);
+
+ verify(fakeJvpp, times(1)).lispAddDelRemoteMapping(mappingCaptor.capture());
+
+ LispAddDelRemoteMapping request = mappingCaptor.getValue();
+
+ assertNotNull(request);
+ assertEquals(1, request.isAdd);
+ assertEquals("1.2.168.192", TranslateUtils.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, InterruptedException, ExecutionException {
+ customizer.deleteCurrentAttributes(id, intf, writeContext);
+
+ verify(fakeJvpp, times(1)).lispAddDelRemoteMapping(mappingCaptor.capture());
+
+ LispAddDelRemoteMapping request = mappingCaptor.getValue();
+
+ assertNotNull(request);
+ assertEquals(0, request.isAdd);
+ assertEquals("1.2.168.192", TranslateUtils.arrayToIpv4AddressNoZone(request.eid).getValue());
+ assertEquals(25, request.vni);
+ }
+
+}