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/VxlanCustomizerTest.java | 38 ++++------------------ 1 file changed, 7 insertions(+), 31 deletions(-) (limited to 'v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/VxlanCustomizerTest.java') 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 { -- cgit 1.2.3-korg