From 7ad1eb51710b65fdad35fab04122de4eb887e541 Mon Sep 17 00:00:00 2001 From: Marek Gradzki Date: Fri, 23 Sep 2016 09:06:19 +0200 Subject: HONEYCOMB-116: utility for stubbing MappingContext methods - introduces MappingContextHelper (refactored ContextTestUtils) - updates all v3po and lisp unit tests to use MCH - updates lisp tests to mock EidMappingContext Change-Id: I73b1adda767db71388ca1c4d7206cfd7ee9c70e1 Signed-off-by: Marek Gradzki --- .../v3po/interfaces/AclCustomizerTest.java | 3 +- .../v3po/interfaces/GreCustomizerTest.java | 26 +++---- .../v3po/interfaces/RewriteCustomizerTest.java | 3 +- .../interfaces/SubInterfaceCustomizerTest.java | 17 ++--- .../v3po/interfaces/TapCustomizerTest.java | 19 +++-- .../v3po/interfaces/VhostUserCustomizerTest.java | 19 +++-- .../v3po/interfaces/VxlanCustomizerTest.java | 27 +++---- .../v3po/interfaces/VxlanGpeCustomizerTest.java | 29 ++++---- .../interfaces/ip/Ipv4AddressCustomizerTest.java | 15 ++-- .../interfaces/ip/Ipv4NeighbourCustomizerTest.java | 3 +- .../v3po/interfacesstate/AclCustomizerTest.java | 3 +- .../v3po/interfacesstate/GreCustomizerTest.java | 3 +- .../interfacesstate/InterfaceCustomizerTest.java | 7 +- .../v3po/interfacesstate/L2CustomizerTest.java | 5 +- .../interfacesstate/RewriteCustomizerTest.java | 3 +- .../SubInterfaceCustomizerTest.java | 9 +-- .../v3po/interfacesstate/VxlanCustomizerTest.java | 3 +- .../interfacesstate/VxlanGpeCustomizerTest.java | 3 +- .../ip/Ipv4AddressCustomizerTest.java | 5 +- .../InterfaceChangeNotificationProducerTest.java | 6 +- .../translate/v3po/test/ContextTestUtils.java | 86 ---------------------- .../ArpTerminationTableEntryCustomizerTest.java | 5 +- .../v3po/vpp/BridgeDomainCustomizerTest.java | 25 +++---- .../v3po/vpp/L2FibEntryCustomizerTest.java | 5 +- .../v3po/vppstate/L2FibEntryCustomizerTest.java | 5 +- .../translate/v3po/vppstate/VppStateTest.java | 10 +-- 26 files changed, 113 insertions(+), 231 deletions(-) delete mode 100644 v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/test/ContextTestUtils.java (limited to 'v3po/v3po2vpp/src/test/java/io/fd') diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/AclCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/AclCustomizerTest.java index b55a5ce2b..5de6e5e73 100644 --- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/AclCustomizerTest.java +++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/AclCustomizerTest.java @@ -22,7 +22,6 @@ import static org.mockito.Matchers.any; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.verify; -import io.fd.honeycomb.translate.v3po.test.ContextTestUtils; import io.fd.honeycomb.translate.v3po.util.NamingContext; import io.fd.honeycomb.translate.v3po.vppclassifier.VppClassifierContextManager; import io.fd.honeycomb.translate.write.WriteFailedException; @@ -58,7 +57,7 @@ public class AclCustomizerTest extends WriterCustomizerTest { @Override public void setUp() { - ContextTestUtils.mockMapping(mappingContext, IF_NAME, IF_INDEX, IFC_TEST_INSTANCE); + defineMapping(mappingContext, IF_NAME, IF_INDEX, IFC_TEST_INSTANCE); customizer = new AclCustomizer(api, new NamingContext("generatedInterfaceName", IFC_TEST_INSTANCE), classifyTableContext); } diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/GreCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/GreCustomizerTest.java index 6918e1f01..1a8aec645 100644 --- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/GreCustomizerTest.java +++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/GreCustomizerTest.java @@ -16,10 +16,6 @@ package io.fd.honeycomb.translate.v3po.interfaces; -import static io.fd.honeycomb.translate.v3po.test.ContextTestUtils.getMapping; -import static io.fd.honeycomb.translate.v3po.test.ContextTestUtils.getMappingIid; -import static io.fd.honeycomb.translate.v3po.test.ContextTestUtils.mockEmptyMapping; -import static io.fd.honeycomb.translate.v3po.test.ContextTestUtils.mockMapping; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -116,12 +112,12 @@ public class GreCustomizerTest extends WriterCustomizerTest { whenGreAddDelTunnelThenSuccess(); - mockEmptyMapping(mappingContext, IFACE_NAME, IFC_TEST_INSTANCE); + noMappingDefined(mappingContext, IFACE_NAME, IFC_TEST_INSTANCE); customizer.writeCurrentAttributes(id, gre, writeContext); verifyGreAddWasInvoked(gre); - verify(mappingContext).put(eq(getMappingIid(IFACE_NAME, IFC_TEST_INSTANCE)), - eq(getMapping(IFACE_NAME, IFACE_ID).get())); + verify(mappingContext).put(eq(mappingIid(IFACE_NAME, IFC_TEST_INSTANCE)), + eq(mapping(IFACE_NAME, IFACE_ID).get())); } @Test @@ -129,14 +125,14 @@ public class GreCustomizerTest extends WriterCustomizerTest { final Gre gre = generateGre(); whenGreAddDelTunnelThenSuccess(); - mockMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_TEST_INSTANCE); + defineMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_TEST_INSTANCE); customizer.writeCurrentAttributes(id, gre, writeContext); verifyGreAddWasInvoked(gre); // Remove the first mapping before putting in the new one - verify(mappingContext).delete(eq(getMappingIid(IFACE_NAME, IFC_TEST_INSTANCE))); - verify(mappingContext).put(eq(getMappingIid(IFACE_NAME, IFC_TEST_INSTANCE)), eq(getMapping(IFACE_NAME, IFACE_ID).get())); + verify(mappingContext).delete(eq(mappingIid(IFACE_NAME, IFC_TEST_INSTANCE))); + verify(mappingContext).put(eq(mappingIid(IFACE_NAME, IFC_TEST_INSTANCE)), eq(mapping(IFACE_NAME, IFACE_ID).get())); } @Test @@ -151,7 +147,7 @@ public class GreCustomizerTest extends WriterCustomizerTest { assertTrue(e.getCause() instanceof VppBaseCallException); verifyGreAddWasInvoked(gre); // Mapping not stored due to failure - verify(mappingContext, times(0)).put(eq(getMappingIid(IFACE_NAME, IFC_TEST_INSTANCE)), eq(getMapping( + verify(mappingContext, times(0)).put(eq(mappingIid(IFACE_NAME, IFC_TEST_INSTANCE)), eq(mapping( IFACE_NAME, 0).get())); return; } @@ -174,11 +170,11 @@ public class GreCustomizerTest extends WriterCustomizerTest { final Gre gre = generateGre(); whenGreAddDelTunnelThenSuccess(); - mockMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_TEST_INSTANCE); + defineMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_TEST_INSTANCE); customizer.deleteCurrentAttributes(id, gre, writeContext); verifyGreDeleteWasInvoked(gre); - verify(mappingContext).delete(eq(getMappingIid(IFACE_NAME, IFC_TEST_INSTANCE))); + verify(mappingContext).delete(eq(mappingIid(IFACE_NAME, IFC_TEST_INSTANCE))); } @Test @@ -186,14 +182,14 @@ public class GreCustomizerTest extends WriterCustomizerTest { final Gre gre = generateGre(); whenGreAddDelTunnelThenFailure(); - mockMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_TEST_INSTANCE); + defineMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_TEST_INSTANCE); try { customizer.deleteCurrentAttributes(id, gre, writeContext); } catch (WriteFailedException.DeleteFailedException e) { assertTrue(e.getCause() instanceof VppBaseCallException); verifyGreDeleteWasInvoked(gre); - verify(mappingContext, times(0)).delete(eq(getMappingIid(IFACE_NAME, IFC_TEST_INSTANCE))); + verify(mappingContext, times(0)).delete(eq(mappingIid(IFACE_NAME, IFC_TEST_INSTANCE))); return; } fail("WriteFailedException.DeleteFailedException was expected"); diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/RewriteCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/RewriteCustomizerTest.java index e28a0f6c6..d6d1631bb 100644 --- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/RewriteCustomizerTest.java +++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/RewriteCustomizerTest.java @@ -22,7 +22,6 @@ import static org.mockito.Matchers.any; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.verify; -import io.fd.honeycomb.translate.v3po.test.ContextTestUtils; import io.fd.honeycomb.translate.v3po.util.NamingContext; import io.fd.honeycomb.translate.v3po.util.TagRewriteOperation; import io.fd.honeycomb.translate.write.WriteFailedException; @@ -63,7 +62,7 @@ public class RewriteCustomizerTest extends WriterCustomizerTest { namingContext = new NamingContext("generatedSubInterfaceName", IFC_TEST_INSTANCE); customizer = new RewriteCustomizer(api, namingContext); VLAN_IID = getVlanTagRewriteId(IF_NAME, VLAN_IF_ID); - ContextTestUtils.mockMapping(mappingContext, VLAN_IF_NAME, VLAN_IF_INDEX, IFC_TEST_INSTANCE); + defineMapping(mappingContext, VLAN_IF_NAME, VLAN_IF_INDEX, IFC_TEST_INSTANCE); } private static InstanceIdentifier getVlanTagRewriteId(final String name, final long index) { diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/SubInterfaceCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/SubInterfaceCustomizerTest.java index 1fee0b3cf..86af0f094 100644 --- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/SubInterfaceCustomizerTest.java +++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/SubInterfaceCustomizerTest.java @@ -25,7 +25,6 @@ import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; -import io.fd.honeycomb.translate.v3po.test.ContextTestUtils; import io.fd.honeycomb.translate.v3po.util.NamingContext; import io.fd.honeycomb.translate.write.WriteFailedException; import io.fd.honeycomb.vpp.test.write.WriterCustomizerTest; @@ -91,8 +90,8 @@ public class SubInterfaceCustomizerTest extends WriterCustomizerTest { public void setUp() throws Exception { namingContext = new NamingContext("generatedSubInterfaceName", IFC_TEST_INSTANCE); customizer = new SubInterfaceCustomizer(api, namingContext); - ContextTestUtils.mockMapping(mappingContext, SUB_IFACE_NAME, SUBIF_INDEX, IFC_TEST_INSTANCE); - ContextTestUtils.mockMapping(mappingContext, SUPER_IF_NAME, SUPER_IF_ID, IFC_TEST_INSTANCE); + defineMapping(mappingContext, SUB_IFACE_NAME, SUBIF_INDEX, IFC_TEST_INSTANCE); + defineMapping(mappingContext, SUPER_IF_NAME, SUPER_IF_ID, IFC_TEST_INSTANCE); } private SubInterface generateSubInterface(final boolean enabled, final List tagList) { @@ -198,8 +197,8 @@ public class SubInterfaceCustomizerTest extends WriterCustomizerTest { verify(api).createSubif(generateSubInterfaceRequest(SUPER_IF_ID, CTAG_ID, false)); verify(mappingContext) - .put(eq(ContextTestUtils.getMappingIid(SUB_IFACE_NAME, IFC_TEST_INSTANCE)), eq( - ContextTestUtils.getMapping(SUB_IFACE_NAME, 0).get())); + .put(eq(mappingIid(SUB_IFACE_NAME, IFC_TEST_INSTANCE)), eq( + mapping(SUB_IFACE_NAME, 0).get())); } @Test @@ -214,8 +213,8 @@ public class SubInterfaceCustomizerTest extends WriterCustomizerTest { verify(api).createSubif(generateSubInterfaceRequest(SUPER_IF_ID, CTAG_ANY_ID, true)); verify(mappingContext) - .put(eq(ContextTestUtils.getMappingIid(SUB_IFACE_NAME, IFC_TEST_INSTANCE)), eq( - ContextTestUtils.getMapping(SUB_IFACE_NAME, 0).get())); + .put(eq(mappingIid(SUB_IFACE_NAME, IFC_TEST_INSTANCE)), eq( + mapping(SUB_IFACE_NAME, 0).get())); } @Test @@ -231,8 +230,8 @@ public class SubInterfaceCustomizerTest extends WriterCustomizerTest { assertTrue(e.getCause() instanceof VppBaseCallException); verify(api).createSubif(generateSubInterfaceRequest(SUPER_IF_ID, CTAG_ID, false)); verify(mappingContext, times(0)).put( - eq(ContextTestUtils.getMappingIid(SUPER_IF_NAME, IFC_TEST_INSTANCE)), - eq(ContextTestUtils.getMapping(SUPER_IF_NAME, 0).get())); + eq(mappingIid(SUPER_IF_NAME, IFC_TEST_INSTANCE)), + eq(mapping(SUPER_IF_NAME, 0).get())); return; } fail("WriteFailedException.CreateFailedException was expected"); diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/TapCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/TapCustomizerTest.java index c2c687602..88232d55f 100644 --- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/TapCustomizerTest.java +++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/TapCustomizerTest.java @@ -23,7 +23,6 @@ import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; -import io.fd.honeycomb.translate.v3po.test.ContextTestUtils; import io.fd.honeycomb.translate.v3po.util.NamingContext; import io.fd.honeycomb.vpp.test.write.WriterCustomizerTest; import org.junit.Test; @@ -74,10 +73,10 @@ public class TapCustomizerTest extends WriterCustomizerTest { tapCustomizer.writeCurrentAttributes(getTapId("tap2"), getTapData("tap2", "ff:ff:ff:ff:ff:ff"), writeContext); verify(api, times(2)).tapConnect(any(TapConnect.class)); - verify(mappingContext).put(eq(ContextTestUtils.getMappingIid("tap", IFC_TEST_INSTANCE)), eq( - ContextTestUtils.getMapping("tap", 0).get())); - verify(mappingContext).put(eq(ContextTestUtils.getMappingIid("tap2", IFC_TEST_INSTANCE)), eq( - ContextTestUtils.getMapping("tap2", 1).get())); + verify(mappingContext).put(eq(mappingIid("tap", IFC_TEST_INSTANCE)), eq( + mapping("tap", 0).get())); + verify(mappingContext).put(eq(mappingIid("tap2", IFC_TEST_INSTANCE)), eq( + mapping("tap2", 1).get())); } @Test @@ -92,14 +91,14 @@ public class TapCustomizerTest extends WriterCustomizerTest { tapCustomizer.writeCurrentAttributes(getTapId("tap"), getTapData("tap", "ff:ff:ff:ff:ff:ff"), writeContext); - ContextTestUtils.mockMapping(mappingContext, "tap", 1, IFC_TEST_INSTANCE); + defineMapping(mappingContext, "tap", 1, IFC_TEST_INSTANCE); tapCustomizer.updateCurrentAttributes(getTapId("tap"), getTapData("tap", "ff:ff:ff:ff:ff:ff"), getTapData("tap", "ff:ff:ff:ff:ff:f1"), writeContext); verify(api).tapConnect(any(TapConnect.class)); verify(api).tapModify(any(TapModify.class)); - verify(mappingContext).put(eq(ContextTestUtils.getMappingIid("tap", IFC_TEST_INSTANCE)), eq( - ContextTestUtils.getMapping("tap", 0).get())); + verify(mappingContext).put(eq(mappingIid("tap", IFC_TEST_INSTANCE)), eq( + mapping("tap", 0).get())); } @Test @@ -111,12 +110,12 @@ public class TapCustomizerTest extends WriterCustomizerTest { doReturn(future(new TapDeleteReply())).when(api).tapDelete(any(TapDelete.class)); tapCustomizer.writeCurrentAttributes(getTapId("tap"), getTapData("tap", "ff:ff:ff:ff:ff:ff"), writeContext); - ContextTestUtils.mockMapping(mappingContext, "tap", 1, IFC_TEST_INSTANCE); + defineMapping(mappingContext, "tap", 1, IFC_TEST_INSTANCE); tapCustomizer.deleteCurrentAttributes(getTapId("tap"), getTapData("tap", "ff:ff:ff:ff:ff:ff"), writeContext); verify(api).tapConnect(any(TapConnect.class)); verify(api).tapDelete(any(TapDelete.class)); - verify(mappingContext).delete(eq(ContextTestUtils.getMappingIid("tap", IFC_TEST_INSTANCE))); + verify(mappingContext).delete(eq(mappingIid("tap", IFC_TEST_INSTANCE))); } private InstanceIdentifier getTapId(final String tap) { diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/VhostUserCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/VhostUserCustomizerTest.java index a47f5b641..176f3209c 100644 --- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/VhostUserCustomizerTest.java +++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/VhostUserCustomizerTest.java @@ -29,7 +29,6 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyZeroInteractions; import static org.mockito.Mockito.when; -import io.fd.honeycomb.translate.v3po.test.ContextTestUtils; import io.fd.honeycomb.translate.v3po.util.Ipv4Translator; import io.fd.honeycomb.translate.v3po.util.NamingContext; import io.fd.honeycomb.translate.write.WriteFailedException; @@ -121,8 +120,8 @@ public class VhostUserCustomizerTest extends WriterCustomizerTest implements Ipv customizer.writeCurrentAttributes(ID, vhostUser, writeContext); verifyCreateVhostUserIfWasInvoked(vhostUser); - verify(mappingContext).put(eq(ContextTestUtils.getMappingIid(IFACE_NAME, "test-instance")), eq( - ContextTestUtils.getMapping(IFACE_NAME, 0).get())); + verify(mappingContext).put(eq(mappingIid(IFACE_NAME, "test-instance")), eq( + mapping(IFACE_NAME, 0).get())); } @Test @@ -146,7 +145,7 @@ public class VhostUserCustomizerTest extends WriterCustomizerTest implements Ipv public void testUpdateCurrentAttributes() throws Exception { final VhostUser vhostUserBefore = generateVhostUser(VhostUserRole.Client, "socketName0"); final VhostUser vhostUserAfter = generateVhostUser(VhostUserRole.Server, "socketName1"); - ContextTestUtils.mockMapping(mappingContext, IFACE_NAME, IFACE_ID, "test-instance"); + defineMapping(mappingContext, IFACE_NAME, IFACE_ID, "test-instance"); when(api.modifyVhostUserIf(any(ModifyVhostUserIf.class))).thenReturn(future(new ModifyVhostUserIfReply())); @@ -158,7 +157,7 @@ public class VhostUserCustomizerTest extends WriterCustomizerTest implements Ipv public void testUpdateCurrentAttributesFailed() throws Exception { final VhostUser vhostUserBefore = generateVhostUser(VhostUserRole.Client, "socketName0"); final VhostUser vhostUserAfter = generateVhostUser(VhostUserRole.Server, "socketName1"); - ContextTestUtils.mockMapping(mappingContext, IFACE_NAME, IFACE_ID, "test-instance"); + defineMapping(mappingContext, IFACE_NAME, IFACE_ID, "test-instance"); doReturn(failedFuture()).when(api).modifyVhostUserIf(any(ModifyVhostUserIf.class)); @@ -175,19 +174,19 @@ public class VhostUserCustomizerTest extends WriterCustomizerTest implements Ipv @Test public void testDeleteCurrentAttributes() throws Exception { final VhostUser vhostUser = generateVhostUser(VhostUserRole.Client, "socketName"); - ContextTestUtils.mockMapping(mappingContext, IFACE_NAME, IFACE_ID, "test-instance"); + defineMapping(mappingContext, IFACE_NAME, IFACE_ID, "test-instance"); when(api.deleteVhostUserIf(any(DeleteVhostUserIf.class))).thenReturn(future(new DeleteVhostUserIfReply())); customizer.deleteCurrentAttributes(ID, vhostUser, writeContext); verifyDeleteVhostUserIfWasInvoked(IFACE_ID); - verify(mappingContext).delete(eq(ContextTestUtils.getMappingIid(IFACE_NAME, "test-instance"))); + verify(mappingContext).delete(eq(mappingIid(IFACE_NAME, "test-instance"))); } @Test public void testDeleteCurrentAttributesFailed() throws Exception { final VhostUser vhostUser = generateVhostUser(VhostUserRole.Client, "socketName"); - ContextTestUtils.mockMapping(mappingContext, IFACE_NAME, IFACE_ID, "test-instance"); + defineMapping(mappingContext, IFACE_NAME, IFACE_ID, "test-instance"); doReturn(failedFuture()).when(api).deleteVhostUserIf(any(DeleteVhostUserIf.class)); @@ -197,8 +196,8 @@ public class VhostUserCustomizerTest extends WriterCustomizerTest implements Ipv assertTrue(e.getCause() instanceof VppBaseCallException); verifyDeleteVhostUserIfWasInvoked(IFACE_ID); // Delete from context not invoked if delete from VPP failed - verify(mappingContext, times(0)).delete(eq(ContextTestUtils.getMappingIid(IFACE_NAME, "test-instance"))); - verify(mappingContext).read(eq(ContextTestUtils.getMappingIid(IFACE_NAME, "test-instance"))); + verify(mappingContext, times(0)).delete(eq(mappingIid(IFACE_NAME, "test-instance"))); + verify(mappingContext).read(eq(mappingIid(IFACE_NAME, "test-instance"))); return; } fail("WriteFailedException.DeleteFailedException was expected"); diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/VxlanCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/VxlanCustomizerTest.java index ed099f740..6bb8bd279 100644 --- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/VxlanCustomizerTest.java +++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/VxlanCustomizerTest.java @@ -16,8 +16,6 @@ package io.fd.honeycomb.translate.v3po.interfaces; -import static io.fd.honeycomb.translate.v3po.test.ContextTestUtils.getMapping; -import static io.fd.honeycomb.translate.v3po.test.ContextTestUtils.getMappingIid; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -31,7 +29,6 @@ import static org.mockito.Mockito.when; import com.google.common.net.InetAddresses; import io.fd.honeycomb.translate.v3po.DisabledInterfacesManager; -import io.fd.honeycomb.translate.v3po.test.ContextTestUtils; import io.fd.honeycomb.translate.v3po.util.NamingContext; import io.fd.honeycomb.translate.write.WriteFailedException; import io.fd.honeycomb.vpp.test.write.WriterCustomizerTest; @@ -129,11 +126,11 @@ public class VxlanCustomizerTest extends WriterCustomizerTest { final Vxlan vxlan = generateVxlan(); whenVxlanAddDelTunnelThenSuccess(); - ContextTestUtils.mockEmptyMapping(mappingContext, ifaceName, "test-instance"); + noMappingDefined(mappingContext, ifaceName, "test-instance"); customizer.writeCurrentAttributes(id, vxlan, writeContext); verifyVxlanAddWasInvoked(vxlan); - verify(mappingContext).put(eq(getMappingIid(ifaceName, "test-instance")), eq(getMapping(ifaceName, 0).get())); + verify(mappingContext).put(eq(mappingIid(ifaceName, "test-instance")), eq(mapping(ifaceName, 0).get())); } @Test @@ -141,12 +138,12 @@ public class VxlanCustomizerTest extends WriterCustomizerTest { final Vxlan vxlan = generateVxlan(); whenVxlanAddDelTunnelThenSuccess(); - ContextTestUtils.mockEmptyMapping(mappingContext, ifaceName, "test-instance"); + noMappingDefined(mappingContext, ifaceName, "test-instance"); doReturn(true).when(disableContext).isInterfaceDisabled(0, mappingContext); customizer.writeCurrentAttributes(id, vxlan, writeContext); verifyVxlanAddWasInvoked(vxlan); - verify(mappingContext).put(eq(getMappingIid(ifaceName, "test-instance")), eq(getMapping(ifaceName, 0).get())); + verify(mappingContext).put(eq(mappingIid(ifaceName, "test-instance")), eq(mapping(ifaceName, 0).get())); verify(disableContext).removeDisabledInterface(0, mappingContext); } @@ -156,15 +153,15 @@ public class VxlanCustomizerTest extends WriterCustomizerTest { final int ifaceId = 0; whenVxlanAddDelTunnelThenSuccess(); - ContextTestUtils.mockMapping(mappingContext, ifaceName, ifaceId, "test-instance"); + defineMapping(mappingContext, ifaceName, ifaceId, "test-instance"); customizer.writeCurrentAttributes(id, vxlan, writeContext); verifyVxlanAddWasInvoked(vxlan); // Remove the first mapping before putting in the new one - verify(mappingContext).delete(eq(getMappingIid(ifaceName, "test-instance"))); + verify(mappingContext).delete(eq(mappingIid(ifaceName, "test-instance"))); verify(mappingContext) - .put(eq(getMappingIid(ifaceName, "test-instance")), eq(getMapping(ifaceName, ifaceId).get())); + .put(eq(mappingIid(ifaceName, "test-instance")), eq(mapping(ifaceName, ifaceId).get())); } @Test @@ -180,7 +177,7 @@ public class VxlanCustomizerTest extends WriterCustomizerTest { verifyVxlanAddWasInvoked(vxlan); // Mapping not stored due to failure verify(mappingContext, times(0)) - .put(eq(getMappingIid(ifaceName, "test-instance")), eq(getMapping(ifaceName, 0).get())); + .put(eq(mappingIid(ifaceName, "test-instance")), eq(mapping(ifaceName, 0).get())); return; } fail("WriteFailedException.CreateFailedException was expected"); @@ -202,11 +199,11 @@ public class VxlanCustomizerTest extends WriterCustomizerTest { final Vxlan vxlan = generateVxlan(); whenVxlanAddDelTunnelThenSuccess(); - ContextTestUtils.mockMapping(mappingContext, ifaceName, 1, "test-instance"); + defineMapping(mappingContext, ifaceName, 1, "test-instance"); customizer.deleteCurrentAttributes(id, vxlan, writeContext); verifyVxlanDeleteWasInvoked(vxlan); - verify(mappingContext).delete(eq(getMappingIid(ifaceName, "test-instance"))); + verify(mappingContext).delete(eq(mappingIid(ifaceName, "test-instance"))); verify(disableContext).disableInterface(1, mappingContext); } @@ -215,14 +212,14 @@ public class VxlanCustomizerTest extends WriterCustomizerTest { final Vxlan vxlan = generateVxlan(); whenVxlanAddDelTunnelThenFailure(); - ContextTestUtils.mockMapping(mappingContext, ifaceName, 1, "test-instance"); + defineMapping(mappingContext, ifaceName, 1, "test-instance"); try { customizer.deleteCurrentAttributes(id, vxlan, writeContext); } catch (WriteFailedException.DeleteFailedException e) { assertTrue(e.getCause() instanceof VppBaseCallException); verifyVxlanDeleteWasInvoked(vxlan); - verify(mappingContext, times(0)).delete(eq(getMappingIid(ifaceName, "test-instance"))); + verify(mappingContext, times(0)).delete(eq(mappingIid(ifaceName, "test-instance"))); return; } fail("WriteFailedException.DeleteFailedException was expected"); diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/VxlanGpeCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/VxlanGpeCustomizerTest.java index 75e0d3bb1..d90aeb14d 100644 --- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/VxlanGpeCustomizerTest.java +++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/VxlanGpeCustomizerTest.java @@ -16,8 +16,6 @@ package io.fd.honeycomb.translate.v3po.interfaces; -import static io.fd.honeycomb.translate.v3po.test.ContextTestUtils.getMapping; -import static io.fd.honeycomb.translate.v3po.test.ContextTestUtils.getMappingIid; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -31,7 +29,6 @@ import static org.mockito.Mockito.when; import com.google.common.net.InetAddresses; import io.fd.honeycomb.translate.v3po.DisabledInterfacesManager; -import io.fd.honeycomb.translate.v3po.test.ContextTestUtils; import io.fd.honeycomb.translate.v3po.util.NamingContext; import io.fd.honeycomb.translate.write.WriteFailedException; import io.fd.honeycomb.vpp.test.write.WriterCustomizerTest; @@ -133,12 +130,12 @@ public class VxlanGpeCustomizerTest extends WriterCustomizerTest { final VxlanGpe vxlanGpe = generateVxlanGpe(); whenVxlanGpeAddDelTunnelThenSuccess(); - ContextTestUtils.mockEmptyMapping(mappingContext, ifaceName, "test-instance"); + noMappingDefined(mappingContext, ifaceName, "test-instance"); customizer.writeCurrentAttributes(id, vxlanGpe, writeContext); verifyVxlanGpeAddWasInvoked(vxlanGpe); - verify(mappingContext).put(eq(getMappingIid(ifaceName, "test-instance")), eq( - getMapping(ifaceName, 0).get())); + verify(mappingContext).put(eq(mappingIid(ifaceName, "test-instance")), eq( + mapping(ifaceName, 0).get())); } @Test @@ -147,15 +144,15 @@ public class VxlanGpeCustomizerTest extends WriterCustomizerTest { final int ifaceId = 0; whenVxlanGpeAddDelTunnelThenSuccess(); - ContextTestUtils.mockMapping(mappingContext, ifaceName, ifaceId, "test-instance"); + defineMapping(mappingContext, ifaceName, ifaceId, "test-instance"); customizer.writeCurrentAttributes(id, vxlanGpe, writeContext); verifyVxlanGpeAddWasInvoked(vxlanGpe); // Remove the first mapping before putting in the new one - verify(mappingContext).delete(eq(getMappingIid(ifaceName, "test-instance"))); - verify(mappingContext).put(eq(getMappingIid(ifaceName, "test-instance")), - eq(getMapping(ifaceName, ifaceId).get())); + verify(mappingContext).delete(eq(mappingIid(ifaceName, "test-instance"))); + verify(mappingContext).put(eq(mappingIid(ifaceName, "test-instance")), + eq(mapping(ifaceName, ifaceId).get())); } @Test @@ -171,8 +168,8 @@ public class VxlanGpeCustomizerTest extends WriterCustomizerTest { verifyVxlanGpeAddWasInvoked(vxlanGpe); // Mapping not stored due to failure verify(mappingContext, times(0)) - .put(eq(getMappingIid(ifaceName, "test-instance")), eq( - getMapping(ifaceName, 0).get())); + .put(eq(mappingIid(ifaceName, "test-instance")), eq( + mapping(ifaceName, 0).get())); return; } fail("WriteFailedException.CreateFailedException was expected"); @@ -194,11 +191,11 @@ public class VxlanGpeCustomizerTest extends WriterCustomizerTest { final VxlanGpe vxlanGpe = generateVxlanGpe(); whenVxlanGpeAddDelTunnelThenSuccess(); - ContextTestUtils.mockMapping(mappingContext, ifaceName, 1, "test-instance"); + defineMapping(mappingContext, ifaceName, 1, "test-instance"); customizer.deleteCurrentAttributes(id, vxlanGpe, writeContext); verifyVxlanGpeDeleteWasInvoked(vxlanGpe); - verify(mappingContext).delete(eq(getMappingIid(ifaceName, "test-instance"))); + verify(mappingContext).delete(eq(mappingIid(ifaceName, "test-instance"))); } @Test @@ -206,14 +203,14 @@ public class VxlanGpeCustomizerTest extends WriterCustomizerTest { final VxlanGpe vxlanGpe = generateVxlanGpe(); whenVxlanGpeAddDelTunnelThenFailure(); - ContextTestUtils.mockMapping(mappingContext, ifaceName, 1, "test-instance"); + defineMapping(mappingContext, ifaceName, 1, "test-instance"); try { customizer.deleteCurrentAttributes(id, vxlanGpe, writeContext); } catch (WriteFailedException.DeleteFailedException e) { assertTrue(e.getCause() instanceof VppBaseCallException); verifyVxlanGpeDeleteWasInvoked(vxlanGpe); - verify(mappingContext, times(0)).delete(eq(getMappingIid(ifaceName, "test-instance"))); + verify(mappingContext, times(0)).delete(eq(mappingIid(ifaceName, "test-instance"))); return; } fail("WriteFailedException.DeleteFailedException was expected"); diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/ip/Ipv4AddressCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/ip/Ipv4AddressCustomizerTest.java index 7b1fb53e0..56430cd46 100644 --- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/ip/Ipv4AddressCustomizerTest.java +++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/ip/Ipv4AddressCustomizerTest.java @@ -30,7 +30,6 @@ import static org.mockito.Mockito.when; import com.google.common.base.Optional; import io.fd.honeycomb.translate.v3po.interfaces.ip.subnet.validation.SubnetValidationException; import io.fd.honeycomb.translate.v3po.interfaces.ip.subnet.validation.SubnetValidator; -import io.fd.honeycomb.translate.v3po.test.ContextTestUtils; import io.fd.honeycomb.translate.v3po.util.NamingContext; import io.fd.honeycomb.translate.write.WriteFailedException; import io.fd.honeycomb.vpp.test.write.WriterCustomizerTest; @@ -114,7 +113,7 @@ public class Ipv4AddressCustomizerTest extends WriterCustomizerTest { PrefixLength length = new PrefixLengthBuilder().setPrefixLength(new Integer(24).shortValue()).build(); Address data = new AddressBuilder().setIp(noZoneIp).setSubnet(length).build(); - ContextTestUtils.mockMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME); + defineMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME); whenSwInterfaceAddDelAddressThenSuccess(); customizer.writeCurrentAttributes(id, data, writeContext); @@ -132,7 +131,7 @@ public class Ipv4AddressCustomizerTest extends WriterCustomizerTest { PrefixLength length = new PrefixLengthBuilder().setPrefixLength(new Integer(24).shortValue()).build(); Address data = new AddressBuilder().setIp(noZoneIp).setSubnet(length).build(); - ContextTestUtils.mockMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME); + defineMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME); whenSwInterfaceAddDelAddressThenFailure(); try { @@ -166,7 +165,7 @@ public class Ipv4AddressCustomizerTest extends WriterCustomizerTest { doReturn(Optional.of(new Ipv4Builder().setAddress(addressList).build())).when(writeContext) .readAfter(argThat(matchInstanceIdentifier(Ipv4.class))); - ContextTestUtils.mockMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME); + defineMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME); try { customizer.writeCurrentAttributes(id, data, writeContext); @@ -210,7 +209,7 @@ public class Ipv4AddressCustomizerTest extends WriterCustomizerTest { PrefixLength length = new PrefixLengthBuilder().setPrefixLength(new Integer(24).shortValue()).build(); Address data = new AddressBuilder().setIp(noZoneIp).setSubnet(length).build(); - ContextTestUtils.mockMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME); + defineMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME); whenSwInterfaceAddDelAddressThenSuccess(); customizer.deleteCurrentAttributes(id, data, writeContext); @@ -227,7 +226,7 @@ public class Ipv4AddressCustomizerTest extends WriterCustomizerTest { PrefixLength length = new PrefixLengthBuilder().setPrefixLength(new Integer(24).shortValue()).build(); Address data = new AddressBuilder().setIp(noZoneIp).setSubnet(length).build(); - ContextTestUtils.mockMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME); + defineMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME); whenSwInterfaceAddDelAddressThenFailure(); try { @@ -250,7 +249,7 @@ public class Ipv4AddressCustomizerTest extends WriterCustomizerTest { Netmask subnet = new NetmaskBuilder().setNetmask(new DottedQuad(stringMask)).build(); Address data = new AddressBuilder().setIp(noZoneIp).setSubnet(subnet).build(); - ContextTestUtils.mockMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME); + defineMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME); whenSwInterfaceAddDelAddressThenSuccess(); customizer.writeCurrentAttributes(id, data, writeContext); @@ -268,7 +267,7 @@ public class Ipv4AddressCustomizerTest extends WriterCustomizerTest { Netmask subnet = new NetmaskBuilder().setNetmask(new DottedQuad(stringMask)).build(); Address data = new AddressBuilder().setIp(noZoneIp).setSubnet(subnet).build(); - ContextTestUtils.mockMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME); + defineMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME); whenSwInterfaceAddDelAddressThenSuccess(); customizer.writeCurrentAttributes(id, data, writeContext); diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/ip/Ipv4NeighbourCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/ip/Ipv4NeighbourCustomizerTest.java index 416468300..e9acdbe88 100644 --- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/ip/Ipv4NeighbourCustomizerTest.java +++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/ip/Ipv4NeighbourCustomizerTest.java @@ -23,7 +23,6 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import com.google.common.io.BaseEncoding; -import io.fd.honeycomb.translate.v3po.test.ContextTestUtils; import io.fd.honeycomb.translate.v3po.util.Ipv4Translator; import io.fd.honeycomb.translate.v3po.util.NamingContext; import io.fd.honeycomb.translate.write.WriteFailedException; @@ -56,7 +55,7 @@ public class Ipv4NeighbourCustomizerTest extends WriterCustomizerTest implements @Before public void init() { - ContextTestUtils.mockMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME); + defineMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME); customizer = new Ipv4NeighbourCustomizer(api, new NamingContext("prefix", IFC_CTX_NAME)); requestCaptor = ArgumentCaptor.forClass(IpNeighborAddDel.class); diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/AclCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/AclCustomizerTest.java index b2a76c5c0..00dadddb1 100644 --- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/AclCustomizerTest.java +++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/AclCustomizerTest.java @@ -22,7 +22,6 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; -import io.fd.honeycomb.translate.v3po.test.ContextTestUtils; import io.fd.honeycomb.translate.v3po.util.NamingContext; import io.fd.honeycomb.translate.v3po.vppclassifier.VppClassifierContextManager; import io.fd.honeycomb.vpp.test.read.ReaderCustomizerTest; @@ -61,7 +60,7 @@ public class AclCustomizerTest extends ReaderCustomizerTest { @Override public void setUp() { interfaceContext = new NamingContext("generatedIfaceName", IFC_CTX_NAME); - ContextTestUtils.mockMapping(mappingContext, IF_NAME, IF_INDEX, IFC_CTX_NAME); + defineMapping(mappingContext, IF_NAME, IF_INDEX, IFC_CTX_NAME); } @Override diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/GreCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/GreCustomizerTest.java index 0728a5a2a..e62edadef 100644 --- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/GreCustomizerTest.java +++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/GreCustomizerTest.java @@ -26,7 +26,6 @@ import static org.mockito.Mockito.verifyZeroInteractions; import com.google.common.collect.Lists; import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; -import io.fd.honeycomb.translate.v3po.test.ContextTestUtils; import io.fd.honeycomb.translate.v3po.util.NamingContext; import io.fd.honeycomb.vpp.test.read.ReaderCustomizerTest; import java.net.InetAddress; @@ -65,7 +64,7 @@ public class GreCustomizerTest extends ReaderCustomizerTest { @Override public void setUp() throws UnknownHostException, VppInvocationException { interfacesContext = new NamingContext("gre-tunnel", IFC_CTX_NAME); - ContextTestUtils.mockMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME); + defineMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME); final SwInterfaceDetails v = new SwInterfaceDetails(); v.interfaceName = "gre-tunnel4".getBytes(); diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/InterfaceCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/InterfaceCustomizerTest.java index 5c6f88abd..94dfd077a 100644 --- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/InterfaceCustomizerTest.java +++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/InterfaceCustomizerTest.java @@ -28,7 +28,6 @@ import static org.mockito.Mockito.when; import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; import io.fd.honeycomb.translate.v3po.DisabledInterfacesManager; -import io.fd.honeycomb.translate.v3po.test.ContextTestUtils; import io.fd.honeycomb.translate.v3po.util.NamingContext; import io.fd.honeycomb.vpp.test.read.ListReaderCustomizerTest; import java.util.Arrays; @@ -70,9 +69,9 @@ public class InterfaceCustomizerTest extends @Override public void setUp() { interfacesContext = new NamingContext("generatedIfaceName", IFC_CTX_NAME); - ContextTestUtils.mockMapping(mappingContext, IFACE0_NAME, IFACE0_ID, IFC_CTX_NAME); - ContextTestUtils.mockMapping(mappingContext, IFACE1_NAME, IFACE1_ID, IFC_CTX_NAME); - ContextTestUtils.mockMapping(mappingContext, SUB_IFACE_NAME, SUB_IFACE_ID, IFC_CTX_NAME); + defineMapping(mappingContext, IFACE0_NAME, IFACE0_ID, IFC_CTX_NAME); + defineMapping(mappingContext, IFACE1_NAME, IFACE1_ID, IFC_CTX_NAME); + defineMapping(mappingContext, SUB_IFACE_NAME, SUB_IFACE_ID, IFC_CTX_NAME); } @Override diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/L2CustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/L2CustomizerTest.java index 29f0d0eb7..6be759bc5 100644 --- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/L2CustomizerTest.java +++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/L2CustomizerTest.java @@ -22,7 +22,6 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; -import io.fd.honeycomb.translate.v3po.test.ContextTestUtils; import io.fd.honeycomb.translate.v3po.util.NamingContext; import io.fd.honeycomb.vpp.test.read.ReaderCustomizerTest; import java.util.Collections; @@ -118,8 +117,8 @@ public class L2CustomizerTest extends ReaderCustomizerTest { final int bdId = 1; final String bdName = "bd001"; final String ifName = "eth0.sub0"; - ContextTestUtils.mockMapping(mappingContext, ifName, ifId, IFC_CTX_NAME); - ContextTestUtils.mockMapping(mappingContext, bdName, bdId, BD_CTX_NAME); + defineMapping(mappingContext, ifName, ifId, IFC_CTX_NAME); + defineMapping(mappingContext, bdName, bdId, BD_CTX_NAME); final SwInterfaceDetails ifaceDetails = new SwInterfaceDetails(); ifaceDetails.subId = ifId; diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/RewriteCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/RewriteCustomizerTest.java index 432469ddc..ad2d4f6ce 100644 --- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/RewriteCustomizerTest.java +++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/RewriteCustomizerTest.java @@ -22,7 +22,6 @@ import static org.mockito.Mockito.verify; import io.fd.honeycomb.translate.read.ReadFailedException; import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; -import io.fd.honeycomb.translate.v3po.test.ContextTestUtils; import io.fd.honeycomb.vpp.test.read.ReaderCustomizerTest; import io.fd.honeycomb.translate.v3po.util.NamingContext; import io.fd.honeycomb.translate.v3po.util.TagRewriteOperation; @@ -68,7 +67,7 @@ public class RewriteCustomizerTest extends ReaderCustomizerTest getMapping(final String name, final int index) { - return Optional.of(new MappingBuilder().setName(name).setIndex(index).build()); - } - - public static KeyedInstanceIdentifier getMappingIid(final String name, - final String namingContextName) { - return InstanceIdentifier.create(Contexts.class).child( - org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.contexts.NamingContext.class, - new NamingContextKey(namingContextName)).child(Mappings.class).child(Mapping.class, new MappingKey(name)); - } - - private static List getMappingList(final MappingContext mappingContext, final InstanceIdentifier mappingsIid) { - final Optional previousMappings = mappingContext.read(mappingsIid); - final MappingsBuilder mappingsBuilder; - if (previousMappings != null && previousMappings.isPresent()) { - mappingsBuilder = new MappingsBuilder(previousMappings.get()); - } else { - mappingsBuilder = new MappingsBuilder(); - mappingsBuilder.setMapping(Lists.newArrayList()); - } - - return mappingsBuilder.getMapping(); - } - - public static void mockMapping(final MappingContext mappingContext, final String name, final int id, - final String namingContextName) { - final InstanceIdentifier mappingsIid = - getMappingIid(name, namingContextName).firstIdentifierOf(Mappings.class); - - final Optional singleMapping = getMapping(name, id); - final List mappingList = getMappingList(mappingContext, mappingsIid); - mappingList.add(singleMapping.get()); - - doReturn(Optional.of(new MappingsBuilder().setMapping(mappingList).build())) - .when(mappingContext).read(mappingsIid); - doReturn(singleMapping).when(mappingContext).read(getMappingIid(name, namingContextName)); - } - - public static void mockEmptyMapping(final MappingContext mappingContext, final String name, - final String namingContextName) { - final InstanceIdentifier mappingsIid = - getMappingIid(name, namingContextName).firstIdentifierOf(Mappings.class); - - final List mappingList = getMappingList(mappingContext, mappingsIid); - - doReturn(Optional.of(new MappingsBuilder().setMapping(mappingList).build())) - .when(mappingContext).read(mappingsIid); - doReturn(Optional.absent()).when(mappingContext).read(getMappingIid(name, namingContextName)); - } -} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/vpp/ArpTerminationTableEntryCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/vpp/ArpTerminationTableEntryCustomizerTest.java index 4a38101af..8c2082210 100644 --- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/vpp/ArpTerminationTableEntryCustomizerTest.java +++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/vpp/ArpTerminationTableEntryCustomizerTest.java @@ -25,7 +25,6 @@ import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; -import io.fd.honeycomb.translate.v3po.test.ContextTestUtils; import io.fd.honeycomb.translate.v3po.util.NamingContext; import io.fd.honeycomb.translate.write.WriteFailedException; import io.fd.honeycomb.vpp.test.write.WriterCustomizerTest; @@ -75,8 +74,8 @@ public class ArpTerminationTableEntryCustomizerTest extends WriterCustomizerTest entry = generateArpEntry(ipAddress, physAddress); id = getArpEntryId(ipAddress, physAddress); - ContextTestUtils.mockMapping(mappingContext, BD_NAME, BD_ID, BD_CTX_NAME); - ContextTestUtils.mockMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME); + defineMapping(mappingContext, BD_NAME, BD_ID, BD_CTX_NAME); + defineMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME); } private static InstanceIdentifier getArpEntryId(final IpAddress ipAddress, diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/vpp/BridgeDomainCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/vpp/BridgeDomainCustomizerTest.java index f41448bf0..43b9c37fa 100644 --- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/vpp/BridgeDomainCustomizerTest.java +++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/vpp/BridgeDomainCustomizerTest.java @@ -23,7 +23,6 @@ import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import io.fd.honeycomb.translate.v3po.test.ContextTestUtils; import io.fd.honeycomb.translate.v3po.util.ByteDataTranslator; import io.fd.honeycomb.translate.v3po.util.NamingContext; import io.fd.honeycomb.translate.write.WriteFailedException; @@ -120,15 +119,14 @@ public class BridgeDomainCustomizerTest extends WriterCustomizerTest implements final int bdId = 1; final String bdName = "bd1"; final BridgeDomain bd = generateBridgeDomain(bdName); - ContextTestUtils.mockEmptyMapping(mappingContext, bdName, BD_CTX_NAME); + noMappingDefined(mappingContext, bdName, BD_CTX_NAME); whenBridgeDomainAddDelThenSuccess(); customizer.writeCurrentAttributes(bdIdentifierForName(bdName), bd, writeContext); verifyBridgeDomainAddOrUpdateWasInvoked(bd, bdId); - verify(mappingContext).put( - ContextTestUtils.getMappingIid(bdName, BD_CTX_NAME), ContextTestUtils.getMapping(bdName, bdId).get()); + verify(mappingContext).put(mappingIid(bdName, BD_CTX_NAME), mapping(bdName, bdId).get()); } @Test @@ -136,15 +134,14 @@ public class BridgeDomainCustomizerTest extends WriterCustomizerTest implements final int bdId = 1; final String bdName = "bd1"; final BridgeDomain bd = generateBridgeDomain(bdName); - ContextTestUtils.mockMapping(mappingContext, bdName, bdId, BD_CTX_NAME); + defineMapping(mappingContext, bdName, bdId, BD_CTX_NAME); whenBridgeDomainAddDelThenSuccess(); customizer.writeCurrentAttributes(bdIdentifierForName(bdName), bd, writeContext); verifyBridgeDomainAddOrUpdateWasInvoked(bd, bdId); - verify(mappingContext).put( - ContextTestUtils.getMappingIid(bdName, BD_CTX_NAME), ContextTestUtils.getMapping(bdName, bdId).get()); + verify(mappingContext).put(mappingIid(bdName, BD_CTX_NAME), mapping(bdName, bdId).get()); } @Test @@ -152,7 +149,7 @@ public class BridgeDomainCustomizerTest extends WriterCustomizerTest implements final int bdId = 1; final String bdName = "bd1"; final BridgeDomain bd = generateBridgeDomain(bdName); - ContextTestUtils.mockEmptyMapping(mappingContext, bdName, BD_CTX_NAME); + noMappingDefined(mappingContext, bdName, BD_CTX_NAME); whenBridgeDomainAddDelThenFailure(); @@ -170,7 +167,7 @@ public class BridgeDomainCustomizerTest extends WriterCustomizerTest implements final int bdId = 1; final String bdName = "bd1"; final BridgeDomain bd = generateBridgeDomain(bdName); - ContextTestUtils.mockMapping(mappingContext, bdName, bdId, BD_CTX_NAME); + defineMapping(mappingContext, bdName, bdId, BD_CTX_NAME); whenBridgeDomainAddDelThenSuccess(); @@ -183,7 +180,7 @@ public class BridgeDomainCustomizerTest extends WriterCustomizerTest implements public void testDeleteUnknownBridgeDomain() throws Exception { final String bdName = "bd1"; final BridgeDomain bd = generateBridgeDomain("bd1"); - ContextTestUtils.mockEmptyMapping(mappingContext, bdName, BD_CTX_NAME); + noMappingDefined(mappingContext, bdName, BD_CTX_NAME); try { customizer.deleteCurrentAttributes(bdIdentifierForName(bdName), bd, writeContext); @@ -199,7 +196,7 @@ public class BridgeDomainCustomizerTest extends WriterCustomizerTest implements final int bdId = 1; final String bdName = "bd1"; final BridgeDomain bd = generateBridgeDomain(bdName); - ContextTestUtils.mockMapping(mappingContext, bdName, bdId, BD_CTX_NAME); + defineMapping(mappingContext, bdName, bdId, BD_CTX_NAME); whenBridgeDomainAddDelThenFailure(); @@ -217,7 +214,7 @@ public class BridgeDomainCustomizerTest extends WriterCustomizerTest implements public void testUpdateBridgeDomain() throws Exception { final int bdId = 1; final String bdName = "bd1"; - ContextTestUtils.mockMapping(mappingContext, bdName, bdId, BD_CTX_NAME); + defineMapping(mappingContext, bdName, bdId, BD_CTX_NAME); final byte arpTermBefore = 1; final byte floodBefore = 1; @@ -244,7 +241,7 @@ public class BridgeDomainCustomizerTest extends WriterCustomizerTest implements final String bdName = "bd1"; final BridgeDomain bdBefore = generateBridgeDomain(bdName, 0, 1, 0, 1, 0); final BridgeDomain bdAfter = generateBridgeDomain(bdName, 1, 1, 0, 1, 0); - ContextTestUtils.mockEmptyMapping(mappingContext, bdName, BD_CTX_NAME); + noMappingDefined(mappingContext, bdName, BD_CTX_NAME); try { customizer @@ -263,7 +260,7 @@ public class BridgeDomainCustomizerTest extends WriterCustomizerTest implements final String bdName = "bd1"; final BridgeDomain bdBefore = generateBridgeDomain(bdName, 0, 1, 0, 1, 0); final BridgeDomain bdAfter = generateBridgeDomain(bdName, 1, 1, 0, 1, 0); - ContextTestUtils.mockMapping(mappingContext, bdName, bdId, BD_CTX_NAME); + defineMapping(mappingContext, bdName, bdId, BD_CTX_NAME); whenBridgeDomainAddDelThenFailure(); diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/vpp/L2FibEntryCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/vpp/L2FibEntryCustomizerTest.java index 174e27215..e52cc1783 100644 --- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/vpp/L2FibEntryCustomizerTest.java +++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/vpp/L2FibEntryCustomizerTest.java @@ -24,7 +24,6 @@ import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; -import io.fd.honeycomb.translate.v3po.test.ContextTestUtils; import io.fd.honeycomb.translate.v3po.util.NamingContext; import io.fd.honeycomb.translate.write.WriteFailedException; import io.fd.honeycomb.vpp.test.write.WriterCustomizerTest; @@ -58,8 +57,8 @@ public class L2FibEntryCustomizerTest extends WriterCustomizerTest { @Override public void setUp() throws Exception { - ContextTestUtils.mockMapping(mappingContext, BD_NAME, BD_ID, BD_CTX_NAME); - ContextTestUtils.mockMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME); + defineMapping(mappingContext, BD_NAME, BD_ID, BD_CTX_NAME); + defineMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME); customizer = new L2FibEntryCustomizer( api, diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/vppstate/L2FibEntryCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/vppstate/L2FibEntryCustomizerTest.java index 953332da7..f837717c7 100644 --- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/vppstate/L2FibEntryCustomizerTest.java +++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/vppstate/L2FibEntryCustomizerTest.java @@ -23,7 +23,6 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; -import io.fd.honeycomb.translate.v3po.test.ContextTestUtils; import io.fd.honeycomb.translate.v3po.util.NamingContext; import io.fd.honeycomb.vpp.test.read.ListReaderCustomizerTest; import java.util.Collections; @@ -64,7 +63,7 @@ public class L2FibEntryCustomizerTest extends ListReaderCustomizerTest