package io.fd.honeycomb.translate.v3po.interfaces;
-import static io.fd.honeycomb.translate.v3po.test.ContextTestUtils.getMapping;
-import static io.fd.honeycomb.translate.v3po.test.ContextTestUtils.getMappingIid;
import static junit.framework.TestCase.assertTrue;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.verify;
import static org.mockito.MockitoAnnotations.initMocks;
-import com.google.common.base.Optional;
import io.fd.honeycomb.translate.MappingContext;
+import io.fd.honeycomb.translate.v3po.test.ContextTestUtils;
import io.fd.honeycomb.translate.v3po.test.TestHelperUtils;
import io.fd.honeycomb.translate.v3po.util.NamingContext;
import io.fd.honeycomb.translate.v3po.vppclassifier.VppClassifierContextManager;
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.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.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.interfaces._interface.Acl;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces._interface.AclBuilder;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
import org.openvpp.jvpp.VppBaseCallException;
import org.openvpp.jvpp.core.dto.InputAclSetInterface;
import org.openvpp.jvpp.core.dto.InputAclSetInterfaceReply;
public void setUp() throws Exception {
initMocks(this);
interfaceContext = new NamingContext("generatedInterfaceName", IFC_TEST_INSTANCE);
+ ContextTestUtils.mockMapping(mappingContext, IF_NAME, IF_INDEX, IFC_TEST_INSTANCE);
+
doReturn(mappingContext).when(writeContext).getMappingContext();
customizer = new AclCustomizer(api, interfaceContext, classifyTableContext);
-
- final KeyedInstanceIdentifier<Mapping, MappingKey> ifcMappingKey = getMappingIid(IF_NAME, IFC_TEST_INSTANCE);
- final Optional<Mapping> ifcMapping = getMapping(IF_NAME, IF_INDEX);
- doReturn(ifcMapping).when(mappingContext).read(ifcMappingKey);
}
import static io.fd.honeycomb.translate.v3po.test.ContextTestUtils.getMapping;
import static io.fd.honeycomb.translate.v3po.test.ContextTestUtils.getMappingIid;
-import static java.util.Collections.singletonList;
+import static io.fd.honeycomb.translate.v3po.test.ContextTestUtils.mockEmptyMapping;
+import static io.fd.honeycomb.translate.v3po.test.ContextTestUtils.mockMapping;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.when;
import static org.mockito.MockitoAnnotations.initMocks;
-import com.google.common.base.Optional;
import com.google.common.net.InetAddresses;
import io.fd.honeycomb.translate.MappingContext;
import io.fd.honeycomb.translate.ModificationCache;
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;
-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.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.yangtools.yang.binding.InstanceIdentifier;
import org.openvpp.jvpp.VppBaseCallException;
import org.openvpp.jvpp.VppInvocationException;
-import org.openvpp.jvpp.core.future.FutureJVppCore;
import org.openvpp.jvpp.core.dto.GreAddDelTunnel;
import org.openvpp.jvpp.core.dto.GreAddDelTunnelReply;
+import org.openvpp.jvpp.core.future.FutureJVppCore;
public class GreCustomizerTest {
+ 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 MappingContext mappingContext;
private GreCustomizer customizer;
- private String ifaceName;
- private InstanceIdentifier<Gre> id;
@Before
public void setUp() throws Exception {
InterfaceTypeTestUtils.setupWriteContext(writeContext,
org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.GreTunnel.class);
// TODO HONEYCOMB-116 create base class for tests using vppApi
- NamingContext namingContext = new NamingContext("generateInterfaceNAme", "test-instance");
+ NamingContext namingContext = new NamingContext("generateInterfaceNAme", IFC_TEST_INSTANCE);
final ModificationCache toBeReturned = new ModificationCache();
doReturn(toBeReturned).when(writeContext).getModificationCache();
doReturn(mappingContext).when(writeContext).getMappingContext();
customizer = new GreCustomizer(api, namingContext);
-
- ifaceName = "eth0";
- id = InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(ifaceName))
- .augmentation(VppInterfaceAugmentation.class).child(Gre.class);
}
private void whenGreAddDelTunnelThenSuccess()
final CompletableFuture<GreAddDelTunnelReply> replyFuture = mock(CompletableFuture.class);
when(replyCS.toCompletableFuture()).thenReturn(replyFuture);
final GreAddDelTunnelReply reply = new GreAddDelTunnelReply();
+ reply.swIfIndex = IFACE_ID;
when(replyFuture.get(anyLong(), eq(TimeUnit.SECONDS))).thenReturn(reply);
when(api.greAddDelTunnel(any(GreAddDelTunnel.class))).thenReturn(replyCS);
}
whenGreAddDelTunnelThenSuccess();
- doReturn(Optional.absent())
- .when(mappingContext).read(getMappingIid(ifaceName, "test-instance").firstIdentifierOf(Mappings.class));
+ mockEmptyMapping(mappingContext, IFACE_NAME, IFC_TEST_INSTANCE);
customizer.writeCurrentAttributes(id, gre, writeContext);
verifyGreAddWasInvoked(gre);
- verify(mappingContext).put(eq(getMappingIid(ifaceName, "test-instance")), eq(getMapping(ifaceName, 0).get()));
+ verify(mappingContext).put(eq(getMappingIid(IFACE_NAME, IFC_TEST_INSTANCE)),
+ eq(getMapping(IFACE_NAME, IFACE_ID).get()));
}
@Test
final Gre gre = generateGre();
whenGreAddDelTunnelThenSuccess();
- final Optional<Mapping> ifcMapping = getMapping(ifaceName, 0);
-
- doReturn(Optional.of(new MappingsBuilder().setMapping(singletonList(ifcMapping.get())).build()))
- .when(mappingContext).read(getMappingIid(ifaceName, "test-instance").firstIdentifierOf(Mappings.class));
+ mockMapping(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(getMappingIid(ifaceName, "test-instance")));
- verify(mappingContext).put(eq(getMappingIid(ifaceName, "test-instance")), eq(ifcMapping.get()));
+ verify(mappingContext).delete(eq(getMappingIid(IFACE_NAME, IFC_TEST_INSTANCE)));
+ verify(mappingContext).put(eq(getMappingIid(IFACE_NAME, IFC_TEST_INSTANCE)), eq(getMapping(IFACE_NAME, IFACE_ID).get()));
}
@Test
assertTrue(e.getCause() instanceof VppBaseCallException);
verifyGreAddWasInvoked(gre);
// Mapping not stored due to failure
- verify(mappingContext, times(0)).put(eq(getMappingIid(ifaceName, "test-instance")), eq(getMapping(ifaceName, 0).get()));
+ verify(mappingContext, times(0)).put(eq(getMappingIid(IFACE_NAME, IFC_TEST_INSTANCE)), eq(getMapping(
+ IFACE_NAME, 0).get()));
return;
}
fail("WriteFailedException.CreateFailedException was expected");
final Gre gre = generateGre();
whenGreAddDelTunnelThenSuccess();
- doReturn(getMapping(ifaceName, 1)).when(mappingContext).read(getMappingIid(ifaceName, "test-instance"));
+ mockMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_TEST_INSTANCE);
customizer.deleteCurrentAttributes(id, gre, writeContext);
verifyGreDeleteWasInvoked(gre);
- verify(mappingContext).delete(eq(getMappingIid(ifaceName, "test-instance")));
+ verify(mappingContext).delete(eq(getMappingIid(IFACE_NAME, IFC_TEST_INSTANCE)));
}
@Test
final Gre gre = generateGre();
whenGreAddDelTunnelThenFailure();
- doReturn(getMapping(ifaceName, 1)).when(mappingContext).read(getMappingIid(ifaceName, "test-instance"));
+ mockMapping(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(getMappingIid(ifaceName, "test-instance")));
+ verify(mappingContext, times(0)).delete(eq(getMappingIid(IFACE_NAME, IFC_TEST_INSTANCE)));
return;
}
fail("WriteFailedException.DeleteFailedException was expected");
import static org.mockito.Mockito.verify;
import static org.mockito.MockitoAnnotations.initMocks;
-import com.google.common.base.Optional;
-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.v3po.test.ContextTestUtils;
import io.fd.honeycomb.translate.v3po.test.TestHelperUtils;
import io.fd.honeycomb.translate.v3po.util.NamingContext;
import io.fd.honeycomb.translate.v3po.util.TagRewriteOperation;
+import io.fd.honeycomb.translate.write.WriteContext;
import io.fd.honeycomb.translate.write.WriteFailedException;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
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;
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;
+ private static final String IFC_TEST_INSTANCE = "ifc-test-instance";
+ private static final String IF_NAME = "local0";
+ private static final String VLAN_IF_NAME = "local0.1";
+ private static final int VLAN_IF_ID = 1;
+ private static final int VLAN_IF_INDEX = 11;
+ private InstanceIdentifier<Rewrite> VLAN_IID;
@Before
public void setUp() throws Exception {
initMocks(this);
- namingContext = new NamingContext("generatedSubInterfaceName", "test-instance");
+ namingContext = new NamingContext("generatedSubInterfaceName", IFC_TEST_INSTANCE);
doReturn(mappingContext).when(writeContext).getMappingContext();
customizer = new RewriteCustomizer(api, namingContext);
-
- final Optional<Mapping> ifcMapping = ContextTestUtils.getMapping(VLAN_IF_NAME, VLAN_IF_INDEX);
- doReturn(ifcMapping).when(mappingContext).read(any());
+ VLAN_IID = getVlanTagRewriteId(IF_NAME, VLAN_IF_ID);
+ ContextTestUtils.mockMapping(mappingContext, VLAN_IF_NAME, VLAN_IF_INDEX, IFC_TEST_INSTANCE);
}
- private InstanceIdentifier<Rewrite> getVlanTagRewriteId(final String name, final long index) {
+ private static InstanceIdentifier<Rewrite> getVlanTagRewriteId(final String name, final long index) {
final Class<ChildOf<? super SubInterface>> child = (Class)Rewrite.class;
final InstanceIdentifier id =
InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(name)).augmentation(
public void testCreate() throws Exception {
final TagRewriteOperation op = TagRewriteOperation.pop_2;
final Rewrite vlanTagRewrite = generateRewrite(op);
- final InstanceIdentifier<Rewrite> id = getVlanTagRewriteId(VLAN_IF_NAME, VLAN_IF_ID);
whenL2InterfaceVlanTagRewriteThenSuccess();
- customizer.writeCurrentAttributes(id, vlanTagRewrite, writeContext);
+ customizer.writeCurrentAttributes(VLAN_IID, vlanTagRewrite, writeContext);
verifyL2InterfaceVlanTagRewriteWasInvoked(generateL2InterfaceVlanTagRewrite(VLAN_IF_INDEX, op));
}
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<Rewrite> id = getVlanTagRewriteId(subIfaceName, subifIndex);
whenL2InterfaceVlanTagRewriteThenFailure();
try {
- customizer.writeCurrentAttributes(id, vlanTagRewrite, writeContext);
+ customizer.writeCurrentAttributes(VLAN_IID, vlanTagRewrite, writeContext);
} catch (WriteFailedException.CreateFailedException e) {
assertTrue(e.getCause() instanceof VppBaseCallException);
verifyL2InterfaceVlanTagRewriteWasInvoked(generateL2InterfaceVlanTagRewrite(VLAN_IF_INDEX, op));
public void testUpdate() throws Exception {
final Rewrite before = generateRewrite(TagRewriteOperation.pop_2);
final Rewrite after = generateRewrite(TagRewriteOperation.pop_1);
- final InstanceIdentifier<Rewrite> id = getVlanTagRewriteId(VLAN_IF_NAME, VLAN_IF_ID);
whenL2InterfaceVlanTagRewriteThenSuccess();
- customizer.updateCurrentAttributes(id, before, after, writeContext);
+ customizer.updateCurrentAttributes(VLAN_IID, before, after, writeContext);
verifyL2InterfaceVlanTagRewriteWasInvoked(
generateL2InterfaceVlanTagRewrite(VLAN_IF_INDEX, TagRewriteOperation.pop_1));
public void testUpdateFailed() throws Exception {
final Rewrite before = generateRewrite(TagRewriteOperation.pop_2);
final Rewrite after = generateRewrite(TagRewriteOperation.pop_1);
- final InstanceIdentifier<Rewrite> id = getVlanTagRewriteId(VLAN_IF_NAME, VLAN_IF_ID);
whenL2InterfaceVlanTagRewriteThenFailure();
try {
- customizer.updateCurrentAttributes(id, before, after, writeContext);
+ customizer.updateCurrentAttributes(VLAN_IID, before, after, writeContext);
} catch (WriteFailedException.UpdateFailedException e) {
assertTrue(e.getCause() instanceof VppBaseCallException);
verifyL2InterfaceVlanTagRewriteWasInvoked(generateL2InterfaceVlanTagRewrite(VLAN_IF_INDEX,
@Test
public void testDelete() throws Exception {
- final InstanceIdentifier<Rewrite> id = getVlanTagRewriteId(VLAN_IF_NAME, VLAN_IF_ID);
-
whenL2InterfaceVlanTagRewriteThenSuccess();
- customizer.deleteCurrentAttributes(id, null, writeContext);
+ customizer.deleteCurrentAttributes(VLAN_IID, null, writeContext);
verifyL2InterfaceVlanTagRewriteDeleteWasInvoked();
}
@Test
public void testDeleteFailed() throws Exception {
- final InstanceIdentifier<Rewrite> id = getVlanTagRewriteId(VLAN_IF_NAME, VLAN_IF_ID);
-
whenL2InterfaceVlanTagRewriteThenFailure();
try {
- customizer.deleteCurrentAttributes(id, null, writeContext);
+ customizer.deleteCurrentAttributes(VLAN_IID, null, writeContext);
} catch (WriteFailedException.DeleteFailedException e) {
Assert.assertTrue(e.getCause() instanceof VppBaseCallException);
verifyL2InterfaceVlanTagRewriteDeleteWasInvoked();
import static org.mockito.Mockito.verify;
import static org.mockito.MockitoAnnotations.initMocks;
-import com.google.common.base.Optional;
import io.fd.honeycomb.translate.MappingContext;
import io.fd.honeycomb.translate.v3po.test.ContextTestUtils;
import io.fd.honeycomb.translate.v3po.test.TestHelperUtils;
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;
private NamingContext namingContext;
private SubInterfaceCustomizer customizer;
- public static final String SUPER_IF_NAME = "local0";
- public static final int SUPER_IF_ID = 1;
+ private static final String IFC_TEST_INSTANCE = "ifc-test-instance";
+ private static final String SUPER_IF_NAME = "local0";
+ private static final int SUPER_IF_ID = 1;
private static final String SUB_IFACE_NAME = "local0.11";
private static final int SUBIF_INDEX = 11;
@Before
public void setUp() throws Exception {
initMocks(this);
- namingContext = new NamingContext("generatedSubInterfaceName", "test-instance");
+ namingContext = new NamingContext("generatedSubInterfaceName", IFC_TEST_INSTANCE);
doReturn(mappingContext).when(writeContext).getMappingContext();
// TODO HONEYCOMB-116 create base class for tests using vppApi
customizer = new SubInterfaceCustomizer(api, namingContext);
- doReturn(ContextTestUtils.getMapping(SUPER_IF_NAME, SUPER_IF_ID)).when(mappingContext)
- .read(ContextTestUtils.getMappingIid(SUPER_IF_NAME, "test-instance"));
+ ContextTestUtils.mockMapping(mappingContext, SUB_IFACE_NAME, SUBIF_INDEX, IFC_TEST_INSTANCE);
+ ContextTestUtils.mockMapping(mappingContext, SUPER_IF_NAME, SUPER_IF_ID, IFC_TEST_INSTANCE);
}
private SubInterface generateSubInterface(final boolean enabled, final List<Tag> tagList) {
verifyCreateSubifWasInvoked(generateSubInterfaceRequest(SUPER_IF_ID, CTAG_ID, false));
verify(mappingContext)
- .put(eq(ContextTestUtils.getMappingIid(SUB_IFACE_NAME, "test-instance")), eq(
+ .put(eq(ContextTestUtils.getMappingIid(SUB_IFACE_NAME, IFC_TEST_INSTANCE)), eq(
ContextTestUtils.getMapping(SUB_IFACE_NAME, 0).get()));
}
verifyCreateSubifWasInvoked(generateSubInterfaceRequest(SUPER_IF_ID, CTAG_ANY_ID, true));
verify(mappingContext)
- .put(eq(ContextTestUtils.getMappingIid(SUB_IFACE_NAME, "test-instance")), eq(
+ .put(eq(ContextTestUtils.getMappingIid(SUB_IFACE_NAME, IFC_TEST_INSTANCE)), eq(
ContextTestUtils.getMapping(SUB_IFACE_NAME, 0).get()));
}
assertTrue(e.getCause() instanceof VppBaseCallException);
verifyCreateSubifWasInvoked(generateSubInterfaceRequest(SUPER_IF_ID, CTAG_ID, false));
verify(mappingContext, times(0)).put(
- eq(ContextTestUtils.getMappingIid(SUPER_IF_NAME, "test-instance")),
+ eq(ContextTestUtils.getMappingIid(SUPER_IF_NAME, IFC_TEST_INSTANCE)),
eq(ContextTestUtils.getMapping(SUPER_IF_NAME, 0).get()));
return;
}
final InstanceIdentifier<SubInterface> id = getSubInterfaceId(SUPER_IF_NAME, SUBIF_INDEX);
whenSwInterfaceSetFlagsThenSuccess();
- final Optional<Mapping> ifcMapping = ContextTestUtils.getMapping(SUPER_IF_NAME, SUBIF_INDEX);
- doReturn(ifcMapping).when(mappingContext).read(any());
-
customizer.updateCurrentAttributes(id, before, after, writeContext);
verifySwInterfaceSetFlagsWasInvoked(generateSwInterfaceEnableRequest(SUBIF_INDEX));
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.test.ContextTestUtils;
import io.fd.honeycomb.translate.v3po.util.NamingContext;
+import io.fd.honeycomb.translate.write.WriteContext;
import java.util.concurrent.CompletableFuture;
import org.junit.Before;
import org.junit.Test;
public class TapCustomizerTest {
+ private static final String IFC_TEST_INSTANCE = "ifc-test-instance";
+
@Mock
private FutureJVppCore vppApi;
@Mock
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 NamingContext ctx = new NamingContext("ifcintest", IFC_TEST_INSTANCE);
final ModificationCache toBeReturned = new ModificationCache();
doReturn(toBeReturned).when(writeContext).getModificationCache();
doReturn(mappingContext).when(writeContext).getMappingContext();
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(
+ verify(mappingContext).put(eq(ContextTestUtils.getMappingIid("tap", IFC_TEST_INSTANCE)), eq(
ContextTestUtils.getMapping("tap", 0).get()));
- verify(mappingContext).put(eq(ContextTestUtils.getMappingIid("tap2", "test-instance")), eq(
+ verify(mappingContext).put(eq(ContextTestUtils.getMappingIid("tap2", IFC_TEST_INSTANCE)), eq(
ContextTestUtils.getMapping("tap2", 1).get()));
}
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"));
+
+ ContextTestUtils.mockMapping(mappingContext, "tap", 1, IFC_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(
+ verify(mappingContext).put(eq(ContextTestUtils.getMappingIid("tap", IFC_TEST_INSTANCE)), eq(
ContextTestUtils.getMapping("tap", 0).get()));
}
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"));
+ ContextTestUtils.mockMapping(mappingContext, "tap", 1, IFC_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")));
+ verify(mappingContext).delete(eq(ContextTestUtils.getMappingIid("tap", IFC_TEST_INSTANCE)));
}
private InstanceIdentifier<Tap> getTapId(final String tap) {
public void testUpdateCurrentAttributes() throws Exception {
final VhostUser vhostUserBefore = generateVhostUser(VhostUserRole.Client, "socketName0");
final VhostUser vhostUserAfter = generateVhostUser(VhostUserRole.Server, "socketName1");
- doReturn(ContextTestUtils.getMapping(IFACE_NAME, IFACE_ID)).when(mappingContext).read(
- ContextTestUtils.getMappingIid(IFACE_NAME, "test-instance"));
+ ContextTestUtils.mockMapping(mappingContext, IFACE_NAME, IFACE_ID, "test-instance");
whenModifyVhostUserIfThenSuccess();
public void testUpdateCurrentAttributesFailed() throws Exception {
final VhostUser vhostUserBefore = generateVhostUser(VhostUserRole.Client, "socketName0");
final VhostUser vhostUserAfter = generateVhostUser(VhostUserRole.Server, "socketName1");
- doReturn(ContextTestUtils.getMapping(IFACE_NAME, IFACE_ID)).when(mappingContext).read(
- ContextTestUtils.getMappingIid(IFACE_NAME, "test-instance"));
+ ContextTestUtils.mockMapping(mappingContext, IFACE_NAME, IFACE_ID, "test-instance");
whenModifyVhostUserIfThenFailure();
@Test
public void testDeleteCurrentAttributes() throws Exception {
final VhostUser vhostUser = generateVhostUser(VhostUserRole.Client, "socketName");
- doReturn(ContextTestUtils.getMapping(IFACE_NAME, IFACE_ID)).when(mappingContext).read(
- ContextTestUtils.getMappingIid(IFACE_NAME, "test-instance"));
+ ContextTestUtils.mockMapping(mappingContext, IFACE_NAME, IFACE_ID, "test-instance");
whenDeleteVhostUserIfThenSuccess();
@Test
public void testDeleteCurrentAttributesFailed() throws Exception {
final VhostUser vhostUser = generateVhostUser(VhostUserRole.Client, "socketName");
- doReturn(ContextTestUtils.getMapping(IFACE_NAME, IFACE_ID)).when(mappingContext).read(
- ContextTestUtils.getMappingIid(IFACE_NAME, "test-instance"));
+ ContextTestUtils.mockMapping(mappingContext, IFACE_NAME, IFACE_ID, "test-instance");
whenDeleteVhostUserIfThenFailure();
import static io.fd.honeycomb.translate.v3po.test.ContextTestUtils.getMapping;
import static io.fd.honeycomb.translate.v3po.test.ContextTestUtils.getMappingIid;
-import static java.util.Collections.singletonList;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.when;
import static org.mockito.MockitoAnnotations.initMocks;
-import com.google.common.base.Optional;
import com.google.common.net.InetAddresses;
import io.fd.honeycomb.translate.MappingContext;
import io.fd.honeycomb.translate.ModificationCache;
import io.fd.honeycomb.translate.v3po.DisabledInterfacesManager;
+import io.fd.honeycomb.translate.v3po.test.ContextTestUtils;
import io.fd.honeycomb.translate.v3po.test.TestHelperUtils;
import io.fd.honeycomb.translate.v3po.util.NamingContext;
import io.fd.honeycomb.translate.write.WriteContext;
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;
-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.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;
ifaceName = "eth0";
id = InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(ifaceName))
- .augmentation(VppInterfaceAugmentation.class).child(Vxlan.class);
+ .augmentation(VppInterfaceAugmentation.class).child(Vxlan.class);
}
private void whenVxlanAddDelTunnelThenSuccess()
* Failure response send
*/
private void whenVxlanAddDelTunnelThenFailure()
- throws ExecutionException, InterruptedException, VppInvocationException {
+ throws ExecutionException, InterruptedException, VppInvocationException {
doReturn(TestHelperUtils.<VxlanAddDelTunnelReply>createFutureException()).when(api)
- .vxlanAddDelTunnel(any(VxlanAddDelTunnel.class));
+ .vxlanAddDelTunnel(any(VxlanAddDelTunnel.class));
}
private VxlanAddDelTunnel verifyVxlanAddDelTunnelWasInvoked(final Vxlan vxlan) throws VppInvocationException {
assertEquals(0, actual.isIpv6);
assertEquals(-1, actual.decapNextIndex);
assertArrayEquals(InetAddresses.forString(vxlan.getSrc().getIpv4Address().getValue()).getAddress(),
- actual.srcAddress);
+ actual.srcAddress);
assertArrayEquals(InetAddresses.forString(vxlan.getDst().getIpv4Address().getValue()).getAddress(),
- actual.dstAddress);
+ actual.dstAddress);
assertEquals(vxlan.getEncapVrfId().intValue(), actual.encapVrfId);
assertEquals(vxlan.getVni().getValue().intValue(), actual.vni);
return actual;
final Vxlan vxlan = generateVxlan();
whenVxlanAddDelTunnelThenSuccess();
-
- doReturn(Optional.absent())
- .when(mappingContext).read(getMappingIid(ifaceName, "test-instance").firstIdentifierOf(Mappings.class));
+ ContextTestUtils.mockEmptyMapping(mappingContext, ifaceName, "test-instance");
customizer.writeCurrentAttributes(id, vxlan, writeContext);
verifyVxlanAddWasInvoked(vxlan);
final Vxlan vxlan = generateVxlan();
whenVxlanAddDelTunnelThenSuccess();
-
- doReturn(Optional.absent())
- .when(mappingContext).read(getMappingIid(ifaceName, "test-instance").firstIdentifierOf(Mappings.class));
+ ContextTestUtils.mockEmptyMapping(mappingContext, ifaceName, "test-instance");
doReturn(true).when(disableContext).isInterfaceDisabled(0, mappingContext);
customizer.writeCurrentAttributes(id, vxlan, writeContext);
@Test
public void testWriteCurrentAttributesMappingAlreadyPresent() throws Exception {
final Vxlan vxlan = generateVxlan();
+ final int ifaceId = 0;
whenVxlanAddDelTunnelThenSuccess();
- final Optional<Mapping> ifcMapping = getMapping(ifaceName, 0);
-
- doReturn(Optional.of(new MappingsBuilder().setMapping(singletonList(ifcMapping.get())).build()))
- .when(mappingContext).read(getMappingIid(ifaceName, "test-instance").firstIdentifierOf(Mappings.class));
+ ContextTestUtils.mockMapping(mappingContext, ifaceName, ifaceId, "test-instance");
customizer.writeCurrentAttributes(id, vxlan, writeContext);
verifyVxlanAddWasInvoked(vxlan);
// Remove the first mapping before putting in the new one
verify(mappingContext).delete(eq(getMappingIid(ifaceName, "test-instance")));
- verify(mappingContext).put(eq(getMappingIid(ifaceName, "test-instance")), eq(ifcMapping.get()));
+ verify(mappingContext)
+ .put(eq(getMappingIid(ifaceName, "test-instance")), eq(getMapping(ifaceName, ifaceId).get()));
}
@Test
assertTrue(e.getCause() instanceof VppBaseCallException);
verifyVxlanAddWasInvoked(vxlan);
// Mapping not stored due to failure
- verify(mappingContext, times(0)).put(eq(getMappingIid(ifaceName, "test-instance")), eq(getMapping(ifaceName, 0).get()));
+ verify(mappingContext, times(0))
+ .put(eq(getMappingIid(ifaceName, "test-instance")), eq(getMapping(ifaceName, 0).get()));
return;
}
fail("WriteFailedException.CreateFailedException was expected");
final Vxlan vxlan = generateVxlan();
whenVxlanAddDelTunnelThenSuccess();
- doReturn(getMapping(ifaceName, 1)).when(mappingContext).read(getMappingIid(ifaceName, "test-instance"));
+ ContextTestUtils.mockMapping(mappingContext, ifaceName, 1, "test-instance");
customizer.deleteCurrentAttributes(id, vxlan, writeContext);
verifyVxlanDeleteWasInvoked(vxlan);
final Vxlan vxlan = generateVxlan();
whenVxlanAddDelTunnelThenFailure();
- doReturn(getMapping(ifaceName, 1)).when(mappingContext).read(getMappingIid(ifaceName, "test-instance"));
+ ContextTestUtils.mockMapping(mappingContext, ifaceName, 1, "test-instance");
try {
customizer.deleteCurrentAttributes(id, vxlan, writeContext);
package io.fd.honeycomb.translate.v3po.interfaces;
-import static java.util.Collections.singletonList;
+import static io.fd.honeycomb.translate.v3po.test.ContextTestUtils.getMapping;
+import static io.fd.honeycomb.translate.v3po.test.ContextTestUtils.getMappingIid;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.when;
import static org.mockito.MockitoAnnotations.initMocks;
-import com.google.common.base.Optional;
import com.google.common.net.InetAddresses;
+import io.fd.honeycomb.translate.MappingContext;
import io.fd.honeycomb.translate.ModificationCache;
import io.fd.honeycomb.translate.v3po.DisabledInterfacesManager;
import io.fd.honeycomb.translate.v3po.test.ContextTestUtils;
import io.fd.honeycomb.translate.v3po.util.NamingContext;
import io.fd.honeycomb.translate.write.WriteContext;
import io.fd.honeycomb.translate.write.WriteFailedException;
-import io.fd.honeycomb.translate.MappingContext;
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.mockito.Mock;
-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.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;
customizer = new VxlanGpeCustomizer(api, namingContext, interfaceDisableContext);
- ifaceName = "eth0";
+ ifaceName = "elth0";
id = InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(ifaceName))
.augmentation(VppInterfaceAugmentation.class).child(VxlanGpe.class);
}
final VxlanGpe vxlanGpe = generateVxlanGpe();
whenVxlanGpeAddDelTunnelThenSuccess();
-
- doReturn(Optional.absent())
- .when(mappingContext).read(ContextTestUtils.getMappingIid(ifaceName, "test-instance").firstIdentifierOf(Mappings.class));
+ ContextTestUtils.mockEmptyMapping(mappingContext, ifaceName, "test-instance");
customizer.writeCurrentAttributes(id, vxlanGpe, writeContext);
verifyVxlanGpeAddWasInvoked(vxlanGpe);
- verify(mappingContext).put(eq(ContextTestUtils.getMappingIid(ifaceName, "test-instance")), eq(
- ContextTestUtils.getMapping(ifaceName, 0).get()));
+ verify(mappingContext).put(eq(getMappingIid(ifaceName, "test-instance")), eq(
+ getMapping(ifaceName, 0).get()));
}
@Test
public void testWriteCurrentAttributesMappingAlreadyPresent() throws Exception {
final VxlanGpe vxlanGpe = generateVxlanGpe();
+ final int ifaceId = 0;
whenVxlanGpeAddDelTunnelThenSuccess();
- final Optional<Mapping> ifcMapping = ContextTestUtils.getMapping(ifaceName, 0);
-
- doReturn(Optional.of(new MappingsBuilder().setMapping(singletonList(ifcMapping.get())).build()))
- .when(mappingContext).read(ContextTestUtils.getMappingIid(ifaceName, "test-instance").firstIdentifierOf(Mappings.class));
+ ContextTestUtils.mockMapping(mappingContext, ifaceName, ifaceId, "test-instance");
customizer.writeCurrentAttributes(id, vxlanGpe, writeContext);
verifyVxlanGpeAddWasInvoked(vxlanGpe);
// Remove the first mapping before putting in the new one
- verify(mappingContext).delete(eq(ContextTestUtils.getMappingIid(ifaceName, "test-instance")));
- verify(mappingContext).put(eq(ContextTestUtils.getMappingIid(ifaceName, "test-instance")), eq(ifcMapping.get()));
+ verify(mappingContext).delete(eq(getMappingIid(ifaceName, "test-instance")));
+ verify(mappingContext).put(eq(getMappingIid(ifaceName, "test-instance")),
+ eq(getMapping(ifaceName, ifaceId).get()));
}
@Test
verifyVxlanGpeAddWasInvoked(vxlanGpe);
// Mapping not stored due to failure
verify(mappingContext, times(0))
- .put(eq(ContextTestUtils.getMappingIid(ifaceName, "test-instance")), eq(
- ContextTestUtils.getMapping(ifaceName, 0).get()));
+ .put(eq(getMappingIid(ifaceName, "test-instance")), eq(
+ getMapping(ifaceName, 0).get()));
return;
}
fail("WriteFailedException.CreateFailedException was expected");
final VxlanGpe vxlanGpe = generateVxlanGpe();
whenVxlanGpeAddDelTunnelThenSuccess();
- doReturn(ContextTestUtils.getMapping(ifaceName, 1)).when(mappingContext).read(
- ContextTestUtils.getMappingIid(ifaceName, "test-instance"));
+ ContextTestUtils.mockMapping(mappingContext, ifaceName, 1, "test-instance");
customizer.deleteCurrentAttributes(id, vxlanGpe, writeContext);
verifyVxlanGpeDeleteWasInvoked(vxlanGpe);
- verify(mappingContext).delete(eq(ContextTestUtils.getMappingIid(ifaceName, "test-instance")));
+ verify(mappingContext).delete(eq(getMappingIid(ifaceName, "test-instance")));
}
@Test
final VxlanGpe vxlanGpe = generateVxlanGpe();
whenVxlanGpeAddDelTunnelThenFailure();
- doReturn(ContextTestUtils.getMapping(ifaceName, 1)).when(mappingContext).read(
- ContextTestUtils.getMappingIid(ifaceName, "test-instance"));
+ ContextTestUtils.mockMapping(mappingContext, ifaceName, 1, "test-instance");
try {
customizer.deleteCurrentAttributes(id, vxlanGpe, writeContext);
} catch (WriteFailedException.DeleteFailedException e) {
assertTrue(e.getCause() instanceof VppBaseCallException);
verifyVxlanGpeDeleteWasInvoked(vxlanGpe);
- verify(mappingContext, times(0)).delete(eq(ContextTestUtils.getMappingIid(ifaceName, "test-instance")));
+ verify(mappingContext, times(0)).delete(eq(getMappingIid(ifaceName, "test-instance")));
return;
}
fail("WriteFailedException.DeleteFailedException was expected");
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
-import com.google.common.base.Optional;
import com.google.common.io.BaseEncoding;
import io.fd.honeycomb.translate.MappingContext;
+import io.fd.honeycomb.translate.v3po.test.ContextTestUtils;
import io.fd.honeycomb.translate.v3po.util.NamingContext;
import io.fd.honeycomb.translate.v3po.util.TranslateUtils;
import io.fd.honeycomb.translate.write.WriteContext;
public class Ipv4NeighbourCustomizerTest {
+ private static final String IFC_CTX_NAME = "ifc-test-instance";
+ private static final String IFACE_NAME = "parent";
+ private static final int IFACE_ID = 5;
+
@Mock
private FutureJVppCore jvpp;
@Before
public void init() {
MockitoAnnotations.initMocks(this);
+ when(context.getMappingContext()).thenReturn(mappingContext);
- namingContext = new NamingContext("prefix", "instance");
- namingContext.addName(5, "parent", mappingContext);
+ namingContext = new NamingContext("prefix", IFC_CTX_NAME);
+ ContextTestUtils.mockMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME);
customizer = new Ipv4NeighbourCustomizer(jvpp,namingContext);
requestCaptor = ArgumentCaptor.forClass(IpNeighborAddDel.class);
-
CompletableFuture<IpNeighborAddDelReply> future = new CompletableFuture<>();
future.complete(new IpNeighborAddDelReply());
-
- when(context.getMappingContext()).thenReturn(mappingContext);
- when(mapping.getIndex()).thenReturn(5);
- when(mapping.getName()).thenReturn("parent");
- when(mappingContext.read(Mockito.any())).thenReturn(Optional.fromNullable(mapping));
when(jvpp.ipNeighborAddDel(Mockito.any(IpNeighborAddDel.class))).thenReturn(future);
}
@Test
public void testWriteCurrentAttributes() throws WriteFailedException {
- InterfaceKey intfKey = new InterfaceKey("parent");
+ InterfaceKey intfKey = new InterfaceKey(IFACE_NAME);
InstanceIdentifier<Neighbor> id = InstanceIdentifier.builder(Interfaces.class).child(Interface.class, intfKey)
.augmentation(Interface1.class).child(Ipv4.class).child(Neighbor.class).build();
@Test
public void testDeleteCurrentAttributes() throws WriteFailedException {
- InterfaceKey intfKey = new InterfaceKey("parent");
+ InterfaceKey intfKey = new InterfaceKey(IFACE_NAME);
InstanceIdentifier<Neighbor> id = InstanceIdentifier.builder(Interfaces.class).child(Interface.class, intfKey)
.augmentation(Interface1.class).child(Ipv4.class).child(Neighbor.class).build();
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
-import com.google.common.base.Optional;
-import com.google.common.collect.Lists;
import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
import io.fd.honeycomb.translate.v3po.test.ContextTestUtils;
import io.fd.honeycomb.translate.v3po.test.ReaderCustomizerTest;
import io.fd.honeycomb.translate.v3po.util.NamingContext;
import io.fd.honeycomb.translate.v3po.vppclassifier.VppClassifierContextManager;
-import java.util.List;
import java.util.concurrent.CompletableFuture;
import org.junit.Test;
import org.mockito.Mock;
-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.interfaces.state._interface.Acl;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces.state._interface.AclBuilder;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
import org.openvpp.jvpp.core.dto.ClassifyTableByInterface;
import org.openvpp.jvpp.core.dto.ClassifyTableByInterfaceReply;
private static final int TABLE_INDEX = 123;
private static final String TABLE_NAME = "table123";
- private static final String IFC_TEST_INSTANCE = "ifc-test-instance";
+ private static final String IFC_CTX_NAME = "ifc-test-instance";
private NamingContext interfaceContext;
@Override
public void setUpBefore() {
- interfaceContext = new NamingContext("generatedIfaceName", IFC_TEST_INSTANCE);
-
- final KeyedInstanceIdentifier<Mapping, MappingKey> ifcMappingKey = ContextTestUtils
- .getMappingIid(IF_NAME, IFC_TEST_INSTANCE);
- final Optional<Mapping> ifcMapping = ContextTestUtils.getMapping(IF_NAME, IF_INDEX);
- doReturn(ifcMapping).when(mappingContext).read(ifcMappingKey);
-
- final List<Mapping> allIfcMappings = Lists.newArrayList(ifcMapping.get());
- final Mappings allIfcMappingsBaObject = new MappingsBuilder().setMapping(allIfcMappings).build();
- doReturn(Optional.of(allIfcMappingsBaObject)).when(mappingContext)
- .read(ifcMappingKey.firstIdentifierOf(Mappings.class));
+ interfaceContext = new NamingContext("generatedIfaceName", IFC_CTX_NAME);
+ ContextTestUtils.mockMapping(mappingContext, IF_NAME, IF_INDEX, IFC_CTX_NAME);
}
@Override
package io.fd.honeycomb.translate.v3po.interfacesstate;
-import static io.fd.honeycomb.translate.v3po.test.ContextTestUtils.getMapping;
-import static io.fd.honeycomb.translate.v3po.test.ContextTestUtils.getMappingIid;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import com.google.common.collect.Lists;
import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
+import io.fd.honeycomb.translate.v3po.test.ContextTestUtils;
import io.fd.honeycomb.translate.v3po.test.ReaderCustomizerTest;
import io.fd.honeycomb.translate.v3po.util.NamingContext;
import java.net.InetAddress;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces.state._interface.GreBuilder;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.openvpp.jvpp.VppInvocationException;
-import org.openvpp.jvpp.core.dto.SwInterfaceDetails;
import org.openvpp.jvpp.core.dto.GreTunnelDetails;
import org.openvpp.jvpp.core.dto.GreTunnelDetailsReplyDump;
import org.openvpp.jvpp.core.dto.GreTunnelDump;
+import org.openvpp.jvpp.core.dto.SwInterfaceDetails;
public class GreCustomizerTest extends ReaderCustomizerTest<Gre, GreBuilder> {
+ private static final String IFACE_NAME = "ifc1";
+ private static final int IFACE_ID = 0;
+ private static final String IFC_CTX_NAME = "ifc-test-instance";
+
private NamingContext interfacesContext;
static final InstanceIdentifier<Gre> IID =
- InstanceIdentifier.create(InterfacesState.class).child(Interface.class, new InterfaceKey("ifc1"))
+ InstanceIdentifier.create(InterfacesState.class).child(Interface.class, new InterfaceKey(IFACE_NAME))
.augmentation(VppInterfaceStateAugmentation.class).child(Gre.class);
public GreCustomizerTest() {
@Override
public void setUpBefore() {
- interfacesContext = new NamingContext("gre-tunnel", "test-instance");
- doReturn(getMapping("ifc1", 0)).when(mappingContext).read(getMappingIid("ifc1", "test-instance"));
+ interfacesContext = new NamingContext("gre-tunnel", IFC_CTX_NAME);
+ ContextTestUtils.mockMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME);
final SwInterfaceDetails v = new SwInterfaceDetails();
v.interfaceName = "gre-tunnel4".getBytes();
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyZeroInteractions;
-import com.google.common.base.Optional;
-import com.google.common.collect.Lists;
import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
import io.fd.honeycomb.translate.v3po.DisabledInterfacesManager;
import io.fd.honeycomb.translate.v3po.test.ContextTestUtils;
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;
-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.InterfacesStateBuilder;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.InterfaceBuilder;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.InterfaceKey;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
import org.openvpp.jvpp.VppInvocationException;
import org.openvpp.jvpp.core.dto.SwInterfaceDetails;
import org.openvpp.jvpp.core.dto.SwInterfaceDump;
public class InterfaceCustomizerTest extends
ListReaderCustomizerTest<Interface, InterfaceKey, InterfaceBuilder> {
+ private static final String IFC_CTX_NAME = "ifc-test-instance";
+ private static final String IFACE0_NAME = "eth0";
+ private static final String IFACE1_NAME = "eth1";
+ private static final String SUB_IFACE_NAME = "eth1.1";
+ private static final int IFACE0_ID = 0;
+ private static final int IFACE1_ID = 1;
+ private static final int SUB_IFACE_ID = 2;
+
private NamingContext interfacesContext;
@Mock
private DisabledInterfacesManager interfaceDisableContext;
@Override
public void setUpBefore() {
- interfacesContext = new NamingContext("generatedIfaceName", "test-instance");
+ interfacesContext = new NamingContext("generatedIfaceName", IFC_CTX_NAME);
+ ContextTestUtils.mockMapping(mappingContext, IFACE0_NAME, IFACE0_ID, IFC_CTX_NAME);
+ ContextTestUtils.mockMapping(mappingContext, IFACE1_NAME, IFACE1_ID, IFC_CTX_NAME);
+ ContextTestUtils.mockMapping(mappingContext, SUB_IFACE_NAME, SUB_IFACE_ID, IFC_CTX_NAME);
}
@Override
protected ReaderCustomizer<Interface, InterfaceBuilder> initCustomizer() {
- final KeyedInstanceIdentifier<Mapping, MappingKey> eth0Id = ContextTestUtils
- .getMappingIid("eth0", "test-instance");
- final KeyedInstanceIdentifier<Mapping, MappingKey> eth1Id = ContextTestUtils
- .getMappingIid("eth1", "test-instance");
- final KeyedInstanceIdentifier<Mapping, MappingKey> subEth1Id = ContextTestUtils
- .getMappingIid("eth1.1", "test-instance");
- final Optional<Mapping> eth0 = ContextTestUtils.getMapping("eth0", 0);
- final Optional<Mapping> eth1 = ContextTestUtils.getMapping("eth1", 1);
- final Optional<Mapping> subEth1 = ContextTestUtils.getMapping("eth1.1", 2);
-
- final List<Mapping> allMappings =
- Lists.newArrayList(ContextTestUtils.getMapping("eth0", 0).get(), ContextTestUtils.getMapping("eth1", 1).get(), ContextTestUtils
- .getMapping("eth1.1", 2).get());
- final Mappings allMappingsBaObject = new MappingsBuilder().setMapping(allMappings).build();
- doReturn(Optional.of(allMappingsBaObject)).when(mappingContext).read(eth0Id.firstIdentifierOf(Mappings.class));
-
- doReturn(eth0).when(mappingContext).read(eth0Id);
- doReturn(eth1).when(mappingContext).read(eth1Id);
- doReturn(subEth1).when(mappingContext).read(subEth1Id);
-
return new InterfaceCustomizer(api, interfacesContext, interfaceDisableContext);
}
@Test
public void testReadCurrentAttributes() throws Exception {
- final String ifaceName = "eth0";
final InstanceIdentifier<Interface> id = InstanceIdentifier.create(InterfacesState.class)
- .child(Interface.class, new InterfaceKey(ifaceName));
+ .child(Interface.class, new InterfaceKey(IFACE0_NAME));
final InterfaceBuilder builder = getCustomizer().getBuilder(id);
final SwInterfaceDetails iface = new SwInterfaceDetails();
- iface.interfaceName = ifaceName.getBytes();
+ iface.interfaceName = IFACE0_NAME.getBytes();
iface.swIfIndex = 0;
iface.linkSpeed = 1;
iface.l2AddressLength = 6;
getCustomizer().readCurrentAttributes(id, builder, ctx);
- verifySwInterfaceDumpWasInvoked(1, ifaceName, 1);
+ verifySwInterfaceDumpWasInvoked(1, IFACE0_NAME, 1);
assertIfacesAreEqual(builder.build(), iface);
}
@Test
public void testReadCurrentAttributesFailed() throws Exception {
- final String ifaceName = "eth0";
+ final String ifaceName = IFACE0_NAME;
final InstanceIdentifier<Interface> id = InstanceIdentifier.create(InterfacesState.class)
.child(Interface.class, new InterfaceKey(ifaceName));
final InterfaceBuilder builder = getCustomizer().getBuilder(id);
@Test
public void testReadSubInterface() throws Exception {
- final String ifaceName = "eth1.1";
final InstanceIdentifier<Interface> id = InstanceIdentifier.create(InterfacesState.class)
- .child(Interface.class, new InterfaceKey(ifaceName));
+ .child(Interface.class, new InterfaceKey(SUB_IFACE_NAME));
final InterfaceBuilder builder = mock(InterfaceBuilder.class);
final SwInterfaceDetails iface = new SwInterfaceDetails();
- iface.interfaceName = ifaceName.getBytes();
+ iface.interfaceName = SUB_IFACE_NAME.getBytes();
iface.swIfIndex = 2;
iface.supSwIfIndex = 1;
iface.subId = 1;
getCustomizer().readCurrentAttributes(id, builder, ctx);
- verifySwInterfaceDumpWasInvoked(1, ifaceName, 1);
+ verifySwInterfaceDumpWasInvoked(1, SUB_IFACE_NAME, 1);
verifyZeroInteractions(builder);
}
final InstanceIdentifier<Interface> id = InstanceIdentifier.create(InterfacesState.class)
.child(Interface.class);
- final String swIf0Name = "eth0";
final SwInterfaceDetails swIf0 = new SwInterfaceDetails();
swIf0.swIfIndex = 0;
- swIf0.interfaceName = swIf0Name.getBytes();
- final String swIf1Name = "eth1";
+ swIf0.interfaceName = IFACE0_NAME.getBytes();
final SwInterfaceDetails swIf1 = new SwInterfaceDetails();
swIf1.swIfIndex = 1;
- swIf1.interfaceName = swIf1Name.getBytes();
- final String swSubIf1Name = "eth1.1";
+ swIf1.interfaceName = IFACE1_NAME.getBytes();
final SwInterfaceDetails swSubIf1 = new SwInterfaceDetails();
swSubIf1.swIfIndex = 2;
swSubIf1.subId = 1;
swSubIf1.supSwIfIndex = 1;
- swSubIf1.interfaceName = swSubIf1Name.getBytes();
+ swSubIf1.interfaceName = SUB_IFACE_NAME.getBytes();
InterfaceTestUtils.whenSwInterfaceDumpThenReturn(api, Arrays.asList(swIf0, swIf1, swSubIf1));
- final List<InterfaceKey> expectedIds = Arrays.asList(new InterfaceKey(swIf0Name), new InterfaceKey(swIf1Name));
+ final List<InterfaceKey> expectedIds = Arrays.asList(new InterfaceKey(IFACE0_NAME), new InterfaceKey(
+ IFACE1_NAME));
final List<InterfaceKey> actualIds = getCustomizer().getAllIds(id, ctx);
verifySwInterfaceDumpWasInvoked(0, "", 1);
doReturn(true).when(interfaceDisableContext).isInterfaceDisabled(1, mappingContext);
- final String swIf0Name = "eth0";
final SwInterfaceDetails swIf0 = new SwInterfaceDetails();
swIf0.swIfIndex = 0;
- swIf0.interfaceName = swIf0Name.getBytes();
- final String swIf1Name = "eth1";
+ swIf0.interfaceName = IFACE0_NAME.getBytes();
final SwInterfaceDetails swIf1 = new SwInterfaceDetails();
swIf1.swIfIndex = 1;
- swIf1.interfaceName = swIf1Name.getBytes();
+ swIf1.interfaceName = IFACE1_NAME.getBytes();
InterfaceTestUtils.whenSwInterfaceDumpThenReturn(api, Arrays.asList(swIf0, swIf1));
- final List<InterfaceKey> expectedIds = Arrays.asList(new InterfaceKey(swIf0Name));
+ final List<InterfaceKey> expectedIds = Arrays.asList(new InterfaceKey(IFACE0_NAME));
final List<InterfaceKey> actualIds = getCustomizer().getAllIds(id, ctx);
// disabled interface should not be on the list
package io.fd.honeycomb.translate.v3po.interfacesstate;
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 static org.mockito.Mockito.when;
-import com.google.common.base.Optional;
-import com.google.common.collect.Lists;
import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
import io.fd.honeycomb.translate.v3po.test.ContextTestUtils;
import io.fd.honeycomb.translate.v3po.test.ReaderCustomizerTest;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
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.l2.base.attributes.Interconnection;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.l2.base.attributes.interconnection.BridgeBasedBuilder;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
import org.openvpp.jvpp.VppInvocationException;
import org.openvpp.jvpp.core.dto.BridgeDomainDetails;
import org.openvpp.jvpp.core.dto.BridgeDomainDetailsReplyDump;
public class L2CustomizerTest extends ReaderCustomizerTest<L2, L2Builder> {
+ private static final String IFC_CTX_NAME = "ifc-test-instance";
+ private static final String BD_CTX_NAME = "bd-test-instance";
private NamingContext interfaceContext;
private NamingContext bridgeDomainContext;
@Override
public void setUpBefore() {
- interfaceContext = new NamingContext("generatedIfaceName", "ifc-test-instance");
- bridgeDomainContext = new NamingContext("generatedBDName", "bd-test-instance");
+ interfaceContext = new NamingContext("generatedIfaceName", IFC_CTX_NAME);
+ bridgeDomainContext = new NamingContext("generatedBDName", BD_CTX_NAME);
}
@Override
final int bdId = 1;
final String bdName = "bd001";
final String ifName = "eth0.sub0";
- final KeyedInstanceIdentifier<Mapping, MappingKey> ifcIid = ContextTestUtils
- .getMappingIid(ifName, "ifc-test-instance");
- doReturn(ContextTestUtils.getMapping(ifName, ifId)).when(mappingContext).read(ifcIid);
- final KeyedInstanceIdentifier<Mapping, MappingKey> bdIid = ContextTestUtils
- .getMappingIid(bdName, "bd-test-instance");
- doReturn(ContextTestUtils.getMapping(bdName, bdId)).when(mappingContext).read(bdIid);
-
- List<Mapping> allMappings = Lists.newArrayList(ContextTestUtils.getMapping(ifName, ifId).get());
- Mappings allMappingsBaObject = new MappingsBuilder().setMapping(allMappings).build();
- doReturn(Optional.of(allMappingsBaObject)).when(mappingContext).read(ifcIid.firstIdentifierOf(Mappings.class));
-
- allMappings = Lists.newArrayList(ContextTestUtils.getMapping(bdName, bdId).get());
- allMappingsBaObject = new MappingsBuilder().setMapping(allMappings).build();
- doReturn(Optional.of(allMappingsBaObject)).when(mappingContext).read(bdIid.firstIdentifierOf(Mappings.class));
+ ContextTestUtils.mockMapping(mappingContext, ifName, ifId, IFC_CTX_NAME);
+ ContextTestUtils.mockMapping(mappingContext, bdName, bdId, BD_CTX_NAME);
final SwInterfaceDetails ifaceDetails = new SwInterfaceDetails();
ifaceDetails.subId = ifId;
package io.fd.honeycomb.translate.v3po.interfacesstate;
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.translate.read.ReadFailedException;
import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
import io.fd.honeycomb.translate.v3po.test.ContextTestUtils;
-import io.fd.honeycomb.translate.read.ReadFailedException;
import io.fd.honeycomb.translate.v3po.test.ReaderCustomizerTest;
import io.fd.honeycomb.translate.v3po.util.NamingContext;
import io.fd.honeycomb.translate.v3po.util.TagRewriteOperation;
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;
public class RewriteCustomizerTest extends ReaderCustomizerTest<Rewrite, RewriteBuilder> {
- 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 static final String IFC_CTX_NAME = "ifc-test-instance";
+ private static final String IF_NAME = "local0";
+ private static final String VLAN_IF_NAME = "local0.1";
+ private static final int VLAN_IF_INDEX = 11;
+ private static final int VLAN_ID = 1;
private NamingContext interfacesContext;
@Override
public void setUpBefore() {
- interfacesContext = new NamingContext("generatedIfaceName", "test-instance");
-
- final Optional<Mapping> ifcMapping = ContextTestUtils.getMapping(VLAN_IF_NAME, VLAN_IF_INDEX);
- doReturn(ifcMapping).when(mappingContext).read(any());
+ interfacesContext = new NamingContext("generatedIfaceName", IFC_CTX_NAME);
+ ContextTestUtils.mockMapping(mappingContext, VLAN_IF_NAME, VLAN_IF_INDEX, IFC_CTX_NAME);
}
@Override
final Map<Integer, SwInterfaceDetails> cachedInterfaceDump = new HashMap<>();
final SwInterfaceDetails ifaceDetails = new SwInterfaceDetails();
- ifaceDetails.subId = VLAN_IF_ID;
+ ifaceDetails.subId = VLAN_ID;
ifaceDetails.interfaceName = VLAN_IF_NAME.getBytes();
ifaceDetails.vtrOp = TagRewriteOperation.translate_2_to_2.ordinal();
ifaceDetails.subNumberOfTags = 2;
final RewriteBuilder builder = mock(RewriteBuilder.class);
- getCustomizer().readCurrentAttributes(getVlanTagRewriteId(VLAN_IF_NAME, VLAN_IF_ID), builder, ctx);
+ getCustomizer().readCurrentAttributes(getVlanTagRewriteId(IF_NAME, VLAN_ID), builder, ctx);
verify(builder).setVlanType(_802dot1q.class);
verify(builder).setPopTags((short) 2);
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.translate.read.ReadFailedException;
import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
import io.fd.honeycomb.translate.v3po.test.ContextTestUtils;
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;
public class SubInterfaceCustomizerTest extends
ListReaderCustomizerTest<SubInterface, SubInterfaceKey, SubInterfaceBuilder> {
- 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 static final String IFC_CTX_NAME = "ifc-test-instance";
+ private static final String SUPER_IF_NAME = "local0";
+ private static final int SUPER_IF_INDEX = 1;
+ private static final String VLAN_IF_NAME = "local0.1";
+ private static final int VLAN_IF_ID = 1;
+ private static final int VLAN_IF_INDEX = 11;
private NamingContext interfacesContext;
@Override
public void setUpBefore() {
- interfacesContext = new NamingContext("generatedIfaceName", "test-instance");
+ interfacesContext = new NamingContext("generatedIfaceName", IFC_CTX_NAME);
+ ContextTestUtils.mockMapping(mappingContext, SUPER_IF_NAME, SUPER_IF_INDEX, IFC_CTX_NAME);
+ ContextTestUtils.mockMapping(mappingContext, VLAN_IF_NAME, VLAN_IF_INDEX, IFC_CTX_NAME);
}
@Override
@Test
public void testRead() throws ReadFailedException {
- final Optional<Mapping> ifcMapping = ContextTestUtils.getMapping(VLAN_IF_NAME, VLAN_IF_INDEX);
- doReturn(ifcMapping).when(mappingContext).read(any());
-
final Map<Integer, SwInterfaceDetails> cachedInterfaceDump = new HashMap<>();
final SwInterfaceDetails ifaceDetails = new SwInterfaceDetails();
ifaceDetails.subId = VLAN_IF_ID;
ifaceDetails.interfaceName = VLAN_IF_NAME.getBytes();
ifaceDetails.subDot1Ad = 1;
+ ContextTestUtils.mockMapping(mappingContext, SUPER_IF_NAME, SUPER_IF_INDEX, IFC_CTX_NAME);
+ ContextTestUtils.mockMapping(mappingContext, VLAN_IF_NAME, VLAN_IF_INDEX, IFC_CTX_NAME);
ifaceDetails.subNumberOfTags = 2;
ifaceDetails.subOuterVlanIdAny = 1;
ifaceDetails.subInnerVlanIdAny = 1;
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);
+ getCustomizer().readCurrentAttributes(getSubInterfaceId(SUPER_IF_NAME, VLAN_IF_ID), builder, ctx);
verify(builder).setIdentifier((long) VLAN_IF_ID);
@Test
public void testGetAllIds() throws Exception {
- final Optional<Mapping> ifcMapping = ContextTestUtils.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;
InterfaceTestUtils.whenSwInterfaceDumpThenReturn(api, ifaces);
final List<SubInterfaceKey> allIds =
- getCustomizer().getAllIds(getSubInterfaceId(VLAN_IF_NAME, VLAN_IF_ID), ctx);
+ getCustomizer().getAllIds(getSubInterfaceId(SUPER_IF_NAME, VLAN_IF_ID), ctx);
assertEquals(ifaces.size(), allIds.size());
-
}
}
\ No newline at end of file
public class VxlanCustomizerTest extends ReaderCustomizerTest<Vxlan, VxlanBuilder> {
+ private static final String IFC_CTX_NAME = "ifc-test-instance";
+ private static final String IF_NAME = "ifc1";
+ private static final int IF_INDEX = 0;
+
private NamingContext interfacesContext;
static final InstanceIdentifier<Vxlan> IID =
- InstanceIdentifier.create(InterfacesState.class).child(Interface.class, new InterfaceKey("ifc1"))
+ InstanceIdentifier.create(InterfacesState.class).child(Interface.class, new InterfaceKey(IF_NAME))
.augmentation(VppInterfaceStateAugmentation.class).child(Vxlan.class);
public VxlanCustomizerTest() {
@Override
public void setUpBefore() {
- interfacesContext = new NamingContext("vxlan-tunnel", "test-instance");
- doReturn(ContextTestUtils.getMapping("ifc1", 0)).when(mappingContext).read(
- ContextTestUtils.getMappingIid("ifc1", "test-instance"));
+ interfacesContext = new NamingContext("vxlan-tunnel", IFC_CTX_NAME);
+ ContextTestUtils.mockMapping(mappingContext, IF_NAME, IF_INDEX, IFC_CTX_NAME);
final SwInterfaceDetails v = new SwInterfaceDetails();
v.interfaceName = "vxlan-tunnel4".getBytes();
public class VxlanGpeCustomizerTest extends ReaderCustomizerTest<VxlanGpe, VxlanGpeBuilder> {
+ private static final String IFC_CTX_NAME = "ifc-test-instance";
+ private static final String IF_NAME = "ifc2";
+ private static final int IF_INDEX = 0;
+
private NamingContext interfacesContext;
- static final InstanceIdentifier<VxlanGpe> VXLAN_GPE_ID =
- InstanceIdentifier.create(InterfacesState.class).child(Interface.class, new InterfaceKey("ifc2"))
+ private static final InstanceIdentifier<VxlanGpe> VXLAN_GPE_ID =
+ InstanceIdentifier.create(InterfacesState.class).child(Interface.class, new InterfaceKey(IF_NAME))
.augmentation(VppInterfaceStateAugmentation.class).child(VxlanGpe.class);
public VxlanGpeCustomizerTest() {
@Override
public void setUpBefore() {
- interfacesContext = new NamingContext("vxlan_gpe_inf", "test-instance");
- doReturn(ContextTestUtils.getMapping("ifc2", 0)).when(mappingContext).read(
- ContextTestUtils.getMappingIid("ifc2", "test-instance"));
+ interfacesContext = new NamingContext("vxlan_gpe_inf", IFC_CTX_NAME);
+ ContextTestUtils.mockMapping(mappingContext, IF_NAME, IF_INDEX, IFC_CTX_NAME);
final SwInterfaceDetails v = new SwInterfaceDetails();
v.interfaceName = "vxlan_gpe_inf2".getBytes();
package io.fd.honeycomb.translate.v3po.interfacesstate.ip;
-import static io.fd.honeycomb.translate.v3po.test.ContextTestUtils.getMapping;
-import static io.fd.honeycomb.translate.v3po.test.ContextTestUtils.getMappingIid;
import static io.fd.honeycomb.translate.v3po.util.TranslateUtils.reverseBytes;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
-import static org.mockito.Mockito.doReturn;
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.ImmutableList;
-import com.google.common.collect.Lists;
-import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
-import io.fd.honeycomb.translate.v3po.test.ListReaderCustomizerTest;
import io.fd.honeycomb.translate.ModificationCache;
import io.fd.honeycomb.translate.read.ReadFailedException;
+import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
+import io.fd.honeycomb.translate.v3po.test.ContextTestUtils;
+import io.fd.honeycomb.translate.v3po.test.ListReaderCustomizerTest;
import io.fd.honeycomb.translate.v3po.util.NamingContext;
import io.fd.honeycomb.translate.v3po.util.TranslateUtils;
import java.util.Arrays;
import org.hamcrest.CoreMatchers;
import org.junit.Test;
import org.mockito.Mockito;
-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.inet.types.rev130715.Ipv4Address;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone;
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.ip.rev140616.interfaces.state._interface.ipv4.AddressBuilder;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.ipv4.AddressKey;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
import org.openvpp.jvpp.core.dto.IpAddressDetails;
import org.openvpp.jvpp.core.dto.IpAddressDetailsReplyDump;
import org.openvpp.jvpp.core.dto.IpAddressDump;
private static final String IFACE_2_NAME = "eth1";
private static final int IFACE_ID = 1;
private static final int IFACE_2_ID = 2;
+ private static final String IFC_CTX_NAME = "ifc-test-instance";
private NamingContext interfacesContext;
@Override
public void setUpBefore() {
- interfacesContext = new NamingContext("generatedIfaceName", "test-instance");
+ interfacesContext = new NamingContext("generatedIfaceName", IFC_CTX_NAME);
+ ContextTestUtils.mockMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME);
+ ContextTestUtils.mockMapping(mappingContext, IFACE_2_NAME, IFACE_2_ID, IFC_CTX_NAME);
}
@Override
protected ReaderCustomizer<Address, AddressBuilder> initCustomizer() {
- final KeyedInstanceIdentifier<Mapping, MappingKey> eth0Id = getMappingIid(IFACE_NAME, "test-instance");
- final KeyedInstanceIdentifier<Mapping, MappingKey> eth1Id = getMappingIid(IFACE_2_NAME, "test-instance");
- final Optional<Mapping> eth0 = getMapping(IFACE_NAME, IFACE_ID);
- final Optional<Mapping> eth1 = getMapping(IFACE_2_NAME, IFACE_2_ID);
-
- final List<Mapping> allMappings = Lists.newArrayList(eth0.get(), eth1.get());
- final Mappings allMappingsBaObject = new MappingsBuilder().setMapping(allMappings).build();
- doReturn(Optional.of(allMappingsBaObject)).when(mappingContext).read(eth0Id.firstIdentifierOf(Mappings.class));
-
- doReturn(eth0).when(mappingContext).read(eth0Id);
- doReturn(eth1).when(mappingContext).read(eth1Id);
-
return new Ipv4AddressCustomizer(api, interfacesContext);
}
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
-import com.google.common.base.Optional;
-import com.google.common.collect.Lists;
import io.fd.honeycomb.notification.NotificationCollector;
import io.fd.honeycomb.translate.MappingContext;
import io.fd.honeycomb.translate.v3po.test.ContextTestUtils;
import io.fd.honeycomb.translate.v3po.util.NamingContext;
-import java.util.List;
import java.util.concurrent.CompletableFuture;
import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
-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.opendaylight.params.xml.ns.yang.v3po.rev150105.InterfaceStateChange;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.InterfaceStatus;
-import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
import org.openvpp.jvpp.core.callback.SwInterfaceSetFlagsNotificationCallback;
import org.openvpp.jvpp.core.dto.SwInterfaceSetFlagsNotification;
import org.openvpp.jvpp.core.dto.WantInterfaceEvents;
public class InterfaceChangeNotificationProducerTest {
+ private static final String IFC_CTX_NAME = "ifc-test-instance";
+ private static final String IFACE_NAME = "eth0";
+ private static final int IFACE_ID = 0;
+
@Mock
private FutureJVppCore jVpp;
- private NamingContext namingContext = new NamingContext("test", "test-instance");
+ private NamingContext namingContext = new NamingContext("test", IFC_CTX_NAME);
@Mock
private MappingContext mappingContext;
@Mock
callbackArgumentCaptor = ArgumentCaptor.forClass(SwInterfaceSetFlagsNotificationCallback.class);
doReturn(notificationListenerReg).when(notificationRegistry).registerSwInterfaceSetFlagsNotificationCallback(
callbackArgumentCaptor.capture());
-
- final KeyedInstanceIdentifier<Mapping, MappingKey> eth0Id = ContextTestUtils
- .getMappingIid("eth0", "test-instance");
- final Optional<Mapping> eth0 = ContextTestUtils.getMapping("eth0", 0);
-
- final List<Mapping> allMappings = Lists.newArrayList(ContextTestUtils.getMapping("eth0", 0).get());
- final Mappings allMappingsBaObject = new MappingsBuilder().setMapping(allMappings).build();
- doReturn(Optional.of(allMappingsBaObject)).when(mappingContext).read(eth0Id.firstIdentifierOf(Mappings.class));
-
- doReturn(eth0).when(mappingContext).read(eth0Id);
+ ContextTestUtils.mockMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME);
}
@Test
final SwInterfaceSetFlagsNotification swInterfaceSetFlagsNotification = new SwInterfaceSetFlagsNotification();
swInterfaceSetFlagsNotification.deleted = 0;
- swInterfaceSetFlagsNotification.swIfIndex = 0;
+ swInterfaceSetFlagsNotification.swIfIndex = IFACE_ID;
swInterfaceSetFlagsNotification.adminUpDown = 1;
swInterfaceSetFlagsNotification.linkUpDown = 1;
-
callbackArgumentCaptor.getValue().onSwInterfaceSetFlagsNotification(swInterfaceSetFlagsNotification);
final ArgumentCaptor<InterfaceStateChange> notificationCaptor =
ArgumentCaptor.forClass(InterfaceStateChange.class);
verify(collector).onNotification(notificationCaptor.capture());
- assertEquals("eth0", notificationCaptor.getValue().getName().getString());
+ assertEquals(IFACE_NAME, notificationCaptor.getValue().getName().getString());
assertEquals(InterfaceStatus.Up, notificationCaptor.getValue().getAdminStatus());
assertEquals(InterfaceStatus.Up, notificationCaptor.getValue().getOperStatus());
}
new NamingContextKey(namingContextName)).child(Mappings.class).child(Mapping.class, new MappingKey(name));
}
- public static void mockMapping(final MappingContext mappingContext, final String name, final int id,
- final String namingContextName) {
- final InstanceIdentifier<Mappings> mappingsIid =
- getMappingIid(name, namingContextName).firstIdentifierOf(Mappings.class);
-
- final Optional<Mapping> singleMapping = getMapping(name, id);
+ private static List<Mapping> getMappingList(final MappingContext mappingContext, final InstanceIdentifier<Mappings> mappingsIid) {
final Optional<Mappings> previousMappings = mappingContext.read(mappingsIid);
-
final MappingsBuilder mappingsBuilder;
if (previousMappings != null && previousMappings.isPresent()) {
mappingsBuilder = new MappingsBuilder(previousMappings.get());
mappingsBuilder.setMapping(Lists.newArrayList());
}
- final List<Mapping> mappingList = mappingsBuilder.getMapping();
+ return mappingsBuilder.getMapping();
+ }
+
+ public static void mockMapping(final MappingContext mappingContext, final String name, final int id,
+ final String namingContextName) {
+ final InstanceIdentifier<Mappings> mappingsIid =
+ getMappingIid(name, namingContextName).firstIdentifierOf(Mappings.class);
+
+ final Optional<Mapping> singleMapping = getMapping(name, id);
+ final List<Mapping> mappingList = getMappingList(mappingContext, mappingsIid);
mappingList.add(singleMapping.get());
- doReturn(Optional.of(mappingsBuilder.setMapping(mappingList).build()))
+
+ doReturn(Optional.of(new MappingsBuilder().setMapping(mappingList).build()))
.when(mappingContext).read(mappingsIid);
doReturn(singleMapping).when(mappingContext).read(getMappingIid(name, namingContextName));
}
+
+ public static void mockEmptyMapping(final MappingContext mappingContext, final String name,
+ final String namingContextName) {
+ final InstanceIdentifier<Mappings> mappingsIid =
+ getMappingIid(name, namingContextName).firstIdentifierOf(Mappings.class);
+
+ final List<Mapping> mappingList = getMappingList(mappingContext, mappingsIid);
+
+ doReturn(Optional.of(new MappingsBuilder().setMapping(mappingList).build()))
+ .when(mappingContext).read(mappingsIid);
+ doReturn(Optional.absent()).when(mappingContext).read(getMappingIid(name, namingContextName));
+ }
}
import static org.mockito.Mockito.when;
import static org.mockito.MockitoAnnotations.initMocks;
-import com.google.common.base.Optional;
+import io.fd.honeycomb.translate.MappingContext;
import io.fd.honeycomb.translate.ModificationCache;
import io.fd.honeycomb.translate.v3po.test.ContextTestUtils;
import io.fd.honeycomb.translate.v3po.test.TestHelperUtils;
import io.fd.honeycomb.translate.v3po.util.NamingContext;
import io.fd.honeycomb.translate.write.WriteContext;
import io.fd.honeycomb.translate.write.WriteFailedException;
-import io.fd.honeycomb.translate.MappingContext;
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.mockito.Mock;
-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.MappingBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.bridge.domains.BridgeDomain;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.bridge.domains.BridgeDomainBuilder;
import org.openvpp.jvpp.VppInvocationException;
public class BridgeDomainCustomizerTest {
+ private static final String BD_CTX_NAME = "bd-test-instance";
+
private static final byte ADD_OR_UPDATE_BD = (byte) 1;
private static final byte ZERO = 0;
public void setUp() throws Exception {
initMocks(this);
// TODO HONEYCOMB-116 create base class for tests using vppApi
- NamingContext namingContext = new NamingContext("generatedBDName", "test-instance");
final ModificationCache toBeReturned = new ModificationCache();
doReturn(toBeReturned).when(ctx).getModificationCache();
doReturn(mappingContext).when(ctx).getMappingContext();
- customizer = new BridgeDomainCustomizer(api, namingContext);
+ customizer = new BridgeDomainCustomizer(api, new NamingContext("generatedBDName", BD_CTX_NAME));
}
private BridgeDomain generateBridgeDomain(final String bdName) {
final int bdId = 1;
final String bdName = "bd1";
final BridgeDomain bd = generateBridgeDomain(bdName);
- // Make bdContext.containsName() return false
- doReturn(Optional.absent()).when(mappingContext)
- .read(ContextTestUtils.getMappingIid(bdName, "test-instance").firstIdentifierOf(Mappings.class));
- // Make bdContext.containsIndex() return false
- doReturn(Optional.absent()).when(mappingContext)
- .read(ContextTestUtils.getMappingIid(bdName, "test-instance"));
+ ContextTestUtils.mockEmptyMapping(mappingContext, bdName, BD_CTX_NAME);
whenBridgeDomainAddDelThenSuccess();
verifyBridgeDomainAddOrUpdateWasInvoked(bd, bdId);
verify(mappingContext).put(
- ContextTestUtils.getMappingIid(bdName, "test-instance"), ContextTestUtils.getMapping(bdName, bdId).get());
+ ContextTestUtils.getMappingIid(bdName, BD_CTX_NAME), ContextTestUtils.getMapping(bdName, bdId).get());
}
@Test
final int bdId = 1;
final String bdName = "bd1";
final BridgeDomain bd = generateBridgeDomain(bdName);
- // Make bdContext.containsIndex() return true
- doReturn(Optional.of(new MappingBuilder().setIndex(bdId).build())).when(mappingContext)
- .read(ContextTestUtils.getMappingIid(bdName, "test-instance"));
+ ContextTestUtils.mockMapping(mappingContext, bdName, bdId, BD_CTX_NAME);
whenBridgeDomainAddDelThenSuccess();
verifyBridgeDomainAddOrUpdateWasInvoked(bd, bdId);
verify(mappingContext).put(
- ContextTestUtils.getMappingIid(bdName, "test-instance"), ContextTestUtils.getMapping(bdName, bdId).get());
+ ContextTestUtils.getMappingIid(bdName, BD_CTX_NAME), ContextTestUtils.getMapping(bdName, bdId).get());
}
@Test
final int bdId = 1;
final String bdName = "bd1";
final BridgeDomain bd = generateBridgeDomain(bdName);
-
- // Returning no Mappings for "test-instance" makes bdContext.containsName() return false
- doReturn(Optional.absent()).when(mappingContext)
- .read(ContextTestUtils.getMappingIid(bdName, "test-instance").firstIdentifierOf(Mappings.class));
- // Make bdContext.containsIndex() return false
- doReturn(Optional.absent()).when(mappingContext)
- .read(ContextTestUtils.getMappingIid(bdName, "test-instance"));
+ ContextTestUtils.mockEmptyMapping(mappingContext, bdName, BD_CTX_NAME);
whenBridgeDomainAddDelThenFailure();
final int bdId = 1;
final String bdName = "bd1";
final BridgeDomain bd = generateBridgeDomain(bdName);
- doReturn(ContextTestUtils.getMapping(bdName, bdId)).when(mappingContext).read(
- ContextTestUtils.getMappingIid(bdName, "test-instance"));
+ ContextTestUtils.mockMapping(mappingContext, bdName, bdId, BD_CTX_NAME);
whenBridgeDomainAddDelThenSuccess();
public void testDeleteUnknownBridgeDomain() throws Exception {
final String bdName = "bd1";
final BridgeDomain bd = generateBridgeDomain("bd1");
- doReturn(Optional.absent()).when(mappingContext).read(ContextTestUtils.getMappingIid(bdName, "test-instance"));
+ ContextTestUtils.mockEmptyMapping(mappingContext, bdName, BD_CTX_NAME);
try {
customizer.deleteCurrentAttributes(BridgeDomainTestUtils.bdIdentifierForName(bdName), bd, ctx);
final int bdId = 1;
final String bdName = "bd1";
final BridgeDomain bd = generateBridgeDomain(bdName);
- doReturn(ContextTestUtils.getMapping(bdName, bdId)).when(mappingContext).read(
- ContextTestUtils.getMappingIid(bdName, "test-instance"));
+ ContextTestUtils.mockMapping(mappingContext, bdName, bdId, BD_CTX_NAME);
whenBridgeDomainAddDelThenFailure();
public void testUpdateBridgeDomain() throws Exception {
final int bdId = 1;
final String bdName = "bd1";
- doReturn(ContextTestUtils.getMapping(bdName, bdId)).when(mappingContext).read(
- ContextTestUtils.getMappingIid(bdName, "test-instance"));
+ ContextTestUtils.mockMapping(mappingContext, bdName, bdId, BD_CTX_NAME);
final byte arpTermBefore = 1;
final byte floodBefore = 1;
final String bdName = "bd1";
final BridgeDomain bdBefore = generateBridgeDomain(bdName, 0, 1, 0, 1, 0);
final BridgeDomain bdAfter = generateBridgeDomain(bdName, 1, 1, 0, 1, 0);
- doReturn(Optional.absent()).when(mappingContext).read(ContextTestUtils.getMappingIid(bdName, "test-instance"));
+ ContextTestUtils.mockEmptyMapping(mappingContext, bdName, BD_CTX_NAME);
try {
customizer
final String bdName = "bd1";
final BridgeDomain bdBefore = generateBridgeDomain(bdName, 0, 1, 0, 1, 0);
final BridgeDomain bdAfter = generateBridgeDomain(bdName, 1, 1, 0, 1, 0);
- doReturn(ContextTestUtils.getMapping(bdName, bdId)).when(mappingContext).read(
- ContextTestUtils.getMappingIid(bdName, "test-instance"));
+ ContextTestUtils.mockMapping(mappingContext, bdName, bdId, BD_CTX_NAME);
whenBridgeDomainAddDelThenFailure();
package io.fd.honeycomb.translate.v3po.vpp;
import javax.annotation.Nullable;
-import org.mockito.invocation.InvocationOnMock;
-import org.mockito.stubbing.Answer;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.BridgeDomains;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.bridge.domains.BridgeDomain;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.bridge.domains.BridgeDomainKey;
return null;
}
- public static int bdNameToID(String bName) {
- return Integer.parseInt(((Character)bName.charAt(bName.length() - 1)).toString());
- }
-
public static KeyedInstanceIdentifier<BridgeDomain, BridgeDomainKey> bdIdentifierForName(
final String bdName) {
return InstanceIdentifier.create(BridgeDomains.class).child(BridgeDomain.class, new BridgeDomainKey(bdName));
}
-
- public static final Answer<Integer> BD_NAME_TO_ID_ANSWER = new Answer<Integer>() {
- @Override
- public Integer answer(final InvocationOnMock invocationOnMock) throws Throwable {
- return bdNameToID((String) invocationOnMock.getArguments()[0]);
- }
- };
}
\ No newline at end of file
initMocks(this);
doReturn(mappingContext).when(writeContext).getMappingContext();
bdContext = new NamingContext("generatedBdName", BD_CTX_NAME);
+ ContextTestUtils.mockMapping(mappingContext, BD_NAME, BD_ID, BD_CTX_NAME);
interfaceContext = new NamingContext("generatedIfaceName", IFC_CTX_NAME);
+ ContextTestUtils.mockMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME);
customizer = new L2FibEntryCustomizer(api, bdContext, interfaceContext);
}
final L2FibEntry entry = generateL2FibEntry(address);
final InstanceIdentifier<L2FibEntry> id = getL2FibEntryId(address);
- ContextTestUtils.mockMapping(mappingContext, BD_NAME, BD_ID, BD_CTX_NAME);
- ContextTestUtils.mockMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME);
-
whenL2FibAddDelThenSuccess();
customizer.writeCurrentAttributes(id, entry, writeContext);
final L2FibEntry entry = generateL2FibEntry(address);
final InstanceIdentifier<L2FibEntry> id = getL2FibEntryId(address);
- ContextTestUtils.mockMapping(mappingContext, BD_NAME, BD_ID, BD_CTX_NAME);
- ContextTestUtils.mockMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME);
-
whenL2FibAddDelThenFailure();
try {
final L2FibEntry entry = generateL2FibEntry(address);
final InstanceIdentifier<L2FibEntry> id = getL2FibEntryId(address);
- ContextTestUtils.mockMapping(mappingContext, BD_NAME, BD_ID, BD_CTX_NAME);
- ContextTestUtils.mockMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME);
-
whenL2FibAddDelThenSuccess();
customizer.deleteCurrentAttributes(id, entry, writeContext);
final L2FibEntry entry = generateL2FibEntry(address);
final InstanceIdentifier<L2FibEntry> id = getL2FibEntryId(address);
- ContextTestUtils.mockMapping(mappingContext, BD_NAME, BD_ID, BD_CTX_NAME);
- ContextTestUtils.mockMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME);
-
whenL2FibAddDelThenFailure();
try {
@Override
public void setUpBefore() {
bdContext = new NamingContext("generatedBdName", BD_CTX_NAME);
+ ContextTestUtils.mockMapping(mappingContext, BD_NAME, BD_ID, BD_CTX_NAME);
interfacesContext = new NamingContext("generatedIfaceName", IFC_CTX_NAME);
}
public void testRead() throws Exception {
final long address_vpp = 0x0000010203040506L;
final PhysAddress address = new PhysAddress("01:02:03:04:05:06");
-
- ContextTestUtils.mockMapping(mappingContext, BD_NAME, BD_ID, BD_CTX_NAME);
ContextTestUtils.mockMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME);
whenL2FibTableDumpThenReturn(Collections.singletonList(generateL2FibEntry(address_vpp)));
public void testGetAllIds() throws Exception {
final long address_vpp = 0x0000112233445566L;
final PhysAddress address = new PhysAddress("11:22:33:44:55:66");
- ContextTestUtils.mockMapping(mappingContext, BD_NAME, BD_ID, BD_CTX_NAME);
whenL2FibTableDumpThenReturn(Collections.singletonList(generateL2FibEntry(address_vpp)));
public void testReadCurrentAttributes() throws Exception {
final CompletableFuture<ShowVersionReply> replyFuture = new CompletableFuture<>();
final ShowVersionReply reply = new ShowVersionReply();
- reply.version = new byte[]{};
- reply.program = new byte[]{};
- reply.buildDate = new byte[]{};
- reply.buildDirectory = new byte[]{};
+ reply.version = new byte[] {};
+ reply.program = new byte[] {};
+ reply.buildDate = new byte[] {};
+ reply.buildDirectory = new byte[] {};
replyFuture.complete(reply);
when(api.showVersion(any(ShowVersion.class))).thenReturn(replyFuture);
public class VppStateTest {
+ private static final String BD_CTX_NAME = "bd-test-instance";
@Mock
private FutureJVppCore api;
@Mock
doReturn(cache).when(ctx).getModificationCache();
doReturn(mappingContext).when(ctx).getMappingContext();
- bdContext = new NamingContext("generatedBdName", "bd-test-instance");
+ bdContext = new NamingContext("generatedBdName", BD_CTX_NAME);
interfaceContext = new NamingContext("generatedIfaceName", "ifc-test-instance");
readerRegistry = VppStateTestUtils.getVppStateReader(api, bdContext);
}
}
private void mockBdMapping(final BridgeDomainDetails bd, final String bdName) {
- ContextTestUtils.mockMapping(mappingContext, bdName, bd.bdId, "bd-test-instance");
+ ContextTestUtils.mockMapping(mappingContext, bdName, bd.bdId, BD_CTX_NAME);
}
@Test
@Test(expected = ReadFailedException.class)
public void testReadBridgeDomainNotExisting() throws Exception {
- doReturn(Optional.absent()).when(mappingContext).read(
- ContextTestUtils.getMappingIid("NOT EXISTING", "bd-test-instance"));
+ final String nonExistingBdName = "NOT EXISTING";
+ ContextTestUtils.mockEmptyMapping(mappingContext, nonExistingBdName, BD_CTX_NAME);
- final Optional<? extends DataObject> read =
- readerRegistry.read(InstanceIdentifier.create(VppState.class).child(BridgeDomains.class).child(
- BridgeDomain.class, new BridgeDomainKey("NOT EXISTING")), ctx);
- assertFalse(read.isPresent());
+ readerRegistry.read(InstanceIdentifier.create(VppState.class).child(BridgeDomains.class).child(
+ BridgeDomain.class, new BridgeDomainKey(nonExistingBdName)), ctx);
}
@Test