From e3c31cee916480b2d9d169c1f5afb1c42efaabe1 Mon Sep 17 00:00:00 2001 From: Maros Marsalek Date: Fri, 29 Jul 2016 16:27:12 +0200 Subject: HONEYCOMB-130: Rename infra packages(remove vpp/v3po) Change-Id: Ic5b90e397e3743623d01b206bc60bc5c7df6b981 Signed-off-by: Maros Marsalek --- .../v3po/interfaces/TapCustomizerTest.java | 161 +++++++++++++++++++++ 1 file changed, 161 insertions(+) create mode 100644 v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/TapCustomizerTest.java (limited to 'v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/TapCustomizerTest.java') diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/TapCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/TapCustomizerTest.java new file mode 100644 index 000000000..43e210073 --- /dev/null +++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/TapCustomizerTest.java @@ -0,0 +1,161 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.honeycomb.translate.v3po.interfaces; + +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.doAnswer; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +import io.fd.honeycomb.translate.v3po.test.ContextTestUtils; +import io.fd.honeycomb.translate.write.WriteContext; +import io.fd.honeycomb.translate.MappingContext; +import io.fd.honeycomb.translate.ModificationCache; +import io.fd.honeycomb.translate.v3po.util.NamingContext; +import java.util.concurrent.CompletableFuture; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.mockito.invocation.InvocationOnMock; +import org.mockito.stubbing.Answer; +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.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress; +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.Tap; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces._interface.TapBuilder; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.openvpp.jvpp.dto.TapConnect; +import org.openvpp.jvpp.dto.TapConnectReply; +import org.openvpp.jvpp.dto.TapDelete; +import org.openvpp.jvpp.dto.TapDeleteReply; +import org.openvpp.jvpp.dto.TapModify; +import org.openvpp.jvpp.dto.TapModifyReply; +import org.openvpp.jvpp.future.FutureJVpp; + +public class TapCustomizerTest { + + @Mock + private FutureJVpp vppApi; + @Mock + private WriteContext writeContext; + @Mock + private MappingContext mappingContext; + + private TapCustomizer tapCustomizer; + + @Before + public void setUp() throws Exception { + MockitoAnnotations.initMocks(this); + InterfaceTypeTestUtils.setupWriteContext(writeContext, + org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.Tap.class); + final NamingContext ctx = new NamingContext("ifcintest", "test-instance"); + final ModificationCache toBeReturned = new ModificationCache(); + doReturn(toBeReturned).when(writeContext).getModificationCache(); + doReturn(mappingContext).when(writeContext).getMappingContext(); + + tapCustomizer = new TapCustomizer(vppApi, ctx); + } + + @Test + public void testCreate() throws Exception { + doAnswer(new Answer() { + + int idx = 0; + + @Override + public Object answer(final InvocationOnMock invocation) throws Throwable { + final CompletableFuture reply = new CompletableFuture<>(); + final TapConnectReply t = new TapConnectReply(); + t.swIfIndex = idx++; + reply.complete(t); + return reply; + } + }).when(vppApi).tapConnect(any(TapConnect.class)); + + tapCustomizer.writeCurrentAttributes(getTapId("tap"), getTapData("tap", "ff:ff:ff:ff:ff:ff"), writeContext); + tapCustomizer.writeCurrentAttributes(getTapId("tap2"), getTapData("tap2", "ff:ff:ff:ff:ff:ff"), writeContext); + + verify(vppApi, times(2)).tapConnect(any(TapConnect.class)); + verify(mappingContext).put(eq(ContextTestUtils.getMappingIid("tap", "test-instance")), eq( + ContextTestUtils.getMapping("tap", 0).get())); + verify(mappingContext).put(eq(ContextTestUtils.getMappingIid("tap2", "test-instance")), eq( + ContextTestUtils.getMapping("tap2", 1).get())); + } + + @Test + public void testModify() throws Exception { + final CompletableFuture reply = new CompletableFuture<>(); + final TapConnectReply t = new TapConnectReply(); + t.swIfIndex = 0; + reply.complete(t); + doReturn(reply).when(vppApi).tapConnect(any(TapConnect.class)); + + final CompletableFuture replyModif = new CompletableFuture<>(); + final TapModifyReply tmodif = new TapModifyReply(); + tmodif.swIfIndex = 0; + replyModif.complete(tmodif); + doReturn(replyModif).when(vppApi).tapModify(any(TapModify.class)); + + tapCustomizer.writeCurrentAttributes(getTapId("tap"), getTapData("tap", "ff:ff:ff:ff:ff:ff"), writeContext); + doReturn(ContextTestUtils.getMapping("tap", 1)).when(mappingContext).read( + ContextTestUtils.getMappingIid("tap", "test-instance")); + tapCustomizer.updateCurrentAttributes(getTapId("tap"), getTapData("tap", "ff:ff:ff:ff:ff:ff"), getTapData("tap", "ff:ff:ff:ff:ff:f1"), writeContext); + + verify(vppApi).tapConnect(any(TapConnect.class)); + verify(vppApi).tapModify(any(TapModify.class)); + + verify(mappingContext).put(eq(ContextTestUtils.getMappingIid("tap", "test-instance")), eq( + ContextTestUtils.getMapping("tap", 0).get())); + } + + @Test + public void testDelete() throws Exception { + final CompletableFuture reply = new CompletableFuture<>(); + final TapConnectReply t = new TapConnectReply(); + t.swIfIndex = 0; + reply.complete(t); + doReturn(reply).when(vppApi).tapConnect(any(TapConnect.class)); + + final CompletableFuture replyDelete = new CompletableFuture<>(); + final TapDeleteReply tmodif = new TapDeleteReply(); + replyDelete.complete(tmodif); + doReturn(replyDelete).when(vppApi).tapDelete(any(TapDelete.class)); + + tapCustomizer.writeCurrentAttributes(getTapId("tap"), getTapData("tap", "ff:ff:ff:ff:ff:ff"), writeContext); + doReturn(ContextTestUtils.getMapping("tap", 1)).when(mappingContext).read( + ContextTestUtils.getMappingIid("tap", "test-instance")); + tapCustomizer.deleteCurrentAttributes(getTapId("tap"), getTapData("tap", "ff:ff:ff:ff:ff:ff"), writeContext); + + verify(vppApi).tapConnect(any(TapConnect.class)); + verify(vppApi).tapDelete(any(TapDelete.class)); + verify(mappingContext).delete(eq(ContextTestUtils.getMappingIid("tap", "test-instance"))); + } + + private InstanceIdentifier getTapId(final String tap) { + return InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(tap)).augmentation( + VppInterfaceAugmentation.class).child(Tap.class); + } + + private Tap getTapData(final String tap, final String mac) { + return new TapBuilder().setTapName(tap).setMac(new PhysAddress(mac)).build(); + } +} \ No newline at end of file -- cgit 1.2.3-korg