summaryrefslogtreecommitdiffstats
path: root/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfacesstate/ip/Ipv4AddressCustomizerTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfacesstate/ip/Ipv4AddressCustomizerTest.java')
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfacesstate/ip/Ipv4AddressCustomizerTest.java176
1 files changed, 110 insertions, 66 deletions
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfacesstate/ip/Ipv4AddressCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfacesstate/ip/Ipv4AddressCustomizerTest.java
index 8008ba5bd..85f528e1e 100644
--- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfacesstate/ip/Ipv4AddressCustomizerTest.java
+++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfacesstate/ip/Ipv4AddressCustomizerTest.java
@@ -16,17 +16,23 @@
package io.fd.honeycomb.v3po.translate.v3po.interfacesstate.ip;
+import static io.fd.honeycomb.v3po.translate.v3po.test.ContextTestUtils.getMapping;
+import static io.fd.honeycomb.v3po.translate.v3po.test.ContextTestUtils.getMappingIid;
+import static io.fd.honeycomb.v3po.translate.v3po.util.TranslateUtils.reverseBytes;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+import com.google.common.base.Optional;
import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Lists;
import io.fd.honeycomb.v3po.translate.ModificationCache;
-import io.fd.honeycomb.v3po.translate.read.ReadContext;
import io.fd.honeycomb.v3po.translate.read.ReadFailedException;
+import io.fd.honeycomb.v3po.translate.spi.read.RootReaderCustomizer;
+import io.fd.honeycomb.v3po.translate.v3po.test.ListReaderCustomizerTest;
+import io.fd.honeycomb.v3po.translate.v3po.util.NamingContext;
import io.fd.honeycomb.v3po.translate.v3po.util.TranslateUtils;
import java.util.Arrays;
import java.util.List;
@@ -34,10 +40,15 @@ import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;
import org.junit.Test;
import org.mockito.Mockito;
+import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.contexts.naming.context.Mappings;
+import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.contexts.naming.context.MappingsBuilder;
+import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.contexts.naming.context.mappings.Mapping;
+import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.contexts.naming.context.mappings.MappingKey;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfacesState;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.InterfaceKey;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.Interface2;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.Ipv4;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.Ipv4Builder;
@@ -45,64 +56,93 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev14061
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.ipv4.AddressBuilder;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.ipv4.AddressKey;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
import org.openvpp.jvpp.dto.IpAddressDetails;
import org.openvpp.jvpp.dto.IpAddressDetailsReplyDump;
import org.openvpp.jvpp.dto.IpAddressDump;
-import org.openvpp.jvpp.future.FutureJVpp;
-public class Ipv4AddressCustomizerTest {
+public class Ipv4AddressCustomizerTest extends ListReaderCustomizerTest<Address, AddressKey, AddressBuilder> {
- @Test
- public void testGetBuilder() {
- assertNotNull(new Ipv4AddressCustomizer(mock(FutureJVpp.class)).getBuilder(null));
+ private static final String IFACE_NAME = "eth0";
+ private static final int IFACE_ID = 1;
+
+ private NamingContext interfacesContext;
+
+ public Ipv4AddressCustomizerTest() {
+ super(Address.class);
+ }
+
+ @Override
+ public void setUpBefore() {
+ interfacesContext = new NamingContext("generatedIfaceName", "test-instance");
+ }
+
+ @Override
+ protected RootReaderCustomizer<Address, AddressBuilder> initCustomizer() {
+ final KeyedInstanceIdentifier<Mapping, MappingKey> eth0Id = getMappingIid(IFACE_NAME, "test-instance");
+ final Optional<Mapping> eth0 = getMapping(IFACE_NAME, IFACE_ID);
+
+ final List<Mapping> allMappings = Lists.newArrayList(getMapping(IFACE_NAME, IFACE_ID).get());
+ final Mappings allMappingsBaObject = new MappingsBuilder().setMapping(allMappings).build();
+ doReturn(Optional.of(allMappingsBaObject)).when(mappingContext).read(eth0Id.firstIdentifierOf(Mappings.class));
+
+ doReturn(eth0).when(mappingContext).read(eth0Id);
+
+ return new Ipv4AddressCustomizer(api, interfacesContext);
+ }
+
+ private static InstanceIdentifier<Address> getId(final String address) {
+ return InstanceIdentifier.builder(InterfacesState.class)
+ .child(Interface.class, new InterfaceKey(IFACE_NAME))
+ .augmentation(Interface2.class)
+ .child(Ipv4.class)
+ .child(Address.class, new AddressKey(new Ipv4AddressNoZone(new Ipv4Address(address))))
+ .build();
}
@Test
public void testReadCurrentAttributesFromCache() throws ReadFailedException {
- ReadContext context = mock(ReadContext.class);
ModificationCache cache = new ModificationCache();
- FutureJVpp jvpp = mock(FutureJVpp.class);
IpAddressDetails detail1 = new IpAddressDetails();
IpAddressDetails detail2 = new IpAddressDetails();
IpAddressDetails detail3 = new IpAddressDetails();
- detail1.ip = TranslateUtils.ipv4AddressNoZoneToArray(new Ipv4AddressNoZone(new Ipv4Address("192.168.2.1")));
- detail2.ip = TranslateUtils.ipv4AddressNoZoneToArray(new Ipv4AddressNoZone(new Ipv4Address("192.168.2.2")));
- detail3.ip = TranslateUtils.ipv4AddressNoZoneToArray(new Ipv4AddressNoZone(new Ipv4Address("192.168.2.3")));
+ 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(Ipv4AddressCustomizer.class.getName(), reply);
- when(context.getModificationCache()).thenReturn(cache);
+ when(ctx.getModificationCache()).thenReturn(cache);
- AddressBuilder builder = new AddressBuilder();
- InstanceIdentifier<Address> id = InstanceIdentifier.builder(InterfacesState.class)
- .child(Interface.class)
- .augmentation(Interface2.class)
- .child(Ipv4.class)
- .child(Address.class, new AddressKey(new Ipv4AddressNoZone(new Ipv4Address("192.168.2.1"))))
- .build();
+ final AddressBuilder builder = new AddressBuilder();
+ final InstanceIdentifier<Address> id = getId("192.168.2.1");
- new Ipv4AddressCustomizer(jvpp).readCurrentAttributes(id, builder, context);
+ getCustomizer().readCurrentAttributes(id, builder, ctx);
- assertEquals("1.2.168.192", builder.getIp().getValue());
+ assertEquals("192.168.2.1", builder.getIp().getValue());
}
@Test
public void testReadCurrentAttributesFromOperationalData() throws ReadFailedException {
- ReadContext context = mock(ReadContext.class);
ModificationCache cache = new ModificationCache();
- FutureJVpp jvpp = mock(FutureJVpp.class);
IpAddressDetails detail1 = new IpAddressDetails();
IpAddressDetails detail2 = new IpAddressDetails();
IpAddressDetails detail3 = new IpAddressDetails();
- detail1.ip = TranslateUtils.ipv4AddressNoZoneToArray(new Ipv4AddressNoZone(new Ipv4Address("192.168.2.1")));
- detail2.ip = TranslateUtils.ipv4AddressNoZoneToArray(new Ipv4AddressNoZone(new Ipv4Address("192.168.2.2")));
- detail3.ip = TranslateUtils.ipv4AddressNoZoneToArray(new Ipv4AddressNoZone(new Ipv4Address("192.168.2.3")));
+ 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);
@@ -110,65 +150,66 @@ public class Ipv4AddressCustomizerTest {
CompletableFuture<IpAddressDetailsReplyDump> future = new CompletableFuture<>();
future.complete(reply);
- when(jvpp.ipAddressDump(Mockito.any(IpAddressDump.class))).thenReturn(future);
- when(context.getModificationCache()).thenReturn(cache);
+ when(api.ipAddressDump(Mockito.any(IpAddressDump.class))).thenReturn(future);
+ when(ctx.getModificationCache()).thenReturn(cache);
+
- AddressBuilder builder = new AddressBuilder();
- InstanceIdentifier<Address> id = InstanceIdentifier.builder(InterfacesState.class)
- .child(Interface.class)
- .augmentation(Interface2.class)
- .child(Ipv4.class)
- .child(Address.class, new AddressKey(new Ipv4AddressNoZone(new Ipv4Address("192.168.2.1"))))
- .build();
+ final AddressBuilder builder = new AddressBuilder();
+ final InstanceIdentifier<Address> id = getId("192.168.2.1");
- new Ipv4AddressCustomizer(jvpp).readCurrentAttributes(id, builder, context);
+ getCustomizer().readCurrentAttributes(id, builder, ctx);
- assertEquals("1.2.168.192", builder.getIp().getValue());
+ assertEquals("192.168.2.1", builder.getIp().getValue());
}
@Test
public void testGetAllIdsFromCache() throws ReadFailedException {
- ReadContext context = mock(ReadContext.class);
ModificationCache cache = new ModificationCache();
- FutureJVpp jvpp = mock(FutureJVpp.class);
IpAddressDetails detail1 = new IpAddressDetails();
IpAddressDetails detail2 = new IpAddressDetails();
IpAddressDetails detail3 = new IpAddressDetails();
- detail1.ip = TranslateUtils.ipv4AddressNoZoneToArray(new Ipv4AddressNoZone(new Ipv4Address("192.168.2.1")));
- detail2.ip = TranslateUtils.ipv4AddressNoZoneToArray(new Ipv4AddressNoZone(new Ipv4Address("192.168.2.2")));
- detail3.ip = TranslateUtils.ipv4AddressNoZoneToArray(new Ipv4AddressNoZone(new Ipv4Address("192.168.2.3")));
+ 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(Ipv4AddressCustomizer.class.getName(), reply);
- when(context.getModificationCache()).thenReturn(cache);
- List<Ipv4AddressNoZone> ids = new Ipv4AddressCustomizer(jvpp).getAllIds(null, context).stream()
- .map(id -> id.getIp())
- .collect(Collectors.toList());
+ when(ctx.getModificationCache()).thenReturn(cache);
- verify(jvpp, times(0)).ipAddressDump(Mockito.any(IpAddressDump.class));
+ final InstanceIdentifier<Address> id = getId("192.168.2.1");
+
+ 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, "1.2.168.192".equals(ids.get(0).getValue()));
- assertEquals(true, "2.2.168.192".equals(ids.get(1).getValue()));
- assertEquals(true, "3.2.168.192".equals(ids.get(2).getValue()));
+ 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 {
- ReadContext context = mock(ReadContext.class);
ModificationCache cache = new ModificationCache();
- FutureJVpp jvpp = mock(FutureJVpp.class);
IpAddressDetails detail1 = new IpAddressDetails();
IpAddressDetails detail2 = new IpAddressDetails();
IpAddressDetails detail3 = new IpAddressDetails();
- detail1.ip = TranslateUtils.ipv4AddressNoZoneToArray(new Ipv4AddressNoZone(new Ipv4Address("192.168.2.1")));
- detail2.ip = TranslateUtils.ipv4AddressNoZoneToArray(new Ipv4AddressNoZone(new Ipv4Address("192.168.2.2")));
- detail3.ip = TranslateUtils.ipv4AddressNoZoneToArray(new Ipv4AddressNoZone(new Ipv4Address("192.168.2.3")));
+ 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);
@@ -176,16 +217,19 @@ public class Ipv4AddressCustomizerTest {
CompletableFuture<IpAddressDetailsReplyDump> future = new CompletableFuture<>();
future.complete(reply);
- when(jvpp.ipAddressDump(Mockito.any(IpAddressDump.class))).thenReturn(future);
- when(context.getModificationCache()).thenReturn(cache);
- List<Ipv4AddressNoZone> ids = new Ipv4AddressCustomizer(jvpp).getAllIds(null, context).stream()
- .map(id -> id.getIp())
- .collect(Collectors.toList());
+ when(api.ipAddressDump(Mockito.any(IpAddressDump.class))).thenReturn(future);
+ when(ctx.getModificationCache()).thenReturn(cache);
+
+ final InstanceIdentifier<Address> id = getId("192.168.2.1");
+
+ List<Ipv4AddressNoZone> ids = getCustomizer().getAllIds(id, ctx).stream()
+ .map(key -> key.getIp())
+ .collect(Collectors.toList());
assertEquals(3, ids.size());
- assertEquals(true, "1.2.168.192".equals(ids.get(0).getValue()));
- assertEquals(true, "2.2.168.192".equals(ids.get(1).getValue()));
- assertEquals(true, "3.2.168.192".equals(ids.get(2).getValue()));
+ 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
@@ -193,7 +237,7 @@ public class Ipv4AddressCustomizerTest {
Address address = new AddressBuilder().build();
Ipv4Builder ipv4Builder = new Ipv4Builder();
- new Ipv4AddressCustomizer(mock(FutureJVpp.class)).merge(ipv4Builder, Arrays.asList(address));
+ getCustomizer().merge(ipv4Builder, Arrays.asList(address));
assertEquals(1, ipv4Builder.getAddress().size());
assertEquals(true, ipv4Builder.getAddress().contains(address));