aboutsummaryrefslogtreecommitdiffstats
path: root/cps-service/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'cps-service/src/test')
-rw-r--r--cps-service/src/test/groovy/org/onap/cps/api/impl/CpsModuleServiceImplSpec.groovy22
-rw-r--r--cps-service/src/test/groovy/org/onap/cps/spi/model/DataNodeBuilderSpec.groovy19
-rw-r--r--cps-service/src/test/resources/data-with-choice-node.json8
-rw-r--r--cps-service/src/test/resources/yang-with-choice-node.yang27
4 files changed, 76 insertions, 0 deletions
diff --git a/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsModuleServiceImplSpec.groovy b/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsModuleServiceImplSpec.groovy
index 690578ea05..358a6fb3f3 100644
--- a/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsModuleServiceImplSpec.groovy
+++ b/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsModuleServiceImplSpec.groovy
@@ -3,6 +3,7 @@
* Copyright (C) 2020-2022 Nordix Foundation
* Modifications Copyright (C) 2020-2021 Pantheon.tech
* Modifications Copyright (C) 2020-2022 Bell Canada.
+ * Modifications Copyright (C) 2022 TechMahindra Ltd.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -30,6 +31,8 @@ import org.onap.cps.spi.exceptions.SchemaSetInUseException
import org.onap.cps.spi.utils.CpsValidator
import org.onap.cps.spi.model.Anchor
import org.onap.cps.spi.model.ModuleReference
+import org.onap.cps.spi.model.SchemaSet
+import org.onap.cps.yang.YangTextSchemaSourceSet
import org.onap.cps.yang.YangTextSchemaSourceSetBuilder
import spock.lang.Specification
import static org.onap.cps.spi.CascadeDeleteAllowed.CASCADE_DELETE_ALLOWED
@@ -91,6 +94,25 @@ class CpsModuleServiceImplSpec extends Specification {
1 * mockCpsValidator.validateNameCharacters('someDataspace', 'someSchemaSet')
}
+ def 'Get schema sets by dataspace name.'() {
+ given: 'two already present schema sets'
+ def moduleReference = new ModuleReference('sample1', '2022-12-07')
+ def sampleSchemaSet1 = new SchemaSet('testSchemaSet1', 'testDataspace', [moduleReference])
+ def sampleSchemaSet2 = new SchemaSet('testSchemaSet2', 'testDataspace', [moduleReference])
+ and: 'the persistence service returns the created schema sets'
+ mockCpsModulePersistenceService.getSchemaSetsByDataspaceName('testDataspace') >> [sampleSchemaSet1, sampleSchemaSet2]
+ and: 'yang resource cache always returns a schema source set'
+ def mockYangTextSchemaSourceSet = Mock(YangTextSchemaSourceSet)
+ mockYangTextSchemaSourceSetCache.get('testDataspace', _) >> mockYangTextSchemaSourceSet
+ when: 'get schema sets method is invoked'
+ def result = objectUnderTest.getSchemaSets('testDataspace')
+ then: 'the correct schema sets are returned'
+ assert result.size() == 2
+ assert result.containsAll(sampleSchemaSet1, sampleSchemaSet2)
+ and: 'the Cps Validator is called on the dataspaceName'
+ 1 * mockCpsValidator.validateNameCharacters('testDataspace')
+ }
+
def 'Delete schema-set when cascade is allowed.'() {
given: '#numberOfAnchors anchors are associated with schemaset'
def associatedAnchors = createAnchors(numberOfAnchors)
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 a775cbe43f..e46147c04d 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 0000000000..5f81ed8ed7
--- /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 0000000000..55c0bfbe62
--- /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;
+ }
+ }
+ }
+ }
+}