diff options
author | danielhanrahan <daniel.hanrahan@est.tech> | 2023-09-28 11:13:36 +0100 |
---|---|---|
committer | danielhanrahan <daniel.hanrahan@est.tech> | 2023-09-28 11:13:36 +0100 |
commit | d8620d2bceab3001543d795b3d44925377d00cf1 (patch) | |
tree | ebfa0b1cb14a365488098fd96bb0ba1674b99f97 /cps-service/src/test | |
parent | b4939f3dc286b23edd6f7950e74952208f983eb4 (diff) |
JSON list support when updating multiple datanodes
updateDataNodesAndDescendants if supplied with a JSON list such as
{"branch": [{"name":"Name1"}, {"name":"Name2"}]}
would only replace the first node /test-tree/branch[@name='Name1'],
and ignore any remaining list items. This is caused by the use of a
legacy buildDataNode, which returns only a single DataNode from JSON,
even if the JSON contained a list.
Issue-ID: CPS-1889
Signed-off-by: danielhanrahan <daniel.hanrahan@est.tech>
Change-Id: I257491b6bc3f047a64eb241eaac70fd457b24347
Diffstat (limited to 'cps-service/src/test')
-rw-r--r-- | cps-service/src/test/groovy/org/onap/cps/api/impl/CpsDataServiceImplSpec.groovy | 15 |
1 files changed, 9 insertions, 6 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 b4ac7a68f3..e1d15d68ab 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 @@ -307,15 +307,16 @@ class CpsDataServiceImplSpec extends Specification { objectUnderTest.updateDataNodeAndDescendants(dataspaceName, anchorName, parentNodeXpath, jsonData, observedTimestamp) then: 'the persistence service method is invoked with correct parameters' 1 * mockCpsDataPersistenceService.updateDataNodesAndDescendants(dataspaceName, anchorName, - { dataNode -> dataNode.xpath[0] == expectedNodeXpath }) + { dataNode -> dataNode.xpath == expectedNodeXpath}) and: 'data updated event is sent to notification service' 1 * mockNotificationService.processDataUpdatedEvent(anchor, parentNodeXpath, Operation.UPDATE, observedTimestamp) and: 'the CpsValidator is called on the dataspaceName and AnchorName' 1 * mockCpsValidator.validateNameCharacters(dataspaceName, anchorName) where: 'following parameters were used' - scenario | parentNodeXpath | jsonData || expectedNodeXpath - 'top level node' | '/' | '{"test-tree": {"branch": []}}' || '/test-tree' - 'level 2 node' | '/test-tree' | '{"branch": [{"name":"Name"}]}' || '/test-tree/branch[@name=\'Name\']' + scenario | parentNodeXpath | jsonData || expectedNodeXpath + 'top level node' | '/' | '{"test-tree": {"branch": []}}' || ['/test-tree'] + 'level 2 node' | '/test-tree' | '{"branch": [{"name":"Name"}]}' || ['/test-tree/branch[@name=\'Name\']'] + 'json list' | '/test-tree' | '{"branch": [{"name":"Name1"}, {"name":"Name2"}]}' || ["/test-tree/branch[@name='Name1']", "/test-tree/branch[@name='Name2']"] } def 'Replace data node using multiple data nodes: #scenario.'() { @@ -327,14 +328,16 @@ class CpsDataServiceImplSpec extends Specification { 1 * mockCpsDataPersistenceService.updateDataNodesAndDescendants(dataspaceName, anchorName, { dataNode -> dataNode.xpath == expectedNodeXpath}) and: 'data updated event is sent to notification service' - 1 * mockNotificationService.processDataUpdatedEvent(anchor, nodesJsonData.keySet()[0], Operation.UPDATE, observedTimestamp) - 1 * mockNotificationService.processDataUpdatedEvent(anchor, nodesJsonData.keySet()[1], Operation.UPDATE, observedTimestamp) + nodesJsonData.keySet().each { + 1 * mockNotificationService.processDataUpdatedEvent(anchor, it, Operation.UPDATE, observedTimestamp) + } and: 'the CpsValidator is called on the dataspaceName and AnchorName' 1 * mockCpsValidator.validateNameCharacters(dataspaceName, anchorName) where: 'following parameters were used' scenario | nodesJsonData || expectedNodeXpath 'top level node' | ['/' : '{"test-tree": {"branch": []}}', '/test-tree' : '{"branch": [{"name":"Name"}]}'] || ["/test-tree", "/test-tree/branch[@name='Name']"] 'level 2 node' | ['/test-tree' : '{"branch": [{"name":"Name"}]}', '/test-tree/branch[@name=\'Name\']':'{"nest":{"name":"nestName"}}'] || ["/test-tree/branch[@name='Name']", "/test-tree/branch[@name='Name']/nest"] + 'json list' | ['/test-tree' : '{"branch": [{"name":"Name1"}, {"name":"Name2"}]}'] || ["/test-tree/branch[@name='Name1']", "/test-tree/branch[@name='Name2']"] } def 'Replace data node with concurrency exception in persistence layer.'() { |