From e7f24d3f2f239e6bdc14a78eb01d07525650a960 Mon Sep 17 00:00:00 2001 From: Lena Peuker Date: Tue, 29 Nov 2022 15:38:00 +0100 Subject: Fix DataNodeBuilder for ChoiceNodes Fix implemented to handle YangChoiceNode in right format Issue-ID: CPS-1352 Signed-off-by: Lena Peuker Change-Id: I48d433bac96cfc647bc31c82817870995bace860 --- .../onap/cps/spi/model/DataNodeBuilderSpec.groovy | 19 +++++++++++++++ .../src/test/resources/data-with-choice-node.json | 8 +++++++ .../src/test/resources/yang-with-choice-node.yang | 27 ++++++++++++++++++++++ 3 files changed, 54 insertions(+) create mode 100644 cps-service/src/test/resources/data-with-choice-node.json create mode 100644 cps-service/src/test/resources/yang-with-choice-node.yang (limited to 'cps-service/src/test') diff --git a/cps-service/src/test/groovy/org/onap/cps/spi/model/DataNodeBuilderSpec.groovy b/cps-service/src/test/groovy/org/onap/cps/spi/model/DataNodeBuilderSpec.groovy index fcfb4826d..a58504ff4 100644 --- a/cps-service/src/test/groovy/org/onap/cps/spi/model/DataNodeBuilderSpec.groovy +++ b/cps-service/src/test/groovy/org/onap/cps/spi/model/DataNodeBuilderSpec.groovy @@ -140,6 +140,25 @@ class DataNodeBuilderSpec extends Specification { assert result.leaves['source-tp'] == '1-2-1' } + def 'Converting NormalizedNode (tree) to a DataNode (tree) -- with ChoiceNode.'() { + given: 'a schema context for expected model' + def yangResourceNameToContent = TestUtils.getYangResourcesAsMap('yang-with-choice-node.yang') + def schemaContext = YangTextSchemaSourceSetBuilder.of(yangResourceNameToContent) getSchemaContext() + and: 'the json data fragment parsed into normalized node object' + def jsonData = TestUtils.getResourceFileContent('data-with-choice-node.json') + def normalizedNode = YangUtils.parseJsonData(jsonData, schemaContext) + when: 'the normalized node is converted to a data node' + def result = new DataNodeBuilder().withNormalizedNodeTree(normalizedNode).build() + def mappedResult = TestUtils.getFlattenMapByXpath(result) + then: 'the resulting data node contains only one xpath with 3 leaves' + mappedResult.keySet().containsAll([ + "/container-with-choice-leaves" + ]) + assert result.leaves['leaf-1'] == "test" + assert result.leaves['choice-case1-leaf-a'] == "test" + assert result.leaves['choice-case1-leaf-b'] == "test" + } + def 'Converting NormalizedNode into DataNode collection: #scenario.'() { given: 'a schema context for expected model' def yangResourceNameToContent = TestUtils.getYangResourcesAsMap('test-tree.yang') diff --git a/cps-service/src/test/resources/data-with-choice-node.json b/cps-service/src/test/resources/data-with-choice-node.json new file mode 100644 index 000000000..5f81ed8ed --- /dev/null +++ b/cps-service/src/test/resources/data-with-choice-node.json @@ -0,0 +1,8 @@ +{ + "container-with-choice-leaves": { + "leaf-1": "test", + "choice-case1-leaf-a": "test", + "choice-case1-leaf-b": "test" + } +} + diff --git a/cps-service/src/test/resources/yang-with-choice-node.yang b/cps-service/src/test/resources/yang-with-choice-node.yang new file mode 100644 index 000000000..55c0bfbe6 --- /dev/null +++ b/cps-service/src/test/resources/yang-with-choice-node.yang @@ -0,0 +1,27 @@ +module yang-with-choice-node { + yang-version 1.1; + namespace "org:onap:cps:test:yang-with-choice-node"; + prefix "yang-with-choice-node"; + + container container-with-choice-leaves { + leaf leaf-1 { + type string; + } + + choice choicenode { + case case-1 { + leaf choice-case1-leaf-a { + type string; + } + leaf choice-case1-leaf-b { + type string; + } + } + case case-2 { + leaf choice-case2-leaf-a { + type string; + } + } + } + } +} -- cgit 1.2.3-korg