summaryrefslogtreecommitdiffstats
path: root/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/vppstate
diff options
context:
space:
mode:
Diffstat (limited to 'v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/vppstate')
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/vppstate/BridgeDomainCustomizerTest.java61
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/vppstate/L2FibEntryCustomizerTest.java139
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/vppstate/VersionCustomizerTest.java68
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/vppstate/VppStateTest.java308
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/vppstate/VppStateTestUtils.java72
5 files changed, 648 insertions, 0 deletions
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/vppstate/BridgeDomainCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/vppstate/BridgeDomainCustomizerTest.java
new file mode 100644
index 000000000..bcd6a36f6
--- /dev/null
+++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/vppstate/BridgeDomainCustomizerTest.java
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2016 Cisco and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.honeycomb.translate.v3po.vppstate;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+
+import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
+import io.fd.honeycomb.translate.v3po.test.ListReaderCustomizerTest;
+import io.fd.honeycomb.translate.v3po.util.NamingContext;
+import java.util.Collections;
+import java.util.List;
+import org.junit.Test;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.BridgeDomainsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.bridge.domains.BridgeDomain;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.bridge.domains.BridgeDomainBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.bridge.domains.BridgeDomainKey;
+
+public class BridgeDomainCustomizerTest
+ extends ListReaderCustomizerTest<BridgeDomain, BridgeDomainKey, BridgeDomainBuilder> {
+
+ private NamingContext bdContext;
+ private NamingContext interfacesContext;
+
+ public BridgeDomainCustomizerTest() {
+ super(BridgeDomain.class);
+ }
+
+ @Override
+ public void setUpBefore() {
+ bdContext = new NamingContext("generatedBdName", "bd-test-instance");
+ interfacesContext = new NamingContext("generatedIfaceName", "ifc-test-instance");
+ }
+
+ @Test
+ public void testMerge() throws Exception {
+ final BridgeDomainsBuilder builder = mock(BridgeDomainsBuilder.class);
+ final List<BridgeDomain> value = Collections.emptyList();
+ getCustomizer().merge(builder, value);
+ verify(builder).setBridgeDomain(value);
+ }
+
+ @Override
+ protected ReaderCustomizer<BridgeDomain, BridgeDomainBuilder> initCustomizer() {
+ return new BridgeDomainCustomizer(api, bdContext);
+ }
+} \ No newline at end of file
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/vppstate/L2FibEntryCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/vppstate/L2FibEntryCustomizerTest.java
new file mode 100644
index 000000000..f9eb2d6c6
--- /dev/null
+++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/vppstate/L2FibEntryCustomizerTest.java
@@ -0,0 +1,139 @@
+/*
+ * Copyright (c) 2016 Cisco and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.honeycomb.translate.v3po.vppstate;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
+import io.fd.honeycomb.translate.v3po.test.ContextTestUtils;
+import io.fd.honeycomb.translate.v3po.test.ListReaderCustomizerTest;
+import io.fd.honeycomb.translate.v3po.util.NamingContext;
+import java.util.Collections;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+import org.junit.Test;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.L2FibForward;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.l2.fib.attributes.L2FibTable;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.l2.fib.attributes.L2FibTableBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.l2.fib.attributes.l2.fib.table.L2FibEntry;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.l2.fib.attributes.l2.fib.table.L2FibEntryBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.l2.fib.attributes.l2.fib.table.L2FibEntryKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.BridgeDomains;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.bridge.domains.BridgeDomain;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.bridge.domains.BridgeDomainKey;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.openvpp.jvpp.VppInvocationException;
+import org.openvpp.jvpp.dto.L2FibTableDump;
+import org.openvpp.jvpp.dto.L2FibTableEntry;
+import org.openvpp.jvpp.dto.L2FibTableEntryReplyDump;
+
+public class L2FibEntryCustomizerTest extends ListReaderCustomizerTest<L2FibEntry, L2FibEntryKey, L2FibEntryBuilder> {
+
+ private static final String BD_NAME = "testBD0";
+ private static final int BD_ID = 111;
+ private static final String IFACE_NAME = "eth0";
+ private static final int IFACE_ID = 123;
+ private static final String BD_CTX_NAME = "bd-test-instance";
+ private static final String IFC_CTX_NAME = "ifc-test-instance";
+ private NamingContext bdContext;
+ private NamingContext interfacesContext;
+
+ public L2FibEntryCustomizerTest() {
+ super(L2FibEntry.class);
+ }
+
+ @Override
+ public void setUpBefore() {
+ bdContext = new NamingContext("generatedBdName", BD_CTX_NAME);
+ interfacesContext = new NamingContext("generatedIfaceName", IFC_CTX_NAME);
+ }
+
+ @Override
+ protected ReaderCustomizer<L2FibEntry, L2FibEntryBuilder> initCustomizer() {
+ return new L2FibEntryCustomizer(api, bdContext, interfacesContext);
+ }
+
+ @Test
+ public void testMerge() throws Exception {
+ final L2FibTableBuilder builder = mock(L2FibTableBuilder.class);
+ final List<L2FibEntry> value = Collections.emptyList();
+ getCustomizer().merge(builder, value);
+ verify(builder).setL2FibEntry(value);
+ }
+
+ private static InstanceIdentifier<L2FibEntry> getL2FibEntryId(final String bdName, final PhysAddress address) {
+ return InstanceIdentifier.create(BridgeDomains.class).child(BridgeDomain.class, new BridgeDomainKey(bdName))
+ .child(L2FibTable.class).child(L2FibEntry.class, new L2FibEntryKey(address));
+ }
+
+ private void whenL2FibTableDumpThenReturn(final List<L2FibTableEntry> l2FibTableEntryList)
+ throws ExecutionException, InterruptedException, VppInvocationException {
+ final L2FibTableEntryReplyDump reply = new L2FibTableEntryReplyDump();
+ reply.l2FibTableEntry = l2FibTableEntryList;
+
+ final CompletableFuture<L2FibTableEntryReplyDump> replyFuture = new CompletableFuture<>();
+ replyFuture.complete(reply);
+ when(api.l2FibTableDump(any(L2FibTableDump.class))).thenReturn(replyFuture);
+ }
+
+ @Test
+ public void testRead() throws Exception {
+ final long address_vpp = 0x0000010203040506L;
+ final PhysAddress address = new PhysAddress("01:02:03:04:05:06");
+
+ ContextTestUtils.mockMapping(mappingContext, BD_NAME, BD_ID, BD_CTX_NAME);
+ ContextTestUtils.mockMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME);
+
+ whenL2FibTableDumpThenReturn(Collections.singletonList(generateL2FibEntry(address_vpp)));
+
+ final L2FibEntryBuilder builder = mock(L2FibEntryBuilder.class);
+ getCustomizer().readCurrentAttributes(getL2FibEntryId(BD_NAME, address), builder, ctx);
+
+ verify(builder).setAction(L2FibForward.class);
+ verify(builder).setBridgedVirtualInterface(false);
+ verify(builder).setOutgoingInterface(IFACE_NAME);
+ verify(builder).setStaticConfig(false);
+ verify(builder).setPhysAddress(address);
+ verify(builder).setKey(new L2FibEntryKey(address));
+ }
+
+ private L2FibTableEntry generateL2FibEntry(final long mac) {
+ final L2FibTableEntry entry = new L2FibTableEntry();
+ entry.mac = mac;
+ entry.swIfIndex = IFACE_ID;
+ return entry;
+ }
+
+ @Test
+ public void testGetAllIds() throws Exception {
+ final long address_vpp = 0x0000112233445566L;
+ final PhysAddress address = new PhysAddress("11:22:33:44:55:66");
+ ContextTestUtils.mockMapping(mappingContext, BD_NAME, BD_ID, BD_CTX_NAME);
+
+ whenL2FibTableDumpThenReturn(Collections.singletonList(generateL2FibEntry(address_vpp)));
+
+ final List<L2FibEntryKey> ids = getCustomizer().getAllIds(getL2FibEntryId(BD_NAME, address), ctx);
+ assertEquals(1, ids.size());
+ assertEquals(address, ids.get(0).getPhysAddress());
+ }
+} \ No newline at end of file
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/vppstate/VersionCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/vppstate/VersionCustomizerTest.java
new file mode 100644
index 000000000..b220b32da
--- /dev/null
+++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/vppstate/VersionCustomizerTest.java
@@ -0,0 +1,68 @@
+/*
+ * Copyright (c) 2016 Cisco and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.honeycomb.translate.v3po.vppstate;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
+import io.fd.honeycomb.translate.v3po.test.ReaderCustomizerTest;
+import java.util.concurrent.CompletableFuture;
+import org.junit.Test;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VppStateBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.Version;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.VersionBuilder;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.openvpp.jvpp.dto.ShowVersion;
+import org.openvpp.jvpp.dto.ShowVersionReply;
+
+public class VersionCustomizerTest extends ReaderCustomizerTest<Version, VersionBuilder> {
+
+ public VersionCustomizerTest() {
+ super(Version.class);
+ }
+
+ @Override
+ protected ReaderCustomizer<Version, VersionBuilder> initCustomizer() {
+ return new VersionCustomizer(api);
+ }
+
+ @Test
+ public void testMerge() {
+ final VppStateBuilder builder = mock(VppStateBuilder.class);
+ final Version value = mock(Version.class);
+ getCustomizer().merge(builder, value);
+ verify(builder).setVersion(value);
+ }
+
+ @Test
+ public void testReadCurrentAttributes() throws Exception {
+ final CompletableFuture<ShowVersionReply> replyFuture = new CompletableFuture<>();
+ final ShowVersionReply reply = new ShowVersionReply();
+ reply.version = new byte[]{};
+ reply.program = new byte[]{};
+ reply.buildDate = new byte[]{};
+ reply.buildDirectory = new byte[]{};
+ replyFuture.complete(reply);
+
+ when(api.showVersion(any(ShowVersion.class))).thenReturn(replyFuture);
+ getCustomizer().readCurrentAttributes(InstanceIdentifier.create(Version.class), new VersionBuilder(), ctx);
+ verify(api).showVersion(any(ShowVersion.class));
+ }
+} \ No newline at end of file
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/vppstate/VppStateTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/vppstate/VppStateTest.java
new file mode 100644
index 000000000..7287c2859
--- /dev/null
+++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/vppstate/VppStateTest.java
@@ -0,0 +1,308 @@
+/*
+ * Copyright (c) 2016 Cisco and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.honeycomb.translate.v3po.vppstate;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.doAnswer;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+import static org.mockito.MockitoAnnotations.initMocks;
+
+import com.google.common.base.Optional;
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Multimap;
+import io.fd.honeycomb.translate.ModificationCache;
+import io.fd.honeycomb.translate.impl.read.GenericListReader;
+import io.fd.honeycomb.translate.read.ReadContext;
+import io.fd.honeycomb.translate.v3po.test.ContextTestUtils;
+import io.fd.honeycomb.translate.MappingContext;
+import io.fd.honeycomb.translate.read.registry.ReaderRegistry;
+import io.fd.honeycomb.translate.v3po.util.NamingContext;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.CompletionStage;
+import java.util.concurrent.ExecutionException;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VppState;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.l2.fib.attributes.L2FibTable;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.l2.fib.attributes.l2.fib.table.L2FibEntry;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.l2.fib.attributes.l2.fib.table.L2FibEntryKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.BridgeDomains;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.Version;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.VersionBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.bridge.domains.BridgeDomain;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.bridge.domains.BridgeDomainBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.bridge.domains.BridgeDomainKey;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.openvpp.jvpp.VppInvocationException;
+import org.openvpp.jvpp.dto.BridgeDomainDetails;
+import org.openvpp.jvpp.dto.BridgeDomainDetailsReplyDump;
+import org.openvpp.jvpp.dto.BridgeDomainDump;
+import org.openvpp.jvpp.dto.L2FibTableDump;
+import org.openvpp.jvpp.dto.L2FibTableEntry;
+import org.openvpp.jvpp.dto.L2FibTableEntryReplyDump;
+import org.openvpp.jvpp.dto.ShowVersion;
+import org.openvpp.jvpp.dto.ShowVersionReply;
+import org.openvpp.jvpp.future.FutureJVpp;
+
+public class VppStateTest {
+
+ @Mock
+ private FutureJVpp api;
+ @Mock
+ private ReadContext ctx;
+ @Mock
+ private MappingContext mappingContext;
+
+ private NamingContext bdContext;
+ private NamingContext interfaceContext;
+
+ private ReaderRegistry readerRegistry;
+
+ @Before
+ public void setUp() throws Exception {
+ initMocks(this);
+ final ModificationCache cache = new ModificationCache();
+ doReturn(cache).when(ctx).getModificationCache();
+ doReturn(mappingContext).when(ctx).getMappingContext();
+
+ bdContext = new NamingContext("generatedBdName", "bd-test-instance");
+ interfaceContext = new NamingContext("generatedIfaceName", "ifc-test-instance");
+ readerRegistry = VppStateTestUtils.getVppStateReader(api, bdContext);
+ }
+
+ private static Version getVersion() {
+ return new VersionBuilder()
+ .setName("test")
+ .setBuildDirectory("1")
+ .setBranch("2")
+ .setBuildDate("3")
+ .build();
+ }
+
+ private void whenShowVersionThenReturn(int retval, Version version)
+ throws ExecutionException, InterruptedException, VppInvocationException {
+ final CompletableFuture<ShowVersionReply> replyFuture = new CompletableFuture<>();
+ final ShowVersionReply reply = new ShowVersionReply();
+ reply.buildDate = version.getBuildDate().getBytes();
+ reply.program = version.getName().getBytes();
+ reply.version = version.getBranch().getBytes();
+ reply.buildDirectory = version.getBuildDirectory().getBytes();
+
+ replyFuture.complete(reply);
+ when(api.showVersion(any(ShowVersion.class))).thenReturn(replyFuture);
+ }
+
+ private void whenL2FibTableDumpThenReturn(final List<L2FibTableEntry> entryList)
+ throws ExecutionException, InterruptedException, VppInvocationException {
+ final CompletionStage<L2FibTableEntryReplyDump> replyCS = mock(CompletionStage.class);
+ final CompletableFuture<L2FibTableEntryReplyDump> replyFuture = mock(CompletableFuture.class);
+ when(replyCS.toCompletableFuture()).thenReturn(replyFuture);
+ final L2FibTableEntryReplyDump reply = new L2FibTableEntryReplyDump();
+ reply.l2FibTableEntry = entryList;
+ when(replyFuture.get()).thenReturn(reply);
+ when(api.l2FibTableDump(any(L2FibTableDump.class))).thenReturn(replyCS);
+ }
+
+ private void whenBridgeDomainDumpThenReturn(final List<BridgeDomainDetails> bdList)
+ throws ExecutionException, InterruptedException, VppInvocationException {
+ final CompletionStage<BridgeDomainDetailsReplyDump> replyCS = mock(CompletionStage.class);
+ final CompletableFuture<BridgeDomainDetailsReplyDump> replyFuture = mock(CompletableFuture.class);
+ when(replyCS.toCompletableFuture()).thenReturn(replyFuture);
+ final BridgeDomainDetailsReplyDump reply = new BridgeDomainDetailsReplyDump();
+ reply.bridgeDomainDetails = bdList;
+ when(replyFuture.get()).thenReturn(reply);
+
+ doAnswer(invocation -> {
+ BridgeDomainDump request = (BridgeDomainDump) invocation.getArguments()[0];
+ if (request.bdId == -1) {
+ reply.bridgeDomainDetails = bdList;
+ } else {
+ reply.bridgeDomainDetails = Collections.singletonList(bdList.get(request.bdId));
+ }
+ return replyCS;
+ }).when(api).bridgeDomainDump(any(BridgeDomainDump.class));
+ }
+
+ @Test
+ public void testReadAll() throws Exception {
+ final Version version = getVersion();
+ whenShowVersionThenReturn(0, version);
+
+ final BridgeDomainDetails bridgeDomainDetails = new BridgeDomainDetails();
+ final BridgeDomainDetails bridgeDomainDetails2 = new BridgeDomainDetails();
+ bridgeDomainDetails2.bdId = 1;
+
+ final List<BridgeDomainDetails> bdList = Arrays.asList(bridgeDomainDetails, bridgeDomainDetails2);
+ mockBdMapping(bridgeDomainDetails, "bd1");
+ mockBdMapping(bridgeDomainDetails2, "bd2");
+
+ whenBridgeDomainDumpThenReturn(bdList);
+
+ final Multimap<InstanceIdentifier<? extends DataObject>, ? extends DataObject> dataObjects =
+ readerRegistry.readAll(ctx);
+ assertEquals(dataObjects.size(), 1);
+ final VppState dataObject =
+ (VppState) Iterables.getOnlyElement(dataObjects.get(Iterables.getOnlyElement(dataObjects.keySet())));
+ assertEquals(version, dataObject.getVersion());
+ assertEquals(2, dataObject.getBridgeDomains().getBridgeDomain().size());
+ }
+
+ @Test
+ public void testReadSpecific() throws Exception {
+ final Version version = getVersion();
+ whenShowVersionThenReturn(0, version);
+ whenBridgeDomainDumpThenReturn(Collections.emptyList());
+
+ final Optional<? extends DataObject> read = readerRegistry.read(InstanceIdentifier.create(VppState.class), ctx);
+ assertTrue(read.isPresent());
+ assertEquals(version, ((VppState) read.get()).getVersion());
+ }
+
+ @Test
+ public void testReadBridgeDomains() throws Exception {
+ final Version version = getVersion();
+ whenShowVersionThenReturn(0, version);
+ final BridgeDomainDetails details = new BridgeDomainDetails();
+ whenBridgeDomainDumpThenReturn(Collections.singletonList(details));
+
+ mockBdMapping(details, "bdn1");
+ VppState readRoot = (VppState) readerRegistry.read(InstanceIdentifier.create(VppState.class), ctx).get();
+
+ Optional<? extends DataObject> read =
+ readerRegistry.read(InstanceIdentifier.create(VppState.class).child(BridgeDomains.class), ctx);
+ assertTrue(read.isPresent());
+ assertEquals(readRoot.getBridgeDomains(), read.get());
+ }
+
+ /**
+ * L2fib does not have a dedicated reader, relying on auto filtering
+ */
+ @Test
+ @Ignore("L2 FIB was moved to dedicated customizer. TODO: add infra test that covers such case")
+ @SuppressWarnings("unchecked")
+ public void testReadL2Fib() throws Exception {
+ final BridgeDomainDetails bd = new BridgeDomainDetails();
+ bd.bdId = 0;
+ final String bdName = "bdn1";
+ mockBdMapping(bd, bdName);
+ ContextTestUtils.mockMapping(mappingContext, "eth1", 0, "ifc-test-instance");
+
+ whenBridgeDomainDumpThenReturn(Collections.singletonList(bd));
+ final L2FibTableEntry l2FibEntry = new L2FibTableEntry();
+ l2FibEntry.bdId = 0;
+ l2FibEntry.mac = 0x0605040302010000L;
+ whenL2FibTableDumpThenReturn(Collections.singletonList(l2FibEntry));
+
+ // Deep child without a dedicated reader with specific l2fib key
+ final InstanceIdentifier<? extends DataObject> idExisting =
+ InstanceIdentifier.create(VppState.class).child(BridgeDomains.class).child(
+ BridgeDomain.class, new BridgeDomainKey("bdn1")).child(L2FibTable.class)
+ .child(L2FibEntry.class, new L2FibEntryKey(new PhysAddress("01:02:03:04:05:06")));
+ Optional<? extends DataObject> read =
+ readerRegistry.read(idExisting, ctx);
+ assertTrue(read.isPresent());
+
+ // non existing l2fib
+ final InstanceIdentifier<? extends DataObject> idNonExisting =
+ InstanceIdentifier.create(VppState.class).child(BridgeDomains.class).child(
+ BridgeDomain.class, new BridgeDomainKey("bdn1")).child(L2FibTable.class)
+ .child(L2FibEntry.class, new L2FibEntryKey(new PhysAddress("FF:FF:FF:04:05:06")));
+ read = readerRegistry.read(idNonExisting, ctx);
+ assertFalse(read.isPresent());
+ }
+
+ private void mockBdMapping(final BridgeDomainDetails bd, final String bdName) {
+ ContextTestUtils.mockMapping(mappingContext, bdName, bd.bdId, "bd-test-instance");
+ }
+
+ @Test
+ public void testReadBridgeDomainAll() throws Exception {
+ final Version version = getVersion();
+ whenShowVersionThenReturn(0, version);
+ final BridgeDomainDetails details = new BridgeDomainDetails();
+ whenBridgeDomainDumpThenReturn(Collections.singletonList(details));
+ mockBdMapping(details, "bd2");
+
+ VppState readRoot = (VppState) readerRegistry.read(InstanceIdentifier.create(VppState.class), ctx).get();
+
+ final GenericListReader<BridgeDomain, BridgeDomainKey, BridgeDomainBuilder> bridgeDomainReader =
+ VppStateTestUtils.getBridgeDomainReader(api, bdContext);
+
+ final List<BridgeDomain> read =
+ bridgeDomainReader.readList(InstanceIdentifier.create(VppState.class).child(BridgeDomains.class).child(
+ BridgeDomain.class), ctx);
+
+ assertEquals(readRoot.getBridgeDomains().getBridgeDomain(), read);
+ }
+
+ @Test
+ public void testReadBridgeDomain() throws Exception {
+ final BridgeDomainDetails bd = new BridgeDomainDetails();
+ bd.bdId = 0;
+ final String bdName = "bdn1";
+ mockBdMapping(bd, bdName);
+
+ whenBridgeDomainDumpThenReturn(Collections.singletonList(bd));
+ whenShowVersionThenReturn(0, getVersion());
+
+ VppState readRoot = (VppState) readerRegistry.read(InstanceIdentifier.create(VppState.class), ctx).get();
+
+ final Optional<? extends DataObject> read =
+ readerRegistry.read(InstanceIdentifier.create(VppState.class).child(BridgeDomains.class).child(
+ BridgeDomain.class, new BridgeDomainKey(bdName)), ctx);
+
+ assertTrue(read.isPresent());
+ assertEquals(readRoot.getBridgeDomains().getBridgeDomain().stream().filter(
+ input -> input.getKey().getName().equals(bdName)).findFirst().get(),
+ read.get());
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testReadBridgeDomainNotExisting() throws Exception {
+ doReturn(Optional.absent()).when(mappingContext).read(
+ ContextTestUtils.getMappingIid("NOT EXISTING", "bd-test-instance"));
+
+ final Optional<? extends DataObject> read =
+ readerRegistry.read(InstanceIdentifier.create(VppState.class).child(BridgeDomains.class).child(
+ BridgeDomain.class, new BridgeDomainKey("NOT EXISTING")), ctx);
+ assertFalse(read.isPresent());
+ }
+
+ @Test
+ public void testReadVersion() throws Exception {
+ whenShowVersionThenReturn(0, getVersion());
+ whenBridgeDomainDumpThenReturn(Collections.emptyList());
+ VppState readRoot = (VppState) readerRegistry.read(InstanceIdentifier.create(VppState.class), ctx).get();
+
+ Optional<? extends DataObject> read =
+ readerRegistry.read(InstanceIdentifier.create(VppState.class).child(Version.class), ctx);
+ assertTrue(read.isPresent());
+ assertEquals(readRoot.getVersion(), read.get());
+ }
+} \ No newline at end of file
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/vppstate/VppStateTestUtils.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/vppstate/VppStateTestUtils.java
new file mode 100644
index 000000000..b0f8e78d3
--- /dev/null
+++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/vppstate/VppStateTestUtils.java
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 2016 Cisco and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.honeycomb.translate.v3po.vppstate;
+
+import io.fd.honeycomb.translate.impl.read.GenericListReader;
+import io.fd.honeycomb.translate.impl.read.GenericReader;
+import io.fd.honeycomb.translate.read.registry.ReaderRegistry;
+import io.fd.honeycomb.translate.util.read.registry.CompositeReaderRegistryBuilder;
+import io.fd.honeycomb.translate.v3po.util.NamingContext;
+import javax.annotation.Nonnull;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VppState;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VppStateBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.BridgeDomains;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.BridgeDomainsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.Version;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.bridge.domains.BridgeDomain;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.bridge.domains.BridgeDomainBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.bridge.domains.BridgeDomainKey;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.openvpp.jvpp.future.FutureJVpp;
+
+final class VppStateTestUtils {
+
+ private static InstanceIdentifier<BridgeDomains> bridgeDomainsId;
+
+ public VppStateTestUtils() {
+ }
+
+ /**
+ * Create root VppState reader with all its children wired.
+ */
+ static ReaderRegistry getVppStateReader(@Nonnull final FutureJVpp jVpp,
+ @Nonnull final NamingContext bdContext) {
+ final CompositeReaderRegistryBuilder registry = new CompositeReaderRegistryBuilder();
+
+ // VppState(Structural)
+ final InstanceIdentifier<VppState> vppStateId = InstanceIdentifier.create(VppState.class);
+ registry.addStructuralReader(vppStateId, VppStateBuilder.class);
+ // Version
+ // Wrap with keepalive reader to detect connection issues
+ // TODO keepalive reader wrapper relies on VersionReaderCustomizer (to perform timeout on reads)
+ // Once readers+customizers are asynchronous, pull the timeout to keepalive executor so that keepalive wrapper
+ // is truly generic
+ registry.add(new GenericReader<>(vppStateId.child(Version.class), new VersionCustomizer(jVpp)));
+ // BridgeDomains(Structural)
+ bridgeDomainsId = vppStateId.child(BridgeDomains.class);
+ registry.addStructuralReader(bridgeDomainsId, BridgeDomainsBuilder.class);
+ // BridgeDomain
+ registry.add(getBridgeDomainReader(jVpp, bdContext));
+ return registry.build();
+ }
+
+ static GenericListReader<BridgeDomain, BridgeDomainKey, BridgeDomainBuilder> getBridgeDomainReader(
+ final @Nonnull FutureJVpp jVpp, final @Nonnull NamingContext bdContext) {
+ final InstanceIdentifier<BridgeDomain> bridgeDomainId = bridgeDomainsId.child(BridgeDomain.class);
+ return new GenericListReader<>(bridgeDomainId, new BridgeDomainCustomizer(jVpp, bdContext));
+ }
+}