summaryrefslogtreecommitdiffstats
path: root/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/ip/Ipv4AddressCustomizerTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/ip/Ipv4AddressCustomizerTest.java')
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/ip/Ipv4AddressCustomizerTest.java121
1 files changed, 35 insertions, 86 deletions
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()));