summaryrefslogtreecommitdiffstats
path: root/v3po/v3po2vpp/src/test/java
diff options
context:
space:
mode:
Diffstat (limited to 'v3po/v3po2vpp/src/test/java')
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfacesstate/ip/Ipv4AddressCustomizerTest.java77
1 files changed, 64 insertions, 13 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 85f528e1e..584464645 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
@@ -19,7 +19,9 @@ 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.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
@@ -38,6 +40,7 @@ import java.util.Arrays;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;
+import org.hamcrest.CoreMatchers;
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;
@@ -64,7 +67,9 @@ import org.openvpp.jvpp.dto.IpAddressDump;
public class Ipv4AddressCustomizerTest extends ListReaderCustomizerTest<Address, AddressKey, AddressBuilder> {
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 NamingContext interfacesContext;
@@ -80,24 +85,27 @@ public class Ipv4AddressCustomizerTest extends ListReaderCustomizerTest<Address,
@Override
protected RootReaderCustomizer<Address, AddressBuilder> initCustomizer() {
final KeyedInstanceIdentifier<Mapping, MappingKey> eth0Id = getMappingIid(IFACE_NAME, "test-instance");
+ final KeyedInstanceIdentifier<Mapping, MappingKey> eth1Id = getMappingIid(IFACE_2_NAME, "test-instance");
final Optional<Mapping> eth0 = getMapping(IFACE_NAME, IFACE_ID);
+ final Optional<Mapping> eth1 = getMapping(IFACE_2_NAME, IFACE_2_ID);
- final List<Mapping> allMappings = Lists.newArrayList(getMapping(IFACE_NAME, IFACE_ID).get());
+ final List<Mapping> allMappings = Lists.newArrayList(eth0.get(), eth1.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);
+ doReturn(eth1).when(mappingContext).read(eth1Id);
return new Ipv4AddressCustomizer(api, interfacesContext);
}
- private static InstanceIdentifier<Address> getId(final String address) {
+ private static InstanceIdentifier<Address> getId(final String address, final String ifaceName) {
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();
+ .child(Interface.class, new InterfaceKey(ifaceName))
+ .augmentation(Interface2.class)
+ .child(Ipv4.class)
+ .child(Address.class, new AddressKey(new Ipv4AddressNoZone(new Ipv4Address(address))))
+ .build();
}
@Test
@@ -118,11 +126,11 @@ public class Ipv4AddressCustomizerTest extends ListReaderCustomizerTest<Address,
IpAddressDetailsReplyDump reply = new IpAddressDetailsReplyDump();
reply.ipAddressDetails = ImmutableList.of(detail1, detail2, detail3);
- cache.put(Ipv4AddressCustomizer.class.getName(), reply);
+ cache.put(Ipv4AddressCustomizer.class.getName() + IFACE_NAME, reply);
when(ctx.getModificationCache()).thenReturn(cache);
final AddressBuilder builder = new AddressBuilder();
- final InstanceIdentifier<Address> id = getId("192.168.2.1");
+ final InstanceIdentifier<Address> id = getId("192.168.2.1", IFACE_NAME);
getCustomizer().readCurrentAttributes(id, builder, ctx);
@@ -130,6 +138,49 @@ public class Ipv4AddressCustomizerTest extends ListReaderCustomizerTest<Address,
}
@Test
+ public void testReadCurrentAttributesFor2Ifcs() throws ReadFailedException {
+ ModificationCache cache = new ModificationCache();
+
+ IpAddressDetails detail1 = new IpAddressDetails();
+ IpAddressDetails detail2 = 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"))));
+
+ IpAddressDetailsReplyDump reply = new IpAddressDetailsReplyDump();
+ reply.ipAddressDetails = ImmutableList.of(detail1);
+ IpAddressDetailsReplyDump reply2 = new IpAddressDetailsReplyDump();
+ reply2.ipAddressDetails = ImmutableList.of(detail2);
+
+ 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);
+ 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"))));
+ 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"))));
+
+ AddressBuilder builder = new AddressBuilder();
+ getCustomizer().readCurrentAttributes(id, builder, ctx);
+ assertEquals(builder.getIp().getValue(), "192.168.2.1");
+ builder = new AddressBuilder();
+ getCustomizer().readCurrentAttributes(id2, builder, ctx);
+ assertEquals(builder.getIp().getValue(), "192.168.2.2");
+ }
+
+ @Test
public void testReadCurrentAttributesFromOperationalData() throws ReadFailedException {
ModificationCache cache = new ModificationCache();
@@ -155,7 +206,7 @@ public class Ipv4AddressCustomizerTest extends ListReaderCustomizerTest<Address,
final AddressBuilder builder = new AddressBuilder();
- final InstanceIdentifier<Address> id = getId("192.168.2.1");
+ final InstanceIdentifier<Address> id = getId("192.168.2.1", IFACE_NAME);
getCustomizer().readCurrentAttributes(id, builder, ctx);
@@ -180,10 +231,10 @@ public class Ipv4AddressCustomizerTest extends ListReaderCustomizerTest<Address,
IpAddressDetailsReplyDump reply = new IpAddressDetailsReplyDump();
reply.ipAddressDetails = ImmutableList.of(detail1, detail2, detail3);
- cache.put(Ipv4AddressCustomizer.class.getName(), reply);
+ cache.put(Ipv4AddressCustomizer.class.getName() + IFACE_NAME, reply);
when(ctx.getModificationCache()).thenReturn(cache);
- final InstanceIdentifier<Address> id = getId("192.168.2.1");
+ final InstanceIdentifier<Address> id = getId("192.168.2.1", IFACE_NAME);
List<Ipv4AddressNoZone> ids = getCustomizer().getAllIds(id, ctx).stream()
.map(key -> key.getIp())
@@ -220,7 +271,7 @@ public class Ipv4AddressCustomizerTest extends ListReaderCustomizerTest<Address,
when(api.ipAddressDump(Mockito.any(IpAddressDump.class))).thenReturn(future);
when(ctx.getModificationCache()).thenReturn(cache);
- final InstanceIdentifier<Address> id = getId("192.168.2.1");
+ final InstanceIdentifier<Address> id = getId("192.168.2.1", IFACE_NAME);
List<Ipv4AddressNoZone> ids = getCustomizer().getAllIds(id, ctx).stream()
.map(key -> key.getIp())