summaryrefslogtreecommitdiffstats
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
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>
-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
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/AclCustomizerTest.java3
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/GreCustomizerTest.java26
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/RewriteCustomizerTest.java3
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/SubInterfaceCustomizerTest.java17
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/TapCustomizerTest.java19
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/VhostUserCustomizerTest.java19
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/VxlanCustomizerTest.java27
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/VxlanGpeCustomizerTest.java29
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/ip/Ipv4AddressCustomizerTest.java15
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/ip/Ipv4NeighbourCustomizerTest.java3
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/AclCustomizerTest.java3
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/GreCustomizerTest.java3
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/InterfaceCustomizerTest.java7
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/L2CustomizerTest.java5
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/RewriteCustomizerTest.java3
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/SubInterfaceCustomizerTest.java9
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/VxlanCustomizerTest.java3
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/VxlanGpeCustomizerTest.java3
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/ip/Ipv4AddressCustomizerTest.java5
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/notification/InterfaceChangeNotificationProducerTest.java6
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/test/ContextTestUtils.java86
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/vpp/ArpTerminationTableEntryCustomizerTest.java5
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/vpp/BridgeDomainCustomizerTest.java25
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/vpp/L2FibEntryCustomizerTest.java5
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/vppstate/L2FibEntryCustomizerTest.java5
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/vppstate/VppStateTest.java10
-rw-r--r--vpp-common/vpp-translate-test/pom.xml5
-rw-r--r--vpp-common/vpp-translate-test/src/main/java/io/fd/honeycomb/vpp/test/read/ReaderCustomizerTest.java6
-rw-r--r--vpp-common/vpp-translate-test/src/main/java/io/fd/honeycomb/vpp/test/util/NamingContextHelper.java119
-rw-r--r--vpp-common/vpp-translate-test/src/main/java/io/fd/honeycomb/vpp/test/write/WriterCustomizerTest.java4
35 files changed, 279 insertions, 303 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());
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/AclCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/AclCustomizerTest.java
index b55a5ce2b..5de6e5e73 100644
--- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/AclCustomizerTest.java
+++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/AclCustomizerTest.java
@@ -22,7 +22,6 @@ import static org.mockito.Matchers.any;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.verify;
-import io.fd.honeycomb.translate.v3po.test.ContextTestUtils;
import io.fd.honeycomb.translate.v3po.util.NamingContext;
import io.fd.honeycomb.translate.v3po.vppclassifier.VppClassifierContextManager;
import io.fd.honeycomb.translate.write.WriteFailedException;
@@ -58,7 +57,7 @@ public class AclCustomizerTest extends WriterCustomizerTest {
@Override
public void setUp() {
- ContextTestUtils.mockMapping(mappingContext, IF_NAME, IF_INDEX, IFC_TEST_INSTANCE);
+ defineMapping(mappingContext, IF_NAME, IF_INDEX, IFC_TEST_INSTANCE);
customizer = new AclCustomizer(api, new NamingContext("generatedInterfaceName", IFC_TEST_INSTANCE),
classifyTableContext);
}
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/GreCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/GreCustomizerTest.java
index 6918e1f01..1a8aec645 100644
--- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/GreCustomizerTest.java
+++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/GreCustomizerTest.java
@@ -16,10 +16,6 @@
package io.fd.honeycomb.translate.v3po.interfaces;
-import static io.fd.honeycomb.translate.v3po.test.ContextTestUtils.getMapping;
-import static io.fd.honeycomb.translate.v3po.test.ContextTestUtils.getMappingIid;
-import static io.fd.honeycomb.translate.v3po.test.ContextTestUtils.mockEmptyMapping;
-import static io.fd.honeycomb.translate.v3po.test.ContextTestUtils.mockMapping;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@@ -116,12 +112,12 @@ public class GreCustomizerTest extends WriterCustomizerTest {
whenGreAddDelTunnelThenSuccess();
- mockEmptyMapping(mappingContext, IFACE_NAME, IFC_TEST_INSTANCE);
+ noMappingDefined(mappingContext, IFACE_NAME, IFC_TEST_INSTANCE);
customizer.writeCurrentAttributes(id, gre, writeContext);
verifyGreAddWasInvoked(gre);
- verify(mappingContext).put(eq(getMappingIid(IFACE_NAME, IFC_TEST_INSTANCE)),
- eq(getMapping(IFACE_NAME, IFACE_ID).get()));
+ verify(mappingContext).put(eq(mappingIid(IFACE_NAME, IFC_TEST_INSTANCE)),
+ eq(mapping(IFACE_NAME, IFACE_ID).get()));
}
@Test
@@ -129,14 +125,14 @@ public class GreCustomizerTest extends WriterCustomizerTest {
final Gre gre = generateGre();
whenGreAddDelTunnelThenSuccess();
- mockMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_TEST_INSTANCE);
+ defineMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_TEST_INSTANCE);
customizer.writeCurrentAttributes(id, gre, writeContext);
verifyGreAddWasInvoked(gre);
// Remove the first mapping before putting in the new one
- verify(mappingContext).delete(eq(getMappingIid(IFACE_NAME, IFC_TEST_INSTANCE)));
- verify(mappingContext).put(eq(getMappingIid(IFACE_NAME, IFC_TEST_INSTANCE)), eq(getMapping(IFACE_NAME, IFACE_ID).get()));
+ verify(mappingContext).delete(eq(mappingIid(IFACE_NAME, IFC_TEST_INSTANCE)));
+ verify(mappingContext).put(eq(mappingIid(IFACE_NAME, IFC_TEST_INSTANCE)), eq(mapping(IFACE_NAME, IFACE_ID).get()));
}
@Test
@@ -151,7 +147,7 @@ public class GreCustomizerTest extends WriterCustomizerTest {
assertTrue(e.getCause() instanceof VppBaseCallException);
verifyGreAddWasInvoked(gre);
// Mapping not stored due to failure
- verify(mappingContext, times(0)).put(eq(getMappingIid(IFACE_NAME, IFC_TEST_INSTANCE)), eq(getMapping(
+ verify(mappingContext, times(0)).put(eq(mappingIid(IFACE_NAME, IFC_TEST_INSTANCE)), eq(mapping(
IFACE_NAME, 0).get()));
return;
}
@@ -174,11 +170,11 @@ public class GreCustomizerTest extends WriterCustomizerTest {
final Gre gre = generateGre();
whenGreAddDelTunnelThenSuccess();
- mockMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_TEST_INSTANCE);
+ defineMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_TEST_INSTANCE);
customizer.deleteCurrentAttributes(id, gre, writeContext);
verifyGreDeleteWasInvoked(gre);
- verify(mappingContext).delete(eq(getMappingIid(IFACE_NAME, IFC_TEST_INSTANCE)));
+ verify(mappingContext).delete(eq(mappingIid(IFACE_NAME, IFC_TEST_INSTANCE)));
}
@Test
@@ -186,14 +182,14 @@ public class GreCustomizerTest extends WriterCustomizerTest {
final Gre gre = generateGre();
whenGreAddDelTunnelThenFailure();
- mockMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_TEST_INSTANCE);
+ defineMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_TEST_INSTANCE);
try {
customizer.deleteCurrentAttributes(id, gre, writeContext);
} catch (WriteFailedException.DeleteFailedException e) {
assertTrue(e.getCause() instanceof VppBaseCallException);
verifyGreDeleteWasInvoked(gre);
- verify(mappingContext, times(0)).delete(eq(getMappingIid(IFACE_NAME, IFC_TEST_INSTANCE)));
+ verify(mappingContext, times(0)).delete(eq(mappingIid(IFACE_NAME, IFC_TEST_INSTANCE)));
return;
}
fail("WriteFailedException.DeleteFailedException was expected");
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/RewriteCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/RewriteCustomizerTest.java
index e28a0f6c6..d6d1631bb 100644
--- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/RewriteCustomizerTest.java
+++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/RewriteCustomizerTest.java
@@ -22,7 +22,6 @@ import static org.mockito.Matchers.any;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.verify;
-import io.fd.honeycomb.translate.v3po.test.ContextTestUtils;
import io.fd.honeycomb.translate.v3po.util.NamingContext;
import io.fd.honeycomb.translate.v3po.util.TagRewriteOperation;
import io.fd.honeycomb.translate.write.WriteFailedException;
@@ -63,7 +62,7 @@ public class RewriteCustomizerTest extends WriterCustomizerTest {
namingContext = new NamingContext("generatedSubInterfaceName", IFC_TEST_INSTANCE);
customizer = new RewriteCustomizer(api, namingContext);
VLAN_IID = getVlanTagRewriteId(IF_NAME, VLAN_IF_ID);
- ContextTestUtils.mockMapping(mappingContext, VLAN_IF_NAME, VLAN_IF_INDEX, IFC_TEST_INSTANCE);
+ defineMapping(mappingContext, VLAN_IF_NAME, VLAN_IF_INDEX, IFC_TEST_INSTANCE);
}
private static InstanceIdentifier<Rewrite> getVlanTagRewriteId(final String name, final long index) {
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/SubInterfaceCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/SubInterfaceCustomizerTest.java
index 1fee0b3cf..86af0f094 100644
--- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/SubInterfaceCustomizerTest.java
+++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/SubInterfaceCustomizerTest.java
@@ -25,7 +25,6 @@ import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
-import io.fd.honeycomb.translate.v3po.test.ContextTestUtils;
import io.fd.honeycomb.translate.v3po.util.NamingContext;
import io.fd.honeycomb.translate.write.WriteFailedException;
import io.fd.honeycomb.vpp.test.write.WriterCustomizerTest;
@@ -91,8 +90,8 @@ public class SubInterfaceCustomizerTest extends WriterCustomizerTest {
public void setUp() throws Exception {
namingContext = new NamingContext("generatedSubInterfaceName", IFC_TEST_INSTANCE);
customizer = new SubInterfaceCustomizer(api, namingContext);
- ContextTestUtils.mockMapping(mappingContext, SUB_IFACE_NAME, SUBIF_INDEX, IFC_TEST_INSTANCE);
- ContextTestUtils.mockMapping(mappingContext, SUPER_IF_NAME, SUPER_IF_ID, IFC_TEST_INSTANCE);
+ defineMapping(mappingContext, SUB_IFACE_NAME, SUBIF_INDEX, IFC_TEST_INSTANCE);
+ defineMapping(mappingContext, SUPER_IF_NAME, SUPER_IF_ID, IFC_TEST_INSTANCE);
}
private SubInterface generateSubInterface(final boolean enabled, final List<Tag> tagList) {
@@ -198,8 +197,8 @@ public class SubInterfaceCustomizerTest extends WriterCustomizerTest {
verify(api).createSubif(generateSubInterfaceRequest(SUPER_IF_ID, CTAG_ID, false));
verify(mappingContext)
- .put(eq(ContextTestUtils.getMappingIid(SUB_IFACE_NAME, IFC_TEST_INSTANCE)), eq(
- ContextTestUtils.getMapping(SUB_IFACE_NAME, 0).get()));
+ .put(eq(mappingIid(SUB_IFACE_NAME, IFC_TEST_INSTANCE)), eq(
+ mapping(SUB_IFACE_NAME, 0).get()));
}
@Test
@@ -214,8 +213,8 @@ public class SubInterfaceCustomizerTest extends WriterCustomizerTest {
verify(api).createSubif(generateSubInterfaceRequest(SUPER_IF_ID, CTAG_ANY_ID, true));
verify(mappingContext)
- .put(eq(ContextTestUtils.getMappingIid(SUB_IFACE_NAME, IFC_TEST_INSTANCE)), eq(
- ContextTestUtils.getMapping(SUB_IFACE_NAME, 0).get()));
+ .put(eq(mappingIid(SUB_IFACE_NAME, IFC_TEST_INSTANCE)), eq(
+ mapping(SUB_IFACE_NAME, 0).get()));
}
@Test
@@ -231,8 +230,8 @@ public class SubInterfaceCustomizerTest extends WriterCustomizerTest {
assertTrue(e.getCause() instanceof VppBaseCallException);
verify(api).createSubif(generateSubInterfaceRequest(SUPER_IF_ID, CTAG_ID, false));
verify(mappingContext, times(0)).put(
- eq(ContextTestUtils.getMappingIid(SUPER_IF_NAME, IFC_TEST_INSTANCE)),
- eq(ContextTestUtils.getMapping(SUPER_IF_NAME, 0).get()));
+ eq(mappingIid(SUPER_IF_NAME, IFC_TEST_INSTANCE)),
+ eq(mapping(SUPER_IF_NAME, 0).get()));
return;
}
fail("WriteFailedException.CreateFailedException was expected");
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/TapCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/TapCustomizerTest.java
index c2c687602..88232d55f 100644
--- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/TapCustomizerTest.java
+++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/TapCustomizerTest.java
@@ -23,7 +23,6 @@ import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
-import io.fd.honeycomb.translate.v3po.test.ContextTestUtils;
import io.fd.honeycomb.translate.v3po.util.NamingContext;
import io.fd.honeycomb.vpp.test.write.WriterCustomizerTest;
import org.junit.Test;
@@ -74,10 +73,10 @@ public class TapCustomizerTest extends WriterCustomizerTest {
tapCustomizer.writeCurrentAttributes(getTapId("tap2"), getTapData("tap2", "ff:ff:ff:ff:ff:ff"), writeContext);
verify(api, times(2)).tapConnect(any(TapConnect.class));
- verify(mappingContext).put(eq(ContextTestUtils.getMappingIid("tap", IFC_TEST_INSTANCE)), eq(
- ContextTestUtils.getMapping("tap", 0).get()));
- verify(mappingContext).put(eq(ContextTestUtils.getMappingIid("tap2", IFC_TEST_INSTANCE)), eq(
- ContextTestUtils.getMapping("tap2", 1).get()));
+ verify(mappingContext).put(eq(mappingIid("tap", IFC_TEST_INSTANCE)), eq(
+ mapping("tap", 0).get()));
+ verify(mappingContext).put(eq(mappingIid("tap2", IFC_TEST_INSTANCE)), eq(
+ mapping("tap2", 1).get()));
}
@Test
@@ -92,14 +91,14 @@ public class TapCustomizerTest extends WriterCustomizerTest {
tapCustomizer.writeCurrentAttributes(getTapId("tap"), getTapData("tap", "ff:ff:ff:ff:ff:ff"), writeContext);
- ContextTestUtils.mockMapping(mappingContext, "tap", 1, IFC_TEST_INSTANCE);
+ defineMapping(mappingContext, "tap", 1, IFC_TEST_INSTANCE);
tapCustomizer.updateCurrentAttributes(getTapId("tap"), getTapData("tap", "ff:ff:ff:ff:ff:ff"), getTapData("tap", "ff:ff:ff:ff:ff:f1"), writeContext);
verify(api).tapConnect(any(TapConnect.class));
verify(api).tapModify(any(TapModify.class));
- verify(mappingContext).put(eq(ContextTestUtils.getMappingIid("tap", IFC_TEST_INSTANCE)), eq(
- ContextTestUtils.getMapping("tap", 0).get()));
+ verify(mappingContext).put(eq(mappingIid("tap", IFC_TEST_INSTANCE)), eq(
+ mapping("tap", 0).get()));
}
@Test
@@ -111,12 +110,12 @@ public class TapCustomizerTest extends WriterCustomizerTest {
doReturn(future(new TapDeleteReply())).when(api).tapDelete(any(TapDelete.class));
tapCustomizer.writeCurrentAttributes(getTapId("tap"), getTapData("tap", "ff:ff:ff:ff:ff:ff"), writeContext);
- ContextTestUtils.mockMapping(mappingContext, "tap", 1, IFC_TEST_INSTANCE);
+ defineMapping(mappingContext, "tap", 1, IFC_TEST_INSTANCE);
tapCustomizer.deleteCurrentAttributes(getTapId("tap"), getTapData("tap", "ff:ff:ff:ff:ff:ff"), writeContext);
verify(api).tapConnect(any(TapConnect.class));
verify(api).tapDelete(any(TapDelete.class));
- verify(mappingContext).delete(eq(ContextTestUtils.getMappingIid("tap", IFC_TEST_INSTANCE)));
+ verify(mappingContext).delete(eq(mappingIid("tap", IFC_TEST_INSTANCE)));
}
private InstanceIdentifier<Tap> getTapId(final String tap) {
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/VhostUserCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/VhostUserCustomizerTest.java
index a47f5b641..176f3209c 100644
--- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/VhostUserCustomizerTest.java
+++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/VhostUserCustomizerTest.java
@@ -29,7 +29,6 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyZeroInteractions;
import static org.mockito.Mockito.when;
-import io.fd.honeycomb.translate.v3po.test.ContextTestUtils;
import io.fd.honeycomb.translate.v3po.util.Ipv4Translator;
import io.fd.honeycomb.translate.v3po.util.NamingContext;
import io.fd.honeycomb.translate.write.WriteFailedException;
@@ -121,8 +120,8 @@ public class VhostUserCustomizerTest extends WriterCustomizerTest implements Ipv
customizer.writeCurrentAttributes(ID, vhostUser, writeContext);
verifyCreateVhostUserIfWasInvoked(vhostUser);
- verify(mappingContext).put(eq(ContextTestUtils.getMappingIid(IFACE_NAME, "test-instance")), eq(
- ContextTestUtils.getMapping(IFACE_NAME, 0).get()));
+ verify(mappingContext).put(eq(mappingIid(IFACE_NAME, "test-instance")), eq(
+ mapping(IFACE_NAME, 0).get()));
}
@Test
@@ -146,7 +145,7 @@ public class VhostUserCustomizerTest extends WriterCustomizerTest implements Ipv
public void testUpdateCurrentAttributes() throws Exception {
final VhostUser vhostUserBefore = generateVhostUser(VhostUserRole.Client, "socketName0");
final VhostUser vhostUserAfter = generateVhostUser(VhostUserRole.Server, "socketName1");
- ContextTestUtils.mockMapping(mappingContext, IFACE_NAME, IFACE_ID, "test-instance");
+ defineMapping(mappingContext, IFACE_NAME, IFACE_ID, "test-instance");
when(api.modifyVhostUserIf(any(ModifyVhostUserIf.class))).thenReturn(future(new ModifyVhostUserIfReply()));
@@ -158,7 +157,7 @@ public class VhostUserCustomizerTest extends WriterCustomizerTest implements Ipv
public void testUpdateCurrentAttributesFailed() throws Exception {
final VhostUser vhostUserBefore = generateVhostUser(VhostUserRole.Client, "socketName0");
final VhostUser vhostUserAfter = generateVhostUser(VhostUserRole.Server, "socketName1");
- ContextTestUtils.mockMapping(mappingContext, IFACE_NAME, IFACE_ID, "test-instance");
+ defineMapping(mappingContext, IFACE_NAME, IFACE_ID, "test-instance");
doReturn(failedFuture()).when(api).modifyVhostUserIf(any(ModifyVhostUserIf.class));
@@ -175,19 +174,19 @@ public class VhostUserCustomizerTest extends WriterCustomizerTest implements Ipv
@Test
public void testDeleteCurrentAttributes() throws Exception {
final VhostUser vhostUser = generateVhostUser(VhostUserRole.Client, "socketName");
- ContextTestUtils.mockMapping(mappingContext, IFACE_NAME, IFACE_ID, "test-instance");
+ defineMapping(mappingContext, IFACE_NAME, IFACE_ID, "test-instance");
when(api.deleteVhostUserIf(any(DeleteVhostUserIf.class))).thenReturn(future(new DeleteVhostUserIfReply()));
customizer.deleteCurrentAttributes(ID, vhostUser, writeContext);
verifyDeleteVhostUserIfWasInvoked(IFACE_ID);
- verify(mappingContext).delete(eq(ContextTestUtils.getMappingIid(IFACE_NAME, "test-instance")));
+ verify(mappingContext).delete(eq(mappingIid(IFACE_NAME, "test-instance")));
}
@Test
public void testDeleteCurrentAttributesFailed() throws Exception {
final VhostUser vhostUser = generateVhostUser(VhostUserRole.Client, "socketName");
- ContextTestUtils.mockMapping(mappingContext, IFACE_NAME, IFACE_ID, "test-instance");
+ defineMapping(mappingContext, IFACE_NAME, IFACE_ID, "test-instance");
doReturn(failedFuture()).when(api).deleteVhostUserIf(any(DeleteVhostUserIf.class));
@@ -197,8 +196,8 @@ public class VhostUserCustomizerTest extends WriterCustomizerTest implements Ipv
assertTrue(e.getCause() instanceof VppBaseCallException);
verifyDeleteVhostUserIfWasInvoked(IFACE_ID);
// Delete from context not invoked if delete from VPP failed
- verify(mappingContext, times(0)).delete(eq(ContextTestUtils.getMappingIid(IFACE_NAME, "test-instance")));
- verify(mappingContext).read(eq(ContextTestUtils.getMappingIid(IFACE_NAME, "test-instance")));
+ verify(mappingContext, times(0)).delete(eq(mappingIid(IFACE_NAME, "test-instance")));
+ verify(mappingContext).read(eq(mappingIid(IFACE_NAME, "test-instance")));
return;
}
fail("WriteFailedException.DeleteFailedException was expected");
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/VxlanCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/VxlanCustomizerTest.java
index ed099f740..6bb8bd279 100644
--- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/VxlanCustomizerTest.java
+++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/VxlanCustomizerTest.java
@@ -16,8 +16,6 @@
package io.fd.honeycomb.translate.v3po.interfaces;
-import static io.fd.honeycomb.translate.v3po.test.ContextTestUtils.getMapping;
-import static io.fd.honeycomb.translate.v3po.test.ContextTestUtils.getMappingIid;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@@ -31,7 +29,6 @@ import static org.mockito.Mockito.when;
import com.google.common.net.InetAddresses;
import io.fd.honeycomb.translate.v3po.DisabledInterfacesManager;
-import io.fd.honeycomb.translate.v3po.test.ContextTestUtils;
import io.fd.honeycomb.translate.v3po.util.NamingContext;
import io.fd.honeycomb.translate.write.WriteFailedException;
import io.fd.honeycomb.vpp.test.write.WriterCustomizerTest;
@@ -129,11 +126,11 @@ public class VxlanCustomizerTest extends WriterCustomizerTest {
final Vxlan vxlan = generateVxlan();
whenVxlanAddDelTunnelThenSuccess();
- ContextTestUtils.mockEmptyMapping(mappingContext, ifaceName, "test-instance");
+ noMappingDefined(mappingContext, ifaceName, "test-instance");
customizer.writeCurrentAttributes(id, vxlan, writeContext);
verifyVxlanAddWasInvoked(vxlan);
- verify(mappingContext).put(eq(getMappingIid(ifaceName, "test-instance")), eq(getMapping(ifaceName, 0).get()));
+ verify(mappingContext).put(eq(mappingIid(ifaceName, "test-instance")), eq(mapping(ifaceName, 0).get()));
}
@Test
@@ -141,12 +138,12 @@ public class VxlanCustomizerTest extends WriterCustomizerTest {
final Vxlan vxlan = generateVxlan();
whenVxlanAddDelTunnelThenSuccess();
- ContextTestUtils.mockEmptyMapping(mappingContext, ifaceName, "test-instance");
+ noMappingDefined(mappingContext, ifaceName, "test-instance");
doReturn(true).when(disableContext).isInterfaceDisabled(0, mappingContext);
customizer.writeCurrentAttributes(id, vxlan, writeContext);
verifyVxlanAddWasInvoked(vxlan);
- verify(mappingContext).put(eq(getMappingIid(ifaceName, "test-instance")), eq(getMapping(ifaceName, 0).get()));
+ verify(mappingContext).put(eq(mappingIid(ifaceName, "test-instance")), eq(mapping(ifaceName, 0).get()));
verify(disableContext).removeDisabledInterface(0, mappingContext);
}
@@ -156,15 +153,15 @@ public class VxlanCustomizerTest extends WriterCustomizerTest {
final int ifaceId = 0;
whenVxlanAddDelTunnelThenSuccess();
- ContextTestUtils.mockMapping(mappingContext, ifaceName, ifaceId, "test-instance");
+ defineMapping(mappingContext, ifaceName, ifaceId, "test-instance");
customizer.writeCurrentAttributes(id, vxlan, writeContext);
verifyVxlanAddWasInvoked(vxlan);
// Remove the first mapping before putting in the new one
- verify(mappingContext).delete(eq(getMappingIid(ifaceName, "test-instance")));
+ verify(mappingContext).delete(eq(mappingIid(ifaceName, "test-instance")));
verify(mappingContext)
- .put(eq(getMappingIid(ifaceName, "test-instance")), eq(getMapping(ifaceName, ifaceId).get()));
+ .put(eq(mappingIid(ifaceName, "test-instance")), eq(mapping(ifaceName, ifaceId).get()));
}
@Test
@@ -180,7 +177,7 @@ public class VxlanCustomizerTest extends WriterCustomizerTest {
verifyVxlanAddWasInvoked(vxlan);
// Mapping not stored due to failure
verify(mappingContext, times(0))
- .put(eq(getMappingIid(ifaceName, "test-instance")), eq(getMapping(ifaceName, 0).get()));
+ .put(eq(mappingIid(ifaceName, "test-instance")), eq(mapping(ifaceName, 0).get()));
return;
}
fail("WriteFailedException.CreateFailedException was expected");
@@ -202,11 +199,11 @@ public class VxlanCustomizerTest extends WriterCustomizerTest {
final Vxlan vxlan = generateVxlan();
whenVxlanAddDelTunnelThenSuccess();
- ContextTestUtils.mockMapping(mappingContext, ifaceName, 1, "test-instance");
+ defineMapping(mappingContext, ifaceName, 1, "test-instance");
customizer.deleteCurrentAttributes(id, vxlan, writeContext);
verifyVxlanDeleteWasInvoked(vxlan);
- verify(mappingContext).delete(eq(getMappingIid(ifaceName, "test-instance")));
+ verify(mappingContext).delete(eq(mappingIid(ifaceName, "test-instance")));
verify(disableContext).disableInterface(1, mappingContext);
}
@@ -215,14 +212,14 @@ public class VxlanCustomizerTest extends WriterCustomizerTest {
final Vxlan vxlan = generateVxlan();
whenVxlanAddDelTunnelThenFailure();
- ContextTestUtils.mockMapping(mappingContext, ifaceName, 1, "test-instance");
+ defineMapping(mappingContext, ifaceName, 1, "test-instance");
try {
customizer.deleteCurrentAttributes(id, vxlan, writeContext);
} catch (WriteFailedException.DeleteFailedException e) {
assertTrue(e.getCause() instanceof VppBaseCallException);
verifyVxlanDeleteWasInvoked(vxlan);
- verify(mappingContext, times(0)).delete(eq(getMappingIid(ifaceName, "test-instance")));
+ verify(mappingContext, times(0)).delete(eq(mappingIid(ifaceName, "test-instance")));
return;
}
fail("WriteFailedException.DeleteFailedException was expected");
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/VxlanGpeCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/VxlanGpeCustomizerTest.java
index 75e0d3bb1..d90aeb14d 100644
--- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/VxlanGpeCustomizerTest.java
+++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/VxlanGpeCustomizerTest.java
@@ -16,8 +16,6 @@
package io.fd.honeycomb.translate.v3po.interfaces;
-import static io.fd.honeycomb.translate.v3po.test.ContextTestUtils.getMapping;
-import static io.fd.honeycomb.translate.v3po.test.ContextTestUtils.getMappingIid;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@@ -31,7 +29,6 @@ import static org.mockito.Mockito.when;
import com.google.common.net.InetAddresses;
import io.fd.honeycomb.translate.v3po.DisabledInterfacesManager;
-import io.fd.honeycomb.translate.v3po.test.ContextTestUtils;
import io.fd.honeycomb.translate.v3po.util.NamingContext;
import io.fd.honeycomb.translate.write.WriteFailedException;
import io.fd.honeycomb.vpp.test.write.WriterCustomizerTest;
@@ -133,12 +130,12 @@ public class VxlanGpeCustomizerTest extends WriterCustomizerTest {
final VxlanGpe vxlanGpe = generateVxlanGpe();
whenVxlanGpeAddDelTunnelThenSuccess();
- ContextTestUtils.mockEmptyMapping(mappingContext, ifaceName, "test-instance");
+ noMappingDefined(mappingContext, ifaceName, "test-instance");
customizer.writeCurrentAttributes(id, vxlanGpe, writeContext);
verifyVxlanGpeAddWasInvoked(vxlanGpe);
- verify(mappingContext).put(eq(getMappingIid(ifaceName, "test-instance")), eq(
- getMapping(ifaceName, 0).get()));
+ verify(mappingContext).put(eq(mappingIid(ifaceName, "test-instance")), eq(
+ mapping(ifaceName, 0).get()));
}
@Test
@@ -147,15 +144,15 @@ public class VxlanGpeCustomizerTest extends WriterCustomizerTest {
final int ifaceId = 0;
whenVxlanGpeAddDelTunnelThenSuccess();
- ContextTestUtils.mockMapping(mappingContext, ifaceName, ifaceId, "test-instance");
+ defineMapping(mappingContext, ifaceName, ifaceId, "test-instance");
customizer.writeCurrentAttributes(id, vxlanGpe, writeContext);
verifyVxlanGpeAddWasInvoked(vxlanGpe);
// Remove the first mapping before putting in the new one
- verify(mappingContext).delete(eq(getMappingIid(ifaceName, "test-instance")));
- verify(mappingContext).put(eq(getMappingIid(ifaceName, "test-instance")),
- eq(getMapping(ifaceName, ifaceId).get()));
+ verify(mappingContext).delete(eq(mappingIid(ifaceName, "test-instance")));
+ verify(mappingContext).put(eq(mappingIid(ifaceName, "test-instance")),
+ eq(mapping(ifaceName, ifaceId).get()));
}
@Test
@@ -171,8 +168,8 @@ public class VxlanGpeCustomizerTest extends WriterCustomizerTest {
verifyVxlanGpeAddWasInvoked(vxlanGpe);
// Mapping not stored due to failure
verify(mappingContext, times(0))
- .put(eq(getMappingIid(ifaceName, "test-instance")), eq(
- getMapping(ifaceName, 0).get()));
+ .put(eq(mappingIid(ifaceName, "test-instance")), eq(
+ mapping(ifaceName, 0).get()));
return;
}
fail("WriteFailedException.CreateFailedException was expected");
@@ -194,11 +191,11 @@ public class VxlanGpeCustomizerTest extends WriterCustomizerTest {
final VxlanGpe vxlanGpe = generateVxlanGpe();
whenVxlanGpeAddDelTunnelThenSuccess();
- ContextTestUtils.mockMapping(mappingContext, ifaceName, 1, "test-instance");
+ defineMapping(mappingContext, ifaceName, 1, "test-instance");
customizer.deleteCurrentAttributes(id, vxlanGpe, writeContext);
verifyVxlanGpeDeleteWasInvoked(vxlanGpe);
- verify(mappingContext).delete(eq(getMappingIid(ifaceName, "test-instance")));
+ verify(mappingContext).delete(eq(mappingIid(ifaceName, "test-instance")));
}
@Test
@@ -206,14 +203,14 @@ public class VxlanGpeCustomizerTest extends WriterCustomizerTest {
final VxlanGpe vxlanGpe = generateVxlanGpe();
whenVxlanGpeAddDelTunnelThenFailure();
- ContextTestUtils.mockMapping(mappingContext, ifaceName, 1, "test-instance");
+ defineMapping(mappingContext, ifaceName, 1, "test-instance");
try {
customizer.deleteCurrentAttributes(id, vxlanGpe, writeContext);
} catch (WriteFailedException.DeleteFailedException e) {
assertTrue(e.getCause() instanceof VppBaseCallException);
verifyVxlanGpeDeleteWasInvoked(vxlanGpe);
- verify(mappingContext, times(0)).delete(eq(getMappingIid(ifaceName, "test-instance")));
+ verify(mappingContext, times(0)).delete(eq(mappingIid(ifaceName, "test-instance")));
return;
}
fail("WriteFailedException.DeleteFailedException was expected");
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/ip/Ipv4AddressCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/ip/Ipv4AddressCustomizerTest.java
index 7b1fb53e0..56430cd46 100644
--- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/ip/Ipv4AddressCustomizerTest.java
+++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/ip/Ipv4AddressCustomizerTest.java
@@ -30,7 +30,6 @@ import static org.mockito.Mockito.when;
import com.google.common.base.Optional;
import io.fd.honeycomb.translate.v3po.interfaces.ip.subnet.validation.SubnetValidationException;
import io.fd.honeycomb.translate.v3po.interfaces.ip.subnet.validation.SubnetValidator;
-import io.fd.honeycomb.translate.v3po.test.ContextTestUtils;
import io.fd.honeycomb.translate.v3po.util.NamingContext;
import io.fd.honeycomb.translate.write.WriteFailedException;
import io.fd.honeycomb.vpp.test.write.WriterCustomizerTest;
@@ -114,7 +113,7 @@ public class Ipv4AddressCustomizerTest extends WriterCustomizerTest {
PrefixLength length = new PrefixLengthBuilder().setPrefixLength(new Integer(24).shortValue()).build();
Address data = new AddressBuilder().setIp(noZoneIp).setSubnet(length).build();
- ContextTestUtils.mockMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME);
+ defineMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME);
whenSwInterfaceAddDelAddressThenSuccess();
customizer.writeCurrentAttributes(id, data, writeContext);
@@ -132,7 +131,7 @@ public class Ipv4AddressCustomizerTest extends WriterCustomizerTest {
PrefixLength length = new PrefixLengthBuilder().setPrefixLength(new Integer(24).shortValue()).build();
Address data = new AddressBuilder().setIp(noZoneIp).setSubnet(length).build();
- ContextTestUtils.mockMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME);
+ defineMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME);
whenSwInterfaceAddDelAddressThenFailure();
try {
@@ -166,7 +165,7 @@ public class Ipv4AddressCustomizerTest extends WriterCustomizerTest {
doReturn(Optional.of(new Ipv4Builder().setAddress(addressList).build())).when(writeContext)
.readAfter(argThat(matchInstanceIdentifier(Ipv4.class)));
- ContextTestUtils.mockMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME);
+ defineMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME);
try {
customizer.writeCurrentAttributes(id, data, writeContext);
@@ -210,7 +209,7 @@ public class Ipv4AddressCustomizerTest extends WriterCustomizerTest {
PrefixLength length = new PrefixLengthBuilder().setPrefixLength(new Integer(24).shortValue()).build();
Address data = new AddressBuilder().setIp(noZoneIp).setSubnet(length).build();
- ContextTestUtils.mockMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME);
+ defineMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME);
whenSwInterfaceAddDelAddressThenSuccess();
customizer.deleteCurrentAttributes(id, data, writeContext);
@@ -227,7 +226,7 @@ public class Ipv4AddressCustomizerTest extends WriterCustomizerTest {
PrefixLength length = new PrefixLengthBuilder().setPrefixLength(new Integer(24).shortValue()).build();
Address data = new AddressBuilder().setIp(noZoneIp).setSubnet(length).build();
- ContextTestUtils.mockMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME);
+ defineMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME);
whenSwInterfaceAddDelAddressThenFailure();
try {
@@ -250,7 +249,7 @@ public class Ipv4AddressCustomizerTest extends WriterCustomizerTest {
Netmask subnet = new NetmaskBuilder().setNetmask(new DottedQuad(stringMask)).build();
Address data = new AddressBuilder().setIp(noZoneIp).setSubnet(subnet).build();
- ContextTestUtils.mockMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME);
+ defineMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME);
whenSwInterfaceAddDelAddressThenSuccess();
customizer.writeCurrentAttributes(id, data, writeContext);
@@ -268,7 +267,7 @@ public class Ipv4AddressCustomizerTest extends WriterCustomizerTest {
Netmask subnet = new NetmaskBuilder().setNetmask(new DottedQuad(stringMask)).build();
Address data = new AddressBuilder().setIp(noZoneIp).setSubnet(subnet).build();
- ContextTestUtils.mockMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME);
+ defineMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME);
whenSwInterfaceAddDelAddressThenSuccess();
customizer.writeCurrentAttributes(id, data, writeContext);
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/ip/Ipv4NeighbourCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/ip/Ipv4NeighbourCustomizerTest.java
index 416468300..e9acdbe88 100644
--- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/ip/Ipv4NeighbourCustomizerTest.java
+++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/ip/Ipv4NeighbourCustomizerTest.java
@@ -23,7 +23,6 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import com.google.common.io.BaseEncoding;
-import io.fd.honeycomb.translate.v3po.test.ContextTestUtils;
import io.fd.honeycomb.translate.v3po.util.Ipv4Translator;
import io.fd.honeycomb.translate.v3po.util.NamingContext;
import io.fd.honeycomb.translate.write.WriteFailedException;
@@ -56,7 +55,7 @@ public class Ipv4NeighbourCustomizerTest extends WriterCustomizerTest implements
@Before
public void init() {
- ContextTestUtils.mockMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME);
+ defineMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME);
customizer = new Ipv4NeighbourCustomizer(api, new NamingContext("prefix", IFC_CTX_NAME));
requestCaptor = ArgumentCaptor.forClass(IpNeighborAddDel.class);
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/AclCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/AclCustomizerTest.java
index b2a76c5c0..00dadddb1 100644
--- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/AclCustomizerTest.java
+++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/AclCustomizerTest.java
@@ -22,7 +22,6 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
-import io.fd.honeycomb.translate.v3po.test.ContextTestUtils;
import io.fd.honeycomb.translate.v3po.util.NamingContext;
import io.fd.honeycomb.translate.v3po.vppclassifier.VppClassifierContextManager;
import io.fd.honeycomb.vpp.test.read.ReaderCustomizerTest;
@@ -61,7 +60,7 @@ public class AclCustomizerTest extends ReaderCustomizerTest<Acl, AclBuilder> {
@Override
public void setUp() {
interfaceContext = new NamingContext("generatedIfaceName", IFC_CTX_NAME);
- ContextTestUtils.mockMapping(mappingContext, IF_NAME, IF_INDEX, IFC_CTX_NAME);
+ defineMapping(mappingContext, IF_NAME, IF_INDEX, IFC_CTX_NAME);
}
@Override
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/GreCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/GreCustomizerTest.java
index 0728a5a2a..e62edadef 100644
--- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/GreCustomizerTest.java
+++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/GreCustomizerTest.java
@@ -26,7 +26,6 @@ import static org.mockito.Mockito.verifyZeroInteractions;
import com.google.common.collect.Lists;
import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
-import io.fd.honeycomb.translate.v3po.test.ContextTestUtils;
import io.fd.honeycomb.translate.v3po.util.NamingContext;
import io.fd.honeycomb.vpp.test.read.ReaderCustomizerTest;
import java.net.InetAddress;
@@ -65,7 +64,7 @@ public class GreCustomizerTest extends ReaderCustomizerTest<Gre, GreBuilder> {
@Override
public void setUp() throws UnknownHostException, VppInvocationException {
interfacesContext = new NamingContext("gre-tunnel", IFC_CTX_NAME);
- ContextTestUtils.mockMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME);
+ defineMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME);
final SwInterfaceDetails v = new SwInterfaceDetails();
v.interfaceName = "gre-tunnel4".getBytes();
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/InterfaceCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/InterfaceCustomizerTest.java
index 5c6f88abd..94dfd077a 100644
--- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/InterfaceCustomizerTest.java
+++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/InterfaceCustomizerTest.java
@@ -28,7 +28,6 @@ import static org.mockito.Mockito.when;
import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
import io.fd.honeycomb.translate.v3po.DisabledInterfacesManager;
-import io.fd.honeycomb.translate.v3po.test.ContextTestUtils;
import io.fd.honeycomb.translate.v3po.util.NamingContext;
import io.fd.honeycomb.vpp.test.read.ListReaderCustomizerTest;
import java.util.Arrays;
@@ -70,9 +69,9 @@ public class InterfaceCustomizerTest extends
@Override
public void setUp() {
interfacesContext = new NamingContext("generatedIfaceName", IFC_CTX_NAME);
- ContextTestUtils.mockMapping(mappingContext, IFACE0_NAME, IFACE0_ID, IFC_CTX_NAME);
- ContextTestUtils.mockMapping(mappingContext, IFACE1_NAME, IFACE1_ID, IFC_CTX_NAME);
- ContextTestUtils.mockMapping(mappingContext, SUB_IFACE_NAME, SUB_IFACE_ID, IFC_CTX_NAME);
+ defineMapping(mappingContext, IFACE0_NAME, IFACE0_ID, IFC_CTX_NAME);
+ defineMapping(mappingContext, IFACE1_NAME, IFACE1_ID, IFC_CTX_NAME);
+ defineMapping(mappingContext, SUB_IFACE_NAME, SUB_IFACE_ID, IFC_CTX_NAME);
}
@Override
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/L2CustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/L2CustomizerTest.java
index 29f0d0eb7..6be759bc5 100644
--- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/L2CustomizerTest.java
+++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/L2CustomizerTest.java
@@ -22,7 +22,6 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
-import io.fd.honeycomb.translate.v3po.test.ContextTestUtils;
import io.fd.honeycomb.translate.v3po.util.NamingContext;
import io.fd.honeycomb.vpp.test.read.ReaderCustomizerTest;
import java.util.Collections;
@@ -118,8 +117,8 @@ public class L2CustomizerTest extends ReaderCustomizerTest<L2, L2Builder> {
final int bdId = 1;
final String bdName = "bd001";
final String ifName = "eth0.sub0";
- ContextTestUtils.mockMapping(mappingContext, ifName, ifId, IFC_CTX_NAME);
- ContextTestUtils.mockMapping(mappingContext, bdName, bdId, BD_CTX_NAME);
+ defineMapping(mappingContext, ifName, ifId, IFC_CTX_NAME);
+ defineMapping(mappingContext, bdName, bdId, BD_CTX_NAME);
final SwInterfaceDetails ifaceDetails = new SwInterfaceDetails();
ifaceDetails.subId = ifId;
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/RewriteCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/RewriteCustomizerTest.java
index 432469ddc..ad2d4f6ce 100644
--- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/RewriteCustomizerTest.java
+++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/RewriteCustomizerTest.java
@@ -22,7 +22,6 @@ import static org.mockito.Mockito.verify;
import io.fd.honeycomb.translate.read.ReadFailedException;
import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
-import io.fd.honeycomb.translate.v3po.test.ContextTestUtils;
import io.fd.honeycomb.vpp.test.read.ReaderCustomizerTest;
import io.fd.honeycomb.translate.v3po.util.NamingContext;
import io.fd.honeycomb.translate.v3po.util.TagRewriteOperation;
@@ -68,7 +67,7 @@ public class RewriteCustomizerTest extends ReaderCustomizerTest<Rewrite, Rewrite
@Override
public void setUp() {
interfacesContext = new NamingContext("generatedIfaceName", IFC_CTX_NAME);
- ContextTestUtils.mockMapping(mappingContext, VLAN_IF_NAME, VLAN_IF_INDEX, IFC_CTX_NAME);
+ defineMapping(mappingContext, VLAN_IF_NAME, VLAN_IF_INDEX, IFC_CTX_NAME);
}
@Override
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/SubInterfaceCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/SubInterfaceCustomizerTest.java
index 0d0a2cc83..74580bb73 100644
--- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/SubInterfaceCustomizerTest.java
+++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/SubInterfaceCustomizerTest.java
@@ -25,7 +25,6 @@ import static org.mockito.Mockito.when;
import io.fd.honeycomb.translate.read.ReadFailedException;
import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
-import io.fd.honeycomb.translate.v3po.test.ContextTestUtils;
import io.fd.honeycomb.translate.v3po.util.NamingContext;
import io.fd.honeycomb.vpp.test.read.ListReaderCustomizerTest;
import java.util.Collections;
@@ -70,8 +69,8 @@ public class SubInterfaceCustomizerTest extends
@Override
public void setUp() {
interfacesContext = new NamingContext("generatedIfaceName", IFC_CTX_NAME);
- ContextTestUtils.mockMapping(mappingContext, SUPER_IF_NAME, SUPER_IF_INDEX, IFC_CTX_NAME);
- ContextTestUtils.mockMapping(mappingContext, VLAN_IF_NAME, VLAN_IF_INDEX, IFC_CTX_NAME);
+ defineMapping(mappingContext, SUPER_IF_NAME, SUPER_IF_INDEX, IFC_CTX_NAME);
+ defineMapping(mappingContext, VLAN_IF_NAME, VLAN_IF_INDEX, IFC_CTX_NAME);
}
@Override
@@ -101,8 +100,8 @@ public class SubInterfaceCustomizerTest extends
ifaceDetails.subId = VLAN_IF_ID;
ifaceDetails.interfaceName = VLAN_IF_NAME.getBytes();
ifaceDetails.subDot1Ad = 1;
- ContextTestUtils.mockMapping(mappingContext, SUPER_IF_NAME, SUPER_IF_INDEX, IFC_CTX_NAME);
- ContextTestUtils.mockMapping(mappingContext, VLAN_IF_NAME, VLAN_IF_INDEX, IFC_CTX_NAME);
+ defineMapping(mappingContext, SUPER_IF_NAME, SUPER_IF_INDEX, IFC_CTX_NAME);
+ defineMapping(mappingContext, VLAN_IF_NAME, VLAN_IF_INDEX, IFC_CTX_NAME);
ifaceDetails.subNumberOfTags = 2;
ifaceDetails.subOuterVlanIdAny = 1;
ifaceDetails.subInnerVlanIdAny = 1;
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/VxlanCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/VxlanCustomizerTest.java
index e71441333..4bab8fcfa 100644
--- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/VxlanCustomizerTest.java
+++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/VxlanCustomizerTest.java
@@ -26,7 +26,6 @@ import static org.mockito.Mockito.verifyZeroInteractions;
import com.google.common.collect.Lists;
import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
-import io.fd.honeycomb.translate.v3po.test.ContextTestUtils;
import io.fd.honeycomb.translate.v3po.util.NamingContext;
import io.fd.honeycomb.vpp.test.read.ReaderCustomizerTest;
import java.net.InetAddress;
@@ -65,7 +64,7 @@ public class VxlanCustomizerTest extends ReaderCustomizerTest<Vxlan, VxlanBuilde
@Override
public void setUp() throws UnknownHostException, VppInvocationException {
interfacesContext = new NamingContext("vxlan-tunnel", IFC_CTX_NAME);
- ContextTestUtils.mockMapping(mappingContext, IF_NAME, IF_INDEX, IFC_CTX_NAME);
+ defineMapping(mappingContext, IF_NAME, IF_INDEX, IFC_CTX_NAME);
final SwInterfaceDetails v = new SwInterfaceDetails();
v.interfaceName = "vxlan-tunnel4".getBytes();
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/VxlanGpeCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/VxlanGpeCustomizerTest.java
index e40962da3..19b3be862 100644
--- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/VxlanGpeCustomizerTest.java
+++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/VxlanGpeCustomizerTest.java
@@ -26,7 +26,6 @@ import static org.mockito.Mockito.verifyZeroInteractions;
import com.google.common.collect.Lists;
import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
-import io.fd.honeycomb.translate.v3po.test.ContextTestUtils;
import io.fd.honeycomb.translate.v3po.util.NamingContext;
import io.fd.honeycomb.vpp.test.read.ReaderCustomizerTest;
import java.net.InetAddress;
@@ -65,7 +64,7 @@ public class VxlanGpeCustomizerTest extends ReaderCustomizerTest<VxlanGpe, Vxlan
@Override
public void setUp() throws UnknownHostException, VppBaseCallException {
interfacesContext = new NamingContext("vxlan_gpe_inf", IFC_CTX_NAME);
- ContextTestUtils.mockMapping(mappingContext, IF_NAME, IF_INDEX, IFC_CTX_NAME);
+ defineMapping(mappingContext, IF_NAME, IF_INDEX, IFC_CTX_NAME);
final SwInterfaceDetails v = new SwInterfaceDetails();
v.interfaceName = "vxlan_gpe_inf2".getBytes();
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/ip/Ipv4AddressCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/ip/Ipv4AddressCustomizerTest.java
index d351d2402..fc189d399 100644
--- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/ip/Ipv4AddressCustomizerTest.java
+++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/ip/Ipv4AddressCustomizerTest.java
@@ -27,7 +27,6 @@ import com.google.common.collect.ImmutableList;
import io.fd.honeycomb.translate.ModificationCache;
import io.fd.honeycomb.translate.read.ReadFailedException;
import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
-import io.fd.honeycomb.translate.v3po.test.ContextTestUtils;
import io.fd.honeycomb.translate.v3po.util.Ipv4Translator;
import io.fd.honeycomb.translate.v3po.util.NamingContext;
import io.fd.honeycomb.vpp.test.read.ListReaderCustomizerTest;
@@ -73,8 +72,8 @@ public class Ipv4AddressCustomizerTest extends ListReaderCustomizerTest<Address,
@Override
public void setUp() {
interfacesContext = new NamingContext("generatedIfaceName", IFC_CTX_NAME);
- ContextTestUtils.mockMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME);
- ContextTestUtils.mockMapping(mappingContext, IFACE_2_NAME, IFACE_2_ID, IFC_CTX_NAME);
+ defineMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME);
+ defineMapping(mappingContext, IFACE_2_NAME, IFACE_2_ID, IFC_CTX_NAME);
}
@Override
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/notification/InterfaceChangeNotificationProducerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/notification/InterfaceChangeNotificationProducerTest.java
index a227602b4..96acb9979 100644
--- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/notification/InterfaceChangeNotificationProducerTest.java
+++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/notification/InterfaceChangeNotificationProducerTest.java
@@ -23,7 +23,7 @@ import static org.mockito.Mockito.verify;
import io.fd.honeycomb.notification.NotificationCollector;
import io.fd.honeycomb.translate.MappingContext;
-import io.fd.honeycomb.translate.v3po.test.ContextTestUtils;
+import io.fd.honeycomb.vpp.test.util.NamingContextHelper;
import io.fd.honeycomb.translate.v3po.util.NamingContext;
import io.fd.honeycomb.vpp.test.util.FutureProducer;
import org.junit.Before;
@@ -40,7 +40,7 @@ import org.openvpp.jvpp.core.dto.WantInterfaceEventsReply;
import org.openvpp.jvpp.core.future.FutureJVppCore;
import org.openvpp.jvpp.core.notification.CoreNotificationRegistry;
-public class InterfaceChangeNotificationProducerTest implements FutureProducer {
+public class InterfaceChangeNotificationProducerTest implements FutureProducer, NamingContextHelper {
private static final String IFC_CTX_NAME = "ifc-test-instance";
private static final String IFACE_NAME = "eth0";
@@ -67,7 +67,7 @@ public class InterfaceChangeNotificationProducerTest implements FutureProducer {
callbackArgumentCaptor = ArgumentCaptor.forClass(SwInterfaceSetFlagsNotificationCallback.class);
doReturn(notificationListenerReg).when(notificationRegistry).registerSwInterfaceSetFlagsNotificationCallback(
callbackArgumentCaptor.capture());
- ContextTestUtils.mockMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME);
+ defineMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME);
doReturn(future(new WantInterfaceEventsReply())).when(jVpp).wantInterfaceEvents(any(WantInterfaceEvents.class));
}
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/test/ContextTestUtils.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/test/ContextTestUtils.java
deleted file mode 100644
index 9bfcd4d82..000000000
--- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/test/ContextTestUtils.java
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * Copyright (c) 2016 Cisco and/or its affiliates.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at:
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package io.fd.honeycomb.translate.v3po.test;
-
-import static org.mockito.Mockito.doReturn;
-
-import com.google.common.base.Optional;
-import com.google.common.collect.Lists;
-import io.fd.honeycomb.translate.MappingContext;
-import java.util.List;
-import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.Contexts;
-import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.contexts.NamingContextKey;
-import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.contexts.naming.context.Mappings;
-import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.contexts.naming.context.MappingsBuilder;
-import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.contexts.naming.context.mappings.Mapping;
-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.honeycomb.params.xml.ns.yang.naming.context.rev160513.contexts.naming.context.mappings.MappingKey;
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
-
-public class ContextTestUtils {
-
- public static Optional<Mapping> getMapping(final String name, final int index) {
- return Optional.of(new MappingBuilder().setName(name).setIndex(index).build());
- }
-
- public static KeyedInstanceIdentifier<Mapping, MappingKey> getMappingIid(final String name,
- final String namingContextName) {
- return InstanceIdentifier.create(Contexts.class).child(
- org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.contexts.NamingContext.class,
- new NamingContextKey(namingContextName)).child(Mappings.class).child(Mapping.class, new MappingKey(name));
- }
-
- private static List<Mapping> getMappingList(final MappingContext mappingContext, final InstanceIdentifier<Mappings> mappingsIid) {
- final Optional<Mappings> previousMappings = mappingContext.read(mappingsIid);
- final MappingsBuilder mappingsBuilder;
- if (previousMappings != null && previousMappings.isPresent()) {
- mappingsBuilder = new MappingsBuilder(previousMappings.get());
- } else {
- mappingsBuilder = new MappingsBuilder();
- mappingsBuilder.setMapping(Lists.newArrayList());
- }
-
- return mappingsBuilder.getMapping();
- }
-
- public static void mockMapping(final MappingContext mappingContext, final String name, final int id,
- final String namingContextName) {
- final InstanceIdentifier<Mappings> mappingsIid =
- getMappingIid(name, namingContextName).firstIdentifierOf(Mappings.class);
-
- final Optional<Mapping> singleMapping = getMapping(name, id);
- final List<Mapping> mappingList = getMappingList(mappingContext, mappingsIid);
- mappingList.add(singleMapping.get());
-
- doReturn(Optional.of(new MappingsBuilder().setMapping(mappingList).build()))
- .when(mappingContext).read(mappingsIid);
- doReturn(singleMapping).when(mappingContext).read(getMappingIid(name, namingContextName));
- }
-
- public static void mockEmptyMapping(final MappingContext mappingContext, final String name,
- final String namingContextName) {
- final InstanceIdentifier<Mappings> mappingsIid =
- getMappingIid(name, namingContextName).firstIdentifierOf(Mappings.class);
-
- final List<Mapping> mappingList = getMappingList(mappingContext, mappingsIid);
-
- doReturn(Optional.of(new MappingsBuilder().setMapping(mappingList).build()))
- .when(mappingContext).read(mappingsIid);
- doReturn(Optional.absent()).when(mappingContext).read(getMappingIid(name, namingContextName));
- }
-}
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/vpp/ArpTerminationTableEntryCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/vpp/ArpTerminationTableEntryCustomizerTest.java
index 4a38101af..8c2082210 100644
--- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/vpp/ArpTerminationTableEntryCustomizerTest.java
+++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/vpp/ArpTerminationTableEntryCustomizerTest.java
@@ -25,7 +25,6 @@ import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
-import io.fd.honeycomb.translate.v3po.test.ContextTestUtils;
import io.fd.honeycomb.translate.v3po.util.NamingContext;
import io.fd.honeycomb.translate.write.WriteFailedException;
import io.fd.honeycomb.vpp.test.write.WriterCustomizerTest;
@@ -75,8 +74,8 @@ public class ArpTerminationTableEntryCustomizerTest extends WriterCustomizerTest
entry = generateArpEntry(ipAddress, physAddress);
id = getArpEntryId(ipAddress, physAddress);
- ContextTestUtils.mockMapping(mappingContext, BD_NAME, BD_ID, BD_CTX_NAME);
- ContextTestUtils.mockMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME);
+ defineMapping(mappingContext, BD_NAME, BD_ID, BD_CTX_NAME);
+ defineMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME);
}
private static InstanceIdentifier<ArpTerminationTableEntry> getArpEntryId(final IpAddress ipAddress,
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/vpp/BridgeDomainCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/vpp/BridgeDomainCustomizerTest.java
index f41448bf0..43b9c37fa 100644
--- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/vpp/BridgeDomainCustomizerTest.java
+++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/vpp/BridgeDomainCustomizerTest.java
@@ -23,7 +23,6 @@ import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
-import io.fd.honeycomb.translate.v3po.test.ContextTestUtils;
import io.fd.honeycomb.translate.v3po.util.ByteDataTranslator;
import io.fd.honeycomb.translate.v3po.util.NamingContext;
import io.fd.honeycomb.translate.write.WriteFailedException;
@@ -120,15 +119,14 @@ public class BridgeDomainCustomizerTest extends WriterCustomizerTest implements
final int bdId = 1;
final String bdName = "bd1";
final BridgeDomain bd = generateBridgeDomain(bdName);
- ContextTestUtils.mockEmptyMapping(mappingContext, bdName, BD_CTX_NAME);
+ noMappingDefined(mappingContext, bdName, BD_CTX_NAME);
whenBridgeDomainAddDelThenSuccess();
customizer.writeCurrentAttributes(bdIdentifierForName(bdName), bd, writeContext);
verifyBridgeDomainAddOrUpdateWasInvoked(bd, bdId);
- verify(mappingContext).put(
- ContextTestUtils.getMappingIid(bdName, BD_CTX_NAME), ContextTestUtils.getMapping(bdName, bdId).get());
+ verify(mappingContext).put(mappingIid(bdName, BD_CTX_NAME), mapping(bdName, bdId).get());
}
@Test
@@ -136,15 +134,14 @@ public class BridgeDomainCustomizerTest extends WriterCustomizerTest implements
final int bdId = 1;
final String bdName = "bd1";
final BridgeDomain bd = generateBridgeDomain(bdName);
- ContextTestUtils.mockMapping(mappingContext, bdName, bdId, BD_CTX_NAME);
+ defineMapping(mappingContext, bdName, bdId, BD_CTX_NAME);
whenBridgeDomainAddDelThenSuccess();
customizer.writeCurrentAttributes(bdIdentifierForName(bdName), bd, writeContext);
verifyBridgeDomainAddOrUpdateWasInvoked(bd, bdId);
- verify(mappingContext).put(
- ContextTestUtils.getMappingIid(bdName, BD_CTX_NAME), ContextTestUtils.getMapping(bdName, bdId).get());
+ verify(mappingContext).put(mappingIid(bdName, BD_CTX_NAME), mapping(bdName, bdId).get());
}
@Test
@@ -152,7 +149,7 @@ public class BridgeDomainCustomizerTest extends WriterCustomizerTest implements
final int bdId = 1;
final String bdName = "bd1";
final BridgeDomain bd = generateBridgeDomain(bdName);
- ContextTestUtils.mockEmptyMapping(mappingContext, bdName, BD_CTX_NAME);
+ noMappingDefined(mappingContext, bdName, BD_CTX_NAME);
whenBridgeDomainAddDelThenFailure();
@@ -170,7 +167,7 @@ public class BridgeDomainCustomizerTest extends WriterCustomizerTest implements
final int bdId = 1;
final String bdName = "bd1";
final BridgeDomain bd = generateBridgeDomain(bdName);
- ContextTestUtils.mockMapping(mappingContext, bdName, bdId, BD_CTX_NAME);
+ defineMapping(mappingContext, bdName, bdId, BD_CTX_NAME);
whenBridgeDomainAddDelThenSuccess();
@@ -183,7 +180,7 @@ public class BridgeDomainCustomizerTest extends WriterCustomizerTest implements
public void testDeleteUnknownBridgeDomain() throws Exception {
final String bdName = "bd1";
final BridgeDomain bd = generateBridgeDomain("bd1");
- ContextTestUtils.mockEmptyMapping(mappingContext, bdName, BD_CTX_NAME);
+ noMappingDefined(mappingContext, bdName, BD_CTX_NAME);
try {
customizer.deleteCurrentAttributes(bdIdentifierForName(bdName), bd, writeContext);
@@ -199,7 +196,7 @@ public class BridgeDomainCustomizerTest extends WriterCustomizerTest implements
final int bdId = 1;
final String bdName = "bd1";
final BridgeDomain bd = generateBridgeDomain(bdName);
- ContextTestUtils.mockMapping(mappingContext, bdName, bdId, BD_CTX_NAME);
+ defineMapping(mappingContext, bdName, bdId, BD_CTX_NAME);
whenBridgeDomainAddDelThenFailure();
@@ -217,7 +214,7 @@ public class BridgeDomainCustomizerTest extends WriterCustomizerTest implements
public void testUpdateBridgeDomain() throws Exception {
final int bdId = 1;
final String bdName = "bd1";
- ContextTestUtils.mockMapping(mappingContext, bdName, bdId, BD_CTX_NAME);
+ defineMapping(mappingContext, bdName, bdId, BD_CTX_NAME);
final byte arpTermBefore = 1;
final byte floodBefore = 1;
@@ -244,7 +241,7 @@ public class BridgeDomainCustomizerTest extends WriterCustomizerTest implements
final String bdName = "bd1";
final BridgeDomain bdBefore = generateBridgeDomain(bdName, 0, 1, 0, 1, 0);
final BridgeDomain bdAfter = generateBridgeDomain(bdName, 1, 1, 0, 1, 0);
- ContextTestUtils.mockEmptyMapping(mappingContext, bdName, BD_CTX_NAME);
+ noMappingDefined(mappingContext, bdName, BD_CTX_NAME);
try {
customizer
@@ -263,7 +260,7 @@ public class BridgeDomainCustomizerTest extends WriterCustomizerTest implements
final String bdName = "bd1";
final BridgeDomain bdBefore = generateBridgeDomain(bdName, 0, 1, 0, 1, 0);
final BridgeDomain bdAfter = generateBridgeDomain(bdName, 1, 1, 0, 1, 0);
- ContextTestUtils.mockMapping(mappingContext, bdName, bdId, BD_CTX_NAME);
+ defineMapping(mappingContext, bdName, bdId, BD_CTX_NAME);
whenBridgeDomainAddDelThenFailure();
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/vpp/L2FibEntryCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/vpp/L2FibEntryCustomizerTest.java
index 174e27215..e52cc1783 100644
--- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/vpp/L2FibEntryCustomizerTest.java
+++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/vpp/L2FibEntryCustomizerTest.java
@@ -24,7 +24,6 @@ import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
-import io.fd.honeycomb.translate.v3po.test.ContextTestUtils;
import io.fd.honeycomb.translate.v3po.util.NamingContext;
import io.fd.honeycomb.translate.write.WriteFailedException;
import io.fd.honeycomb.vpp.test.write.WriterCustomizerTest;
@@ -58,8 +57,8 @@ public class L2FibEntryCustomizerTest extends WriterCustomizerTest {
@Override
public void setUp() throws Exception {
- ContextTestUtils.mockMapping(mappingContext, BD_NAME, BD_ID, BD_CTX_NAME);
- ContextTestUtils.mockMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME);
+ defineMapping(mappingContext, BD_NAME, BD_ID, BD_CTX_NAME);
+ defineMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME);
customizer = new L2FibEntryCustomizer(
api,
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/vppstate/L2FibEntryCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/vppstate/L2FibEntryCustomizerTest.java
index 953332da7..f837717c7 100644
--- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/vppstate/L2FibEntryCustomizerTest.java
+++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/vppstate/L2FibEntryCustomizerTest.java
@@ -23,7 +23,6 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
-import io.fd.honeycomb.translate.v3po.test.ContextTestUtils;
import io.fd.honeycomb.translate.v3po.util.NamingContext;
import io.fd.honeycomb.vpp.test.read.ListReaderCustomizerTest;
import java.util.Collections;
@@ -64,7 +63,7 @@ public class L2FibEntryCustomizerTest extends ListReaderCustomizerTest<L2FibEntr
@Override
public void setUp() {
bdContext = new NamingContext("generatedBdName", BD_CTX_NAME);
- ContextTestUtils.mockMapping(mappingContext, BD_NAME, BD_ID, BD_CTX_NAME);
+ defineMapping(mappingContext, BD_NAME, BD_ID, BD_CTX_NAME);
interfacesContext = new NamingContext("generatedIfaceName", IFC_CTX_NAME);
}
@@ -97,7 +96,7 @@ public class L2FibEntryCustomizerTest extends ListReaderCustomizerTest<L2FibEntr
public void testRead() throws Exception {
final long address_vpp = 0x0000010203040506L;
final PhysAddress address = new PhysAddress("01:02:03:04:05:06");
- ContextTestUtils.mockMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME);
+ defineMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME);
whenL2FibTableDumpThenReturn(Collections.singletonList(generateL2FibEntry(address_vpp)));
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/vppstate/VppStateTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/vppstate/VppStateTest.java
index b8013b59e..8cd8edad3 100644
--- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/vppstate/VppStateTest.java
+++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/vppstate/VppStateTest.java
@@ -36,7 +36,7 @@ import io.fd.honeycomb.translate.read.ReadContext;
import io.fd.honeycomb.translate.read.ReadFailedException;
import io.fd.honeycomb.translate.read.registry.ReaderRegistry;
import io.fd.honeycomb.translate.util.read.registry.CompositeReaderRegistryBuilder;
-import io.fd.honeycomb.translate.v3po.test.ContextTestUtils;
+import io.fd.honeycomb.vpp.test.util.NamingContextHelper;
import io.fd.honeycomb.translate.v3po.util.NamingContext;
import io.fd.honeycomb.vpp.test.util.FutureProducer;
import java.util.Arrays;
@@ -72,7 +72,7 @@ import org.openvpp.jvpp.core.dto.ShowVersion;
import org.openvpp.jvpp.core.dto.ShowVersionReply;
import org.openvpp.jvpp.core.future.FutureJVppCore;
-public class VppStateTest implements FutureProducer {
+public class VppStateTest implements FutureProducer, NamingContextHelper {
private static final String BD_CTX_NAME = "bd-test-instance";
@Mock
@@ -226,7 +226,7 @@ public class VppStateTest implements FutureProducer {
bd.bdId = 0;
final String bdName = "bdn1";
mockBdMapping(bd, bdName);
- ContextTestUtils.mockMapping(mappingContext, "eth1", 0, "ifc-test-instance");
+ defineMapping(mappingContext, "eth1", 0, "ifc-test-instance");
whenBridgeDomainDumpThenReturn(Collections.singletonList(bd));
final L2FibTableEntry l2FibEntry = new L2FibTableEntry();
@@ -253,7 +253,7 @@ public class VppStateTest implements FutureProducer {
}
private void mockBdMapping(final BridgeDomainDetails bd, final String bdName) {
- ContextTestUtils.mockMapping(mappingContext, bdName, bd.bdId, BD_CTX_NAME);
+ defineMapping(mappingContext, bdName, bd.bdId, BD_CTX_NAME);
}
@Test
@@ -301,7 +301,7 @@ public class VppStateTest implements FutureProducer {
@Test(expected = ReadFailedException.class)
public void testReadBridgeDomainNotExisting() throws Exception {
final String nonExistingBdName = "NOT EXISTING";
- ContextTestUtils.mockEmptyMapping(mappingContext, nonExistingBdName, BD_CTX_NAME);
+ noMappingDefined(mappingContext, nonExistingBdName, BD_CTX_NAME);
readerRegistry.read(InstanceIdentifier.create(VppState.class).child(BridgeDomains.class).child(
BridgeDomain.class, new BridgeDomainKey(nonExistingBdName)), ctx);
diff --git a/vpp-common/vpp-translate-test/pom.xml b/vpp-common/vpp-translate-test/pom.xml
index bef9a3014..4a28d8c1b 100644
--- a/vpp-common/vpp-translate-test/pom.xml
+++ b/vpp-common/vpp-translate-test/pom.xml
@@ -31,6 +31,11 @@
<dependencies>
<dependency>
+ <groupId>io.fd.honeycomb.vpp</groupId>
+ <artifactId>naming-context-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
<groupId>io.fd.honeycomb</groupId>
<artifactId>translate-spi</artifactId>
<version>${project.version}</version>
diff --git a/vpp-common/vpp-translate-test/src/main/java/io/fd/honeycomb/vpp/test/read/ReaderCustomizerTest.java b/vpp-common/vpp-translate-test/src/main/java/io/fd/honeycomb/vpp/test/read/ReaderCustomizerTest.java
index 3637ee2c8..c90504264 100644
--- a/vpp-common/vpp-translate-test/src/main/java/io/fd/honeycomb/vpp/test/read/ReaderCustomizerTest.java
+++ b/vpp-common/vpp-translate-test/src/main/java/io/fd/honeycomb/vpp/test/read/ReaderCustomizerTest.java
@@ -25,6 +25,7 @@ import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
import io.fd.honeycomb.translate.read.ReadContext;
import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
import io.fd.honeycomb.vpp.test.util.FutureProducer;
+import io.fd.honeycomb.vpp.test.util.NamingContextHelper;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
@@ -41,7 +42,8 @@ import org.openvpp.jvpp.core.future.FutureJVppCore;
* @param <D> Specific DataObject derived type (Identifiable), that is handled by this customizer
* @param <B> Specific Builder for handled type (D)
*/
-public abstract class ReaderCustomizerTest<D extends DataObject, B extends Builder<D>> implements FutureProducer {
+public abstract class ReaderCustomizerTest<D extends DataObject, B extends Builder<D>> implements FutureProducer,
+ NamingContextHelper {
@Mock
protected FutureJVppCore api;
@@ -52,7 +54,7 @@ public abstract class ReaderCustomizerTest<D extends DataObject, B extends Build
protected ModificationCache cache;
protected final Class<D> dataObjectClass;
- private ReaderCustomizer<D, B> customizer;
+ protected ReaderCustomizer<D, B> customizer;
protected ReaderCustomizerTest(Class<D> dataObjectClass) {
this.dataObjectClass = dataObjectClass;
diff --git a/vpp-common/vpp-translate-test/src/main/java/io/fd/honeycomb/vpp/test/util/NamingContextHelper.java b/vpp-common/vpp-translate-test/src/main/java/io/fd/honeycomb/vpp/test/util/NamingContextHelper.java
new file mode 100644
index 000000000..85f73fe1e
--- /dev/null
+++ b/vpp-common/vpp-translate-test/src/main/java/io/fd/honeycomb/vpp/test/util/NamingContextHelper.java
@@ -0,0 +1,119 @@
+/*
+ * Copyright (c) 2016 Cisco and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.honeycomb.vpp.test.util;
+
+import static org.mockito.Mockito.doReturn;
+
+import com.google.common.base.Optional;
+import com.google.common.collect.Lists;
+import io.fd.honeycomb.translate.MappingContext;
+import java.util.List;
+import javax.annotation.Nonnull;
+import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.Contexts;
+import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.contexts.NamingContext;
+import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.contexts.NamingContextKey;
+import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.contexts.naming.context.Mappings;
+import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.contexts.naming.context.MappingsBuilder;
+import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.contexts.naming.context.mappings.Mapping;
+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.honeycomb.params.xml.ns.yang.naming.context.rev160513.contexts.naming.context.mappings.MappingKey;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
+
+/**
+ * Utility that helps stubbing {@link io.fd.honeycomb.translate.v3po.util.NamingContext} methods.
+ */
+// TODO(HONEYCOMB-226): the class needs to be refactored or even removed after extracting interface from NamingContext
+public interface NamingContextHelper {
+
+ /**
+ * Creates {@link Mapping} for given data.
+ *
+ * @param name to be mapped
+ * @param index to be mapped
+ * @return name to index mapping
+ */
+ default Optional<Mapping> mapping(@Nonnull final String name, final int index) {
+ return Optional.of(new MappingBuilder().setName(name).setIndex(index).build());
+ }
+
+ /**
+ * Creates {@link KeyedInstanceIdentifier} for {@link Mapping} in {@link NamingContext}.
+ *
+ * @param name name of the mapping
+ * @param namingContextName name of the naming context
+ * @return identifier for the mapping
+ */
+ default KeyedInstanceIdentifier<Mapping, MappingKey> mappingIid(@Nonnull final String name,
+ @Nonnull final String namingContextName) {
+ return InstanceIdentifier.create(Contexts.class).child(NamingContext.class,
+ new NamingContextKey(namingContextName)).child(Mappings.class).child(Mapping.class, new MappingKey(name));
+ }
+
+ /**
+ * Stubs {@link MappingContext#read} to include given mapping in {@link NamingContext}.
+ *
+ * @param mappingContext mock instance of {@link MappingContext}
+ * @param name name of the mapping
+ * @param index index to be mapped
+ * @param namingContextName name of the naming context
+ */
+ default void defineMapping(@Nonnull final MappingContext mappingContext, @Nonnull final String name,
+ final int index, @Nonnull final String namingContextName) {
+ final KeyedInstanceIdentifier<Mapping, MappingKey> mappingIid = mappingIid(name, namingContextName);
+ final InstanceIdentifier<Mappings> mappingsIid = mappingIid.firstIdentifierOf(Mappings.class);
+
+ final Optional<Mapping> singleMapping = mapping(name, index);
+ final List<Mapping> list = Common.getMappingList(mappingContext, mappingsIid);
+ list.add(singleMapping.get());
+
+ doReturn(Optional.of(new MappingsBuilder().setMapping(list).build())).when(mappingContext).read(mappingsIid);
+ doReturn(singleMapping).when(mappingContext).read(mappingIid);
+ }
+
+ /**
+ * Stubs {@link MappingContext#read} for given {@link NamingContext} to return {@link Optional#absent} for provided
+ * name.
+ *
+ * @param mappingContext mock instance of {@link MappingContext}
+ * @param name name of the mapping
+ * @param namingContextName name of the naming context
+ */
+ default void noMappingDefined(@Nonnull final MappingContext mappingContext, @Nonnull final String name,
+ @Nonnull final String namingContextName) {
+ final InstanceIdentifier<Mappings> iid = mappingIid(name, namingContextName).firstIdentifierOf(Mappings.class);
+ final List<Mapping> list = Common.getMappingList(mappingContext, iid);
+
+ doReturn(Optional.of(new MappingsBuilder().setMapping(list).build())).when(mappingContext).read(iid);
+ doReturn(Optional.absent()).when(mappingContext).read(mappingIid(name, namingContextName));
+ }
+
+ final class Common {
+ private static List<Mapping> getMappingList(@Nonnull final MappingContext mappingContext,
+ @Nonnull final InstanceIdentifier<Mappings> mappingsIid) {
+ final Optional<Mappings> previousMappings = mappingContext.read(mappingsIid);
+ final MappingsBuilder mappingsBuilder;
+ if (previousMappings != null && previousMappings.isPresent()) {
+ mappingsBuilder = new MappingsBuilder(previousMappings.get());
+ } else {
+ mappingsBuilder = new MappingsBuilder();
+ mappingsBuilder.setMapping(Lists.newArrayList());
+ }
+ return mappingsBuilder.getMapping();
+ }
+ }
+}
diff --git a/vpp-common/vpp-translate-test/src/main/java/io/fd/honeycomb/vpp/test/write/WriterCustomizerTest.java b/vpp-common/vpp-translate-test/src/main/java/io/fd/honeycomb/vpp/test/write/WriterCustomizerTest.java
index e09d7b617..fe8c8fe42 100644
--- a/vpp-common/vpp-translate-test/src/main/java/io/fd/honeycomb/vpp/test/write/WriterCustomizerTest.java
+++ b/vpp-common/vpp-translate-test/src/main/java/io/fd/honeycomb/vpp/test/write/WriterCustomizerTest.java
@@ -21,6 +21,7 @@ import io.fd.honeycomb.translate.ModificationCache;
import io.fd.honeycomb.translate.spi.write.WriterCustomizer;
import io.fd.honeycomb.translate.write.WriteContext;
import io.fd.honeycomb.vpp.test.util.FutureProducer;
+import io.fd.honeycomb.vpp.test.util.NamingContextHelper;
import org.junit.Before;
import org.mockito.Mock;
import org.mockito.Mockito;
@@ -30,7 +31,8 @@ import org.openvpp.jvpp.core.future.FutureJVppCore;
/**
* Generic test for classes implementing {@link WriterCustomizer} interface.
*/
-public abstract class WriterCustomizerTest implements FutureProducer {
+public abstract class WriterCustomizerTest implements FutureProducer,
+ NamingContextHelper {
@Mock
protected FutureJVppCore api;