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 --- .../lisp/translate/write/LispCustomizerTest.java | 75 +++++++++------------- 1 file changed, 30 insertions(+), 45 deletions(-) (limited to 'lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/write/LispCustomizerTest.java') diff --git a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/write/LispCustomizerTest.java b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/write/LispCustomizerTest.java index aaa73303c..171377cab 100755 --- a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/write/LispCustomizerTest.java +++ b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/write/LispCustomizerTest.java @@ -25,8 +25,7 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; 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.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.Lisp; @@ -36,7 +35,18 @@ import org.openvpp.jvpp.core.dto.LispEnableDisableReply; import org.openvpp.jvpp.core.future.FutureJVppCore; -public class LispCustomizerTest { +public class LispCustomizerTest extends WriterCustomizerTest { + + private LispCustomizer customizer; + + @Override + public void setUp() { + customizer = new LispCustomizer(api); + } + + private void whenlispEnableDisableThenSuccess() { + when(api.lispEnableDisable(any(LispEnableDisable.class))).thenReturn(future(new LispEnableDisableReply())); + } @Test(expected = NullPointerException.class) public void testWriteCurrentAttributesNullData() throws WriteFailedException { @@ -44,22 +54,14 @@ public class LispCustomizerTest { } @Test - public void testWriteCurrentAttributes() throws InterruptedException, ExecutionException, WriteFailedException { - FutureJVppCore fakeJvpp = mock(FutureJVppCore.class); + public void testWriteCurrentAttributes() throws WriteFailedException { Lisp intf = new LispBuilder().setEnable(true).build(); - ArgumentCaptor mappingCaptor = ArgumentCaptor.forClass(LispEnableDisable.class); - - LispEnableDisableReply fakeReply = new LispEnableDisableReply(); - - CompletableFuture completeFuture = new CompletableFuture<>(); - completeFuture.complete(fakeReply); - - when(fakeJvpp.lispEnableDisable(any(LispEnableDisable.class))).thenReturn(completeFuture); + whenlispEnableDisableThenSuccess(); + customizer.writeCurrentAttributes(null, intf, null); - new LispCustomizer(fakeJvpp).writeCurrentAttributes(null, intf, null); - - verify(fakeJvpp, times(1)).lispEnableDisable(mappingCaptor.capture()); + ArgumentCaptor mappingCaptor = ArgumentCaptor.forClass(LispEnableDisable.class); + verify(api, times(1)).lispEnableDisable(mappingCaptor.capture()); LispEnableDisable request = mappingCaptor.getValue(); @@ -69,26 +71,18 @@ public class LispCustomizerTest { @Test(expected = NullPointerException.class) public void testUpdateCurrentAttributesNullData() throws WriteFailedException { - new LispCustomizer(mock(FutureJVppCore.class)).updateCurrentAttributes(null, null, null, null); + customizer.updateCurrentAttributes(null, null, null, null); } @Test - public void testUpdateCurrentAttributes() throws WriteFailedException, InterruptedException, ExecutionException { - FutureJVppCore fakeJvpp = mock(FutureJVppCore.class); + public void testUpdateCurrentAttributes() throws WriteFailedException { Lisp lisp = new LispBuilder().setEnable(true).build(); - ArgumentCaptor lispCaptor = ArgumentCaptor.forClass(LispEnableDisable.class); - - LispEnableDisableReply fakeReply = new LispEnableDisableReply(); - - CompletableFuture completeFuture = new CompletableFuture<>(); - completeFuture.complete(fakeReply); - - when(fakeJvpp.lispEnableDisable(any(LispEnableDisable.class))).thenReturn(completeFuture); + whenlispEnableDisableThenSuccess(); + customizer.updateCurrentAttributes(null, null, lisp, null); - new LispCustomizer(fakeJvpp).updateCurrentAttributes(null, null, lisp, null); - - verify(fakeJvpp, times(1)).lispEnableDisable(lispCaptor.capture()); + ArgumentCaptor lispCaptor = ArgumentCaptor.forClass(LispEnableDisable.class); + verify(api, times(1)).lispEnableDisable(lispCaptor.capture()); LispEnableDisable request = lispCaptor.getValue(); @@ -98,31 +92,22 @@ public class LispCustomizerTest { @Test(expected = NullPointerException.class) public void testDeleteCurrentAttributesNullData() throws WriteFailedException { - new LispCustomizer(mock(FutureJVppCore.class)).deleteCurrentAttributes(null, null, null); + customizer.deleteCurrentAttributes(null, null, null); } @Test - public void testDeleteCurrentAttributes() throws WriteFailedException, InterruptedException, ExecutionException { - FutureJVppCore fakeJvpp = mock(FutureJVppCore.class); + public void testDeleteCurrentAttributes() throws WriteFailedException { Lisp lisp = new LispBuilder().setEnable(true).build(); - ArgumentCaptor lispCaptor = ArgumentCaptor.forClass(LispEnableDisable.class); - - LispEnableDisableReply fakeReply = new LispEnableDisableReply(); - - CompletableFuture completeFuture = new CompletableFuture<>(); - completeFuture.complete(fakeReply); - - when(fakeJvpp.lispEnableDisable(any(LispEnableDisable.class))).thenReturn(completeFuture); + whenlispEnableDisableThenSuccess(); + customizer.deleteCurrentAttributes(null, lisp, null); - new LispCustomizer(fakeJvpp).deleteCurrentAttributes(null, lisp, null); - - verify(fakeJvpp, times(1)).lispEnableDisable(lispCaptor.capture()); + ArgumentCaptor lispCaptor = ArgumentCaptor.forClass(LispEnableDisable.class); + verify(api, times(1)).lispEnableDisable(lispCaptor.capture()); LispEnableDisable request = lispCaptor.getValue(); assertNotNull(request); assertEquals(0, request.isEn); } - } -- cgit 1.2.3-korg