summaryrefslogtreecommitdiffstats
path: root/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/GreCustomizerTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/GreCustomizerTest.java')
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/GreCustomizerTest.java197
1 files changed, 0 insertions, 197 deletions
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/GreCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/GreCustomizerTest.java
deleted file mode 100644
index ee0d8fc23..000000000
--- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/GreCustomizerTest.java
+++ /dev/null
@@ -1,197 +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.translate.v3po.interfaces;
-
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-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 com.google.common.net.InetAddresses;
-import io.fd.honeycomb.translate.vpp.util.NamingContext;
-import io.fd.honeycomb.translate.write.WriteFailedException;
-import io.fd.honeycomb.vpp.test.write.WriterCustomizerTest;
-import org.junit.Test;
-import org.mockito.ArgumentCaptor;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.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.rev161214.VppInterfaceAugmentation;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.interfaces._interface.Gre;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.interfaces._interface.GreBuilder;
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import io.fd.vpp.jvpp.VppBaseCallException;
-import io.fd.vpp.jvpp.VppInvocationException;
-import io.fd.vpp.jvpp.core.dto.GreAddDelTunnel;
-import io.fd.vpp.jvpp.core.dto.GreAddDelTunnelReply;
-
-public class GreCustomizerTest extends WriterCustomizerTest {
-
- private static final String IFC_TEST_INSTANCE = "ifc-test-instance";
- private final String IFACE_NAME = "eth0";
- private final int IFACE_ID = 1;
- private InstanceIdentifier<Gre> id = InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(IFACE_NAME))
- .augmentation(VppInterfaceAugmentation.class).child(Gre.class);
- private static final byte ADD_GRE = 1;
- private static final byte DEL_GRE = 0;
-
- private GreCustomizer customizer;
-
- @Override
- public void setUp() throws Exception {
- InterfaceTypeTestUtils.setupWriteContext(writeContext,
- org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.GreTunnel.class);
- customizer = new GreCustomizer(api, new NamingContext("generateInterfaceNAme", IFC_TEST_INSTANCE));
- }
-
- private void whenGreAddDelTunnelThenSuccess() {
- final GreAddDelTunnelReply reply = new GreAddDelTunnelReply();
- reply.swIfIndex = IFACE_ID;
- doReturn(future(reply)).when(api).greAddDelTunnel(any(GreAddDelTunnel.class));
- }
-
- private void whenGreAddDelTunnelThenFailure() {
- doReturn(failedFuture()).when(api).greAddDelTunnel(any(GreAddDelTunnel.class));
- }
-
- private GreAddDelTunnel verifyGreAddDelTunnelWasInvoked(final Gre gre) throws VppInvocationException {
- ArgumentCaptor<GreAddDelTunnel> argumentCaptor = ArgumentCaptor.forClass(GreAddDelTunnel.class);
- verify(api).greAddDelTunnel(argumentCaptor.capture());
- final GreAddDelTunnel actual = argumentCaptor.getValue();
- assertEquals(0, actual.isIpv6);
- assertArrayEquals(InetAddresses.forString(gre.getSrc().getIpv4Address().getValue()).getAddress(),
- actual.srcAddress);
- assertArrayEquals(InetAddresses.forString(gre.getDst().getIpv4Address().getValue()).getAddress(),
- actual.dstAddress);
- assertEquals(gre.getOuterFibId().intValue(), actual.outerFibId);
- return actual;
- }
-
- private void verifyGreAddWasInvoked(final Gre gre) throws VppInvocationException {
- final GreAddDelTunnel actual = verifyGreAddDelTunnelWasInvoked(gre);
- assertEquals(ADD_GRE, actual.isAdd);
- }
-
- private void verifyGreDeleteWasInvoked(final Gre gre) throws VppInvocationException {
- final GreAddDelTunnel actual = verifyGreAddDelTunnelWasInvoked(gre);
- assertEquals(DEL_GRE, actual.isAdd);
- }
-
- private static Gre generateGre() {
- final GreBuilder builder = new GreBuilder();
- builder.setSrc(new IpAddress(new Ipv4Address("192.168.20.10")));
- builder.setDst(new IpAddress(new Ipv4Address("192.168.20.11")));
- builder.setOuterFibId(Long.valueOf(123));
- return builder.build();
- }
-
- @Test
- public void testWriteCurrentAttributes() throws Exception {
- final Gre gre = generateGre();
-
- whenGreAddDelTunnelThenSuccess();
-
- noMappingDefined(mappingContext, IFACE_NAME, IFC_TEST_INSTANCE);
-
- customizer.writeCurrentAttributes(id, gre, writeContext);
- verifyGreAddWasInvoked(gre);
- verify(mappingContext).put(eq(mappingIid(IFACE_NAME, IFC_TEST_INSTANCE)),
- eq(mapping(IFACE_NAME, IFACE_ID).get()));
- }
-
- @Test
- public void testWriteCurrentAttributesMappingAlreadyPresent() throws Exception {
- final Gre gre = generateGre();
-
- whenGreAddDelTunnelThenSuccess();
- defineMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_TEST_INSTANCE);
-
- customizer.writeCurrentAttributes(id, gre, writeContext);
- verifyGreAddWasInvoked(gre);
-
- // Remove the first mapping before putting in the new one
- verify(mappingContext).delete(eq(mappingIid(IFACE_NAME, IFC_TEST_INSTANCE)));
- verify(mappingContext).put(eq(mappingIid(IFACE_NAME, IFC_TEST_INSTANCE)), eq(mapping(IFACE_NAME, IFACE_ID).get()));
- }
-
- @Test
- public void testWriteCurrentAttributesFailed() throws Exception {
- final Gre gre = generateGre();
-
- whenGreAddDelTunnelThenFailure();
-
- try {
- customizer.writeCurrentAttributes(id, gre, writeContext);
- } catch (WriteFailedException.CreateFailedException e) {
- assertTrue(e.getCause() instanceof VppBaseCallException);
- verifyGreAddWasInvoked(gre);
- // Mapping not stored due to failure
- verify(mappingContext, times(0)).put(eq(mappingIid(IFACE_NAME, IFC_TEST_INSTANCE)), eq(mapping(
- IFACE_NAME, 0).get()));
- return;
- }
- fail("WriteFailedException.CreateFailedException was expected");
- }
-
- @Test
- public void testUpdateCurrentAttributes() throws Exception {
- try {
- customizer.updateCurrentAttributes(id, generateGre(), generateGre(), writeContext);
- } catch (WriteFailedException.UpdateFailedException e) {
- assertEquals(UnsupportedOperationException.class, e.getCause().getClass());
- return;
- }
- fail("WriteFailedException.UpdateFailedException was expected");
- }
-
- @Test
- public void testDeleteCurrentAttributes() throws Exception {
- final Gre gre = generateGre();
-
- whenGreAddDelTunnelThenSuccess();
- defineMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_TEST_INSTANCE);
-
- customizer.deleteCurrentAttributes(id, gre, writeContext);
- verifyGreDeleteWasInvoked(gre);
- verify(mappingContext).delete(eq(mappingIid(IFACE_NAME, IFC_TEST_INSTANCE)));
- }
-
- @Test
- public void testDeleteCurrentAttributesaFailed() throws Exception {
- final Gre gre = generateGre();
-
- whenGreAddDelTunnelThenFailure();
- defineMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_TEST_INSTANCE);
-
- try {
- customizer.deleteCurrentAttributes(id, gre, writeContext);
- } catch (WriteFailedException.DeleteFailedException e) {
- assertTrue(e.getCause() instanceof VppBaseCallException);
- verifyGreDeleteWasInvoked(gre);
- verify(mappingContext, times(0)).delete(eq(mappingIid(IFACE_NAME, IFC_TEST_INSTANCE)));
- return;
- }
- fail("WriteFailedException.DeleteFailedException was expected");
- }
-} \ No newline at end of file