summaryrefslogtreecommitdiffstats
path: root/v3po/v3po2vpp/src
diff options
context:
space:
mode:
authorMarek Gradzki <mgradzki@cisco.com>2016-09-18 15:17:02 +0200
committerMaros Marsalek <mmarsale@cisco.com>2016-09-20 15:55:04 +0000
commit7a7a31ae0a390113399119835bdaa3a4ed694170 (patch)
treeea5c6bbf21f5d1829d4d6698dc50cc5f48bc096e /v3po/v3po2vpp/src
parent27eba3a20b98378a07178722606752960978ea5a (diff)
HONEYCOMB-116: refactor v3po tests to use CTU.mockMapping
Change-Id: I72d3a545d66e1280e34beff72adcdf876dae86fd Signed-off-by: Marek Gradzki <mgradzki@cisco.com>
Diffstat (limited to 'v3po/v3po2vpp/src')
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/AclCustomizerTest.java13
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/GreCustomizerTest.java49
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/RewriteCustomizerTest.java46
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/SubInterfaceCustomizerTest.java22
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/TapCustomizerTest.java23
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/VhostUserCustomizerTest.java12
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/VxlanCustomizerTest.java40
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/VxlanGpeCustomizerTest.java44
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/ip/Ipv4NeighbourCustomizerTest.java21
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/AclCustomizerTest.java23
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/GreCustomizerTest.java15
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/InterfaceCustomizerTest.java76
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/L2CustomizerTest.java30
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/RewriteCustomizerTest.java24
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/SubInterfaceCustomizerTest.java32
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/VxlanCustomizerTest.java11
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/VxlanGpeCustomizerTest.java13
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/ip/Ipv4AddressCustomizerTest.java32
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/notification/InterfaceChangeNotificationProducerTest.java30
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/test/ContextTestUtils.java34
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/vpp/BridgeDomainCustomizerTest.java49
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/vpp/BridgeDomainTestUtils.java13
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/vpp/L2FibEntryCustomizerTest.java14
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/vppstate/L2FibEntryCustomizerTest.java4
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/vppstate/VersionCustomizerTest.java8
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/vppstate/VppStateTest.java15
26 files changed, 264 insertions, 429 deletions
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 578b24578..f3cee8127 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
@@ -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 junit.framework.TestCase.assertTrue;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
@@ -26,8 +24,8 @@ import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.verify;
import static org.mockito.MockitoAnnotations.initMocks;
-import com.google.common.base.Optional;
import io.fd.honeycomb.translate.MappingContext;
+import io.fd.honeycomb.translate.v3po.test.ContextTestUtils;
import io.fd.honeycomb.translate.v3po.test.TestHelperUtils;
import io.fd.honeycomb.translate.v3po.util.NamingContext;
import io.fd.honeycomb.translate.v3po.vppclassifier.VppClassifierContextManager;
@@ -39,8 +37,6 @@ import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
-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.MappingKey;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceKey;
@@ -50,7 +46,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces._interface.Acl;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces._interface.AclBuilder;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
import org.openvpp.jvpp.VppBaseCallException;
import org.openvpp.jvpp.core.dto.InputAclSetInterface;
import org.openvpp.jvpp.core.dto.InputAclSetInterfaceReply;
@@ -82,12 +77,10 @@ public class AclCustomizerTest {
public void setUp() throws Exception {
initMocks(this);
interfaceContext = new NamingContext("generatedInterfaceName", IFC_TEST_INSTANCE);
+ ContextTestUtils.mockMapping(mappingContext, IF_NAME, IF_INDEX, IFC_TEST_INSTANCE);
+
doReturn(mappingContext).when(writeContext).getMappingContext();
customizer = new AclCustomizer(api, interfaceContext, classifyTableContext);
-
- final KeyedInstanceIdentifier<Mapping, MappingKey> ifcMappingKey = getMappingIid(IF_NAME, IFC_TEST_INSTANCE);
- final Optional<Mapping> ifcMapping = getMapping(IF_NAME, IF_INDEX);
- doReturn(ifcMapping).when(mappingContext).read(ifcMappingKey);
}
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 58a44d7cf..8eaf2397a 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
@@ -18,7 +18,8 @@ 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 java.util.Collections.singletonList;
+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;
@@ -33,7 +34,6 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.mockito.MockitoAnnotations.initMocks;
-import com.google.common.base.Optional;
import com.google.common.net.InetAddresses;
import io.fd.honeycomb.translate.MappingContext;
import io.fd.honeycomb.translate.ModificationCache;
@@ -50,9 +50,6 @@ import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
-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.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces;
@@ -64,12 +61,17 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.openvpp.jvpp.VppBaseCallException;
import org.openvpp.jvpp.VppInvocationException;
-import org.openvpp.jvpp.core.future.FutureJVppCore;
import org.openvpp.jvpp.core.dto.GreAddDelTunnel;
import org.openvpp.jvpp.core.dto.GreAddDelTunnelReply;
+import org.openvpp.jvpp.core.future.FutureJVppCore;
public class GreCustomizerTest {
+ private static final String IFC_TEST_INSTANCE = "ifc-test-instance";
+ private final String IFACE_NAME = "eth0";
+ private final int IFACE_ID = 1;
+ private InstanceIdentifier<Gre> id = InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(IFACE_NAME))
+ .augmentation(VppInterfaceAugmentation.class).child(Gre.class);
private static final byte ADD_GRE = 1;
private static final byte DEL_GRE = 0;
@@ -81,8 +83,6 @@ public class GreCustomizerTest {
private MappingContext mappingContext;
private GreCustomizer customizer;
- private String ifaceName;
- private InstanceIdentifier<Gre> id;
@Before
public void setUp() throws Exception {
@@ -90,16 +90,12 @@ public class GreCustomizerTest {
InterfaceTypeTestUtils.setupWriteContext(writeContext,
org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.GreTunnel.class);
// TODO HONEYCOMB-116 create base class for tests using vppApi
- NamingContext namingContext = new NamingContext("generateInterfaceNAme", "test-instance");
+ NamingContext namingContext = new NamingContext("generateInterfaceNAme", IFC_TEST_INSTANCE);
final ModificationCache toBeReturned = new ModificationCache();
doReturn(toBeReturned).when(writeContext).getModificationCache();
doReturn(mappingContext).when(writeContext).getMappingContext();
customizer = new GreCustomizer(api, namingContext);
-
- ifaceName = "eth0";
- id = InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(ifaceName))
- .augmentation(VppInterfaceAugmentation.class).child(Gre.class);
}
private void whenGreAddDelTunnelThenSuccess()
@@ -108,6 +104,7 @@ public class GreCustomizerTest {
final CompletableFuture<GreAddDelTunnelReply> replyFuture = mock(CompletableFuture.class);
when(replyCS.toCompletableFuture()).thenReturn(replyFuture);
final GreAddDelTunnelReply reply = new GreAddDelTunnelReply();
+ reply.swIfIndex = IFACE_ID;
when(replyFuture.get(anyLong(), eq(TimeUnit.SECONDS))).thenReturn(reply);
when(api.greAddDelTunnel(any(GreAddDelTunnel.class))).thenReturn(replyCS);
}
@@ -162,12 +159,12 @@ public class GreCustomizerTest {
whenGreAddDelTunnelThenSuccess();
- doReturn(Optional.absent())
- .when(mappingContext).read(getMappingIid(ifaceName, "test-instance").firstIdentifierOf(Mappings.class));
+ mockEmptyMapping(mappingContext, IFACE_NAME, IFC_TEST_INSTANCE);
customizer.writeCurrentAttributes(id, gre, writeContext);
verifyGreAddWasInvoked(gre);
- verify(mappingContext).put(eq(getMappingIid(ifaceName, "test-instance")), eq(getMapping(ifaceName, 0).get()));
+ verify(mappingContext).put(eq(getMappingIid(IFACE_NAME, IFC_TEST_INSTANCE)),
+ eq(getMapping(IFACE_NAME, IFACE_ID).get()));
}
@Test
@@ -175,17 +172,14 @@ public class GreCustomizerTest {
final Gre gre = generateGre();
whenGreAddDelTunnelThenSuccess();
- final Optional<Mapping> ifcMapping = getMapping(ifaceName, 0);
-
- doReturn(Optional.of(new MappingsBuilder().setMapping(singletonList(ifcMapping.get())).build()))
- .when(mappingContext).read(getMappingIid(ifaceName, "test-instance").firstIdentifierOf(Mappings.class));
+ mockMapping(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(ifaceName, "test-instance")));
- verify(mappingContext).put(eq(getMappingIid(ifaceName, "test-instance")), eq(ifcMapping.get()));
+ 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()));
}
@Test
@@ -200,7 +194,8 @@ public class GreCustomizerTest {
assertTrue(e.getCause() instanceof VppBaseCallException);
verifyGreAddWasInvoked(gre);
// Mapping not stored due to failure
- verify(mappingContext, times(0)).put(eq(getMappingIid(ifaceName, "test-instance")), eq(getMapping(ifaceName, 0).get()));
+ verify(mappingContext, times(0)).put(eq(getMappingIid(IFACE_NAME, IFC_TEST_INSTANCE)), eq(getMapping(
+ IFACE_NAME, 0).get()));
return;
}
fail("WriteFailedException.CreateFailedException was expected");
@@ -222,11 +217,11 @@ public class GreCustomizerTest {
final Gre gre = generateGre();
whenGreAddDelTunnelThenSuccess();
- doReturn(getMapping(ifaceName, 1)).when(mappingContext).read(getMappingIid(ifaceName, "test-instance"));
+ mockMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_TEST_INSTANCE);
customizer.deleteCurrentAttributes(id, gre, writeContext);
verifyGreDeleteWasInvoked(gre);
- verify(mappingContext).delete(eq(getMappingIid(ifaceName, "test-instance")));
+ verify(mappingContext).delete(eq(getMappingIid(IFACE_NAME, IFC_TEST_INSTANCE)));
}
@Test
@@ -234,14 +229,14 @@ public class GreCustomizerTest {
final Gre gre = generateGre();
whenGreAddDelTunnelThenFailure();
- doReturn(getMapping(ifaceName, 1)).when(mappingContext).read(getMappingIid(ifaceName, "test-instance"));
+ mockMapping(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(ifaceName, "test-instance")));
+ verify(mappingContext, times(0)).delete(eq(getMappingIid(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 09abc9b6f..73c0dc76b 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
@@ -24,13 +24,12 @@ import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.verify;
import static org.mockito.MockitoAnnotations.initMocks;
-import com.google.common.base.Optional;
-import io.fd.honeycomb.translate.v3po.test.ContextTestUtils;
-import io.fd.honeycomb.translate.write.WriteContext;
import io.fd.honeycomb.translate.MappingContext;
+import io.fd.honeycomb.translate.v3po.test.ContextTestUtils;
import io.fd.honeycomb.translate.v3po.test.TestHelperUtils;
import io.fd.honeycomb.translate.v3po.util.NamingContext;
import io.fd.honeycomb.translate.v3po.util.TagRewriteOperation;
+import io.fd.honeycomb.translate.write.WriteContext;
import io.fd.honeycomb.translate.write.WriteFailedException;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
@@ -39,7 +38,6 @@ import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
-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.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceKey;
@@ -70,22 +68,24 @@ public class RewriteCustomizerTest {
private NamingContext namingContext;
private RewriteCustomizer customizer;
- public static final String VLAN_IF_NAME = "local0.1";
- public static final int VLAN_IF_ID = 1;
- public static final int VLAN_IF_INDEX = 11;
+ private static final String IFC_TEST_INSTANCE = "ifc-test-instance";
+ private static final String IF_NAME = "local0";
+ private static final String VLAN_IF_NAME = "local0.1";
+ private static final int VLAN_IF_ID = 1;
+ private static final int VLAN_IF_INDEX = 11;
+ private InstanceIdentifier<Rewrite> VLAN_IID;
@Before
public void setUp() throws Exception {
initMocks(this);
- namingContext = new NamingContext("generatedSubInterfaceName", "test-instance");
+ namingContext = new NamingContext("generatedSubInterfaceName", IFC_TEST_INSTANCE);
doReturn(mappingContext).when(writeContext).getMappingContext();
customizer = new RewriteCustomizer(api, namingContext);
-
- final Optional<Mapping> ifcMapping = ContextTestUtils.getMapping(VLAN_IF_NAME, VLAN_IF_INDEX);
- doReturn(ifcMapping).when(mappingContext).read(any());
+ VLAN_IID = getVlanTagRewriteId(IF_NAME, VLAN_IF_ID);
+ ContextTestUtils.mockMapping(mappingContext, VLAN_IF_NAME, VLAN_IF_INDEX, IFC_TEST_INSTANCE);
}
- private InstanceIdentifier<Rewrite> getVlanTagRewriteId(final String name, final long index) {
+ private static InstanceIdentifier<Rewrite> getVlanTagRewriteId(final String name, final long index) {
final Class<ChildOf<? super SubInterface>> child = (Class)Rewrite.class;
final InstanceIdentifier id =
InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(name)).augmentation(
@@ -154,11 +154,10 @@ public class RewriteCustomizerTest {
public void testCreate() throws Exception {
final TagRewriteOperation op = TagRewriteOperation.pop_2;
final Rewrite vlanTagRewrite = generateRewrite(op);
- final InstanceIdentifier<Rewrite> id = getVlanTagRewriteId(VLAN_IF_NAME, VLAN_IF_ID);
whenL2InterfaceVlanTagRewriteThenSuccess();
- customizer.writeCurrentAttributes(id, vlanTagRewrite, writeContext);
+ customizer.writeCurrentAttributes(VLAN_IID, vlanTagRewrite, writeContext);
verifyL2InterfaceVlanTagRewriteWasInvoked(generateL2InterfaceVlanTagRewrite(VLAN_IF_INDEX, op));
}
@@ -167,14 +166,11 @@ public class RewriteCustomizerTest {
public void testCreateFailed() throws Exception {
final TagRewriteOperation op = TagRewriteOperation.pop_2;
final Rewrite vlanTagRewrite = generateRewrite(op);
- final String subIfaceName = "local0.11";
- final int subifIndex = 1;
- final InstanceIdentifier<Rewrite> id = getVlanTagRewriteId(subIfaceName, subifIndex);
whenL2InterfaceVlanTagRewriteThenFailure();
try {
- customizer.writeCurrentAttributes(id, vlanTagRewrite, writeContext);
+ customizer.writeCurrentAttributes(VLAN_IID, vlanTagRewrite, writeContext);
} catch (WriteFailedException.CreateFailedException e) {
assertTrue(e.getCause() instanceof VppBaseCallException);
verifyL2InterfaceVlanTagRewriteWasInvoked(generateL2InterfaceVlanTagRewrite(VLAN_IF_INDEX, op));
@@ -187,11 +183,10 @@ public class RewriteCustomizerTest {
public void testUpdate() throws Exception {
final Rewrite before = generateRewrite(TagRewriteOperation.pop_2);
final Rewrite after = generateRewrite(TagRewriteOperation.pop_1);
- final InstanceIdentifier<Rewrite> id = getVlanTagRewriteId(VLAN_IF_NAME, VLAN_IF_ID);
whenL2InterfaceVlanTagRewriteThenSuccess();
- customizer.updateCurrentAttributes(id, before, after, writeContext);
+ customizer.updateCurrentAttributes(VLAN_IID, before, after, writeContext);
verifyL2InterfaceVlanTagRewriteWasInvoked(
generateL2InterfaceVlanTagRewrite(VLAN_IF_INDEX, TagRewriteOperation.pop_1));
@@ -201,12 +196,11 @@ public class RewriteCustomizerTest {
public void testUpdateFailed() throws Exception {
final Rewrite before = generateRewrite(TagRewriteOperation.pop_2);
final Rewrite after = generateRewrite(TagRewriteOperation.pop_1);
- final InstanceIdentifier<Rewrite> id = getVlanTagRewriteId(VLAN_IF_NAME, VLAN_IF_ID);
whenL2InterfaceVlanTagRewriteThenFailure();
try {
- customizer.updateCurrentAttributes(id, before, after, writeContext);
+ customizer.updateCurrentAttributes(VLAN_IID, before, after, writeContext);
} catch (WriteFailedException.UpdateFailedException e) {
assertTrue(e.getCause() instanceof VppBaseCallException);
verifyL2InterfaceVlanTagRewriteWasInvoked(generateL2InterfaceVlanTagRewrite(VLAN_IF_INDEX,
@@ -218,23 +212,19 @@ public class RewriteCustomizerTest {
@Test
public void testDelete() throws Exception {
- final InstanceIdentifier<Rewrite> id = getVlanTagRewriteId(VLAN_IF_NAME, VLAN_IF_ID);
-
whenL2InterfaceVlanTagRewriteThenSuccess();
- customizer.deleteCurrentAttributes(id, null, writeContext);
+ customizer.deleteCurrentAttributes(VLAN_IID, null, writeContext);
verifyL2InterfaceVlanTagRewriteDeleteWasInvoked();
}
@Test
public void testDeleteFailed() throws Exception {
- final InstanceIdentifier<Rewrite> id = getVlanTagRewriteId(VLAN_IF_NAME, VLAN_IF_ID);
-
whenL2InterfaceVlanTagRewriteThenFailure();
try {
- customizer.deleteCurrentAttributes(id, null, writeContext);
+ customizer.deleteCurrentAttributes(VLAN_IID, null, writeContext);
} catch (WriteFailedException.DeleteFailedException e) {
Assert.assertTrue(e.getCause() instanceof VppBaseCallException);
verifyL2InterfaceVlanTagRewriteDeleteWasInvoked();
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 507b43f9c..1a1028197 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
@@ -26,7 +26,6 @@ import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.MockitoAnnotations.initMocks;
-import com.google.common.base.Optional;
import io.fd.honeycomb.translate.MappingContext;
import io.fd.honeycomb.translate.v3po.test.ContextTestUtils;
import io.fd.honeycomb.translate.v3po.test.TestHelperUtils;
@@ -41,7 +40,6 @@ import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
-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.ieee.params.xml.ns.yang.dot1q.types.rev150626.CVlan;
import org.opendaylight.yang.gen.v1.urn.ieee.params.xml.ns.yang.dot1q.types.rev150626.Dot1qTagVlanType;
import org.opendaylight.yang.gen.v1.urn.ieee.params.xml.ns.yang.dot1q.types.rev150626.Dot1qVlanId;
@@ -84,8 +82,9 @@ public class SubInterfaceCustomizerTest {
private NamingContext namingContext;
private SubInterfaceCustomizer customizer;
- public static final String SUPER_IF_NAME = "local0";
- public static final int SUPER_IF_ID = 1;
+ private static final String IFC_TEST_INSTANCE = "ifc-test-instance";
+ private static final String SUPER_IF_NAME = "local0";
+ private static final int SUPER_IF_ID = 1;
private static final String SUB_IFACE_NAME = "local0.11";
private static final int SUBIF_INDEX = 11;
@@ -106,12 +105,12 @@ public class SubInterfaceCustomizerTest {
@Before
public void setUp() throws Exception {
initMocks(this);
- namingContext = new NamingContext("generatedSubInterfaceName", "test-instance");
+ namingContext = new NamingContext("generatedSubInterfaceName", IFC_TEST_INSTANCE);
doReturn(mappingContext).when(writeContext).getMappingContext();
// TODO HONEYCOMB-116 create base class for tests using vppApi
customizer = new SubInterfaceCustomizer(api, namingContext);
- doReturn(ContextTestUtils.getMapping(SUPER_IF_NAME, SUPER_IF_ID)).when(mappingContext)
- .read(ContextTestUtils.getMappingIid(SUPER_IF_NAME, "test-instance"));
+ ContextTestUtils.mockMapping(mappingContext, SUB_IFACE_NAME, SUBIF_INDEX, IFC_TEST_INSTANCE);
+ ContextTestUtils.mockMapping(mappingContext, SUPER_IF_NAME, SUPER_IF_ID, IFC_TEST_INSTANCE);
}
private SubInterface generateSubInterface(final boolean enabled, final List<Tag> tagList) {
@@ -245,7 +244,7 @@ public class SubInterfaceCustomizerTest {
verifyCreateSubifWasInvoked(generateSubInterfaceRequest(SUPER_IF_ID, CTAG_ID, false));
verify(mappingContext)
- .put(eq(ContextTestUtils.getMappingIid(SUB_IFACE_NAME, "test-instance")), eq(
+ .put(eq(ContextTestUtils.getMappingIid(SUB_IFACE_NAME, IFC_TEST_INSTANCE)), eq(
ContextTestUtils.getMapping(SUB_IFACE_NAME, 0).get()));
}
@@ -261,7 +260,7 @@ public class SubInterfaceCustomizerTest {
verifyCreateSubifWasInvoked(generateSubInterfaceRequest(SUPER_IF_ID, CTAG_ANY_ID, true));
verify(mappingContext)
- .put(eq(ContextTestUtils.getMappingIid(SUB_IFACE_NAME, "test-instance")), eq(
+ .put(eq(ContextTestUtils.getMappingIid(SUB_IFACE_NAME, IFC_TEST_INSTANCE)), eq(
ContextTestUtils.getMapping(SUB_IFACE_NAME, 0).get()));
}
@@ -278,7 +277,7 @@ public class SubInterfaceCustomizerTest {
assertTrue(e.getCause() instanceof VppBaseCallException);
verifyCreateSubifWasInvoked(generateSubInterfaceRequest(SUPER_IF_ID, CTAG_ID, false));
verify(mappingContext, times(0)).put(
- eq(ContextTestUtils.getMappingIid(SUPER_IF_NAME, "test-instance")),
+ eq(ContextTestUtils.getMappingIid(SUPER_IF_NAME, IFC_TEST_INSTANCE)),
eq(ContextTestUtils.getMapping(SUPER_IF_NAME, 0).get()));
return;
}
@@ -293,9 +292,6 @@ public class SubInterfaceCustomizerTest {
final InstanceIdentifier<SubInterface> id = getSubInterfaceId(SUPER_IF_NAME, SUBIF_INDEX);
whenSwInterfaceSetFlagsThenSuccess();
- final Optional<Mapping> ifcMapping = ContextTestUtils.getMapping(SUPER_IF_NAME, SUBIF_INDEX);
- doReturn(ifcMapping).when(mappingContext).read(any());
-
customizer.updateCurrentAttributes(id, before, after, writeContext);
verifySwInterfaceSetFlagsWasInvoked(generateSwInterfaceEnableRequest(SUBIF_INDEX));
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 2e65a412b..9bf86c537 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,11 +23,11 @@ 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.write.WriteContext;
import io.fd.honeycomb.translate.MappingContext;
import io.fd.honeycomb.translate.ModificationCache;
+import io.fd.honeycomb.translate.v3po.test.ContextTestUtils;
import io.fd.honeycomb.translate.v3po.util.NamingContext;
+import io.fd.honeycomb.translate.write.WriteContext;
import java.util.concurrent.CompletableFuture;
import org.junit.Before;
import org.junit.Test;
@@ -53,6 +53,8 @@ import org.openvpp.jvpp.core.future.FutureJVppCore;
public class TapCustomizerTest {
+ private static final String IFC_TEST_INSTANCE = "ifc-test-instance";
+
@Mock
private FutureJVppCore vppApi;
@Mock
@@ -67,7 +69,7 @@ public class TapCustomizerTest {
MockitoAnnotations.initMocks(this);
InterfaceTypeTestUtils.setupWriteContext(writeContext,
org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.Tap.class);
- final NamingContext ctx = new NamingContext("ifcintest", "test-instance");
+ final NamingContext ctx = new NamingContext("ifcintest", IFC_TEST_INSTANCE);
final ModificationCache toBeReturned = new ModificationCache();
doReturn(toBeReturned).when(writeContext).getModificationCache();
doReturn(mappingContext).when(writeContext).getMappingContext();
@@ -95,9 +97,9 @@ public class TapCustomizerTest {
tapCustomizer.writeCurrentAttributes(getTapId("tap2"), getTapData("tap2", "ff:ff:ff:ff:ff:ff"), writeContext);
verify(vppApi, times(2)).tapConnect(any(TapConnect.class));
- verify(mappingContext).put(eq(ContextTestUtils.getMappingIid("tap", "test-instance")), eq(
+ verify(mappingContext).put(eq(ContextTestUtils.getMappingIid("tap", IFC_TEST_INSTANCE)), eq(
ContextTestUtils.getMapping("tap", 0).get()));
- verify(mappingContext).put(eq(ContextTestUtils.getMappingIid("tap2", "test-instance")), eq(
+ verify(mappingContext).put(eq(ContextTestUtils.getMappingIid("tap2", IFC_TEST_INSTANCE)), eq(
ContextTestUtils.getMapping("tap2", 1).get()));
}
@@ -116,14 +118,14 @@ public class TapCustomizerTest {
doReturn(replyModif).when(vppApi).tapModify(any(TapModify.class));
tapCustomizer.writeCurrentAttributes(getTapId("tap"), getTapData("tap", "ff:ff:ff:ff:ff:ff"), writeContext);
- doReturn(ContextTestUtils.getMapping("tap", 1)).when(mappingContext).read(
- ContextTestUtils.getMappingIid("tap", "test-instance"));
+
+ ContextTestUtils.mockMapping(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(vppApi).tapConnect(any(TapConnect.class));
verify(vppApi).tapModify(any(TapModify.class));
- verify(mappingContext).put(eq(ContextTestUtils.getMappingIid("tap", "test-instance")), eq(
+ verify(mappingContext).put(eq(ContextTestUtils.getMappingIid("tap", IFC_TEST_INSTANCE)), eq(
ContextTestUtils.getMapping("tap", 0).get()));
}
@@ -141,13 +143,12 @@ public class TapCustomizerTest {
doReturn(replyDelete).when(vppApi).tapDelete(any(TapDelete.class));
tapCustomizer.writeCurrentAttributes(getTapId("tap"), getTapData("tap", "ff:ff:ff:ff:ff:ff"), writeContext);
- doReturn(ContextTestUtils.getMapping("tap", 1)).when(mappingContext).read(
- ContextTestUtils.getMappingIid("tap", "test-instance"));
+ ContextTestUtils.mockMapping(mappingContext, "tap", 1, IFC_TEST_INSTANCE);
tapCustomizer.deleteCurrentAttributes(getTapId("tap"), getTapData("tap", "ff:ff:ff:ff:ff:ff"), writeContext);
verify(vppApi).tapConnect(any(TapConnect.class));
verify(vppApi).tapDelete(any(TapDelete.class));
- verify(mappingContext).delete(eq(ContextTestUtils.getMappingIid("tap", "test-instance")));
+ verify(mappingContext).delete(eq(ContextTestUtils.getMappingIid("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 0bbf04fc0..f3963e669 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
@@ -230,8 +230,7 @@ public class VhostUserCustomizerTest {
public void testUpdateCurrentAttributes() throws Exception {
final VhostUser vhostUserBefore = generateVhostUser(VhostUserRole.Client, "socketName0");
final VhostUser vhostUserAfter = generateVhostUser(VhostUserRole.Server, "socketName1");
- doReturn(ContextTestUtils.getMapping(IFACE_NAME, IFACE_ID)).when(mappingContext).read(
- ContextTestUtils.getMappingIid(IFACE_NAME, "test-instance"));
+ ContextTestUtils.mockMapping(mappingContext, IFACE_NAME, IFACE_ID, "test-instance");
whenModifyVhostUserIfThenSuccess();
@@ -243,8 +242,7 @@ public class VhostUserCustomizerTest {
public void testUpdateCurrentAttributesFailed() throws Exception {
final VhostUser vhostUserBefore = generateVhostUser(VhostUserRole.Client, "socketName0");
final VhostUser vhostUserAfter = generateVhostUser(VhostUserRole.Server, "socketName1");
- doReturn(ContextTestUtils.getMapping(IFACE_NAME, IFACE_ID)).when(mappingContext).read(
- ContextTestUtils.getMappingIid(IFACE_NAME, "test-instance"));
+ ContextTestUtils.mockMapping(mappingContext, IFACE_NAME, IFACE_ID, "test-instance");
whenModifyVhostUserIfThenFailure();
@@ -261,8 +259,7 @@ public class VhostUserCustomizerTest {
@Test
public void testDeleteCurrentAttributes() throws Exception {
final VhostUser vhostUser = generateVhostUser(VhostUserRole.Client, "socketName");
- doReturn(ContextTestUtils.getMapping(IFACE_NAME, IFACE_ID)).when(mappingContext).read(
- ContextTestUtils.getMappingIid(IFACE_NAME, "test-instance"));
+ ContextTestUtils.mockMapping(mappingContext, IFACE_NAME, IFACE_ID, "test-instance");
whenDeleteVhostUserIfThenSuccess();
@@ -274,8 +271,7 @@ public class VhostUserCustomizerTest {
@Test
public void testDeleteCurrentAttributesFailed() throws Exception {
final VhostUser vhostUser = generateVhostUser(VhostUserRole.Client, "socketName");
- doReturn(ContextTestUtils.getMapping(IFACE_NAME, IFACE_ID)).when(mappingContext).read(
- ContextTestUtils.getMappingIid(IFACE_NAME, "test-instance"));
+ ContextTestUtils.mockMapping(mappingContext, IFACE_NAME, IFACE_ID, "test-instance");
whenDeleteVhostUserIfThenFailure();
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 0d954deaa..695c2ff3a 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
@@ -18,7 +18,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 java.util.Collections.singletonList;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@@ -33,11 +32,11 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.mockito.MockitoAnnotations.initMocks;
-import com.google.common.base.Optional;
import com.google.common.net.InetAddresses;
import io.fd.honeycomb.translate.MappingContext;
import io.fd.honeycomb.translate.ModificationCache;
import io.fd.honeycomb.translate.v3po.DisabledInterfacesManager;
+import io.fd.honeycomb.translate.v3po.test.ContextTestUtils;
import io.fd.honeycomb.translate.v3po.test.TestHelperUtils;
import io.fd.honeycomb.translate.v3po.util.NamingContext;
import io.fd.honeycomb.translate.write.WriteContext;
@@ -51,9 +50,6 @@ import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
-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.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces;
@@ -103,7 +99,7 @@ public class VxlanCustomizerTest {
ifaceName = "eth0";
id = InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(ifaceName))
- .augmentation(VppInterfaceAugmentation.class).child(Vxlan.class);
+ .augmentation(VppInterfaceAugmentation.class).child(Vxlan.class);
}
private void whenVxlanAddDelTunnelThenSuccess()
@@ -120,9 +116,9 @@ public class VxlanCustomizerTest {
* Failure response send
*/
private void whenVxlanAddDelTunnelThenFailure()
- throws ExecutionException, InterruptedException, VppInvocationException {
+ throws ExecutionException, InterruptedException, VppInvocationException {
doReturn(TestHelperUtils.<VxlanAddDelTunnelReply>createFutureException()).when(api)
- .vxlanAddDelTunnel(any(VxlanAddDelTunnel.class));
+ .vxlanAddDelTunnel(any(VxlanAddDelTunnel.class));
}
private VxlanAddDelTunnel verifyVxlanAddDelTunnelWasInvoked(final Vxlan vxlan) throws VppInvocationException {
@@ -132,9 +128,9 @@ public class VxlanCustomizerTest {
assertEquals(0, actual.isIpv6);
assertEquals(-1, actual.decapNextIndex);
assertArrayEquals(InetAddresses.forString(vxlan.getSrc().getIpv4Address().getValue()).getAddress(),
- actual.srcAddress);
+ actual.srcAddress);
assertArrayEquals(InetAddresses.forString(vxlan.getDst().getIpv4Address().getValue()).getAddress(),
- actual.dstAddress);
+ actual.dstAddress);
assertEquals(vxlan.getEncapVrfId().intValue(), actual.encapVrfId);
assertEquals(vxlan.getVni().getValue().intValue(), actual.vni);
return actual;
@@ -168,9 +164,7 @@ public class VxlanCustomizerTest {
final Vxlan vxlan = generateVxlan();
whenVxlanAddDelTunnelThenSuccess();
-
- doReturn(Optional.absent())
- .when(mappingContext).read(getMappingIid(ifaceName, "test-instance").firstIdentifierOf(Mappings.class));
+ ContextTestUtils.mockEmptyMapping(mappingContext, ifaceName, "test-instance");
customizer.writeCurrentAttributes(id, vxlan, writeContext);
verifyVxlanAddWasInvoked(vxlan);
@@ -182,9 +176,7 @@ public class VxlanCustomizerTest {
final Vxlan vxlan = generateVxlan();
whenVxlanAddDelTunnelThenSuccess();
-
- doReturn(Optional.absent())
- .when(mappingContext).read(getMappingIid(ifaceName, "test-instance").firstIdentifierOf(Mappings.class));
+ ContextTestUtils.mockEmptyMapping(mappingContext, ifaceName, "test-instance");
doReturn(true).when(disableContext).isInterfaceDisabled(0, mappingContext);
customizer.writeCurrentAttributes(id, vxlan, writeContext);
@@ -196,19 +188,18 @@ public class VxlanCustomizerTest {
@Test
public void testWriteCurrentAttributesMappingAlreadyPresent() throws Exception {
final Vxlan vxlan = generateVxlan();
+ final int ifaceId = 0;
whenVxlanAddDelTunnelThenSuccess();
- final Optional<Mapping> ifcMapping = getMapping(ifaceName, 0);
-
- doReturn(Optional.of(new MappingsBuilder().setMapping(singletonList(ifcMapping.get())).build()))
- .when(mappingContext).read(getMappingIid(ifaceName, "test-instance").firstIdentifierOf(Mappings.class));
+ ContextTestUtils.mockMapping(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).put(eq(getMappingIid(ifaceName, "test-instance")), eq(ifcMapping.get()));
+ verify(mappingContext)
+ .put(eq(getMappingIid(ifaceName, "test-instance")), eq(getMapping(ifaceName, ifaceId).get()));
}
@Test
@@ -223,7 +214,8 @@ public class VxlanCustomizerTest {
assertTrue(e.getCause() instanceof VppBaseCallException);
verifyVxlanAddWasInvoked(vxlan);
// Mapping not stored due to failure
- verify(mappingContext, times(0)).put(eq(getMappingIid(ifaceName, "test-instance")), eq(getMapping(ifaceName, 0).get()));
+ verify(mappingContext, times(0))
+ .put(eq(getMappingIid(ifaceName, "test-instance")), eq(getMapping(ifaceName, 0).get()));
return;
}
fail("WriteFailedException.CreateFailedException was expected");
@@ -245,7 +237,7 @@ public class VxlanCustomizerTest {
final Vxlan vxlan = generateVxlan();
whenVxlanAddDelTunnelThenSuccess();
- doReturn(getMapping(ifaceName, 1)).when(mappingContext).read(getMappingIid(ifaceName, "test-instance"));
+ ContextTestUtils.mockMapping(mappingContext, ifaceName, 1, "test-instance");
customizer.deleteCurrentAttributes(id, vxlan, writeContext);
verifyVxlanDeleteWasInvoked(vxlan);
@@ -258,7 +250,7 @@ public class VxlanCustomizerTest {
final Vxlan vxlan = generateVxlan();
whenVxlanAddDelTunnelThenFailure();
- doReturn(getMapping(ifaceName, 1)).when(mappingContext).read(getMappingIid(ifaceName, "test-instance"));
+ ContextTestUtils.mockMapping(mappingContext, ifaceName, 1, "test-instance");
try {
customizer.deleteCurrentAttributes(id, vxlan, writeContext);
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 35dacab56..07e050ec6 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,7 +16,8 @@
package io.fd.honeycomb.translate.v3po.interfaces;
-import static java.util.Collections.singletonList;
+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,8 +32,8 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.mockito.MockitoAnnotations.initMocks;
-import com.google.common.base.Optional;
import com.google.common.net.InetAddresses;
+import io.fd.honeycomb.translate.MappingContext;
import io.fd.honeycomb.translate.ModificationCache;
import io.fd.honeycomb.translate.v3po.DisabledInterfacesManager;
import io.fd.honeycomb.translate.v3po.test.ContextTestUtils;
@@ -40,7 +41,6 @@ import io.fd.honeycomb.translate.v3po.test.TestHelperUtils;
import io.fd.honeycomb.translate.v3po.util.NamingContext;
import io.fd.honeycomb.translate.write.WriteContext;
import io.fd.honeycomb.translate.write.WriteFailedException;
-import io.fd.honeycomb.translate.MappingContext;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
import java.util.concurrent.ExecutionException;
@@ -50,9 +50,6 @@ import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
-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.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces;
@@ -101,7 +98,7 @@ public class VxlanGpeCustomizerTest {
customizer = new VxlanGpeCustomizer(api, namingContext, interfaceDisableContext);
- ifaceName = "eth0";
+ ifaceName = "elth0";
id = InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(ifaceName))
.augmentation(VppInterfaceAugmentation.class).child(VxlanGpe.class);
}
@@ -172,32 +169,29 @@ public class VxlanGpeCustomizerTest {
final VxlanGpe vxlanGpe = generateVxlanGpe();
whenVxlanGpeAddDelTunnelThenSuccess();
-
- doReturn(Optional.absent())
- .when(mappingContext).read(ContextTestUtils.getMappingIid(ifaceName, "test-instance").firstIdentifierOf(Mappings.class));
+ ContextTestUtils.mockEmptyMapping(mappingContext, ifaceName, "test-instance");
customizer.writeCurrentAttributes(id, vxlanGpe, writeContext);
verifyVxlanGpeAddWasInvoked(vxlanGpe);
- verify(mappingContext).put(eq(ContextTestUtils.getMappingIid(ifaceName, "test-instance")), eq(
- ContextTestUtils.getMapping(ifaceName, 0).get()));
+ verify(mappingContext).put(eq(getMappingIid(ifaceName, "test-instance")), eq(
+ getMapping(ifaceName, 0).get()));
}
@Test
public void testWriteCurrentAttributesMappingAlreadyPresent() throws Exception {
final VxlanGpe vxlanGpe = generateVxlanGpe();
+ final int ifaceId = 0;
whenVxlanGpeAddDelTunnelThenSuccess();
- final Optional<Mapping> ifcMapping = ContextTestUtils.getMapping(ifaceName, 0);
-
- doReturn(Optional.of(new MappingsBuilder().setMapping(singletonList(ifcMapping.get())).build()))
- .when(mappingContext).read(ContextTestUtils.getMappingIid(ifaceName, "test-instance").firstIdentifierOf(Mappings.class));
+ ContextTestUtils.mockMapping(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(ContextTestUtils.getMappingIid(ifaceName, "test-instance")));
- verify(mappingContext).put(eq(ContextTestUtils.getMappingIid(ifaceName, "test-instance")), eq(ifcMapping.get()));
+ verify(mappingContext).delete(eq(getMappingIid(ifaceName, "test-instance")));
+ verify(mappingContext).put(eq(getMappingIid(ifaceName, "test-instance")),
+ eq(getMapping(ifaceName, ifaceId).get()));
}
@Test
@@ -213,8 +207,8 @@ public class VxlanGpeCustomizerTest {
verifyVxlanGpeAddWasInvoked(vxlanGpe);
// Mapping not stored due to failure
verify(mappingContext, times(0))
- .put(eq(ContextTestUtils.getMappingIid(ifaceName, "test-instance")), eq(
- ContextTestUtils.getMapping(ifaceName, 0).get()));
+ .put(eq(getMappingIid(ifaceName, "test-instance")), eq(
+ getMapping(ifaceName, 0).get()));
return;
}
fail("WriteFailedException.CreateFailedException was expected");
@@ -236,12 +230,11 @@ public class VxlanGpeCustomizerTest {
final VxlanGpe vxlanGpe = generateVxlanGpe();
whenVxlanGpeAddDelTunnelThenSuccess();
- doReturn(ContextTestUtils.getMapping(ifaceName, 1)).when(mappingContext).read(
- ContextTestUtils.getMappingIid(ifaceName, "test-instance"));
+ ContextTestUtils.mockMapping(mappingContext, ifaceName, 1, "test-instance");
customizer.deleteCurrentAttributes(id, vxlanGpe, writeContext);
verifyVxlanGpeDeleteWasInvoked(vxlanGpe);
- verify(mappingContext).delete(eq(ContextTestUtils.getMappingIid(ifaceName, "test-instance")));
+ verify(mappingContext).delete(eq(getMappingIid(ifaceName, "test-instance")));
}
@Test
@@ -249,15 +242,14 @@ public class VxlanGpeCustomizerTest {
final VxlanGpe vxlanGpe = generateVxlanGpe();
whenVxlanGpeAddDelTunnelThenFailure();
- doReturn(ContextTestUtils.getMapping(ifaceName, 1)).when(mappingContext).read(
- ContextTestUtils.getMappingIid(ifaceName, "test-instance"));
+ ContextTestUtils.mockMapping(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(ContextTestUtils.getMappingIid(ifaceName, "test-instance")));
+ verify(mappingContext, times(0)).delete(eq(getMappingIid(ifaceName, "test-instance")));
return;
}
fail("WriteFailedException.DeleteFailedException was expected");
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 6d2513d75..d7f9c0c1c 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
@@ -21,9 +21,9 @@ import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
-import com.google.common.base.Optional;
import com.google.common.io.BaseEncoding;
import io.fd.honeycomb.translate.MappingContext;
+import io.fd.honeycomb.translate.v3po.test.ContextTestUtils;
import io.fd.honeycomb.translate.v3po.util.NamingContext;
import io.fd.honeycomb.translate.v3po.util.TranslateUtils;
import io.fd.honeycomb.translate.write.WriteContext;
@@ -53,6 +53,10 @@ import org.openvpp.jvpp.core.future.FutureJVppCore;
public class Ipv4NeighbourCustomizerTest {
+ private static final String IFC_CTX_NAME = "ifc-test-instance";
+ private static final String IFACE_NAME = "parent";
+ private static final int IFACE_ID = 5;
+
@Mock
private FutureJVppCore jvpp;
@@ -73,28 +77,23 @@ public class Ipv4NeighbourCustomizerTest {
@Before
public void init() {
MockitoAnnotations.initMocks(this);
+ when(context.getMappingContext()).thenReturn(mappingContext);
- namingContext = new NamingContext("prefix", "instance");
- namingContext.addName(5, "parent", mappingContext);
+ namingContext = new NamingContext("prefix", IFC_CTX_NAME);
+ ContextTestUtils.mockMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME);
customizer = new Ipv4NeighbourCustomizer(jvpp,namingContext);
requestCaptor = ArgumentCaptor.forClass(IpNeighborAddDel.class);
-
CompletableFuture<IpNeighborAddDelReply> future = new CompletableFuture<>();
future.complete(new IpNeighborAddDelReply());
-
- when(context.getMappingContext()).thenReturn(mappingContext);
- when(mapping.getIndex()).thenReturn(5);
- when(mapping.getName()).thenReturn("parent");
- when(mappingContext.read(Mockito.any())).thenReturn(Optional.fromNullable(mapping));
when(jvpp.ipNeighborAddDel(Mockito.any(IpNeighborAddDel.class))).thenReturn(future);
}
@Test
public void testWriteCurrentAttributes() throws WriteFailedException {
- InterfaceKey intfKey = new InterfaceKey("parent");
+ InterfaceKey intfKey = new InterfaceKey(IFACE_NAME);
InstanceIdentifier<Neighbor> id = InstanceIdentifier.builder(Interfaces.class).child(Interface.class, intfKey)
.augmentation(Interface1.class).child(Ipv4.class).child(Neighbor.class).build();
@@ -120,7 +119,7 @@ public class Ipv4NeighbourCustomizerTest {
@Test
public void testDeleteCurrentAttributes() throws WriteFailedException {
- InterfaceKey intfKey = new InterfaceKey("parent");
+ InterfaceKey intfKey = new InterfaceKey(IFACE_NAME);
InstanceIdentifier<Neighbor> id = InstanceIdentifier.builder(Interfaces.class).child(Interface.class, intfKey)
.augmentation(Interface1.class).child(Ipv4.class).child(Neighbor.class).build();
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 86cb6b90a..ba056573f 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
@@ -21,21 +21,14 @@ import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
-import com.google.common.base.Optional;
-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.test.ReaderCustomizerTest;
import io.fd.honeycomb.translate.v3po.util.NamingContext;
import io.fd.honeycomb.translate.v3po.vppclassifier.VppClassifierContextManager;
-import java.util.List;
import java.util.concurrent.CompletableFuture;
import org.junit.Test;
import org.mockito.Mock;
-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.MappingKey;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfacesState;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.InterfaceKey;
@@ -45,7 +38,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces.state._interface.Acl;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces.state._interface.AclBuilder;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
import org.openvpp.jvpp.core.dto.ClassifyTableByInterface;
import org.openvpp.jvpp.core.dto.ClassifyTableByInterfaceReply;
@@ -56,7 +48,7 @@ public class AclCustomizerTest extends ReaderCustomizerTest<Acl, AclBuilder> {
private static final int TABLE_INDEX = 123;
private static final String TABLE_NAME = "table123";
- private static final String IFC_TEST_INSTANCE = "ifc-test-instance";
+ private static final String IFC_CTX_NAME = "ifc-test-instance";
private NamingContext interfaceContext;
@@ -69,17 +61,8 @@ public class AclCustomizerTest extends ReaderCustomizerTest<Acl, AclBuilder> {
@Override
public void setUpBefore() {
- interfaceContext = new NamingContext("generatedIfaceName", IFC_TEST_INSTANCE);
-
- final KeyedInstanceIdentifier<Mapping, MappingKey> ifcMappingKey = ContextTestUtils
- .getMappingIid(IF_NAME, IFC_TEST_INSTANCE);
- final Optional<Mapping> ifcMapping = ContextTestUtils.getMapping(IF_NAME, IF_INDEX);
- doReturn(ifcMapping).when(mappingContext).read(ifcMappingKey);
-
- final List<Mapping> allIfcMappings = Lists.newArrayList(ifcMapping.get());
- final Mappings allIfcMappingsBaObject = new MappingsBuilder().setMapping(allIfcMappings).build();
- doReturn(Optional.of(allIfcMappingsBaObject)).when(mappingContext)
- .read(ifcMappingKey.firstIdentifierOf(Mappings.class));
+ interfaceContext = new NamingContext("generatedIfaceName", IFC_CTX_NAME);
+ ContextTestUtils.mockMapping(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 962e6c2f3..094d464a2 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
@@ -16,8 +16,6 @@
package io.fd.honeycomb.translate.v3po.interfacesstate;
-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.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
@@ -28,6 +26,7 @@ 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.test.ReaderCustomizerTest;
import io.fd.honeycomb.translate.v3po.util.NamingContext;
import java.net.InetAddress;
@@ -44,16 +43,20 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces.state._interface.GreBuilder;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.openvpp.jvpp.VppInvocationException;
-import org.openvpp.jvpp.core.dto.SwInterfaceDetails;
import org.openvpp.jvpp.core.dto.GreTunnelDetails;
import org.openvpp.jvpp.core.dto.GreTunnelDetailsReplyDump;
import org.openvpp.jvpp.core.dto.GreTunnelDump;
+import org.openvpp.jvpp.core.dto.SwInterfaceDetails;
public class GreCustomizerTest extends ReaderCustomizerTest<Gre, GreBuilder> {
+ private static final String IFACE_NAME = "ifc1";
+ private static final int IFACE_ID = 0;
+ private static final String IFC_CTX_NAME = "ifc-test-instance";
+
private NamingContext interfacesContext;
static final InstanceIdentifier<Gre> IID =
- InstanceIdentifier.create(InterfacesState.class).child(Interface.class, new InterfaceKey("ifc1"))
+ InstanceIdentifier.create(InterfacesState.class).child(Interface.class, new InterfaceKey(IFACE_NAME))
.augmentation(VppInterfaceStateAugmentation.class).child(Gre.class);
public GreCustomizerTest() {
@@ -62,8 +65,8 @@ public class GreCustomizerTest extends ReaderCustomizerTest<Gre, GreBuilder> {
@Override
public void setUpBefore() {
- interfacesContext = new NamingContext("gre-tunnel", "test-instance");
- doReturn(getMapping("ifc1", 0)).when(mappingContext).read(getMappingIid("ifc1", "test-instance"));
+ interfacesContext = new NamingContext("gre-tunnel", IFC_CTX_NAME);
+ ContextTestUtils.mockMapping(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 f64d750fa..86c1df2fd 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
@@ -25,8 +25,6 @@ import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyZeroInteractions;
-import com.google.common.base.Optional;
-import com.google.common.collect.Lists;
import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
import io.fd.honeycomb.translate.v3po.DisabledInterfacesManager;
import io.fd.honeycomb.translate.v3po.test.ContextTestUtils;
@@ -40,17 +38,12 @@ import org.junit.Assert;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
-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.MappingKey;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfacesState;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfacesStateBuilder;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.InterfaceBuilder;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.InterfaceKey;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
import org.openvpp.jvpp.VppInvocationException;
import org.openvpp.jvpp.core.dto.SwInterfaceDetails;
import org.openvpp.jvpp.core.dto.SwInterfaceDump;
@@ -58,6 +51,14 @@ import org.openvpp.jvpp.core.dto.SwInterfaceDump;
public class InterfaceCustomizerTest extends
ListReaderCustomizerTest<Interface, InterfaceKey, InterfaceBuilder> {
+ private static final String IFC_CTX_NAME = "ifc-test-instance";
+ private static final String IFACE0_NAME = "eth0";
+ private static final String IFACE1_NAME = "eth1";
+ private static final String SUB_IFACE_NAME = "eth1.1";
+ private static final int IFACE0_ID = 0;
+ private static final int IFACE1_ID = 1;
+ private static final int SUB_IFACE_ID = 2;
+
private NamingContext interfacesContext;
@Mock
private DisabledInterfacesManager interfaceDisableContext;
@@ -68,31 +69,14 @@ public class InterfaceCustomizerTest extends
@Override
public void setUpBefore() {
- interfacesContext = new NamingContext("generatedIfaceName", "test-instance");
+ 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);
}
@Override
protected ReaderCustomizer<Interface, InterfaceBuilder> initCustomizer() {
- final KeyedInstanceIdentifier<Mapping, MappingKey> eth0Id = ContextTestUtils
- .getMappingIid("eth0", "test-instance");
- final KeyedInstanceIdentifier<Mapping, MappingKey> eth1Id = ContextTestUtils
- .getMappingIid("eth1", "test-instance");
- final KeyedInstanceIdentifier<Mapping, MappingKey> subEth1Id = ContextTestUtils
- .getMappingIid("eth1.1", "test-instance");
- final Optional<Mapping> eth0 = ContextTestUtils.getMapping("eth0", 0);
- final Optional<Mapping> eth1 = ContextTestUtils.getMapping("eth1", 1);
- final Optional<Mapping> subEth1 = ContextTestUtils.getMapping("eth1.1", 2);
-
- final List<Mapping> allMappings =
- Lists.newArrayList(ContextTestUtils.getMapping("eth0", 0).get(), ContextTestUtils.getMapping("eth1", 1).get(), ContextTestUtils
- .getMapping("eth1.1", 2).get());
- final Mappings allMappingsBaObject = new MappingsBuilder().setMapping(allMappings).build();
- doReturn(Optional.of(allMappingsBaObject)).when(mappingContext).read(eth0Id.firstIdentifierOf(Mappings.class));
-
- doReturn(eth0).when(mappingContext).read(eth0Id);
- doReturn(eth1).when(mappingContext).read(eth1Id);
- doReturn(subEth1).when(mappingContext).read(subEth1Id);
-
return new InterfaceCustomizer(api, interfacesContext, interfaceDisableContext);
}
@@ -123,13 +107,12 @@ public class InterfaceCustomizerTest extends
@Test
public void testReadCurrentAttributes() throws Exception {
- final String ifaceName = "eth0";
final InstanceIdentifier<Interface> id = InstanceIdentifier.create(InterfacesState.class)
- .child(Interface.class, new InterfaceKey(ifaceName));
+ .child(Interface.class, new InterfaceKey(IFACE0_NAME));
final InterfaceBuilder builder = getCustomizer().getBuilder(id);
final SwInterfaceDetails iface = new SwInterfaceDetails();
- iface.interfaceName = ifaceName.getBytes();
+ iface.interfaceName = IFACE0_NAME.getBytes();
iface.swIfIndex = 0;
iface.linkSpeed = 1;
iface.l2AddressLength = 6;
@@ -139,13 +122,13 @@ public class InterfaceCustomizerTest extends
getCustomizer().readCurrentAttributes(id, builder, ctx);
- verifySwInterfaceDumpWasInvoked(1, ifaceName, 1);
+ verifySwInterfaceDumpWasInvoked(1, IFACE0_NAME, 1);
assertIfacesAreEqual(builder.build(), iface);
}
@Test
public void testReadCurrentAttributesFailed() throws Exception {
- final String ifaceName = "eth0";
+ final String ifaceName = IFACE0_NAME;
final InstanceIdentifier<Interface> id = InstanceIdentifier.create(InterfacesState.class)
.child(Interface.class, new InterfaceKey(ifaceName));
final InterfaceBuilder builder = getCustomizer().getBuilder(id);
@@ -164,13 +147,12 @@ public class InterfaceCustomizerTest extends
@Test
public void testReadSubInterface() throws Exception {
- final String ifaceName = "eth1.1";
final InstanceIdentifier<Interface> id = InstanceIdentifier.create(InterfacesState.class)
- .child(Interface.class, new InterfaceKey(ifaceName));
+ .child(Interface.class, new InterfaceKey(SUB_IFACE_NAME));
final InterfaceBuilder builder = mock(InterfaceBuilder.class);
final SwInterfaceDetails iface = new SwInterfaceDetails();
- iface.interfaceName = ifaceName.getBytes();
+ iface.interfaceName = SUB_IFACE_NAME.getBytes();
iface.swIfIndex = 2;
iface.supSwIfIndex = 1;
iface.subId = 1;
@@ -179,7 +161,7 @@ public class InterfaceCustomizerTest extends
getCustomizer().readCurrentAttributes(id, builder, ctx);
- verifySwInterfaceDumpWasInvoked(1, ifaceName, 1);
+ verifySwInterfaceDumpWasInvoked(1, SUB_IFACE_NAME, 1);
verifyZeroInteractions(builder);
}
@@ -188,23 +170,21 @@ public class InterfaceCustomizerTest extends
final InstanceIdentifier<Interface> id = InstanceIdentifier.create(InterfacesState.class)
.child(Interface.class);
- final String swIf0Name = "eth0";
final SwInterfaceDetails swIf0 = new SwInterfaceDetails();
swIf0.swIfIndex = 0;
- swIf0.interfaceName = swIf0Name.getBytes();
- final String swIf1Name = "eth1";
+ swIf0.interfaceName = IFACE0_NAME.getBytes();
final SwInterfaceDetails swIf1 = new SwInterfaceDetails();
swIf1.swIfIndex = 1;
- swIf1.interfaceName = swIf1Name.getBytes();
- final String swSubIf1Name = "eth1.1";
+ swIf1.interfaceName = IFACE1_NAME.getBytes();
final SwInterfaceDetails swSubIf1 = new SwInterfaceDetails();
swSubIf1.swIfIndex = 2;
swSubIf1.subId = 1;
swSubIf1.supSwIfIndex = 1;
- swSubIf1.interfaceName = swSubIf1Name.getBytes();
+ swSubIf1.interfaceName = SUB_IFACE_NAME.getBytes();
InterfaceTestUtils.whenSwInterfaceDumpThenReturn(api, Arrays.asList(swIf0, swIf1, swSubIf1));
- final List<InterfaceKey> expectedIds = Arrays.asList(new InterfaceKey(swIf0Name), new InterfaceKey(swIf1Name));
+ final List<InterfaceKey> expectedIds = Arrays.asList(new InterfaceKey(IFACE0_NAME), new InterfaceKey(
+ IFACE1_NAME));
final List<InterfaceKey> actualIds = getCustomizer().getAllIds(id, ctx);
verifySwInterfaceDumpWasInvoked(0, "", 1);
@@ -220,17 +200,15 @@ public class InterfaceCustomizerTest extends
doReturn(true).when(interfaceDisableContext).isInterfaceDisabled(1, mappingContext);
- final String swIf0Name = "eth0";
final SwInterfaceDetails swIf0 = new SwInterfaceDetails();
swIf0.swIfIndex = 0;
- swIf0.interfaceName = swIf0Name.getBytes();
- final String swIf1Name = "eth1";
+ swIf0.interfaceName = IFACE0_NAME.getBytes();
final SwInterfaceDetails swIf1 = new SwInterfaceDetails();
swIf1.swIfIndex = 1;
- swIf1.interfaceName = swIf1Name.getBytes();
+ swIf1.interfaceName = IFACE1_NAME.getBytes();
InterfaceTestUtils.whenSwInterfaceDumpThenReturn(api, Arrays.asList(swIf0, swIf1));
- final List<InterfaceKey> expectedIds = Arrays.asList(new InterfaceKey(swIf0Name));
+ final List<InterfaceKey> expectedIds = Arrays.asList(new InterfaceKey(IFACE0_NAME));
final List<InterfaceKey> actualIds = getCustomizer().getAllIds(id, ctx);
// disabled interface should not be on the list
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 0346e463c..27fa372c6 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
@@ -17,13 +17,10 @@
package io.fd.honeycomb.translate.v3po.interfacesstate;
import static org.mockito.Matchers.any;
-import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
-import com.google.common.base.Optional;
-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.test.ReaderCustomizerTest;
@@ -35,10 +32,6 @@ import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import org.junit.Test;
-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.MappingKey;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfacesState;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.InterfaceKey;
@@ -49,7 +42,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.l2.base.attributes.Interconnection;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.l2.base.attributes.interconnection.BridgeBasedBuilder;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
import org.openvpp.jvpp.VppInvocationException;
import org.openvpp.jvpp.core.dto.BridgeDomainDetails;
import org.openvpp.jvpp.core.dto.BridgeDomainDetailsReplyDump;
@@ -59,6 +51,8 @@ import org.openvpp.jvpp.core.dto.SwInterfaceDetails;
public class L2CustomizerTest extends ReaderCustomizerTest<L2, L2Builder> {
+ private static final String IFC_CTX_NAME = "ifc-test-instance";
+ private static final String BD_CTX_NAME = "bd-test-instance";
private NamingContext interfaceContext;
private NamingContext bridgeDomainContext;
@@ -68,8 +62,8 @@ public class L2CustomizerTest extends ReaderCustomizerTest<L2, L2Builder> {
@Override
public void setUpBefore() {
- interfaceContext = new NamingContext("generatedIfaceName", "ifc-test-instance");
- bridgeDomainContext = new NamingContext("generatedBDName", "bd-test-instance");
+ interfaceContext = new NamingContext("generatedIfaceName", IFC_CTX_NAME);
+ bridgeDomainContext = new NamingContext("generatedBDName", BD_CTX_NAME);
}
@Override
@@ -131,20 +125,8 @@ public class L2CustomizerTest extends ReaderCustomizerTest<L2, L2Builder> {
final int bdId = 1;
final String bdName = "bd001";
final String ifName = "eth0.sub0";
- final KeyedInstanceIdentifier<Mapping, MappingKey> ifcIid = ContextTestUtils
- .getMappingIid(ifName, "ifc-test-instance");
- doReturn(ContextTestUtils.getMapping(ifName, ifId)).when(mappingContext).read(ifcIid);
- final KeyedInstanceIdentifier<Mapping, MappingKey> bdIid = ContextTestUtils
- .getMappingIid(bdName, "bd-test-instance");
- doReturn(ContextTestUtils.getMapping(bdName, bdId)).when(mappingContext).read(bdIid);
-
- List<Mapping> allMappings = Lists.newArrayList(ContextTestUtils.getMapping(ifName, ifId).get());
- Mappings allMappingsBaObject = new MappingsBuilder().setMapping(allMappings).build();
- doReturn(Optional.of(allMappingsBaObject)).when(mappingContext).read(ifcIid.firstIdentifierOf(Mappings.class));
-
- allMappings = Lists.newArrayList(ContextTestUtils.getMapping(bdName, bdId).get());
- allMappingsBaObject = new MappingsBuilder().setMapping(allMappings).build();
- doReturn(Optional.of(allMappingsBaObject)).when(mappingContext).read(bdIid.firstIdentifierOf(Mappings.class));
+ ContextTestUtils.mockMapping(mappingContext, ifName, ifId, IFC_CTX_NAME);
+ ContextTestUtils.mockMapping(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 8db667484..884df320f 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
@@ -17,15 +17,12 @@
package io.fd.honeycomb.translate.v3po.interfacesstate;
import static org.junit.Assert.assertEquals;
-import static org.mockito.Matchers.any;
-import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
-import com.google.common.base.Optional;
+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.read.ReadFailedException;
import io.fd.honeycomb.translate.v3po.test.ReaderCustomizerTest;
import io.fd.honeycomb.translate.v3po.util.NamingContext;
import io.fd.honeycomb.translate.v3po.util.TagRewriteOperation;
@@ -35,7 +32,6 @@ import java.util.Map;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
-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.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfacesState;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.InterfaceKey;
@@ -54,9 +50,11 @@ import org.openvpp.jvpp.core.dto.SwInterfaceDetails;
public class RewriteCustomizerTest extends ReaderCustomizerTest<Rewrite, RewriteBuilder> {
- public static final String VLAN_IF_NAME = "local0.1";
- public static final int VLAN_IF_ID = 1;
- public static final int VLAN_IF_INDEX = 11;
+ private static final String IFC_CTX_NAME = "ifc-test-instance";
+ private static final String IF_NAME = "local0";
+ private static final String VLAN_IF_NAME = "local0.1";
+ private static final int VLAN_IF_INDEX = 11;
+ private static final int VLAN_ID = 1;
private NamingContext interfacesContext;
@@ -69,10 +67,8 @@ public class RewriteCustomizerTest extends ReaderCustomizerTest<Rewrite, Rewrite
@Override
public void setUpBefore() {
- interfacesContext = new NamingContext("generatedIfaceName", "test-instance");
-
- final Optional<Mapping> ifcMapping = ContextTestUtils.getMapping(VLAN_IF_NAME, VLAN_IF_INDEX);
- doReturn(ifcMapping).when(mappingContext).read(any());
+ interfacesContext = new NamingContext("generatedIfaceName", IFC_CTX_NAME);
+ ContextTestUtils.mockMapping(mappingContext, VLAN_IF_NAME, VLAN_IF_INDEX, IFC_CTX_NAME);
}
@Override
@@ -103,7 +99,7 @@ public class RewriteCustomizerTest extends ReaderCustomizerTest<Rewrite, Rewrite
final Map<Integer, SwInterfaceDetails> cachedInterfaceDump = new HashMap<>();
final SwInterfaceDetails ifaceDetails = new SwInterfaceDetails();
- ifaceDetails.subId = VLAN_IF_ID;
+ ifaceDetails.subId = VLAN_ID;
ifaceDetails.interfaceName = VLAN_IF_NAME.getBytes();
ifaceDetails.vtrOp = TagRewriteOperation.translate_2_to_2.ordinal();
ifaceDetails.subNumberOfTags = 2;
@@ -115,7 +111,7 @@ public class RewriteCustomizerTest extends ReaderCustomizerTest<Rewrite, Rewrite
final RewriteBuilder builder = mock(RewriteBuilder.class);
- getCustomizer().readCurrentAttributes(getVlanTagRewriteId(VLAN_IF_NAME, VLAN_IF_ID), builder, ctx);
+ getCustomizer().readCurrentAttributes(getVlanTagRewriteId(IF_NAME, VLAN_ID), builder, ctx);
verify(builder).setVlanType(_802dot1q.class);
verify(builder).setPopTags((short) 2);
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 b6af8a202..13c0631ee 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
@@ -18,12 +18,9 @@ package io.fd.honeycomb.translate.v3po.interfacesstate;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
-import static org.mockito.Matchers.any;
-import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
-import com.google.common.base.Optional;
import io.fd.honeycomb.translate.read.ReadFailedException;
import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
import io.fd.honeycomb.translate.v3po.test.ContextTestUtils;
@@ -36,7 +33,6 @@ import java.util.List;
import java.util.Map;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
-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.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfacesState;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.InterfaceKey;
@@ -55,11 +51,12 @@ import org.openvpp.jvpp.core.dto.SwInterfaceDetails;
public class SubInterfaceCustomizerTest extends
ListReaderCustomizerTest<SubInterface, SubInterfaceKey, SubInterfaceBuilder> {
- public static final String SUPER_IF_NAME = "local0";
- public static final int SUPER_IF_INDEX = 1;
- public static final String VLAN_IF_NAME = "local0.1";
- public static final int VLAN_IF_ID = 1;
- public static final int VLAN_IF_INDEX = 11;
+ private static final String IFC_CTX_NAME = "ifc-test-instance";
+ private static final String SUPER_IF_NAME = "local0";
+ private static final int SUPER_IF_INDEX = 1;
+ private static final String VLAN_IF_NAME = "local0.1";
+ private static final int VLAN_IF_ID = 1;
+ private static final int VLAN_IF_INDEX = 11;
private NamingContext interfacesContext;
@@ -69,7 +66,9 @@ public class SubInterfaceCustomizerTest extends
@Override
public void setUpBefore() {
- interfacesContext = new NamingContext("generatedIfaceName", "test-instance");
+ 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);
}
@Override
@@ -93,15 +92,14 @@ public class SubInterfaceCustomizerTest extends
@Test
public void testRead() throws ReadFailedException {
- final Optional<Mapping> ifcMapping = ContextTestUtils.getMapping(VLAN_IF_NAME, VLAN_IF_INDEX);
- doReturn(ifcMapping).when(mappingContext).read(any());
-
final Map<Integer, SwInterfaceDetails> cachedInterfaceDump = new HashMap<>();
final SwInterfaceDetails ifaceDetails = new SwInterfaceDetails();
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);
ifaceDetails.subNumberOfTags = 2;
ifaceDetails.subOuterVlanIdAny = 1;
ifaceDetails.subInnerVlanIdAny = 1;
@@ -110,7 +108,7 @@ public class SubInterfaceCustomizerTest extends
cache.put(InterfaceCustomizer.DUMPED_IFCS_CONTEXT_KEY, cachedInterfaceDump);
final SubInterfaceBuilder builder = mock(SubInterfaceBuilder.class);
- getCustomizer().readCurrentAttributes(getSubInterfaceId(VLAN_IF_NAME, VLAN_IF_ID), builder, ctx);
+ getCustomizer().readCurrentAttributes(getSubInterfaceId(SUPER_IF_NAME, VLAN_IF_ID), builder, ctx);
verify(builder).setIdentifier((long) VLAN_IF_ID);
@@ -126,9 +124,6 @@ public class SubInterfaceCustomizerTest extends
@Test
public void testGetAllIds() throws Exception {
- final Optional<Mapping> ifcMapping = ContextTestUtils.getMapping(SUPER_IF_NAME, SUPER_IF_INDEX);
- doReturn(ifcMapping).when(mappingContext).read(any());
-
final SwInterfaceDetails iface = new SwInterfaceDetails();
iface.interfaceName = VLAN_IF_NAME.getBytes();
iface.swIfIndex = VLAN_IF_INDEX;
@@ -138,9 +133,8 @@ public class SubInterfaceCustomizerTest extends
InterfaceTestUtils.whenSwInterfaceDumpThenReturn(api, ifaces);
final List<SubInterfaceKey> allIds =
- getCustomizer().getAllIds(getSubInterfaceId(VLAN_IF_NAME, VLAN_IF_ID), ctx);
+ getCustomizer().getAllIds(getSubInterfaceId(SUPER_IF_NAME, VLAN_IF_ID), ctx);
assertEquals(ifaces.size(), allIds.size());
-
}
} \ No newline at end of file
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 f7e1038d5..a65050a82 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
@@ -50,9 +50,13 @@ import org.openvpp.jvpp.core.dto.VxlanTunnelDump;
public class VxlanCustomizerTest extends ReaderCustomizerTest<Vxlan, VxlanBuilder> {
+ private static final String IFC_CTX_NAME = "ifc-test-instance";
+ private static final String IF_NAME = "ifc1";
+ private static final int IF_INDEX = 0;
+
private NamingContext interfacesContext;
static final InstanceIdentifier<Vxlan> IID =
- InstanceIdentifier.create(InterfacesState.class).child(Interface.class, new InterfaceKey("ifc1"))
+ InstanceIdentifier.create(InterfacesState.class).child(Interface.class, new InterfaceKey(IF_NAME))
.augmentation(VppInterfaceStateAugmentation.class).child(Vxlan.class);
public VxlanCustomizerTest() {
@@ -61,9 +65,8 @@ public class VxlanCustomizerTest extends ReaderCustomizerTest<Vxlan, VxlanBuilde
@Override
public void setUpBefore() {
- interfacesContext = new NamingContext("vxlan-tunnel", "test-instance");
- doReturn(ContextTestUtils.getMapping("ifc1", 0)).when(mappingContext).read(
- ContextTestUtils.getMappingIid("ifc1", "test-instance"));
+ interfacesContext = new NamingContext("vxlan-tunnel", IFC_CTX_NAME);
+ ContextTestUtils.mockMapping(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 3cf29becd..65cf0c8e9 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
@@ -50,9 +50,13 @@ import org.openvpp.jvpp.core.dto.VxlanGpeTunnelDump;
public class VxlanGpeCustomizerTest extends ReaderCustomizerTest<VxlanGpe, VxlanGpeBuilder> {
+ private static final String IFC_CTX_NAME = "ifc-test-instance";
+ private static final String IF_NAME = "ifc2";
+ private static final int IF_INDEX = 0;
+
private NamingContext interfacesContext;
- static final InstanceIdentifier<VxlanGpe> VXLAN_GPE_ID =
- InstanceIdentifier.create(InterfacesState.class).child(Interface.class, new InterfaceKey("ifc2"))
+ private static final InstanceIdentifier<VxlanGpe> VXLAN_GPE_ID =
+ InstanceIdentifier.create(InterfacesState.class).child(Interface.class, new InterfaceKey(IF_NAME))
.augmentation(VppInterfaceStateAugmentation.class).child(VxlanGpe.class);
public VxlanGpeCustomizerTest() {
@@ -61,9 +65,8 @@ public class VxlanGpeCustomizerTest extends ReaderCustomizerTest<VxlanGpe, Vxlan
@Override
public void setUpBefore() {
- interfacesContext = new NamingContext("vxlan_gpe_inf", "test-instance");
- doReturn(ContextTestUtils.getMapping("ifc2", 0)).when(mappingContext).read(
- ContextTestUtils.getMappingIid("ifc2", "test-instance"));
+ interfacesContext = new NamingContext("vxlan_gpe_inf", IFC_CTX_NAME);
+ ContextTestUtils.mockMapping(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 794ad182c..744cce0b5 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
@@ -16,24 +16,20 @@
package io.fd.honeycomb.translate.v3po.interfacesstate.ip;
-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.util.TranslateUtils.reverseBytes;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
-import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
-import com.google.common.base.Optional;
import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Lists;
-import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
-import io.fd.honeycomb.translate.v3po.test.ListReaderCustomizerTest;
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.test.ListReaderCustomizerTest;
import io.fd.honeycomb.translate.v3po.util.NamingContext;
import io.fd.honeycomb.translate.v3po.util.TranslateUtils;
import java.util.Arrays;
@@ -43,10 +39,6 @@ import java.util.stream.Collectors;
import org.hamcrest.CoreMatchers;
import org.junit.Test;
import org.mockito.Mockito;
-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.MappingKey;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfacesState;
@@ -59,7 +51,6 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev14061
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.ipv4.AddressBuilder;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.ipv4.AddressKey;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
import org.openvpp.jvpp.core.dto.IpAddressDetails;
import org.openvpp.jvpp.core.dto.IpAddressDetailsReplyDump;
import org.openvpp.jvpp.core.dto.IpAddressDump;
@@ -70,6 +61,7 @@ public class Ipv4AddressCustomizerTest extends ListReaderCustomizerTest<Address,
private static final String IFACE_2_NAME = "eth1";
private static final int IFACE_ID = 1;
private static final int IFACE_2_ID = 2;
+ private static final String IFC_CTX_NAME = "ifc-test-instance";
private NamingContext interfacesContext;
@@ -79,23 +71,13 @@ public class Ipv4AddressCustomizerTest extends ListReaderCustomizerTest<Address,
@Override
public void setUpBefore() {
- interfacesContext = new NamingContext("generatedIfaceName", "test-instance");
+ 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);
}
@Override
protected ReaderCustomizer<Address, AddressBuilder> initCustomizer() {
- final KeyedInstanceIdentifier<Mapping, MappingKey> eth0Id = getMappingIid(IFACE_NAME, "test-instance");
- final KeyedInstanceIdentifier<Mapping, MappingKey> eth1Id = getMappingIid(IFACE_2_NAME, "test-instance");
- final Optional<Mapping> eth0 = getMapping(IFACE_NAME, IFACE_ID);
- final Optional<Mapping> eth1 = getMapping(IFACE_2_NAME, IFACE_2_ID);
-
- final List<Mapping> allMappings = Lists.newArrayList(eth0.get(), eth1.get());
- final Mappings allMappingsBaObject = new MappingsBuilder().setMapping(allMappings).build();
- doReturn(Optional.of(allMappingsBaObject)).when(mappingContext).read(eth0Id.firstIdentifierOf(Mappings.class));
-
- doReturn(eth0).when(mappingContext).read(eth0Id);
- doReturn(eth1).when(mappingContext).read(eth1Id);
-
return new Ipv4AddressCustomizer(api, interfacesContext);
}
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 6566dfe0b..05e48eeee 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
@@ -21,26 +21,18 @@ import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
-import com.google.common.base.Optional;
-import com.google.common.collect.Lists;
import io.fd.honeycomb.notification.NotificationCollector;
import io.fd.honeycomb.translate.MappingContext;
import io.fd.honeycomb.translate.v3po.test.ContextTestUtils;
import io.fd.honeycomb.translate.v3po.util.NamingContext;
-import java.util.List;
import java.util.concurrent.CompletableFuture;
import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
-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.MappingKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.InterfaceStateChange;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.InterfaceStatus;
-import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
import org.openvpp.jvpp.core.callback.SwInterfaceSetFlagsNotificationCallback;
import org.openvpp.jvpp.core.dto.SwInterfaceSetFlagsNotification;
import org.openvpp.jvpp.core.dto.WantInterfaceEvents;
@@ -50,9 +42,13 @@ import org.openvpp.jvpp.core.notification.CoreNotificationRegistry;
public class InterfaceChangeNotificationProducerTest {
+ private static final String IFC_CTX_NAME = "ifc-test-instance";
+ private static final String IFACE_NAME = "eth0";
+ private static final int IFACE_ID = 0;
+
@Mock
private FutureJVppCore jVpp;
- private NamingContext namingContext = new NamingContext("test", "test-instance");
+ private NamingContext namingContext = new NamingContext("test", IFC_CTX_NAME);
@Mock
private MappingContext mappingContext;
@Mock
@@ -71,16 +67,7 @@ public class InterfaceChangeNotificationProducerTest {
callbackArgumentCaptor = ArgumentCaptor.forClass(SwInterfaceSetFlagsNotificationCallback.class);
doReturn(notificationListenerReg).when(notificationRegistry).registerSwInterfaceSetFlagsNotificationCallback(
callbackArgumentCaptor.capture());
-
- final KeyedInstanceIdentifier<Mapping, MappingKey> eth0Id = ContextTestUtils
- .getMappingIid("eth0", "test-instance");
- final Optional<Mapping> eth0 = ContextTestUtils.getMapping("eth0", 0);
-
- final List<Mapping> allMappings = Lists.newArrayList(ContextTestUtils.getMapping("eth0", 0).get());
- final Mappings allMappingsBaObject = new MappingsBuilder().setMapping(allMappings).build();
- doReturn(Optional.of(allMappingsBaObject)).when(mappingContext).read(eth0Id.firstIdentifierOf(Mappings.class));
-
- doReturn(eth0).when(mappingContext).read(eth0Id);
+ ContextTestUtils.mockMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME);
}
@Test
@@ -114,16 +101,15 @@ public class InterfaceChangeNotificationProducerTest {
final SwInterfaceSetFlagsNotification swInterfaceSetFlagsNotification = new SwInterfaceSetFlagsNotification();
swInterfaceSetFlagsNotification.deleted = 0;
- swInterfaceSetFlagsNotification.swIfIndex = 0;
+ swInterfaceSetFlagsNotification.swIfIndex = IFACE_ID;
swInterfaceSetFlagsNotification.adminUpDown = 1;
swInterfaceSetFlagsNotification.linkUpDown = 1;
-
callbackArgumentCaptor.getValue().onSwInterfaceSetFlagsNotification(swInterfaceSetFlagsNotification);
final ArgumentCaptor<InterfaceStateChange> notificationCaptor =
ArgumentCaptor.forClass(InterfaceStateChange.class);
verify(collector).onNotification(notificationCaptor.capture());
- assertEquals("eth0", notificationCaptor.getValue().getName().getString());
+ assertEquals(IFACE_NAME, notificationCaptor.getValue().getName().getString());
assertEquals(InterfaceStatus.Up, notificationCaptor.getValue().getAdminStatus());
assertEquals(InterfaceStatus.Up, notificationCaptor.getValue().getOperStatus());
}
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
index 3b637a44c..9bfcd4d82 100644
--- 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
@@ -45,14 +45,8 @@ public class ContextTestUtils {
new NamingContextKey(namingContextName)).child(Mappings.class).child(Mapping.class, new MappingKey(name));
}
- 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);
+ 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());
@@ -61,10 +55,32 @@ public class ContextTestUtils {
mappingsBuilder.setMapping(Lists.newArrayList());
}
- final List<Mapping> mappingList = mappingsBuilder.getMapping();
+ 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(mappingsBuilder.setMapping(mappingList).build()))
+
+ 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/BridgeDomainCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/vpp/BridgeDomainCustomizerTest.java
index 6851bce22..d7a208f0d 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
@@ -26,14 +26,13 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.mockito.MockitoAnnotations.initMocks;
-import com.google.common.base.Optional;
+import io.fd.honeycomb.translate.MappingContext;
import io.fd.honeycomb.translate.ModificationCache;
import io.fd.honeycomb.translate.v3po.test.ContextTestUtils;
import io.fd.honeycomb.translate.v3po.test.TestHelperUtils;
import io.fd.honeycomb.translate.v3po.util.NamingContext;
import io.fd.honeycomb.translate.write.WriteContext;
import io.fd.honeycomb.translate.write.WriteFailedException;
-import io.fd.honeycomb.translate.MappingContext;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
import java.util.concurrent.ExecutionException;
@@ -41,8 +40,6 @@ import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
-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.mappings.MappingBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.bridge.domains.BridgeDomain;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.bridge.domains.BridgeDomainBuilder;
import org.openvpp.jvpp.VppInvocationException;
@@ -52,6 +49,8 @@ import org.openvpp.jvpp.core.future.FutureJVppCore;
public class BridgeDomainCustomizerTest {
+ private static final String BD_CTX_NAME = "bd-test-instance";
+
private static final byte ADD_OR_UPDATE_BD = (byte) 1;
private static final byte ZERO = 0;
@@ -68,12 +67,11 @@ public class BridgeDomainCustomizerTest {
public void setUp() throws Exception {
initMocks(this);
// TODO HONEYCOMB-116 create base class for tests using vppApi
- NamingContext namingContext = new NamingContext("generatedBDName", "test-instance");
final ModificationCache toBeReturned = new ModificationCache();
doReturn(toBeReturned).when(ctx).getModificationCache();
doReturn(mappingContext).when(ctx).getMappingContext();
- customizer = new BridgeDomainCustomizer(api, namingContext);
+ customizer = new BridgeDomainCustomizer(api, new NamingContext("generatedBDName", BD_CTX_NAME));
}
private BridgeDomain generateBridgeDomain(final String bdName) {
@@ -152,12 +150,7 @@ public class BridgeDomainCustomizerTest {
final int bdId = 1;
final String bdName = "bd1";
final BridgeDomain bd = generateBridgeDomain(bdName);
- // Make bdContext.containsName() return false
- doReturn(Optional.absent()).when(mappingContext)
- .read(ContextTestUtils.getMappingIid(bdName, "test-instance").firstIdentifierOf(Mappings.class));
- // Make bdContext.containsIndex() return false
- doReturn(Optional.absent()).when(mappingContext)
- .read(ContextTestUtils.getMappingIid(bdName, "test-instance"));
+ ContextTestUtils.mockEmptyMapping(mappingContext, bdName, BD_CTX_NAME);
whenBridgeDomainAddDelThenSuccess();
@@ -165,7 +158,7 @@ public class BridgeDomainCustomizerTest {
verifyBridgeDomainAddOrUpdateWasInvoked(bd, bdId);
verify(mappingContext).put(
- ContextTestUtils.getMappingIid(bdName, "test-instance"), ContextTestUtils.getMapping(bdName, bdId).get());
+ ContextTestUtils.getMappingIid(bdName, BD_CTX_NAME), ContextTestUtils.getMapping(bdName, bdId).get());
}
@Test
@@ -173,9 +166,7 @@ public class BridgeDomainCustomizerTest {
final int bdId = 1;
final String bdName = "bd1";
final BridgeDomain bd = generateBridgeDomain(bdName);
- // Make bdContext.containsIndex() return true
- doReturn(Optional.of(new MappingBuilder().setIndex(bdId).build())).when(mappingContext)
- .read(ContextTestUtils.getMappingIid(bdName, "test-instance"));
+ ContextTestUtils.mockMapping(mappingContext, bdName, bdId, BD_CTX_NAME);
whenBridgeDomainAddDelThenSuccess();
@@ -183,7 +174,7 @@ public class BridgeDomainCustomizerTest {
verifyBridgeDomainAddOrUpdateWasInvoked(bd, bdId);
verify(mappingContext).put(
- ContextTestUtils.getMappingIid(bdName, "test-instance"), ContextTestUtils.getMapping(bdName, bdId).get());
+ ContextTestUtils.getMappingIid(bdName, BD_CTX_NAME), ContextTestUtils.getMapping(bdName, bdId).get());
}
@Test
@@ -191,13 +182,7 @@ public class BridgeDomainCustomizerTest {
final int bdId = 1;
final String bdName = "bd1";
final BridgeDomain bd = generateBridgeDomain(bdName);
-
- // Returning no Mappings for "test-instance" makes bdContext.containsName() return false
- doReturn(Optional.absent()).when(mappingContext)
- .read(ContextTestUtils.getMappingIid(bdName, "test-instance").firstIdentifierOf(Mappings.class));
- // Make bdContext.containsIndex() return false
- doReturn(Optional.absent()).when(mappingContext)
- .read(ContextTestUtils.getMappingIid(bdName, "test-instance"));
+ ContextTestUtils.mockEmptyMapping(mappingContext, bdName, BD_CTX_NAME);
whenBridgeDomainAddDelThenFailure();
@@ -215,8 +200,7 @@ public class BridgeDomainCustomizerTest {
final int bdId = 1;
final String bdName = "bd1";
final BridgeDomain bd = generateBridgeDomain(bdName);
- doReturn(ContextTestUtils.getMapping(bdName, bdId)).when(mappingContext).read(
- ContextTestUtils.getMappingIid(bdName, "test-instance"));
+ ContextTestUtils.mockMapping(mappingContext, bdName, bdId, BD_CTX_NAME);
whenBridgeDomainAddDelThenSuccess();
@@ -229,7 +213,7 @@ public class BridgeDomainCustomizerTest {
public void testDeleteUnknownBridgeDomain() throws Exception {
final String bdName = "bd1";
final BridgeDomain bd = generateBridgeDomain("bd1");
- doReturn(Optional.absent()).when(mappingContext).read(ContextTestUtils.getMappingIid(bdName, "test-instance"));
+ ContextTestUtils.mockEmptyMapping(mappingContext, bdName, BD_CTX_NAME);
try {
customizer.deleteCurrentAttributes(BridgeDomainTestUtils.bdIdentifierForName(bdName), bd, ctx);
@@ -245,8 +229,7 @@ public class BridgeDomainCustomizerTest {
final int bdId = 1;
final String bdName = "bd1";
final BridgeDomain bd = generateBridgeDomain(bdName);
- doReturn(ContextTestUtils.getMapping(bdName, bdId)).when(mappingContext).read(
- ContextTestUtils.getMappingIid(bdName, "test-instance"));
+ ContextTestUtils.mockMapping(mappingContext, bdName, bdId, BD_CTX_NAME);
whenBridgeDomainAddDelThenFailure();
@@ -264,8 +247,7 @@ public class BridgeDomainCustomizerTest {
public void testUpdateBridgeDomain() throws Exception {
final int bdId = 1;
final String bdName = "bd1";
- doReturn(ContextTestUtils.getMapping(bdName, bdId)).when(mappingContext).read(
- ContextTestUtils.getMappingIid(bdName, "test-instance"));
+ ContextTestUtils.mockMapping(mappingContext, bdName, bdId, BD_CTX_NAME);
final byte arpTermBefore = 1;
final byte floodBefore = 1;
@@ -291,7 +273,7 @@ public class BridgeDomainCustomizerTest {
final String bdName = "bd1";
final BridgeDomain bdBefore = generateBridgeDomain(bdName, 0, 1, 0, 1, 0);
final BridgeDomain bdAfter = generateBridgeDomain(bdName, 1, 1, 0, 1, 0);
- doReturn(Optional.absent()).when(mappingContext).read(ContextTestUtils.getMappingIid(bdName, "test-instance"));
+ ContextTestUtils.mockEmptyMapping(mappingContext, bdName, BD_CTX_NAME);
try {
customizer
@@ -309,8 +291,7 @@ public class BridgeDomainCustomizerTest {
final String bdName = "bd1";
final BridgeDomain bdBefore = generateBridgeDomain(bdName, 0, 1, 0, 1, 0);
final BridgeDomain bdAfter = generateBridgeDomain(bdName, 1, 1, 0, 1, 0);
- doReturn(ContextTestUtils.getMapping(bdName, bdId)).when(mappingContext).read(
- ContextTestUtils.getMappingIid(bdName, "test-instance"));
+ ContextTestUtils.mockMapping(mappingContext, bdName, bdId, BD_CTX_NAME);
whenBridgeDomainAddDelThenFailure();
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/vpp/BridgeDomainTestUtils.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/vpp/BridgeDomainTestUtils.java
index 9ffc4edaa..1c49a9c62 100644
--- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/vpp/BridgeDomainTestUtils.java
+++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/vpp/BridgeDomainTestUtils.java
@@ -17,8 +17,6 @@
package io.fd.honeycomb.translate.v3po.vpp;
import javax.annotation.Nullable;
-import org.mockito.invocation.InvocationOnMock;
-import org.mockito.stubbing.Answer;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.BridgeDomains;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.bridge.domains.BridgeDomain;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.bridge.domains.BridgeDomainKey;
@@ -46,19 +44,8 @@ final class BridgeDomainTestUtils {
return null;
}
- public static int bdNameToID(String bName) {
- return Integer.parseInt(((Character)bName.charAt(bName.length() - 1)).toString());
- }
-
public static KeyedInstanceIdentifier<BridgeDomain, BridgeDomainKey> bdIdentifierForName(
final String bdName) {
return InstanceIdentifier.create(BridgeDomains.class).child(BridgeDomain.class, new BridgeDomainKey(bdName));
}
-
- public static final Answer<Integer> BD_NAME_TO_ID_ANSWER = new Answer<Integer>() {
- @Override
- public Integer answer(final InvocationOnMock invocationOnMock) throws Throwable {
- return bdNameToID((String) invocationOnMock.getArguments()[0]);
- }
- };
} \ No newline at end of file
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 7ca2bc155..c74423aba 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
@@ -79,7 +79,9 @@ public class L2FibEntryCustomizerTest {
initMocks(this);
doReturn(mappingContext).when(writeContext).getMappingContext();
bdContext = new NamingContext("generatedBdName", BD_CTX_NAME);
+ ContextTestUtils.mockMapping(mappingContext, BD_NAME, BD_ID, BD_CTX_NAME);
interfaceContext = new NamingContext("generatedIfaceName", IFC_CTX_NAME);
+ ContextTestUtils.mockMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME);
customizer = new L2FibEntryCustomizer(api, bdContext, interfaceContext);
}
@@ -145,9 +147,6 @@ public class L2FibEntryCustomizerTest {
final L2FibEntry entry = generateL2FibEntry(address);
final InstanceIdentifier<L2FibEntry> id = getL2FibEntryId(address);
- ContextTestUtils.mockMapping(mappingContext, BD_NAME, BD_ID, BD_CTX_NAME);
- ContextTestUtils.mockMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME);
-
whenL2FibAddDelThenSuccess();
customizer.writeCurrentAttributes(id, entry, writeContext);
@@ -162,9 +161,6 @@ public class L2FibEntryCustomizerTest {
final L2FibEntry entry = generateL2FibEntry(address);
final InstanceIdentifier<L2FibEntry> id = getL2FibEntryId(address);
- ContextTestUtils.mockMapping(mappingContext, BD_NAME, BD_ID, BD_CTX_NAME);
- ContextTestUtils.mockMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME);
-
whenL2FibAddDelThenFailure();
try {
@@ -190,9 +186,6 @@ public class L2FibEntryCustomizerTest {
final L2FibEntry entry = generateL2FibEntry(address);
final InstanceIdentifier<L2FibEntry> id = getL2FibEntryId(address);
- ContextTestUtils.mockMapping(mappingContext, BD_NAME, BD_ID, BD_CTX_NAME);
- ContextTestUtils.mockMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME);
-
whenL2FibAddDelThenSuccess();
customizer.deleteCurrentAttributes(id, entry, writeContext);
@@ -207,9 +200,6 @@ public class L2FibEntryCustomizerTest {
final L2FibEntry entry = generateL2FibEntry(address);
final InstanceIdentifier<L2FibEntry> id = getL2FibEntryId(address);
- ContextTestUtils.mockMapping(mappingContext, BD_NAME, BD_ID, BD_CTX_NAME);
- ContextTestUtils.mockMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME);
-
whenL2FibAddDelThenFailure();
try {
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 8e7e8bddc..4ccaa636b 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
@@ -65,6 +65,7 @@ public class L2FibEntryCustomizerTest extends ListReaderCustomizerTest<L2FibEntr
@Override
public void setUpBefore() {
bdContext = new NamingContext("generatedBdName", BD_CTX_NAME);
+ ContextTestUtils.mockMapping(mappingContext, BD_NAME, BD_ID, BD_CTX_NAME);
interfacesContext = new NamingContext("generatedIfaceName", IFC_CTX_NAME);
}
@@ -100,8 +101,6 @@ 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, BD_NAME, BD_ID, BD_CTX_NAME);
ContextTestUtils.mockMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME);
whenL2FibTableDumpThenReturn(Collections.singletonList(generateL2FibEntry(address_vpp)));
@@ -128,7 +127,6 @@ public class L2FibEntryCustomizerTest extends ListReaderCustomizerTest<L2FibEntr
public void testGetAllIds() throws Exception {
final long address_vpp = 0x0000112233445566L;
final PhysAddress address = new PhysAddress("11:22:33:44:55:66");
- ContextTestUtils.mockMapping(mappingContext, BD_NAME, BD_ID, BD_CTX_NAME);
whenL2FibTableDumpThenReturn(Collections.singletonList(generateL2FibEntry(address_vpp)));
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/vppstate/VersionCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/vppstate/VersionCustomizerTest.java
index aa4d4326c..1e0ff2429 100644
--- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/vppstate/VersionCustomizerTest.java
+++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/vppstate/VersionCustomizerTest.java
@@ -55,10 +55,10 @@ public class VersionCustomizerTest extends ReaderCustomizerTest<Version, Version
public void testReadCurrentAttributes() throws Exception {
final CompletableFuture<ShowVersionReply> replyFuture = new CompletableFuture<>();
final ShowVersionReply reply = new ShowVersionReply();
- reply.version = new byte[]{};
- reply.program = new byte[]{};
- reply.buildDate = new byte[]{};
- reply.buildDirectory = new byte[]{};
+ reply.version = new byte[] {};
+ reply.program = new byte[] {};
+ reply.buildDate = new byte[] {};
+ reply.buildDirectory = new byte[] {};
replyFuture.complete(reply);
when(api.showVersion(any(ShowVersion.class))).thenReturn(replyFuture);
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 208fa2d8c..6b7ab71a2 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
@@ -73,6 +73,7 @@ import org.openvpp.jvpp.core.future.FutureJVppCore;
public class VppStateTest {
+ private static final String BD_CTX_NAME = "bd-test-instance";
@Mock
private FutureJVppCore api;
@Mock
@@ -92,7 +93,7 @@ public class VppStateTest {
doReturn(cache).when(ctx).getModificationCache();
doReturn(mappingContext).when(ctx).getMappingContext();
- bdContext = new NamingContext("generatedBdName", "bd-test-instance");
+ bdContext = new NamingContext("generatedBdName", BD_CTX_NAME);
interfaceContext = new NamingContext("generatedIfaceName", "ifc-test-instance");
readerRegistry = VppStateTestUtils.getVppStateReader(api, bdContext);
}
@@ -239,7 +240,7 @@ public class VppStateTest {
}
private void mockBdMapping(final BridgeDomainDetails bd, final String bdName) {
- ContextTestUtils.mockMapping(mappingContext, bdName, bd.bdId, "bd-test-instance");
+ ContextTestUtils.mockMapping(mappingContext, bdName, bd.bdId, BD_CTX_NAME);
}
@Test
@@ -286,13 +287,11 @@ public class VppStateTest {
@Test(expected = ReadFailedException.class)
public void testReadBridgeDomainNotExisting() throws Exception {
- doReturn(Optional.absent()).when(mappingContext).read(
- ContextTestUtils.getMappingIid("NOT EXISTING", "bd-test-instance"));
+ final String nonExistingBdName = "NOT EXISTING";
+ ContextTestUtils.mockEmptyMapping(mappingContext, nonExistingBdName, BD_CTX_NAME);
- final Optional<? extends DataObject> read =
- readerRegistry.read(InstanceIdentifier.create(VppState.class).child(BridgeDomains.class).child(
- BridgeDomain.class, new BridgeDomainKey("NOT EXISTING")), ctx);
- assertFalse(read.isPresent());
+ readerRegistry.read(InstanceIdentifier.create(VppState.class).child(BridgeDomains.class).child(
+ BridgeDomain.class, new BridgeDomainKey(nonExistingBdName)), ctx);
}
@Test