summaryrefslogtreecommitdiffstats
path: root/cps-service/src/test/groovy
diff options
context:
space:
mode:
authorRuslan Kashapov <ruslan.kashapov@pantheon.tech>2021-02-09 17:25:18 +0200
committerRuslan Kashapov <ruslan.kashapov@pantheon.tech>2021-02-18 11:54:36 +0200
commit24c72db6b3674bde16eb5a7313d71f507a880de9 (patch)
treec6eb5a55e544954782cc0fdab820c26ed81ed8d2 /cps-service/src/test/groovy
parent6d13f166f2e3d1c357677ad6f37f6e35238aeac6 (diff)
Data fragment update by xpath #3 - rest and service layers
Issue-ID: CPS-58 Change-Id: Ie224da95b07748b63648226df6484cebae91cdec Signed-off-by: Ruslan Kashapov <ruslan.kashapov@pantheon.tech>
Diffstat (limited to 'cps-service/src/test/groovy')
-rw-r--r--cps-service/src/test/groovy/org/onap/cps/api/impl/CpsDataServiceImplSpec.groovy51
1 files changed, 47 insertions, 4 deletions
diff --git a/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsDataServiceImplSpec.groovy b/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsDataServiceImplSpec.groovy
index 65a0d54f40..d561475273 100644
--- a/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsDataServiceImplSpec.groovy
+++ b/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsDataServiceImplSpec.groovy
@@ -52,9 +52,7 @@ class CpsDataServiceImplSpec extends Specification {
def 'Saving json data.'() {
given: 'that the admin service will return an anchor'
- def anchor = new Anchor()
- anchor.name = anchorName
- anchor.schemaSetName = schemaSetName
+ def anchor = Anchor.builder().name(anchorName).schemaSetName(schemaSetName).build()
mockCpsAdminService.getAnchor(dataspaceName, anchorName) >> anchor
and: 'the schema source set cache returns a schema source set'
def mockYangTextSchemaSourceSet = Mock(YangTextSchemaSourceSet)
@@ -72,7 +70,7 @@ class CpsDataServiceImplSpec extends Specification {
}
@Unroll
- def 'Get data node with option #fetchChildrenOption'() {
+ def 'Get data node with option #fetchDescendantsOption.'() {
def xpath = '/xpath'
def dataNode = new DataNodeBuilder().withXpath(xpath).build()
given: 'persistence service returns data for get data request'
@@ -82,4 +80,49 @@ class CpsDataServiceImplSpec extends Specification {
where: 'all fetch options are supported'
fetchDescendantsOption << FetchDescendantsOption.values()
}
+
+ @Unroll
+ def 'Update data node leaves: #scenario.'() {
+ given: 'that the admin service will return an anchor'
+ def anchor = Anchor.builder().name(anchorName).schemaSetName(schemaSetName).build()
+ mockCpsAdminService.getAnchor(dataspaceName, anchorName) >> anchor
+ and: 'the schema source set cache returns a schema source set'
+ def mockYangTextSchemaSourceSet = Mock(YangTextSchemaSourceSet)
+ mockYangTextSchemaSourceSetCache.get(dataspaceName, schemaSetName) >> mockYangTextSchemaSourceSet
+ and: 'the schema source sets returns the test-tree schema context'
+ def yangResourceNameToContent = TestUtils.getYangResourcesAsMap('test-tree.yang')
+ def schemaContext = YangTextSchemaSourceSetBuilder.of(yangResourceNameToContent).getSchemaContext()
+ mockYangTextSchemaSourceSet.getSchemaContext() >> schemaContext
+ when: 'update data method is invoked with json data #jsonData and parent node xpath #parentNodeXpath'
+ objectUnderTest.updateNodeLeaves(dataspaceName, anchorName, parentNodeXpath, jsonData)
+ then: 'the persistence service method is invoked with correct parameters'
+ 1 * mockCpsDataPersistenceService.updateDataLeaves(dataspaceName, anchorName, nodeXpath, leaves)
+ where: 'following parameters were used'
+ scenario | parentNodeXpath | jsonData | nodeXpath | leaves
+ 'top level node' | '/' | '{ "test-tree": {"branch": []}}' | '/test-tree' | Collections.emptyMap()
+ 'level 2 node' | '/test-tree' | '{"branch": [{"name":"Name"}]}' | '/test-tree/branch[@name=\'Name\']' | ['name': 'Name']
+ }
+
+ @Unroll
+ def 'Replace data node: #scenario.'() {
+ given: 'that the admin service will return an anchor'
+ def anchor = Anchor.builder().name(anchorName).schemaSetName(schemaSetName).build()
+ mockCpsAdminService.getAnchor(dataspaceName, anchorName) >> anchor
+ and: 'the schema source set cache returns a schema source set'
+ def mockYangTextSchemaSourceSet = Mock(YangTextSchemaSourceSet)
+ mockYangTextSchemaSourceSetCache.get(dataspaceName, schemaSetName) >> mockYangTextSchemaSourceSet
+ and: 'the schema source sets returns the test-tree schema context'
+ def yangResourceNameToContent = TestUtils.getYangResourcesAsMap('test-tree.yang')
+ def schemaContext = YangTextSchemaSourceSetBuilder.of(yangResourceNameToContent).getSchemaContext()
+ mockYangTextSchemaSourceSet.getSchemaContext() >> schemaContext
+ when: 'replace data method is invoked with json data #jsonData and parent node xpath #parentNodeXpath'
+ objectUnderTest.replaceNodeTree(dataspaceName, anchorName, parentNodeXpath, jsonData)
+ then: 'the persistence service method is invoked with correct parameters'
+ 1 * mockCpsDataPersistenceService.replaceDataNodeTree(dataspaceName, anchorName,
+ { dataNode -> dataNode.xpath == nodeXpath })
+ where: 'following parameters were used'
+ scenario | parentNodeXpath | jsonData | nodeXpath
+ 'top level node' | '/' | '{ "test-tree": {"branch": []}}' | '/test-tree'
+ 'level 2 node' | '/test-tree' | '{"branch": [{"name":"Name"}]}' | '/test-tree/branch[@name=\'Name\']'
+ }
} \ No newline at end of file