From 3c310e16d44083b03a64a78295b3295c8a0465bc Mon Sep 17 00:00:00 2001 From: Jan Srnicek Date: Fri, 10 Feb 2017 10:43:31 +0100 Subject: HONEYCOMB-335 - Initialization test support - initialization test support for container and list customizers - test samples Change-Id: If3fe4faf82a86c43fafdfab694a4388d50f61de4 Signed-off-by: Jan Srnicek --- .../translate/read/LispStateCustomizerTest.java | 38 ++++++++++--- .../translate/read/LocatorSetCustomizerTest.java | 63 +++++++++++++++++----- lisp/lisp2vpp/src/test/resources/lisp-config.json | 7 +++ .../src/test/resources/lisp-operational.json | 7 +++ lisp/lisp2vpp/src/test/resources/locator-set.json | 5 ++ .../common/test/read/InitializationTest.java | 54 +++++++++++++++++++ .../read/InitializingListReaderCustomizerTest.java | 17 ++++-- .../read/InitializingReaderCustomizerTest.java | 12 ++++- 8 files changed, 181 insertions(+), 22 deletions(-) create mode 100644 lisp/lisp2vpp/src/test/resources/lisp-config.json create mode 100644 lisp/lisp2vpp/src/test/resources/lisp-operational.json create mode 100644 lisp/lisp2vpp/src/test/resources/locator-set.json create mode 100644 vpp-common/vpp-translate-test/src/main/java/io/fd/hc2vpp/common/test/read/InitializationTest.java 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 3df3f35b7..06eda220f 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,21 +16,32 @@ package io.fd.hc2vpp.lisp.translate.read; -import static org.junit.Assert.assertEquals; -import static org.mockito.Mockito.when; - +import com.google.common.collect.ImmutableSet; +import io.fd.hc2vpp.common.test.read.InitializingReaderCustomizerTest; +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.hc2vpp.common.test.read.ReaderCustomizerTest; +import io.fd.vpp.jvpp.core.dto.ShowLispStatusReply; import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; import org.mockito.Mockito; +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 io.fd.vpp.jvpp.core.dto.ShowLispStatusReply; -public class LispStateCustomizerTest extends ReaderCustomizerTest { +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.when; + +@RunWith(HoneycombTestRunner.class) +public class LispStateCustomizerTest extends InitializingReaderCustomizerTest + implements InjectablesProcessor{ private InstanceIdentifier identifier; @@ -56,6 +67,21 @@ public class LispStateCustomizerTest extends ReaderCustomizerTest operationalPath = InstanceIdentifier.create(LispState.class); + final InstanceIdentifier configPath = InstanceIdentifier.create(Lisp.class); + + invokeInitTest(operationalPath, operational, configPath, config); + } + @Override protected ReaderCustomizer initCustomizer() { return new LispStateCustomizer(api); 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 7c57e6b63..744c57590 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 @@ -16,32 +16,50 @@ package io.fd.hc2vpp.lisp.translate.read; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.when; - import com.google.common.collect.ImmutableList; -import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; +import com.google.common.collect.ImmutableSet; +import io.fd.hc2vpp.common.test.read.InitializingListReaderCustomizerTest; import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.hc2vpp.common.test.read.ListReaderCustomizerTest; -import java.nio.charset.StandardCharsets; -import java.util.List; +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.spi.read.ReaderCustomizer; +import io.fd.vpp.jvpp.core.dto.LispLocatorSetDetails; +import io.fd.vpp.jvpp.core.dto.LispLocatorSetDetailsReplyDump; import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; +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.lisp.feature.data.grouping.LispFeatureData; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.locator.sets.grouping.LocatorSets; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.locator.sets.grouping.LocatorSetsBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.locator.sets.grouping.locator.sets.LocatorSet; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.locator.sets.grouping.locator.sets.LocatorSetBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.locator.sets.grouping.locator.sets.LocatorSetKey; +import org.opendaylight.yangtools.sal.binding.generator.impl.ModuleInfoBackedContext; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import io.fd.vpp.jvpp.core.dto.LispLocatorSetDetails; -import io.fd.vpp.jvpp.core.dto.LispLocatorSetDetailsReplyDump; +import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier; +import java.nio.charset.StandardCharsets; +import java.util.List; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.when; +@RunWith(HoneycombTestRunner.class) public class LocatorSetCustomizerTest - extends ListReaderCustomizerTest { + extends InitializingListReaderCustomizerTest + implements InjectablesProcessor { + private static final String LOC_1_PATH = "/lisp:lisp-state" + + "/lisp:lisp-feature-data" + + "/lisp:locator-sets" + + "/lisp:locator-set[lisp:name='loc1']"; private InstanceIdentifier emptyId; private InstanceIdentifier validId; @@ -89,6 +107,27 @@ public class LocatorSetCustomizerTest assertEquals("loc-set", keys.get(0).getName()); } + @SchemaContextProvider + public ModuleInfoBackedContext schemaContext() { + return provideSchemaContextFor(ImmutableSet.of($YangModuleInfoImpl.getInstance())); + } + + @Test + public void testInit(@InjectTestData(resourcePath = "/locator-set.json", id = LOC_1_PATH) LocatorSet locatorSet) { + final LocatorSetKey loc1Key = new LocatorSetKey("loc1"); + final KeyedInstanceIdentifier operationalPath = InstanceIdentifier.create(LispState.class) + .child(LispFeatureData.class) + .child(LocatorSets.class) + .child(LocatorSet.class, loc1Key); + + final KeyedInstanceIdentifier configPath = InstanceIdentifier.create(Lisp.class) + .child(LispFeatureData.class) + .child(LocatorSets.class) + .child(LocatorSet.class, loc1Key); + + invokeInitTest(operationalPath, locatorSet, configPath, locatorSet); + } + @Override protected ReaderCustomizer initCustomizer() { return new LocatorSetCustomizer(api, new NamingContext("loc", "locator-set-context")); diff --git a/lisp/lisp2vpp/src/test/resources/lisp-config.json b/lisp/lisp2vpp/src/test/resources/lisp-config.json new file mode 100644 index 000000000..27a92db58 --- /dev/null +++ b/lisp/lisp2vpp/src/test/resources/lisp-config.json @@ -0,0 +1,7 @@ +{ + "lisp": { + "enable": true, + "lisp-feature-data": { + } + } +} \ No newline at end of file diff --git a/lisp/lisp2vpp/src/test/resources/lisp-operational.json b/lisp/lisp2vpp/src/test/resources/lisp-operational.json new file mode 100644 index 000000000..436b71292 --- /dev/null +++ b/lisp/lisp2vpp/src/test/resources/lisp-operational.json @@ -0,0 +1,7 @@ +{ + "lisp-state": { + "enable":true, + "lisp-feature-data": { + } + } +} \ No newline at end of file diff --git a/lisp/lisp2vpp/src/test/resources/locator-set.json b/lisp/lisp2vpp/src/test/resources/locator-set.json new file mode 100644 index 000000000..446ba1104 --- /dev/null +++ b/lisp/lisp2vpp/src/test/resources/locator-set.json @@ -0,0 +1,5 @@ +{ + "locator-set": { + "name": "loc1" + } +} \ No newline at end of file diff --git a/vpp-common/vpp-translate-test/src/main/java/io/fd/hc2vpp/common/test/read/InitializationTest.java b/vpp-common/vpp-translate-test/src/main/java/io/fd/hc2vpp/common/test/read/InitializationTest.java new file mode 100644 index 000000000..5ea1257ce --- /dev/null +++ b/vpp-common/vpp-translate-test/src/main/java/io/fd/hc2vpp/common/test/read/InitializationTest.java @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2017 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.hc2vpp.common.test.read; + + +import io.fd.honeycomb.translate.read.ReadContext; +import io.fd.honeycomb.translate.spi.read.Initialized; +import io.fd.honeycomb.translate.spi.read.InitializingCustomizer; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +import javax.annotation.Nonnull; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +interface InitializationTest { + + /** + * Invokes initialization test + * + * @param customizer initialization capable customizer + * @param ctx read context + * @param operationalPath paths passed to initialization + * @param operationalData data passed to initialization + * @param configPath expected data path + * @param configData expected data + */ + default void invokeInit(@Nonnull final InitializingCustomizer customizer, + @Nonnull final ReadContext ctx, + @Nonnull final InstanceIdentifier operationalPath, + @Nonnull final D operationalData, + @Nonnull final InstanceIdentifier configPath, + @Nonnull final Object configData) { + final Initialized init = customizer.init(operationalPath, operationalData, ctx); + assertNotNull(init); + assertEquals(configPath, init.getId()); + assertEquals(configData, init.getData()); + } +} diff --git a/vpp-common/vpp-translate-test/src/main/java/io/fd/hc2vpp/common/test/read/InitializingListReaderCustomizerTest.java b/vpp-common/vpp-translate-test/src/main/java/io/fd/hc2vpp/common/test/read/InitializingListReaderCustomizerTest.java index b6089c4da..7ad2055c7 100644 --- a/vpp-common/vpp-translate-test/src/main/java/io/fd/hc2vpp/common/test/read/InitializingListReaderCustomizerTest.java +++ b/vpp-common/vpp-translate-test/src/main/java/io/fd/hc2vpp/common/test/read/InitializingListReaderCustomizerTest.java @@ -21,6 +21,9 @@ import org.opendaylight.yangtools.concepts.Builder; import org.opendaylight.yangtools.yang.binding.DataObject; import org.opendaylight.yangtools.yang.binding.Identifiable; import org.opendaylight.yangtools.yang.binding.Identifier; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +import javax.annotation.Nonnull; /** * Generic test for classes implementing {@link InitializingListReaderCustomizer} interface. @@ -30,11 +33,12 @@ import org.opendaylight.yangtools.yang.binding.Identifier; * @param Specific Builder for handled type (D) */ public abstract class InitializingListReaderCustomizerTest, K extends Identifier, B extends Builder> extends - ListReaderCustomizerTest { + ListReaderCustomizerTest implements InitializationTest { + protected InitializingListReaderCustomizerTest( - final Class dataObjectClass, - final Class> parentBuilderClass) { + final Class dataObjectClass, + final Class> parentBuilderClass) { super(dataObjectClass, parentBuilderClass); } @@ -42,4 +46,11 @@ public abstract class InitializingListReaderCustomizerTest getCustomizer() { return InitializingListReaderCustomizer.class.cast(super.getCustomizer()); } + + protected void invokeInitTest(@Nonnull InstanceIdentifier operationalPath, + @Nonnull D operationalData, + @Nonnull InstanceIdentifier configPath, + @Nonnull Object configData) { + invokeInit(getCustomizer(), ctx, operationalPath, operationalData, configPath, configData); + } } diff --git a/vpp-common/vpp-translate-test/src/main/java/io/fd/hc2vpp/common/test/read/InitializingReaderCustomizerTest.java b/vpp-common/vpp-translate-test/src/main/java/io/fd/hc2vpp/common/test/read/InitializingReaderCustomizerTest.java index e102ef827..69fd6abac 100644 --- a/vpp-common/vpp-translate-test/src/main/java/io/fd/hc2vpp/common/test/read/InitializingReaderCustomizerTest.java +++ b/vpp-common/vpp-translate-test/src/main/java/io/fd/hc2vpp/common/test/read/InitializingReaderCustomizerTest.java @@ -19,6 +19,9 @@ package io.fd.hc2vpp.common.test.read; import io.fd.honeycomb.translate.spi.read.InitializingReaderCustomizer; import org.opendaylight.yangtools.concepts.Builder; import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +import javax.annotation.Nonnull; /** * Generic test for classes implementing {@link InitializingReaderCustomizer} interface. @@ -27,7 +30,7 @@ import org.opendaylight.yangtools.yang.binding.DataObject; * @param Specific Builder for handled type (D) */ public abstract class InitializingReaderCustomizerTest> extends - ReaderCustomizerTest { + ReaderCustomizerTest implements InitializationTest { protected InitializingReaderCustomizerTest( final Class dataObjectClass, @@ -39,4 +42,11 @@ public abstract class InitializingReaderCustomizerTest getCustomizer() { return InitializingReaderCustomizer.class.cast(super.getCustomizer()); } + + protected void invokeInitTest(@Nonnull InstanceIdentifier operationalPath, + @Nonnull D operationalData, + @Nonnull InstanceIdentifier configPath, + @Nonnull Object configData) { + invokeInit(getCustomizer(), ctx, operationalPath, operationalData, configPath, configData); + } } -- cgit 1.2.3-korg