summaryrefslogtreecommitdiffstats
path: root/lisp/lisp2vpp/src/test/java
diff options
context:
space:
mode:
authorMarek Gradzki <mgradzki@cisco.com>2016-09-23 09:06:19 +0200
committerMarek Gradzki <mgradzki@cisco.com>2016-09-26 08:15:38 +0200
commit0cfdff5e57bd6357acc64debf0ee49c9455a24d7 (patch)
tree54f14153077acb811212c0ba7293d894ffca7596 /lisp/lisp2vpp/src/test/java
parent60d69218642cc976fa606fd8a38623d8c035dd86 (diff)
HONEYCOMB-116: utility for stubbing MappingContext methods
- introduces MappingContextHelper (refactored ContextTestUtils) - updates all v3po and lisp unit tests to use MCH - updates lisp tests to mock EidMappingContext Change-Id: I73b1adda767db71388ca1c4d7206cfd7ee9c70e1 Signed-off-by: Marek Gradzki <mgradzki@cisco.com>
Diffstat (limited to 'lisp/lisp2vpp/src/test/java')
-rwxr-xr-xlisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/write/InterfaceCustomizerTest.java44
-rwxr-xr-xlisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/write/LispCustomizerTest.java4
-rwxr-xr-xlisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/write/LocalMappingCustomizerTest.java32
-rwxr-xr-xlisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/write/LocatorSetCustomizerTest.java3
-rwxr-xr-xlisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/write/RemoteMappingCustomizerTest.java21
5 files changed, 35 insertions, 69 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
index 409f27bbc..334774341 100755
--- 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
@@ -24,17 +24,13 @@ 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.v3po.util.ByteDataTranslator;
import io.fd.honeycomb.translate.v3po.util.NamingContext;
import io.fd.honeycomb.translate.write.WriteFailedException;
import io.fd.honeycomb.vpp.test.write.WriterCustomizerTest;
-import java.util.concurrent.ExecutionException;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
-import org.mockito.Mockito;
-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;
@@ -42,28 +38,29 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev
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 extends WriterCustomizerTest implements ByteDataTranslator {
@Captor
private ArgumentCaptor<LispAddDelLocator> intfCaptor;
- private NamingContext namingContext;
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(LocatorSets.class)
.child(LocatorSet.class, new LocatorSetKey("Locator"))
- .child(Interface.class, new InterfaceKey("Interface"))
+ .child(Interface.class, new InterfaceKey(interfaceName))
.build();
intf = new InterfaceBuilder()
@@ -71,19 +68,14 @@ public class InterfaceCustomizerTest extends WriterCustomizerTest implements Byt
.setWeight((short) 2)
.build();
- namingContext = new NamingContext("PREFIX", "INSTANCE");
-
- customizer = new InterfaceCustomizer(api, namingContext);
+ customizer = new InterfaceCustomizer(api, new NamingContext("PREFIX", ifcCtxName));
- when(mappingContext.read(Mockito.any()))
- .thenReturn(Optional.of((DataObject) new MappingBuilder().setIndex(5).setName("interface").build()));
when(api.lispAddDelLocator(any(LispAddDelLocator.class))).thenReturn(future(new LispAddDelLocatorReply()));
}
@Test(expected = NullPointerException.class)
public void testWriteCurrentAttributesNullData() throws WriteFailedException {
- new InterfaceCustomizer(mock(FutureJVppCore.class), new NamingContext("PREFIX", "INSTANCE"))
- .writeCurrentAttributes(null, null, null);
+ customizer.writeCurrentAttributes(null, null, null);
}
@Test(expected = NullPointerException.class)
@@ -92,8 +84,7 @@ public class InterfaceCustomizerTest extends WriterCustomizerTest implements Byt
when(intf.getWeight()).thenReturn((short) 1);
when(intf.getPriority()).thenReturn(null);
- new InterfaceCustomizer(mock(FutureJVppCore.class), new NamingContext("PREFIX", "INSTANCE"))
- .writeCurrentAttributes(null, intf, null);
+ customizer.writeCurrentAttributes(null, intf, null);
}
@Test(expected = NullPointerException.class)
@@ -102,12 +93,11 @@ public class InterfaceCustomizerTest extends WriterCustomizerTest implements Byt
when(intf.getWeight()).thenReturn(null);
when(intf.getPriority()).thenReturn((short) 1);
- new InterfaceCustomizer(mock(FutureJVppCore.class), new NamingContext("PREFIX", "INSTANCE"))
- .writeCurrentAttributes(null, intf, null);
+ customizer.writeCurrentAttributes(null, intf, null);
}
@Test
- public void testWriteCurrentAttributes() throws InterruptedException, ExecutionException, WriteFailedException {
+ public void testWriteCurrentAttributes() throws WriteFailedException {
customizer.writeCurrentAttributes(id, intf, writeContext);
verify(api, times(1)).lispAddDelLocator(intfCaptor.capture());
@@ -124,14 +114,12 @@ public class InterfaceCustomizerTest extends WriterCustomizerTest implements Byt
@Test(expected = UnsupportedOperationException.class)
public void testUpdateCurrentAttributes() throws WriteFailedException {
- new InterfaceCustomizer(api, namingContext)
- .updateCurrentAttributes(null, null, null, null);
+ customizer.updateCurrentAttributes(null, null, null, null);
}
@Test(expected = NullPointerException.class)
public void testDeleteCurrentAttributesNullData() throws WriteFailedException {
- new InterfaceCustomizer(api, namingContext)
- .deleteCurrentAttributes(null, null, null);
+ customizer.deleteCurrentAttributes(null, null, null);
}
@Test(expected = NullPointerException.class)
@@ -140,8 +128,7 @@ public class InterfaceCustomizerTest extends WriterCustomizerTest implements Byt
when(interf.getWeight()).thenReturn((short) 1);
when(interf.getPriority()).thenReturn(null);
- new InterfaceCustomizer(mock(FutureJVppCore.class), new NamingContext("PREFIX", "INSTANCE"))
- .deleteCurrentAttributes(null, interf, null);
+ customizer.deleteCurrentAttributes(null, interf, null);
}
@Test(expected = NullPointerException.class)
@@ -150,12 +137,11 @@ public class InterfaceCustomizerTest extends WriterCustomizerTest implements Byt
when(interf.getWeight()).thenReturn(null);
when(interf.getPriority()).thenReturn((short) 1);
- new InterfaceCustomizer(mock(FutureJVppCore.class), new NamingContext("PREFIX", "INSTANCE"))
- .deleteCurrentAttributes(null, interf, null);
+ customizer.deleteCurrentAttributes(null, interf, null);
}
@Test
- public void testDeleteCurrentAttributes() throws InterruptedException, ExecutionException, WriteFailedException {
+ public void testDeleteCurrentAttributes() throws WriteFailedException {
customizer.deleteCurrentAttributes(id, intf, writeContext);
verify(api, times(1)).lispAddDelLocator(intfCaptor.capture());
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
index 171377cab..235f9eee6 100755
--- 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
@@ -19,7 +19,6 @@ 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;
@@ -32,7 +31,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev
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 extends WriterCustomizerTest {
@@ -50,7 +48,7 @@ public class LispCustomizerTest extends WriterCustomizerTest {
@Test(expected = NullPointerException.class)
public void testWriteCurrentAttributesNullData() throws WriteFailedException {
- new LispCustomizer(mock(FutureJVppCore.class)).writeCurrentAttributes(null, null, null);
+ customizer.writeCurrentAttributes(null, null, null);
}
@Test
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
index 9887c6351..61c9084d0 100755
--- 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
@@ -19,6 +19,7 @@ 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.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
@@ -33,7 +34,7 @@ import java.util.concurrent.ExecutionException;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
-import org.mockito.Mockito;
+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.lisp.address.address.Ipv4Builder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.Lisp;
@@ -50,19 +51,17 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev
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 extends WriterCustomizerTest implements ByteDataTranslator, Ipv4Translator {
+ @Mock
+ private EidMappingContext eidMappingContext;
@Captor
private ArgumentCaptor<LispAddDelLocalEid> mappingCaptor;
- private MappingId mappingId;
private InstanceIdentifier<LocalMapping> id;
private LocalMapping mapping;
private LocalMappingCustomizer customizer;
- private EidMappingContext localMappingContext;
@Override
public void setUp() {
@@ -73,11 +72,6 @@ public class LocalMappingCustomizerTest extends WriterCustomizerTest implements
.build())
.build();
-
- mappingId = new MappingId("REMOTE");
- final LocalMappingKey key = new LocalMappingKey(mappingId);
- localMappingContext = new EidMappingContext("local");
-
mapping = new LocalMappingBuilder()
.setEid(eid)
.setLocatorSet("Locator")
@@ -90,11 +84,9 @@ public class LocalMappingCustomizerTest extends WriterCustomizerTest implements
.child(LocalMapping.class, new LocalMappingKey(new MappingId("local")))
.build();
- customizer = new LocalMappingCustomizer(api, localMappingContext);
+ customizer = new LocalMappingCustomizer(api, eidMappingContext);
when(api.lispAddDelLocalEid(any(LispAddDelLocalEid.class))).thenReturn(future(new LispAddDelLocalEidReply()));
- when(mappingContext.read(Mockito.any())).thenReturn(com.google.common.base.Optional
- .of(new LocalMappingBuilder().setKey(key).setId(mappingId).setEid(eid).build()));
}
@@ -105,18 +97,15 @@ public class LocalMappingCustomizerTest extends WriterCustomizerTest implements
@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);
+ 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);
@@ -126,10 +115,7 @@ public class LocalMappingCustomizerTest extends WriterCustomizerTest implements
@Test
- public void testWriteCurrentAttributes() throws WriteFailedException, InterruptedException, ExecutionException {
- //to simulate no mapping
- when(mappingContext.read(Mockito.any())).thenReturn(com.google.common.base.Optional.absent());
-
+ public void testWriteCurrentAttributes() throws WriteFailedException {
customizer.writeCurrentAttributes(id, mapping, writeContext);
verify(api, times(1)).lispAddDelLocalEid(mappingCaptor.capture());
@@ -147,12 +133,12 @@ public class LocalMappingCustomizerTest extends WriterCustomizerTest implements
@Test(expected = UnsupportedOperationException.class)
public void testUpdateCurrentAttributes() throws WriteFailedException {
- new LocalMappingCustomizer(mock(FutureJVppCore.class), localMappingContext)
- .updateCurrentAttributes(null, null, null, writeContext);
+ 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());
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
index 444b9b658..296728ad0 100755
--- 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
@@ -61,8 +61,7 @@ public class LocatorSetCustomizerTest extends WriterCustomizerTest {
@Test(expected = NullPointerException.class)
public void testWriteCurrentAttributesBadData() throws WriteFailedException {
- customizer
- .writeCurrentAttributes(null, mock(LocatorSet.class), null);
+ customizer.writeCurrentAttributes(null, mock(LocatorSet.class), null);
}
@Test
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
index dab387a62..c96badd3e 100755
--- 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
@@ -18,6 +18,8 @@ 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.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
@@ -27,11 +29,10 @@ import io.fd.honeycomb.lisp.context.util.EidMappingContext;
import io.fd.honeycomb.translate.v3po.util.Ipv4Translator;
import io.fd.honeycomb.translate.write.WriteFailedException;
import io.fd.honeycomb.vpp.test.write.WriterCustomizerTest;
-import java.util.concurrent.ExecutionException;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
-import org.mockito.Mockito;
+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.lisp.address.address.Ipv4Builder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.Lisp;
@@ -51,7 +52,6 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.openvpp.jvpp.core.dto.LispAddDelRemoteMapping;
import org.openvpp.jvpp.core.dto.LispAddDelRemoteMappingReply;
-
public class RemoteMappingCustomizerTest extends WriterCustomizerTest implements Ipv4Translator {
@Captor
@@ -61,6 +61,8 @@ public class RemoteMappingCustomizerTest extends WriterCustomizerTest implements
private RemoteMappingCustomizer customizer;
private RemoteMapping intf;
private InstanceIdentifier<RemoteMapping> id;
+
+ @Mock
private EidMappingContext remoteMappingContext;
@Override
@@ -73,7 +75,6 @@ public class RemoteMappingCustomizerTest extends WriterCustomizerTest implements
mappingId = new MappingId("REMOTE");
final RemoteMappingKey key = new RemoteMappingKey(mappingId);
- remoteMappingContext = new EidMappingContext("remote");
intf = new RemoteMappingBuilder()
.setEid(
@@ -88,9 +89,7 @@ public class RemoteMappingCustomizerTest extends WriterCustomizerTest implements
customizer = new RemoteMappingCustomizer(api, remoteMappingContext);
- when(api.lispAddDelRemoteMapping(Mockito.any())).thenReturn(future(new LispAddDelRemoteMappingReply()));
- when(mappingContext.read(Mockito.any())).thenReturn(com.google.common.base.Optional
- .of(new RemoteMappingBuilder().setKey(key).setId(mappingId).setEid(eid).build()));
+ when(api.lispAddDelRemoteMapping(any())).thenReturn(future(new LispAddDelRemoteMappingReply()));
}
@Test(expected = NullPointerException.class)
@@ -105,10 +104,7 @@ public class RemoteMappingCustomizerTest extends WriterCustomizerTest implements
}
@Test
- public void testWriteCurrentAttributes() throws WriteFailedException, InterruptedException, ExecutionException {
- //to simulate no mapping
- when(mappingContext.read(Mockito.any())).thenReturn(com.google.common.base.Optional.absent());
-
+ public void testWriteCurrentAttributes() throws WriteFailedException {
customizer.writeCurrentAttributes(id, intf, writeContext);
verify(api, times(1)).lispAddDelRemoteMapping(mappingCaptor.capture());
@@ -132,7 +128,8 @@ public class RemoteMappingCustomizerTest extends WriterCustomizerTest implements
}
@Test
- public void testDeleteCurrentAttributes() throws WriteFailedException, InterruptedException, ExecutionException {
+ 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());