summaryrefslogtreecommitdiffstats
path: root/v3po/v3po2vpp/src/test/java
diff options
context:
space:
mode:
authorMarek Gradzki <mgradzki@cisco.com>2016-05-04 10:17:39 +0200
committerMarek Gradzki <mgradzki@cisco.com>2016-05-05 08:41:23 +0200
commitca361fd5bfe881014d0791fd9c3b13b66a2d13b2 (patch)
tree27f2424062bda7e1f4a5c90bc473877b0be1f2eb /v3po/v3po2vpp/src/test/java
parentbd1da232ce96416dfde5bb8a2a04afc070395678 (diff)
HONEYCOMB-10: Porting v3po2vpp to the new Java API
Change-Id: Ic7166b0f578442165595aa44a587ebbc5db0e75c Signed-off-by: Marek Gradzki <mgradzki@cisco.com> Signed-off-by: Maros Marsalek <mmarsale@cisco.com>
Diffstat (limited to 'v3po/v3po2vpp/src/test/java')
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfacesstate/InterfaceCustomizerTest.java200
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/test/ChildReaderCustomizerTest.java49
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/test/ListReaderCustomizerTest.java52
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/test/RootReaderCustomizerTest.java84
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/utils/V3poUtilsTest.java32
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/vpp/BridgeDomainCustomizerTest.java205
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/vpp/VppTest.java185
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/vpp/VppUtils.java9
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/vppstate/BridgeDomainCustomizerTest.java59
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/vppstate/VersionCustomizerTest.java73
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/vppstate/VppStateTest.java238
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/vppstate/VppStateTestUtils.java (renamed from v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/vppstate/VppStateUtils.java)41
12 files changed, 823 insertions, 404 deletions
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfacesstate/InterfaceCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfacesstate/InterfaceCustomizerTest.java
index 111d813aa..7c88c3198 100644
--- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfacesstate/InterfaceCustomizerTest.java
+++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfacesstate/InterfaceCustomizerTest.java
@@ -16,112 +16,150 @@
package io.fd.honeycomb.v3po.translate.v3po.interfacesstate;
-import com.google.common.base.Optional;
-import com.google.common.collect.Iterables;
-import com.google.common.collect.Multimap;
-import io.fd.honeycomb.v3po.translate.impl.read.CompositeListReader;
-import io.fd.honeycomb.v3po.translate.impl.read.CompositeRootReader;
-import io.fd.honeycomb.v3po.translate.read.ChildReader;
-import io.fd.honeycomb.v3po.translate.read.ReadContext;
+import static io.fd.honeycomb.v3po.translate.v3po.interfacesstate.InterfaceUtils.YangIfIndexToVpp;
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+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.v3po.translate.read.ReadFailedException;
-import io.fd.honeycomb.v3po.translate.read.Reader;
-import io.fd.honeycomb.v3po.translate.util.RWUtils;
-import io.fd.honeycomb.v3po.translate.util.read.DelegatingReaderRegistry;
-import io.fd.honeycomb.v3po.translate.util.read.ReflexiveRootReaderCustomizer;
-import io.fd.honeycomb.v3po.translate.v3po.interfacesstate.InterfaceCustomizer;
-import org.junit.Before;
+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 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.Test;
-import org.junit.runner.RunWith;
+import org.mockito.ArgumentCaptor;
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.InterfacesStateBuilder;
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.InterfaceBuilder;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.InterfaceKey;
-import org.opendaylight.yangtools.yang.binding.ChildOf;
-import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.openvpp.vppjapi.vppApi;
-import org.openvpp.vppjapi.vppInterfaceDetails;
-import org.openvpp.vppjapi.vppVersion;
-import org.powermock.api.mockito.PowerMockito;
-import org.powermock.core.classloader.annotations.PrepareForTest;
-import org.powermock.core.classloader.annotations.SuppressStaticInitializationFor;
-import org.powermock.modules.junit4.PowerMockRunner;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
+import org.openvpp.jvpp.dto.SwInterfaceDetails;
+import org.openvpp.jvpp.dto.SwInterfaceDetailsReplyDump;
+import org.openvpp.jvpp.dto.SwInterfaceDump;
-import static org.junit.Assert.assertTrue;
-import static org.powermock.api.mockito.PowerMockito.mock;
+public class InterfaceCustomizerTest extends
+ ListReaderCustomizerTest<Interface, InterfaceKey, InterfaceBuilder> {
-@RunWith(PowerMockRunner.class)
-@SuppressStaticInitializationFor("org.openvpp.vppjapi.vppConn")
-@PrepareForTest(vppApi.class)
-public class InterfaceCustomizerTest {
+ private NamingContext interfacesContext;
- public static final vppVersion VERSION = new vppVersion("test", "1", "2", "33");
+ public InterfaceCustomizerTest() {
+ super(Interface.class);
+ }
- private vppApi api;
- private CompositeRootReader<InterfacesState, InterfacesStateBuilder> interfacesStateReader;
- private DelegatingReaderRegistry readerRegistry;
- private ReadContext ctx;
+ @Override
+ public void setUpBefore() {
+ interfacesContext = new NamingContext("generatedIfaceName");
+ }
- private CompositeRootReader<InterfacesState, InterfacesStateBuilder> getInterfacesStateReader(
- final vppApi vppApi) {
+ @Override
+ protected RootReaderCustomizer<Interface, InterfaceBuilder> initCustomizer() {
+ return new InterfaceCustomizer(api, interfacesContext);
+ }
- final CompositeListReader<Interface, InterfaceKey, InterfaceBuilder> interfacesReader =
- new CompositeListReader<>(Interface.class, new InterfaceCustomizer(vppApi));
+ // TODO use reflexion and move to ListReaderCustomizerTest
+ @Test
+ public void testMerge() throws Exception {
+ final InterfacesStateBuilder builder = mock(InterfacesStateBuilder.class);
+ final List<Interface> value = Collections.emptyList();
+ getCustomizer().merge(builder, value);
+ verify(builder).setInterface(value);
+ }
- final List<ChildReader<? extends ChildOf<InterfacesState>>> childReaders = new ArrayList<>();
- childReaders.add(interfacesReader);
+ private void verifyBridgeDomainDumpUpdateWasInvoked(final int nameFilterValid, final String ifaceName) {
+ // TODO adding equals methods for jvpp DTOs would make ArgumentCaptor usage obsolete
+ ArgumentCaptor<SwInterfaceDump> argumentCaptor = ArgumentCaptor.forClass(SwInterfaceDump.class);
+ verify(api).swInterfaceDump(argumentCaptor.capture());
+ final SwInterfaceDump actual = argumentCaptor.getValue();
+ assertEquals(nameFilterValid, actual.nameFilterValid);
+ assertArrayEquals(ifaceName.getBytes(), actual.nameFilter);
+ }
- return new CompositeRootReader<>(InterfacesState.class, childReaders,
- RWUtils.<InterfacesState>emptyAugReaderList(),
- new ReflexiveRootReaderCustomizer<>(InterfacesStateBuilder.class));
+ private static void assertIfacesAreEqual(final Interface iface, final SwInterfaceDetails details) {
+ assertEquals(iface.getName(), new String(details.interfaceName));
+ assertEquals(YangIfIndexToVpp(iface.getIfIndex().intValue()), details.swIfIndex);
+ assertEquals(iface.getPhysAddress().getValue(), InterfaceUtils.vppPhysAddrToYang(details.l2Address));
}
- public static vppInterfaceDetails createVppInterfaceDetails(int ifIndex, String name) {
- return new vppInterfaceDetails(
- ifIndex, name, 0,
- new byte[]{ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00},
- (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, 0, 0,
- (byte) 0, (byte) 0, (byte) 0, (byte) 0, 0, 0, 0, 0, 0);
+ private void whenSwInterfaceDumpThenReturn(final List<SwInterfaceDetails> interfaceList)
+ throws ExecutionException, InterruptedException {
+ final CompletionStage<SwInterfaceDetailsReplyDump> replyCS = mock(CompletionStage.class);
+ final CompletableFuture<SwInterfaceDetailsReplyDump> replyFuture = mock(CompletableFuture.class);
+ when(replyCS.toCompletableFuture()).thenReturn(replyFuture);
+ final SwInterfaceDetailsReplyDump reply = new SwInterfaceDetailsReplyDump();
+ reply.swInterfaceDetails = interfaceList;
+ when(replyFuture.get()).thenReturn(reply);
+ when(api.swInterfaceDump(any(SwInterfaceDump.class))).thenReturn(replyCS);
}
- @Before
- public void setUp() throws Exception {
- api = mock(vppApi.class);
- // PowerMockito.doReturn(VERSION).when(api).getVppVersion();
- ctx = mock(ReadContext.class);
- List<vppInterfaceDetails> ifaces = new ArrayList<>();
- ifaces.add(createVppInterfaceDetails(0, "loop0"));
- vppInterfaceDetails[] ifArr = ifaces.toArray(new vppInterfaceDetails[ifaces.size()]);
-
- PowerMockito.when(api.swInterfaceDump((byte) 0, new byte[]{})).
- thenReturn(ifArr);
- PowerMockito.when(api.swInterfaceDump((byte) 1, ifArr[0].interfaceName.getBytes())).thenReturn(ifArr);
-
- interfacesStateReader = getInterfacesStateReader(api);
- readerRegistry = new DelegatingReaderRegistry(
- Collections.<Reader<? extends DataObject>>singletonList(interfacesStateReader));
+ @Test
+ public void testReadCurrentAttributes() throws Exception {
+ final String ifaceName = "eth0";
+ final InstanceIdentifier<Interface> id = InstanceIdentifier.create(InterfacesState.class)
+ .child(Interface.class, new InterfaceKey(ifaceName));
+ final InterfaceBuilder builder = getCustomizer().getBuilder(id);
+
+ final SwInterfaceDetails iface = new SwInterfaceDetails();
+ iface.interfaceName = ifaceName.getBytes();
+ iface.swIfIndex = 0;
+ iface.linkSpeed = 1;
+ iface.l2AddressLength = 6;
+ iface.l2Address = new byte[iface.l2AddressLength];
+ final List<SwInterfaceDetails> interfaceList = Collections.singletonList(iface);
+ whenSwInterfaceDumpThenReturn(interfaceList);
+
+ getCustomizer().readCurrentAttributes(id, builder, ctx);
+
+ verifyBridgeDomainDumpUpdateWasInvoked(1, ifaceName);
+ assertIfacesAreEqual(builder.build(), iface);
}
@Test
- public void testReadAll() throws ReadFailedException {
- final Multimap<InstanceIdentifier<? extends DataObject>, ? extends DataObject> dataObjects =
- readerRegistry.readAll(ctx);
-
- System.out.println(dataObjects.keys());
- final DataObject obj = Iterables.getOnlyElement(
- dataObjects.get(Iterables.getOnlyElement(dataObjects.keySet())));
- assertTrue(obj instanceof InterfacesState);
+ public void testReadCurrentAttributesFailed() throws Exception {
+ final String ifaceName = "eth0";
+ final InstanceIdentifier<Interface> id = InstanceIdentifier.create(InterfacesState.class)
+ .child(Interface.class, new InterfaceKey(ifaceName));
+ final InterfaceBuilder builder = getCustomizer().getBuilder(id);
+
+ whenSwInterfaceDumpThenReturn(Collections.emptyList());
+
+ try {
+ getCustomizer().readCurrentAttributes(id, builder, ctx);
+ } catch (ReadFailedException e) {
+ verifyBridgeDomainDumpUpdateWasInvoked(1, ifaceName);
+ return;
+ }
+
+ fail("ReadFailedException was expected");
}
@Test
- public void testReadId() throws ReadFailedException {
- Optional<? extends DataObject> read =
- readerRegistry.read(InstanceIdentifier.create(InterfacesState.class).child(Interface.class, new InterfaceKey("Loofdsafdsap0")), ctx);
- System.err.println(read);
+ public void testGetAllIds() throws Exception {
+ final InstanceIdentifier<Interface> id = InstanceIdentifier.create(InterfacesState.class)
+ .child(Interface.class);
+
+ final String swIf0Name = "eth0";
+ final SwInterfaceDetails swIf0 = new SwInterfaceDetails();
+ swIf0.interfaceName = swIf0Name.getBytes();
+ final String swIf1Name = "eth0";
+ final SwInterfaceDetails swIf1 = new SwInterfaceDetails();
+ swIf1.interfaceName = swIf1Name.getBytes();
+ whenSwInterfaceDumpThenReturn(Arrays.asList(swIf0, swIf1));
+
+ final List<InterfaceKey> expectedIds = Arrays.asList(new InterfaceKey(swIf0Name), new InterfaceKey(swIf1Name));
+ final List<InterfaceKey> actualIds = getCustomizer().getAllIds(id, ctx);
+
+ verifyBridgeDomainDumpUpdateWasInvoked(0, "");
+
+ assertEquals(expectedIds, actualIds);
}
}
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/test/ChildReaderCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/test/ChildReaderCustomizerTest.java
new file mode 100644
index 000000000..57369d665
--- /dev/null
+++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/test/ChildReaderCustomizerTest.java
@@ -0,0 +1,49 @@
+/*
+ * 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.v3po.translate.v3po.test;
+
+import static org.junit.Assert.assertNotNull;
+
+import io.fd.honeycomb.v3po.translate.spi.read.ChildReaderCustomizer;
+import org.junit.Test;
+import org.opendaylight.yangtools.concepts.Builder;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+/**
+ * Generic test for classes implementing {@link ChildReaderCustomizer} interface.
+ *
+ * @param <D> Specific DataObject derived type (Identifiable), that is handled by this customizer
+ * @param <B> Specific Builder for handled type (D)
+ */
+public abstract class ChildReaderCustomizerTest<D extends DataObject, B extends Builder<D>> extends RootReaderCustomizerTest<D, B>{
+
+
+ protected ChildReaderCustomizerTest(Class<D> dataObjectClass) {
+ super(dataObjectClass);
+ }
+
+ @Override
+ protected ChildReaderCustomizer<D, B> getCustomizer() {
+ return ChildReaderCustomizer.class.cast(super.getCustomizer());
+ }
+
+ @Test
+ public void testGetBuilder() throws Exception {
+ assertNotNull(getCustomizer().getBuilder(InstanceIdentifier.create(dataObjectClass)));
+ }
+}
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/test/ListReaderCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/test/ListReaderCustomizerTest.java
new file mode 100644
index 000000000..00cac2d5d
--- /dev/null
+++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/test/ListReaderCustomizerTest.java
@@ -0,0 +1,52 @@
+/*
+ * 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.v3po.translate.v3po.test;
+
+import static org.junit.Assert.assertNotNull;
+
+import io.fd.honeycomb.v3po.translate.spi.read.ListReaderCustomizer;
+import org.junit.Test;
+import org.opendaylight.yangtools.concepts.Builder;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.Identifiable;
+import org.opendaylight.yangtools.yang.binding.Identifier;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+/**
+ * Generic test for classes implementing {@link ListReaderCustomizer} interface.
+ *
+ * @param <D> Specific DataObject derived type (Identifiable), that is handled by this customizer
+ * @param <K> Specific Identifier for handled type (D)
+ * @param <B> Specific Builder for handled type (D)
+ */
+public abstract class ListReaderCustomizerTest<D extends DataObject & Identifiable<K>, K extends Identifier<D>, B extends Builder<D>> extends RootReaderCustomizerTest<D, B>{
+
+
+ protected ListReaderCustomizerTest(Class<D> dataObjectClass) {
+ super(dataObjectClass);
+ }
+
+ @Override
+ protected ListReaderCustomizer<D, K, B> getCustomizer() {
+ return ListReaderCustomizer.class.cast(super.getCustomizer());
+ }
+
+ @Test
+ public void testGetBuilder() throws Exception {
+ assertNotNull(getCustomizer().getBuilder(InstanceIdentifier.create(dataObjectClass)));
+ }
+}
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/test/RootReaderCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/test/RootReaderCustomizerTest.java
new file mode 100644
index 000000000..76eb0fb3f
--- /dev/null
+++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/test/RootReaderCustomizerTest.java
@@ -0,0 +1,84 @@
+/*
+ * 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.v3po.translate.v3po.test;
+
+import static org.junit.Assert.assertNotNull;
+import static org.mockito.MockitoAnnotations.initMocks;
+
+import io.fd.honeycomb.v3po.translate.Context;
+import io.fd.honeycomb.v3po.translate.spi.read.RootReaderCustomizer;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.opendaylight.yangtools.concepts.Builder;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.openvpp.jvpp.future.FutureJVpp;
+
+/**
+ * Generic test for classes implementing {@link RootReaderCustomizer} interface.
+ *
+ * @param <D> Specific DataObject derived type (Identifiable), that is handled by this customizer
+ * @param <B> Specific Builder for handled type (D)
+ */
+public abstract class RootReaderCustomizerTest<D extends DataObject, B extends Builder<D>> {
+
+ @Mock
+ protected FutureJVpp api;
+ @Mock
+ protected Context ctx;
+
+ protected final Class<D> dataObjectClass;
+ private RootReaderCustomizer<D, B> customizer;
+
+ protected RootReaderCustomizerTest(Class<D> dataObjectClass) {
+ this.dataObjectClass = dataObjectClass;
+ }
+
+ @Before
+ public void setUpParent() throws Exception {
+ initMocks(this);
+ setUpBefore();
+ customizer = initCustomizer();
+ setUpAfter();
+ }
+
+ /**
+ * Optional setup for subclasses. Invoked before customizer is initialized.
+ */
+ protected void setUpBefore() {
+
+ }
+
+ /**
+ * Optional setup for subclasses. Invoked after customizer is initialized.
+ */
+ protected void setUpAfter() {
+
+ }
+
+ protected abstract RootReaderCustomizer<D, B> initCustomizer();
+
+ protected RootReaderCustomizer<D, B> getCustomizer() {
+ return customizer;
+ }
+
+ @Test
+ public void testGetBuilder() throws Exception {
+ assertNotNull(customizer.getBuilder(InstanceIdentifier.create(dataObjectClass)));
+ }
+}
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/utils/V3poUtilsTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/utils/V3poUtilsTest.java
index 3cb054ad4..115eb2b9c 100644
--- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/utils/V3poUtilsTest.java
+++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/utils/V3poUtilsTest.java
@@ -1,35 +1,17 @@
package io.fd.honeycomb.v3po.translate.v3po.utils;
-import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertArrayEquals;
import org.junit.Test;
-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;
public class V3poUtilsTest {
@Test
- public void testRemoveIpv4AddressNoZoneFromIpv4WithZone() throws Exception {
- String ipWithZone = "1.2.3.4%20";
- String ipNoZone = "1.2.3.4";
- final Ipv4Address expectedIp = new Ipv4Address(ipNoZone);
- final Ipv4AddressNoZone actualIp = V3poUtils.removeIpv4AddressNoZone(new Ipv4Address(ipWithZone));
- assertEquals(expectedIp.getValue(), actualIp.getValue());
- }
-
- @Test
- public void testRemoveIpv4AddressNoZoneFromIpv4WithoutZone() throws Exception {
- String ipNoZone = "1.2.3.4";
- final Ipv4Address expectedIp = new Ipv4Address(ipNoZone);
- final Ipv4AddressNoZone actualIp = V3poUtils.removeIpv4AddressNoZone(expectedIp);
- assertEquals(expectedIp.getValue(), actualIp.getValue());
- }
-
- @Test
- public void testRemoveIpv4AddressNoZoneNop() throws Exception {
- String ipNoZone = "1.2.3.4";
- final Ipv4Address expectedIp = new Ipv4AddressNoZone(ipNoZone);
- final Ipv4AddressNoZone actualIp = V3poUtils.removeIpv4AddressNoZone(expectedIp);
- assertEquals(expectedIp, actualIp);
+ public void testToString() {
+ final byte[] expected = "test".getBytes();
+ final byte[] cString = new byte[expected.length+10];
+ System.arraycopy(expected, 0, cString, 0, expected.length);
+ final String jString = V3poUtils.toString(cString);
+ assertArrayEquals(expected, jString.getBytes());
}
} \ No newline at end of file
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/vpp/BridgeDomainCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/vpp/BridgeDomainCustomizerTest.java
index f504918a8..5d5781adb 100644
--- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/vpp/BridgeDomainCustomizerTest.java
+++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/vpp/BridgeDomainCustomizerTest.java
@@ -13,57 +13,53 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package io.fd.honeycomb.v3po.translate.v3po.vpp;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
-import static org.mockito.Matchers.anyInt;
-import static org.mockito.Matchers.anyString;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
import static org.mockito.MockitoAnnotations.initMocks;
import io.fd.honeycomb.v3po.translate.Context;
+import io.fd.honeycomb.v3po.translate.write.WriteFailedException;
+import io.fd.honeycomb.v3po.translate.v3po.util.NamingContext;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.CompletionStage;
+import java.util.concurrent.ExecutionException;
import org.junit.Before;
import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.bridge.domains.BridgeDomain;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.bridge.domains.BridgeDomainBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.bridge.domains.BridgeDomainKey;
-import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
-import org.openvpp.vppjapi.vppApi;
-import org.powermock.api.mockito.PowerMockito;
-import org.powermock.core.classloader.annotations.PrepareForTest;
-import org.powermock.core.classloader.annotations.SuppressStaticInitializationFor;
-import org.powermock.modules.junit4.PowerMockRunner;
-
-@RunWith(PowerMockRunner.class)
-@SuppressStaticInitializationFor("org.openvpp.vppjapi.vppConn")
-@PrepareForTest(vppApi.class)
+import org.openvpp.jvpp.dto.BridgeDomainAddDel;
+import org.openvpp.jvpp.dto.BridgeDomainAddDelReply;
+import org.openvpp.jvpp.future.FutureJVpp;
+
public class BridgeDomainCustomizerTest {
- private static final int RESPONSE_NOT_READY = -77;
private static final byte ADD_OR_UPDATE_BD = (byte) 1;
private static final byte ZERO = 0;
- private vppApi api;
+
+ @Mock
+ private FutureJVpp api;
@Mock
private Context ctx;
private BridgeDomainCustomizer customizer;
+ private NamingContext namingContext;
@Before
public void setUp() throws Exception {
- // TODO create base class for tests using vppApi
- api = PowerMockito.mock(vppApi.class);
initMocks(this);
- customizer = new BridgeDomainCustomizer(api);
-
- PowerMockito.doAnswer(BridgeDomainTestUtils.BD_NAME_TO_ID_ANSWER).when(api).findOrAddBridgeDomainId(anyString());
- PowerMockito.doAnswer(BridgeDomainTestUtils.BD_NAME_TO_ID_ANSWER).when(api).bridgeDomainIdFromName(anyString());
- PowerMockito.when(api.getRetval(anyInt(), anyInt())).thenReturn(RESPONSE_NOT_READY).thenReturn(0);
- PowerMockito.doReturn(0).when(api).getRetval(anyInt(), anyInt());
+ // TODO create base class for tests using vppApi
+ namingContext = new NamingContext("generatedBDName");
+ customizer = new BridgeDomainCustomizer(api, namingContext);
}
private BridgeDomain generateBridgeDomain(final String bdName) {
@@ -87,127 +83,140 @@ public class BridgeDomainCustomizerTest {
.build();
}
- private final int verifyBridgeDomainAddOrUpdateWasInvoked(final BridgeDomain bd) {
- final int bdn1Id = BridgeDomainTestUtils.bdNameToID(bd.getName());
+ private void verifyBridgeDomainAddOrUpdateWasInvoked(final BridgeDomain bd, final int bdId) {
final byte arpTerm = BridgeDomainTestUtils.booleanToByte(bd.isArpTermination());
final byte flood = BridgeDomainTestUtils.booleanToByte(bd.isFlood());
final byte forward = BridgeDomainTestUtils.booleanToByte(bd.isForward());
final byte learn = BridgeDomainTestUtils.booleanToByte(bd.isLearn());
final byte uuf = BridgeDomainTestUtils.booleanToByte(bd.isUnknownUnicastFlood());
- return verify(api).bridgeDomainAddDel(bdn1Id, flood, forward, learn, uuf, arpTerm, ADD_OR_UPDATE_BD);
+
+ // TODO adding equals methods for jvpp DTOs would make ArgumentCaptor usage obsolete
+ ArgumentCaptor<BridgeDomainAddDel> argumentCaptor = ArgumentCaptor.forClass(BridgeDomainAddDel.class);
+ verify(api).bridgeDomainAddDel(argumentCaptor.capture());
+ final BridgeDomainAddDel actual = argumentCaptor.getValue();
+ assertEquals(arpTerm, actual.arpTerm);
+ assertEquals(flood, actual.flood);
+ assertEquals(forward, actual.forward);
+ assertEquals(learn, actual.learn);
+ assertEquals(uuf, actual.uuFlood);
+ assertEquals(ADD_OR_UPDATE_BD, actual.isAdd);
+ assertEquals(bdId, actual.bdId);
}
- private int verifyBridgeDomainAddOrUpdateWasNotInvoked(final BridgeDomain bd) {
- final int bdn1Id = BridgeDomainTestUtils.bdNameToID(bd.getName());
- final byte arpTerm = BridgeDomainTestUtils.booleanToByte(bd.isArpTermination());
- final byte flood = BridgeDomainTestUtils.booleanToByte(bd.isFlood());
- final byte forward = BridgeDomainTestUtils.booleanToByte(bd.isForward());
- final byte learn = BridgeDomainTestUtils.booleanToByte(bd.isLearn());
- final byte uuf = BridgeDomainTestUtils.booleanToByte(bd.isUnknownUnicastFlood());
- return verify(api, never()).bridgeDomainAddDel(bdn1Id, flood, forward, learn, uuf, arpTerm, ADD_OR_UPDATE_BD);
+ private void verifyBridgeDomainDeleteWasInvoked(final int bdId) {
+ ArgumentCaptor<BridgeDomainAddDel> argumentCaptor = ArgumentCaptor.forClass(BridgeDomainAddDel.class);
+ verify(api).bridgeDomainAddDel(argumentCaptor.capture());
+ final BridgeDomainAddDel actual = argumentCaptor.getValue();
+ assertEquals(bdId, actual.bdId);
+ assertEquals(ZERO, actual.arpTerm);
+ assertEquals(ZERO, actual.flood);
+ assertEquals(ZERO, actual.forward);
+ assertEquals(ZERO, actual.learn);
+ assertEquals(ZERO, actual.uuFlood);
+ assertEquals(ZERO, actual.isAdd);
+ }
+
+ private void whenBridgeDomainAddDelThen(final int retval) throws ExecutionException, InterruptedException {
+ final CompletionStage<BridgeDomainAddDelReply> replyCS = mock(CompletionStage.class);
+ final CompletableFuture<BridgeDomainAddDelReply> replyFuture = mock(CompletableFuture.class);
+ when(replyCS.toCompletableFuture()).thenReturn(replyFuture);
+ final BridgeDomainAddDelReply reply = new BridgeDomainAddDelReply();
+ reply.retval = retval;
+ when(replyFuture.get()).thenReturn(reply);
+ when(api.bridgeDomainAddDel(any(BridgeDomainAddDel.class))).thenReturn(replyCS);
}
- private int verifyBridgeDomainDeletedWasInvoked(final BridgeDomain bd) {
- final int bdn1Id = BridgeDomainTestUtils.bdNameToID(bd.getName());
- return verify(api).bridgeDomainAddDel(bdn1Id, ZERO, ZERO, ZERO, ZERO, ZERO, ZERO);
+ private void whenBridgeDomainAddDelThenSuccess() throws ExecutionException, InterruptedException {
+ whenBridgeDomainAddDelThen(0);
}
- private int verifyBridgeDomainDeletedWasNotInvoked(final BridgeDomain bd) {
- final int bdn1Id = BridgeDomainTestUtils.bdNameToID(bd.getName());
- return verify(api, never()).bridgeDomainAddDel(bdn1Id, ZERO, ZERO, ZERO, ZERO, ZERO, ZERO);
+ private void whenBridgeDomainAddDelThenFailure() throws ExecutionException, InterruptedException {
+ whenBridgeDomainAddDelThen(-1);
}
@Test
- public void testAddBridgeDomain() {
+ public void testAddBridgeDomain() throws Exception {
+ final int bdId = 1;
final String bdName = "bd1";
- final BridgeDomain bd = generateBridgeDomain("bd1");
+ final BridgeDomain bd = generateBridgeDomain(bdName);
+
+ whenBridgeDomainAddDelThenSuccess();
customizer.writeCurrentAttributes(BridgeDomainTestUtils.bdIdentifierForName(bdName), bd, ctx);
- verifyBridgeDomainAddOrUpdateWasInvoked(bd);
+ verifyBridgeDomainAddOrUpdateWasInvoked(bd, bdId);
}
@Test
- public void testBridgeDomainNameCreateFailed() {
+ public void testAddBridgeDomainFailed() throws Exception {
+ final int bdId = 1;
final String bdName = "bd1";
- final BridgeDomain bd = generateBridgeDomain("bd1");
+ final BridgeDomain bd = generateBridgeDomain(bdName);
- // make vpp api fail to create id for our bd name
- PowerMockito.doReturn(-1).when(api).findOrAddBridgeDomainId(bdName);
+ whenBridgeDomainAddDelThenFailure();
try {
customizer.writeCurrentAttributes(BridgeDomainTestUtils.bdIdentifierForName(bdName), bd, ctx);
- } catch (IllegalStateException e) {
- verifyBridgeDomainAddOrUpdateWasNotInvoked(bd);
+ } catch (WriteFailedException.CreateFailedException e) {
+ verifyBridgeDomainAddOrUpdateWasInvoked(bd, bdId);
return;
}
- fail("IllegalStateException was expected");
+ fail("WriteFailedException.CreateFailedException was expected");
}
@Test
- public void testAddBridgeDomainFailed() {
- // make any call to vpp fail
- PowerMockito.doReturn(-1).when(api).getRetval(anyInt(), anyInt());
-
+ public void testDeleteBridgeDomain() throws Exception {
+ final int bdId = 1;
final String bdName = "bd1";
final BridgeDomain bd = generateBridgeDomain(bdName);
+ namingContext.addName(bdId, bdName);
- try {
- customizer.writeCurrentAttributes(BridgeDomainTestUtils.bdIdentifierForName(bdName), bd, ctx);
- } catch (IllegalStateException e) {
- verifyBridgeDomainAddOrUpdateWasInvoked(bd);
- return;
- }
- fail("IllegalStateException was expected");
- }
-
- @Test
- public void testDeleteBridgeDomain() {
- final String bdName = "bd1";
- final BridgeDomain bd = generateBridgeDomain("bd1");
+ whenBridgeDomainAddDelThenSuccess();
customizer.deleteCurrentAttributes(BridgeDomainTestUtils.bdIdentifierForName(bdName), bd, ctx);
- verifyBridgeDomainDeletedWasInvoked(bd);
+ verifyBridgeDomainDeleteWasInvoked(bdId);
}
@Test
- public void testDeleteUnknownBridgeDomain() {
+ public void testDeleteUnknownBridgeDomain() throws Exception {
final String bdName = "bd1";
final BridgeDomain bd = generateBridgeDomain("bd1");
- // make vpp api not find our bd
- PowerMockito.doReturn(-1).when(api).bridgeDomainIdFromName(bdName);
-
try {
customizer.deleteCurrentAttributes(BridgeDomainTestUtils.bdIdentifierForName(bdName), bd, ctx);
- } catch (IllegalStateException e) {
- verifyBridgeDomainDeletedWasNotInvoked(bd);
+ } catch (IllegalArgumentException e) {
+ verify(api, never()).bridgeDomainAddDel(any(BridgeDomainAddDel.class));
return;
}
- fail("IllegalStateException was expected");
+ fail("IllegalArgumentException was expected");
}
@Test
- public void testDeleteBridgeDomainFailed() {
- // make any call to vpp fail
- PowerMockito.doReturn(-1).when(api).getRetval(anyInt(), anyInt());
-
+ public void testDeleteBridgeDomainFailed() throws Exception {
+ final int bdId = 1;
final String bdName = "bd1";
final BridgeDomain bd = generateBridgeDomain(bdName);
+ namingContext.addName(bdId, bdName);
+
+ whenBridgeDomainAddDelThenFailure();
try {
customizer.deleteCurrentAttributes(BridgeDomainTestUtils.bdIdentifierForName(bdName), bd, ctx);
- } catch (IllegalStateException e) {
- verifyBridgeDomainDeletedWasInvoked(bd);
+ } catch (WriteFailedException.DeleteFailedException e) {
+ verifyBridgeDomainDeleteWasInvoked(bdId);
return;
}
- fail("IllegalStateException was expected");
+
+ fail("WriteFailedException.DeleteFailedException was expected");
}
@Test
public void testUpdateBridgeDomain() throws Exception {
+ final int bdId = 1;
final String bdName = "bd1";
+ namingContext.addName(bdId, bdName);
+
final byte arpTermBefore = 1;
final byte floodBefore = 1;
final byte forwardBefore = 0;
@@ -220,11 +229,11 @@ public class BridgeDomainCustomizerTest {
generateBridgeDomain(bdName, arpTermBefore ^ 1, floodBefore ^ 1, forwardBefore ^ 1, learnBefore ^ 1,
uufBefore ^ 1);
- final KeyedInstanceIdentifier<BridgeDomain, BridgeDomainKey> id = BridgeDomainTestUtils.bdIdentifierForName(bdName);
+ whenBridgeDomainAddDelThenSuccess();
- customizer.updateCurrentAttributes(id, dataBefore, dataAfter, ctx);
+ customizer.updateCurrentAttributes(BridgeDomainTestUtils.bdIdentifierForName(bdName), dataBefore, dataAfter, ctx);
- verifyBridgeDomainAddOrUpdateWasInvoked(dataAfter);
+ verifyBridgeDomainAddOrUpdateWasInvoked(dataAfter, bdId);
}
@Test
@@ -232,30 +241,28 @@ public class BridgeDomainCustomizerTest {
final String bdName = "bd1";
final BridgeDomain bd = generateBridgeDomain("bd1");
- // make vpp api not find our bd
- PowerMockito.doReturn(-1).when(api).bridgeDomainIdFromName(bdName);
-
try {
customizer.updateCurrentAttributes(BridgeDomainTestUtils.bdIdentifierForName(bdName), bd, bd, ctx);
- } catch (IllegalStateException e) {
- verifyBridgeDomainAddOrUpdateWasNotInvoked(bd);
+ } catch (IllegalArgumentException e) {
+ verify(api, never()).bridgeDomainAddDel(any(BridgeDomainAddDel.class));
return;
}
- fail("IllegalStateException was expected");
+ fail("IllegalArgumentException was expected");
}
@Test
- public void testUpdateBridgeDomainFailed() {
- // make any call to vpp fail
- PowerMockito.doReturn(-1).when(api).getRetval(anyInt(), anyInt());
-
+ public void testUpdateBridgeDomainFailed() throws Exception {
+ final int bdId = 1;
final String bdName = "bd1";
final BridgeDomain bd = generateBridgeDomain(bdName);
+ namingContext.addName(bdId, bdName);
+
+ whenBridgeDomainAddDelThenFailure();
try {
customizer.updateCurrentAttributes(BridgeDomainTestUtils.bdIdentifierForName(bdName), bd, bd, ctx);
- } catch (IllegalStateException e) {
- verifyBridgeDomainAddOrUpdateWasInvoked(bd);
+ } catch (WriteFailedException.UpdateFailedException e) {
+ verifyBridgeDomainAddOrUpdateWasInvoked(bd, bdId);
return;
}
fail("IllegalStateException was expected");
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/vpp/VppTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/vpp/VppTest.java
index 0ff3ba16d..820cf0555 100644
--- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/vpp/VppTest.java
+++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/vpp/VppTest.java
@@ -16,23 +16,28 @@
package io.fd.honeycomb.v3po.translate.v3po.vpp;
-import static org.mockito.Matchers.anyInt;
-import static org.mockito.Matchers.anyString;
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyZeroInteractions;
+import static org.mockito.Mockito.when;
+import com.google.common.collect.Iterators;
import com.google.common.collect.Lists;
import io.fd.honeycomb.v3po.translate.impl.write.CompositeRootWriter;
-import io.fd.honeycomb.v3po.translate.write.WriteContext;
import io.fd.honeycomb.v3po.translate.util.write.DelegatingWriterRegistry;
+import io.fd.honeycomb.v3po.translate.v3po.util.NamingContext;
+import io.fd.honeycomb.v3po.translate.write.WriteContext;
import io.fd.honeycomb.v3po.translate.write.Writer;
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.Test;
-import org.junit.runner.RunWith;
+import org.mockito.ArgumentCaptor;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.Vpp;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VppBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.BridgeDomains;
@@ -41,98 +46,147 @@ 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.vpp.bridge.domains.BridgeDomainBuilder;
import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.openvpp.vppjapi.vppApi;
-import org.powermock.api.mockito.PowerMockito;
-import org.powermock.core.classloader.annotations.PrepareForTest;
-import org.powermock.core.classloader.annotations.SuppressStaticInitializationFor;
-import org.powermock.modules.junit4.PowerMockRunner;
-
-@RunWith(PowerMockRunner.class)
-@SuppressStaticInitializationFor("org.openvpp.vppjapi.vppConn")
-@PrepareForTest(vppApi.class)
+import org.openvpp.jvpp.dto.BridgeDomainAddDel;
+import org.openvpp.jvpp.dto.BridgeDomainAddDelReply;
+import org.openvpp.jvpp.future.FutureJVpp;
+
public class VppTest {
- private vppApi api;
+ private static final byte ADD_OR_UPDATE_BD = 1;
+ private static final byte ZERO = 0;
+ private FutureJVpp api;
private DelegatingWriterRegistry rootRegistry;
private CompositeRootWriter<Vpp> vppWriter;
private WriteContext ctx;
-
- final byte zero = (byte) 0;
- final byte flood = (byte) 1;
- final byte forward = (byte) 0;
- final byte learn = (byte) 1;
- final byte uuf = (byte) 0;
- final byte arpTerm = (byte) 0;
- final byte add = (byte) 1;
+ private NamingContext bdContext;
@Before
public void setUp() throws Exception {
- api = PowerMockito.mock(vppApi.class);
+ api = mock(FutureJVpp.class);
ctx = mock(WriteContext.class);
- PowerMockito.doAnswer(BridgeDomainTestUtils.BD_NAME_TO_ID_ANSWER).when(api).findOrAddBridgeDomainId(anyString());
- PowerMockito.doAnswer(BridgeDomainTestUtils.BD_NAME_TO_ID_ANSWER).when(api).bridgeDomainIdFromName(anyString());
- PowerMockito.doReturn(1).when(api).getRetval(anyInt(), anyInt());
- vppWriter = VppUtils.getVppWriter(api);
+ bdContext = new NamingContext("generatedBdName");
+ vppWriter = VppUtils.getVppWriter(api, bdContext);
rootRegistry = new DelegatingWriterRegistry(
Collections.<Writer<? extends DataObject>>singletonList(vppWriter));
}
+ private BridgeDomains getBridgeDomains(String... name) {
+ final List<BridgeDomain> bdmns = Lists.newArrayList();
+ for (String s : name) {
+ bdmns.add(new BridgeDomainBuilder()
+ .setName(s)
+ .setArpTermination(false)
+ .setFlood(true)
+ .setForward(false)
+ .setLearn(true)
+ .build());
+ }
+ return new BridgeDomainsBuilder()
+ .setBridgeDomain(bdmns)
+ .build();
+ }
+
+ private void whenBridgeDomainAddDelThen(final int retval) throws ExecutionException, InterruptedException {
+ final CompletionStage<BridgeDomainAddDelReply> replyCS = mock(CompletionStage.class);
+ final CompletableFuture<BridgeDomainAddDelReply> replyFuture = mock(CompletableFuture.class);
+ when(replyCS.toCompletableFuture()).thenReturn(replyFuture);
+ final BridgeDomainAddDelReply reply = new BridgeDomainAddDelReply();
+ reply.retval = retval;
+ when(replyFuture.get()).thenReturn(reply);
+ when(api.bridgeDomainAddDel(any(BridgeDomainAddDel.class))).thenReturn(replyCS);
+ }
+
+ private void verifyBridgeDomainAddDel(final BridgeDomain bd, final int bdId) {
+ final byte arpTerm = BridgeDomainTestUtils.booleanToByte(bd.isArpTermination());
+ final byte flood = BridgeDomainTestUtils.booleanToByte(bd.isFlood());
+ final byte forward = BridgeDomainTestUtils.booleanToByte(bd.isForward());
+ final byte learn = BridgeDomainTestUtils.booleanToByte(bd.isLearn());
+ final byte uuf = BridgeDomainTestUtils.booleanToByte(bd.isUnknownUnicastFlood());
+
+ // TODO adding equals methods for jvpp DTOs would make ArgumentCaptor usage obsolete
+ ArgumentCaptor<BridgeDomainAddDel> argumentCaptor = ArgumentCaptor.forClass(BridgeDomainAddDel.class);
+ verify(api).bridgeDomainAddDel(argumentCaptor.capture());
+ final BridgeDomainAddDel actual = argumentCaptor.getValue();
+ assertEquals(arpTerm, actual.arpTerm);
+ assertEquals(flood, actual.flood);
+ assertEquals(forward, actual.forward);
+ assertEquals(learn, actual.learn);
+ assertEquals(uuf, actual.uuFlood);
+ assertEquals(ADD_OR_UPDATE_BD, actual.isAdd);
+ assertEquals(bdId, actual.bdId);
+ }
+
+ private void verifyBridgeDomainDeleteWasInvoked(final int bdId) {
+ ArgumentCaptor<BridgeDomainAddDel> argumentCaptor = ArgumentCaptor.forClass(BridgeDomainAddDel.class);
+ verify(api).bridgeDomainAddDel(argumentCaptor.capture());
+ final BridgeDomainAddDel actual = argumentCaptor.getValue();
+ assertEquals(bdId, actual.bdId);
+ assertEquals(ZERO, actual.arpTerm);
+ assertEquals(ZERO, actual.flood);
+ assertEquals(ZERO, actual.forward);
+ assertEquals(ZERO, actual.learn);
+ assertEquals(ZERO, actual.uuFlood);
+ assertEquals(ZERO, actual.isAdd);
+ }
+
@Test
- public void writeVpp() throws Exception {
+ public void writeVppUsingRootRegistry() throws Exception {
+ final int bdId = 1;
+ final BridgeDomains bdn1 = getBridgeDomains("bdn1");
+ whenBridgeDomainAddDelThen(0);
+
rootRegistry.update(
- InstanceIdentifier.create(Vpp.class),
- null,
- new VppBuilder().setBridgeDomains(getBridgeDomains("bdn1")).build(),
- ctx);
+ InstanceIdentifier.create(Vpp.class),
+ null,
+ new VppBuilder().setBridgeDomains(bdn1).build(),
+ ctx);
+
+ verifyBridgeDomainAddDel(Iterators.getOnlyElement(bdn1.getBridgeDomain().iterator()), bdId);
+ }
- verify(api).bridgeDomainAddDel(1, flood, forward, learn, uuf, arpTerm, add);
+ @Test
+ public void writeVppUsingVppWriter() throws Exception {
+ final int bdId = 1;
+ final BridgeDomains bdn1 = getBridgeDomains("bdn1");
+ whenBridgeDomainAddDelThen(0);
vppWriter.update(InstanceIdentifier.create(Vpp.class),
- null,
- new VppBuilder().setBridgeDomains(getBridgeDomains("bdn1")).build(),
- ctx);
+ null,
+ new VppBuilder().setBridgeDomains(bdn1).build(),
+ ctx);
- verify(api, times(2)).bridgeDomainAddDel(1, flood, forward, learn, uuf, arpTerm, add);
+ verifyBridgeDomainAddDel(Iterators.getOnlyElement(bdn1.getBridgeDomain().iterator()), bdId);
}
@Test
public void writeVppFromRoot() throws Exception {
- final Vpp vpp = new VppBuilder().setBridgeDomains(getBridgeDomains("bdn1")).build();
+ final BridgeDomains bdn1 = getBridgeDomains("bdn1");
+ final int bdId = 1;
+ final Vpp vpp = new VppBuilder().setBridgeDomains(bdn1).build();
+ whenBridgeDomainAddDelThen(0);
rootRegistry.update(Collections.<InstanceIdentifier<?>, DataObject>emptyMap(),
Collections.<InstanceIdentifier<?>, DataObject>singletonMap(InstanceIdentifier.create(Vpp.class),
vpp), ctx);
- verify(api).bridgeDomainAddDel(1, flood, forward, learn, uuf, arpTerm, add);
- }
-
- private BridgeDomains getBridgeDomains(String... name) {
- final List<BridgeDomain> bdmns = Lists.newArrayList();
- for (String s : name) {
- bdmns.add(new BridgeDomainBuilder()
- .setName(s)
- .setArpTermination(false)
- .setFlood(true)
- .setForward(false)
- .setLearn(true)
- .build());
- }
- return new BridgeDomainsBuilder()
- .setBridgeDomain(bdmns)
- .build();
+ verifyBridgeDomainAddDel(Iterators.getOnlyElement(bdn1.getBridgeDomain().iterator()), bdId);
}
@Test
public void deleteVpp() throws Exception {
+ final String bdName = "bdn1";
+ final BridgeDomains bdn1 = getBridgeDomains(bdName);
+ final int bdId = 1;
+ whenBridgeDomainAddDelThen(0);
+ bdContext.addName(bdId, bdName);
+
rootRegistry.update(
InstanceIdentifier.create(Vpp.class),
- new VppBuilder().setBridgeDomains(getBridgeDomains("bdn1")).build(),
+ new VppBuilder().setBridgeDomains(bdn1).build(),
null,
ctx);
- final byte zero = (byte) 0;
-
- verify(api).bridgeDomainAddDel(1, zero, zero, zero, zero, zero, zero);
+ verifyBridgeDomainDeleteWasInvoked(bdId);
}
@Test
@@ -148,7 +202,10 @@ public class VppTest {
@Test
public void writeUpdate() throws Exception {
- final BridgeDomains domainsBefore = getBridgeDomains("bdn1");
+ final String bdName = "bdn1";
+ final int bdn1Id = 1;
+ bdContext.addName(bdn1Id, bdName);
+ final BridgeDomains domainsBefore = getBridgeDomains(bdName);
final BridgeDomain bdn1Before = domainsBefore.getBridgeDomain().get(0);
final BridgeDomain bdn1After = new BridgeDomainBuilder(bdn1Before).setFlood(!bdn1Before.isFlood()).build();
@@ -156,16 +213,16 @@ public class VppTest {
.setBridgeDomain(Collections.singletonList(bdn1After))
.build();
+ whenBridgeDomainAddDelThen(0);
+
rootRegistry.update(
InstanceIdentifier.create(Vpp.class),
new VppBuilder().setBridgeDomains(domainsBefore).build(),
new VppBuilder().setBridgeDomains(domainsAfter).build(),
ctx);
- final int bdn1Id = 1;
-
// bdn1 is created with negated flood value
- verify(api).bridgeDomainAddDel(bdn1Id, (byte) (flood ^ 1), forward, learn, uuf, arpTerm, add);
+ verifyBridgeDomainAddDel(bdn1After, bdn1Id);
}
// TODO test unkeyed list
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/vpp/VppUtils.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/vpp/VppUtils.java
index cb74314e3..4b3eb5adc 100644
--- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/vpp/VppUtils.java
+++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/vpp/VppUtils.java
@@ -19,10 +19,11 @@ package io.fd.honeycomb.v3po.translate.v3po.vpp;
import io.fd.honeycomb.v3po.translate.impl.write.CompositeChildWriter;
import io.fd.honeycomb.v3po.translate.impl.write.CompositeListWriter;
import io.fd.honeycomb.v3po.translate.impl.write.CompositeRootWriter;
+import io.fd.honeycomb.v3po.translate.util.RWUtils;
import io.fd.honeycomb.v3po.translate.util.write.NoopWriterCustomizer;
import io.fd.honeycomb.v3po.translate.util.write.ReflexiveChildWriterCustomizer;
+import io.fd.honeycomb.v3po.translate.v3po.util.NamingContext;
import io.fd.honeycomb.v3po.translate.write.ChildWriter;
-import io.fd.honeycomb.v3po.translate.util.RWUtils;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Nonnull;
@@ -31,7 +32,7 @@ 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.vpp.bridge.domains.BridgeDomain;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.bridge.domains.BridgeDomainKey;
import org.opendaylight.yangtools.yang.binding.ChildOf;
-import org.openvpp.vppjapi.vppApi;
+import org.openvpp.jvpp.future.FutureJVpp;
final class VppUtils {
@@ -40,11 +41,11 @@ final class VppUtils {
/**
* Create root Vpp writer with all its children wired
*/
- static CompositeRootWriter<Vpp> getVppWriter(@Nonnull final vppApi vppApi) {
+ static CompositeRootWriter<Vpp> getVppWriter(@Nonnull final FutureJVpp vppApi, final NamingContext bdContext) {
final CompositeListWriter<BridgeDomain, BridgeDomainKey> bridgeDomainWriter = new CompositeListWriter<>(
BridgeDomain.class,
- new BridgeDomainCustomizer(vppApi));
+ new BridgeDomainCustomizer(vppApi, bdContext));
final ChildWriter<BridgeDomains> bridgeDomainsReader = new CompositeChildWriter<>(
BridgeDomains.class,
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/vppstate/BridgeDomainCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/vppstate/BridgeDomainCustomizerTest.java
new file mode 100644
index 000000000..c482c4485
--- /dev/null
+++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/vppstate/BridgeDomainCustomizerTest.java
@@ -0,0 +1,59 @@
+/*
+ * 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.v3po.translate.v3po.vppstate;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+
+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 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");
+ interfacesContext = new NamingContext("generatedIfaceName");
+ }
+
+ @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 RootReaderCustomizer<BridgeDomain, BridgeDomainBuilder> initCustomizer() {
+ return new BridgeDomainCustomizer(api, bdContext, interfacesContext);
+ }
+} \ No newline at end of file
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/vppstate/VersionCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/vppstate/VersionCustomizerTest.java
new file mode 100644
index 000000000..03b923102
--- /dev/null
+++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/vppstate/VersionCustomizerTest.java
@@ -0,0 +1,73 @@
+/*
+ * 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.v3po.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.v3po.translate.spi.read.ChildReaderCustomizer;
+import io.fd.honeycomb.v3po.translate.v3po.test.ChildReaderCustomizerTest;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.CompletionStage;
+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 ChildReaderCustomizerTest<Version, VersionBuilder> {
+
+ public VersionCustomizerTest() {
+ super(Version.class);
+ }
+
+ @Override
+ protected ChildReaderCustomizer<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 CompletionStage<ShowVersionReply> replyCS = mock(CompletionStage.class);
+ final CompletableFuture<ShowVersionReply> replyFuture = mock(CompletableFuture.class);
+ when(replyCS.toCompletableFuture()).thenReturn(replyFuture);
+ final ShowVersionReply reply = new ShowVersionReply();
+ reply.retval = 0;
+ reply.version = new byte[]{};
+ reply.program = new byte[]{};
+ reply.buildDate = new byte[]{};
+ reply.buildDirectory = new byte[]{};
+ when(replyFuture.get()).thenReturn(reply);
+ when(api.showVersion(any(ShowVersion.class))).thenReturn(replyCS);
+
+ 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/v3po/translate/v3po/vppstate/VppStateTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/vppstate/VppStateTest.java
index 6f53f6519..bf1d12152 100644
--- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/vppstate/VppStateTest.java
+++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/vppstate/VppStateTest.java
@@ -19,27 +19,30 @@ package io.fd.honeycomb.v3po.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.anyString;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.doAnswer;
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.base.Predicate;
import com.google.common.collect.Iterables;
import com.google.common.collect.Multimap;
import io.fd.honeycomb.v3po.translate.impl.read.CompositeListReader;
import io.fd.honeycomb.v3po.translate.impl.read.CompositeRootReader;
-import io.fd.honeycomb.v3po.translate.util.read.DelegatingReaderRegistry;
import io.fd.honeycomb.v3po.translate.read.ReadContext;
import io.fd.honeycomb.v3po.translate.read.Reader;
+import io.fd.honeycomb.v3po.translate.util.read.DelegatingReaderRegistry;
+import io.fd.honeycomb.v3po.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.junit.runner.RunWith;
-import org.mockito.Matchers;
-import org.mockito.invocation.InvocationOnMock;
-import org.mockito.stubbing.Answer;
+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.VppStateBuilder;
@@ -53,131 +56,123 @@ 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.vpp.state.bridge.domains.bridge.domain.L2FibKey;
import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.openvpp.vppjapi.vppApi;
-import org.openvpp.vppjapi.vppBridgeDomainDetails;
-import org.openvpp.vppjapi.vppBridgeDomainInterfaceDetails;
-import org.openvpp.vppjapi.vppL2Fib;
-import org.openvpp.vppjapi.vppVersion;
-import org.powermock.api.mockito.PowerMockito;
-import org.powermock.core.classloader.annotations.PrepareForTest;
-import org.powermock.core.classloader.annotations.SuppressStaticInitializationFor;
-import org.powermock.modules.junit4.PowerMockRunner;
-
-@RunWith(PowerMockRunner.class)
-@SuppressStaticInitializationFor("org.openvpp.vppjapi.vppConn")
-@PrepareForTest(vppApi.class)
+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 {
- public static final vppVersion VERSION = new vppVersion("test", "1", "2", "33");
+ @Mock
+ private FutureJVpp api;
+ @Mock
+ private ReadContext ctx;
+
+ private NamingContext bdContext;
+ private NamingContext interfaceContext;
- private vppApi api;
private CompositeRootReader<VppState, VppStateBuilder> vppStateReader;
private DelegatingReaderRegistry readerRegistry;
- private vppBridgeDomainDetails bdDetails;
- private vppBridgeDomainDetails bdDetails2;
- private ReadContext ctx;
@Before
public void setUp() throws Exception {
- api = PowerMockito.mock(vppApi.class);
-
- ctx = mock(ReadContext.class);
-
- bdDetails = new vppBridgeDomainDetails();
- setIfcs(bdDetails);
- setBaseAttrs(bdDetails, "bdn1", 1);
-
- bdDetails2 = new vppBridgeDomainDetails();
- setIfcs(bdDetails2);
- setBaseAttrs(bdDetails2, "bdn2", 2);
-
- final vppL2Fib[] l2Fibs = getL2Fibs();
- PowerMockito.doReturn(l2Fibs).when(api).l2FibTableDump(Matchers.anyInt());
- PowerMockito.doAnswer(new Answer<vppBridgeDomainDetails>() {
-
- @Override
- public vppBridgeDomainDetails answer(final InvocationOnMock invocationOnMock) throws Throwable {
- final Integer idx = (Integer) invocationOnMock.getArguments()[0];
- switch (idx) {
- case 1 : return bdDetails;
- case 2 : return bdDetails2;
- default: return null;
- }
- }
- }).when(api).getBridgeDomainDetails(Matchers.anyInt());
-
- PowerMockito.doAnswer(new Answer<Object>() {
- @Override
- public Object answer(final InvocationOnMock invocationOnMock) throws Throwable {
- final String name = (String) invocationOnMock.getArguments()[0];
- switch (name) {
- case "bdn1" : return 1;
- case "bdn2" : return 2;
- default: return null;
- }
- }
- }).when(api).bridgeDomainIdFromName(anyString());
- PowerMockito.doReturn(new int[] {1, 2}).when(api).bridgeDomainDump(Matchers.anyInt());
- PowerMockito.doReturn(VERSION).when(api).getVppVersion();
- vppStateReader = VppStateUtils.getVppStateReader(api);
+ initMocks(this);
+
+ bdContext = new NamingContext("generatedBdName");
+ interfaceContext = new NamingContext("generatedInterfaceName");
+ vppStateReader = VppStateTestUtils.getVppStateReader(api, bdContext, interfaceContext);
readerRegistry = new DelegatingReaderRegistry(Collections.<Reader<? extends DataObject>>singletonList(vppStateReader));
}
- private vppL2Fib[] getL2Fibs() {
- return new vppL2Fib[] {
- new vppL2Fib(new byte[]{1,2,3,4,5,6}, true, "ifc1", true, true),
- new vppL2Fib(new byte[]{2,2,3,4,5,6}, true, "ifc2", true, true),
- };
+ private static Version getVersion() {
+ return new VersionBuilder()
+ .setName("test")
+ .setBuildDirectory("1")
+ .setBranch("2")
+ .setBuildDate("3")
+ .build();
}
- private void setIfcs(final vppBridgeDomainDetails bdDetails) {
- final vppBridgeDomainInterfaceDetails ifcDetails = new vppBridgeDomainInterfaceDetails();
- ifcDetails.interfaceName = "ifc";
- ifcDetails.splitHorizonGroup = 2;
- bdDetails.interfaces = new vppBridgeDomainInterfaceDetails[] {ifcDetails};
+ private void whenShowVersionThenReturn(int retval, Version version) throws ExecutionException, InterruptedException {
+ final CompletionStage<ShowVersionReply> replyCS = mock(CompletionStage.class);
+ final CompletableFuture<ShowVersionReply> replyFuture = mock(CompletableFuture.class);
+ when(replyCS.toCompletableFuture()).thenReturn(replyFuture);
+ final ShowVersionReply reply = new ShowVersionReply();
+ reply.retval = 0; // success
+ reply.buildDate = version.getBuildDate().getBytes();
+ reply.program = version.getName().getBytes();
+ reply.version = version.getBranch().getBytes();
+ reply.buildDirectory = version.getBuildDirectory().getBytes();
+ when(replyFuture.get()).thenReturn(reply);
+ when(api.showVersion(any(ShowVersion.class))).thenReturn(replyCS);
}
- private void setBaseAttrs(final vppBridgeDomainDetails bdDetails, final String bdn, final int i) {
- bdDetails.name = bdn;
- bdDetails.arpTerm = true;
- bdDetails.bdId = i;
- bdDetails.bviInterfaceName = "ifc";
- bdDetails.flood = true;
- bdDetails.forward = true;
- bdDetails.learn = true;
- bdDetails.uuFlood = true;
+ private void whenL2FibTableDumpThenReturn(final List<L2FibTableEntry> entryList) throws ExecutionException, InterruptedException {
+ 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 {
+ 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 List<BridgeDomainDetails> bdList = Arrays.asList(new BridgeDomainDetails(), new BridgeDomainDetails());
+ whenBridgeDomainDumpThenReturn(bdList);
+
final Multimap<InstanceIdentifier<? extends DataObject>, ? extends DataObject> dataObjects = readerRegistry.readAll(ctx);
assertEquals(dataObjects.size(), 1);
- final DataObject dataObject = Iterables.getOnlyElement(dataObjects.get(Iterables.getOnlyElement(dataObjects.keySet())));
- assertTrue(dataObject instanceof VppState);
- assertVersion((VppState) dataObject);
- assertEquals(2, ((VppState) dataObject).getBridgeDomains().getBridgeDomain().size());
- }
-
- private void assertVersion(final VppState dataObject) {
- assertEquals(
- new VersionBuilder()
- .setName("test")
- .setBuildDirectory("1")
- .setBranch("2")
- .setBuildDate("33")
- .build(),
- dataObject.getVersion());
+ 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());
- assertVersion((VppState) read.get());
+ assertEquals(version, ((VppState) read.get()).getVersion());
}
@Test
public void testReadBridgeDomains() throws Exception {
+ final Version version = getVersion();
+ whenShowVersionThenReturn(0, version);
+ whenBridgeDomainDumpThenReturn(Collections.singletonList(new BridgeDomainDetails()));
+
VppState readRoot = (VppState) readerRegistry.read(InstanceIdentifier.create(VppState.class), ctx).get();
Optional<? extends DataObject> read =
@@ -191,6 +186,16 @@ public class VppStateTest {
*/
@Test
public void testReadL2Fib() throws Exception {
+ final BridgeDomainDetails bd = new BridgeDomainDetails();
+ bd.bdId = 0;
+ final String bdName = "bdn1";
+ bdContext.addName(bd.bdId, bdName);
+ 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
Optional<? extends DataObject> read =
readerRegistry.read(InstanceIdentifier.create(VppState.class).child(BridgeDomains.class).child(
@@ -208,10 +213,14 @@ public class VppStateTest {
@Test
public void testReadBridgeDomainAll() throws Exception {
+ final Version version = getVersion();
+ whenShowVersionThenReturn(0, version);
+ whenBridgeDomainDumpThenReturn(Collections.singletonList(new BridgeDomainDetails()));
+
VppState readRoot = (VppState) readerRegistry.read(InstanceIdentifier.create(VppState.class), ctx).get();
final CompositeListReader<BridgeDomain, BridgeDomainKey, BridgeDomainBuilder> bridgeDomainReader =
- VppStateUtils.getBridgeDomainReader(api);
+ VppStateTestUtils.getBridgeDomainReader(api, bdContext, interfaceContext);
final List<BridgeDomain> read =
bridgeDomainReader.readList(InstanceIdentifier.create(VppState.class).child(BridgeDomains.class).child(
@@ -222,24 +231,25 @@ public class VppStateTest {
@Test
public void testReadBridgeDomain() throws Exception {
+ final BridgeDomainDetails bd = new BridgeDomainDetails();
+ bd.bdId = 0;
+ final String bdName = "bdn1";
+ bdContext.addName(bd.bdId, 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("bdn1")), ctx);
+ BridgeDomain.class, new BridgeDomainKey(bdName)), ctx);
assertTrue(read.isPresent());
- assertEquals(Iterables.find(readRoot.getBridgeDomains().getBridgeDomain(), new Predicate<BridgeDomain>() {
- @Override
- public boolean apply(final BridgeDomain input) {
- return input.getKey().getName().equals("bdn1");
- }
- }), read.get());
+ assertEquals(Iterables.find(readRoot.getBridgeDomains().getBridgeDomain(),
+ input -> input.getKey().getName().equals(bdName)), read.get());
}
- // FIXME
- @Ignore("Bridge domain customizer does not check whether the bd exists or not and fails with NPE, add it there")
- @Test
+ @Test(expected = IllegalArgumentException.class)
public void testReadBridgeDomainNotExisting() throws Exception {
final Optional<? extends DataObject> read =
readerRegistry.read(InstanceIdentifier.create(VppState.class).child(BridgeDomains.class).child(
@@ -249,6 +259,8 @@ public class VppStateTest {
@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 =
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/vppstate/VppStateUtils.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/vppstate/VppStateTestUtils.java
index 5c619d84d..688f75911 100644
--- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/vppstate/VppStateUtils.java
+++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/vppstate/VppStateTestUtils.java
@@ -19,10 +19,11 @@ package io.fd.honeycomb.v3po.translate.v3po.vppstate;
import io.fd.honeycomb.v3po.translate.impl.read.CompositeChildReader;
import io.fd.honeycomb.v3po.translate.impl.read.CompositeListReader;
import io.fd.honeycomb.v3po.translate.impl.read.CompositeRootReader;
+import io.fd.honeycomb.v3po.translate.read.ChildReader;
+import io.fd.honeycomb.v3po.translate.util.RWUtils;
import io.fd.honeycomb.v3po.translate.util.read.ReflexiveChildReaderCustomizer;
import io.fd.honeycomb.v3po.translate.util.read.ReflexiveRootReaderCustomizer;
-import io.fd.honeycomb.v3po.translate.util.RWUtils;
-import io.fd.honeycomb.v3po.translate.read.ChildReader;
+import io.fd.honeycomb.v3po.translate.v3po.util.NamingContext;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Nonnull;
@@ -35,43 +36,47 @@ 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.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.ChildOf;
-import org.openvpp.vppjapi.vppApi;
+import org.openvpp.jvpp.future.FutureJVpp;
-final class VppStateUtils {
+final class VppStateTestUtils {
- public VppStateUtils() {}
+ public VppStateTestUtils() {
+ }
/**
* Create root VppState reader with all its children wired
*/
- static CompositeRootReader<VppState, VppStateBuilder> getVppStateReader(@Nonnull final vppApi vppApi) {
+ static CompositeRootReader<VppState, VppStateBuilder> getVppStateReader(@Nonnull final FutureJVpp futureJVpp,
+ @Nonnull final NamingContext bdContext,
+ @Nonnull final NamingContext interfaceContext) {
final ChildReader<Version> versionReader = new CompositeChildReader<>(
- Version.class, new VersionCustomizer(vppApi));
+ Version.class, new VersionCustomizer(futureJVpp));
final CompositeListReader<BridgeDomain, BridgeDomainKey, BridgeDomainBuilder> bridgeDomainReader =
- getBridgeDomainReader(vppApi);
+ getBridgeDomainReader(futureJVpp, bdContext, interfaceContext);
final ChildReader<BridgeDomains> bridgeDomainsReader = new CompositeChildReader<>(
- BridgeDomains.class,
- RWUtils.singletonChildReaderList(bridgeDomainReader),
- new ReflexiveChildReaderCustomizer<>(BridgeDomainsBuilder.class));
+ BridgeDomains.class,
+ RWUtils.singletonChildReaderList(bridgeDomainReader),
+ new ReflexiveChildReaderCustomizer<>(BridgeDomainsBuilder.class));
final List<ChildReader<? extends ChildOf<VppState>>> childVppReaders = new ArrayList<>();
childVppReaders.add(versionReader);
childVppReaders.add(bridgeDomainsReader);
return new CompositeRootReader<>(
- VppState.class,
- childVppReaders,
- RWUtils.<VppState>emptyAugReaderList(),
- new ReflexiveRootReaderCustomizer<>(VppStateBuilder.class));
+ VppState.class,
+ childVppReaders,
+ RWUtils.<VppState>emptyAugReaderList(),
+ new ReflexiveRootReaderCustomizer<>(VppStateBuilder.class));
}
static CompositeListReader<BridgeDomain, BridgeDomainKey, BridgeDomainBuilder> getBridgeDomainReader(
- final @Nonnull vppApi vppApi) {
+ final @Nonnull FutureJVpp futureJVpp, @Nonnull final NamingContext bdContext,
+ @Nonnull final NamingContext interfaceContext) {
return new CompositeListReader<>(
- BridgeDomain.class,
- new BridgeDomainCustomizer(vppApi));
+ BridgeDomain.class,
+ new BridgeDomainCustomizer(futureJVpp, bdContext, interfaceContext));
}
}