From e7a0775b21c2ea6b7bb8efb63b5384df26e27fbb Mon Sep 17 00:00:00 2001 From: Marek Gradzki Date: Fri, 23 Sep 2016 07:21:11 +0200 Subject: HONEYCOMB-116: utility for stubbing jvpp methods - introduces FutureProducer (inspired by https://gerrit.fd.io/r/#/c/2650/) - updates unit tests for v3po and lisp Change-Id: I56488bb1dcd6fcaf6821a58f99b528677e095662 Signed-off-by: Marek Gradzki --- .../v3po/interfaces/AclCustomizerTest.java | 60 ++++------------ .../v3po/interfaces/GreCustomizerTest.java | 37 ++-------- .../v3po/interfaces/RewriteCustomizerTest.java | 59 +++++----------- .../interfaces/SubInterfaceCustomizerTest.java | 55 ++++----------- .../v3po/interfaces/TapCustomizerTest.java | 24 ++----- .../v3po/interfaces/VhostUserCustomizerTest.java | 79 ++-------------------- .../v3po/interfaces/VxlanCustomizerTest.java | 38 ++--------- .../v3po/interfaces/VxlanGpeCustomizerTest.java | 47 ++++--------- .../interfaces/ip/Ipv4AddressCustomizerTest.java | 73 ++++---------------- .../interfaces/ip/Ipv4NeighbourCustomizerTest.java | 9 +-- 10 files changed, 99 insertions(+), 382 deletions(-) (limited to 'v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces') 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 75999e5a4..b55a5ce2b 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 @@ -17,23 +17,17 @@ package io.fd.honeycomb.translate.v3po.interfaces; import static junit.framework.TestCase.assertTrue; -import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; import static org.mockito.Matchers.any; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.verify; -import static org.mockito.MockitoAnnotations.initMocks; import io.fd.honeycomb.translate.v3po.test.ContextTestUtils; -import io.fd.honeycomb.translate.v3po.test.TestHelperUtils; -import io.fd.honeycomb.vpp.test.write.WriterCustomizerTest; import io.fd.honeycomb.translate.v3po.util.NamingContext; import io.fd.honeycomb.translate.v3po.vppclassifier.VppClassifierContextManager; import io.fd.honeycomb.translate.write.WriteFailedException; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.ExecutionException; +import io.fd.honeycomb.vpp.test.write.WriterCustomizerTest; import org.junit.Test; -import org.mockito.ArgumentCaptor; import org.mockito.Mock; 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; @@ -47,14 +41,12 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.openvpp.jvpp.VppBaseCallException; import org.openvpp.jvpp.core.dto.InputAclSetInterface; import org.openvpp.jvpp.core.dto.InputAclSetInterfaceReply; -import org.openvpp.jvpp.core.dto.L2InterfaceVlanTagRewriteReply; public class AclCustomizerTest extends WriterCustomizerTest { @Mock private VppClassifierContextManager classifyTableContext; - private NamingContext interfaceContext; private AclCustomizer customizer; private static final String IFC_TEST_INSTANCE = "ifc-test-instance"; @@ -65,16 +57,12 @@ public class AclCustomizerTest extends WriterCustomizerTest { private static final String ACL_TABLE_NAME = "table0"; @Override - public void setUp() throws Exception { - initMocks(this); - interfaceContext = new NamingContext("generatedInterfaceName", IFC_TEST_INSTANCE); + public void setUp() { ContextTestUtils.mockMapping(mappingContext, IF_NAME, IF_INDEX, IFC_TEST_INSTANCE); - - doReturn(mappingContext).when(writeContext).getMappingContext(); - customizer = new AclCustomizer(api, interfaceContext, classifyTableContext); + customizer = new AclCustomizer(api, new NamingContext("generatedInterfaceName", IFC_TEST_INSTANCE), + classifyTableContext); } - private InstanceIdentifier getAclId(final String name) { return InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(name)).augmentation( VppInterfaceAugmentation.class).child(Acl.class); @@ -87,36 +75,13 @@ public class AclCustomizerTest extends WriterCustomizerTest { return builder.build(); } - private void whenInputAclSetInterfaceThenSuccess() throws ExecutionException, InterruptedException { - final CompletableFuture replyFuture = new CompletableFuture<>(); - final InputAclSetInterfaceReply reply = new InputAclSetInterfaceReply(); - replyFuture.complete(reply); - doReturn(replyFuture).when(api).inputAclSetInterface(any(InputAclSetInterface.class)); - } - - private void whenInputAclSetInterfaceThenFailure() throws ExecutionException, InterruptedException { - doReturn(TestHelperUtils.createFutureException()).when(api) + private void whenInputAclSetInterfaceThenSuccess() { + doReturn(future(new InputAclSetInterfaceReply())).when(api) .inputAclSetInterface(any(InputAclSetInterface.class)); } - private void verifyInputAclSetInterfaceWasInvoked(final InputAclSetInterface expected) { - final ArgumentCaptor argumentCaptor = ArgumentCaptor.forClass(InputAclSetInterface.class); - verify(api).inputAclSetInterface(argumentCaptor.capture()); - final InputAclSetInterface actual = argumentCaptor.getValue(); - assertEquals(expected.swIfIndex, actual.swIfIndex); - assertEquals(expected.l2TableIndex, actual.l2TableIndex); - assertEquals(expected.ip4TableIndex, actual.ip4TableIndex); - assertEquals(expected.ip6TableIndex, actual.ip6TableIndex); - assertEquals(expected.isAdd, actual.isAdd); - } - - private void verifyInputAclSetInterfaceDisableWasInvoked(final InputAclSetInterface expected) { - final ArgumentCaptor argumentCaptor = ArgumentCaptor.forClass(InputAclSetInterface.class); - verify(api).inputAclSetInterface(argumentCaptor.capture()); - final InputAclSetInterface actual = argumentCaptor.getValue(); - assertEquals(expected.swIfIndex, actual.swIfIndex); - assertEquals(expected.l2TableIndex, actual.l2TableIndex); - assertEquals(0, actual.isAdd); + private void whenInputAclSetInterfaceThenFailure() { + doReturn(failedFuture()).when(api).inputAclSetInterface(any(InputAclSetInterface.class)); } private static InputAclSetInterface generateInputAclSetInterface(final byte isAdd, final int ifIndex, @@ -139,7 +104,7 @@ public class AclCustomizerTest extends WriterCustomizerTest { customizer.writeCurrentAttributes(id, acl, writeContext); - verifyInputAclSetInterfaceWasInvoked(generateInputAclSetInterface((byte) 1, IF_INDEX, ACL_TABLE_INDEX)); + verify(api).inputAclSetInterface(generateInputAclSetInterface((byte) 1, IF_INDEX, ACL_TABLE_INDEX)); } @Test @@ -153,7 +118,7 @@ public class AclCustomizerTest extends WriterCustomizerTest { customizer.writeCurrentAttributes(id, acl, writeContext); } catch (WriteFailedException.CreateFailedException e) { assertTrue(e.getCause() instanceof VppBaseCallException); - verifyInputAclSetInterfaceWasInvoked(generateInputAclSetInterface((byte) 1, IF_INDEX, ACL_TABLE_INDEX)); + verify(api).inputAclSetInterface(generateInputAclSetInterface((byte) 1, IF_INDEX, ACL_TABLE_INDEX)); return; } fail("WriteFailedException.CreateFailedException was expected"); @@ -168,7 +133,7 @@ public class AclCustomizerTest extends WriterCustomizerTest { customizer.deleteCurrentAttributes(id, acl, writeContext); - verifyInputAclSetInterfaceDisableWasInvoked(generateInputAclSetInterface((byte) 0, IF_INDEX, ACL_TABLE_INDEX)); + verify(api).inputAclSetInterface(generateInputAclSetInterface((byte) 0, IF_INDEX, ACL_TABLE_INDEX)); } @Test @@ -182,8 +147,7 @@ public class AclCustomizerTest extends WriterCustomizerTest { customizer.deleteCurrentAttributes(id, acl, writeContext); } catch (WriteFailedException.DeleteFailedException e) { assertTrue(e.getCause() instanceof VppBaseCallException); - verifyInputAclSetInterfaceDisableWasInvoked( - generateInputAclSetInterface((byte) 0, IF_INDEX, ACL_TABLE_INDEX)); + verify(api).inputAclSetInterface(generateInputAclSetInterface((byte) 0, IF_INDEX, ACL_TABLE_INDEX)); return; } fail("WriteFailedException.DeleteFailedException was expected"); 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 cf92ab91f..6918e1f01 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 @@ -25,24 +25,15 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyLong; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; import com.google.common.net.InetAddresses; -import io.fd.honeycomb.translate.v3po.test.TestHelperUtils; -import io.fd.honeycomb.vpp.test.write.WriterCustomizerTest; import io.fd.honeycomb.translate.v3po.util.NamingContext; import io.fd.honeycomb.translate.write.WriteFailedException; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.CompletionStage; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; +import io.fd.honeycomb.vpp.test.write.WriterCustomizerTest; import org.junit.Test; import org.mockito.ArgumentCaptor; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress; @@ -78,24 +69,14 @@ public class GreCustomizerTest extends WriterCustomizerTest { customizer = new GreCustomizer(api, new NamingContext("generateInterfaceNAme", IFC_TEST_INSTANCE)); } - private void whenGreAddDelTunnelThenSuccess() - throws ExecutionException, InterruptedException, VppInvocationException, TimeoutException { - final CompletionStage replyCS = mock(CompletionStage.class); - final CompletableFuture replyFuture = mock(CompletableFuture.class); - when(replyCS.toCompletableFuture()).thenReturn(replyFuture); + private void whenGreAddDelTunnelThenSuccess() { 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); + doReturn(future(reply)).when(api).greAddDelTunnel(any(GreAddDelTunnel.class)); } - /** - * Failure response send - */ - private void whenGreAddDelTunnelThenFailure() - throws ExecutionException, InterruptedException, VppInvocationException { - doReturn(TestHelperUtils.createFutureException()).when(api) - .greAddDelTunnel(any(GreAddDelTunnel.class)); + private void whenGreAddDelTunnelThenFailure() { + doReturn(failedFuture()).when(api).greAddDelTunnel(any(GreAddDelTunnel.class)); } private GreAddDelTunnel verifyGreAddDelTunnelWasInvoked(final Gre gre) throws VppInvocationException { @@ -121,7 +102,7 @@ public class GreCustomizerTest extends WriterCustomizerTest { assertEquals(DEL_GRE, actual.isAdd); } - private static Gre generateGre(long vni) { + private static Gre generateGre() { final GreBuilder builder = new GreBuilder(); builder.setSrc(new IpAddress(new Ipv4Address("192.168.20.10"))); builder.setDst(new IpAddress(new Ipv4Address("192.168.20.11"))); @@ -129,10 +110,6 @@ public class GreCustomizerTest extends WriterCustomizerTest { return builder.build(); } - private static Gre generateGre() { - return generateGre(Long.valueOf(11)); - } - @Test public void testWriteCurrentAttributes() throws Exception { final Gre gre = generateGre(); @@ -184,7 +161,7 @@ public class GreCustomizerTest extends WriterCustomizerTest { @Test public void testUpdateCurrentAttributes() throws Exception { try { - customizer.updateCurrentAttributes(id, generateGre(10), generateGre(11), writeContext); + customizer.updateCurrentAttributes(id, generateGre(), generateGre(), writeContext); } catch (WriteFailedException.UpdateFailedException e) { assertEquals(UnsupportedOperationException.class, e.getCause().getClass()); return; 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 366d9429e..e28a0f6c6 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 @@ -17,23 +17,18 @@ package io.fd.honeycomb.translate.v3po.interfaces; import static junit.framework.TestCase.assertTrue; -import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; 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.test.TestHelperUtils; -import io.fd.honeycomb.vpp.test.write.WriterCustomizerTest; import io.fd.honeycomb.translate.v3po.util.NamingContext; import io.fd.honeycomb.translate.v3po.util.TagRewriteOperation; import io.fd.honeycomb.translate.write.WriteFailedException; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.ExecutionException; +import io.fd.honeycomb.vpp.test.write.WriterCustomizerTest; import org.junit.Assert; import org.junit.Test; -import org.mockito.ArgumentCaptor; 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; @@ -72,12 +67,12 @@ public class RewriteCustomizerTest extends WriterCustomizerTest { } private static InstanceIdentifier getVlanTagRewriteId(final String name, final long index) { - final Class> child = (Class)Rewrite.class; + final Class> child = (Class) Rewrite.class; final InstanceIdentifier id = - InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(name)).augmentation( - SubinterfaceAugmentation.class).child(SubInterfaces.class) - .child(SubInterface.class, new SubInterfaceKey(index)) - .child(child); + InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(name)).augmentation( + SubinterfaceAugmentation.class).child(SubInterfaces.class) + .child(SubInterface.class, new SubInterfaceKey(index)) + .child(child); return id; } @@ -100,40 +95,22 @@ public class RewriteCustomizerTest extends WriterCustomizerTest { /** * Positive response */ - private void whenL2InterfaceVlanTagRewriteThenSuccess() - throws ExecutionException, InterruptedException, VppInvocationException { - final CompletableFuture replyFuture = new CompletableFuture<>(); - final L2InterfaceVlanTagRewriteReply reply = new L2InterfaceVlanTagRewriteReply(); - replyFuture.complete(reply); - doReturn(replyFuture).when(api).l2InterfaceVlanTagRewrite(any(L2InterfaceVlanTagRewrite.class)); + private void whenL2InterfaceVlanTagRewriteThenSuccess() { + doReturn(future(new L2InterfaceVlanTagRewriteReply())).when(api) + .l2InterfaceVlanTagRewrite(any(L2InterfaceVlanTagRewrite.class)); } /** * Failure response send */ - private void whenL2InterfaceVlanTagRewriteThenFailure() - throws ExecutionException, InterruptedException, VppInvocationException { - doReturn(TestHelperUtils.createFutureException()).when(api) - .l2InterfaceVlanTagRewrite(any(L2InterfaceVlanTagRewrite.class)); - } - - private void verifyL2InterfaceVlanTagRewriteWasInvoked(final L2InterfaceVlanTagRewrite expected) - throws VppInvocationException { - ArgumentCaptor argumentCaptor = - ArgumentCaptor.forClass(L2InterfaceVlanTagRewrite.class); - verify(api).l2InterfaceVlanTagRewrite(argumentCaptor.capture()); - final L2InterfaceVlanTagRewrite actual = argumentCaptor.getValue(); - assertEquals(expected.swIfIndex, actual.swIfIndex); - assertEquals(expected.vtrOp, actual.vtrOp); - assertEquals(expected.pushDot1Q, actual.pushDot1Q); - assertEquals(expected.tag1, actual.tag1); - assertEquals(expected.tag2, actual.tag2); + private void whenL2InterfaceVlanTagRewriteThenFailure() { + doReturn(failedFuture()).when(api).l2InterfaceVlanTagRewrite(any(L2InterfaceVlanTagRewrite.class)); } private void verifyL2InterfaceVlanTagRewriteDeleteWasInvoked() throws VppInvocationException { final L2InterfaceVlanTagRewrite request = new L2InterfaceVlanTagRewrite(); request.swIfIndex = VLAN_IF_INDEX; - verifyL2InterfaceVlanTagRewriteWasInvoked(request); + verify(api).l2InterfaceVlanTagRewrite(request); } @Test @@ -145,7 +122,7 @@ public class RewriteCustomizerTest extends WriterCustomizerTest { customizer.writeCurrentAttributes(VLAN_IID, vlanTagRewrite, writeContext); - verifyL2InterfaceVlanTagRewriteWasInvoked(generateL2InterfaceVlanTagRewrite(VLAN_IF_INDEX, op)); + verify(api).l2InterfaceVlanTagRewrite(generateL2InterfaceVlanTagRewrite(VLAN_IF_INDEX, op)); } @Test @@ -159,7 +136,7 @@ public class RewriteCustomizerTest extends WriterCustomizerTest { customizer.writeCurrentAttributes(VLAN_IID, vlanTagRewrite, writeContext); } catch (WriteFailedException.CreateFailedException e) { assertTrue(e.getCause() instanceof VppBaseCallException); - verifyL2InterfaceVlanTagRewriteWasInvoked(generateL2InterfaceVlanTagRewrite(VLAN_IF_INDEX, op)); + verify(api).l2InterfaceVlanTagRewrite(generateL2InterfaceVlanTagRewrite(VLAN_IF_INDEX, op)); return; } fail("WriteFailedException.CreateFailedException was expected"); @@ -174,8 +151,8 @@ public class RewriteCustomizerTest extends WriterCustomizerTest { customizer.updateCurrentAttributes(VLAN_IID, before, after, writeContext); - verifyL2InterfaceVlanTagRewriteWasInvoked( - generateL2InterfaceVlanTagRewrite(VLAN_IF_INDEX, TagRewriteOperation.pop_1)); + verify(api) + .l2InterfaceVlanTagRewrite(generateL2InterfaceVlanTagRewrite(VLAN_IF_INDEX, TagRewriteOperation.pop_1)); } @Test @@ -189,8 +166,8 @@ public class RewriteCustomizerTest extends WriterCustomizerTest { customizer.updateCurrentAttributes(VLAN_IID, before, after, writeContext); } catch (WriteFailedException.UpdateFailedException e) { assertTrue(e.getCause() instanceof VppBaseCallException); - verifyL2InterfaceVlanTagRewriteWasInvoked(generateL2InterfaceVlanTagRewrite(VLAN_IF_INDEX, - TagRewriteOperation.pop_1)); + verify(api) + .l2InterfaceVlanTagRewrite(generateL2InterfaceVlanTagRewrite(VLAN_IF_INDEX, TagRewriteOperation.pop_1)); return; } fail("WriteFailedException.UpdateFailedException was expected"); 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 c370a97ea..1fee0b3cf 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,14 +26,11 @@ 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.test.TestHelperUtils; -import io.fd.honeycomb.vpp.test.write.WriterCustomizerTest; import io.fd.honeycomb.translate.v3po.util.NamingContext; import io.fd.honeycomb.translate.write.WriteFailedException; +import io.fd.honeycomb.vpp.test.write.WriterCustomizerTest; import java.util.Arrays; import java.util.List; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.ExecutionException; import org.junit.Test; import org.mockito.ArgumentCaptor; import org.opendaylight.yang.gen.v1.urn.ieee.params.xml.ns.yang.dot1q.types.rev150626.CVlan; @@ -163,47 +160,19 @@ public class SubInterfaceCustomizerTest extends WriterCustomizerTest { .child(SubInterface.class, new SubInterfaceKey(index)); } - private void whenCreateSubifThenSuccess() throws ExecutionException, InterruptedException, VppBaseCallException { - final CompletableFuture replyFuture = new CompletableFuture<>(); - final CreateSubifReply reply = new CreateSubifReply(); - replyFuture.complete(reply); - doReturn(replyFuture).when(api).createSubif(any(CreateSubif.class)); + private void whenCreateSubifThenSuccess() { + doReturn(future(new CreateSubifReply())).when(api).createSubif(any(CreateSubif.class)); } /** * Failure response send */ - private void whenCreateSubifThenFailure() throws ExecutionException, InterruptedException, VppBaseCallException { - doReturn(TestHelperUtils.createFutureException()).when(api) - .createSubif(any(CreateSubif.class)); - } - - private void whenSwInterfaceSetFlagsThenSuccess() - throws ExecutionException, InterruptedException, VppBaseCallException { - final CompletableFuture replyFuture = new CompletableFuture<>(); - final SwInterfaceSetFlagsReply reply = new SwInterfaceSetFlagsReply(); - replyFuture.complete(reply); - doReturn(replyFuture).when(api).swInterfaceSetFlags(any(SwInterfaceSetFlags.class)); + private void whenCreateSubifThenFailure() { + doReturn(failedFuture()).when(api).createSubif(any(CreateSubif.class)); } - private CreateSubif verifyCreateSubifWasInvoked(final CreateSubif expected) throws VppBaseCallException { - ArgumentCaptor argumentCaptor = ArgumentCaptor.forClass(CreateSubif.class); - verify(api).createSubif(argumentCaptor.capture()); - final CreateSubif actual = argumentCaptor.getValue(); - - assertEquals(expected.swIfIndex, actual.swIfIndex); - assertEquals(expected.subId, actual.subId); - assertEquals(expected.noTags, actual.noTags); - assertEquals(expected.oneTag, actual.oneTag); - assertEquals(expected.twoTags, actual.twoTags); - assertEquals(expected.dot1Ad, actual.dot1Ad); - assertEquals(expected.exactMatch, actual.exactMatch); - assertEquals(expected.defaultSub, actual.defaultSub); - assertEquals(expected.outerVlanIdAny, actual.outerVlanIdAny); - assertEquals(expected.innerVlanIdAny, actual.innerVlanIdAny); - assertEquals(expected.outerVlanId, actual.outerVlanId); - assertEquals(expected.innerVlanId, actual.innerVlanId); - return actual; + private void whenSwInterfaceSetFlagsThenSuccess() { + doReturn(future(new SwInterfaceSetFlagsReply())).when(api).swInterfaceSetFlags(any(SwInterfaceSetFlags.class)); } private SwInterfaceSetFlags verifySwInterfaceSetFlagsWasInvoked(final SwInterfaceSetFlags expected) @@ -227,10 +196,10 @@ public class SubInterfaceCustomizerTest extends WriterCustomizerTest { customizer.writeCurrentAttributes(id, subInterface, writeContext); - verifyCreateSubifWasInvoked(generateSubInterfaceRequest(SUPER_IF_ID, CTAG_ID, false)); + 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())); + ContextTestUtils.getMapping(SUB_IFACE_NAME, 0).get())); } @Test @@ -243,10 +212,10 @@ public class SubInterfaceCustomizerTest extends WriterCustomizerTest { customizer.writeCurrentAttributes(id, subInterface, writeContext); - verifyCreateSubifWasInvoked(generateSubInterfaceRequest(SUPER_IF_ID, CTAG_ANY_ID, true)); + 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())); + ContextTestUtils.getMapping(SUB_IFACE_NAME, 0).get())); } @Test @@ -260,7 +229,7 @@ public class SubInterfaceCustomizerTest extends WriterCustomizerTest { customizer.writeCurrentAttributes(id, subInterface, writeContext); } catch (WriteFailedException.CreateFailedException e) { assertTrue(e.getCause() instanceof VppBaseCallException); - verifyCreateSubifWasInvoked(generateSubInterfaceRequest(SUPER_IF_ID, CTAG_ID, false)); + 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())); 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 fedc59e79..c2c687602 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 @@ -24,9 +24,8 @@ import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import io.fd.honeycomb.translate.v3po.test.ContextTestUtils; -import io.fd.honeycomb.vpp.test.write.WriterCustomizerTest; import io.fd.honeycomb.translate.v3po.util.NamingContext; -import java.util.concurrent.CompletableFuture; +import io.fd.honeycomb.vpp.test.write.WriterCustomizerTest; import org.junit.Test; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; @@ -65,11 +64,9 @@ public class TapCustomizerTest extends WriterCustomizerTest { @Override public Object answer(final InvocationOnMock invocation) throws Throwable { - final CompletableFuture reply = new CompletableFuture<>(); final TapConnectReply t = new TapConnectReply(); t.swIfIndex = idx++; - reply.complete(t); - return reply; + return future(t); } }).when(api).tapConnect(any(TapConnect.class)); @@ -85,17 +82,13 @@ public class TapCustomizerTest extends WriterCustomizerTest { @Test public void testModify() throws Exception { - final CompletableFuture reply = new CompletableFuture<>(); final TapConnectReply t = new TapConnectReply(); t.swIfIndex = 0; - reply.complete(t); - doReturn(reply).when(api).tapConnect(any(TapConnect.class)); + doReturn(future(t)).when(api).tapConnect(any(TapConnect.class)); - final CompletableFuture replyModif = new CompletableFuture<>(); final TapModifyReply tmodif = new TapModifyReply(); tmodif.swIfIndex = 0; - replyModif.complete(tmodif); - doReturn(replyModif).when(api).tapModify(any(TapModify.class)); + doReturn(future(tmodif)).when(api).tapModify(any(TapModify.class)); tapCustomizer.writeCurrentAttributes(getTapId("tap"), getTapData("tap", "ff:ff:ff:ff:ff:ff"), writeContext); @@ -111,16 +104,11 @@ public class TapCustomizerTest extends WriterCustomizerTest { @Test public void testDelete() throws Exception { - final CompletableFuture reply = new CompletableFuture<>(); final TapConnectReply t = new TapConnectReply(); t.swIfIndex = 0; - reply.complete(t); - doReturn(reply).when(api).tapConnect(any(TapConnect.class)); + doReturn(future(t)).when(api).tapConnect(any(TapConnect.class)); - final CompletableFuture replyDelete = new CompletableFuture<>(); - final TapDeleteReply tmodif = new TapDeleteReply(); - replyDelete.complete(tmodif); - doReturn(replyDelete).when(api).tapDelete(any(TapDelete.class)); + 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); 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 1d2fb609d..0c1d2d72f 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 @@ -22,26 +22,18 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyLong; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; 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.test.TestHelperUtils; -import io.fd.honeycomb.vpp.test.write.WriterCustomizerTest; import io.fd.honeycomb.translate.v3po.util.NamingContext; import io.fd.honeycomb.translate.v3po.util.TranslateUtils; import io.fd.honeycomb.translate.write.WriteFailedException; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.CompletionStage; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; +import io.fd.honeycomb.vpp.test.write.WriterCustomizerTest; import org.junit.Test; import org.mockito.ArgumentCaptor; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces; @@ -77,63 +69,6 @@ public class VhostUserCustomizerTest extends WriterCustomizerTest { customizer = new VhostUserCustomizer(api, new NamingContext("generatedInterfaceName", "test-instance")); } - private void whenCreateVhostUserIfThenSuccess() - throws ExecutionException, InterruptedException, VppInvocationException, TimeoutException { - final CompletionStage replyCS = mock(CompletionStage.class); - final CompletableFuture replyFuture = mock(CompletableFuture.class); - when(replyCS.toCompletableFuture()).thenReturn(replyFuture); - final CreateVhostUserIfReply reply = new CreateVhostUserIfReply(); - when(replyFuture.get(anyLong(), eq(TimeUnit.SECONDS))).thenReturn(reply); - when(api.createVhostUserIf(any(CreateVhostUserIf.class))).thenReturn(replyCS); - } - - /** - * Failure response send - */ - private void whenCreateVhostUserIfThenFailure() - throws ExecutionException, InterruptedException, VppInvocationException { - doReturn(TestHelperUtils.createFutureException()).when(api) - .createVhostUserIf(any(CreateVhostUserIf.class)); - } - - private void whenModifyVhostUserIfThenSuccess() - throws ExecutionException, InterruptedException, VppInvocationException, TimeoutException { - final CompletionStage replyCS = mock(CompletionStage.class); - final CompletableFuture replyFuture = mock(CompletableFuture.class); - when(replyCS.toCompletableFuture()).thenReturn(replyFuture); - final ModifyVhostUserIfReply reply = new ModifyVhostUserIfReply(); - when(replyFuture.get(anyLong(), eq(TimeUnit.SECONDS))).thenReturn(reply); - when(api.modifyVhostUserIf(any(ModifyVhostUserIf.class))).thenReturn(replyCS); - } - - /** - * Failure response send - */ - private void whenModifyVhostUserIfThenFailure() - throws ExecutionException, InterruptedException, VppInvocationException { - doReturn(TestHelperUtils.createFutureException()).when(api) - .modifyVhostUserIf(any(ModifyVhostUserIf.class)); - } - - private void whenDeleteVhostUserIfThenSuccess() - throws ExecutionException, InterruptedException, VppInvocationException, TimeoutException { - final CompletionStage replyCS = mock(CompletionStage.class); - final CompletableFuture replyFuture = mock(CompletableFuture.class); - when(replyCS.toCompletableFuture()).thenReturn(replyFuture); - final DeleteVhostUserIfReply reply = new DeleteVhostUserIfReply(); - when(replyFuture.get(anyLong(), eq(TimeUnit.SECONDS))).thenReturn(reply); - when(api.deleteVhostUserIf(any(DeleteVhostUserIf.class))).thenReturn(replyCS); - } - - /** - * Failure response send - */ - private void whenDeleteVhostUserIfThenFailure() - throws ExecutionException, InterruptedException, VppInvocationException { - doReturn(TestHelperUtils.createFutureException()).when(api) - .deleteVhostUserIf(any(DeleteVhostUserIf.class)); - } - private CreateVhostUserIf verifyCreateVhostUserIfWasInvoked(final VhostUser vhostUser) throws VppInvocationException { ArgumentCaptor argumentCaptor = ArgumentCaptor.forClass(CreateVhostUserIf.class); @@ -182,7 +117,7 @@ public class VhostUserCustomizerTest extends WriterCustomizerTest { public void testWriteCurrentAttributes() throws Exception { final VhostUser vhostUser = generateVhostUser(VhostUserRole.Server, "socketName"); - whenCreateVhostUserIfThenSuccess(); + when(api.createVhostUserIf(any(CreateVhostUserIf.class))).thenReturn(future(new CreateVhostUserIfReply())); customizer.writeCurrentAttributes(ID, vhostUser, writeContext); verifyCreateVhostUserIfWasInvoked(vhostUser); @@ -194,7 +129,7 @@ public class VhostUserCustomizerTest extends WriterCustomizerTest { public void testWriteCurrentAttributesFailed() throws Exception { final VhostUser vhostUser = generateVhostUser(VhostUserRole.Client, "socketName"); - whenCreateVhostUserIfThenFailure(); + doReturn(failedFuture()).when(api).createVhostUserIf(any(CreateVhostUserIf.class)); try { customizer.writeCurrentAttributes(ID, vhostUser, writeContext); @@ -213,7 +148,7 @@ public class VhostUserCustomizerTest extends WriterCustomizerTest { final VhostUser vhostUserAfter = generateVhostUser(VhostUserRole.Server, "socketName1"); ContextTestUtils.mockMapping(mappingContext, IFACE_NAME, IFACE_ID, "test-instance"); - whenModifyVhostUserIfThenSuccess(); + when(api.modifyVhostUserIf(any(ModifyVhostUserIf.class))).thenReturn(future(new ModifyVhostUserIfReply())); customizer.updateCurrentAttributes(ID, vhostUserBefore, vhostUserAfter, writeContext); verifyModifyVhostUserIfWasInvoked(vhostUserAfter, IFACE_ID); @@ -225,7 +160,7 @@ public class VhostUserCustomizerTest extends WriterCustomizerTest { final VhostUser vhostUserAfter = generateVhostUser(VhostUserRole.Server, "socketName1"); ContextTestUtils.mockMapping(mappingContext, IFACE_NAME, IFACE_ID, "test-instance"); - whenModifyVhostUserIfThenFailure(); + doReturn(failedFuture()).when(api).modifyVhostUserIf(any(ModifyVhostUserIf.class)); try { customizer.updateCurrentAttributes(ID, vhostUserBefore, vhostUserAfter, writeContext); @@ -242,7 +177,7 @@ public class VhostUserCustomizerTest extends WriterCustomizerTest { final VhostUser vhostUser = generateVhostUser(VhostUserRole.Client, "socketName"); ContextTestUtils.mockMapping(mappingContext, IFACE_NAME, IFACE_ID, "test-instance"); - whenDeleteVhostUserIfThenSuccess(); + when(api.deleteVhostUserIf(any(DeleteVhostUserIf.class))).thenReturn(future(new DeleteVhostUserIfReply())); customizer.deleteCurrentAttributes(ID, vhostUser, writeContext); verifyDeleteVhostUserIfWasInvoked(IFACE_ID); @@ -254,7 +189,7 @@ public class VhostUserCustomizerTest extends WriterCustomizerTest { final VhostUser vhostUser = generateVhostUser(VhostUserRole.Client, "socketName"); ContextTestUtils.mockMapping(mappingContext, IFACE_NAME, IFACE_ID, "test-instance"); - whenDeleteVhostUserIfThenFailure(); + doReturn(failedFuture()).when(api).deleteVhostUserIf(any(DeleteVhostUserIf.class)); try { customizer.deleteCurrentAttributes(ID, vhostUser, writeContext); 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 d9678621b..ed099f740 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 @@ -23,27 +23,18 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyLong; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import com.google.common.net.InetAddresses; -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.vpp.test.write.WriterCustomizerTest; import io.fd.honeycomb.translate.v3po.util.NamingContext; import io.fd.honeycomb.translate.write.WriteFailedException; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.CompletionStage; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; +import io.fd.honeycomb.vpp.test.write.WriterCustomizerTest; import org.junit.Test; import org.mockito.ArgumentCaptor; import org.mockito.Mock; @@ -78,36 +69,21 @@ public class VxlanCustomizerTest extends WriterCustomizerTest { public void setUp() throws Exception { InterfaceTypeTestUtils.setupWriteContext(writeContext, org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VxlanTunnel.class); - // TODO HONEYCOMB-116 create base class for tests using vppApi - NamingContext namingContext = new NamingContext("generateInterfaceNAme", "test-instance"); - final ModificationCache toBeReturned = new ModificationCache(); - doReturn(toBeReturned).when(writeContext).getModificationCache(); - doReturn(mappingContext).when(writeContext).getMappingContext(); - customizer = new VxlanCustomizer(api, namingContext, disableContext); + customizer = + new VxlanCustomizer(api, new NamingContext("generateInterfaceNAme", "test-instance"), disableContext); ifaceName = "eth0"; id = InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(ifaceName)) .augmentation(VppInterfaceAugmentation.class).child(Vxlan.class); } - private void whenVxlanAddDelTunnelThenSuccess() - throws ExecutionException, InterruptedException, VppInvocationException, TimeoutException { - final CompletionStage replyCS = mock(CompletionStage.class); - final CompletableFuture replyFuture = mock(CompletableFuture.class); - when(replyCS.toCompletableFuture()).thenReturn(replyFuture); - final VxlanAddDelTunnelReply reply = new VxlanAddDelTunnelReply(); - when(replyFuture.get(anyLong(), eq(TimeUnit.SECONDS))).thenReturn(reply); - when(api.vxlanAddDelTunnel(any(VxlanAddDelTunnel.class))).thenReturn(replyCS); + private void whenVxlanAddDelTunnelThenSuccess() { + when(api.vxlanAddDelTunnel(any(VxlanAddDelTunnel.class))).thenReturn(future(new VxlanAddDelTunnelReply())); } - /** - * Failure response send - */ - private void whenVxlanAddDelTunnelThenFailure() - throws ExecutionException, InterruptedException, VppInvocationException { - doReturn(TestHelperUtils.createFutureException()).when(api) - .vxlanAddDelTunnel(any(VxlanAddDelTunnel.class)); + private void whenVxlanAddDelTunnelThenFailure() { + doReturn(failedFuture()).when(api).vxlanAddDelTunnel(any(VxlanAddDelTunnel.class)); } private VxlanAddDelTunnel verifyVxlanAddDelTunnelWasInvoked(final Vxlan vxlan) throws VppInvocationException { 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 9d6adff6f..75e0d3bb1 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 @@ -23,10 +23,8 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyLong; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -34,15 +32,9 @@ 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.test.TestHelperUtils; -import io.fd.honeycomb.vpp.test.write.WriterCustomizerTest; import io.fd.honeycomb.translate.v3po.util.NamingContext; import io.fd.honeycomb.translate.write.WriteFailedException; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.CompletionStage; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; +import io.fd.honeycomb.vpp.test.write.WriterCustomizerTest; import org.junit.Test; import org.mockito.ArgumentCaptor; import org.mockito.Mock; @@ -58,7 +50,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.VxlanGpeBuilder; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.openvpp.jvpp.VppBaseCallException; -import org.openvpp.jvpp.core.dto.VxlanAddDelTunnelReply; import org.openvpp.jvpp.core.dto.VxlanGpeAddDelTunnel; import org.openvpp.jvpp.core.dto.VxlanGpeAddDelTunnelReply; @@ -83,38 +74,28 @@ public class VxlanGpeCustomizerTest extends WriterCustomizerTest { ifaceName = "elth0"; id = InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(ifaceName)) - .augmentation(VppInterfaceAugmentation.class).child(VxlanGpe.class); + .augmentation(VppInterfaceAugmentation.class).child(VxlanGpe.class); } - private void whenVxlanGpeAddDelTunnelThenSuccess() - throws ExecutionException, InterruptedException, VppBaseCallException, TimeoutException { - final CompletionStage replyCS = mock(CompletionStage.class); - final CompletableFuture replyFuture = mock(CompletableFuture.class); - when(replyCS.toCompletableFuture()).thenReturn(replyFuture); - final VxlanGpeAddDelTunnelReply reply = new VxlanGpeAddDelTunnelReply(); - when(replyFuture.get(anyLong(), eq(TimeUnit.SECONDS))).thenReturn(reply); - when(api.vxlanGpeAddDelTunnel(any(VxlanGpeAddDelTunnel.class))).thenReturn(replyCS); + private void whenVxlanGpeAddDelTunnelThenSuccess() { + when(api.vxlanGpeAddDelTunnel(any(VxlanGpeAddDelTunnel.class))) + .thenReturn(future(new VxlanGpeAddDelTunnelReply())); } - /** - * Failure response send - */ - private void whenVxlanGpeAddDelTunnelThenFailure() - throws ExecutionException, InterruptedException, VppBaseCallException { - doReturn(TestHelperUtils.createFutureException()).when(api) - .vxlanGpeAddDelTunnel(any(VxlanGpeAddDelTunnel.class)); + private void whenVxlanGpeAddDelTunnelThenFailure() { + doReturn(failedFuture()).when(api).vxlanGpeAddDelTunnel(any(VxlanGpeAddDelTunnel.class)); } private VxlanGpeAddDelTunnel verifyVxlanGpeAddDelTunnelWasInvoked(final VxlanGpe vxlanGpe) - throws VppBaseCallException { + throws VppBaseCallException { ArgumentCaptor argumentCaptor = ArgumentCaptor.forClass(VxlanGpeAddDelTunnel.class); verify(api).vxlanGpeAddDelTunnel(argumentCaptor.capture()); final VxlanGpeAddDelTunnel actual = argumentCaptor.getValue(); assertEquals(0, actual.isIpv6); assertArrayEquals(InetAddresses.forString(vxlanGpe.getLocal().getIpv4Address().getValue()).getAddress(), - actual.local); + actual.local); assertArrayEquals(InetAddresses.forString(vxlanGpe.getRemote().getIpv4Address().getValue()).getAddress(), - actual.remote); + actual.remote); assertEquals(vxlanGpe.getVni().getValue().intValue(), actual.vni); assertEquals(vxlanGpe.getNextProtocol().getIntValue(), actual.protocol); assertEquals(vxlanGpe.getEncapVrfId().intValue(), actual.encapVrfId); @@ -127,7 +108,7 @@ public class VxlanGpeCustomizerTest extends WriterCustomizerTest { assertEquals(ADD_VXLAN_GPE, actual.isAdd); } - private void verifyVxlanGpeDeleteWasInvoked(final VxlanGpe vxlanGpe) throws VppBaseCallException{ + private void verifyVxlanGpeDeleteWasInvoked(final VxlanGpe vxlanGpe) throws VppBaseCallException { final VxlanGpeAddDelTunnel actual = verifyVxlanGpeAddDelTunnelWasInvoked(vxlanGpe); assertEquals(DEL_VXLAN_GPE, actual.isAdd); } @@ -157,7 +138,7 @@ public class VxlanGpeCustomizerTest extends WriterCustomizerTest { customizer.writeCurrentAttributes(id, vxlanGpe, writeContext); verifyVxlanGpeAddWasInvoked(vxlanGpe); verify(mappingContext).put(eq(getMappingIid(ifaceName, "test-instance")), eq( - getMapping(ifaceName, 0).get())); + getMapping(ifaceName, 0).get())); } @Test @@ -190,8 +171,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(getMappingIid(ifaceName, "test-instance")), eq( + getMapping(ifaceName, 0).get())); return; } fail("WriteFailedException.CreateFailedException 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 f3c9e79f7..7b1fb53e0 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 @@ -16,8 +16,6 @@ package io.fd.honeycomb.translate.v3po.interfaces.ip; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import static org.mockito.Matchers.any; @@ -33,19 +31,15 @@ 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.test.TestHelperUtils; -import io.fd.honeycomb.vpp.test.write.WriterCustomizerTest; import io.fd.honeycomb.translate.v3po.util.NamingContext; import io.fd.honeycomb.translate.write.WriteFailedException; +import io.fd.honeycomb.vpp.test.write.WriterCustomizerTest; import java.util.Arrays; import java.util.Collections; import java.util.List; -import java.util.concurrent.CompletableFuture; import org.junit.Before; import org.junit.Test; -import org.mockito.ArgumentCaptor; import org.mockito.ArgumentMatcher; -import org.mockito.Captor; import org.mockito.Mock; import org.mockito.Mockito; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address; @@ -65,7 +59,6 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev14061 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DottedQuad; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.openvpp.jvpp.VppBaseCallException; -import org.openvpp.jvpp.VppInvocationException; import org.openvpp.jvpp.core.dto.IpAddressDetailsReplyDump; import org.openvpp.jvpp.core.dto.SwInterfaceAddDelAddress; import org.openvpp.jvpp.core.dto.SwInterfaceAddDelAddressReply; @@ -76,9 +69,6 @@ public class Ipv4AddressCustomizerTest extends WriterCustomizerTest { private static final String IFACE_NAME = "eth0"; private static final int IFACE_ID = 123; - @Captor - private ArgumentCaptor> addressesCaptor; - @Mock private SubnetValidator subnetValidator; @@ -91,10 +81,7 @@ public class Ipv4AddressCustomizerTest extends WriterCustomizerTest { customizer = new Ipv4AddressCustomizer(api, interfaceContext, subnetValidator); - CompletableFuture future = new CompletableFuture(); - future.complete(new IpAddressDetailsReplyDump()); - - when(api.ipAddressDump(Mockito.any())).thenReturn(future); + doReturn(future(new IpAddressDetailsReplyDump())).when(api).ipAddressDump(any()); when(writeContext.readAfter(Mockito.any())) .thenReturn(Optional.of(new Ipv4Builder().setAddress(Collections.emptyList()).build())); } @@ -109,34 +96,11 @@ public class Ipv4AddressCustomizerTest extends WriterCustomizerTest { } private void whenSwInterfaceAddDelAddressThenSuccess() { - final CompletableFuture replyFuture = new CompletableFuture<>(); - final SwInterfaceAddDelAddressReply reply = new SwInterfaceAddDelAddressReply(); - replyFuture.complete(reply); - doReturn(replyFuture).when(api).swInterfaceAddDelAddress(any(SwInterfaceAddDelAddress.class)); + doReturn(future(new SwInterfaceAddDelAddressReply())).when(api).swInterfaceAddDelAddress(any(SwInterfaceAddDelAddress.class)); } private void whenSwInterfaceAddDelAddressThenFailure() { - doReturn(TestHelperUtils.createFutureException()).when(api) - .swInterfaceAddDelAddress(any(SwInterfaceAddDelAddress.class)); - } - - private void verifySwInterfaceAddDelAddressWasInvoked(final SwInterfaceAddDelAddress expected) throws - VppInvocationException { - ArgumentCaptor argumentCaptor = - ArgumentCaptor.forClass(SwInterfaceAddDelAddress.class); - verify(api).swInterfaceAddDelAddress(argumentCaptor.capture()); - verifySwInterfaceAddDelAddressWasInvoked(expected, argumentCaptor.getValue()); - } - - private void verifySwInterfaceAddDelAddressWasInvoked(final SwInterfaceAddDelAddress expected, - final SwInterfaceAddDelAddress actual) throws - VppInvocationException { - assertArrayEquals(expected.address, actual.address); - assertEquals(expected.addressLength, actual.addressLength); - assertEquals(expected.delAll, actual.delAll); - assertEquals(expected.isAdd, actual.isAdd); - assertEquals(expected.isIpv6, actual.isIpv6); - assertEquals(expected.swIfIndex, actual.swIfIndex); + doReturn(failedFuture()).when(api).swInterfaceAddDelAddress(any(SwInterfaceAddDelAddress.class)); } @Test @@ -155,7 +119,7 @@ public class Ipv4AddressCustomizerTest extends WriterCustomizerTest { customizer.writeCurrentAttributes(id, data, writeContext); - verifySwInterfaceAddDelAddressWasInvoked(generateSwInterfaceAddDelAddressRequest(new byte[]{-64, -88, 2, 1}, + verify(api).swInterfaceAddDelAddress(generateSwInterfaceAddDelAddressRequest(new byte[]{-64, -88, 2, 1}, (byte) 1, (byte) 24)); } @@ -175,7 +139,7 @@ public class Ipv4AddressCustomizerTest extends WriterCustomizerTest { customizer.writeCurrentAttributes(id, data, writeContext); } catch (WriteFailedException e) { assertTrue(e.getCause() instanceof VppBaseCallException); - verifySwInterfaceAddDelAddressWasInvoked( + verify(api).swInterfaceAddDelAddress( generateSwInterfaceAddDelAddressRequest(new byte[]{-64, -88, 2, 1}, (byte) 1, (byte) 24)); return; @@ -211,8 +175,7 @@ public class Ipv4AddressCustomizerTest extends WriterCustomizerTest { assertTrue(e.getCause() instanceof SubnetValidationException); //verify that validation call was invoked with data from writeContext - verify(subnetValidator, times(1)).checkNotAddingToSameSubnet(addressesCaptor.capture()); - assertEquals(addressList, addressesCaptor.getValue()); + verify(subnetValidator, times(1)).checkNotAddingToSameSubnet(addressList); } } @@ -252,7 +215,7 @@ public class Ipv4AddressCustomizerTest extends WriterCustomizerTest { customizer.deleteCurrentAttributes(id, data, writeContext); - verifySwInterfaceAddDelAddressWasInvoked(generateSwInterfaceAddDelAddressRequest(new byte[]{-64, -88, 2, 1}, + verify(api).swInterfaceAddDelAddress(generateSwInterfaceAddDelAddressRequest(new byte[]{-64, -88, 2, 1}, (byte) 0, (byte) 24)); } @@ -271,7 +234,7 @@ public class Ipv4AddressCustomizerTest extends WriterCustomizerTest { customizer.deleteCurrentAttributes(id, data, writeContext); } catch (WriteFailedException e) { assertTrue(e.getCause() instanceof VppBaseCallException); - verifySwInterfaceAddDelAddressWasInvoked( + verify(api).swInterfaceAddDelAddress( generateSwInterfaceAddDelAddressRequest(new byte[]{-64, -88, 2, 1}, (byte) 0, (byte) 24)); return; @@ -288,17 +251,12 @@ public class Ipv4AddressCustomizerTest extends WriterCustomizerTest { Address data = new AddressBuilder().setIp(noZoneIp).setSubnet(subnet).build(); ContextTestUtils.mockMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME); - - final CompletableFuture replyFuture = new CompletableFuture<>(); - replyFuture.complete(new SwInterfaceAddDelAddressReply()); - ArgumentCaptor argumentCaptor = - ArgumentCaptor.forClass(SwInterfaceAddDelAddress.class); - doReturn(replyFuture).when(api).swInterfaceAddDelAddress(argumentCaptor.capture()); + whenSwInterfaceAddDelAddressThenSuccess(); customizer.writeCurrentAttributes(id, data, writeContext); - verifySwInterfaceAddDelAddressWasInvoked(generateSwInterfaceAddDelAddressRequest(new byte[]{-64, -88, 2, 1}, - (byte) 1, (byte) expectedPrefixLength), argumentCaptor.getValue()); + verify(api).swInterfaceAddDelAddress(generateSwInterfaceAddDelAddressRequest(new byte[]{-64, -88, 2, 1}, + (byte) 1, (byte) expectedPrefixLength)); } private void testSingleIllegalNetmask(final String stringMask) throws Exception { @@ -311,12 +269,7 @@ public class Ipv4AddressCustomizerTest extends WriterCustomizerTest { Address data = new AddressBuilder().setIp(noZoneIp).setSubnet(subnet).build(); ContextTestUtils.mockMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME); - - final CompletableFuture replyFuture = new CompletableFuture<>(); - replyFuture.complete(new SwInterfaceAddDelAddressReply()); - ArgumentCaptor argumentCaptor = - ArgumentCaptor.forClass(SwInterfaceAddDelAddress.class); - doReturn(replyFuture).when(api).swInterfaceAddDelAddress(argumentCaptor.capture()); + whenSwInterfaceAddDelAddressThenSuccess(); customizer.writeCurrentAttributes(id, data, writeContext); } catch (IllegalArgumentException e) { 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 dcde0b43d..745276473 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 @@ -17,21 +17,20 @@ package io.fd.honeycomb.translate.v3po.interfaces.ip; import static org.junit.Assert.assertEquals; +import static org.mockito.Matchers.any; import static org.mockito.Mockito.times; 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.vpp.test.write.WriterCustomizerTest; import io.fd.honeycomb.translate.v3po.util.NamingContext; import io.fd.honeycomb.translate.v3po.util.TranslateUtils; import io.fd.honeycomb.translate.write.WriteFailedException; -import java.util.concurrent.CompletableFuture; +import io.fd.honeycomb.vpp.test.write.WriterCustomizerTest; import org.junit.Before; import org.junit.Test; import org.mockito.ArgumentCaptor; -import org.mockito.Mockito; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces; @@ -61,9 +60,7 @@ public class Ipv4NeighbourCustomizerTest extends WriterCustomizerTest { customizer = new Ipv4NeighbourCustomizer(api, new NamingContext("prefix", IFC_CTX_NAME)); requestCaptor = ArgumentCaptor.forClass(IpNeighborAddDel.class); - CompletableFuture future = new CompletableFuture<>(); - future.complete(new IpNeighborAddDelReply()); - when(api.ipNeighborAddDel(Mockito.any(IpNeighborAddDel.class))).thenReturn(future); + when(api.ipNeighborAddDel(any())).thenReturn(future(new IpNeighborAddDelReply())); } @Test -- cgit 1.2.3-korg