summaryrefslogtreecommitdiffstats
path: root/v3po/v3po2vpp/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'v3po/v3po2vpp/src/test')
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/AclCustomizerTest.java20
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/AclCustomizerTest.java20
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/vppclassifier/ClassifySessionReaderTest.java21
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/vppclassifier/ClassifySessionWriterTest.java27
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/vppclassifier/ClassifyTableReaderTest.java41
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/vppclassifier/ClassifyTableWriterTest.java39
-rw-r--r--v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/vppclassifier/VppClassifierContextManagerImplTest.java155
7 files changed, 217 insertions, 106 deletions
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/AclCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/AclCustomizerTest.java
index 66e96b45d..578b24578 100644
--- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/AclCustomizerTest.java
+++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfaces/AclCustomizerTest.java
@@ -27,21 +27,18 @@ import static org.mockito.Mockito.verify;
import static org.mockito.MockitoAnnotations.initMocks;
import com.google.common.base.Optional;
-import com.google.common.collect.Lists;
import io.fd.honeycomb.translate.MappingContext;
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 io.fd.honeycomb.translate.write.WriteContext;
import io.fd.honeycomb.translate.write.WriteFailedException;
-import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
-import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.contexts.naming.context.Mappings;
-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.Interfaces;
@@ -68,13 +65,13 @@ public class AclCustomizerTest {
private WriteContext writeContext;
@Mock
private MappingContext mappingContext;
+ @Mock
+ private VppClassifierContextManager classifyTableContext;
private NamingContext interfaceContext;
- private NamingContext classifyTableContext;
private AclCustomizer customizer;
private static final String IFC_TEST_INSTANCE = "ifc-test-instance";
- private static final String CT_TEST_INSTANCE = "ct-test-instance";
private static final String IF_NAME = "local0";
private static final int IF_INDEX = 1;
@@ -85,23 +82,12 @@ public class AclCustomizerTest {
public void setUp() throws Exception {
initMocks(this);
interfaceContext = new NamingContext("generatedInterfaceName", IFC_TEST_INSTANCE);
- classifyTableContext = new NamingContext("generatedClassifyTable", CT_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);
-
- final KeyedInstanceIdentifier<Mapping, MappingKey> ctMappingKey =
- getMappingIid(ACL_TABLE_NAME, CT_TEST_INSTANCE);
- final Optional<Mapping> ctMapping = getMapping(ACL_TABLE_NAME, ACL_TABLE_INDEX);
- doReturn(ctMapping).when(mappingContext).read(ctMappingKey);
-
- final List<Mapping> allCtMappings = Lists.newArrayList(ctMapping.get());
- final Mappings allCtMappingsBaObject = new MappingsBuilder().setMapping(allCtMappings).build();
- doReturn(Optional.of(allCtMappingsBaObject)).when(mappingContext)
- .read(ctMappingKey.firstIdentifierOf(Mappings.class));
}
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/AclCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/AclCustomizerTest.java
index 84d2306e6..86cb6b90a 100644
--- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/AclCustomizerTest.java
+++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/interfacesstate/AclCustomizerTest.java
@@ -27,9 +27,11 @@ 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;
@@ -55,10 +57,11 @@ public class AclCustomizerTest extends ReaderCustomizerTest<Acl, AclBuilder> {
private static final String TABLE_NAME = "table123";
private static final String IFC_TEST_INSTANCE = "ifc-test-instance";
- private static final String CT_TEST_INSTANCE = "ct-test-instance";
private NamingContext interfaceContext;
- private NamingContext classifyTableContext;
+
+ @Mock
+ private VppClassifierContextManager classifyTableContext;
public AclCustomizerTest() {
super(Acl.class);
@@ -67,23 +70,12 @@ public class AclCustomizerTest extends ReaderCustomizerTest<Acl, AclBuilder> {
@Override
public void setUpBefore() {
interfaceContext = new NamingContext("generatedIfaceName", IFC_TEST_INSTANCE);
- classifyTableContext = new NamingContext("generatedTableContext", CT_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 KeyedInstanceIdentifier<Mapping, MappingKey> ctMappingKey = ContextTestUtils
- .getMappingIid(TABLE_NAME, CT_TEST_INSTANCE);
- final Optional<Mapping> ctMapping = ContextTestUtils.getMapping(TABLE_NAME, TABLE_INDEX);
- doReturn(ctMapping).when(mappingContext).read(ctMappingKey);
-
- final List<Mapping> allCtMappings = Lists.newArrayList(ctMapping.get());
- final Mappings allCtMappingsBaObject = new MappingsBuilder().setMapping(allCtMappings).build();
- doReturn(Optional.of(allCtMappingsBaObject)).when(mappingContext)
- .read(ctMappingKey.firstIdentifierOf(Mappings.class));
-
final List<Mapping> allIfcMappings = Lists.newArrayList(ifcMapping.get());
final Mappings allIfcMappingsBaObject = new MappingsBuilder().setMapping(allIfcMappings).build();
doReturn(Optional.of(allIfcMappingsBaObject)).when(mappingContext)
@@ -122,6 +114,8 @@ public class AclCustomizerTest extends ReaderCustomizerTest<Acl, AclBuilder> {
replyFuture.complete(reply);
doReturn(replyFuture).when(api).classifyTableByInterface(any(ClassifyTableByInterface.class));
+ doReturn(TABLE_NAME).when(classifyTableContext).getTableName(TABLE_INDEX, mappingContext);
+
getCustomizer().readCurrentAttributes(id, builder, ctx);
verify(builder).setL2Acl(new L2AclBuilder().setClassifyTable(TABLE_NAME).build());
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/vppclassifier/ClassifySessionReaderTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/vppclassifier/ClassifySessionReaderTest.java
index f5159919c..d1bda8793 100644
--- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/vppclassifier/ClassifySessionReaderTest.java
+++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/vppclassifier/ClassifySessionReaderTest.java
@@ -23,19 +23,16 @@ 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 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 java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import org.junit.Test;
-import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.contexts.naming.context.mappings.Mapping;
+import org.mockito.Mock;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.HexString;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.rev150603.VppClassifierState;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.rev150603.classify.table.base.attributes.ClassifySession;
@@ -58,23 +55,16 @@ public class ClassifySessionReaderTest extends
private static final int TABLE_INDEX = 1;
private static final String TABLE_NAME = "table1";
- private NamingContext classifyTableContext;
+ @Mock
+ private VppClassifierContextManager classifierContext;
public ClassifySessionReaderTest() {
super(ClassifySession.class);
}
@Override
- public void setUpBefore() {
- classifyTableContext = new NamingContext("classifyTableContext", "test-instance");
-
- final Optional<Mapping> ifcMapping = ContextTestUtils.getMapping(TABLE_NAME, TABLE_INDEX);
- doReturn(ifcMapping).when(mappingContext).read(any());
- }
-
- @Override
protected ReaderCustomizer<ClassifySession, ClassifySessionBuilder> initCustomizer() {
- return new ClassifySessionReader(api, classifyTableContext);
+ return new ClassifySessionReader(api, classifierContext);
}
private static InstanceIdentifier<ClassifySession> getClassifySessionId(final String tableName,
@@ -127,6 +117,9 @@ public class ClassifySessionReaderTest extends
replyFuture.complete(dump);
doReturn(replyFuture).when(api).classifySessionDump(any(ClassifySessionDump.class));
+ when(classifierContext.containsTable(TABLE_NAME, mappingContext)).thenReturn(true);
+ when(classifierContext.getTableIndex(TABLE_NAME, mappingContext)).thenReturn(TABLE_INDEX);
+
final List<ClassifySessionKey> allIds = getCustomizer().getAllIds(id, ctx);
assertEquals(2, allIds.size());
assertEquals(MATCH_1, allIds.get(0).getMatch().getValue());
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/vppclassifier/ClassifySessionWriterTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/vppclassifier/ClassifySessionWriterTest.java
index 85f7b8638..d7d7ded25 100644
--- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/vppclassifier/ClassifySessionWriterTest.java
+++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/vppclassifier/ClassifySessionWriterTest.java
@@ -16,20 +16,20 @@
package io.fd.honeycomb.translate.v3po.vppclassifier;
-import static io.fd.honeycomb.translate.v3po.test.ContextTestUtils.getMapping;
-import static junit.framework.TestCase.assertTrue;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
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.translate.MappingContext;
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 java.util.concurrent.CompletableFuture;
@@ -38,12 +38,12 @@ import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
-import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.contexts.naming.context.mappings.Mapping;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.HexString;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.rev150603.OpaqueIndex;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.rev150603.PacketHandlingAction;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.rev150603.VppClassifier;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.rev150603.VppNode;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.rev150603.VppNodeName;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.rev150603.classify.table.base.attributes.ClassifySession;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.rev150603.classify.table.base.attributes.ClassifySessionBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.rev150603.classify.table.base.attributes.ClassifySessionKey;
@@ -66,21 +66,26 @@ public class ClassifySessionWriterTest {
@Mock
private WriteContext writeContext;
@Mock
- private MappingContext mappingContext;
+ private MappingContext ctx;
+ @Mock
+ private VppClassifierContextManager classfierContext;
- private NamingContext classifyTableContext;
private ClassifySessionWriter customizer;
private static final int SESSION_INDEX = 456;
@Before
public void setUp() throws Exception {
initMocks(this);
- classifyTableContext = new NamingContext("generatedClassifyTableName", "test-instance");
- doReturn(mappingContext).when(writeContext).getMappingContext();
- customizer = new ClassifySessionWriter(api, classifyTableContext);
+ doReturn(ctx).when(writeContext).getMappingContext();
+ customizer = new ClassifySessionWriter(api, classfierContext);
+
+ when(classfierContext.containsTable(TABLE_NAME, ctx)).thenReturn(true);
+ when(classfierContext.getTableIndex(TABLE_NAME, ctx)).thenReturn(TABLE_INDEX);
- final Optional<Mapping> ifcMapping = getMapping(TABLE_NAME, TABLE_INDEX);
- doReturn(ifcMapping).when(mappingContext).read(any());
+ final ClassifyTable table = mock(ClassifyTable.class);
+ when(table.getClassifierNode()).thenReturn(new VppNodeName("ip4-classifier"));
+ when(writeContext.readAfter(any())).thenReturn(Optional.of(table));
+ when(writeContext.readBefore(any())).thenReturn(Optional.of(table));
}
private static ClassifySession generateClassifySession(final long opaqueIndex, final String match) {
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/vppclassifier/ClassifyTableReaderTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/vppclassifier/ClassifyTableReaderTest.java
index 38ca324d9..d4a8c4363 100644
--- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/vppclassifier/ClassifyTableReaderTest.java
+++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/vppclassifier/ClassifyTableReaderTest.java
@@ -23,21 +23,16 @@ 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.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.read.ReadFailedException;
-import io.fd.honeycomb.translate.v3po.util.NamingContext;
import java.util.List;
import java.util.concurrent.CompletableFuture;
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.mockito.Mock;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.HexString;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.rev150603.PacketHandlingAction;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.rev150603.VppClassifierState;
@@ -47,7 +42,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.clas
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.rev150603.vpp.classifier.state.ClassifyTableBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.rev150603.vpp.classifier.state.ClassifyTableKey;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
import org.openvpp.jvpp.core.dto.ClassifyTableIds;
import org.openvpp.jvpp.core.dto.ClassifyTableIdsReply;
import org.openvpp.jvpp.core.dto.ClassifyTableInfo;
@@ -61,32 +55,16 @@ public class ClassifyTableReaderTest extends
private static final int TABLE_INDEX_2 = 2;
private static final String TABLE_NAME_2 = "table2";
- private NamingContext classifyTableContext;
+ @Mock
+ private VppClassifierContextManager classifierContext;
public ClassifyTableReaderTest() {
super(ClassifyTable.class);
}
@Override
- public void setUpBefore() {
- classifyTableContext = new NamingContext("classifyTableContext", "test-instance");
-
- final KeyedInstanceIdentifier<Mapping, MappingKey> t0Id = ContextTestUtils
- .getMappingIid(TABLE_NAME_1, "test-instance");
- final KeyedInstanceIdentifier<Mapping, MappingKey> t1Id = ContextTestUtils
- .getMappingIid(TABLE_NAME_2, "test-instance");
- final Optional<Mapping> t0 = ContextTestUtils.getMapping(TABLE_NAME_1, TABLE_INDEX_1);
- final Optional<Mapping> t1 = ContextTestUtils.getMapping(TABLE_NAME_2, TABLE_INDEX_2);
- final List<Mapping> allMappings = Lists.newArrayList(t0.get(), t1.get());
- final Mappings allMappingsBaObject = new MappingsBuilder().setMapping(allMappings).build();
- doReturn(Optional.of(allMappingsBaObject)).when(mappingContext).read(t0Id.firstIdentifierOf(Mappings.class));
- doReturn(t0).when(mappingContext).read(t0Id);
- doReturn(t1).when(mappingContext).read(t1Id);
- }
-
- @Override
protected ReaderCustomizer<ClassifyTable, ClassifyTableBuilder> initCustomizer() {
- return new ClassifyTableReader(api, classifyTableContext);
+ return new ClassifyTableReader(api, classifierContext);
}
private static InstanceIdentifier<ClassifyTable> getClassifyTableId(final String name) {
@@ -131,6 +109,10 @@ public class ClassifyTableReaderTest extends
replyFuture.complete(generateClassifyTableInfoReply());
doReturn(replyFuture).when(api).classifyTableInfo(any(ClassifyTableInfo.class));
+ when(classifierContext.containsTable(TABLE_NAME_1, mappingContext)).thenReturn(true);
+ when(classifierContext.getTableIndex(TABLE_NAME_1, mappingContext)).thenReturn(TABLE_INDEX_1);
+ when(classifierContext.getTableBaseNode(TABLE_NAME_1, mappingContext)).thenReturn(Optional.absent());
+
final ClassifyTableBuilder builder = mock(ClassifyTableBuilder.class);
getCustomizer().readCurrentAttributes(getClassifyTableId(TABLE_NAME_1), builder, ctx);
@@ -145,6 +127,9 @@ public class ClassifyTableReaderTest extends
replyFuture.complete(reply);
doReturn(replyFuture).when(api).classifyTableIds(any(ClassifyTableIds.class));
+ when(classifierContext.getTableName(TABLE_INDEX_1, mappingContext)).thenReturn(TABLE_NAME_1);
+ when(classifierContext.getTableName(TABLE_INDEX_2, mappingContext)).thenReturn(TABLE_NAME_2);
+
final List<ClassifyTableKey> allIds = getCustomizer().getAllIds(getClassifyTableId(TABLE_NAME_1), ctx);
assertEquals(reply.ids.length, allIds.size());
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/vppclassifier/ClassifyTableWriterTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/vppclassifier/ClassifyTableWriterTest.java
index 5a3717e50..af91ead8c 100644
--- a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/vppclassifier/ClassifyTableWriterTest.java
+++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/vppclassifier/ClassifyTableWriterTest.java
@@ -16,23 +16,19 @@
package io.fd.honeycomb.translate.v3po.vppclassifier;
-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.assertArrayEquals;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
+import 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.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 java.util.concurrent.CompletableFuture;
@@ -41,11 +37,11 @@ import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
-import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.contexts.naming.context.mappings.Mapping;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.HexString;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.rev150603.PacketHandlingAction;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.rev150603.VppClassifier;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.rev150603.VppNode;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.rev150603.VppNodeName;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.rev150603.vpp.classifier.ClassifyTable;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.rev150603.vpp.classifier.ClassifyTableBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.rev150603.vpp.classifier.ClassifyTableKey;
@@ -66,22 +62,23 @@ public class ClassifyTableWriterTest {
@Mock
private WriteContext writeContext;
@Mock
- private MappingContext mappingContext;
+ private MappingContext ctx;
+ @Mock
+ private VppClassifierContextManager classifierContext;
- private NamingContext classifyTableContext;
private ClassifyTableWriter customizer;
@Before
public void setUp() throws Exception {
initMocks(this);
- classifyTableContext = new NamingContext("generatedClassifyTableName", "test-instance");
- doReturn(mappingContext).when(writeContext).getMappingContext();
- customizer = new ClassifyTableWriter(api, classifyTableContext);
+ customizer = new ClassifyTableWriter(api, classifierContext);
+ doReturn(ctx).when(writeContext).getMappingContext();
}
private static ClassifyTable generateClassifyTable(final String name) {
final ClassifyTableBuilder builder = new ClassifyTableBuilder();
builder.setName(name);
+ builder.setClassifierNode(new VppNodeName("ip4-classifier"));
builder.setKey(new ClassifyTableKey(name));
builder.setSkipNVectors(0L);
builder.setNbuckets(2L);
@@ -158,8 +155,7 @@ public class ClassifyTableWriterTest {
customizer.writeCurrentAttributes(id, classifyTable, writeContext);
verifyClassifyAddDelTableAddWasInvoked(generateClassifyAddDelTable((byte) 1, TABLE_INDEX));
- verify(mappingContext)
- .put(eq(getMappingIid(TABLE_NAME, "test-instance")), eq(getMapping(TABLE_NAME, TABLE_INDEX).get()));
+ verify(classifierContext).addTable(TABLE_INDEX, classifyTable.getName(), classifyTable.getClassifierNode(), ctx);
}
@Test
@@ -174,9 +170,8 @@ public class ClassifyTableWriterTest {
} catch (WriteFailedException.CreateFailedException e) {
assertTrue(e.getCause() instanceof VppBaseCallException);
verifyClassifyAddDelTableAddWasInvoked(generateClassifyAddDelTable((byte) 1, TABLE_INDEX));
- verify(mappingContext, times(0)).put(
- eq(getMappingIid(TABLE_NAME, "test-instance")),
- eq(getMapping(TABLE_NAME, TABLE_INDEX).get()));
+ verify(classifierContext, times(0))
+ .addTable(TABLE_INDEX, classifyTable.getName(), classifyTable.getClassifierNode(), ctx);
return;
}
fail("WriteFailedException.CreateFailedException was expected");
@@ -187,9 +182,8 @@ public class ClassifyTableWriterTest {
final ClassifyTable classifyTable = generateClassifyTable(TABLE_NAME);
final InstanceIdentifier<ClassifyTable> id = getClassifyTableId(TABLE_NAME);
- final Optional<Mapping> ifcMapping = getMapping(TABLE_NAME, TABLE_INDEX);
- doReturn(ifcMapping).when(mappingContext).read(any());
-
+ when(classifierContext.containsTable(TABLE_NAME, ctx)).thenReturn(true);
+ when(classifierContext.getTableIndex(TABLE_NAME, ctx)).thenReturn(TABLE_INDEX);
whenClassifyAddDelTableThenSuccess();
customizer.deleteCurrentAttributes(id, classifyTable, writeContext);
@@ -202,9 +196,8 @@ public class ClassifyTableWriterTest {
final ClassifyTable classifyTable = generateClassifyTable(TABLE_NAME);
final InstanceIdentifier<ClassifyTable> id = getClassifyTableId(TABLE_NAME);
- final Optional<Mapping> ifcMapping = getMapping(TABLE_NAME, TABLE_INDEX);
- doReturn(ifcMapping).when(mappingContext).read(any());
-
+ when(classifierContext.containsTable(TABLE_NAME, ctx)).thenReturn(true);
+ when(classifierContext.getTableIndex(TABLE_NAME, ctx)).thenReturn(TABLE_INDEX);
whenClassifyAddDelTableThenFailure();
try {
diff --git a/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/vppclassifier/VppClassifierContextManagerImplTest.java b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/vppclassifier/VppClassifierContextManagerImplTest.java
new file mode 100644
index 000000000..cbc0c3802
--- /dev/null
+++ b/v3po/v3po2vpp/src/test/java/io/fd/honeycomb/translate/v3po/vppclassifier/VppClassifierContextManagerImplTest.java
@@ -0,0 +1,155 @@
+/*
+ * Copyright (c) 2016 Cisco and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.honeycomb.translate.v3po.vppclassifier;
+
+import static io.fd.honeycomb.translate.v3po.vppclassifier.VppClassifierContextManagerImpl.VPP_CLASSIFIER_CONTEXT_IID;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+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.translate.MappingContext;
+import java.util.Arrays;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.rev150603.VppNodeName;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.rev160909.VppClassifierContext;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.rev160909.VppClassifierContextBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.rev160909.vpp.classifier.context.ClassifyTableContext;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.rev160909.vpp.classifier.context.ClassifyTableContextBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.rev160909.vpp.classifier.context.ClassifyTableContextKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.rev160909.vpp.classifier.context.classify.table.context.NodeContext;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.rev160909.vpp.classifier.context.classify.table.context.NodeContextBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.classifier.rev160909.vpp.classifier.context.classify.table.context.NodeContextKey;
+import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
+
+public class VppClassifierContextManagerImplTest {
+
+ private static final int TABLE_ID_0 = 0;
+ private static final String TABLE_NAME_0 = "table0";
+ private static final KeyedInstanceIdentifier<ClassifyTableContext, ClassifyTableContextKey> TABLE_IID_0 =
+ VPP_CLASSIFIER_CONTEXT_IID.child(ClassifyTableContext.class, new ClassifyTableContextKey(TABLE_NAME_0));
+
+ private static final int TABLE_ID_1 = 1;
+ private static final String TABLE_NAME_1 = "table1";
+
+ private VppClassifierContextManagerImpl vppClassfierContext;
+
+ @Mock
+ private MappingContext ctx;
+
+ @Before
+ public void setUp() throws Exception {
+ initMocks(this);
+ vppClassfierContext = new VppClassifierContextManagerImpl("classify-table-");
+ }
+
+ @Test
+ public void testAddTable() throws Exception {
+ final String classfierNodeName = "node123";
+ vppClassfierContext.addTable(TABLE_ID_0, TABLE_NAME_0, new VppNodeName(classfierNodeName), ctx);
+ verify(ctx).put(TABLE_IID_0, table(TABLE_ID_0, TABLE_NAME_0, classfierNodeName));
+ }
+
+ @Test
+ public void testContainsTable() throws Exception {
+ when(ctx.read(TABLE_IID_0)).thenReturn(Optional.absent());
+ assertFalse(vppClassfierContext.containsTable(TABLE_NAME_0, ctx));
+ }
+
+ @Test
+ public void testGetTableIndex() throws Exception {
+ when(ctx.read(TABLE_IID_0)).thenReturn(Optional.of(table(TABLE_ID_0, TABLE_NAME_0)));
+ assertEquals(TABLE_ID_0, vppClassfierContext.getTableIndex(TABLE_NAME_0, ctx));
+ }
+
+ @Test
+ public void testGetTableName() throws Exception {
+ when(ctx.read(VPP_CLASSIFIER_CONTEXT_IID))
+ .thenReturn(Optional.of(context(table(TABLE_ID_0, TABLE_NAME_0), table(TABLE_ID_1, TABLE_NAME_1))));
+ assertEquals(TABLE_NAME_0, (vppClassfierContext.getTableName(TABLE_ID_0, ctx)));
+ }
+
+ @Test
+ public void testGetTableBaseNode() throws Exception {
+ final String classfierNodeName = "node123";
+ when(ctx.read(TABLE_IID_0)).thenReturn(Optional.of(table(TABLE_ID_0, TABLE_NAME_0, classfierNodeName)));
+ vppClassfierContext.getTableBaseNode(TABLE_NAME_0, ctx);
+ assertEquals(Optional.of(classfierNodeName), (vppClassfierContext.getTableBaseNode(TABLE_NAME_0, ctx)));
+ }
+
+ @Test
+ public void testRemoveTable() throws Exception {
+ vppClassfierContext.removeTable(TABLE_NAME_0, ctx);
+ verify(ctx).delete(TABLE_IID_0);
+ }
+
+ @Test
+ public void testAddNodeName() throws Exception {
+ final String nodeName = "node123";
+ final int nodeIndex = 1;
+
+ vppClassfierContext.addNodeName(TABLE_NAME_0, nodeIndex, nodeName, ctx);
+ verify(ctx).put(
+ TABLE_IID_0.child(NodeContext.class, new NodeContextKey(nodeName)),
+ node(nodeName, nodeIndex)
+ );
+ }
+
+ @Test
+ public void testGetNonExistingNodeName() throws Exception {
+ when(ctx.read(VPP_CLASSIFIER_CONTEXT_IID)).thenReturn(Optional.of(context(table(TABLE_ID_1, TABLE_NAME_1))));
+ assertFalse(vppClassfierContext.getNodeName(TABLE_ID_0, 123, ctx).isPresent());
+ }
+
+ @Test
+ public void testGetNodeName() throws Exception {
+ final ClassifyTableContext tableCtx = table(TABLE_ID_0, TABLE_NAME_0, "aa", node("node123", 123));
+ when(ctx.read(VPP_CLASSIFIER_CONTEXT_IID)).thenReturn(Optional.of(context(tableCtx)));
+ when(ctx.read(TABLE_IID_0)).thenReturn(Optional.of(tableCtx));
+ assertEquals(Optional.of("node123"), vppClassfierContext.getNodeName(TABLE_ID_0, 123, ctx));
+ }
+
+ private VppClassifierContext context(ClassifyTableContext... tables) {
+ VppClassifierContextBuilder context = new VppClassifierContextBuilder();
+ context.setClassifyTableContext(Arrays.asList(tables));
+ return context.build();
+ }
+
+ private static ClassifyTableContext table(final Integer id, final String name) {
+ return table(id, name, null);
+ }
+
+ private static ClassifyTableContext table(final Integer id, final String name, final String classfierNodeName,
+ final NodeContext... nodeContexts) {
+ final ClassifyTableContextBuilder builder =
+ new ClassifyTableContextBuilder().setIndex(id).setName(name).setClassifierNodeName(classfierNodeName);
+
+ if (nodeContexts.length > 0) {
+ builder.setNodeContext(Arrays.asList(nodeContexts));
+ }
+
+ return builder.build();
+ }
+
+ private NodeContext node(final String nodeName, final int nodeIndex) {
+ return new NodeContextBuilder().setName(nodeName).setIndex(nodeIndex).build();
+ }
+} \ No newline at end of file