diff options
Diffstat (limited to 'v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces')
9 files changed, 112 insertions, 158 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(); |