From 4f7fb7f2e12687d42a6ae287531bb788636a8bc6 Mon Sep 17 00:00:00 2001 From: Marek Gradzki Date: Thu, 2 Jun 2016 18:13:41 +0200 Subject: Updated tests for new vlan model Change-Id: I2982d52a7d8e319b9b6ed1be5d312296ef843599 Signed-off-by: Marek Gradzki --- .../v3po/translate/v3po/ContextTestUtils.java | 40 -- .../v3po/interfaces/RewriteCustomizerTest.java | 232 ++++++++++ .../interfaces/SubInterfaceCustomizerTest.java | 492 ++++++++++++--------- .../v3po/interfaces/TapCustomizerTest.java | 4 +- .../v3po/interfaces/VhostUserCustomizerTest.java | 4 +- .../interfaces/VlanTagRewriteCustomizerTest.java | 239 ---------- .../v3po/interfaces/VxlanCustomizerTest.java | 4 +- .../v3po/interfaces/VxlanGpeCustomizerTest.java | 4 +- .../interfacesstate/InterfaceCustomizerTest.java | 28 +- .../v3po/interfacesstate/L2CustomizerTest.java | 4 +- .../interfacesstate/RewriteCustomizerTest.java | 127 ++++++ .../SubInterfaceCustomizerTest.java | 268 +++++------ .../VlanTagRewriteCustomizerTest.java | 102 ----- .../v3po/interfacesstate/VxlanCustomizerTest.java | 4 +- .../interfacesstate/VxlanGpeCustomizerTest.java | 4 +- .../v3po/translate/v3po/test/ContextTestUtils.java | 40 ++ .../translate/v3po/test/InterfaceTestUtils.java | 47 ++ .../v3po/vpp/BridgeDomainCustomizerTest.java | 4 +- .../honeycomb/v3po/translate/v3po/vpp/VppTest.java | 4 +- .../v3po/translate/v3po/vppstate/VppStateTest.java | 4 +- 20 files changed, 912 insertions(+), 743 deletions(-) delete mode 100644 v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/ContextTestUtils.java create mode 100644 v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/RewriteCustomizerTest.java delete mode 100644 v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/VlanTagRewriteCustomizerTest.java create mode 100644 v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfacesstate/RewriteCustomizerTest.java delete mode 100644 v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfacesstate/VlanTagRewriteCustomizerTest.java create mode 100644 v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/test/ContextTestUtils.java create mode 100644 v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/test/InterfaceTestUtils.java diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/ContextTestUtils.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/ContextTestUtils.java deleted file mode 100644 index 5c731bcb5..000000000 --- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/ContextTestUtils.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * 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; - -import com.google.common.base.Optional; -import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.Contexts; -import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.contexts.NamingContextKey; -import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.contexts.naming.context.Mappings; -import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.contexts.naming.context.mappings.Mapping; -import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.contexts.naming.context.mappings.MappingBuilder; -import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.contexts.naming.context.mappings.MappingKey; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier; - -public class ContextTestUtils { - - public static Optional getMapping(final String name, final int index) { - return Optional.of(new MappingBuilder().setName(name).setIndex(index).build()); - } - - public static KeyedInstanceIdentifier getMappingIid(final String name, final String namingContextName) { - return InstanceIdentifier.create(Contexts.class).child( - org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.contexts.NamingContext.class, - new NamingContextKey(namingContextName)).child(Mappings.class).child(Mapping.class, new MappingKey(name)); - } -} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/RewriteCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/RewriteCustomizerTest.java new file mode 100644 index 000000000..068f9147e --- /dev/null +++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/RewriteCustomizerTest.java @@ -0,0 +1,232 @@ +/* + * 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.interfaces; + +import static io.fd.honeycomb.v3po.translate.v3po.test.ContextTestUtils.getMapping; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.verify; +import static org.mockito.MockitoAnnotations.initMocks; + +import com.google.common.base.Optional; +import io.fd.honeycomb.v3po.translate.MappingContext; +import io.fd.honeycomb.v3po.translate.v3po.util.NamingContext; +import io.fd.honeycomb.v3po.translate.v3po.util.TagRewriteOperation; +import io.fd.honeycomb.v3po.translate.v3po.util.VppApiInvocationException; +import io.fd.honeycomb.v3po.translate.write.WriteContext; +import io.fd.honeycomb.v3po.translate.write.WriteFailedException; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutionException; +import org.junit.Before; +import org.junit.Test; +import org.mockito.ArgumentCaptor; +import org.mockito.Mock; +import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.contexts.naming.context.mappings.Mapping; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.SubinterfaceAugmentation; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527._802dot1q; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.interfaces._interface.SubInterfaces; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.interfaces._interface.sub.interfaces.SubInterface; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.interfaces._interface.sub.interfaces.SubInterfaceKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.sub._interface.base.attributes.l2.Rewrite; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.sub._interface.base.attributes.l2.RewriteBuilder; +import org.opendaylight.yangtools.yang.binding.ChildOf; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.openvpp.jvpp.dto.L2InterfaceVlanTagRewrite; +import org.openvpp.jvpp.dto.L2InterfaceVlanTagRewriteReply; +import org.openvpp.jvpp.future.FutureJVpp; + +public class RewriteCustomizerTest { + + @Mock + private FutureJVpp api; + @Mock + private WriteContext writeContext; + @Mock + private MappingContext mappingContext; + + private NamingContext namingContext; + private RewriteCustomizer customizer; + + public static final String VLAN_IF_NAME = "local0.1"; + public static final int VLAN_IF_ID = 1; + public static final int VLAN_IF_INDEX = 11; + + @Before + public void setUp() throws Exception { + initMocks(this); + namingContext = new NamingContext("generatedSubInterfaceName", "test-instance"); + doReturn(mappingContext).when(writeContext).getMappingContext(); + customizer = new RewriteCustomizer(api, namingContext); + + final Optional ifcMapping = getMapping(VLAN_IF_NAME, VLAN_IF_INDEX); + doReturn(ifcMapping).when(mappingContext).read(any()); + } + + private InstanceIdentifier getVlanTagRewriteId(final String name, final long index) { + final Class> child = (Class)Rewrite.class; + final InstanceIdentifier id = + InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(name)).augmentation( + SubinterfaceAugmentation.class).child(SubInterfaces.class) + .child(SubInterface.class, new SubInterfaceKey(index)) + .child(child); + return id; + } + + private Rewrite generateRewrite(final TagRewriteOperation op) { + final RewriteBuilder builder = new RewriteBuilder(); + builder.setPopTags((short) op.getPopTags()); + builder.setVlanType(_802dot1q.class); + return builder.build(); + } + + private L2InterfaceVlanTagRewrite generateL2InterfaceVlanTagRewrite(final int swIfIndex, final TagRewriteOperation op) { + final L2InterfaceVlanTagRewrite request = new L2InterfaceVlanTagRewrite(); + request.swIfIndex = swIfIndex; + request.vtrOp = op.ordinal(); + request.pushDot1Q = 1; + return request; + } + + private void whenL2InterfaceVlanTagRewriteThen(final int retval) throws ExecutionException, InterruptedException { + final CompletableFuture replyFuture = new CompletableFuture<>(); + final L2InterfaceVlanTagRewriteReply reply = new L2InterfaceVlanTagRewriteReply(); + reply.retval = retval; + replyFuture.complete(reply); + doReturn(replyFuture).when(api).l2InterfaceVlanTagRewrite(any(L2InterfaceVlanTagRewrite.class)); + } + + private void whenL2InterfaceVlanTagRewriteThenSuccess() throws ExecutionException, InterruptedException { + whenL2InterfaceVlanTagRewriteThen(0); + } + + private void whenL2InterfaceVlanTagRewriteThenFailure() throws ExecutionException, InterruptedException { + whenL2InterfaceVlanTagRewriteThen(-1); + } + + private void verifyL2InterfaceVlanTagRewriteWasInvoked(final L2InterfaceVlanTagRewrite expected) { + ArgumentCaptor argumentCaptor = ArgumentCaptor.forClass(L2InterfaceVlanTagRewrite.class); + verify(api).l2InterfaceVlanTagRewrite(argumentCaptor.capture()); + final L2InterfaceVlanTagRewrite actual = argumentCaptor.getValue(); + assertEquals(expected.swIfIndex, actual.swIfIndex); + assertEquals(expected.vtrOp, actual.vtrOp); + assertEquals(expected.pushDot1Q, actual.pushDot1Q); + assertEquals(expected.tag1, actual.tag1); + assertEquals(expected.tag2, actual.tag2); + } + + private void verifyL2InterfaceVlanTagRewriteDeleteWasInvoked() { + final L2InterfaceVlanTagRewrite request = new L2InterfaceVlanTagRewrite(); + request.swIfIndex = VLAN_IF_INDEX; + verifyL2InterfaceVlanTagRewriteWasInvoked(request); + } + + @Test + public void testCreate() throws Exception { + final TagRewriteOperation op = TagRewriteOperation.pop_2; + final Rewrite vlanTagRewrite = generateRewrite(op); + final InstanceIdentifier id = getVlanTagRewriteId(VLAN_IF_NAME, VLAN_IF_ID); + + whenL2InterfaceVlanTagRewriteThenSuccess(); + + customizer.writeCurrentAttributes(id, vlanTagRewrite, writeContext); + + verifyL2InterfaceVlanTagRewriteWasInvoked(generateL2InterfaceVlanTagRewrite(VLAN_IF_INDEX, op)); + } + + @Test + public void testCreateFailed() throws Exception { + final TagRewriteOperation op = TagRewriteOperation.pop_2; + final Rewrite vlanTagRewrite = generateRewrite(op); + final String subIfaceName = "local0.11"; + final int subifIndex = 1; + final InstanceIdentifier id = getVlanTagRewriteId(subIfaceName, subifIndex); + + whenL2InterfaceVlanTagRewriteThenFailure(); + + try { + customizer.writeCurrentAttributes(id, vlanTagRewrite, writeContext); + } catch (WriteFailedException.CreateFailedException e) { + assertEquals(VppApiInvocationException.class, e.getCause().getClass()); + verifyL2InterfaceVlanTagRewriteWasInvoked(generateL2InterfaceVlanTagRewrite(VLAN_IF_INDEX, op)); + return; + } + fail("WriteFailedException.CreateFailedException was expected"); + } + + @Test + public void testUpdate() throws Exception { + final Rewrite before = generateRewrite(TagRewriteOperation.pop_2); + final Rewrite after = generateRewrite(TagRewriteOperation.pop_1); + final InstanceIdentifier id = getVlanTagRewriteId(VLAN_IF_NAME, VLAN_IF_ID); + + whenL2InterfaceVlanTagRewriteThenSuccess(); + + customizer.updateCurrentAttributes(id, before, after, writeContext); + + verifyL2InterfaceVlanTagRewriteWasInvoked(generateL2InterfaceVlanTagRewrite(VLAN_IF_INDEX, TagRewriteOperation.pop_1)); + } + + @Test + public void testUpdateFailed() throws Exception { + final Rewrite before = generateRewrite(TagRewriteOperation.pop_2); + final Rewrite after = generateRewrite(TagRewriteOperation.pop_1); + final InstanceIdentifier id = getVlanTagRewriteId(VLAN_IF_NAME, VLAN_IF_ID); + + whenL2InterfaceVlanTagRewriteThenFailure(); + + try { + customizer.updateCurrentAttributes(id, before, after, writeContext); + } catch (WriteFailedException.UpdateFailedException e) { + assertEquals(VppApiInvocationException.class, e.getCause().getClass()); + verifyL2InterfaceVlanTagRewriteWasInvoked(generateL2InterfaceVlanTagRewrite(VLAN_IF_INDEX, TagRewriteOperation.pop_1)); + return; + } + fail("WriteFailedException.UpdateFailedException was expected"); + } + + @Test + public void testDelete() throws Exception { + final InstanceIdentifier id = getVlanTagRewriteId(VLAN_IF_NAME, VLAN_IF_ID); + + whenL2InterfaceVlanTagRewriteThenSuccess(); + + customizer.deleteCurrentAttributes(id, null, writeContext); + + verifyL2InterfaceVlanTagRewriteDeleteWasInvoked(); + } + + @Test + public void testDeleteFailed() throws Exception { + final InstanceIdentifier id = getVlanTagRewriteId(VLAN_IF_NAME, VLAN_IF_ID); + + whenL2InterfaceVlanTagRewriteThenFailure(); + + try { + customizer.deleteCurrentAttributes(id, null, writeContext); + } catch (WriteFailedException.DeleteFailedException e) { + assertEquals(VppApiInvocationException.class, e.getCause().getClass()); + verifyL2InterfaceVlanTagRewriteDeleteWasInvoked(); + return; + } + fail("WriteFailedException.DeleteFailedException was expected"); + } +} \ No newline at end of file diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/SubInterfaceCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/SubInterfaceCustomizerTest.java index 4fdb92759..a97e43697 100644 --- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/SubInterfaceCustomizerTest.java +++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/SubInterfaceCustomizerTest.java @@ -1,198 +1,294 @@ -// FIXME new vlan model -///* -// * 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.interfaces; -// -//import static io.fd.honeycomb.v3po.translate.v3po.ContextTestUtils.getMapping; -//import static io.fd.honeycomb.v3po.translate.v3po.ContextTestUtils.getMappingIid; -//import static org.junit.Assert.assertEquals; -//import static org.junit.Assert.fail; -//import static org.mockito.Matchers.any; -//import static org.mockito.Matchers.eq; -//import static org.mockito.Mockito.doReturn; -//import static org.mockito.Mockito.times; -//import static org.mockito.Mockito.verify; -//import static org.mockito.MockitoAnnotations.initMocks; -// -//import io.fd.honeycomb.v3po.translate.MappingContext; -//import io.fd.honeycomb.v3po.translate.v3po.util.NamingContext; -//import io.fd.honeycomb.v3po.translate.v3po.util.VppApiInvocationException; -//import io.fd.honeycomb.v3po.translate.write.WriteContext; -//import io.fd.honeycomb.v3po.translate.write.WriteFailedException; -//import java.util.concurrent.CompletableFuture; -//import java.util.concurrent.ExecutionException; -//import org.junit.Before; -//import org.junit.Test; -//import org.mockito.ArgumentCaptor; -//import org.mockito.Mock; -//import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces; -//import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface; -//import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceKey; -//import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VlanTag; -//import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VlanType; -//import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VppInterfaceAugmentation; -//import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces._interface.SubInterface; -//import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces._interface.SubInterfaceBuilder; -//import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -//import org.openvpp.jvpp.dto.CreateSubif; -//import org.openvpp.jvpp.dto.CreateSubifReply; -//import org.openvpp.jvpp.future.FutureJVpp; -// -//public class SubInterfaceCustomizerTest { -// -// @Mock -// private FutureJVpp api; -// @Mock -// private WriteContext writeContext; -// @Mock -// private MappingContext mappingContext; -// -// private NamingContext namingContext; -// private SubInterfaceCustomizer customizer; -// public static final String SUPER_IF_NAME = "local0"; -// public static final int SUPER_IF_ID = 1; -// -// @Before -// public void setUp() throws Exception { -// initMocks(this); -// InterfaceTypeTestUtils.setupWriteContext(writeContext, -// org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.SubInterface.class); -// namingContext = new NamingContext("generatedSubInterfaceName", "test-instance"); -// doReturn(mappingContext).when(writeContext).getMappingContext(); -// // TODO create base class for tests using vppApi -// customizer = new SubInterfaceCustomizer(api, namingContext); -// doReturn(getMapping(SUPER_IF_NAME, SUPER_IF_ID)).when(mappingContext).read(getMappingIid(SUPER_IF_NAME, "test-instance")); -// } -// -// private SubInterface generateSubInterface(final String superIfName) { -// SubInterfaceBuilder builder = new SubInterfaceBuilder(); -// builder.setVlanType(VlanType._802dot1ad); -// builder.setIdentifier(11L); -// builder.setNumberOfTags((short)1); -// builder.setOuterId(new VlanTag(100)); -// builder.setInnerId(new VlanTag(200)); -// builder.setSuperInterface(superIfName); -// return builder.build(); -// } -// -// private CreateSubif generateSubInterfaceRequest(final int superIfId) { -// CreateSubif request = new CreateSubif(); -// request.subId = 11; -// request.swIfIndex = superIfId; -// request.oneTag = 1; -// request.dot1Ad = 1; -// request.outerVlanId = 100; -// request.innerVlanId = 200; -// return request; -// } -// -// private InstanceIdentifier getSubInterfaceId(final String name) { -// return InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(name)).augmentation( -// VppInterfaceAugmentation.class).child(SubInterface.class); -// } -// -// private void whenCreateSubifThen(final int retval) throws ExecutionException, InterruptedException { -// final CompletableFuture replyFuture = new CompletableFuture<>(); -// final CreateSubifReply reply = new CreateSubifReply(); -// reply.retval = retval; -// replyFuture.complete(reply); -// doReturn(replyFuture).when(api).createSubif(any(CreateSubif.class)); -// } -// -// private void whenCreateSubifThenSuccess() throws ExecutionException, InterruptedException { -// whenCreateSubifThen(0); -// } -// -// private void whenCreateSubifThenFailure() throws ExecutionException, InterruptedException { -// whenCreateSubifThen(-1); -// } -// -// private CreateSubif verifyCreateSubifWasInvoked(final CreateSubif expected) { -// ArgumentCaptor argumentCaptor = ArgumentCaptor.forClass(CreateSubif.class); -// verify(api).createSubif(argumentCaptor.capture()); -// final CreateSubif actual = argumentCaptor.getValue(); -// -// assertEquals(expected.swIfIndex, actual.swIfIndex); -// assertEquals(expected.subId, actual.subId); -// assertEquals(expected.noTags, actual.noTags); -// assertEquals(expected.oneTag, actual.oneTag); -// assertEquals(expected.twoTags, actual.twoTags); -// assertEquals(expected.dot1Ad, actual.dot1Ad); -// assertEquals(expected.exactMatch, actual.exactMatch); -// assertEquals(expected.defaultSub, actual.defaultSub); -// assertEquals(expected.outerVlanIdAny, actual.outerVlanIdAny); -// assertEquals(expected.innerVlanIdAny, actual.innerVlanIdAny); -// assertEquals(expected.outerVlanId, actual.outerVlanId); -// assertEquals(expected.innerVlanId, actual.innerVlanId); -// return actual; -// } -// -// @Test -// public void testCreate() throws Exception { -// final SubInterface subInterface = generateSubInterface(SUPER_IF_NAME); -// final String subIfaceName = "local0.sub1"; -// final InstanceIdentifier id = getSubInterfaceId(subIfaceName); -// -// whenCreateSubifThenSuccess(); -// -// customizer.writeCurrentAttributes(id, subInterface, writeContext); -// -// verifyCreateSubifWasInvoked(generateSubInterfaceRequest(SUPER_IF_ID)); -// verify(mappingContext).put(eq(getMappingIid(subIfaceName, "test-instance")), eq(getMapping(subIfaceName, 0).get())); -// } -// -// @Test -// public void testCreateFailed() throws Exception { -// final SubInterface subInterface = generateSubInterface(SUPER_IF_NAME); -// final String subIfaceName = "local0.sub1"; -// final InstanceIdentifier id = getSubInterfaceId(subIfaceName); -// -// whenCreateSubifThenFailure(); -// -// try { -// customizer.writeCurrentAttributes(id, subInterface, writeContext); -// } catch (WriteFailedException.CreateFailedException e) { -// assertEquals(VppApiInvocationException.class, e.getCause().getClass()); -// verifyCreateSubifWasInvoked(generateSubInterfaceRequest(SUPER_IF_ID)); -// verify(mappingContext, times(0)).put( -// eq(getMappingIid(subIfaceName, "test-instance")), -// eq(getMapping(subIfaceName, 0).get())); -// return; -// } -// fail("WriteFailedException.CreateFailedException was expected"); -// } -// -// @Test -// public void testUpdateNoChange() throws Exception { -// final SubInterface before = generateSubInterface(SUPER_IF_NAME); -// final SubInterface after = generateSubInterface(SUPER_IF_NAME); -// customizer.updateCurrentAttributes(null, before, after, writeContext); -// } -// -// @Test(expected = UnsupportedOperationException.class) -// public void testUpdate() throws Exception { -// final SubInterface before = generateSubInterface("eth0"); -// final SubInterface after = generateSubInterface("eth1"); -// customizer.updateCurrentAttributes(null, before, after, writeContext); -// } -// -// @Test(expected = UnsupportedOperationException.class) -// public void testDelete() throws Exception { -// final SubInterface subInterface = generateSubInterface("eth0"); -// customizer.deleteCurrentAttributes(null, subInterface, writeContext); -// } -//} \ No newline at end of file +/* + * 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.interfaces; + +import static io.fd.honeycomb.v3po.translate.v3po.test.ContextTestUtils.getMapping; +import static io.fd.honeycomb.v3po.translate.v3po.test.ContextTestUtils.getMappingIid; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.MockitoAnnotations.initMocks; + +import com.google.common.base.Optional; +import io.fd.honeycomb.v3po.translate.MappingContext; +import io.fd.honeycomb.v3po.translate.v3po.util.NamingContext; +import io.fd.honeycomb.v3po.translate.v3po.util.VppApiInvocationException; +import io.fd.honeycomb.v3po.translate.write.WriteContext; +import io.fd.honeycomb.v3po.translate.write.WriteFailedException; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutionException; +import org.junit.Before; +import org.junit.Test; +import org.mockito.ArgumentCaptor; +import org.mockito.Mock; +import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.contexts.naming.context.mappings.Mapping; +import org.opendaylight.yang.gen.v1.urn.ieee.params.xml.ns.yang.dot1q.types.rev150626.CVlan; +import org.opendaylight.yang.gen.v1.urn.ieee.params.xml.ns.yang.dot1q.types.rev150626.Dot1qTagVlanType; +import org.opendaylight.yang.gen.v1.urn.ieee.params.xml.ns.yang.dot1q.types.rev150626.Dot1qVlanId; +import org.opendaylight.yang.gen.v1.urn.ieee.params.xml.ns.yang.dot1q.types.rev150626.SVlan; +import org.opendaylight.yang.gen.v1.urn.ieee.params.xml.ns.yang.dot1q.types.rev150626.dot1q.tag.or.any.Dot1qTag; +import org.opendaylight.yang.gen.v1.urn.ieee.params.xml.ns.yang.dot1q.types.rev150626.dot1q.tag.or.any.Dot1qTagBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.SubinterfaceAugmentation; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527._802dot1ad; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.interfaces._interface.SubInterfaces; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.interfaces._interface.sub.interfaces.SubInterface; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.interfaces._interface.sub.interfaces.SubInterfaceBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.interfaces._interface.sub.interfaces.SubInterfaceKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.match.attributes.match.type.vlan.tagged.VlanTaggedBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.sub._interface.base.attributes.Match; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.sub._interface.base.attributes.MatchBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.sub._interface.base.attributes.TagsBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.sub._interface.base.attributes.tags.Tag; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.sub._interface.base.attributes.tags.TagBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.sub._interface.base.attributes.tags.TagKey; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.openvpp.jvpp.dto.CreateSubif; +import org.openvpp.jvpp.dto.CreateSubifReply; +import org.openvpp.jvpp.dto.SwInterfaceSetFlags; +import org.openvpp.jvpp.dto.SwInterfaceSetFlagsReply; +import org.openvpp.jvpp.future.FutureJVpp; + +public class SubInterfaceCustomizerTest { + + @Mock + private FutureJVpp api; + @Mock + private WriteContext writeContext; + @Mock + private MappingContext mappingContext; + + private NamingContext namingContext; + private SubInterfaceCustomizer customizer; + public static final String SUPER_IF_NAME = "local0"; + public static final int SUPER_IF_ID = 1; + + @Before + public void setUp() throws Exception { + initMocks(this); + namingContext = new NamingContext("generatedSubInterfaceName", "test-instance"); + doReturn(mappingContext).when(writeContext).getMappingContext(); + // TODO create base class for tests using vppApi + customizer = new SubInterfaceCustomizer(api, namingContext); + doReturn(getMapping(SUPER_IF_NAME, SUPER_IF_ID)).when(mappingContext) + .read(getMappingIid(SUPER_IF_NAME, "test-instance")); + } + + private SubInterface generateSubInterface(final String superIfName, final boolean enabled) { + SubInterfaceBuilder builder = new SubInterfaceBuilder(); + builder.setVlanType(_802dot1ad.class); + builder.setIdentifier(11L); + final TagsBuilder tags = new TagsBuilder(); + final List list = new ArrayList<>(); + list.add(generateTag((short) 0, SVlan.class, new Dot1qTag.VlanId(new Dot1qVlanId(100)))); + list.add(generateTag((short) 1, CVlan.class, new Dot1qTag.VlanId(new Dot1qVlanId(200)))); + + tags.setTag(list); + + builder.setTags(tags.build()); + + builder.setMatch(generateMatch()); + builder.setEnabled(enabled); + return builder.build(); + } + + private static Tag generateTag(final short index, final Class tagType, + final Dot1qTag.VlanId vlanId) { + TagBuilder tag = new TagBuilder(); + tag.setIndex(index); + tag.setKey(new TagKey(index)); + final Dot1qTagBuilder dtag = new Dot1qTagBuilder(); + dtag.setTagType(tagType); + dtag.setVlanId(vlanId); + tag.setDot1qTag(dtag.build()); + return tag.build(); + } + + private static Match generateMatch() { + final MatchBuilder match = new MatchBuilder(); + final VlanTaggedBuilder tagged = new VlanTaggedBuilder(); + tagged.setMatchExactTags(true); + match.setMatchType( + new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.match.attributes.match.type.VlanTaggedBuilder() + .setVlanTagged(tagged.build()).build()); + return match.build(); + } + + private CreateSubif generateSubInterfaceRequest(final int superIfId) { + CreateSubif request = new CreateSubif(); + request.subId = 11; + request.swIfIndex = superIfId; + request.twoTags = 1; + request.dot1Ad = 1; + request.outerVlanId = 100; + request.innerVlanId = 200; + return request; + } + + private SwInterfaceSetFlags generateSwInterfaceEnableRequest(final int swIfIndex) { + SwInterfaceSetFlags request = new SwInterfaceSetFlags(); + request.swIfIndex = swIfIndex; + request.adminUpDown = 1; + return request; + } + + private InstanceIdentifier getSubInterfaceId(final String name, final long index) { + return InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(name)).augmentation( + SubinterfaceAugmentation.class).child(SubInterfaces.class).child(SubInterface.class, new SubInterfaceKey(index)); + } + + private void whenCreateSubifThen(final int retval) throws ExecutionException, InterruptedException { + final CompletableFuture replyFuture = new CompletableFuture<>(); + final CreateSubifReply reply = new CreateSubifReply(); + reply.retval = retval; + replyFuture.complete(reply); + doReturn(replyFuture).when(api).createSubif(any(CreateSubif.class)); + } + + private void whenSwInterfaceSetFlagsThen(final int retval) throws ExecutionException, InterruptedException { + final CompletableFuture replyFuture = new CompletableFuture<>(); + final SwInterfaceSetFlagsReply reply = new SwInterfaceSetFlagsReply(); + reply.retval = retval; + replyFuture.complete(reply); + doReturn(replyFuture).when(api).swInterfaceSetFlags(any(SwInterfaceSetFlags.class)); + } + + private void whenCreateSubifThenSuccess() throws ExecutionException, InterruptedException { + whenCreateSubifThen(0); + } + + private void whenCreateSubifThenFailure() throws ExecutionException, InterruptedException { + whenCreateSubifThen(-1); + } + + private void whenSwInterfaceSetFlagsThenSuccess() throws ExecutionException, InterruptedException { + whenSwInterfaceSetFlagsThen(0); + } + + private CreateSubif verifyCreateSubifWasInvoked(final CreateSubif expected) { + ArgumentCaptor argumentCaptor = ArgumentCaptor.forClass(CreateSubif.class); + verify(api).createSubif(argumentCaptor.capture()); + final CreateSubif actual = argumentCaptor.getValue(); + + assertEquals(expected.swIfIndex, actual.swIfIndex); + assertEquals(expected.subId, actual.subId); + assertEquals(expected.noTags, actual.noTags); + assertEquals(expected.oneTag, actual.oneTag); + assertEquals(expected.twoTags, actual.twoTags); + assertEquals(expected.dot1Ad, actual.dot1Ad); + assertEquals(expected.exactMatch, actual.exactMatch); + assertEquals(expected.defaultSub, actual.defaultSub); + assertEquals(expected.outerVlanIdAny, actual.outerVlanIdAny); + assertEquals(expected.innerVlanIdAny, actual.innerVlanIdAny); + assertEquals(expected.outerVlanId, actual.outerVlanId); + assertEquals(expected.innerVlanId, actual.innerVlanId); + return actual; + } + + private SwInterfaceSetFlags verifySwInterfaceSetFlagsWasInvoked(final SwInterfaceSetFlags expected) { + ArgumentCaptor argumentCaptor = ArgumentCaptor.forClass(SwInterfaceSetFlags.class); + verify(api).swInterfaceSetFlags(argumentCaptor.capture()); + final SwInterfaceSetFlags actual = argumentCaptor.getValue(); + + assertEquals(expected.swIfIndex, actual.swIfIndex); + assertEquals(expected.adminUpDown, actual.adminUpDown); + return actual; + } + + @Test + public void testCreate() throws Exception { + final SubInterface subInterface = generateSubInterface(SUPER_IF_NAME, false); + final String superIfName = "local0"; + final String subIfaceName = "local0.11"; + final long subifIndex = 11; + final InstanceIdentifier id = getSubInterfaceId(superIfName, subifIndex); + + whenCreateSubifThenSuccess(); + whenSwInterfaceSetFlagsThenSuccess(); + + customizer.writeCurrentAttributes(id, subInterface, writeContext); + + verifyCreateSubifWasInvoked(generateSubInterfaceRequest(SUPER_IF_ID)); + verify(mappingContext) + .put(eq(getMappingIid(subIfaceName, "test-instance")), eq(getMapping(subIfaceName, 0).get())); + } + + @Test + public void testCreateFailed() throws Exception { + final SubInterface subInterface = generateSubInterface(SUPER_IF_NAME, false); + final String superIfName = "local0"; + final String subIfaceName = "local0.11"; + final long subifIndex = 11; + final InstanceIdentifier id = getSubInterfaceId(superIfName, subifIndex); + + whenCreateSubifThenFailure(); + + try { + customizer.writeCurrentAttributes(id, subInterface, writeContext); + } catch (WriteFailedException.CreateFailedException e) { + assertEquals(VppApiInvocationException.class, e.getCause().getClass()); + verifyCreateSubifWasInvoked(generateSubInterfaceRequest(SUPER_IF_ID)); + verify(mappingContext, times(0)).put( + eq(getMappingIid(subIfaceName, "test-instance")), + eq(getMapping(subIfaceName, 0).get())); + return; + } + fail("WriteFailedException.CreateFailedException was expected"); + } + + @Test + public void testUpdate() throws Exception { + final SubInterface before = generateSubInterface("eth0", false); + final SubInterface after = generateSubInterface("eth1", true); + final String superIfName = "local0"; + final String subIfaceName = "local0.11"; + final int subifIndex = 11; + final InstanceIdentifier id = getSubInterfaceId(superIfName, subifIndex); + + whenSwInterfaceSetFlagsThenSuccess(); + final Optional ifcMapping = getMapping(subIfaceName, subifIndex); + doReturn(ifcMapping).when(mappingContext).read(any()); + + customizer.updateCurrentAttributes(id, before, after, writeContext); + + verifySwInterfaceSetFlagsWasInvoked(generateSwInterfaceEnableRequest(subifIndex)); + } + + @Test + public void testUpdateNoStateChange() throws Exception { + final SubInterface before = generateSubInterface(SUPER_IF_NAME, false); + final SubInterface after = generateSubInterface(SUPER_IF_NAME, false); + customizer.updateCurrentAttributes(null, before, after, writeContext); + + verify(api, never()).swInterfaceSetFlags(any()); + } + + @Test(expected = UnsupportedOperationException.class) + public void testDelete() throws Exception { + final SubInterface subInterface = generateSubInterface("eth0", false); + customizer.deleteCurrentAttributes(null, subInterface, writeContext); + } +} \ No newline at end of file diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/TapCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/TapCustomizerTest.java index e717ec504..61a94f8d2 100644 --- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/TapCustomizerTest.java +++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/TapCustomizerTest.java @@ -16,8 +16,8 @@ package io.fd.honeycomb.v3po.translate.v3po.interfaces; -import static io.fd.honeycomb.v3po.translate.v3po.ContextTestUtils.getMapping; -import static io.fd.honeycomb.v3po.translate.v3po.ContextTestUtils.getMappingIid; +import static io.fd.honeycomb.v3po.translate.v3po.test.ContextTestUtils.getMapping; +import static io.fd.honeycomb.v3po.translate.v3po.test.ContextTestUtils.getMappingIid; import static org.mockito.Matchers.any; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.doAnswer; diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/VhostUserCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/VhostUserCustomizerTest.java index a6fb64331..660430690 100644 --- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/VhostUserCustomizerTest.java +++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/VhostUserCustomizerTest.java @@ -16,8 +16,8 @@ package io.fd.honeycomb.v3po.translate.v3po.interfaces; -import static io.fd.honeycomb.v3po.translate.v3po.ContextTestUtils.getMapping; -import static io.fd.honeycomb.v3po.translate.v3po.ContextTestUtils.getMappingIid; +import static io.fd.honeycomb.v3po.translate.v3po.test.ContextTestUtils.getMapping; +import static io.fd.honeycomb.v3po.translate.v3po.test.ContextTestUtils.getMappingIid; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/VlanTagRewriteCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/VlanTagRewriteCustomizerTest.java deleted file mode 100644 index e8954dac2..000000000 --- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/VlanTagRewriteCustomizerTest.java +++ /dev/null @@ -1,239 +0,0 @@ -// FIXME new vlan model -///* -// * 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.interfaces; -// -//import static io.fd.honeycomb.v3po.translate.v3po.ContextTestUtils.getMapping; -//import static io.fd.honeycomb.v3po.translate.v3po.ContextTestUtils.getMappingIid; -//import static org.junit.Assert.assertEquals; -//import static org.junit.Assert.fail; -//import static org.mockito.Matchers.any; -//import static org.mockito.Mockito.doReturn; -//import static org.mockito.Mockito.verify; -//import static org.mockito.MockitoAnnotations.initMocks; -// -//import com.google.common.base.Optional; -//import io.fd.honeycomb.v3po.translate.MappingContext; -//import io.fd.honeycomb.v3po.translate.v3po.util.NamingContext; -//import io.fd.honeycomb.v3po.translate.v3po.util.VppApiInvocationException; -//import io.fd.honeycomb.v3po.translate.write.WriteContext; -//import io.fd.honeycomb.v3po.translate.write.WriteFailedException; -//import java.util.concurrent.CompletableFuture; -//import java.util.concurrent.ExecutionException; -//import org.junit.Before; -//import org.junit.Test; -//import org.mockito.ArgumentCaptor; -//import org.mockito.Mock; -//import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces; -//import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface; -//import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceBuilder; -//import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceKey; -//import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.SubInterface; -//import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.TagRewriteOperation; -//import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VlanTag; -//import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VlanType; -//import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VppInterfaceAugmentation; -//import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces._interface.L2; -//import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces._interface.l2.VlanTagRewrite; -//import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces._interface.l2.VlanTagRewriteBuilder; -//import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -//import org.openvpp.jvpp.dto.L2InterfaceVlanTagRewrite; -//import org.openvpp.jvpp.dto.L2InterfaceVlanTagRewriteReply; -//import org.openvpp.jvpp.future.FutureJVpp; -// -//public class VlanTagRewriteCustomizerTest { -// -// @Mock -// private FutureJVpp api; -// @Mock -// private WriteContext writeContext; -// @Mock -// private MappingContext mappingContext; -// -// private NamingContext namingContext; -// private VlanTagRewriteCustomizer customizer; -// -// public static final String VLAN_IF_NAME = "local0.0"; -// public static final int VLAN_IF_ID = 1; -// -// @Before -// public void setUp() throws Exception { -// initMocks(this); -// namingContext = new NamingContext("generatedSubInterfaceName", "test-instance"); -// doReturn(mappingContext).when(writeContext).getMappingContext(); -// customizer = new VlanTagRewriteCustomizer(api, namingContext); -// doReturn(getMapping(VLAN_IF_NAME, VLAN_IF_ID)).when(mappingContext).read(getMappingIid(VLAN_IF_NAME, "test-instance")); -// } -// -// private InstanceIdentifier getVlanTagRewriteId(final String name) { -// return InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(name)).augmentation( -// VppInterfaceAugmentation.class).child(L2.class).child(VlanTagRewrite.class); -// } -// -// private VlanTagRewrite generateVlanTagRewrite(final int vtrOp) { -// final VlanTagRewriteBuilder builder = new VlanTagRewriteBuilder(); -// builder.setRewriteOperation(TagRewriteOperation.forValue(vtrOp)); -// builder.setTag1(new VlanTag(100)); -// builder.setTag2(new VlanTag(200)); -// builder.setFirstPushed(VlanType._802dot1ad); -// return builder.build(); -// } -// -// private L2InterfaceVlanTagRewrite generateL2InterfaceVlanTagRewrite(final int superIfId, final int vtrOp) { -// final L2InterfaceVlanTagRewrite request = new L2InterfaceVlanTagRewrite(); -// request.swIfIndex = superIfId; -// request.vtrOp = vtrOp; -// request.pushDot1Q = 0; -// request.tag1 = 100; -// request.tag2 = 200; -// return request; -// } -// -// private void whenL2InterfaceVlanTagRewriteThen(final int retval) throws ExecutionException, InterruptedException { -// final CompletableFuture replyFuture = new CompletableFuture<>(); -// final L2InterfaceVlanTagRewriteReply reply = new L2InterfaceVlanTagRewriteReply(); -// reply.retval = retval; -// replyFuture.complete(reply); -// doReturn(replyFuture).when(api).l2InterfaceVlanTagRewrite(any(L2InterfaceVlanTagRewrite.class)); -// } -// -// private void whenL2InterfaceVlanTagRewriteThenSuccess() throws ExecutionException, InterruptedException { -// whenL2InterfaceVlanTagRewriteThen(0); -// } -// -// private void whenL2InterfaceVlanTagRewriteThenFailure() throws ExecutionException, InterruptedException { -// whenL2InterfaceVlanTagRewriteThen(-1); -// } -// -// private void verifyL2InterfaceVlanTagRewriteWasInvoked(final L2InterfaceVlanTagRewrite expected) { -// ArgumentCaptor argumentCaptor = ArgumentCaptor.forClass(L2InterfaceVlanTagRewrite.class); -// verify(api).l2InterfaceVlanTagRewrite(argumentCaptor.capture()); -// final L2InterfaceVlanTagRewrite actual = argumentCaptor.getValue(); -// assertEquals(expected.swIfIndex, actual.swIfIndex); -// assertEquals(expected.vtrOp, actual.vtrOp); -// assertEquals(expected.pushDot1Q, actual.pushDot1Q); -// assertEquals(expected.tag1, actual.tag1); -// assertEquals(expected.tag2, actual.tag2); -// } -// -// private void verifyL2InterfaceVlanTagRewriteDeleteWasInvoked() { -// final L2InterfaceVlanTagRewrite request = new L2InterfaceVlanTagRewrite(); -// request.swIfIndex = VLAN_IF_ID; -// verifyL2InterfaceVlanTagRewriteWasInvoked(request); -// } -// -// @Test -// public void testCreate() throws Exception { -// final int vtrOp = 6; -// final VlanTagRewrite vlanTagRewrite = generateVlanTagRewrite(vtrOp); -// final InstanceIdentifier id = getVlanTagRewriteId(VLAN_IF_NAME); -// -// whenL2InterfaceVlanTagRewriteThenSuccess(); -// // Vlan Tag rewrite is checking ifc type by reading its configuration from write context -// doReturn(Optional.of(new InterfaceBuilder().setType(SubInterface.class).build())) -// .when(writeContext).readAfter(any(InstanceIdentifier.class)); -// -// customizer.writeCurrentAttributes(id, vlanTagRewrite, writeContext); -// -// verifyL2InterfaceVlanTagRewriteWasInvoked(generateL2InterfaceVlanTagRewrite(VLAN_IF_ID, vtrOp)); -// } -// -// @Test -// public void testCreateFailed() throws Exception { -// final int vtrOp = 6; -// final VlanTagRewrite vlanTagRewrite = generateVlanTagRewrite(vtrOp); -// final InstanceIdentifier id = getVlanTagRewriteId(VLAN_IF_NAME); -// -// whenL2InterfaceVlanTagRewriteThenFailure(); -// // Vlan Tag rewrite is checking ifc type by reading its configuration from write context -// doReturn(Optional.of(new InterfaceBuilder().setType(SubInterface.class).build())) -// .when(writeContext).readAfter(any(InstanceIdentifier.class)); -// -// try { -// customizer.writeCurrentAttributes(id, vlanTagRewrite, writeContext); -// } catch (WriteFailedException.CreateFailedException e) { -// assertEquals(VppApiInvocationException.class, e.getCause().getClass()); -// verifyL2InterfaceVlanTagRewriteWasInvoked(generateL2InterfaceVlanTagRewrite(VLAN_IF_ID, vtrOp)); -// return; -// } -// fail("WriteFailedException.CreateFailedException was expected"); -// } -// -// @Test -// public void testUpdate() throws Exception { -// final int vtrOpAfter = 5; -// final VlanTagRewrite before = generateVlanTagRewrite(6); -// final VlanTagRewrite after = generateVlanTagRewrite(vtrOpAfter); -// final InstanceIdentifier id = getVlanTagRewriteId(VLAN_IF_NAME); -// -// whenL2InterfaceVlanTagRewriteThenSuccess(); -// -// customizer.updateCurrentAttributes(id, before, after, writeContext); -// -// verifyL2InterfaceVlanTagRewriteWasInvoked(generateL2InterfaceVlanTagRewrite(VLAN_IF_ID, vtrOpAfter)); -// } -// -// @Test -// public void testUpdateFailed() throws Exception { -// final int vtrOpAfter = 5; -// final VlanTagRewrite before = generateVlanTagRewrite(6); -// final VlanTagRewrite after = generateVlanTagRewrite(vtrOpAfter); -// final InstanceIdentifier id = getVlanTagRewriteId(VLAN_IF_NAME); -// -// whenL2InterfaceVlanTagRewriteThenFailure(); -// -// try { -// customizer.updateCurrentAttributes(id, before, after, writeContext); -// } catch (WriteFailedException.UpdateFailedException e) { -// assertEquals(VppApiInvocationException.class, e.getCause().getClass()); -// verifyL2InterfaceVlanTagRewriteWasInvoked(generateL2InterfaceVlanTagRewrite(VLAN_IF_ID, vtrOpAfter)); -// return; -// } -// fail("WriteFailedException.UpdateFailedException was expected"); -// } -// -// @Test -// public void testDelete() throws Exception { -// final VlanTagRewriteBuilder builder = new VlanTagRewriteBuilder(); -// builder.setRewriteOperation(TagRewriteOperation.Disabled); -// final InstanceIdentifier id = getVlanTagRewriteId(VLAN_IF_NAME); -// -// whenL2InterfaceVlanTagRewriteThenSuccess(); -// -// customizer.deleteCurrentAttributes(id, builder.build(), writeContext); -// -// verifyL2InterfaceVlanTagRewriteDeleteWasInvoked(); -// } -// -// @Test -// public void testDeleteFailed() throws Exception { -// final VlanTagRewriteBuilder builder = new VlanTagRewriteBuilder(); -// builder.setRewriteOperation(TagRewriteOperation.Disabled); -// final InstanceIdentifier id = getVlanTagRewriteId(VLAN_IF_NAME); -// -// whenL2InterfaceVlanTagRewriteThenFailure(); -// -// try { -// customizer.deleteCurrentAttributes(id, builder.build(), writeContext); -// } catch (WriteFailedException.DeleteFailedException e) { -// assertEquals(VppApiInvocationException.class, e.getCause().getClass()); -// verifyL2InterfaceVlanTagRewriteDeleteWasInvoked(); -// return; -// } -// fail("WriteFailedException.DeleteFailedException was expected"); -// } -//} \ No newline at end of file diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/VxlanCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/VxlanCustomizerTest.java index f44057f7e..312ec9c01 100644 --- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/VxlanCustomizerTest.java +++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/VxlanCustomizerTest.java @@ -16,8 +16,8 @@ package io.fd.honeycomb.v3po.translate.v3po.interfaces; -import static io.fd.honeycomb.v3po.translate.v3po.ContextTestUtils.getMapping; -import static io.fd.honeycomb.v3po.translate.v3po.ContextTestUtils.getMappingIid; +import static io.fd.honeycomb.v3po.translate.v3po.test.ContextTestUtils.getMapping; +import static io.fd.honeycomb.v3po.translate.v3po.test.ContextTestUtils.getMappingIid; import static java.util.Collections.singletonList; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/VxlanGpeCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/VxlanGpeCustomizerTest.java index 7e1d9e95e..44e8559b4 100644 --- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/VxlanGpeCustomizerTest.java +++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/VxlanGpeCustomizerTest.java @@ -16,8 +16,8 @@ package io.fd.honeycomb.v3po.translate.v3po.interfaces; -import static io.fd.honeycomb.v3po.translate.v3po.ContextTestUtils.getMapping; -import static io.fd.honeycomb.v3po.translate.v3po.ContextTestUtils.getMappingIid; +import static io.fd.honeycomb.v3po.translate.v3po.test.ContextTestUtils.getMapping; +import static io.fd.honeycomb.v3po.translate.v3po.test.ContextTestUtils.getMappingIid; import static java.util.Collections.singletonList; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; 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 822b16c2b..a43bb136f 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,18 +16,17 @@ package io.fd.honeycomb.v3po.translate.v3po.interfacesstate; -import static io.fd.honeycomb.v3po.translate.v3po.ContextTestUtils.getMapping; -import static io.fd.honeycomb.v3po.translate.v3po.ContextTestUtils.getMappingIid; import static io.fd.honeycomb.v3po.translate.v3po.interfacesstate.InterfaceUtils.yangIfIndexToVpp; +import static io.fd.honeycomb.v3po.translate.v3po.test.ContextTestUtils.getMapping; +import static io.fd.honeycomb.v3po.translate.v3po.test.ContextTestUtils.getMappingIid; +import static io.fd.honeycomb.v3po.translate.v3po.test.InterfaceTestUtils.whenSwInterfaceDumpThenReturn; 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.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; import com.google.common.base.Optional; import com.google.common.collect.Lists; @@ -37,9 +36,6 @@ 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.mockito.ArgumentCaptor; import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.contexts.naming.context.Mappings; @@ -54,7 +50,6 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces. import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier; import org.openvpp.jvpp.dto.SwInterfaceDetails; -import org.openvpp.jvpp.dto.SwInterfaceDetailsReplyDump; import org.openvpp.jvpp.dto.SwInterfaceDump; public class InterfaceCustomizerTest extends @@ -113,16 +108,7 @@ public class InterfaceCustomizerTest extends assertEquals(iface.getPhysAddress().getValue(), InterfaceUtils.vppPhysAddrToYang(details.l2Address)); } - private void whenSwInterfaceDumpThenReturn(final List interfaceList) - throws ExecutionException, InterruptedException { - final CompletionStage replyCS = mock(CompletionStage.class); - final CompletableFuture 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); - } + @Test public void testReadCurrentAttributes() throws Exception { @@ -138,7 +124,7 @@ public class InterfaceCustomizerTest extends iface.l2AddressLength = 6; iface.l2Address = new byte[iface.l2AddressLength]; final List interfaceList = Collections.singletonList(iface); - whenSwInterfaceDumpThenReturn(interfaceList); + whenSwInterfaceDumpThenReturn(api, interfaceList); getCustomizer().readCurrentAttributes(id, builder, ctx); @@ -153,7 +139,7 @@ public class InterfaceCustomizerTest extends .child(Interface.class, new InterfaceKey(ifaceName)); final InterfaceBuilder builder = getCustomizer().getBuilder(id); - whenSwInterfaceDumpThenReturn(Collections.emptyList()); + whenSwInterfaceDumpThenReturn(api, Collections.emptyList()); try { getCustomizer().readCurrentAttributes(id, builder, ctx); @@ -178,7 +164,7 @@ public class InterfaceCustomizerTest extends final SwInterfaceDetails swIf1 = new SwInterfaceDetails(); swIf1.swIfIndex = 1; swIf1.interfaceName = swIf1Name.getBytes(); - whenSwInterfaceDumpThenReturn(Arrays.asList(swIf0, swIf1)); + whenSwInterfaceDumpThenReturn(api, Arrays.asList(swIf0, swIf1)); final List expectedIds = Arrays.asList(new InterfaceKey(swIf0Name), new InterfaceKey(swIf1Name)); final List actualIds = getCustomizer().getAllIds(id, ctx); diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfacesstate/L2CustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfacesstate/L2CustomizerTest.java index b3cf5ebfd..bb935bca0 100644 --- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfacesstate/L2CustomizerTest.java +++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfacesstate/L2CustomizerTest.java @@ -16,8 +16,8 @@ package io.fd.honeycomb.v3po.translate.v3po.interfacesstate; -import static io.fd.honeycomb.v3po.translate.v3po.ContextTestUtils.getMapping; -import static io.fd.honeycomb.v3po.translate.v3po.ContextTestUtils.getMappingIid; +import static io.fd.honeycomb.v3po.translate.v3po.test.ContextTestUtils.getMapping; +import static io.fd.honeycomb.v3po.translate.v3po.test.ContextTestUtils.getMappingIid; import static org.mockito.Matchers.any; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfacesstate/RewriteCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfacesstate/RewriteCustomizerTest.java new file mode 100644 index 000000000..f7f7bb377 --- /dev/null +++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfacesstate/RewriteCustomizerTest.java @@ -0,0 +1,127 @@ +/* + * 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.interfacesstate; + +import static io.fd.honeycomb.v3po.translate.v3po.test.ContextTestUtils.getMapping; +import static org.junit.Assert.assertEquals; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; + +import com.google.common.base.Optional; +import io.fd.honeycomb.v3po.translate.read.ReadFailedException; +import io.fd.honeycomb.v3po.translate.spi.read.RootReaderCustomizer; +import io.fd.honeycomb.v3po.translate.v3po.test.ChildReaderCustomizerTest; +import io.fd.honeycomb.v3po.translate.v3po.util.NamingContext; +import io.fd.honeycomb.v3po.translate.v3po.util.TagRewriteOperation; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.junit.Test; +import org.mockito.ArgumentCaptor; +import org.mockito.Captor; +import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.contexts.naming.context.mappings.Mapping; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfacesState; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.InterfaceKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.SubinterfaceStateAugmentation; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527._802dot1q; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.interfaces.state._interface.SubInterfaces; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.interfaces.state._interface.sub.interfaces.SubInterface; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.interfaces.state._interface.sub.interfaces.SubInterfaceKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.sub._interface.base.attributes.L2Builder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.sub._interface.base.attributes.l2.Rewrite; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.sub._interface.base.attributes.l2.RewriteBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.tag.rewrite.PushTags; +import org.opendaylight.yangtools.yang.binding.ChildOf; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.openvpp.jvpp.dto.SwInterfaceDetails; + +public class RewriteCustomizerTest extends ChildReaderCustomizerTest { + + public static final String VLAN_IF_NAME = "local0.1"; + public static final int VLAN_IF_ID = 1; + public static final int VLAN_IF_INDEX = 11; + + private NamingContext interfacesContext; + + @Captor + private ArgumentCaptor> captor; + + public RewriteCustomizerTest() { + super(Rewrite.class); + } + + @Override + public void setUpBefore() { + interfacesContext = new NamingContext("generatedIfaceName", "test-instance"); + + final Optional ifcMapping = getMapping(VLAN_IF_NAME, VLAN_IF_INDEX); + doReturn(ifcMapping).when(mappingContext).read(any()); + } + + @Override + protected RootReaderCustomizer initCustomizer() { + return new RewriteCustomizer(api, interfacesContext); + } + + @Test + public void testMerge() { + final L2Builder builder = mock(L2Builder.class); + final Rewrite value = mock(Rewrite.class); + getCustomizer().merge(builder, value); + verify(builder).setRewrite(value); + } + + private InstanceIdentifier getVlanTagRewriteId(final String name, final long index) { + final Class> child = (Class)Rewrite.class; + final InstanceIdentifier id = + InstanceIdentifier.create(InterfacesState.class).child(Interface.class, new InterfaceKey(name)).augmentation( + SubinterfaceStateAugmentation.class).child(SubInterfaces.class) + .child(SubInterface.class, new SubInterfaceKey(index)) + .child(child); + return id; + } + + @Test + public void testRead() throws ReadFailedException { + final Map cachedInterfaceDump = new HashMap<>(); + + final SwInterfaceDetails ifaceDetails = new SwInterfaceDetails(); + ifaceDetails.subId = VLAN_IF_ID; + ifaceDetails.interfaceName = VLAN_IF_NAME.getBytes(); + ifaceDetails.vtrOp = TagRewriteOperation.translate_2_to_2.ordinal(); + ifaceDetails.subNumberOfTags = 2; + ifaceDetails.vtrTag1 = 123; + ifaceDetails.vtrTag2 = 321; + ifaceDetails.vtrPushDot1Q = 1; + cachedInterfaceDump.put(VLAN_IF_INDEX, ifaceDetails); + cache.put(InterfaceCustomizer.DUMPED_IFCS_CONTEXT_KEY, cachedInterfaceDump); + + final RewriteBuilder builder = mock(RewriteBuilder.class); + + getCustomizer().readCurrentAttributes(getVlanTagRewriteId(VLAN_IF_NAME, VLAN_IF_ID), builder, ctx); + + verify(builder).setVlanType(_802dot1q.class); + verify(builder).setPopTags((short) 2); + + verify(builder).setPushTags(captor.capture()); + final List tags = captor.getValue(); + assertEquals(ifaceDetails.subNumberOfTags, tags.size()); + } +} \ No newline at end of file diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfacesstate/SubInterfaceCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfacesstate/SubInterfaceCustomizerTest.java index 21ffdc943..effe0dbfb 100644 --- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfacesstate/SubInterfaceCustomizerTest.java +++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfacesstate/SubInterfaceCustomizerTest.java @@ -1,123 +1,145 @@ -// FIXME new vlan model -///* -// * 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.interfacesstate; -// -//import static io.fd.honeycomb.v3po.translate.v3po.ContextTestUtils.getMapping; -//import static io.fd.honeycomb.v3po.translate.v3po.ContextTestUtils.getMappingIid; -//import static org.mockito.Matchers.any; -//import static org.mockito.Matchers.anyString; -//import static org.mockito.Mockito.doReturn; -//import static org.mockito.Mockito.mock; -//import static org.mockito.Mockito.never; -//import static org.mockito.Mockito.verify; -// -//import com.google.common.base.Optional; -//import com.google.common.collect.Lists; -//import io.fd.honeycomb.v3po.translate.read.ReadFailedException; -//import io.fd.honeycomb.v3po.translate.spi.read.ChildReaderCustomizer; -//import io.fd.honeycomb.v3po.translate.v3po.test.ChildReaderCustomizerTest; -//import io.fd.honeycomb.v3po.translate.v3po.util.NamingContext; -//import java.util.HashMap; -//import java.util.List; -//import java.util.Map; -//import org.junit.Test; -//import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.contexts.naming.context.Mappings; -//import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.contexts.naming.context.MappingsBuilder; -//import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.contexts.naming.context.mappings.Mapping; -//import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.contexts.naming.context.mappings.MappingKey; -//import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfacesState; -//import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface; -//import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.InterfaceKey; -//import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VlanType; -//import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VppInterfaceStateAugmentation; -//import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VppInterfaceStateAugmentationBuilder; -//import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces.state._interface.SubInterface; -//import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces.state._interface.SubInterfaceBuilder; -//import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -//import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier; -//import org.openvpp.jvpp.dto.SwInterfaceDetails; -// -//public class SubInterfaceCustomizerTest extends ChildReaderCustomizerTest { -// -// private NamingContext interfacesContext; -// -// public SubInterfaceCustomizerTest() { -// super(SubInterface.class); -// } -// -// @Override -// protected ChildReaderCustomizer initCustomizer() { -// return new SubInterfaceCustomizer(api, interfacesContext); -// } -// -// @Override -// public void setUpBefore() { -// interfacesContext = new NamingContext("generatedIfaceName", "test-instance"); -// } -// -// private InstanceIdentifier getSubInterfaceId(final String name) { -// return InstanceIdentifier.create(InterfacesState.class).child(Interface.class, new InterfaceKey(name)).augmentation( -// VppInterfaceStateAugmentation.class).child( -// SubInterface.class); -// } -// -// @Test -// public void testMerge() { -// final VppInterfaceStateAugmentationBuilder builder = mock(VppInterfaceStateAugmentationBuilder.class); -// final SubInterface value = mock(SubInterface.class); -// getCustomizer().merge(builder, value); -// verify(builder).setSubInterface(value); -// } -// -// @Test -// public void testRead() throws ReadFailedException { -// final Map cachedInterfaceDump = new HashMap<>(); -// final int ifId = 1; -// final String ifName = "eth0.sub0"; -// -// final KeyedInstanceIdentifier ifcIid = getMappingIid(ifName, "test-instance"); -// doReturn(getMapping(ifName, ifId)).when(mappingContext).read(ifcIid); -// final KeyedInstanceIdentifier superIfcIid = getMappingIid("super", "test-instance"); -// doReturn(getMapping("super", 0)).when(mappingContext).read(superIfcIid); -// -// final List allMappings = Lists.newArrayList(getMapping(ifName, ifId).get(), getMapping("super", 0).get()); -// final Mappings allMappingsBaObject = new MappingsBuilder().setMapping(allMappings).build(); -// doReturn(Optional.of(allMappingsBaObject)).when(mappingContext).read(ifcIid.firstIdentifierOf(Mappings.class)); -// -// final SwInterfaceDetails ifaceDetails = new SwInterfaceDetails(); -// ifaceDetails.subId = ifId; -// ifaceDetails.interfaceName = ifName.getBytes(); -// ifaceDetails.subDot1Ad = 1; -// cachedInterfaceDump.put(ifId, ifaceDetails); -// cache.put(InterfaceCustomizer.DUMPED_IFCS_CONTEXT_KEY, cachedInterfaceDump); -// -// final SubInterfaceBuilder builder = mock(SubInterfaceBuilder.class); -// getCustomizer().readCurrentAttributes(getSubInterfaceId(ifName), builder, ctx); -// -// verify(builder).setIdentifier((long)ifId); -// verify(builder).setSuperInterface(anyString()); -// verify(builder).setNumberOfTags((short)0); -// verify(builder).setVlanType(VlanType._802dot1ad); -// verify(builder, never()).setExactMatch(any()); -// verify(builder, never()).setDefaultSubif(any()); -// verify(builder, never()).setMatchAnyOuterId(any()); -// verify(builder, never()).setMatchAnyInnerId(any()); -// verify(builder, never()).setInnerId(any()); -// verify(builder, never()).setOuterId(any()); -// } -//} \ No newline at end of file +/* + * 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.interfacesstate; + +import static io.fd.honeycomb.v3po.translate.v3po.test.ContextTestUtils.getMapping; +import static io.fd.honeycomb.v3po.translate.v3po.test.InterfaceTestUtils.whenSwInterfaceDumpThenReturn; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; + +import com.google.common.base.Optional; +import io.fd.honeycomb.v3po.translate.read.ReadFailedException; +import io.fd.honeycomb.v3po.translate.spi.read.RootReaderCustomizer; +import io.fd.honeycomb.v3po.translate.v3po.test.ListReaderCustomizerTest; +import io.fd.honeycomb.v3po.translate.v3po.util.NamingContext; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.junit.Test; +import org.mockito.ArgumentCaptor; +import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.contexts.naming.context.mappings.Mapping; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfacesState; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.InterfaceKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.SubinterfaceStateAugmentation; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.interfaces.state._interface.SubInterfaces; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.interfaces.state._interface.SubInterfacesBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.interfaces.state._interface.sub.interfaces.SubInterface; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.interfaces.state._interface.sub.interfaces.SubInterfaceBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.interfaces.state._interface.sub.interfaces.SubInterfaceKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.match.attributes.match.type.VlanTagged; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.sub._interface.base.attributes.Match; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.sub._interface.base.attributes.Tags; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.openvpp.jvpp.dto.SwInterfaceDetails; + +public class SubInterfaceCustomizerTest extends ListReaderCustomizerTest { + + public static final String SUPER_IF_NAME = "local0"; + public static final int SUPER_IF_INDEX = 1; + public static final String VLAN_IF_NAME = "local0.1"; + public static final int VLAN_IF_ID = 1; + public static final int VLAN_IF_INDEX = 11; + + private NamingContext interfacesContext; + + public SubInterfaceCustomizerTest() { + super(SubInterface.class); + } + + @Override + public void setUpBefore() { + interfacesContext = new NamingContext("generatedIfaceName", "test-instance"); + } + + @Override + protected RootReaderCustomizer initCustomizer() { + return new SubInterfaceCustomizer(api, interfacesContext); + } + + private InstanceIdentifier getSubInterfaceId(final String name, final long id) { + return InstanceIdentifier.create(InterfacesState.class).child(Interface.class, new InterfaceKey(name)).augmentation( + SubinterfaceStateAugmentation.class).child( + SubInterfaces.class).child(SubInterface.class, new SubInterfaceKey(id)); + } + + @Test + public void testMerge() { + final SubInterfacesBuilder builder = mock(SubInterfacesBuilder.class); + final List value = mock(List.class); + getCustomizer().merge(builder, value); + verify(builder).setSubInterface(value); + } + + @Test + public void testRead() throws ReadFailedException { + final Optional ifcMapping = getMapping(VLAN_IF_NAME, VLAN_IF_INDEX); + doReturn(ifcMapping).when(mappingContext).read(any()); + + final Map cachedInterfaceDump = new HashMap<>(); + + final SwInterfaceDetails ifaceDetails = new SwInterfaceDetails(); + ifaceDetails.subId = VLAN_IF_ID; + ifaceDetails.interfaceName = VLAN_IF_NAME.getBytes(); + ifaceDetails.subDot1Ad = 1; + ifaceDetails.subNumberOfTags = 2; + ifaceDetails.subOuterVlanIdAny = 1; + ifaceDetails.subInnerVlanIdAny = 1; + ifaceDetails.subExactMatch = 1; + cachedInterfaceDump.put(VLAN_IF_INDEX, ifaceDetails); + cache.put(InterfaceCustomizer.DUMPED_IFCS_CONTEXT_KEY, cachedInterfaceDump); + + final SubInterfaceBuilder builder = mock(SubInterfaceBuilder.class); + getCustomizer().readCurrentAttributes(getSubInterfaceId(VLAN_IF_NAME, VLAN_IF_ID), builder, ctx); + + verify(builder).setIdentifier((long) VLAN_IF_ID); + + ArgumentCaptor tagCaptor = ArgumentCaptor.forClass(Tags.class); + verify(builder).setTags(tagCaptor.capture()); + assertEquals(ifaceDetails.subNumberOfTags, tagCaptor.getValue().getTag().size()); + + ArgumentCaptor matchCaptor = ArgumentCaptor.forClass(Match.class); + verify(builder).setMatch(matchCaptor.capture()); + final VlanTagged matchType = (VlanTagged)matchCaptor.getValue().getMatchType(); + assertTrue(matchType.getVlanTagged().isMatchExactTags()); + } + + @Test + public void testGetAllIds() throws Exception { + final Optional ifcMapping = getMapping(SUPER_IF_NAME, SUPER_IF_INDEX); + doReturn(ifcMapping).when(mappingContext).read(any()); + + final SwInterfaceDetails iface = new SwInterfaceDetails(); + iface.interfaceName = VLAN_IF_NAME.getBytes(); + iface.swIfIndex = VLAN_IF_INDEX; + iface.subId = VLAN_IF_ID; + iface.supSwIfIndex = SUPER_IF_INDEX; + final List ifaces = Collections.singletonList(iface); + whenSwInterfaceDumpThenReturn(api, ifaces); + + final List allIds = + getCustomizer().getAllIds(getSubInterfaceId(VLAN_IF_NAME, VLAN_IF_ID), ctx); + + assertEquals(ifaces.size(), allIds.size()); + + } +} \ No newline at end of file diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfacesstate/VlanTagRewriteCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfacesstate/VlanTagRewriteCustomizerTest.java deleted file mode 100644 index 5e857b5c1..000000000 --- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfacesstate/VlanTagRewriteCustomizerTest.java +++ /dev/null @@ -1,102 +0,0 @@ -// FIXME new vlan model -///* -// * 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.interfacesstate; -// -//import static io.fd.honeycomb.v3po.translate.v3po.ContextTestUtils.getMapping; -//import static io.fd.honeycomb.v3po.translate.v3po.ContextTestUtils.getMappingIid; -//import static org.mockito.Matchers.any; -//import static org.mockito.Mockito.doReturn; -//import static org.mockito.Mockito.mock; -//import static org.mockito.Mockito.never; -//import static org.mockito.Mockito.verify; -// -//import io.fd.honeycomb.v3po.translate.read.ReadFailedException; -//import io.fd.honeycomb.v3po.translate.spi.read.RootReaderCustomizer; -//import io.fd.honeycomb.v3po.translate.v3po.test.ChildReaderCustomizerTest; -//import io.fd.honeycomb.v3po.translate.v3po.util.NamingContext; -//import java.util.HashMap; -//import java.util.Map; -//import org.junit.Test; -//import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfacesState; -//import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface; -//import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.InterfaceKey; -//import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.TagRewriteOperation; -//import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VlanType; -//import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VppInterfaceStateAugmentation; -//import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces.state._interface.L2; -//import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces.state._interface.L2Builder; -//import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces.state._interface.l2.VlanTagRewrite; -//import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces.state._interface.l2.VlanTagRewriteBuilder; -//import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -//import org.openvpp.jvpp.dto.SwInterfaceDetails; -// -//public class VlanTagRewriteCustomizerTest extends ChildReaderCustomizerTest { -// -// private NamingContext interfacesContext; -// -// public VlanTagRewriteCustomizerTest() { -// super(VlanTagRewrite.class); -// } -// -// @Override -// public void setUpBefore() { -// interfacesContext = new NamingContext("generatedIfaceName", "test-instance"); -// } -// -// -// @Override -// protected RootReaderCustomizer initCustomizer() { -// return new VlanTagRewriteCustomizer(api, interfacesContext); -// } -// -// @Test -// public void testMerge() { -// final L2Builder builder = mock(L2Builder.class); -// final VlanTagRewrite value = mock(VlanTagRewrite.class); -// getCustomizer().merge(builder, value); -// verify(builder).setVlanTagRewrite(value); -// } -// -// private InstanceIdentifier getVlanTagRewriteId(final String name) { -// return InstanceIdentifier.create(InterfacesState.class).child(Interface.class, new InterfaceKey(name)).augmentation( -// VppInterfaceStateAugmentation.class).child(L2.class).child(VlanTagRewrite.class); -// } -// -// @Test -// public void testRead() throws ReadFailedException { -// final Map cachedInterfaceDump = new HashMap<>(); -// final int ifId = 1; -// final String ifName = "eth0.sub0"; -// doReturn(getMapping(ifName, ifId)).when(mappingContext).read(getMappingIid(ifName, "test-instance")); -// -// final SwInterfaceDetails ifaceDetails = new SwInterfaceDetails(); -// ifaceDetails.subId = ifId; -// ifaceDetails.interfaceName = ifName.getBytes(); -// ifaceDetails.vtrPushDot1Q = 1; -// cachedInterfaceDump.put(ifId, ifaceDetails); -// cache.put(InterfaceCustomizer.DUMPED_IFCS_CONTEXT_KEY, cachedInterfaceDump); -// -// final VlanTagRewriteBuilder builder = mock(VlanTagRewriteBuilder.class); -// getCustomizer().readCurrentAttributes(getVlanTagRewriteId(ifName), builder, ctx); -// -// verify(builder).setFirstPushed(VlanType._802dot1q); -// verify(builder).setRewriteOperation(TagRewriteOperation.Disabled); -// verify(builder, never()).setTag1(any()); -// verify(builder, never()).setTag2(any()); -// } -//} \ No newline at end of file diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfacesstate/VxlanCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfacesstate/VxlanCustomizerTest.java index 3b32c9478..71e1952bf 100644 --- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfacesstate/VxlanCustomizerTest.java +++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfacesstate/VxlanCustomizerTest.java @@ -16,8 +16,8 @@ package io.fd.honeycomb.v3po.translate.v3po.interfacesstate; -import static io.fd.honeycomb.v3po.translate.v3po.ContextTestUtils.getMapping; -import static io.fd.honeycomb.v3po.translate.v3po.ContextTestUtils.getMappingIid; +import static io.fd.honeycomb.v3po.translate.v3po.test.ContextTestUtils.getMapping; +import static io.fd.honeycomb.v3po.translate.v3po.test.ContextTestUtils.getMappingIid; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfacesstate/VxlanGpeCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfacesstate/VxlanGpeCustomizerTest.java index 4f4ac9e4e..e795bcbf8 100644 --- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfacesstate/VxlanGpeCustomizerTest.java +++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfacesstate/VxlanGpeCustomizerTest.java @@ -16,8 +16,8 @@ package io.fd.honeycomb.v3po.translate.v3po.interfacesstate; -import static io.fd.honeycomb.v3po.translate.v3po.ContextTestUtils.getMapping; -import static io.fd.honeycomb.v3po.translate.v3po.ContextTestUtils.getMappingIid; +import static io.fd.honeycomb.v3po.translate.v3po.test.ContextTestUtils.getMapping; +import static io.fd.honeycomb.v3po.translate.v3po.test.ContextTestUtils.getMappingIid; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/test/ContextTestUtils.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/test/ContextTestUtils.java new file mode 100644 index 000000000..ce20f0734 --- /dev/null +++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/test/ContextTestUtils.java @@ -0,0 +1,40 @@ +/* + * 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 com.google.common.base.Optional; +import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.Contexts; +import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.contexts.NamingContextKey; +import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.contexts.naming.context.Mappings; +import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.contexts.naming.context.mappings.Mapping; +import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.contexts.naming.context.mappings.MappingBuilder; +import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.contexts.naming.context.mappings.MappingKey; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier; + +public class ContextTestUtils { + + public static Optional getMapping(final String name, final int index) { + return Optional.of(new MappingBuilder().setName(name).setIndex(index).build()); + } + + public static KeyedInstanceIdentifier getMappingIid(final String name, final String namingContextName) { + return InstanceIdentifier.create(Contexts.class).child( + org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.contexts.NamingContext.class, + new NamingContextKey(namingContextName)).child(Mappings.class).child(Mapping.class, new MappingKey(name)); + } +} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/test/InterfaceTestUtils.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/test/InterfaceTestUtils.java new file mode 100644 index 000000000..b7486253f --- /dev/null +++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/test/InterfaceTestUtils.java @@ -0,0 +1,47 @@ +/* + * 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.mockito.Matchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import java.util.List; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.CompletionStage; +import java.util.concurrent.ExecutionException; +import org.openvpp.jvpp.dto.SwInterfaceDetails; +import org.openvpp.jvpp.dto.SwInterfaceDetailsReplyDump; +import org.openvpp.jvpp.dto.SwInterfaceDump; +import org.openvpp.jvpp.future.FutureJVpp; + +public final class InterfaceTestUtils { + private InterfaceTestUtils() { + throw new UnsupportedOperationException("Utility class cannot be instantiated"); + } + + public static void whenSwInterfaceDumpThenReturn(final FutureJVpp api, final List interfaceList) + throws ExecutionException, InterruptedException { + final CompletionStage replyCS = mock(CompletionStage.class); + final CompletableFuture 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); + } +} 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 7436c9cf3..a7cf231da 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 @@ -15,8 +15,8 @@ */ package io.fd.honeycomb.v3po.translate.v3po.vpp; -import static io.fd.honeycomb.v3po.translate.v3po.ContextTestUtils.getMapping; -import static io.fd.honeycomb.v3po.translate.v3po.ContextTestUtils.getMappingIid; +import static io.fd.honeycomb.v3po.translate.v3po.test.ContextTestUtils.getMapping; +import static io.fd.honeycomb.v3po.translate.v3po.test.ContextTestUtils.getMappingIid; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; import static org.mockito.Matchers.any; 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 1b30fdde7..d54401237 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,8 +16,8 @@ package io.fd.honeycomb.v3po.translate.v3po.vpp; -import static io.fd.honeycomb.v3po.translate.v3po.ContextTestUtils.getMapping; -import static io.fd.honeycomb.v3po.translate.v3po.ContextTestUtils.getMappingIid; +import static io.fd.honeycomb.v3po.translate.v3po.test.ContextTestUtils.getMapping; +import static io.fd.honeycomb.v3po.translate.v3po.test.ContextTestUtils.getMappingIid; import static org.junit.Assert.assertEquals; import static org.mockito.Matchers.any; import static org.mockito.Mockito.doReturn; 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 5ac108560..79146fad3 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 @@ -16,8 +16,8 @@ package io.fd.honeycomb.v3po.translate.v3po.vppstate; -import static io.fd.honeycomb.v3po.translate.v3po.ContextTestUtils.getMapping; -import static io.fd.honeycomb.v3po.translate.v3po.ContextTestUtils.getMappingIid; +import static io.fd.honeycomb.v3po.translate.v3po.test.ContextTestUtils.getMapping; +import static io.fd.honeycomb.v3po.translate.v3po.test.ContextTestUtils.getMappingIid; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; -- cgit 1.2.3-korg