summaryrefslogtreecommitdiffstats
path: root/cps-service/src/test
diff options
context:
space:
mode:
authorrajesh.kumar <rk00747546@techmahindra.com>2022-12-14 14:27:29 +0000
committerLuke Gleeson <luke.gleeson@est.tech>2023-03-21 09:45:16 +0000
commita317890387fdbc689f8dcd8648b5bfe3b43abd1e (patch)
tree652b78e62895aa186eb26788eb475634ce2ddce9 /cps-service/src/test
parent0b00f81b98e5fa9632b1145e49f62d0b2712f4e4 (diff)
Query data nodes across all anchors under one dataspace
Issue-ID: CPS-1396 Change-ID: I73f97f986a817d423f93a8d922dcd9647b1412ab Signed-off-by: rajesh.kumar <rk00747546@techmahindra.com>
Diffstat (limited to 'cps-service/src/test')
-rw-r--r--cps-service/src/test/groovy/org/onap/cps/api/impl/CpsQueryServiceImplSpec.groovy14
-rw-r--r--cps-service/src/test/groovy/org/onap/cps/utils/DataMapUtilsSpec.groovy32
2 files changed, 46 insertions, 0 deletions
diff --git a/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsQueryServiceImplSpec.groovy b/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsQueryServiceImplSpec.groovy
index 56c43d163..553027a4b 100644
--- a/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsQueryServiceImplSpec.groovy
+++ b/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsQueryServiceImplSpec.groovy
@@ -48,4 +48,18 @@ class CpsQueryServiceImplSpec extends Specification {
FetchDescendantsOption.DIRECT_CHILDREN_ONLY, new FetchDescendantsOption(10)]
}
+ def 'Query data nodes across all anchors by cps path with #fetchDescendantsOption.'() {
+ given: 'a dataspace name, an anchor name and a cps path'
+ def dataspaceName = 'some-dataspace'
+ def cpsPath = '/cps-path'
+ when: 'queryDataNodes is invoked'
+ objectUnderTest.queryDataNodesAcrossAnchors(dataspaceName, cpsPath, fetchDescendantsOption)
+ then: 'the persistence service is called once with the correct parameters'
+ 1 * mockCpsDataPersistenceService.queryDataNodesAcrossAnchors(dataspaceName, cpsPath, fetchDescendantsOption)
+ and: 'the CpsValidator is called on the dataspaceName, schemaSetName and anchorName'
+ 1 * mockCpsValidator.validateNameCharacters(dataspaceName)
+ where: 'all fetch descendants options are supported'
+ fetchDescendantsOption << [FetchDescendantsOption.OMIT_DESCENDANTS, FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS]
+ }
+
}
diff --git a/cps-service/src/test/groovy/org/onap/cps/utils/DataMapUtilsSpec.groovy b/cps-service/src/test/groovy/org/onap/cps/utils/DataMapUtilsSpec.groovy
index 84dddeb60..e27b43763 100644
--- a/cps-service/src/test/groovy/org/onap/cps/utils/DataMapUtilsSpec.groovy
+++ b/cps-service/src/test/groovy/org/onap/cps/utils/DataMapUtilsSpec.groovy
@@ -3,6 +3,7 @@
* Copyright (C) 2021 Pantheon.tech
* Modifications Copyright (C) 2020-2022 Nordix Foundation
* Modifications Copyright (C) 2022 Bell Canada.
+ * Modifications Copyright (C) 2023 TechMahindra Ltd.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -37,10 +38,23 @@ class DataMapUtilsSpec extends Specification {
),
])
+ def dataNodeWithAnchor = buildDataNodeWithAnchor(
+ "/parent", 'anchor01',[parentLeaf:'parentLeafValue', parentLeafList:['parentLeafListEntry1','parentLeafListEntry2']],[
+ buildDataNode('/parent/child-list[@id=1/2]',[listElementLeaf:'listElement1leafValue'],noChildren),
+ buildDataNode('/parent/child-list[@id=2]',[listElementLeaf:'listElement2leafValue'],noChildren),
+ buildDataNode('/parent/child-object',[childLeaf:'childLeafValue'],
+ [buildDataNode('/parent/child-object/grand-child-object',[grandChildLeaf:'grandChildLeafValue'],noChildren)]
+ ),
+ ])
+
static def buildDataNode(xpath, leaves, children) {
return new DataNodeBuilder().withXpath(xpath).withLeaves(leaves).withChildDataNodes(children).build()
}
+ static def buildDataNodeWithAnchor(xpath, anchorName, leaves, children) {
+ return new DataNodeBuilder().withXpath(xpath).withAnchor(anchorName).withLeaves(leaves).withChildDataNodes(children).build()
+ }
+
def 'Data node structure conversion to map.'() {
when: 'data node structure is converted to a map'
def result = DataMapUtils.toDataMap(dataNode)
@@ -90,5 +104,23 @@ class DataMapUtilsSpec extends Specification {
'xpath contains list attributes with /' | '/bookstore/categories[@code=1/2]' | 'sampleModuleName:categories'
}
+
+ def 'Data node structure with anchor name conversion to map with root node identifier.'() {
+ when: 'data node structure is converted to a map with root node identifier'
+ def result = DataMapUtils.toDataMapWithIdentifierAndAnchor(dataNodeWithAnchor, dataNodeWithAnchor.moduleNamePrefix)
+ then: 'root node leaves are populated under its node identifier'
+ def parentNode = result.get("dataNode").parent
+ parentNode.parentLeaf == 'parentLeafValue'
+ parentNode.parentLeafList == ['parentLeafListEntry1','parentLeafListEntry2']
+
+ and: 'leaves for child element is populated under its node identifier'
+ assert parentNode.'child-object'.childLeaf == 'childLeafValue'
+
+ and: 'leaves for grandchild element is populated under its node identifier'
+ assert parentNode.'child-object'.'grand-child-object'.grandChildLeaf == 'grandChildLeafValue'
+
+ and: 'data node is associated with anchor name'
+ assert result.get('anchorName') == 'anchor01'
+ }
}