summaryrefslogtreecommitdiffstats
path: root/v3po/v3po2vpp/src/test/java/io
diff options
context:
space:
mode:
authorTibor Sirovatka <tsirovat@cisco.com>2016-06-10 15:42:30 +0200
committerTibor Sirovatka <tsirovat@cisco.com>2016-06-14 14:45:30 +0200
commit9ad6dfd73089e26bb74cea9ab775cb9030dacb46 (patch)
treeea15b787d8b72dce88304ee67e6909d82b890308 /v3po/v3po2vpp/src/test/java/io
parentdb0c27ecfeb80bac3ecb7b1fb34c7e20e60068ea (diff)
HONEYCOMB-67: Minor corrections in tests, styles
Removed unnecessary calls from tests Sonar corrections Change-Id: Ib182d66fd47a4feb9686989d086482ffe188470f Signed-off-by: Tibor Sirovatka <tsirovat@cisco.com>
Diffstat (limited to 'v3po/v3po2vpp/src/test/java/io')
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/RewriteCustomizerTest.java56
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/SubInterfaceCustomizerTest.java20
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/VhostUserCustomizerTest.java91
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/VxlanCustomizerTest.java55
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/VxlanGpeCustomizerTest.java32
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/test/TestHelperUtils.java8
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/vpp/BridgeDomainCustomizerTest.java62
7 files changed, 159 insertions, 165 deletions
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/RewriteCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/RewriteCustomizerTest.java
index 655bda525..45eaf9ec9 100644
--- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/RewriteCustomizerTest.java
+++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/RewriteCustomizerTest.java
@@ -16,6 +16,15 @@
package io.fd.honeycomb.v3po.translate.v3po.interfaces;
+import static io.fd.honeycomb.v3po.translate.v3po.test.ContextTestUtils.getMapping;
+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 com.google.common.base.Optional;
import io.fd.honeycomb.v3po.translate.MappingContext;
import io.fd.honeycomb.v3po.translate.v3po.test.TestHelperUtils;
@@ -23,6 +32,8 @@ import io.fd.honeycomb.v3po.translate.v3po.util.NamingContext;
import io.fd.honeycomb.v3po.translate.v3po.util.TagRewriteOperation;
import io.fd.honeycomb.v3po.translate.write.WriteContext;
import io.fd.honeycomb.v3po.translate.write.WriteFailedException;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
@@ -32,7 +43,6 @@ import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.cont
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;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.*;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.SubinterfaceAugmentation;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527._802dot1q;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.interfaces._interface.SubInterfaces;
@@ -48,18 +58,6 @@ import org.openvpp.jvpp.dto.L2InterfaceVlanTagRewrite;
import org.openvpp.jvpp.dto.L2InterfaceVlanTagRewriteReply;
import org.openvpp.jvpp.future.FutureJVpp;
-import java.util.concurrent.CompletableFuture;
-import java.util.concurrent.ExecutionException;
-
-import static io.fd.honeycomb.v3po.translate.v3po.test.ContextTestUtils.getMapping;
-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;
-
public class RewriteCustomizerTest {
@Mock
@@ -104,7 +102,8 @@ public class RewriteCustomizerTest {
return builder.build();
}
- private L2InterfaceVlanTagRewrite generateL2InterfaceVlanTagRewrite(final int swIfIndex, final TagRewriteOperation op) {
+ private L2InterfaceVlanTagRewrite generateL2InterfaceVlanTagRewrite(final int swIfIndex,
+ final TagRewriteOperation op) {
final L2InterfaceVlanTagRewrite request = new L2InterfaceVlanTagRewrite();
request.swIfIndex = swIfIndex;
request.vtrOp = op.ordinal();
@@ -115,7 +114,8 @@ public class RewriteCustomizerTest {
/**
* Positive response
*/
- private void whenL2InterfaceVlanTagRewriteThen() throws ExecutionException, InterruptedException, VppInvocationException {
+ private void whenL2InterfaceVlanTagRewriteThenSuccess()
+ throws ExecutionException, InterruptedException, VppInvocationException {
final CompletableFuture<L2InterfaceVlanTagRewriteReply> replyFuture = new CompletableFuture<>();
final L2InterfaceVlanTagRewriteReply reply = new L2InterfaceVlanTagRewriteReply();
replyFuture.complete(reply);
@@ -125,20 +125,16 @@ public class RewriteCustomizerTest {
/**
* Failure response send
*/
- private void whenL2InterfaceVlanTagRewriteFailedThen(final int retval) throws ExecutionException, InterruptedException, VppInvocationException {
- doReturn(TestHelperUtils.<L2InterfaceVlanTagRewriteReply>createFutureException(retval)).when(api).l2InterfaceVlanTagRewrite(any(L2InterfaceVlanTagRewrite.class));
- }
-
- private void whenL2InterfaceVlanTagRewriteThenSuccess() throws ExecutionException, InterruptedException, VppInvocationException {
- whenL2InterfaceVlanTagRewriteThen();
- }
-
- private void whenL2InterfaceVlanTagRewriteThenFailure() throws ExecutionException, InterruptedException, VppInvocationException {
- whenL2InterfaceVlanTagRewriteFailedThen(-1);
+ private void whenL2InterfaceVlanTagRewriteThenFailure()
+ throws ExecutionException, InterruptedException, VppInvocationException {
+ doReturn(TestHelperUtils.<L2InterfaceVlanTagRewriteReply>createFutureException()).when(api)
+ .l2InterfaceVlanTagRewrite(any(L2InterfaceVlanTagRewrite.class));
}
- private void verifyL2InterfaceVlanTagRewriteWasInvoked(final L2InterfaceVlanTagRewrite expected) throws VppInvocationException {
- ArgumentCaptor<L2InterfaceVlanTagRewrite> argumentCaptor = ArgumentCaptor.forClass(L2InterfaceVlanTagRewrite.class);
+ private void verifyL2InterfaceVlanTagRewriteWasInvoked(final L2InterfaceVlanTagRewrite expected)
+ throws VppInvocationException {
+ ArgumentCaptor<L2InterfaceVlanTagRewrite> argumentCaptor =
+ ArgumentCaptor.forClass(L2InterfaceVlanTagRewrite.class);
verify(api).l2InterfaceVlanTagRewrite(argumentCaptor.capture());
final L2InterfaceVlanTagRewrite actual = argumentCaptor.getValue();
assertEquals(expected.swIfIndex, actual.swIfIndex);
@@ -197,7 +193,8 @@ public class RewriteCustomizerTest {
customizer.updateCurrentAttributes(id, before, after, writeContext);
- verifyL2InterfaceVlanTagRewriteWasInvoked(generateL2InterfaceVlanTagRewrite(VLAN_IF_INDEX, TagRewriteOperation.pop_1));
+ verifyL2InterfaceVlanTagRewriteWasInvoked(
+ generateL2InterfaceVlanTagRewrite(VLAN_IF_INDEX, TagRewriteOperation.pop_1));
}
@Test
@@ -212,7 +209,8 @@ public class RewriteCustomizerTest {
customizer.updateCurrentAttributes(id, before, after, writeContext);
} catch (WriteFailedException.UpdateFailedException e) {
assertTrue(e.getCause() instanceof VppBaseCallException);
- verifyL2InterfaceVlanTagRewriteWasInvoked(generateL2InterfaceVlanTagRewrite(VLAN_IF_INDEX, TagRewriteOperation.pop_1));
+ verifyL2InterfaceVlanTagRewriteWasInvoked(generateL2InterfaceVlanTagRewrite(VLAN_IF_INDEX,
+ TagRewriteOperation.pop_1));
return;
}
fail("WriteFailedException.UpdateFailedException was expected");
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/SubInterfaceCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/SubInterfaceCustomizerTest.java
index 7161218a0..7df71fab3 100644
--- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/SubInterfaceCustomizerTest.java
+++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/SubInterfaceCustomizerTest.java
@@ -162,7 +162,7 @@ public class SubInterfaceCustomizerTest {
SubinterfaceAugmentation.class).child(SubInterfaces.class).child(SubInterface.class, new SubInterfaceKey(index));
}
- private void whenCreateSubifThen() throws ExecutionException, InterruptedException, VppBaseCallException {
+ private void whenCreateSubifThenSuccess() throws ExecutionException, InterruptedException, VppBaseCallException {
final CompletableFuture<CreateSubifReply> replyFuture = new CompletableFuture<>();
final CreateSubifReply reply = new CreateSubifReply();
replyFuture.complete(reply);
@@ -172,29 +172,17 @@ public class SubInterfaceCustomizerTest {
/**
* Failure response send
*/
- private void whenCreateSubifFailedThen(final int retval) throws ExecutionException, InterruptedException, VppBaseCallException {
- doReturn(TestHelperUtils.<CreateSubifReply>createFutureException(retval)).when(api).createSubif(any(CreateSubif.class));
+ private void whenCreateSubifThenFailure() throws ExecutionException, InterruptedException, VppBaseCallException {
+ doReturn(TestHelperUtils.<CreateSubifReply>createFutureException()).when(api).createSubif(any(CreateSubif.class));
}
- private void whenSwInterfaceSetFlagsThen(final int retval) throws ExecutionException, InterruptedException, VppBaseCallException {
+ private void whenSwInterfaceSetFlagsThenSuccess() throws ExecutionException, InterruptedException, VppBaseCallException {
final CompletableFuture<SwInterfaceSetFlagsReply> replyFuture = new CompletableFuture<>();
final SwInterfaceSetFlagsReply reply = new SwInterfaceSetFlagsReply();
replyFuture.complete(reply);
doReturn(replyFuture).when(api).swInterfaceSetFlags(any(SwInterfaceSetFlags.class));
}
- private void whenCreateSubifThenSuccess() throws ExecutionException, InterruptedException, VppBaseCallException {
- whenCreateSubifThen();
- }
-
- private void whenCreateSubifThenFailure() throws ExecutionException, InterruptedException, VppBaseCallException {
- whenCreateSubifFailedThen(-1);
- }
-
- private void whenSwInterfaceSetFlagsThenSuccess() throws ExecutionException, InterruptedException, VppBaseCallException {
- whenSwInterfaceSetFlagsThen(0);
- }
-
private CreateSubif verifyCreateSubifWasInvoked(final CreateSubif expected) throws VppBaseCallException {
ArgumentCaptor<CreateSubif> argumentCaptor = ArgumentCaptor.forClass(CreateSubif.class);
verify(api).createSubif(argumentCaptor.capture());
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/VhostUserCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/VhostUserCustomizerTest.java
index 714466ec8..82952ec35 100644
--- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/VhostUserCustomizerTest.java
+++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/VhostUserCustomizerTest.java
@@ -18,6 +18,21 @@ package io.fd.honeycomb.v3po.translate.v3po.interfaces;
import static io.fd.honeycomb.v3po.translate.v3po.test.ContextTestUtils.getMapping;
import static io.fd.honeycomb.v3po.translate.v3po.test.ContextTestUtils.getMappingIid;
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+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.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 static org.mockito.MockitoAnnotations.initMocks;
+
import io.fd.honeycomb.v3po.translate.MappingContext;
import io.fd.honeycomb.v3po.translate.ModificationCache;
import io.fd.honeycomb.v3po.translate.v3po.test.TestHelperUtils;
@@ -25,6 +40,9 @@ import io.fd.honeycomb.v3po.translate.v3po.util.NamingContext;
import io.fd.honeycomb.v3po.translate.v3po.util.TranslateUtils;
import io.fd.honeycomb.v3po.translate.write.WriteContext;
import io.fd.honeycomb.v3po.translate.write.WriteFailedException;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.CompletionStage;
+import java.util.concurrent.ExecutionException;
import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
@@ -39,19 +57,14 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.openvpp.jvpp.VppBaseCallException;
import org.openvpp.jvpp.VppInvocationException;
-import org.openvpp.jvpp.dto.*;
+import org.openvpp.jvpp.dto.CreateVhostUserIf;
+import org.openvpp.jvpp.dto.CreateVhostUserIfReply;
+import org.openvpp.jvpp.dto.DeleteVhostUserIf;
+import org.openvpp.jvpp.dto.DeleteVhostUserIfReply;
+import org.openvpp.jvpp.dto.ModifyVhostUserIf;
+import org.openvpp.jvpp.dto.ModifyVhostUserIfReply;
import org.openvpp.jvpp.future.FutureJVpp;
-import java.util.concurrent.CompletableFuture;
-import java.util.concurrent.CompletionStage;
-import java.util.concurrent.ExecutionException;
-
-import static org.junit.Assert.*;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.*;
-import static org.mockito.MockitoAnnotations.initMocks;
-
public class VhostUserCustomizerTest {
@Mock
@@ -82,7 +95,8 @@ public class VhostUserCustomizerTest {
customizer = new VhostUserCustomizer(api, namingContext);
}
- private void whenCreateVhostUserIfThen() throws ExecutionException, InterruptedException, VppInvocationException {
+ private void whenCreateVhostUserIfThenSuccess()
+ throws ExecutionException, InterruptedException, VppInvocationException {
final CompletionStage<CreateVhostUserIfReply> replyCS = mock(CompletionStage.class);
final CompletableFuture<CreateVhostUserIfReply> replyFuture = mock(CompletableFuture.class);
when(replyCS.toCompletableFuture()).thenReturn(replyFuture);
@@ -94,19 +108,14 @@ public class VhostUserCustomizerTest {
/**
* Failure response send
*/
- private void whenCreateVhostUserIfFailedThen(final int retval) throws ExecutionException, InterruptedException, VppInvocationException {
- doReturn(TestHelperUtils.<CreateVhostUserIfReply>createFutureException(retval)).when(api).createVhostUserIf(any(CreateVhostUserIf.class));
- }
-
- private void whenCreateVhostUserIfThenSuccess() throws ExecutionException, InterruptedException, VppInvocationException {
- whenCreateVhostUserIfThen();
+ private void whenCreateVhostUserIfThenFailure()
+ throws ExecutionException, InterruptedException, VppInvocationException {
+ doReturn(TestHelperUtils.<CreateVhostUserIfReply>createFutureException()).when(api)
+ .createVhostUserIf(any(CreateVhostUserIf.class));
}
- private void whenVxlanAddDelTunnelThenFailure() throws ExecutionException, InterruptedException, VppInvocationException {
- whenCreateVhostUserIfFailedThen(-1);
- }
-
- private void whenModifyVhostUserIfThen() throws ExecutionException, InterruptedException, VppInvocationException {
+ private void whenModifyVhostUserIfThenSuccess()
+ throws ExecutionException, InterruptedException, VppInvocationException {
final CompletionStage<ModifyVhostUserIfReply> replyCS = mock(CompletionStage.class);
final CompletableFuture<ModifyVhostUserIfReply> replyFuture = mock(CompletableFuture.class);
when(replyCS.toCompletableFuture()).thenReturn(replyFuture);
@@ -118,19 +127,14 @@ public class VhostUserCustomizerTest {
/**
* Failure response send
*/
- private void whenModifyVhostUserIfFailedThen(final int retval) throws ExecutionException, InterruptedException, VppInvocationException {
- doReturn(TestHelperUtils.<ModifyVhostUserIfReply>createFutureException(retval)).when(api).modifyVhostUserIf(any(ModifyVhostUserIf.class));
- }
-
- private void whenModifyVhostUserIfThenSuccess() throws ExecutionException, InterruptedException, VppInvocationException {
- whenModifyVhostUserIfThen();
+ private void whenModifyVhostUserIfThenFailure()
+ throws ExecutionException, InterruptedException, VppInvocationException {
+ doReturn(TestHelperUtils.<ModifyVhostUserIfReply>createFutureException()).when(api)
+ .modifyVhostUserIf(any(ModifyVhostUserIf.class));
}
- private void whenModifyVhostUserIfThenFailure() throws ExecutionException, InterruptedException, VppInvocationException {
- whenModifyVhostUserIfFailedThen(-1);
- }
-
- private void whenDeleteVhostUserIfThen() throws ExecutionException, InterruptedException, VppInvocationException {
+ private void whenDeleteVhostUserIfThenSuccess()
+ throws ExecutionException, InterruptedException, VppInvocationException {
final CompletionStage<DeleteVhostUserIfReply> replyCS = mock(CompletionStage.class);
final CompletableFuture<DeleteVhostUserIfReply> replyFuture = mock(CompletableFuture.class);
when(replyCS.toCompletableFuture()).thenReturn(replyFuture);
@@ -142,16 +146,10 @@ public class VhostUserCustomizerTest {
/**
* Failure response send
*/
- private void whenDeleteVhostUserIfFailedThen(final int retval) throws ExecutionException, InterruptedException, VppInvocationException {
- doReturn(TestHelperUtils.<DeleteVhostUserIfReply>createFutureException(retval)).when(api).deleteVhostUserIf(any(DeleteVhostUserIf.class));
- }
-
- private void whenDeleteVhostUserIfThenSuccess() throws ExecutionException, InterruptedException, VppInvocationException {
- whenDeleteVhostUserIfThen();
- }
-
- private void whenDeleteVhostUserIfThenFailure() throws ExecutionException, InterruptedException, VppInvocationException {
- whenDeleteVhostUserIfFailedThen(-1);
+ private void whenDeleteVhostUserIfThenFailure()
+ throws ExecutionException, InterruptedException, VppInvocationException {
+ doReturn(TestHelperUtils.<DeleteVhostUserIfReply>createFutureException()).when(api)
+ .deleteVhostUserIf(any(DeleteVhostUserIf.class));
}
private CreateVhostUserIf verifyCreateVhostUserIfWasInvoked(final VhostUser vhostUser) throws VppInvocationException {
@@ -168,7 +166,8 @@ public class VhostUserCustomizerTest {
return actual;
}
- private ModifyVhostUserIf verifyModifyVhostUserIfWasInvoked(final VhostUser vhostUser, final int swIfIndex) throws VppInvocationException {
+ private ModifyVhostUserIf verifyModifyVhostUserIfWasInvoked(final VhostUser vhostUser, final int swIfIndex)
+ throws VppInvocationException {
ArgumentCaptor<ModifyVhostUserIf> argumentCaptor = ArgumentCaptor.forClass(ModifyVhostUserIf.class);
verify(api).modifyVhostUserIf(argumentCaptor.capture());
final ModifyVhostUserIf actual = argumentCaptor.getValue();
@@ -211,7 +210,7 @@ public class VhostUserCustomizerTest {
public void testWriteCurrentAttributesFailed() throws Exception {
final VhostUser vhostUser = generateVhostUser(VhostUserRole.Client, "socketName");
- whenVxlanAddDelTunnelThenFailure();
+ whenCreateVhostUserIfThenFailure();
try {
customizer.writeCurrentAttributes(ID, vhostUser, writeContext);
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/VxlanCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/VxlanCustomizerTest.java
index e716dc6dc..afe26beff 100644
--- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/VxlanCustomizerTest.java
+++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/VxlanCustomizerTest.java
@@ -16,6 +16,22 @@
package io.fd.honeycomb.v3po.translate.v3po.interfaces;
+import static io.fd.honeycomb.v3po.translate.v3po.test.ContextTestUtils.getMapping;
+import static io.fd.honeycomb.v3po.translate.v3po.test.ContextTestUtils.getMappingIid;
+import static java.util.Collections.singletonList;
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import static org.mockito.Matchers.any;
+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 static org.mockito.MockitoAnnotations.initMocks;
+
import com.google.common.base.Optional;
import com.google.common.net.InetAddresses;
import io.fd.honeycomb.v3po.translate.MappingContext;
@@ -24,6 +40,9 @@ import io.fd.honeycomb.v3po.translate.v3po.test.TestHelperUtils;
import io.fd.honeycomb.v3po.translate.v3po.util.NamingContext;
import io.fd.honeycomb.v3po.translate.write.WriteContext;
import io.fd.honeycomb.v3po.translate.write.WriteFailedException;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.CompletionStage;
+import java.util.concurrent.ExecutionException;
import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
@@ -47,19 +66,6 @@ import org.openvpp.jvpp.dto.VxlanAddDelTunnel;
import org.openvpp.jvpp.dto.VxlanAddDelTunnelReply;
import org.openvpp.jvpp.future.FutureJVpp;
-import java.util.concurrent.CompletableFuture;
-import java.util.concurrent.CompletionStage;
-import java.util.concurrent.ExecutionException;
-
-import static io.fd.honeycomb.v3po.translate.v3po.test.ContextTestUtils.getMapping;
-import static io.fd.honeycomb.v3po.translate.v3po.test.ContextTestUtils.getMappingIid;
-import static java.util.Collections.singletonList;
-import static org.junit.Assert.*;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.*;
-import static org.mockito.MockitoAnnotations.initMocks;
-
public class VxlanCustomizerTest {
private static final byte ADD_VXLAN = 1;
@@ -94,7 +100,7 @@ public class VxlanCustomizerTest {
.augmentation(VppInterfaceAugmentation.class).child(Vxlan.class);
}
- private void whenVxlanAddDelTunnelThen() throws ExecutionException, InterruptedException, VppInvocationException {
+ private void whenVxlanAddDelTunnelThenSuccess() throws ExecutionException, InterruptedException, VppInvocationException {
final CompletionStage<VxlanAddDelTunnelReply> replyCS = mock(CompletionStage.class);
final CompletableFuture<VxlanAddDelTunnelReply> replyFuture = mock(CompletableFuture.class);
when(replyCS.toCompletableFuture()).thenReturn(replyFuture);
@@ -106,16 +112,10 @@ public class VxlanCustomizerTest {
/**
* Failure response send
*/
- private void whenVxlanAddDelTunnelFailedThen(final int retval) throws ExecutionException, InterruptedException, VppInvocationException {
- doReturn(TestHelperUtils.<VxlanAddDelTunnelReply>createFutureException(retval)).when(api).vxlanAddDelTunnel(any(VxlanAddDelTunnel.class));
- }
-
- private void whenVxlanAddDelTunnelThenSuccess() throws ExecutionException, InterruptedException, VppInvocationException {
- whenVxlanAddDelTunnelThen();
- }
-
- private void whenVxlanAddDelTunnelThenFailure() throws ExecutionException, InterruptedException, VppInvocationException {
- whenVxlanAddDelTunnelFailedThen(-1);
+ private void whenVxlanAddDelTunnelThenFailure()
+ throws ExecutionException, InterruptedException, VppInvocationException {
+ doReturn(TestHelperUtils.<VxlanAddDelTunnelReply>createFutureException()).when(api)
+ .vxlanAddDelTunnel(any(VxlanAddDelTunnel.class));
}
private VxlanAddDelTunnel verifyVxlanAddDelTunnelWasInvoked(final Vxlan vxlan) throws VppInvocationException {
@@ -124,12 +124,15 @@ public class VxlanCustomizerTest {
final VxlanAddDelTunnel actual = argumentCaptor.getValue();
assertEquals(0, actual.isIpv6);
assertEquals(-1, actual.decapNextIndex);
- assertArrayEquals(InetAddresses.forString(vxlan.getSrc().getIpv4Address().getValue()).getAddress(), actual.srcAddress);
- assertArrayEquals(InetAddresses.forString(vxlan.getDst().getIpv4Address().getValue()).getAddress(), actual.dstAddress);
+ assertArrayEquals(InetAddresses.forString(vxlan.getSrc().getIpv4Address().getValue()).getAddress(),
+ actual.srcAddress);
+ assertArrayEquals(InetAddresses.forString(vxlan.getDst().getIpv4Address().getValue()).getAddress(),
+ actual.dstAddress);
assertEquals(vxlan.getEncapVrfId().intValue(), actual.encapVrfId);
assertEquals(vxlan.getVni().getValue().intValue(), actual.vni);
return actual;
}
+
private void verifyVxlanAddWasInvoked(final Vxlan vxlan) throws VppInvocationException {
final VxlanAddDelTunnel actual = verifyVxlanAddDelTunnelWasInvoked(vxlan);
assertEquals(ADD_VXLAN, actual.isAdd);
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/VxlanGpeCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/VxlanGpeCustomizerTest.java
index 2ad831f9f..a4fa2f188 100644
--- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/VxlanGpeCustomizerTest.java
+++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/VxlanGpeCustomizerTest.java
@@ -101,7 +101,8 @@ public class VxlanGpeCustomizerTest {
.augmentation(VppInterfaceAugmentation.class).child(VxlanGpe.class);
}
- private void whenVxlanGpeAddDelTunnelThen() throws ExecutionException, InterruptedException, VppBaseCallException {
+ private void whenVxlanGpeAddDelTunnelThenSuccess()
+ throws ExecutionException, InterruptedException, VppBaseCallException {
final CompletionStage<VxlanGpeAddDelTunnelReply> replyCS = mock(CompletionStage.class);
final CompletableFuture<VxlanGpeAddDelTunnelReply> replyFuture = mock(CompletableFuture.class);
when(replyCS.toCompletableFuture()).thenReturn(replyFuture);
@@ -110,35 +111,33 @@ public class VxlanGpeCustomizerTest {
when(api.vxlanGpeAddDelTunnel(any(VxlanGpeAddDelTunnel.class))).thenReturn(replyCS);
}
- private void whenVxlanGpeAddDelTunnelThenSuccess() throws ExecutionException, InterruptedException, VppBaseCallException {
- whenVxlanGpeAddDelTunnelThen();
- }
-
- private void whenVxlanGpeAddDelTunnelThenFailure() throws ExecutionException, InterruptedException, VppBaseCallException {
- whenVxlanGpeAddDelTunnelFailedThen(-1);
- }
-
/**
* Failure response send
*/
- private void whenVxlanGpeAddDelTunnelFailedThen(final int retval) throws ExecutionException, InterruptedException, VppBaseCallException {
- doReturn(TestHelperUtils.<VxlanAddDelTunnelReply>createFutureException(retval)).when(api).vxlanGpeAddDelTunnel(any(VxlanGpeAddDelTunnel.class));
+ private void whenVxlanGpeAddDelTunnelThenFailure()
+ throws ExecutionException, InterruptedException, VppBaseCallException {
+ doReturn(TestHelperUtils.<VxlanAddDelTunnelReply>createFutureException()).when(api)
+ .vxlanGpeAddDelTunnel(any(VxlanGpeAddDelTunnel.class));
}
- private VxlanGpeAddDelTunnel verifyVxlanGpeAddDelTunnelWasInvoked(final VxlanGpe vxlanGpe) throws VppBaseCallException{
+ private VxlanGpeAddDelTunnel verifyVxlanGpeAddDelTunnelWasInvoked(final VxlanGpe vxlanGpe)
+ throws VppBaseCallException {
ArgumentCaptor<VxlanGpeAddDelTunnel> 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);
- assertArrayEquals(InetAddresses.forString(vxlanGpe.getRemote().getIpv4Address().getValue()).getAddress(), actual.remote);
+ assertArrayEquals(InetAddresses.forString(vxlanGpe.getLocal().getIpv4Address().getValue()).getAddress(),
+ actual.local);
+ assertArrayEquals(InetAddresses.forString(vxlanGpe.getRemote().getIpv4Address().getValue()).getAddress(),
+ actual.remote);
assertEquals(vxlanGpe.getVni().getValue().intValue(), actual.vni);
assertEquals(vxlanGpe.getNextProtocol().getIntValue(), actual.protocol);
assertEquals(vxlanGpe.getEncapVrfId().intValue(), actual.encapVrfId);
assertEquals(vxlanGpe.getDecapVrfId().intValue(), actual.decapVrfId);
return actual;
}
- private void verifyVxlanGpeAddWasInvoked(final VxlanGpe vxlanGpe) throws VppBaseCallException{
+
+ private void verifyVxlanGpeAddWasInvoked(final VxlanGpe vxlanGpe) throws VppBaseCallException {
final VxlanGpeAddDelTunnel actual = verifyVxlanGpeAddDelTunnelWasInvoked(vxlanGpe);
assertEquals(ADD_VXLAN_GPE, actual.isAdd);
}
@@ -207,7 +206,8 @@ public class VxlanGpeCustomizerTest {
assertTrue(e.getCause() instanceof VppBaseCallException);
verifyVxlanGpeAddWasInvoked(vxlanGpe);
// Mapping not stored due to failure
- verify(mappingContext, times(0)).put(eq(getMappingIid(ifaceName, "test-instance")), eq(getMapping(ifaceName, 0).get()));
+ verify(mappingContext, times(0))
+ .put(eq(getMappingIid(ifaceName, "test-instance")), eq(getMapping(ifaceName, 0).get()));
return;
}
fail("WriteFailedException.CreateFailedException was expected");
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/test/TestHelperUtils.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/test/TestHelperUtils.java
index 598b62f05..e82b3ec03 100644
--- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/test/TestHelperUtils.java
+++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/test/TestHelperUtils.java
@@ -22,14 +22,16 @@ import org.openvpp.jvpp.dto.JVppReply;
import java.util.concurrent.CompletableFuture;
public class TestHelperUtils {
+ private final static int ERROR_RETVAL = -1;
+
/**
* Static helper method for creation of Exception failure state in CompletableFuture object
- * @param retval result of the operation in exception
+ * with retval = -1
* @return CompletableFuture with VppCallbackException as a cause
*/
- public static CompletableFuture<? extends JVppReply> createFutureException(final int retval) {
+ public static CompletableFuture<? extends JVppReply> createFutureException() {
final CompletableFuture<? extends JVppReply> replyFuture = new CompletableFuture<>();
- replyFuture.completeExceptionally(new VppCallbackException("test-call", 1, retval));
+ replyFuture.completeExceptionally(new VppCallbackException("test-call", 1, ERROR_RETVAL));
return replyFuture;
}
}
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/vpp/BridgeDomainCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/vpp/BridgeDomainCustomizerTest.java
index 8f3c12083..50311a945 100644
--- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/vpp/BridgeDomainCustomizerTest.java
+++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/vpp/BridgeDomainCustomizerTest.java
@@ -17,6 +17,16 @@ package io.fd.honeycomb.v3po.translate.v3po.vpp;
import static io.fd.honeycomb.v3po.translate.v3po.test.ContextTestUtils.getMapping;
import static io.fd.honeycomb.v3po.translate.v3po.test.ContextTestUtils.getMappingIid;
+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.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+import static org.mockito.MockitoAnnotations.initMocks;
+
import com.google.common.base.Optional;
import io.fd.honeycomb.v3po.translate.MappingContext;
import io.fd.honeycomb.v3po.translate.ModificationCache;
@@ -24,6 +34,9 @@ import io.fd.honeycomb.v3po.translate.v3po.test.TestHelperUtils;
import io.fd.honeycomb.v3po.translate.v3po.util.NamingContext;
import io.fd.honeycomb.v3po.translate.write.WriteContext;
import io.fd.honeycomb.v3po.translate.write.WriteFailedException;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.CompletionStage;
+import java.util.concurrent.ExecutionException;
import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
@@ -36,16 +49,6 @@ import org.openvpp.jvpp.dto.BridgeDomainAddDel;
import org.openvpp.jvpp.dto.BridgeDomainAddDelReply;
import org.openvpp.jvpp.future.FutureJVpp;
-import java.util.concurrent.CompletableFuture;
-import java.util.concurrent.CompletionStage;
-import java.util.concurrent.ExecutionException;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
-import static org.mockito.Matchers.any;
-import static org.mockito.Mockito.*;
-import static org.mockito.MockitoAnnotations.initMocks;
-
public class BridgeDomainCustomizerTest {
private static final byte ADD_OR_UPDATE_BD = (byte) 1;
@@ -93,7 +96,8 @@ public class BridgeDomainCustomizerTest {
.build();
}
- private void verifyBridgeDomainAddOrUpdateWasInvoked(final BridgeDomain bd, final int bdId) throws VppInvocationException {
+ private void verifyBridgeDomainAddOrUpdateWasInvoked(final BridgeDomain bd, final int bdId)
+ throws VppInvocationException {
final byte arpTerm = BridgeDomainTestUtils.booleanToByte(bd.isArpTermination());
final byte flood = BridgeDomainTestUtils.booleanToByte(bd.isFlood());
final byte forward = BridgeDomainTestUtils.booleanToByte(bd.isForward());
@@ -126,7 +130,8 @@ public class BridgeDomainCustomizerTest {
assertEquals(ZERO, actual.isAdd);
}
- private void whenBridgeDomainAddDelThen() throws ExecutionException, InterruptedException, VppInvocationException {
+ private void whenBridgeDomainAddDelThenSuccess()
+ throws ExecutionException, InterruptedException, VppInvocationException {
final CompletionStage<BridgeDomainAddDelReply> replyCS = mock(CompletionStage.class);
final CompletableFuture<BridgeDomainAddDelReply> replyFuture = mock(CompletableFuture.class);
when(replyCS.toCompletableFuture()).thenReturn(replyFuture);
@@ -135,16 +140,10 @@ public class BridgeDomainCustomizerTest {
when(api.bridgeDomainAddDel(any(BridgeDomainAddDel.class))).thenReturn(replyCS);
}
- private void whenBridgeDomainAddDelFailedThen(final int retval) throws ExecutionException, InterruptedException, VppInvocationException {
- doReturn(TestHelperUtils.<BridgeDomainAddDelReply>createFutureException(retval)).when(api).bridgeDomainAddDel(any(BridgeDomainAddDel.class));
- }
-
- private void whenBridgeDomainAddDelThenSuccess() throws ExecutionException, InterruptedException, VppInvocationException {
- whenBridgeDomainAddDelThen();
- }
-
- private void whenBridgeDomainAddDelThenFailure() throws ExecutionException, InterruptedException, VppInvocationException {
- whenBridgeDomainAddDelFailedThen(-1);
+ private void whenBridgeDomainAddDelThenFailure()
+ throws ExecutionException, InterruptedException, VppInvocationException {
+ doReturn(TestHelperUtils.<BridgeDomainAddDelReply>createFutureException()).when(api)
+ .bridgeDomainAddDel(any(BridgeDomainAddDel.class));
}
@Test
@@ -152,7 +151,8 @@ public class BridgeDomainCustomizerTest {
final int bdId = 1;
final String bdName = "bd1";
final BridgeDomain bd = generateBridgeDomain(bdName);
- doReturn(Optional.absent()).when(mappingContext).read(getMappingIid(bdName, "test-instance").firstIdentifierOf(Mappings.class));
+ doReturn(Optional.absent()).when(mappingContext)
+ .read(getMappingIid(bdName, "test-instance").firstIdentifierOf(Mappings.class));
whenBridgeDomainAddDelThenSuccess();
@@ -169,7 +169,8 @@ public class BridgeDomainCustomizerTest {
final BridgeDomain bd = generateBridgeDomain(bdName);
// Returning no Mappings for "test-instance" makes bdContext.containsName() return false
- doReturn(Optional.absent()).when(mappingContext).read(getMappingIid(bdName, "test-instance").firstIdentifierOf(Mappings.class));
+ doReturn(Optional.absent()).when(mappingContext)
+ .read(getMappingIid(bdName, "test-instance").firstIdentifierOf(Mappings.class));
whenBridgeDomainAddDelThenFailure();
@@ -250,7 +251,8 @@ public class BridgeDomainCustomizerTest {
whenBridgeDomainAddDelThenSuccess();
- customizer.updateCurrentAttributes(BridgeDomainTestUtils.bdIdentifierForName(bdName), dataBefore, dataAfter, ctx);
+ customizer
+ .updateCurrentAttributes(BridgeDomainTestUtils.bdIdentifierForName(bdName), dataBefore, dataAfter, ctx);
verifyBridgeDomainAddOrUpdateWasInvoked(dataAfter, bdId);
}
@@ -258,12 +260,13 @@ public class BridgeDomainCustomizerTest {
@Test
public void testUpdateUnknownBridgeDomain() throws Exception {
final String bdName = "bd1";
- final BridgeDomain bdBefore = generateBridgeDomain(bdName, 0, 1, 0 ,1, 0);
- final BridgeDomain bdAfter = generateBridgeDomain(bdName, 1, 1, 0 ,1, 0);
+ final BridgeDomain bdBefore = generateBridgeDomain(bdName, 0, 1, 0, 1, 0);
+ final BridgeDomain bdAfter = generateBridgeDomain(bdName, 1, 1, 0, 1, 0);
doReturn(Optional.absent()).when(mappingContext).read(getMappingIid(bdName, "test-instance"));
try {
- customizer.updateCurrentAttributes(BridgeDomainTestUtils.bdIdentifierForName(bdName), bdBefore, bdAfter, ctx);
+ customizer
+ .updateCurrentAttributes(BridgeDomainTestUtils.bdIdentifierForName(bdName), bdBefore, bdAfter, ctx);
} catch (IllegalArgumentException e) {
verify(api, never()).bridgeDomainAddDel(any(BridgeDomainAddDel.class));
return;
@@ -282,7 +285,8 @@ public class BridgeDomainCustomizerTest {
whenBridgeDomainAddDelThenFailure();
try {
- customizer.updateCurrentAttributes(BridgeDomainTestUtils.bdIdentifierForName(bdName), bdBefore, bdAfter, ctx);
+ customizer
+ .updateCurrentAttributes(BridgeDomainTestUtils.bdIdentifierForName(bdName), bdBefore, bdAfter, ctx);
} catch (WriteFailedException.UpdateFailedException e) {
verifyBridgeDomainAddOrUpdateWasInvoked(bdAfter, bdId);
return;