summaryrefslogtreecommitdiffstats
path: root/v3po/v3po2vpp/src/test/java
diff options
context:
space:
mode:
authorMaros Marsalek <mmarsale@cisco.com>2016-05-17 09:10:39 +0200
committerMaros Marsalek <mmarsale@cisco.com>2016-05-23 09:24:12 +0000
commit799ee62f15dff07534beaf98a3ac551deffade38 (patch)
treea47c4696cf6ecff4fbb83c161c5d8e7e6b8af3c8 /v3po/v3po2vpp/src/test/java
parentf19306a9263cb8dd8c10a4867633fbbe14db2e4c (diff)
HONEYCOMB-61: Add BA broker for context data tree
With broker, context data can be accessed in a transactional manner, same as config data + Renamed data-api concepts to not include DataTree + Renamed context related concepts to better distinguish between them + Now passing full ReadContext to read customizers + Naming context is backed by context data broker Change-Id: I0b2876dd74a31a9ced7d9b5145672868e12f8b82 Signed-off-by: Maros Marsalek <mmarsale@cisco.com>
Diffstat (limited to 'v3po/v3po2vpp/src/test/java')
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/ContextTestUtils.java40
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/InterfaceTypeTestUtils.java12
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/SubInterfaceCustomizerTest.java20
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/TapCustomizerTest.java28
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/VhostUserCustomizerTest.java37
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/VlanTagRewriteCustomizerTest.java10
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/VxlanCustomizerTest.java31
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfacesstate/InterfaceCustomizerTest.java26
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfacesstate/L2CustomizerTest.java32
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfacesstate/SubInterfaceCustomizerTest.java30
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfacesstate/VlanTagRewriteCustomizerTest.java12
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfacesstate/VxlanCustomizerTest.java15
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/test/RootReaderCustomizerTest.java14
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/vpp/BridgeDomainCustomizerTest.java32
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/vpp/VppTest.java40
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/vppstate/BridgeDomainCustomizerTest.java4
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/vppstate/VppStateTest.java77
17 files changed, 361 insertions, 99 deletions
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/ContextTestUtils.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/ContextTestUtils.java
new file mode 100644
index 000000000..5c731bcb5
--- /dev/null
+++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/ContextTestUtils.java
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2016 Cisco and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.honeycomb.v3po.translate.v3po;
+
+import com.google.common.base.Optional;
+import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.Contexts;
+import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.contexts.NamingContextKey;
+import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.contexts.naming.context.Mappings;
+import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.contexts.naming.context.mappings.Mapping;
+import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.contexts.naming.context.mappings.MappingBuilder;
+import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.contexts.naming.context.mappings.MappingKey;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
+
+public class ContextTestUtils {
+
+ public static Optional<Mapping> getMapping(final String name, final int index) {
+ return Optional.of(new MappingBuilder().setName(name).setIndex(index).build());
+ }
+
+ public static KeyedInstanceIdentifier<Mapping, MappingKey> getMappingIid(final String name, final String namingContextName) {
+ return InstanceIdentifier.create(Contexts.class).child(
+ org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.contexts.NamingContext.class,
+ new NamingContextKey(namingContextName)).child(Mappings.class).child(Mapping.class, new MappingKey(name));
+ }
+}
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/InterfaceTypeTestUtils.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/InterfaceTypeTestUtils.java
index ff96131b1..fbb47b5d4 100644
--- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/InterfaceTypeTestUtils.java
+++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/InterfaceTypeTestUtils.java
@@ -19,21 +19,29 @@ package io.fd.honeycomb.v3po.translate.v3po.interfaces;
import static org.mockito.Mockito.doReturn;
import com.google.common.base.Optional;
-import io.fd.honeycomb.v3po.translate.Context;
+import io.fd.honeycomb.v3po.translate.ModificationCache;
import io.fd.honeycomb.v3po.translate.write.WriteContext;
import org.mockito.Matchers;
+import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.Contexts;
+import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.contexts.NamingContextKey;
+import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.contexts.naming.context.Mappings;
+import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.contexts.naming.context.mappings.Mapping;
+import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.contexts.naming.context.mappings.MappingBuilder;
+import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.contexts.naming.context.mappings.MappingKey;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfaceType;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceBuilder;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
final class InterfaceTypeTestUtils {
private InterfaceTypeTestUtils() {}
static void setupWriteContext(final WriteContext writeContext, final Class<? extends InterfaceType> ifcType) {
- doReturn(new Context()).when(writeContext).getContext();
+ doReturn(new ModificationCache()).when(writeContext).getModificationCache();
doReturn(Optional.of(new InterfaceBuilder()
.setType(ifcType)
.build())).when(writeContext).readAfter(Matchers.any(InstanceIdentifier.class));
}
+
}
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/SubInterfaceCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/SubInterfaceCustomizerTest.java
index d70654655..31ab3aab5 100644
--- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/SubInterfaceCustomizerTest.java
+++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/SubInterfaceCustomizerTest.java
@@ -16,15 +16,18 @@
package io.fd.honeycomb.v3po.translate.v3po.interfaces;
+import static io.fd.honeycomb.v3po.translate.v3po.ContextTestUtils.getMapping;
+import static io.fd.honeycomb.v3po.translate.v3po.ContextTestUtils.getMappingIid;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-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 static org.mockito.MockitoAnnotations.initMocks;
+import io.fd.honeycomb.v3po.translate.MappingContext;
import io.fd.honeycomb.v3po.translate.v3po.util.NamingContext;
import io.fd.honeycomb.v3po.translate.v3po.util.VppApiInvocationException;
import io.fd.honeycomb.v3po.translate.write.WriteContext;
@@ -54,6 +57,8 @@ public class SubInterfaceCustomizerTest {
private FutureJVpp api;
@Mock
private WriteContext writeContext;
+ @Mock
+ private MappingContext mappingContext;
private NamingContext namingContext;
private SubInterfaceCustomizer customizer;
@@ -65,10 +70,11 @@ public class SubInterfaceCustomizerTest {
initMocks(this);
InterfaceTypeTestUtils.setupWriteContext(writeContext,
org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.SubInterface.class);
- namingContext = new NamingContext("generatedSubInterfaceName");
+ namingContext = new NamingContext("generatedSubInterfaceName", "test-instance");
+ doReturn(mappingContext).when(writeContext).getMappingContext();
// TODO create base class for tests using vppApi
customizer = new SubInterfaceCustomizer(api, namingContext);
- namingContext.addName(SUPER_IF_ID, SUPER_IF_NAME);
+ doReturn(getMapping(SUPER_IF_NAME, SUPER_IF_ID)).when(mappingContext).read(getMappingIid(SUPER_IF_NAME, "test-instance"));
}
private SubInterface generateSubInterface(final String superIfName) {
@@ -145,7 +151,7 @@ public class SubInterfaceCustomizerTest {
customizer.writeCurrentAttributes(id, subInterface, writeContext);
verifyCreateSubifWasInvoked(generateSubInterfaceRequest(SUPER_IF_ID));
- assertTrue(namingContext.containsIndex(subIfaceName));
+ verify(mappingContext).put(eq(getMappingIid(subIfaceName, "test-instance")), eq(getMapping(subIfaceName, 0).get()));
}
@Test
@@ -161,7 +167,9 @@ public class SubInterfaceCustomizerTest {
} catch (WriteFailedException.CreateFailedException e) {
assertEquals(VppApiInvocationException.class, e.getCause().getClass());
verifyCreateSubifWasInvoked(generateSubInterfaceRequest(SUPER_IF_ID));
- assertFalse(namingContext.containsIndex(subIfaceName));
+ verify(mappingContext, times(0)).put(
+ eq(getMappingIid(subIfaceName, "test-instance")),
+ eq(getMapping(subIfaceName, 0).get()));
return;
}
fail("WriteFailedException.CreateFailedException was expected");
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/TapCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/TapCustomizerTest.java
index 8ae04f017..e717ec504 100644
--- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/TapCustomizerTest.java
+++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/TapCustomizerTest.java
@@ -16,14 +16,17 @@
package io.fd.honeycomb.v3po.translate.v3po.interfaces;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static io.fd.honeycomb.v3po.translate.v3po.ContextTestUtils.getMapping;
+import static io.fd.honeycomb.v3po.translate.v3po.ContextTestUtils.getMappingIid;
import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
+import io.fd.honeycomb.v3po.translate.MappingContext;
+import io.fd.honeycomb.v3po.translate.ModificationCache;
import io.fd.honeycomb.v3po.translate.v3po.util.NamingContext;
import io.fd.honeycomb.v3po.translate.write.WriteContext;
import java.util.concurrent.CompletableFuture;
@@ -55,8 +58,9 @@ public class TapCustomizerTest {
private FutureJVpp vppApi;
@Mock
private WriteContext writeContext;
+ @Mock
+ private MappingContext mappingContext;
- private NamingContext ctx;
private TapCustomizer tapCustomizer;
@Before
@@ -64,7 +68,11 @@ public class TapCustomizerTest {
MockitoAnnotations.initMocks(this);
InterfaceTypeTestUtils.setupWriteContext(writeContext,
org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.Tap.class);
- ctx = new NamingContext("ifcintest");
+ final NamingContext ctx = new NamingContext("ifcintest", "test-instance");
+ final ModificationCache toBeReturned = new ModificationCache();
+ doReturn(toBeReturned).when(writeContext).getModificationCache();
+ doReturn(mappingContext).when(writeContext).getMappingContext();
+
tapCustomizer = new TapCustomizer(vppApi, ctx);
}
@@ -89,8 +97,8 @@ public class TapCustomizerTest {
tapCustomizer.writeCurrentAttributes(getTapId("tap2"), getTapData("tap2", "ff:ff:ff:ff:ff:ff"), writeContext);
verify(vppApi, times(2)).tapConnect(any(TapConnect.class));
- assertTrue(ctx.containsIndex("tap"));
- assertTrue(ctx.containsIndex("tap2"));
+ verify(mappingContext).put(eq(getMappingIid("tap", "test-instance")), eq(getMapping("tap", 0).get()));
+ verify(mappingContext).put(eq(getMappingIid("tap2", "test-instance")), eq(getMapping("tap2", 1).get()));
}
@Test
@@ -109,12 +117,13 @@ public class TapCustomizerTest {
doReturn(replyModif).when(vppApi).tapModify(any(TapModify.class));
tapCustomizer.writeCurrentAttributes(getTapId("tap"), getTapData("tap", "ff:ff:ff:ff:ff:ff"), writeContext);
+ doReturn(getMapping("tap", 1)).when(mappingContext).read(getMappingIid("tap", "test-instance"));
tapCustomizer.updateCurrentAttributes(getTapId("tap"), getTapData("tap", "ff:ff:ff:ff:ff:ff"), getTapData("tap", "ff:ff:ff:ff:ff:f1"), writeContext);
verify(vppApi).tapConnect(any(TapConnect.class));
verify(vppApi).tapModify(any(TapModify.class));
- assertTrue(ctx.containsIndex("tap"));
- assertFalse(ctx.containsIndex("tap2"));
+
+ verify(mappingContext).put(eq(getMappingIid("tap", "test-instance")), eq(getMapping("tap", 0).get()));
}
@Test
@@ -132,11 +141,12 @@ public class TapCustomizerTest {
doReturn(replyDelete).when(vppApi).tapDelete(any(TapDelete.class));
tapCustomizer.writeCurrentAttributes(getTapId("tap"), getTapData("tap", "ff:ff:ff:ff:ff:ff"), writeContext);
+ doReturn(getMapping("tap", 1)).when(mappingContext).read(getMappingIid("tap", "test-instance"));
tapCustomizer.deleteCurrentAttributes(getTapId("tap"), getTapData("tap", "ff:ff:ff:ff:ff:ff"), writeContext);
verify(vppApi).tapConnect(any(TapConnect.class));
verify(vppApi).tapDelete(any(TapDelete.class));
- assertFalse(ctx.containsIndex("tap"));
+ verify(mappingContext).delete(eq(getMappingIid("tap", "test-instance")));
}
private InstanceIdentifier<Tap> getTapId(final String tap) {
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/VhostUserCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/VhostUserCustomizerTest.java
index 15b2a75c1..1015f24c0 100644
--- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/VhostUserCustomizerTest.java
+++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/VhostUserCustomizerTest.java
@@ -16,19 +16,25 @@
package io.fd.honeycomb.v3po.translate.v3po.interfaces;
+import static io.fd.honeycomb.v3po.translate.v3po.ContextTestUtils.getMapping;
+import static io.fd.honeycomb.v3po.translate.v3po.ContextTestUtils.getMappingIid;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
-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.mock;
import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyZeroInteractions;
import static org.mockito.Mockito.when;
import static org.mockito.MockitoAnnotations.initMocks;
+import io.fd.honeycomb.v3po.translate.MappingContext;
+import io.fd.honeycomb.v3po.translate.ModificationCache;
import io.fd.honeycomb.v3po.translate.v3po.util.NamingContext;
import io.fd.honeycomb.v3po.translate.v3po.util.VppApiInvocationException;
import io.fd.honeycomb.v3po.translate.v3po.utils.V3poUtils;
@@ -63,8 +69,9 @@ public class VhostUserCustomizerTest {
private FutureJVpp api;
@Mock
private WriteContext writeContext;
+ @Mock
+ private MappingContext mappingContext;
- private NamingContext namingContext;
private VhostUserCustomizer customizer;
private static final int IFACE_ID = 1;
private static final String IFACE_NAME = "eth0";
@@ -77,7 +84,11 @@ public class VhostUserCustomizerTest {
initMocks(this);
InterfaceTypeTestUtils.setupWriteContext(writeContext,
org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VhostUser.class);
- namingContext = new NamingContext("generatedInterfaceName");
+ final NamingContext namingContext = new NamingContext("generatedInterfaceName", "test-instance");
+ final ModificationCache toBeReturned = new ModificationCache();
+ doReturn(toBeReturned).when(writeContext).getModificationCache();
+ doReturn(mappingContext).when(writeContext).getMappingContext();
+
// TODO create base class for tests using vppApi
customizer = new VhostUserCustomizer(api, namingContext);
}
@@ -186,7 +197,7 @@ public class VhostUserCustomizerTest {
customizer.writeCurrentAttributes(ID, vhostUser, writeContext);
verifyCreateVhostUserIfWasInvoked(vhostUser);
- assertTrue(namingContext.containsIndex(IFACE_NAME));
+ verify(mappingContext).put(eq(getMappingIid(IFACE_NAME, "test-instance")), eq(getMapping(IFACE_NAME, 0).get()));
}
@Test
@@ -200,7 +211,7 @@ public class VhostUserCustomizerTest {
} catch (WriteFailedException.CreateFailedException e) {
assertEquals(VppApiInvocationException.class, e.getCause().getClass());
verifyCreateVhostUserIfWasInvoked(vhostUser);
- assertFalse(namingContext.containsIndex(IFACE_NAME));
+ verifyZeroInteractions(mappingContext);
return;
}
fail("WriteFailedException.CreateFailedException was expected");
@@ -210,7 +221,7 @@ public class VhostUserCustomizerTest {
public void testUpdateCurrentAttributes() throws Exception {
final VhostUser vhostUserBefore = generateVhostUser(VhostUserRole.Client, "socketName0");
final VhostUser vhostUserAfter = generateVhostUser(VhostUserRole.Server, "socketName1");
- namingContext.addName(IFACE_ID, IFACE_NAME);
+ doReturn(getMapping(IFACE_NAME, IFACE_ID)).when(mappingContext).read(getMappingIid(IFACE_NAME, "test-instance"));
whenModifyVhostUserIfThenSuccess();
@@ -230,7 +241,7 @@ public class VhostUserCustomizerTest {
public void testUpdateCurrentAttributesFailed() throws Exception {
final VhostUser vhostUserBefore = generateVhostUser(VhostUserRole.Client, "socketName0");
final VhostUser vhostUserAfter = generateVhostUser(VhostUserRole.Server, "socketName1");
- namingContext.addName(IFACE_ID, IFACE_NAME);
+ doReturn(getMapping(IFACE_NAME, IFACE_ID)).when(mappingContext).read(getMappingIid(IFACE_NAME, "test-instance"));
whenModifyVhostUserIfThenFailure();
@@ -247,19 +258,19 @@ public class VhostUserCustomizerTest {
@Test
public void testDeleteCurrentAttributes() throws Exception {
final VhostUser vhostUser = generateVhostUser(VhostUserRole.Client, "socketName");
- namingContext.addName(IFACE_ID, IFACE_NAME);
+ doReturn(getMapping(IFACE_NAME, IFACE_ID)).when(mappingContext).read(getMappingIid(IFACE_NAME, "test-instance"));
whenDeleteVhostUserIfThenSuccess();
customizer.deleteCurrentAttributes(ID, vhostUser, writeContext);
verifyDeleteVhostUserIfWasInvoked(IFACE_ID);
- assertFalse(namingContext.containsIndex(IFACE_NAME));
+ verify(mappingContext).delete(eq(getMappingIid(IFACE_NAME, "test-instance")));
}
@Test
public void testDeleteCurrentAttributesFailed() throws Exception {
final VhostUser vhostUser = generateVhostUser(VhostUserRole.Client, "socketName");
- namingContext.addName(IFACE_ID, IFACE_NAME);
+ doReturn(getMapping(IFACE_NAME, IFACE_ID)).when(mappingContext).read(getMappingIid(IFACE_NAME, "test-instance"));
whenDeleteVhostUserIfThenFailure();
@@ -268,7 +279,9 @@ public class VhostUserCustomizerTest {
} catch (WriteFailedException.DeleteFailedException e) {
assertEquals(VppApiInvocationException.class, e.getCause().getClass());
verifyDeleteVhostUserIfWasInvoked(IFACE_ID);
- assertTrue(namingContext.containsIndex(IFACE_NAME));
+ // Delete from context not invoked if delete from VPP failed
+ verify(mappingContext, times(0)).delete(eq(getMappingIid(IFACE_NAME, "test-instance")));
+ verify(mappingContext).read(eq(getMappingIid(IFACE_NAME, "test-instance")));
return;
}
fail("WriteFailedException.DeleteFailedException was expected");
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/VlanTagRewriteCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/VlanTagRewriteCustomizerTest.java
index ae768145a..39a9823b5 100644
--- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/VlanTagRewriteCustomizerTest.java
+++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/VlanTagRewriteCustomizerTest.java
@@ -16,6 +16,8 @@
package io.fd.honeycomb.v3po.translate.v3po.interfaces;
+import static io.fd.honeycomb.v3po.translate.v3po.ContextTestUtils.getMapping;
+import static io.fd.honeycomb.v3po.translate.v3po.ContextTestUtils.getMappingIid;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import static org.mockito.Matchers.any;
@@ -24,6 +26,7 @@ import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.MockitoAnnotations.initMocks;
+import io.fd.honeycomb.v3po.translate.MappingContext;
import io.fd.honeycomb.v3po.translate.v3po.util.NamingContext;
import io.fd.honeycomb.v3po.translate.v3po.util.VppApiInvocationException;
import io.fd.honeycomb.v3po.translate.write.WriteContext;
@@ -55,6 +58,8 @@ public class VlanTagRewriteCustomizerTest {
private FutureJVpp api;
@Mock
private WriteContext writeContext;
+ @Mock
+ private MappingContext mappingContext;
private NamingContext namingContext;
private VlanTagRewriteCustomizer customizer;
@@ -65,9 +70,10 @@ public class VlanTagRewriteCustomizerTest {
@Before
public void setUp() throws Exception {
initMocks(this);
- namingContext = new NamingContext("generatedSubInterfaceName");
+ namingContext = new NamingContext("generatedSubInterfaceName", "test-instance");
+ doReturn(mappingContext).when(writeContext).getMappingContext();
customizer = new VlanTagRewriteCustomizer(api, namingContext);
- namingContext.addName(VLAN_IF_ID, VLAN_IF_NAME);
+ doReturn(getMapping(VLAN_IF_NAME, VLAN_IF_ID)).when(mappingContext).read(getMappingIid(VLAN_IF_NAME, "test-instance"));
}
private InstanceIdentifier<VlanTagRewrite> getVlanTagRewriteId(final String name) {
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/VxlanCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/VxlanCustomizerTest.java
index af7b4df17..a5103b178 100644
--- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/VxlanCustomizerTest.java
+++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/VxlanCustomizerTest.java
@@ -16,19 +16,24 @@
package io.fd.honeycomb.v3po.translate.v3po.interfaces;
+import static io.fd.honeycomb.v3po.translate.v3po.ContextTestUtils.getMapping;
+import static io.fd.honeycomb.v3po.translate.v3po.ContextTestUtils.getMappingIid;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-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.mock;
import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.mockito.MockitoAnnotations.initMocks;
import com.google.common.net.InetAddresses;
+import io.fd.honeycomb.v3po.translate.MappingContext;
+import io.fd.honeycomb.v3po.translate.ModificationCache;
import io.fd.honeycomb.v3po.translate.v3po.util.NamingContext;
import io.fd.honeycomb.v3po.translate.v3po.util.VppApiInvocationException;
import io.fd.honeycomb.v3po.translate.write.WriteContext;
@@ -63,9 +68,10 @@ public class VxlanCustomizerTest {
private FutureJVpp api;
@Mock
private WriteContext writeContext;
+ @Mock
+ private MappingContext mappingContext;
private VxlanCustomizer customizer;
- private NamingContext namingContext;
private String ifaceName;
private InstanceIdentifier<Vxlan> id;
@@ -75,7 +81,11 @@ public class VxlanCustomizerTest {
InterfaceTypeTestUtils.setupWriteContext(writeContext,
org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VxlanTunnel.class);
// TODO create base class for tests using vppApi
- namingContext = new NamingContext("generateInterfaceNAme");
+ NamingContext namingContext = new NamingContext("generateInterfaceNAme", "test-instance");
+ final ModificationCache toBeReturned = new ModificationCache();
+ doReturn(toBeReturned).when(writeContext).getModificationCache();
+ doReturn(mappingContext).when(writeContext).getMappingContext();
+
customizer = new VxlanCustomizer(api, namingContext);
ifaceName = "eth0";
@@ -144,7 +154,7 @@ public class VxlanCustomizerTest {
customizer.writeCurrentAttributes(id, vxlan, writeContext);
verifyVxlanAddWasInvoked(vxlan);
- assertTrue(namingContext.containsIndex(ifaceName));
+ verify(mappingContext).put(eq(getMappingIid(ifaceName, "test-instance")), eq(getMapping(ifaceName, 0).get()));
}
@Test
@@ -158,7 +168,8 @@ public class VxlanCustomizerTest {
} catch (WriteFailedException.CreateFailedException e) {
assertEquals(VppApiInvocationException.class, e.getCause().getClass());
verifyVxlanAddWasInvoked(vxlan);
- assertFalse(namingContext.containsIndex(ifaceName));
+ // Mapping not stored due to failure
+ verify(mappingContext, times(0)).put(eq(getMappingIid(ifaceName, "test-instance")), eq(getMapping(ifaceName, 0).get()));
return;
}
fail("WriteFailedException.CreateFailedException was expected");
@@ -186,11 +197,11 @@ public class VxlanCustomizerTest {
final Vxlan vxlan = generateVxlan();
whenVxlanAddDelTunnelThenSuccess();
- namingContext.addName(1, ifaceName);
+ doReturn(getMapping(ifaceName, 1)).when(mappingContext).read(getMappingIid(ifaceName, "test-instance"));
customizer.deleteCurrentAttributes(id, vxlan, writeContext);
verifyVxlanDeleteWasInvoked(vxlan);
- assertFalse(namingContext.containsIndex(ifaceName));
+ verify(mappingContext).delete(eq(getMappingIid(ifaceName, "test-instance")));
}
@Test
@@ -198,14 +209,14 @@ public class VxlanCustomizerTest {
final Vxlan vxlan = generateVxlan();
whenVxlanAddDelTunnelThenFailure();
- namingContext.addName(1, ifaceName);
+ doReturn(getMapping(ifaceName, 1)).when(mappingContext).read(getMappingIid(ifaceName, "test-instance"));
try {
customizer.deleteCurrentAttributes(id, vxlan, writeContext);
} catch (WriteFailedException.DeleteFailedException e) {
assertEquals(VppApiInvocationException.class, e.getCause().getClass());
verifyVxlanDeleteWasInvoked(vxlan);
- assertTrue(namingContext.containsIndex(ifaceName));
+ verify(mappingContext, times(0)).delete(eq(getMappingIid(ifaceName, "test-instance")));
return;
}
fail("WriteFailedException.DeleteFailedException was expected");
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfacesstate/InterfaceCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfacesstate/InterfaceCustomizerTest.java
index 3f33d141f..822b16c2b 100644
--- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfacesstate/InterfaceCustomizerTest.java
+++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfacesstate/InterfaceCustomizerTest.java
@@ -16,16 +16,21 @@
package io.fd.honeycomb.v3po.translate.v3po.interfacesstate;
+import static io.fd.honeycomb.v3po.translate.v3po.ContextTestUtils.getMapping;
+import static io.fd.honeycomb.v3po.translate.v3po.ContextTestUtils.getMappingIid;
import static io.fd.honeycomb.v3po.translate.v3po.interfacesstate.InterfaceUtils.yangIfIndexToVpp;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+import com.google.common.base.Optional;
+import com.google.common.collect.Lists;
import io.fd.honeycomb.v3po.translate.spi.read.RootReaderCustomizer;
import io.fd.honeycomb.v3po.translate.v3po.test.ListReaderCustomizerTest;
import io.fd.honeycomb.v3po.translate.v3po.util.NamingContext;
@@ -37,12 +42,17 @@ import java.util.concurrent.CompletionStage;
import java.util.concurrent.ExecutionException;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
+import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.contexts.naming.context.Mappings;
+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.dto.SwInterfaceDetails;
import org.openvpp.jvpp.dto.SwInterfaceDetailsReplyDump;
import org.openvpp.jvpp.dto.SwInterfaceDump;
@@ -58,13 +68,23 @@ public class InterfaceCustomizerTest extends
@Override
public void setUpBefore() {
- interfacesContext = new NamingContext("generatedIfaceName");
+ interfacesContext = new NamingContext("generatedIfaceName", "test-instance");
}
@Override
protected RootReaderCustomizer<Interface, InterfaceBuilder> initCustomizer() {
- interfacesContext.addName(0, "eth0");
- interfacesContext.addName(1, "eth1");
+ final KeyedInstanceIdentifier<Mapping, MappingKey> eth0Id = getMappingIid("eth0", "test-instance");
+ final KeyedInstanceIdentifier<Mapping, MappingKey> eth1Id = getMappingIid("eth1", "test-instance");
+ final Optional<Mapping> eth0 = getMapping("eth0", 0);
+ final Optional<Mapping> eth1 = getMapping("eth1", 1);
+
+ final List<Mapping> allMappings = Lists.newArrayList(getMapping("eth0", 0).get(), getMapping("eth1", 1).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 InterfaceCustomizer(api, interfacesContext);
}
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfacesstate/L2CustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfacesstate/L2CustomizerTest.java
index b454446dc..b09381584 100644
--- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfacesstate/L2CustomizerTest.java
+++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfacesstate/L2CustomizerTest.java
@@ -16,12 +16,16 @@
package io.fd.honeycomb.v3po.translate.v3po.interfacesstate;
+import static io.fd.honeycomb.v3po.translate.v3po.ContextTestUtils.getMapping;
+import static io.fd.honeycomb.v3po.translate.v3po.ContextTestUtils.getMappingIid;
import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
-import io.fd.honeycomb.v3po.translate.Context;
+import com.google.common.base.Optional;
+import com.google.common.collect.Lists;
import io.fd.honeycomb.v3po.translate.spi.read.RootReaderCustomizer;
import io.fd.honeycomb.v3po.translate.v3po.test.ChildReaderCustomizerTest;
import io.fd.honeycomb.v3po.translate.v3po.util.NamingContext;
@@ -33,6 +37,10 @@ import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
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;
@@ -43,6 +51,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces.state._interface.l2.Interconnection;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces.state._interface.l2.interconnection.BridgeBasedBuilder;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
import org.openvpp.jvpp.dto.BridgeDomainDetailsReplyDump;
import org.openvpp.jvpp.dto.BridgeDomainDump;
import org.openvpp.jvpp.dto.BridgeDomainSwIfDetails;
@@ -59,8 +68,8 @@ public class L2CustomizerTest extends ChildReaderCustomizerTest<L2, L2Builder> {
@Override
public void setUpBefore() {
- interfaceContext = new NamingContext("generatedIfaceName");
- bridgeDomainContext = new NamingContext("generatedBDName");
+ interfaceContext = new NamingContext("generatedIfaceName", "ifc-test-instance");
+ bridgeDomainContext = new NamingContext("generatedBDName", "bd-test-instance");
}
@Override
@@ -111,19 +120,28 @@ public class L2CustomizerTest extends ChildReaderCustomizerTest<L2, L2Builder> {
@Test
public void testRead() throws Exception {
- final Context ctx = new Context();
final Map<Integer, SwInterfaceDetails> cachedInterfaceDump = new HashMap<>();
final int ifId = 1;
final int bdId = 1;
final String bdName = "bd001";
final String ifName = "eth0.sub0";
- interfaceContext.addName(ifId, ifName);
- bridgeDomainContext.addName(bdId, bdName);
+ final KeyedInstanceIdentifier<Mapping, MappingKey> ifcIid = getMappingIid(ifName, "ifc-test-instance");
+ doReturn(getMapping(ifName, ifId)).when(mappingContext).read(ifcIid);
+ final KeyedInstanceIdentifier<Mapping, MappingKey> bdIid = getMappingIid(bdName, "bd-test-instance");
+ doReturn(getMapping(bdName, bdId)).when(mappingContext).read(bdIid);
+
+ List<Mapping> allMappings = Lists.newArrayList(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(getMapping(bdName, bdId).get());
+ allMappingsBaObject = new MappingsBuilder().setMapping(allMappings).build();
+ doReturn(Optional.of(allMappingsBaObject)).when(mappingContext).read(bdIid.firstIdentifierOf(Mappings.class));
final SwInterfaceDetails ifaceDetails = new SwInterfaceDetails();
ifaceDetails.subId = ifId;
cachedInterfaceDump.put(ifId, ifaceDetails);
- ctx.put(InterfaceCustomizer.DUMPED_IFCS_CONTEXT_KEY, cachedInterfaceDump);
+ cache.put(InterfaceCustomizer.DUMPED_IFCS_CONTEXT_KEY, cachedInterfaceDump);
whenBridgeDomainSwIfDumpThenReturn(Collections.singletonList(generateBdSwIfDetails(ifId, bdId)));
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfacesstate/SubInterfaceCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfacesstate/SubInterfaceCustomizerTest.java
index 8ed35e01b..4f6857b47 100644
--- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfacesstate/SubInterfaceCustomizerTest.java
+++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfacesstate/SubInterfaceCustomizerTest.java
@@ -16,19 +16,29 @@
package io.fd.honeycomb.v3po.translate.v3po.interfacesstate;
+import static io.fd.honeycomb.v3po.translate.v3po.ContextTestUtils.getMapping;
+import static io.fd.honeycomb.v3po.translate.v3po.ContextTestUtils.getMappingIid;
import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
-import io.fd.honeycomb.v3po.translate.Context;
+import com.google.common.base.Optional;
+import com.google.common.collect.Lists;
import io.fd.honeycomb.v3po.translate.read.ReadFailedException;
import io.fd.honeycomb.v3po.translate.spi.read.ChildReaderCustomizer;
import io.fd.honeycomb.v3po.translate.v3po.test.ChildReaderCustomizerTest;
import io.fd.honeycomb.v3po.translate.v3po.util.NamingContext;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import org.junit.Test;
+import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.contexts.naming.context.Mappings;
+import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.contexts.naming.context.MappingsBuilder;
+import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.contexts.naming.context.mappings.Mapping;
+import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.contexts.naming.context.mappings.MappingKey;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfacesState;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.InterfaceKey;
@@ -38,6 +48,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces.state._interface.SubInterface;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces.state._interface.SubInterfaceBuilder;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
import org.openvpp.jvpp.dto.SwInterfaceDetails;
public class SubInterfaceCustomizerTest extends ChildReaderCustomizerTest<SubInterface, SubInterfaceBuilder> {
@@ -55,7 +66,7 @@ public class SubInterfaceCustomizerTest extends ChildReaderCustomizerTest<SubInt
@Override
public void setUpBefore() {
- interfacesContext = new NamingContext("generatedIfaceName");
+ interfacesContext = new NamingContext("generatedIfaceName", "test-instance");
}
private InstanceIdentifier<SubInterface> getSubInterfaceId(final String name) {
@@ -74,21 +85,30 @@ public class SubInterfaceCustomizerTest extends ChildReaderCustomizerTest<SubInt
@Test
public void testRead() throws ReadFailedException {
- final Context ctx = new Context();
final Map<Integer, SwInterfaceDetails> cachedInterfaceDump = new HashMap<>();
final int ifId = 1;
final String ifName = "eth0.sub0";
- interfacesContext.addName(ifId, ifName);
+
+ final KeyedInstanceIdentifier<Mapping, MappingKey> ifcIid = getMappingIid(ifName, "test-instance");
+ doReturn(getMapping(ifName, ifId)).when(mappingContext).read(ifcIid);
+ final KeyedInstanceIdentifier<Mapping, MappingKey> superIfcIid = getMappingIid("super", "test-instance");
+ doReturn(getMapping("super", 0)).when(mappingContext).read(superIfcIid);
+
+ final List<Mapping> allMappings = Lists.newArrayList(getMapping(ifName, ifId).get(), getMapping("super", 0).get());
+ final Mappings allMappingsBaObject = new MappingsBuilder().setMapping(allMappings).build();
+ doReturn(Optional.of(allMappingsBaObject)).when(mappingContext).read(ifcIid.firstIdentifierOf(Mappings.class));
+
final SwInterfaceDetails ifaceDetails = new SwInterfaceDetails();
ifaceDetails.subId = ifId;
ifaceDetails.interfaceName = ifName.getBytes();
cachedInterfaceDump.put(ifId, ifaceDetails);
- ctx.put(InterfaceCustomizer.DUMPED_IFCS_CONTEXT_KEY, cachedInterfaceDump);
+ cache.put(InterfaceCustomizer.DUMPED_IFCS_CONTEXT_KEY, cachedInterfaceDump);
final SubInterfaceBuilder builder = mock(SubInterfaceBuilder.class);
getCustomizer().readCurrentAttributes(getSubInterfaceId(ifName), builder, ctx);
verify(builder).setIdentifier((long)ifId);
+ verify(builder).setSuperInterface(anyString());
verify(builder).setNumberOfTags((short)0);
verify(builder).setVlanType(VlanType._802dot1ad);
verify(builder, never()).setExactMatch(any());
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfacesstate/VlanTagRewriteCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfacesstate/VlanTagRewriteCustomizerTest.java
index 2263160e3..d00745ec1 100644
--- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfacesstate/VlanTagRewriteCustomizerTest.java
+++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfacesstate/VlanTagRewriteCustomizerTest.java
@@ -16,12 +16,14 @@
package io.fd.honeycomb.v3po.translate.v3po.interfacesstate;
+import static io.fd.honeycomb.v3po.translate.v3po.ContextTestUtils.getMapping;
+import static io.fd.honeycomb.v3po.translate.v3po.ContextTestUtils.getMappingIid;
import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
-import io.fd.honeycomb.v3po.translate.Context;
import io.fd.honeycomb.v3po.translate.read.ReadFailedException;
import io.fd.honeycomb.v3po.translate.spi.read.RootReaderCustomizer;
import io.fd.honeycomb.v3po.translate.v3po.test.ChildReaderCustomizerTest;
@@ -52,7 +54,7 @@ public class VlanTagRewriteCustomizerTest extends ChildReaderCustomizerTest<Vlan
@Override
public void setUpBefore() {
- interfacesContext = new NamingContext("generatedIfaceName");
+ interfacesContext = new NamingContext("generatedIfaceName", "test-instance");
}
@@ -76,15 +78,15 @@ public class VlanTagRewriteCustomizerTest extends ChildReaderCustomizerTest<Vlan
@Test
public void testRead() throws ReadFailedException {
- final Context ctx = new Context();
final Map<Integer, SwInterfaceDetails> cachedInterfaceDump = new HashMap<>();
final int ifId = 1;
final String ifName = "eth0.sub0";
- interfacesContext.addName(ifId, ifName);
+ doReturn(getMapping(ifName, ifId)).when(mappingContext).read(getMappingIid(ifName, "test-instance"));
+
final SwInterfaceDetails ifaceDetails = new SwInterfaceDetails();
ifaceDetails.subId = ifId;
cachedInterfaceDump.put(ifId, ifaceDetails);
- ctx.put(InterfaceCustomizer.DUMPED_IFCS_CONTEXT_KEY, cachedInterfaceDump);
+ cache.put(InterfaceCustomizer.DUMPED_IFCS_CONTEXT_KEY, cachedInterfaceDump);
final VlanTagRewriteBuilder builder = mock(VlanTagRewriteBuilder.class);
getCustomizer().readCurrentAttributes(getVlanTagRewriteId(ifName), builder, ctx);
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfacesstate/VxlanCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfacesstate/VxlanCustomizerTest.java
index 760e85b26..db92ebf17 100644
--- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfacesstate/VxlanCustomizerTest.java
+++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/interfacesstate/VxlanCustomizerTest.java
@@ -16,6 +16,8 @@
package io.fd.honeycomb.v3po.translate.v3po.interfacesstate;
+import static io.fd.honeycomb.v3po.translate.v3po.ContextTestUtils.getMapping;
+import static io.fd.honeycomb.v3po.translate.v3po.ContextTestUtils.getMappingIid;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
@@ -25,7 +27,6 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyZeroInteractions;
import com.google.common.collect.Lists;
-import io.fd.honeycomb.v3po.translate.Context;
import io.fd.honeycomb.v3po.translate.spi.read.RootReaderCustomizer;
import io.fd.honeycomb.v3po.translate.v3po.test.ChildReaderCustomizerTest;
import io.fd.honeycomb.v3po.translate.v3po.util.NamingContext;
@@ -50,7 +51,6 @@ import org.openvpp.jvpp.dto.VxlanTunnelDump;
public class VxlanCustomizerTest extends ChildReaderCustomizerTest<Vxlan, VxlanBuilder> {
private NamingContext interfacesContext;
- private Context ctx;
static final InstanceIdentifier<Vxlan> IID =
InstanceIdentifier.create(InterfacesState.class).child(Interface.class, new InterfaceKey("ifc1"))
.augmentation(VppInterfaceStateAugmentation.class).child(Vxlan.class);
@@ -61,15 +61,14 @@ public class VxlanCustomizerTest extends ChildReaderCustomizerTest<Vxlan, VxlanB
@Override
public void setUpBefore() {
- interfacesContext = new NamingContext("vxlan-tunnel");
- interfacesContext.addName(0, "ifc1");
+ interfacesContext = new NamingContext("vxlan-tunnel", "test-instance");
+ doReturn(getMapping("ifc1", 0)).when(mappingContext).read(getMappingIid("ifc1", "test-instance"));
- ctx = new Context();
final SwInterfaceDetails v = new SwInterfaceDetails();
v.interfaceName = "vxlan-tunnel4".getBytes();
final Map<Integer, SwInterfaceDetails> map = new HashMap<>();
map.put(0, v);
- ctx.put(InterfaceCustomizer.DUMPED_IFCS_CONTEXT_KEY, map);
+ cache.put(InterfaceCustomizer.DUMPED_IFCS_CONTEXT_KEY, map);
}
@Override
@@ -114,7 +113,7 @@ public class VxlanCustomizerTest extends ChildReaderCustomizerTest<Vxlan, VxlanB
@Test(expected = NullPointerException.class)
public void testReadCurrentAttributesVppNameNotCached() throws Exception {
- InterfaceCustomizer.getCachedInterfaceDump(ctx).remove(0);
+ InterfaceCustomizer.getCachedInterfaceDump(cache).remove(0);
final VxlanBuilder builder = getCustomizer().getBuilder(IID);
getCustomizer().readCurrentAttributes(IID, builder, ctx);
@@ -124,7 +123,7 @@ public class VxlanCustomizerTest extends ChildReaderCustomizerTest<Vxlan, VxlanB
public void testReadCurrentAttributesWrongType() throws Exception {
final SwInterfaceDetails v = new SwInterfaceDetails();
v.interfaceName = "tap-2".getBytes();
- InterfaceCustomizer.getCachedInterfaceDump(ctx).put(0, v);
+ InterfaceCustomizer.getCachedInterfaceDump(cache).put(0, v);
final VxlanBuilder builder = getCustomizer().getBuilder(IID);
getCustomizer().readCurrentAttributes(IID, builder, ctx);
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/test/RootReaderCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/test/RootReaderCustomizerTest.java
index 19d307ec9..8500acece 100644
--- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/test/RootReaderCustomizerTest.java
+++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/test/RootReaderCustomizerTest.java
@@ -17,9 +17,12 @@
package io.fd.honeycomb.v3po.translate.v3po.test;
import static org.junit.Assert.assertNotNull;
+import static org.mockito.Mockito.doReturn;
import static org.mockito.MockitoAnnotations.initMocks;
-import io.fd.honeycomb.v3po.translate.Context;
+import io.fd.honeycomb.v3po.translate.MappingContext;
+import io.fd.honeycomb.v3po.translate.ModificationCache;
+import io.fd.honeycomb.v3po.translate.read.ReadContext;
import io.fd.honeycomb.v3po.translate.spi.read.RootReaderCustomizer;
import org.junit.Before;
import org.junit.Test;
@@ -39,8 +42,11 @@ public abstract class RootReaderCustomizerTest<D extends DataObject, B extends B
@Mock
protected FutureJVpp api;
+ protected ModificationCache cache;
@Mock
- protected Context ctx;
+ protected ReadContext ctx;
+ @Mock
+ protected MappingContext mappingContext;
protected final Class<D> dataObjectClass;
private RootReaderCustomizer<D, B> customizer;
@@ -52,6 +58,10 @@ public abstract class RootReaderCustomizerTest<D extends DataObject, B extends B
@Before
public void setUpParent() throws Exception {
initMocks(this);
+ cache = new ModificationCache();
+ doReturn(cache).when(ctx).getModificationCache();
+ doReturn(mappingContext).when(ctx).getMappingContext();
+
setUpBefore();
customizer = initCustomizer();
setUpAfter();
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/vpp/BridgeDomainCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/vpp/BridgeDomainCustomizerTest.java
index f5b19a7be..7436c9cf3 100644
--- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/vpp/BridgeDomainCustomizerTest.java
+++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/vpp/BridgeDomainCustomizerTest.java
@@ -15,15 +15,21 @@
*/
package io.fd.honeycomb.v3po.translate.v3po.vpp;
+import static io.fd.honeycomb.v3po.translate.v3po.ContextTestUtils.getMapping;
+import static io.fd.honeycomb.v3po.translate.v3po.ContextTestUtils.getMappingIid;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.mockito.MockitoAnnotations.initMocks;
+import com.google.common.base.Optional;
+import io.fd.honeycomb.v3po.translate.MappingContext;
+import io.fd.honeycomb.v3po.translate.ModificationCache;
import io.fd.honeycomb.v3po.translate.v3po.util.NamingContext;
import io.fd.honeycomb.v3po.translate.write.WriteContext;
import io.fd.honeycomb.v3po.translate.write.WriteFailedException;
@@ -34,6 +40,7 @@ import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
+import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.contexts.naming.context.Mappings;
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.dto.BridgeDomainAddDel;
@@ -47,18 +54,22 @@ public class BridgeDomainCustomizerTest {
@Mock
private FutureJVpp api;
-
@Mock
private WriteContext ctx;
+ @Mock
+ private MappingContext mappingContext;
private BridgeDomainCustomizer customizer;
- private NamingContext namingContext;
@Before
public void setUp() throws Exception {
initMocks(this);
// TODO create base class for tests using vppApi
- namingContext = new NamingContext("generatedBDName");
+ 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);
}
@@ -139,12 +150,14 @@ public class BridgeDomainCustomizerTest {
final int bdId = 1;
final String bdName = "bd1";
final BridgeDomain bd = generateBridgeDomain(bdName);
+ doReturn(Optional.absent()).when(mappingContext).read(getMappingIid(bdName, "test-instance").firstIdentifierOf(Mappings.class));
whenBridgeDomainAddDelThenSuccess();
customizer.writeCurrentAttributes(BridgeDomainTestUtils.bdIdentifierForName(bdName), bd, ctx);
verifyBridgeDomainAddOrUpdateWasInvoked(bd, bdId);
+ verify(mappingContext).put(getMappingIid(bdName, "test-instance"), getMapping(bdName, bdId).get());
}
@Test
@@ -153,6 +166,9 @@ public class BridgeDomainCustomizerTest {
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(getMappingIid(bdName, "test-instance").firstIdentifierOf(Mappings.class));
+
whenBridgeDomainAddDelThenFailure();
try {
@@ -169,7 +185,7 @@ public class BridgeDomainCustomizerTest {
final int bdId = 1;
final String bdName = "bd1";
final BridgeDomain bd = generateBridgeDomain(bdName);
- namingContext.addName(bdId, bdName);
+ doReturn(getMapping(bdName, bdId)).when(mappingContext).read(getMappingIid(bdName, "test-instance"));
whenBridgeDomainAddDelThenSuccess();
@@ -182,6 +198,7 @@ public class BridgeDomainCustomizerTest {
public void testDeleteUnknownBridgeDomain() throws Exception {
final String bdName = "bd1";
final BridgeDomain bd = generateBridgeDomain("bd1");
+ doReturn(Optional.absent()).when(mappingContext).read(getMappingIid(bdName, "test-instance"));
try {
customizer.deleteCurrentAttributes(BridgeDomainTestUtils.bdIdentifierForName(bdName), bd, ctx);
@@ -197,7 +214,7 @@ public class BridgeDomainCustomizerTest {
final int bdId = 1;
final String bdName = "bd1";
final BridgeDomain bd = generateBridgeDomain(bdName);
- namingContext.addName(bdId, bdName);
+ doReturn(getMapping(bdName, bdId)).when(mappingContext).read(getMappingIid(bdName, "test-instance"));
whenBridgeDomainAddDelThenFailure();
@@ -215,7 +232,7 @@ public class BridgeDomainCustomizerTest {
public void testUpdateBridgeDomain() throws Exception {
final int bdId = 1;
final String bdName = "bd1";
- namingContext.addName(bdId, bdName);
+ doReturn(getMapping(bdName, bdId)).when(mappingContext).read(getMappingIid(bdName, "test-instance"));
final byte arpTermBefore = 1;
final byte floodBefore = 1;
@@ -241,6 +258,7 @@ public class BridgeDomainCustomizerTest {
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(getMappingIid(bdName, "test-instance"));
try {
customizer.updateCurrentAttributes(BridgeDomainTestUtils.bdIdentifierForName(bdName), bdBefore, bdAfter, ctx);
@@ -257,7 +275,7 @@ public class BridgeDomainCustomizerTest {
final String bdName = "bd1";
final BridgeDomain bdBefore = generateBridgeDomain(bdName, 0, 1, 0 ,1, 0);
final BridgeDomain bdAfter = generateBridgeDomain(bdName, 1, 1, 0 ,1, 0);
- namingContext.addName(bdId, bdName);
+ doReturn(getMapping(bdName, bdId)).when(mappingContext).read(getMappingIid(bdName, "test-instance"));
whenBridgeDomainAddDelThenFailure();
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/vpp/VppTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/vpp/VppTest.java
index 820cf0555..1b30fdde7 100644
--- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/vpp/VppTest.java
+++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/vpp/VppTest.java
@@ -16,15 +16,21 @@
package io.fd.honeycomb.v3po.translate.v3po.vpp;
+import static io.fd.honeycomb.v3po.translate.v3po.ContextTestUtils.getMapping;
+import static io.fd.honeycomb.v3po.translate.v3po.ContextTestUtils.getMappingIid;
import static 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 static org.mockito.Mockito.verifyZeroInteractions;
import static org.mockito.Mockito.when;
+import com.google.common.base.Optional;
import com.google.common.collect.Iterators;
import com.google.common.collect.Lists;
+import io.fd.honeycomb.v3po.translate.MappingContext;
+import io.fd.honeycomb.v3po.translate.ModificationCache;
import io.fd.honeycomb.v3po.translate.impl.write.CompositeRootWriter;
import io.fd.honeycomb.v3po.translate.util.write.DelegatingWriterRegistry;
import io.fd.honeycomb.v3po.translate.v3po.util.NamingContext;
@@ -38,6 +44,9 @@ import java.util.concurrent.ExecutionException;
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.opendaylight.params.xml.ns.yang.v3po.rev150105.Vpp;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VppBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.BridgeDomains;
@@ -54,17 +63,24 @@ public class VppTest {
private static final byte ADD_OR_UPDATE_BD = 1;
private static final byte ZERO = 0;
+ @Mock
private FutureJVpp api;
+ @Mock
+ private WriteContext ctx;
+ @Mock
+ private MappingContext mappingContext;
+
private DelegatingWriterRegistry rootRegistry;
private CompositeRootWriter<Vpp> vppWriter;
- private WriteContext ctx;
- private NamingContext bdContext;
@Before
public void setUp() throws Exception {
- api = mock(FutureJVpp.class);
- ctx = mock(WriteContext.class);
- bdContext = new NamingContext("generatedBdName");
+ MockitoAnnotations.initMocks(this);
+ NamingContext bdContext = new NamingContext("generatedBdName", "test-instance");
+ final ModificationCache toBeReturned = new ModificationCache();
+ doReturn(toBeReturned).when(ctx).getModificationCache();
+ doReturn(mappingContext).when(ctx).getMappingContext();
+
vppWriter = VppUtils.getVppWriter(api, bdContext);
rootRegistry = new DelegatingWriterRegistry(
Collections.<Writer<? extends DataObject>>singletonList(vppWriter));
@@ -134,6 +150,8 @@ public class VppTest {
final int bdId = 1;
final BridgeDomains bdn1 = getBridgeDomains("bdn1");
whenBridgeDomainAddDelThen(0);
+ doReturn(Optional
+ .absent()).when(mappingContext).read(getMappingIid("bdn1", "test-instance").firstIdentifierOf(Mappings.class));
rootRegistry.update(
InstanceIdentifier.create(Vpp.class),
@@ -149,6 +167,8 @@ public class VppTest {
final int bdId = 1;
final BridgeDomains bdn1 = getBridgeDomains("bdn1");
whenBridgeDomainAddDelThen(0);
+ doReturn(Optional
+ .absent()).when(mappingContext).read(getMappingIid("bdn1", "test-instance").firstIdentifierOf(Mappings.class));
vppWriter.update(InstanceIdentifier.create(Vpp.class),
null,
@@ -156,6 +176,7 @@ public class VppTest {
ctx);
verifyBridgeDomainAddDel(Iterators.getOnlyElement(bdn1.getBridgeDomain().iterator()), bdId);
+ verify(mappingContext).put(getMappingIid("bdn1", "test-instance"), getMapping("bdn1", 1).get());
}
@Test
@@ -163,9 +184,11 @@ public class VppTest {
final BridgeDomains bdn1 = getBridgeDomains("bdn1");
final int bdId = 1;
final Vpp vpp = new VppBuilder().setBridgeDomains(bdn1).build();
+ doReturn(Optional
+ .absent()).when(mappingContext).read(getMappingIid("bdn1", "test-instance").firstIdentifierOf(Mappings.class));
whenBridgeDomainAddDelThen(0);
- rootRegistry.update(Collections.<InstanceIdentifier<?>, DataObject>emptyMap(),
+ rootRegistry.update(Collections.emptyMap(),
Collections.<InstanceIdentifier<?>, DataObject>singletonMap(InstanceIdentifier.create(Vpp.class),
vpp), ctx);
@@ -178,7 +201,7 @@ public class VppTest {
final BridgeDomains bdn1 = getBridgeDomains(bdName);
final int bdId = 1;
whenBridgeDomainAddDelThen(0);
- bdContext.addName(bdId, bdName);
+ doReturn(getMapping(bdName, bdId)).when(mappingContext).read(getMappingIid(bdName, "test-instance"));
rootRegistry.update(
InstanceIdentifier.create(Vpp.class),
@@ -204,7 +227,8 @@ public class VppTest {
public void writeUpdate() throws Exception {
final String bdName = "bdn1";
final int bdn1Id = 1;
- bdContext.addName(bdn1Id, bdName);
+ doReturn(getMapping(bdName, bdn1Id)).when(mappingContext).read(getMappingIid(bdName, "test-instance"));
+
final BridgeDomains domainsBefore = getBridgeDomains(bdName);
final BridgeDomain bdn1Before = domainsBefore.getBridgeDomain().get(0);
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/vppstate/BridgeDomainCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/vppstate/BridgeDomainCustomizerTest.java
index c482c4485..369038687 100644
--- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/vppstate/BridgeDomainCustomizerTest.java
+++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/vppstate/BridgeDomainCustomizerTest.java
@@ -40,8 +40,8 @@ public class BridgeDomainCustomizerTest extends ListReaderCustomizerTest<BridgeD
@Override
public void setUpBefore() {
- bdContext = new NamingContext("generatedBdName");
- interfacesContext = new NamingContext("generatedIfaceName");
+ bdContext = new NamingContext("generatedBdName", "bd-test-instance");
+ interfacesContext = new NamingContext("generatedIfaceName", "ifc-test-instance");
}
@Test
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/vppstate/VppStateTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/vppstate/VppStateTest.java
index bf1d12152..3d75d09e2 100644
--- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/vppstate/VppStateTest.java
+++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/v3po/translate/v3po/vppstate/VppStateTest.java
@@ -16,18 +16,24 @@
package io.fd.honeycomb.v3po.translate.v3po.vppstate;
+import static io.fd.honeycomb.v3po.translate.v3po.ContextTestUtils.getMapping;
+import static io.fd.honeycomb.v3po.translate.v3po.ContextTestUtils.getMappingIid;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.doAnswer;
+import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.mockito.MockitoAnnotations.initMocks;
import com.google.common.base.Optional;
import com.google.common.collect.Iterables;
+import com.google.common.collect.Lists;
import com.google.common.collect.Multimap;
+import io.fd.honeycomb.v3po.translate.MappingContext;
+import io.fd.honeycomb.v3po.translate.ModificationCache;
import io.fd.honeycomb.v3po.translate.impl.read.CompositeListReader;
import io.fd.honeycomb.v3po.translate.impl.read.CompositeRootReader;
import io.fd.honeycomb.v3po.translate.read.ReadContext;
@@ -43,6 +49,9 @@ import java.util.concurrent.ExecutionException;
import org.junit.Before;
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.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VppState;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VppStateBuilder;
@@ -72,6 +81,8 @@ public class VppStateTest {
private FutureJVpp api;
@Mock
private ReadContext ctx;
+ @Mock
+ private MappingContext mappingContext;
private NamingContext bdContext;
private NamingContext interfaceContext;
@@ -82,9 +93,12 @@ public class VppStateTest {
@Before
public void setUp() throws Exception {
initMocks(this);
+ final ModificationCache cache = new ModificationCache();
+ doReturn(cache).when(ctx).getModificationCache();
+ doReturn(mappingContext).when(ctx).getMappingContext();
- bdContext = new NamingContext("generatedBdName");
- interfaceContext = new NamingContext("generatedInterfaceName");
+ bdContext = new NamingContext("generatedBdName", "bd-test-instance");
+ interfaceContext = new NamingContext("generatedIfaceName", "ifc-test-instance");
vppStateReader = VppStateTestUtils.getVppStateReader(api, bdContext, interfaceContext);
readerRegistry = new DelegatingReaderRegistry(Collections.<Reader<? extends DataObject>>singletonList(vppStateReader));
}
@@ -146,7 +160,14 @@ public class VppStateTest {
final Version version = getVersion();
whenShowVersionThenReturn(0, version);
- final List<BridgeDomainDetails> bdList = Arrays.asList(new BridgeDomainDetails(), new BridgeDomainDetails());
+ final BridgeDomainDetails bridgeDomainDetails = new BridgeDomainDetails();
+ final BridgeDomainDetails bridgeDomainDetails2 = new BridgeDomainDetails();
+ bridgeDomainDetails2.bdId = 1;
+
+ final List<BridgeDomainDetails> bdList = Arrays.asList(bridgeDomainDetails, bridgeDomainDetails2);
+ mockBdMapping(bridgeDomainDetails, "bd1");
+ mockBdMapping(bridgeDomainDetails2, "bd2");
+
whenBridgeDomainDumpThenReturn(bdList);
final Multimap<InstanceIdentifier<? extends DataObject>, ? extends DataObject> dataObjects = readerRegistry.readAll(ctx);
@@ -171,8 +192,10 @@ public class VppStateTest {
public void testReadBridgeDomains() throws Exception {
final Version version = getVersion();
whenShowVersionThenReturn(0, version);
- whenBridgeDomainDumpThenReturn(Collections.singletonList(new BridgeDomainDetails()));
+ final BridgeDomainDetails details = new BridgeDomainDetails();
+ whenBridgeDomainDumpThenReturn(Collections.singletonList(details));
+ mockBdMapping(details, "bdn1");
VppState readRoot = (VppState) readerRegistry.read(InstanceIdentifier.create(VppState.class), ctx).get();
Optional<? extends DataObject> read =
@@ -189,7 +212,9 @@ public class VppStateTest {
final BridgeDomainDetails bd = new BridgeDomainDetails();
bd.bdId = 0;
final String bdName = "bdn1";
- bdContext.addName(bd.bdId, bdName);
+ mockBdMapping(bd, bdName);
+ mockMapping("eth1", 0, "ifc-test-instance");
+
whenBridgeDomainDumpThenReturn(Collections.singletonList(bd));
final L2FibTableEntry l2FibEntry = new L2FibTableEntry();
l2FibEntry.bdId = 0;
@@ -204,18 +229,44 @@ public class VppStateTest {
assertTrue(read.isPresent());
// non existing l2fib
- read =
- readerRegistry.read(InstanceIdentifier.create(VppState.class).child(BridgeDomains.class).child(
+ read = readerRegistry.read(InstanceIdentifier.create(VppState.class).child(BridgeDomains.class).child(
BridgeDomain.class, new BridgeDomainKey("bdn1"))
.child(L2Fib.class, new L2FibKey(new PhysAddress("FF:FF:FF:04:05:06"))), ctx);
assertFalse(read.isPresent());
}
+ private void mockBdMapping(final BridgeDomainDetails bd, final String bdName) {
+ mockMapping(bdName, bd.bdId, "bd-test-instance");
+ }
+
+ private void mockMapping(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 Optional<Mappings> previousMappings = mappingContext.read(mappingsIid);
+
+ final MappingsBuilder mappingsBuilder;
+ if(previousMappings != null && previousMappings.isPresent()) {
+ mappingsBuilder = new MappingsBuilder(previousMappings.get());
+ } else {
+ mappingsBuilder = new MappingsBuilder();
+ mappingsBuilder.setMapping(Lists.newArrayList());
+ }
+
+ final List<Mapping> mappingList = mappingsBuilder.getMapping();
+ mappingList.add(singleMapping.get());
+ doReturn(Optional.of(mappingsBuilder.setMapping(mappingList).build()))
+ .when(mappingContext).read(mappingsIid);
+ doReturn(singleMapping).when(mappingContext).read(getMappingIid(name, namingContextName));
+ }
+
@Test
public void testReadBridgeDomainAll() throws Exception {
final Version version = getVersion();
whenShowVersionThenReturn(0, version);
- whenBridgeDomainDumpThenReturn(Collections.singletonList(new BridgeDomainDetails()));
+ final BridgeDomainDetails details = new BridgeDomainDetails();
+ whenBridgeDomainDumpThenReturn(Collections.singletonList(details));
+ mockBdMapping(details, "bd2");
VppState readRoot = (VppState) readerRegistry.read(InstanceIdentifier.create(VppState.class), ctx).get();
@@ -234,7 +285,8 @@ public class VppStateTest {
final BridgeDomainDetails bd = new BridgeDomainDetails();
bd.bdId = 0;
final String bdName = "bdn1";
- bdContext.addName(bd.bdId, bdName);
+ mockBdMapping(bd, bdName);
+
whenBridgeDomainDumpThenReturn(Collections.singletonList(bd));
whenShowVersionThenReturn(0, getVersion());
@@ -245,12 +297,15 @@ public class VppStateTest {
BridgeDomain.class, new BridgeDomainKey(bdName)), ctx);
assertTrue(read.isPresent());
- assertEquals(Iterables.find(readRoot.getBridgeDomains().getBridgeDomain(),
- input -> input.getKey().getName().equals(bdName)), read.get());
+ assertEquals(readRoot.getBridgeDomains().getBridgeDomain().stream().filter(
+ input -> input.getKey().getName().equals(bdName)).findFirst().get(),
+ read.get());
}
@Test(expected = IllegalArgumentException.class)
public void testReadBridgeDomainNotExisting() throws Exception {
+ doReturn(Optional.absent()).when(mappingContext).read(getMappingIid("NOT EXISTING", "bd-test-instance"));
+
final Optional<? extends DataObject> read =
readerRegistry.read(InstanceIdentifier.create(VppState.class).child(BridgeDomains.class).child(
BridgeDomain.class, new BridgeDomainKey("NOT EXISTING")), ctx);