From f4600723aa5e0fa99905eacd3338b33728a6c68f Mon Sep 17 00:00:00 2001 From: Jan Srnicek Date: Wed, 26 Oct 2016 10:14:11 +0200 Subject: HONEYCOMB-266 - Test data injection with @InjectTestData Field/Method param injection of data from json files that are bindable/parsable by provided yang schema Change-Id: I726ef5d92e85d93d1e48175287b6192538965dd5 Signed-off-by: Maros Marsalek Signed-off-by: Jan Srnicek --- .../test/tools/HoneycombTestRunnerTest.java | 129 +++++++++++++++++++++ .../src/test/resources/containerInList.json | 5 + .../src/test/resources/leafInAugment.json | 7 ++ .../src/test/resources/nestedContainer.json | 5 + .../src/test/resources/simpleContainerEmpty.json | 4 + 5 files changed, 150 insertions(+) create mode 100644 infra/test-utils/test-tools/src/test/java/io/fd/honeycomb/test/tools/HoneycombTestRunnerTest.java create mode 100644 infra/test-utils/test-tools/src/test/resources/containerInList.json create mode 100644 infra/test-utils/test-tools/src/test/resources/leafInAugment.json create mode 100644 infra/test-utils/test-tools/src/test/resources/nestedContainer.json create mode 100644 infra/test-utils/test-tools/src/test/resources/simpleContainerEmpty.json (limited to 'infra/test-utils/test-tools/src/test') diff --git a/infra/test-utils/test-tools/src/test/java/io/fd/honeycomb/test/tools/HoneycombTestRunnerTest.java b/infra/test-utils/test-tools/src/test/java/io/fd/honeycomb/test/tools/HoneycombTestRunnerTest.java new file mode 100644 index 000000000..42de7ed4d --- /dev/null +++ b/infra/test-utils/test-tools/src/test/java/io/fd/honeycomb/test/tools/HoneycombTestRunnerTest.java @@ -0,0 +1,129 @@ +/* + * 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.test.tools; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; + +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 java.util.Collections; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.hc.data.rev150105.$YangModuleInfoImpl; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.hc.data.rev150105.AugContainerAugmentation; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.hc.data.rev150105.SimpleContainer; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.hc.data.rev150105.SimpleContainerBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.hc.data.rev150105.simple.container.NestedContainer; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.hc.data.rev150105.simple.container.simple.list.ContUnderList; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.hc.data.rev150105.simple.container.simple.list.ContUnderListBuilder; +import org.opendaylight.yangtools.sal.binding.generator.impl.ModuleInfoBackedContext; + +@RunWith(HoneycombTestRunner.class) +public class HoneycombTestRunnerTest implements InjectablesProcessor { + + @InjectTestData(resourcePath = "/simpleContainerEmpty.json") + private SimpleContainer simpleContainer; + + @InjectTestData(resourcePath = "/nestedContainer.json", id = "/hc-data:simple-container/hc-data:nested-container") + private NestedContainer nestedContainer; + + @InjectTestData(resourcePath = "/leafInAugment.json") + private SimpleContainer containerWithLeafInAugment; + + @InjectTestData(resourcePath = "/containerInList.json", id = "/hc-data:simple-container" + + "/hc-data:simple-list[hc-data:name='nameUnderSimpleList']" + + "/hc-data:cont-under-list") + private ContUnderList containerUnderList; + + @SchemaContextProvider + public ModuleInfoBackedContext getSchemaContext() { + return provideSchemaContextFor(Collections.singleton($YangModuleInfoImpl.getInstance())); + } + + @Test + public void testSimpleContainer() { + assertNotNull(simpleContainer); + } + + @Test + public void testNestedContainer() { + assertNotNull(nestedContainer); + assertEquals("abcd", nestedContainer.getName()); + } + + @Test + public void testLeafInAugmentedContainer() { + assertNotNull(containerWithLeafInAugment); + assertNotNull(containerWithLeafInAugment.getAugmentedContainer()); + assertEquals("nameInAugment", containerWithLeafInAugment.getAugmentedContainer().getAugmentation( + AugContainerAugmentation.class).getNameInAugment()); + } + + @Test + public void testContainerUnderList() { + assertNotNull(containerUnderList); + assertEquals("nestedName", containerUnderList.getNestedName()); + } + + @Test + public void testParameterInjectionRootNode( + @InjectTestData(resourcePath = "/simpleContainerEmpty.json") SimpleContainer container) { + assertNotNull(container); + } + + @Test + public void testParameterInjectionChildNode( + @InjectTestData(resourcePath = "/nestedContainer.json", + id = "/hc-data:simple-container/hc-data:nested-container") NestedContainer container) { + assertNotNull(container); + } + + @Test + public void testParameterInjectionMultiple( + @InjectTestData(resourcePath = "/simpleContainerEmpty.json") SimpleContainer containerFirst, + @InjectTestData(resourcePath = "/nestedContainer.json", + id = "/hc-data:simple-container/hc-data:nested-container") NestedContainer containerSecond) { + assertNotNull(containerFirst); + assertNotNull(containerSecond); + } + + @Test + public void testParameterInjectionOneNonInjectable( + @InjectTestData(resourcePath = "/simpleContainerEmpty.json") SimpleContainer containerFirst, + String thisOneShouldBeNull) { + assertNotNull(containerFirst); + assertNull(thisOneShouldBeNull); + } + + @Test + public void testConsistenceSimpleNode( + @InjectTestData(resourcePath = "/simpleContainerEmpty.json") SimpleContainer container) { + + assertEquals(new SimpleContainerBuilder().build(), simpleContainer); + } + + @Test + public void testConsistenceWithLeafNode( + @InjectTestData(resourcePath = "/containerInList.json", id = "/hc-data:simple-container" + + "/hc-data:simple-list[hc-data:name='nameUnderSimpleList']" + + "/hc-data:cont-under-list") ContUnderList containerUnderList) { + assertEquals(new ContUnderListBuilder().setNestedName("nestedName").build(), containerUnderList); + } +} \ No newline at end of file diff --git a/infra/test-utils/test-tools/src/test/resources/containerInList.json b/infra/test-utils/test-tools/src/test/resources/containerInList.json new file mode 100644 index 000000000..b55675e7c --- /dev/null +++ b/infra/test-utils/test-tools/src/test/resources/containerInList.json @@ -0,0 +1,5 @@ +{ + "cont-under-list":{ + "nested-name":"nestedName" + } +} \ No newline at end of file diff --git a/infra/test-utils/test-tools/src/test/resources/leafInAugment.json b/infra/test-utils/test-tools/src/test/resources/leafInAugment.json new file mode 100644 index 000000000..d3c52f3b8 --- /dev/null +++ b/infra/test-utils/test-tools/src/test/resources/leafInAugment.json @@ -0,0 +1,7 @@ +{ + "simple-container": { + "augmented-container":{ + "name-in-augment": "nameInAugment" + } + } +} \ No newline at end of file diff --git a/infra/test-utils/test-tools/src/test/resources/nestedContainer.json b/infra/test-utils/test-tools/src/test/resources/nestedContainer.json new file mode 100644 index 000000000..9cc986b87 --- /dev/null +++ b/infra/test-utils/test-tools/src/test/resources/nestedContainer.json @@ -0,0 +1,5 @@ +{ + "nested-container":{ + "name":"abcd" + } +} \ No newline at end of file diff --git a/infra/test-utils/test-tools/src/test/resources/simpleContainerEmpty.json b/infra/test-utils/test-tools/src/test/resources/simpleContainerEmpty.json new file mode 100644 index 000000000..4d56712c3 --- /dev/null +++ b/infra/test-utils/test-tools/src/test/resources/simpleContainerEmpty.json @@ -0,0 +1,4 @@ +{ + "simple-container": { + } +} \ No newline at end of file -- cgit 1.2.3-korg