From de55d1e7c1fa5517ee6eabcd3fa23e5b5136d64b Mon Sep 17 00:00:00 2001 From: Jan Srnicek Date: Fri, 10 Feb 2017 08:55:55 +0100 Subject: HONEYCOMB-334 - List entry injection for yang data Major changes - mechanism to inject list entries by key - provided processor registry to hide explicit implementations Minor changes - general refactoring Test cases - list in root of model - list under container - list under nested container - list in augmentation Change-Id: I9abe1ce5f9176c132ad88627b135516574e40e06 Signed-off-by: Jan Srnicek --- .../test/tools/AbstractYangDataProcessorTest.java | 48 +++++++ .../test/tools/ContainerNodeDataProcessorTest.java | 60 +++++++++ .../tools/HoneycombTestRunnerContainerTest.java | 142 +++++++++++++++++++++ .../test/tools/HoneycombTestRunnerTest.java | 129 ------------------- .../fd/honeycomb/test/tools/InjectionTestData.java | 46 +++++++ .../test/tools/ListNodeDataProcessorTest.java | 79 ++++++++++++ .../src/test/resources/augmentListEntry.json | 10 ++ .../src/test/resources/nestedListEntry.json | 10 ++ .../src/test/resources/rootListEntry.json | 10 ++ .../src/test/resources/simpleListEntry.json | 10 ++ 10 files changed, 415 insertions(+), 129 deletions(-) create mode 100644 infra/test-utils/test-tools/src/test/java/io/fd/honeycomb/test/tools/AbstractYangDataProcessorTest.java create mode 100644 infra/test-utils/test-tools/src/test/java/io/fd/honeycomb/test/tools/ContainerNodeDataProcessorTest.java create mode 100644 infra/test-utils/test-tools/src/test/java/io/fd/honeycomb/test/tools/HoneycombTestRunnerContainerTest.java delete 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/java/io/fd/honeycomb/test/tools/InjectionTestData.java create mode 100644 infra/test-utils/test-tools/src/test/java/io/fd/honeycomb/test/tools/ListNodeDataProcessorTest.java create mode 100644 infra/test-utils/test-tools/src/test/resources/augmentListEntry.json create mode 100644 infra/test-utils/test-tools/src/test/resources/nestedListEntry.json create mode 100644 infra/test-utils/test-tools/src/test/resources/rootListEntry.json create mode 100644 infra/test-utils/test-tools/src/test/resources/simpleListEntry.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/AbstractYangDataProcessorTest.java b/infra/test-utils/test-tools/src/test/java/io/fd/honeycomb/test/tools/AbstractYangDataProcessorTest.java new file mode 100644 index 000000000..2d5f0259d --- /dev/null +++ b/infra/test-utils/test-tools/src/test/java/io/fd/honeycomb/test/tools/AbstractYangDataProcessorTest.java @@ -0,0 +1,48 @@ +/* + * 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.honeycomb.test.tools; + + +import io.fd.honeycomb.test.tools.annotations.InjectablesProcessor; +import org.junit.Before; +import org.opendaylight.controller.md.sal.binding.impl.BindingToNormalizedNodeCodec; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.hc.data.rev150105.$YangModuleInfoImpl; +import org.opendaylight.yangtools.sal.binding.generator.impl.ModuleInfoBackedContext; +import org.opendaylight.yangtools.yang.data.util.AbstractModuleStringInstanceIdentifierCodec; + +import java.lang.reflect.InvocationTargetException; +import java.util.Collections; + +abstract class AbstractYangDataProcessorTest implements InjectablesProcessor, YangContextProducer { + + ModuleInfoBackedContext moduleInfoBackedContext; + AbstractModuleStringInstanceIdentifierCodec codec; + BindingToNormalizedNodeCodec serializer; + + @Before + public void init() throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException { + moduleInfoBackedContext = provideSchemaContextFor(Collections.singleton($YangModuleInfoImpl.getInstance())); + codec = getIIDCodec(moduleInfoBackedContext); + serializer = createSerializer(moduleInfoBackedContext); + + // to init children + setUp(); + } + + // for children init + abstract void setUp(); +} diff --git a/infra/test-utils/test-tools/src/test/java/io/fd/honeycomb/test/tools/ContainerNodeDataProcessorTest.java b/infra/test-utils/test-tools/src/test/java/io/fd/honeycomb/test/tools/ContainerNodeDataProcessorTest.java new file mode 100644 index 000000000..e1dbc1803 --- /dev/null +++ b/infra/test-utils/test-tools/src/test/java/io/fd/honeycomb/test/tools/ContainerNodeDataProcessorTest.java @@ -0,0 +1,60 @@ +/* + * 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.honeycomb.test.tools; + + +import org.junit.Test; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; + +import static org.junit.Assert.*; + +public class ContainerNodeDataProcessorTest extends AbstractYangDataProcessorTest { + + private ContainerNodeDataProcessor processor; + + @Override + void setUp() { + processor = new ContainerNodeDataProcessor(moduleInfoBackedContext.getSchemaContext(), serializer); + } + + @Test + public void testGetNodeDataNestedContainer() { + final DataObject nodeData = processor.getNodeData(codec.deserialize(InjectionTestData.CONTAINER_UNDER_LIST_DATA_PATH), + InjectionTestData.CONTAINER_UNDER_LIST_RESOURCE); + assertNotNull(nodeData); + } + + @Test + public void testGetNodeDataRootContainer() { + final DataObject nodeData = processor.getNodeData(YangInstanceIdentifier.EMPTY, InjectionTestData.CONTAINER_IN_ROOT_RESOURCE); + assertNotNull(nodeData); + } + + + @Test + public void testCanProcessNegative() { + assertFalse(processor.canProcess(codec.deserialize(InjectionTestData.SIMPLE_LIST_DATA_PATH))); + assertFalse(processor.canProcess(codec.deserialize(InjectionTestData.NESTED_LIST_DATA_PATH))); + } + + @Test + public void testCanProcessPositive() { + assertTrue(processor.canProcess(YangInstanceIdentifier.EMPTY)); + assertTrue(processor.canProcess(codec.deserialize(InjectionTestData.CONTAINER_UNDER_LIST_DATA_PATH))); + } +} diff --git a/infra/test-utils/test-tools/src/test/java/io/fd/honeycomb/test/tools/HoneycombTestRunnerContainerTest.java b/infra/test-utils/test-tools/src/test/java/io/fd/honeycomb/test/tools/HoneycombTestRunnerContainerTest.java new file mode 100644 index 000000000..1461fa377 --- /dev/null +++ b/infra/test-utils/test-tools/src/test/java/io/fd/honeycomb/test/tools/HoneycombTestRunnerContainerTest.java @@ -0,0 +1,142 @@ +/* + * 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 io.fd.honeycomb.test.tools.annotations.InjectTestData; +import io.fd.honeycomb.test.tools.annotations.InjectablesProcessor; +import io.fd.honeycomb.test.tools.annotations.SchemaContextProvider; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.hc.data.rev150105.*; +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.SimpleList; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.hc.data.rev150105.simple.container.augmented.container.ListInAugment; +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.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.hc.data.rev150105.simple.container.simple.list.NestedList; +import org.opendaylight.yangtools.sal.binding.generator.impl.ModuleInfoBackedContext; + +import java.util.Collections; + +import static io.fd.honeycomb.test.tools.InjectionTestData.*; +import static org.junit.Assert.*; + +@RunWith(HoneycombTestRunner.class) +public class HoneycombTestRunnerContainerTest 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; + + @InjectTestData(resourcePath = AUGMENT_LIST_RESOURCE, id = AUGMENT_LIST_DATA_PATH) + private ListInAugment listInAugment; + + @InjectTestData(resourcePath = NESTED_LIST_RESOURCE, id = NESTED_LIST_DATA_PATH) + private NestedList nestedList; + + @InjectTestData(resourcePath = ROOT_LIST_RESOURCE, id = ROOT_LIST_DATA_PATH) + private RootList rootList; + + @InjectTestData(resourcePath = SIMPLES_LIST_RESOURCE, id = SIMPLE_LIST_DATA_PATH) + private SimpleList simpleList; + + + @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/java/io/fd/honeycomb/test/tools/HoneycombTestRunnerTest.java b/infra/test-utils/test-tools/src/test/java/io/fd/honeycomb/test/tools/HoneycombTestRunnerTest.java deleted file mode 100644 index 42de7ed4d..000000000 --- a/infra/test-utils/test-tools/src/test/java/io/fd/honeycomb/test/tools/HoneycombTestRunnerTest.java +++ /dev/null @@ -1,129 +0,0 @@ -/* - * 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/java/io/fd/honeycomb/test/tools/InjectionTestData.java b/infra/test-utils/test-tools/src/test/java/io/fd/honeycomb/test/tools/InjectionTestData.java new file mode 100644 index 000000000..4d4ab5420 --- /dev/null +++ b/infra/test-utils/test-tools/src/test/java/io/fd/honeycomb/test/tools/InjectionTestData.java @@ -0,0 +1,46 @@ +/* + * 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.honeycomb.test.tools; + +final class InjectionTestData { + + static final String CONTAINER_UNDER_LIST_DATA_PATH = "/hc-data:simple-container" + + "/hc-data:simple-list[hc-data:name='nameUnderSimpleList']" + + "/hc-data:cont-under-list"; + + static final String SIMPLE_LIST_DATA_PATH = "/hc-data:simple-container" + + "/hc-data:simple-list[hc-data:name='nameUnderSimpleList']"; + + static final String NESTED_LIST_DATA_PATH = "/hc-data:simple-container" + + "/hc-data:simple-list[hc-data:name='nameUnderSimpleList']" + + "/hc-data:nested-list[hc-data:nested-name='nameUnderNestedList']"; + + static final String ROOT_LIST_DATA_PATH = "/hc-data:root-list[hc-data:root-name='rootName']"; + static final String AUGMENT_LIST_DATA_PATH = "/hc-data:simple-container" + + "/hc-data:augmented-container" + + "/hc-data:list-in-augment[hc-data:key-in-augment='keyInAugment']"; + + static final String CONTAINER_IN_ROOT_RESOURCE = "/simpleContainerEmpty.json"; + static final String CONTAINER_UNDER_LIST_RESOURCE = "/containerInList.json"; + static final String SIMPLES_LIST_RESOURCE = "/simpleListEntry.json"; + static final String NESTED_LIST_RESOURCE = "/nestedListEntry.json"; + static final String ROOT_LIST_RESOURCE = "/rootListEntry.json"; + static final String AUGMENT_LIST_RESOURCE = "/augmentListEntry.json"; + + private InjectionTestData() { + } +} diff --git a/infra/test-utils/test-tools/src/test/java/io/fd/honeycomb/test/tools/ListNodeDataProcessorTest.java b/infra/test-utils/test-tools/src/test/java/io/fd/honeycomb/test/tools/ListNodeDataProcessorTest.java new file mode 100644 index 000000000..1118d3387 --- /dev/null +++ b/infra/test-utils/test-tools/src/test/java/io/fd/honeycomb/test/tools/ListNodeDataProcessorTest.java @@ -0,0 +1,79 @@ +/* + * 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.honeycomb.test.tools; + + +import org.junit.Test; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.hc.data.rev150105.RootList; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.hc.data.rev150105.simple.container.SimpleList; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.hc.data.rev150105.simple.container.augmented.container.ListInAugment; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.hc.data.rev150105.simple.container.simple.list.NestedList; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; + +import static io.fd.honeycomb.test.tools.InjectionTestData.*; +import static org.junit.Assert.*; + +public class ListNodeDataProcessorTest extends AbstractYangDataProcessorTest { + + private ListNodeDataProcessor processor; + + @Override + void setUp() { + processor = new ListNodeDataProcessor(moduleInfoBackedContext.getSchemaContext(), serializer); + } + + @Test + public void testCanProcessPositive() { + assertTrue(processor.canProcess(codec.deserialize(SIMPLE_LIST_DATA_PATH))); + assertTrue(processor.canProcess(codec.deserialize(NESTED_LIST_DATA_PATH))); + } + + @Test + public void testCanProcessNegative() { + assertFalse(processor.canProcess(codec.deserialize(CONTAINER_UNDER_LIST_DATA_PATH))); + assertFalse(processor.canProcess(YangInstanceIdentifier.EMPTY)); + } + + @Test + public void testGetNodeDataSimpleList() { + final DataObject nodeData = processor.getNodeData(codec.deserialize(SIMPLE_LIST_DATA_PATH), SIMPLES_LIST_RESOURCE); + assertNotNull(nodeData); + assertEquals("nameUnderSimpleList", ((SimpleList) nodeData).getName()); + } + + @Test + public void testGetNodeDataNestedList() { + final DataObject nodeData = processor.getNodeData(codec.deserialize(NESTED_LIST_DATA_PATH), NESTED_LIST_RESOURCE); + assertNotNull(nodeData); + assertEquals("nameUnderNestedList", ((NestedList) nodeData).getNestedName()); + } + + @Test + public void testGetNodeDataRootList() { + final DataObject nodeData = processor.getNodeData(codec.deserialize(ROOT_LIST_DATA_PATH), ROOT_LIST_RESOURCE); + assertNotNull(nodeData); + assertEquals("rootName", ((RootList) nodeData).getRootName()); + } + + @Test + public void testGetNodeDataAugmentList() { + final DataObject nodeData = processor.getNodeData(codec.deserialize(AUGMENT_LIST_DATA_PATH), AUGMENT_LIST_RESOURCE); + assertNotNull(nodeData); + assertEquals("keyInAugment", ((ListInAugment) nodeData).getKeyInAugment()); + } +} diff --git a/infra/test-utils/test-tools/src/test/resources/augmentListEntry.json b/infra/test-utils/test-tools/src/test/resources/augmentListEntry.json new file mode 100644 index 000000000..1bdc3e6e2 --- /dev/null +++ b/infra/test-utils/test-tools/src/test/resources/augmentListEntry.json @@ -0,0 +1,10 @@ +{ + "list-in-augment":[ + { + "key-in-augment":"keyInAugment" + }, + { + "key-in-augment":"otherKeyInAugment" + } + ] +} \ No newline at end of file diff --git a/infra/test-utils/test-tools/src/test/resources/nestedListEntry.json b/infra/test-utils/test-tools/src/test/resources/nestedListEntry.json new file mode 100644 index 000000000..c874f1c94 --- /dev/null +++ b/infra/test-utils/test-tools/src/test/resources/nestedListEntry.json @@ -0,0 +1,10 @@ +{ + "nested-list": [ + { + "nested-name": "nameUnderNestedList" + }, + { + "nested-name": "otherName" + } + ] +} diff --git a/infra/test-utils/test-tools/src/test/resources/rootListEntry.json b/infra/test-utils/test-tools/src/test/resources/rootListEntry.json new file mode 100644 index 000000000..cd09c685e --- /dev/null +++ b/infra/test-utils/test-tools/src/test/resources/rootListEntry.json @@ -0,0 +1,10 @@ +{ + "root-list":[ + { + "root-name":"rootName" + }, + { + "root-name":"otherRootName" + } + ] +} \ No newline at end of file diff --git a/infra/test-utils/test-tools/src/test/resources/simpleListEntry.json b/infra/test-utils/test-tools/src/test/resources/simpleListEntry.json new file mode 100644 index 000000000..64ad3e6bd --- /dev/null +++ b/infra/test-utils/test-tools/src/test/resources/simpleListEntry.json @@ -0,0 +1,10 @@ +{ + "simple-list": [ + { + "name": "nameUnderSimpleList" + }, + { + "name": "otherName" + } + ] +} -- cgit 1.2.3-korg