summaryrefslogtreecommitdiffstats
path: root/lisp/lisp2vpp/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/lisp2vpp/src/test')
-rw-r--r--lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/read/LispStateCustomizerTest.java92
-rw-r--r--lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/read/LocatorSetCustomizerTest.java3
2 files changed, 87 insertions, 8 deletions
diff --git a/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/read/LispStateCustomizerTest.java b/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/read/LispStateCustomizerTest.java
index 06eda220f..e253b324a 100644
--- a/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/read/LispStateCustomizerTest.java
+++ b/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/read/LispStateCustomizerTest.java
@@ -16,32 +16,54 @@
package io.fd.hc2vpp.lisp.translate.read;
+import static org.junit.Assert.assertEquals;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyNoMoreInteractions;
+import static org.mockito.Mockito.when;
+
+import com.google.common.base.Optional;
import com.google.common.collect.ImmutableSet;
import io.fd.hc2vpp.common.test.read.InitializingReaderCustomizerTest;
+import io.fd.hc2vpp.common.test.util.NamingContextHelper;
+import io.fd.hc2vpp.common.translate.util.NamingContext;
import io.fd.honeycomb.test.tools.HoneycombTestRunner;
import io.fd.honeycomb.test.tools.annotations.InjectTestData;
import io.fd.honeycomb.test.tools.annotations.InjectablesProcessor;
import io.fd.honeycomb.test.tools.annotations.SchemaContextProvider;
import io.fd.honeycomb.translate.read.ReadFailedException;
import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
+import io.fd.vpp.jvpp.core.dto.LispLocatorSetDetails;
+import io.fd.vpp.jvpp.core.dto.LispLocatorSetDetailsReplyDump;
import io.fd.vpp.jvpp.core.dto.ShowLispStatusReply;
+import java.nio.charset.StandardCharsets;
+import java.util.Arrays;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
+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.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.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.opendaylight.params.xml.ns.yang.lisp.rev170315.$YangModuleInfoImpl;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.Lisp;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.LispState;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.LispStateBuilder;
import org.opendaylight.yangtools.sal.binding.generator.impl.ModuleInfoBackedContext;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-
-import static org.junit.Assert.assertEquals;
-import static org.mockito.Mockito.when;
+import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
@RunWith(HoneycombTestRunner.class)
public class LispStateCustomizerTest extends InitializingReaderCustomizerTest<LispState, LispStateBuilder>
- implements InjectablesProcessor{
+ implements InjectablesProcessor, NamingContextHelper {
+
+
+ private NamingContext locatorSetContext;
private InstanceIdentifier<LispState> identifier;
@@ -49,13 +71,15 @@ public class LispStateCustomizerTest extends InitializingReaderCustomizerTest<Li
super(LispState.class, null);
}
+ @Override
@Before
- public void init() {
+ public void setUp() {
identifier = InstanceIdentifier.create(LispState.class);
final ShowLispStatusReply reply = new ShowLispStatusReply();
reply.featureStatus = 1;
when(api.showLispStatus(Mockito.any())).thenReturn(future(reply));
+ locatorSetContext = new NamingContext("loc-set", "locator-set-context");
}
@Test
@@ -79,12 +103,68 @@ public class LispStateCustomizerTest extends InitializingReaderCustomizerTest<Li
final InstanceIdentifier<LispState> operationalPath = InstanceIdentifier.create(LispState.class);
final InstanceIdentifier<Lisp> configPath = InstanceIdentifier.create(Lisp.class);
+ when(api.lispLocatorSetDump(any())).thenReturn(future(new LispLocatorSetDetailsReplyDump()));
+
+ invokeInitTest(operationalPath, operational, configPath, config);
+ }
+
+ @Test
+ public void testInitWithLocatorSetContextInit(@InjectTestData(resourcePath = "/lisp-config.json") Lisp config,
+ @InjectTestData(resourcePath = "/lisp-operational.json") LispState operational) {
+ mockLocatorSetDump();
+ final InstanceIdentifier<LispState> operationalPath = InstanceIdentifier.create(LispState.class);
+ final InstanceIdentifier<Lisp> configPath = InstanceIdentifier.create(Lisp.class);
+
+ final KeyedInstanceIdentifier<org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.contexts.NamingContext, NamingContextKey>
+ namingContextId = InstanceIdentifier.create(Contexts.class).child(
+ org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.contexts.NamingContext.class,
+ new NamingContextKey("locator-set-context"));
+ final KeyedInstanceIdentifier<Mapping, MappingKey> loc1Key = namingContextId
+ .child(Mappings.class).child(Mapping.class, new MappingKey("loc_1"));
+
+ final Mapping loc1Data = new MappingBuilder().setIndex(0).setName("loc_1").build();
+
+ final KeyedInstanceIdentifier<Mapping, MappingKey> loc2Key = namingContextId
+ .child(Mappings.class).child(Mapping.class, new MappingKey("loc_2"));
+
+ final Mapping loc2Data = new MappingBuilder().setIndex(1).setName("loc_2").build();
+
+ when(mappingContext.read(namingContextId.child(Mappings.class)))
+ .thenReturn(Optional.of(new MappingsBuilder().setMapping(Arrays.asList(loc1Data, loc2Data)).build()));
+ when(mappingContext.read(loc1Key)).thenReturn(Optional.absent())
+ .thenReturn(Optional.of(loc1Data)).thenReturn(Optional.of(loc1Data));
+ when(mappingContext.read(loc2Key)).thenReturn(Optional.absent())
+ .thenReturn(Optional.of(loc2Data)).thenReturn(Optional.of(loc2Data));
+
+
invokeInitTest(operationalPath, operational, configPath, config);
+
+ // first read is inside contains,second one is for logger,and its x 2 locator sets
+ verify(mappingContext, times(4)).read(namingContextId.child(Mappings.class));
+ verify(mappingContext, times(1)).put(loc1Key, loc1Data);
+ verify(mappingContext, times(1)).read(loc1Key);
+ verify(mappingContext, times(1)).put(loc2Key, loc2Data);
+ verify(mappingContext, times(1)).read(loc2Key);
+ verifyNoMoreInteractions(mappingContext);
+ }
+
+ private void mockLocatorSetDump() {
+ LispLocatorSetDetailsReplyDump replyDump = new LispLocatorSetDetailsReplyDump();
+ LispLocatorSetDetails locator1 = new LispLocatorSetDetails();
+ locator1.lsIndex = 0;
+ locator1.lsName = "loc_1".getBytes(StandardCharsets.UTF_8);
+ LispLocatorSetDetails locator2 = new LispLocatorSetDetails();
+ locator2.lsIndex = 1;
+ locator2.lsName = "loc_2".getBytes(StandardCharsets.UTF_8);
+
+ replyDump.lispLocatorSetDetails = Arrays.asList(locator1, locator2);
+
+ when(api.lispLocatorSetDump(any())).thenReturn(future(replyDump));
}
@Override
protected ReaderCustomizer<LispState, LispStateBuilder> initCustomizer() {
- return new LispStateCustomizer(api);
+ return new LispStateCustomizer(api, locatorSetContext);
}
@Override
diff --git a/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/read/LocatorSetCustomizerTest.java b/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/read/LocatorSetCustomizerTest.java
index 82c4ceff2..419173857 100644
--- a/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/read/LocatorSetCustomizerTest.java
+++ b/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/read/LocatorSetCustomizerTest.java
@@ -22,7 +22,6 @@ import static org.mockito.Matchers.any;
import static org.mockito.Mockito.when;
import com.google.common.collect.ImmutableList;
-import io.fd.hc2vpp.common.translate.util.NamingContext;
import io.fd.honeycomb.test.tools.HoneycombTestRunner;
import io.fd.honeycomb.test.tools.annotations.InjectTestData;
import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
@@ -119,6 +118,6 @@ public class LocatorSetCustomizerTest
@Override
protected ReaderCustomizer<LocatorSet, LocatorSetBuilder> initCustomizer() {
- return new LocatorSetCustomizer(api, new NamingContext("loc", "locator-set-context"), lispStateCheckService);
+ return new LocatorSetCustomizer(api, lispStateCheckService);
}
} \ No newline at end of file