summaryrefslogtreecommitdiffstats
path: root/v3po/v3po2vpp/src/test
diff options
context:
space:
mode:
authorJan Srnicek <jsrnicek@cisco.com>2016-09-23 16:39:09 +0200
committerJan Srnicek <jsrnicek@cisco.com>2016-09-23 16:41:57 +0200
commita7147d16c31d9028c6b5dc557264433de0f11c91 (patch)
tree15816600ab3dfa5eea706ef1b1910b2e13ae66d7 /v3po/v3po2vpp/src/test
parente7a0775b21c2ea6b7bb8efb63b5384df26e27fbb (diff)
HONEYCOMB-145 - Utility Class Refactoring
problematic mockito-all changed to mockito-core( https://github.com/mockito/mockito/issues/324) Translate Utils Splitted to multiple Trait Interfaces Ipv4Translator - Logic for translation of ipv4-based data Ipv6Translator - Logic for translation of ipv6-based data MacTranslator - Logic for translation of mac-based data AddressTranslator - Aggregation trait for Ipv4/Ipv6/Mac JvppReplyConsumer - Logic for extracting replies from jvpp calls ByteDataTranslator - any byte-based conversions Plus some existing utility classes changed to traits Change-Id: I342b625954223966802e65dca0fabf8456c89345 Signed-off-by: Jan Srnicek <jsrnicek@cisco.com>
Diffstat (limited to 'v3po/v3po2vpp/src/test')
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/DisabledInterfacesManagerTest.java3
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/InterfaceTypeTestUtils.java2
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/VhostUserCustomizerTest.java20
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/ip/Ipv4NeighbourCustomizerTest.java8
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/InterfaceCustomizerTest.java24
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/InterfaceDataTranslatorTest.java (renamed from v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/InterfaceUtilsTest.java)22
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/ip/Ipv4AddressCustomizerTest.java121
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/vpp/BridgeDomainCustomizerTest.java46
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/vpp/L2FibEntryCustomizerTest.java12
9 files changed, 105 insertions, 153 deletions
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/DisabledInterfacesManagerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/DisabledInterfacesManagerTest.java
index 7381533e5..52a7a5c2d 100644
--- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/DisabledInterfacesManagerTest.java
+++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/DisabledInterfacesManagerTest.java
@@ -16,6 +16,9 @@
package io.fd.honeycomb.translate.v3po;
+
+
+
import static org.hamcrest.CoreMatchers.hasItems;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/InterfaceTypeTestUtils.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/InterfaceTypeTestUtils.java
index 0dabe1468..9ff5b1b2d 100644
--- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/InterfaceTypeTestUtils.java
+++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/InterfaceTypeTestUtils.java
@@ -19,8 +19,8 @@ package io.fd.honeycomb.translate.v3po.interfaces;
import static org.mockito.Mockito.doReturn;
import com.google.common.base.Optional;
-import io.fd.honeycomb.translate.write.WriteContext;
import io.fd.honeycomb.translate.ModificationCache;
+import io.fd.honeycomb.translate.write.WriteContext;
import org.mockito.Matchers;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfaceType;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceBuilder;
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 0c1d2d72f..a47f5b641 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
@@ -30,8 +30,8 @@ import static org.mockito.Mockito.verifyZeroInteractions;
import static org.mockito.Mockito.when;
import io.fd.honeycomb.translate.v3po.test.ContextTestUtils;
+import io.fd.honeycomb.translate.v3po.util.Ipv4Translator;
import io.fd.honeycomb.translate.v3po.util.NamingContext;
-import io.fd.honeycomb.translate.v3po.util.TranslateUtils;
import io.fd.honeycomb.translate.write.WriteFailedException;
import io.fd.honeycomb.vpp.test.write.WriterCustomizerTest;
import org.junit.Test;
@@ -53,30 +53,30 @@ import org.openvpp.jvpp.core.dto.DeleteVhostUserIfReply;
import org.openvpp.jvpp.core.dto.ModifyVhostUserIf;
import org.openvpp.jvpp.core.dto.ModifyVhostUserIfReply;
-public class VhostUserCustomizerTest extends WriterCustomizerTest {
+public class VhostUserCustomizerTest extends WriterCustomizerTest implements Ipv4Translator {
private VhostUserCustomizer customizer;
private static final int IFACE_ID = 1;
private static final String IFACE_NAME = "eth0";
private static final InstanceIdentifier<VhostUser> ID =
- InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(IFACE_NAME))
- .augmentation(VppInterfaceAugmentation.class).child(VhostUser.class);
+ InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(IFACE_NAME))
+ .augmentation(VppInterfaceAugmentation.class).child(VhostUser.class);
@Override
public void setUp() throws Exception {
InterfaceTypeTestUtils.setupWriteContext(writeContext,
- org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VhostUser.class);
+ org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VhostUser.class);
customizer = new VhostUserCustomizer(api, new NamingContext("generatedInterfaceName", "test-instance"));
}
private CreateVhostUserIf verifyCreateVhostUserIfWasInvoked(final VhostUser vhostUser)
- throws VppInvocationException {
+ throws VppInvocationException {
ArgumentCaptor<CreateVhostUserIf> argumentCaptor = ArgumentCaptor.forClass(CreateVhostUserIf.class);
verify(api).createVhostUserIf(argumentCaptor.capture());
final CreateVhostUserIf actual = argumentCaptor.getValue();
assertEquals(0, actual.customDevInstance);
- assertEquals(TranslateUtils.booleanToByte(VhostUserRole.Server.equals(vhostUser.getRole())), actual.isServer);
+ assertEquals(booleanToByte(VhostUserRole.Server.equals(vhostUser.getRole())), actual.isServer);
assertEquals(0, actual.renumber);
assertEquals(0, actual.useCustomMac);
assertArrayEquals(vhostUser.getSocket().getBytes(), actual.sockFilename);
@@ -85,13 +85,13 @@ public class VhostUserCustomizerTest extends WriterCustomizerTest {
}
private ModifyVhostUserIf verifyModifyVhostUserIfWasInvoked(final VhostUser vhostUser, final int swIfIndex)
- throws VppInvocationException {
+ throws VppInvocationException {
ArgumentCaptor<ModifyVhostUserIf> argumentCaptor = ArgumentCaptor.forClass(ModifyVhostUserIf.class);
verify(api).modifyVhostUserIf(argumentCaptor.capture());
final ModifyVhostUserIf actual = argumentCaptor.getValue();
assertEquals(0, actual.customDevInstance);
- assertEquals(TranslateUtils.booleanToByte(VhostUserRole.Server.equals(vhostUser.getRole())), actual.isServer);
+ assertEquals(booleanToByte(VhostUserRole.Server.equals(vhostUser.getRole())), actual.isServer);
assertEquals(0, actual.renumber);
assertEquals(swIfIndex, actual.swIfIndex);
assertArrayEquals(vhostUser.getSocket().getBytes(), actual.sockFilename);
@@ -122,7 +122,7 @@ public class VhostUserCustomizerTest extends WriterCustomizerTest {
customizer.writeCurrentAttributes(ID, vhostUser, writeContext);
verifyCreateVhostUserIfWasInvoked(vhostUser);
verify(mappingContext).put(eq(ContextTestUtils.getMappingIid(IFACE_NAME, "test-instance")), eq(
- ContextTestUtils.getMapping(IFACE_NAME, 0).get()));
+ ContextTestUtils.getMapping(IFACE_NAME, 0).get()));
}
@Test
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 745276473..416468300 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
@@ -24,8 +24,8 @@ import static org.mockito.Mockito.when;
import com.google.common.io.BaseEncoding;
import io.fd.honeycomb.translate.v3po.test.ContextTestUtils;
+import io.fd.honeycomb.translate.v3po.util.Ipv4Translator;
import io.fd.honeycomb.translate.v3po.util.NamingContext;
-import io.fd.honeycomb.translate.v3po.util.TranslateUtils;
import io.fd.honeycomb.translate.write.WriteFailedException;
import io.fd.honeycomb.vpp.test.write.WriterCustomizerTest;
import org.junit.Before;
@@ -45,7 +45,7 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.openvpp.jvpp.core.dto.IpNeighborAddDel;
import org.openvpp.jvpp.core.dto.IpNeighborAddDelReply;
-public class Ipv4NeighbourCustomizerTest extends WriterCustomizerTest {
+public class Ipv4NeighbourCustomizerTest extends WriterCustomizerTest implements Ipv4Translator {
private static final String IFC_CTX_NAME = "ifc-test-instance";
private static final String IFACE_NAME = "parent";
@@ -85,7 +85,7 @@ public class Ipv4NeighbourCustomizerTest extends WriterCustomizerTest {
assertEquals(0, request.isIpv6);
assertEquals(1, request.isAdd);
assertEquals(1, request.isStatic);
- assertEquals("1.2.168.192", TranslateUtils.arrayToIpv4AddressNoZone(request.dstAddress).getValue());
+ assertEquals("1.2.168.192", arrayToIpv4AddressNoZone(request.dstAddress).getValue());
assertEquals("aabbccee1122", BaseEncoding.base16().lowerCase().encode(request.macAddress));
assertEquals(5, request.swIfIndex);
}
@@ -111,7 +111,7 @@ public class Ipv4NeighbourCustomizerTest extends WriterCustomizerTest {
assertEquals(0, request.isIpv6);
assertEquals(0, request.isAdd);
assertEquals(1, request.isStatic);
- assertEquals("1.2.168.192", TranslateUtils.arrayToIpv4AddressNoZone(request.dstAddress).getValue());
+ assertEquals("1.2.168.192", arrayToIpv4AddressNoZone(request.dstAddress).getValue());
assertEquals("aabbccee1122", BaseEncoding.base16().lowerCase().encode(request.macAddress));
assertEquals(5, request.swIfIndex);
}
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/InterfaceCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/InterfaceCustomizerTest.java
index acc407bd3..5c6f88abd 100644
--- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/InterfaceCustomizerTest.java
+++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/InterfaceCustomizerTest.java
@@ -49,7 +49,7 @@ import org.openvpp.jvpp.core.dto.SwInterfaceDetailsReplyDump;
import org.openvpp.jvpp.core.dto.SwInterfaceDump;
public class InterfaceCustomizerTest extends
- ListReaderCustomizerTest<Interface, InterfaceKey, InterfaceBuilder> {
+ ListReaderCustomizerTest<Interface, InterfaceKey, InterfaceBuilder> implements InterfaceDataTranslator {
private static final String IFC_CTX_NAME = "ifc-test-instance";
private static final String IFACE0_NAME = "eth0";
@@ -96,23 +96,23 @@ public class InterfaceCustomizerTest extends
private void verifySwInterfaceDumpWasInvoked(final int nameFilterValid, final String ifaceName,
final int dumpIfcsInvocationCount)
- throws VppInvocationException {
+ throws VppInvocationException {
final SwInterfaceDump expected = new SwInterfaceDump();
- expected.nameFilterValid = (byte)nameFilterValid;
+ expected.nameFilterValid = (byte) nameFilterValid;
expected.nameFilter = ifaceName.getBytes();
verify(api, times(dumpIfcsInvocationCount)).swInterfaceDump(expected);
}
- private static void assertIfacesAreEqual(final Interface iface, final SwInterfaceDetails details) {
+ private void assertIfacesAreEqual(final Interface iface, final SwInterfaceDetails details) {
assertEquals(iface.getName(), new String(details.interfaceName));
- Assert.assertEquals(InterfaceUtils.yangIfIndexToVpp(iface.getIfIndex().intValue()), details.swIfIndex);
- assertEquals(iface.getPhysAddress().getValue(), InterfaceUtils.vppPhysAddrToYang(details.l2Address));
+ Assert.assertEquals(yangIfIndexToVpp(iface.getIfIndex().intValue()), details.swIfIndex);
+ assertEquals(iface.getPhysAddress().getValue(), vppPhysAddrToYang(details.l2Address));
}
@Test
public void testReadCurrentAttributes() throws Exception {
final InstanceIdentifier<Interface> id = InstanceIdentifier.create(InterfacesState.class)
- .child(Interface.class, new InterfaceKey(IFACE0_NAME));
+ .child(Interface.class, new InterfaceKey(IFACE0_NAME));
final InterfaceBuilder builder = getCustomizer().getBuilder(id);
final SwInterfaceDetails iface = new SwInterfaceDetails();
@@ -134,7 +134,7 @@ public class InterfaceCustomizerTest extends
public void testReadCurrentAttributesFailed() throws Exception {
final String ifaceName = IFACE0_NAME;
final InstanceIdentifier<Interface> id = InstanceIdentifier.create(InterfacesState.class)
- .child(Interface.class, new InterfaceKey(ifaceName));
+ .child(Interface.class, new InterfaceKey(ifaceName));
final InterfaceBuilder builder = getCustomizer().getBuilder(id);
whenSwInterfaceDumpThenReturn(Collections.emptyList());
@@ -152,7 +152,7 @@ public class InterfaceCustomizerTest extends
@Test
public void testReadSubInterface() throws Exception {
final InstanceIdentifier<Interface> id = InstanceIdentifier.create(InterfacesState.class)
- .child(Interface.class, new InterfaceKey(SUB_IFACE_NAME));
+ .child(Interface.class, new InterfaceKey(SUB_IFACE_NAME));
final InterfaceBuilder builder = mock(InterfaceBuilder.class);
final SwInterfaceDetails iface = new SwInterfaceDetails();
@@ -172,7 +172,7 @@ public class InterfaceCustomizerTest extends
@Test
public void testGetAllIds() throws Exception {
final InstanceIdentifier<Interface> id = InstanceIdentifier.create(InterfacesState.class)
- .child(Interface.class);
+ .child(Interface.class);
final SwInterfaceDetails swIf0 = new SwInterfaceDetails();
swIf0.swIfIndex = 0;
@@ -188,7 +188,7 @@ public class InterfaceCustomizerTest extends
whenSwInterfaceDumpThenReturn(Arrays.asList(swIf0, swIf1, swSubIf1));
final List<InterfaceKey> expectedIds = Arrays.asList(new InterfaceKey(IFACE0_NAME), new InterfaceKey(
- IFACE1_NAME));
+ IFACE1_NAME));
final List<InterfaceKey> actualIds = getCustomizer().getAllIds(id, ctx);
verifySwInterfaceDumpWasInvoked(0, "", 1);
@@ -200,7 +200,7 @@ public class InterfaceCustomizerTest extends
@Test
public void testGetAllIdsWithDisabled() throws Exception {
final InstanceIdentifier<Interface> id = InstanceIdentifier.create(InterfacesState.class)
- .child(Interface.class);
+ .child(Interface.class);
doReturn(true).when(interfaceDisableContext).isInterfaceDisabled(1, mappingContext);
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/InterfaceUtilsTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/InterfaceDataTranslatorTest.java
index c74e1ccfb..56567f282 100644
--- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/InterfaceUtilsTest.java
+++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/InterfaceDataTranslatorTest.java
@@ -25,31 +25,31 @@ 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.VxlanGpeTunnel;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VxlanTunnel;
-public class InterfaceUtilsTest {
+public class InterfaceDataTranslatorTest implements InterfaceDataTranslator {
@Test
public void testVppPhysAddrToYang() throws Exception {
- assertEquals("01:02:03:04:05:06", InterfaceUtils.vppPhysAddrToYang(new byte[]{1, 2, 3, 4, 5, 6}));
- assertEquals("0a:0b:0c:0d:0e:0f", InterfaceUtils.vppPhysAddrToYang(new byte[]{0xa, 0xb, 0xc, 0xd, 0xe, 0xf, 0, 0}));
+ assertEquals("01:02:03:04:05:06", vppPhysAddrToYang(new byte[]{1, 2, 3, 4, 5, 6}));
+ assertEquals("0a:0b:0c:0d:0e:0f", vppPhysAddrToYang(new byte[]{0xa, 0xb, 0xc, 0xd, 0xe, 0xf, 0, 0}));
}
@Test(expected = NullPointerException.class)
public void testVppPhysAddrToYangFailNullArgument() throws Exception {
- InterfaceUtils.vppPhysAddrToYang(null);
+ vppPhysAddrToYang(null);
}
@Test(expected = IllegalArgumentException.class)
public void testVppPhysAddrToYangInvalidByteArrayLength() throws Exception {
- InterfaceUtils.vppPhysAddrToYang(new byte[]{1, 2, 3, 4, 5});
+ vppPhysAddrToYang(new byte[]{1, 2, 3, 4, 5});
}
@Test
public void testGetInterfaceType() {
- assertEquals(Tap.class, InterfaceUtils.getInterfaceType("tap0"));
- assertEquals(VxlanTunnel.class, InterfaceUtils.getInterfaceType("vxlan0"));
- assertEquals(VxlanGpeTunnel.class, InterfaceUtils.getInterfaceType("vxlan_gpe0"));
- assertEquals(VhostUser.class, InterfaceUtils.getInterfaceType("VirtualEthernet0/0/0"));
- assertEquals(EthernetCsmacd.class, InterfaceUtils.getInterfaceType("eth0.0"));
- assertEquals(EthernetCsmacd.class, InterfaceUtils.getInterfaceType("local0"));
+ assertEquals(Tap.class, getInterfaceType("tap0"));
+ assertEquals(VxlanTunnel.class, getInterfaceType("vxlan0"));
+ assertEquals(VxlanGpeTunnel.class, getInterfaceType("vxlan_gpe0"));
+ assertEquals(VhostUser.class, getInterfaceType("VirtualEthernet0/0/0"));
+ assertEquals(EthernetCsmacd.class, getInterfaceType("eth0.0"));
+ assertEquals(EthernetCsmacd.class, getInterfaceType("local0"));
}
} \ No newline at end of file
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/ip/Ipv4AddressCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/ip/Ipv4AddressCustomizerTest.java
index be0ef14df..d351d2402 100644
--- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/ip/Ipv4AddressCustomizerTest.java
+++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/ip/Ipv4AddressCustomizerTest.java
@@ -16,12 +16,11 @@
package io.fd.honeycomb.translate.v3po.interfacesstate.ip;
-import static io.fd.honeycomb.translate.v3po.util.TranslateUtils.reverseBytes;
-import static org.hamcrest.CoreMatchers.is;
+
+import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import com.google.common.collect.ImmutableList;
@@ -29,13 +28,14 @@ import io.fd.honeycomb.translate.ModificationCache;
import io.fd.honeycomb.translate.read.ReadFailedException;
import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
import io.fd.honeycomb.translate.v3po.test.ContextTestUtils;
+import io.fd.honeycomb.translate.v3po.util.Ipv4Translator;
import io.fd.honeycomb.translate.v3po.util.NamingContext;
-import io.fd.honeycomb.translate.v3po.util.TranslateUtils;
import io.fd.honeycomb.vpp.test.read.ListReaderCustomizerTest;
import java.util.Arrays;
import java.util.List;
+import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;
-import org.hamcrest.CoreMatchers;
+import org.hamcrest.Matchers;
import org.junit.Test;
import org.mockito.Mockito;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
@@ -54,13 +54,15 @@ import org.openvpp.jvpp.core.dto.IpAddressDetails;
import org.openvpp.jvpp.core.dto.IpAddressDetailsReplyDump;
import org.openvpp.jvpp.core.dto.IpAddressDump;
-public class Ipv4AddressCustomizerTest extends ListReaderCustomizerTest<Address, AddressKey, AddressBuilder> {
+public class Ipv4AddressCustomizerTest extends ListReaderCustomizerTest<Address, AddressKey, AddressBuilder> implements
+ Ipv4Translator {
private static final String IFACE_NAME = "eth0";
private static final String IFACE_2_NAME = "eth1";
private static final int IFACE_ID = 1;
private static final int IFACE_2_ID = 2;
private static final String IFC_CTX_NAME = "ifc-test-instance";
+ public static final String CACHE_KEY = Ipv4AddressCustomizer.class.getName();
private NamingContext interfacesContext;
@@ -90,63 +92,44 @@ public class Ipv4AddressCustomizerTest extends ListReaderCustomizerTest<Address,
}
@Test
- public void testReadCurrentAttributesFromCache() throws ReadFailedException {
- ModificationCache cache = new ModificationCache();
-
- IpAddressDetails detail1 = new IpAddressDetails();
- IpAddressDetails detail2 = new IpAddressDetails();
- IpAddressDetails detail3 = new IpAddressDetails();
-
- detail1.ip = reverseBytes(
- TranslateUtils.ipv4AddressNoZoneToArray(new Ipv4AddressNoZone(new Ipv4Address("192.168.2.1"))));
- detail2.ip = reverseBytes(
- TranslateUtils.ipv4AddressNoZoneToArray(new Ipv4AddressNoZone(new Ipv4Address("192.168.2.2"))));
- detail3.ip = reverseBytes(
- TranslateUtils.ipv4AddressNoZoneToArray(new Ipv4AddressNoZone(new Ipv4Address("192.168.2.3"))));
-
- IpAddressDetailsReplyDump reply = new IpAddressDetailsReplyDump();
- reply.ipAddressDetails = ImmutableList.of(detail1, detail2, detail3);
-
- cache.put(Ipv4ReadUtils.CACHE_KEY + IFACE_NAME, reply);
- when(ctx.getModificationCache()).thenReturn(cache);
-
- final AddressBuilder builder = new AddressBuilder();
- final InstanceIdentifier<Address> id = getId("192.168.2.1", IFACE_NAME);
-
- getCustomizer().readCurrentAttributes(id, builder, ctx);
-
- assertEquals("192.168.2.1", builder.getIp().getValue());
- }
-
- @Test
public void testReadCurrentAttributesFor2Ifcs() throws ReadFailedException {
- ModificationCache cache = new ModificationCache();
+ //changed to mock to not store first dumped data(otherwise that double thenReturn on line 118 is not gonna work)
+ ModificationCache cache = mock(ModificationCache.class);
IpAddressDetails detail1 = new IpAddressDetails();
IpAddressDetails detail2 = new IpAddressDetails();
detail1.ip = reverseBytes(
- TranslateUtils.ipv4AddressNoZoneToArray(new Ipv4AddressNoZone(new Ipv4Address("192.168.2.1"))));
+ ipv4AddressNoZoneToArray(new Ipv4AddressNoZone(new Ipv4Address("192.168.2.1"))));
detail2.ip = reverseBytes(
- TranslateUtils.ipv4AddressNoZoneToArray(new Ipv4AddressNoZone(new Ipv4Address("192.168.2.2"))));
+ ipv4AddressNoZoneToArray(new Ipv4AddressNoZone(new Ipv4Address("192.168.2.2"))));
IpAddressDetailsReplyDump reply = new IpAddressDetailsReplyDump();
reply.ipAddressDetails = ImmutableList.of(detail1);
IpAddressDetailsReplyDump reply2 = new IpAddressDetailsReplyDump();
reply2.ipAddressDetails = ImmutableList.of(detail2);
- when(api.ipAddressDump(Mockito.any(IpAddressDump.class))).thenReturn(future(reply)).thenReturn(future(reply2));
+ CompletableFuture<IpAddressDetailsReplyDump> future = new CompletableFuture<>();
+ future.complete(reply);
+ CompletableFuture<IpAddressDetailsReplyDump> future2 = new CompletableFuture<>();
+ future2.complete(reply2);
+
+ when(api.ipAddressDump(Mockito.any(IpAddressDump.class))).thenReturn(future).thenReturn(future2)
+ .thenReturn(future).thenReturn(future2);
+ when(api.ipAddressDump(Mockito.any(IpAddressDump.class))).thenReturn(future(reply)).thenReturn(future(reply2))
+ .thenReturn(future(reply)).thenReturn(future(reply2));
when(ctx.getModificationCache()).thenReturn(cache);
+
final InstanceIdentifier<Address> id = getId("192.168.2.1", IFACE_NAME);
final InstanceIdentifier<Address> id2 = getId("192.168.2.2", IFACE_2_NAME);
final List<AddressKey> ifc1Ids = getCustomizer().getAllIds(id, ctx);
assertThat(ifc1Ids.size(), is(1));
- assertThat(ifc1Ids, CoreMatchers.hasItem(new AddressKey(new Ipv4AddressNoZone("192.168.2.1"))));
+ assertThat(ifc1Ids, Matchers.hasItem(new AddressKey(new Ipv4AddressNoZone("192.168.2.1"))));
final List<AddressKey> ifc2Ids = getCustomizer().getAllIds(id2, ctx);
assertThat(ifc2Ids.size(), is(1));
- assertThat(ifc2Ids, CoreMatchers.hasItem(new AddressKey(new Ipv4AddressNoZone("192.168.2.2"))));
+ assertThat(ifc2Ids, Matchers.hasItem(new AddressKey(new Ipv4AddressNoZone("192.168.2.2"))));
AddressBuilder builder = new AddressBuilder();
getCustomizer().readCurrentAttributes(id, builder, ctx);
@@ -157,7 +140,7 @@ public class Ipv4AddressCustomizerTest extends ListReaderCustomizerTest<Address,
}
@Test
- public void testReadCurrentAttributesFromOperationalData() throws ReadFailedException {
+ public void testReadCurrentAttributesSuccessfull() throws ReadFailedException {
ModificationCache cache = new ModificationCache();
IpAddressDetails detail1 = new IpAddressDetails();
@@ -165,11 +148,11 @@ public class Ipv4AddressCustomizerTest extends ListReaderCustomizerTest<Address,
IpAddressDetails detail3 = new IpAddressDetails();
detail1.ip = reverseBytes(
- TranslateUtils.ipv4AddressNoZoneToArray(new Ipv4AddressNoZone(new Ipv4Address("192.168.2.1"))));
+ ipv4AddressNoZoneToArray(new Ipv4AddressNoZone(new Ipv4Address("192.168.2.1"))));
detail2.ip = reverseBytes(
- TranslateUtils.ipv4AddressNoZoneToArray(new Ipv4AddressNoZone(new Ipv4Address("192.168.2.2"))));
+ ipv4AddressNoZoneToArray(new Ipv4AddressNoZone(new Ipv4Address("192.168.2.2"))));
detail3.ip = reverseBytes(
- TranslateUtils.ipv4AddressNoZoneToArray(new Ipv4AddressNoZone(new Ipv4Address("192.168.2.3"))));
+ ipv4AddressNoZoneToArray(new Ipv4AddressNoZone(new Ipv4Address("192.168.2.3"))));
IpAddressDetailsReplyDump reply = new IpAddressDetailsReplyDump();
reply.ipAddressDetails = ImmutableList.of(detail1, detail2, detail3);
@@ -185,41 +168,7 @@ public class Ipv4AddressCustomizerTest extends ListReaderCustomizerTest<Address,
}
@Test
- public void testGetAllIdsFromCache() throws ReadFailedException {
- ModificationCache cache = new ModificationCache();
-
- IpAddressDetails detail1 = new IpAddressDetails();
- IpAddressDetails detail2 = new IpAddressDetails();
- IpAddressDetails detail3 = new IpAddressDetails();
-
- detail1.ip = reverseBytes(
- TranslateUtils.ipv4AddressNoZoneToArray(new Ipv4AddressNoZone(new Ipv4Address("192.168.2.1"))));
- detail2.ip = reverseBytes(
- TranslateUtils.ipv4AddressNoZoneToArray(new Ipv4AddressNoZone(new Ipv4Address("192.168.2.2"))));
- detail3.ip = reverseBytes(
- TranslateUtils.ipv4AddressNoZoneToArray(new Ipv4AddressNoZone(new Ipv4Address("192.168.2.3"))));
-
- IpAddressDetailsReplyDump reply = new IpAddressDetailsReplyDump();
- reply.ipAddressDetails = ImmutableList.of(detail1, detail2, detail3);
-
- cache.put(Ipv4ReadUtils.CACHE_KEY + IFACE_NAME, reply);
- when(ctx.getModificationCache()).thenReturn(cache);
-
- final InstanceIdentifier<Address> id = getId("192.168.2.1", IFACE_NAME);
-
- List<Ipv4AddressNoZone> ids = getCustomizer().getAllIds(id, ctx).stream()
- .map(key -> key.getIp())
- .collect(Collectors.toList());
-
- verify(api, times(0)).ipAddressDump(Mockito.any(IpAddressDump.class));
- assertEquals(3, ids.size());
- assertEquals(true, "192.168.2.1".equals(ids.get(0).getValue()));
- assertEquals(true, "192.168.2.2".equals(ids.get(1).getValue()));
- assertEquals(true, "192.168.2.3".equals(ids.get(2).getValue()));
- }
-
- @Test
- public void testGetAllIdsFromOperationalData() throws ReadFailedException {
+ public void testGetAllIdsFromSuccessfull() throws ReadFailedException {
ModificationCache cache = new ModificationCache();
IpAddressDetails detail1 = new IpAddressDetails();
@@ -227,11 +176,11 @@ public class Ipv4AddressCustomizerTest extends ListReaderCustomizerTest<Address,
IpAddressDetails detail3 = new IpAddressDetails();
detail1.ip = reverseBytes(
- TranslateUtils.ipv4AddressNoZoneToArray(new Ipv4AddressNoZone(new Ipv4Address("192.168.2.1"))));
+ ipv4AddressNoZoneToArray(new Ipv4AddressNoZone(new Ipv4Address("192.168.2.1"))));
detail2.ip = reverseBytes(
- TranslateUtils.ipv4AddressNoZoneToArray(new Ipv4AddressNoZone(new Ipv4Address("192.168.2.2"))));
+ ipv4AddressNoZoneToArray(new Ipv4AddressNoZone(new Ipv4Address("192.168.2.2"))));
detail3.ip = reverseBytes(
- TranslateUtils.ipv4AddressNoZoneToArray(new Ipv4AddressNoZone(new Ipv4Address("192.168.2.3"))));
+ ipv4AddressNoZoneToArray(new Ipv4AddressNoZone(new Ipv4Address("192.168.2.3"))));
IpAddressDetailsReplyDump reply = new IpAddressDetailsReplyDump();
reply.ipAddressDetails = ImmutableList.of(detail1, detail2, detail3);
@@ -241,8 +190,8 @@ public class Ipv4AddressCustomizerTest extends ListReaderCustomizerTest<Address,
final InstanceIdentifier<Address> id = getId("192.168.2.1", IFACE_NAME);
List<Ipv4AddressNoZone> ids = getCustomizer().getAllIds(id, ctx).stream()
- .map(key -> key.getIp())
- .collect(Collectors.toList());
+ .map(key -> key.getIp())
+ .collect(Collectors.toList());
assertEquals(3, ids.size());
assertEquals(true, "192.168.2.1".equals(ids.get(0).getValue()));
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/vpp/BridgeDomainCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/vpp/BridgeDomainCustomizerTest.java
index 6029f3faf..f41448bf0 100644
--- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/vpp/BridgeDomainCustomizerTest.java
+++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/vpp/BridgeDomainCustomizerTest.java
@@ -16,7 +16,6 @@
package io.fd.honeycomb.translate.v3po.vpp;
-import static io.fd.honeycomb.translate.v3po.util.TranslateUtils.booleanToByte;
import static org.junit.Assert.fail;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.doReturn;
@@ -25,6 +24,7 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import io.fd.honeycomb.translate.v3po.test.ContextTestUtils;
+import io.fd.honeycomb.translate.v3po.util.ByteDataTranslator;
import io.fd.honeycomb.translate.v3po.util.NamingContext;
import io.fd.honeycomb.translate.write.WriteFailedException;
import io.fd.honeycomb.vpp.test.write.WriterCustomizerTest;
@@ -40,7 +40,7 @@ import org.openvpp.jvpp.VppInvocationException;
import org.openvpp.jvpp.core.dto.BridgeDomainAddDel;
import org.openvpp.jvpp.core.dto.BridgeDomainAddDelReply;
-public class BridgeDomainCustomizerTest extends WriterCustomizerTest {
+public class BridgeDomainCustomizerTest extends WriterCustomizerTest implements ByteDataTranslator {
private static final String BD_CTX_NAME = "bd-test-instance";
private static final byte ADD_OR_UPDATE_BD = (byte) 1;
@@ -53,7 +53,7 @@ public class BridgeDomainCustomizerTest extends WriterCustomizerTest {
@Nullable
private static Boolean intToBoolean(final int value) {
- if (value == 0) {
+ if (value == 0) {
return Boolean.FALSE;
}
if (value == 1) {
@@ -63,7 +63,7 @@ public class BridgeDomainCustomizerTest extends WriterCustomizerTest {
}
private static KeyedInstanceIdentifier<BridgeDomain, BridgeDomainKey> bdIdentifierForName(
- final String bdName) {
+ final String bdName) {
return InstanceIdentifier.create(BridgeDomains.class).child(BridgeDomain.class, new BridgeDomainKey(bdName));
}
@@ -79,17 +79,17 @@ public class BridgeDomainCustomizerTest extends WriterCustomizerTest {
private BridgeDomain generateBridgeDomain(final String bdName, final int arpTerm, final int flood,
final int forward, final int learn, final int uuf) {
return new BridgeDomainBuilder()
- .setName(bdName)
- .setArpTermination(intToBoolean(arpTerm))
- .setFlood(intToBoolean(flood))
- .setForward(intToBoolean(forward))
- .setLearn(intToBoolean(learn))
- .setUnknownUnicastFlood(intToBoolean(uuf))
- .build();
+ .setName(bdName)
+ .setArpTermination(intToBoolean(arpTerm))
+ .setFlood(intToBoolean(flood))
+ .setForward(intToBoolean(forward))
+ .setLearn(intToBoolean(learn))
+ .setUnknownUnicastFlood(intToBoolean(uuf))
+ .build();
}
private void verifyBridgeDomainAddOrUpdateWasInvoked(final BridgeDomain bd, final int bdId)
- throws VppInvocationException {
+ throws VppInvocationException {
final BridgeDomainAddDel expected = new BridgeDomainAddDel();
expected.arpTerm = booleanToByte(bd.isArpTermination());
expected.flood = booleanToByte(bd.isFlood());
@@ -128,7 +128,7 @@ public class BridgeDomainCustomizerTest extends WriterCustomizerTest {
verifyBridgeDomainAddOrUpdateWasInvoked(bd, bdId);
verify(mappingContext).put(
- ContextTestUtils.getMappingIid(bdName, BD_CTX_NAME), ContextTestUtils.getMapping(bdName, bdId).get());
+ ContextTestUtils.getMappingIid(bdName, BD_CTX_NAME), ContextTestUtils.getMapping(bdName, bdId).get());
}
@Test
@@ -144,7 +144,7 @@ public class BridgeDomainCustomizerTest extends WriterCustomizerTest {
verifyBridgeDomainAddOrUpdateWasInvoked(bd, bdId);
verify(mappingContext).put(
- ContextTestUtils.getMappingIid(bdName, BD_CTX_NAME), ContextTestUtils.getMapping(bdName, bdId).get());
+ ContextTestUtils.getMappingIid(bdName, BD_CTX_NAME), ContextTestUtils.getMapping(bdName, bdId).get());
}
@Test
@@ -226,16 +226,16 @@ public class BridgeDomainCustomizerTest extends WriterCustomizerTest {
final byte uufBefore = 0;
final BridgeDomain dataBefore =
- generateBridgeDomain(bdName, arpTermBefore, floodBefore, forwardBefore, learnBefore, uufBefore);
+ generateBridgeDomain(bdName, arpTermBefore, floodBefore, forwardBefore, learnBefore, uufBefore);
final BridgeDomain dataAfter =
- generateBridgeDomain(bdName, arpTermBefore ^ 1, floodBefore ^ 1, forwardBefore ^ 1, learnBefore ^ 1,
- uufBefore ^ 1);
+ generateBridgeDomain(bdName, arpTermBefore ^ 1, floodBefore ^ 1, forwardBefore ^ 1, learnBefore ^ 1,
+ uufBefore ^ 1);
whenBridgeDomainAddDelThenSuccess();
customizer
- .updateCurrentAttributes(bdIdentifierForName(bdName), dataBefore, dataAfter,
- writeContext);
+ .updateCurrentAttributes(bdIdentifierForName(bdName), dataBefore, dataAfter,
+ writeContext);
verifyBridgeDomainAddOrUpdateWasInvoked(dataAfter, bdId);
}
@@ -248,8 +248,8 @@ public class BridgeDomainCustomizerTest extends WriterCustomizerTest {
try {
customizer
- .updateCurrentAttributes(bdIdentifierForName(bdName), bdBefore, bdAfter,
- writeContext);
+ .updateCurrentAttributes(bdIdentifierForName(bdName), bdBefore, bdAfter,
+ writeContext);
} catch (IllegalArgumentException e) {
verify(api, never()).bridgeDomainAddDel(any(BridgeDomainAddDel.class));
return;
@@ -269,8 +269,8 @@ public class BridgeDomainCustomizerTest extends WriterCustomizerTest {
try {
customizer
- .updateCurrentAttributes(bdIdentifierForName(bdName), bdBefore, bdAfter,
- writeContext);
+ .updateCurrentAttributes(bdIdentifierForName(bdName), bdBefore, bdAfter,
+ writeContext);
} catch (WriteFailedException.UpdateFailedException e) {
verifyBridgeDomainAddOrUpdateWasInvoked(bdAfter, bdId);
return;
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/vpp/L2FibEntryCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/vpp/L2FibEntryCustomizerTest.java
index 728ba9306..174e27215 100644
--- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/vpp/L2FibEntryCustomizerTest.java
+++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/vpp/L2FibEntryCustomizerTest.java
@@ -62,14 +62,14 @@ public class L2FibEntryCustomizerTest extends WriterCustomizerTest {
ContextTestUtils.mockMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME);
customizer = new L2FibEntryCustomizer(
- api,
- new NamingContext("generatedBdName", BD_CTX_NAME),
- new NamingContext("generatedIfaceName", IFC_CTX_NAME));
+ api,
+ new NamingContext("generatedBdName", BD_CTX_NAME),
+ new NamingContext("generatedIfaceName", IFC_CTX_NAME));
}
private static InstanceIdentifier<L2FibEntry> getL2FibEntryId(final PhysAddress address) {
return InstanceIdentifier.create(BridgeDomains.class).child(BridgeDomain.class, new BridgeDomainKey(BD_NAME))
- .child(L2FibTable.class).child(L2FibEntry.class, new L2FibEntryKey(address));
+ .child(L2FibTable.class).child(L2FibEntry.class, new L2FibEntryKey(address));
}
private void whenL2FibAddDelThenSuccess() {
@@ -105,7 +105,7 @@ public class L2FibEntryCustomizerTest extends WriterCustomizerTest {
}
private void verifyL2FibAddDelWasInvoked(final L2FibAddDel expected) throws
- VppInvocationException {
+ VppInvocationException {
ArgumentCaptor<L2FibAddDel> argumentCaptor = ArgumentCaptor.forClass(L2FibAddDel.class);
verify(api).l2FibAddDel(argumentCaptor.capture());
final L2FibAddDel actual = argumentCaptor.getValue();
@@ -153,7 +153,7 @@ public class L2FibEntryCustomizerTest extends WriterCustomizerTest {
@Test(expected = UnsupportedOperationException.class)
public void testUpdate() throws Exception {
customizer.updateCurrentAttributes(InstanceIdentifier.create(L2FibEntry.class), mock(L2FibEntry.class),
- mock(L2FibEntry.class), writeContext);
+ mock(L2FibEntry.class), writeContext);
}
@Test