diff options
author | Ruslan Kashapov <ruslan.kashapov@pantheon.tech> | 2021-05-14 14:41:05 +0300 |
---|---|---|
committer | Rishi Chail <rishi.chail@est.tech> | 2021-05-25 09:21:08 +0000 |
commit | 576f48e8d3ef2ac7526b5684eba0a3e8259ce3cc (patch) | |
tree | 631e393e235987531da722f56622785265cc1fdb | |
parent | b0e78acb6aefdcb5866955802099e6091b2a6952 (diff) |
Replace list-node content (part 2): CPS REST layer
Issue-ID: CPS-362
Change-Id: I46dc9b48758fa10a47a648aa4e6a63775466234b
Signed-off-by: Ruslan Kashapov <ruslan.kashapov@pantheon.tech>
3 files changed, 50 insertions, 1 deletions
diff --git a/cps-rest/docs/api/swagger/cpsData.yml b/cps-rest/docs/api/swagger/cpsData.yml index c0cd85b28d..aa8a31dfcb 100755 --- a/cps-rest/docs/api/swagger/cpsData.yml +++ b/cps-rest/docs/api/swagger/cpsData.yml @@ -50,6 +50,32 @@ listNodeByDataspaceAndAnchor: '403': $ref: 'components.yml#/components/responses/Forbidden' + patch: + description: Replace list-node child elements under existing node for a given anchor and dataspace + tags: + - cps-data + summary: Replace list-node child element(s) under existing parent node + operationId: replaceListNodeElements + parameters: + - $ref: 'components.yml#/components/parameters/dataspaceNameInPath' + - $ref: 'components.yml#/components/parameters/anchorNameInPath' + - $ref: 'components.yml#/components/parameters/requiredXpathInQuery' + requestBody: + required: true + content: + application/json: + schema: + type: string + responses: + '200': + $ref: 'components.yml#/components/responses/Created' + '400': + $ref: 'components.yml#/components/responses/BadRequest' + '401': + $ref: 'components.yml#/components/responses/Unauthorized' + '403': + $ref: 'components.yml#/components/responses/Forbidden' + nodesByDataspaceAndAnchor: post: description: Create a node for a given anchor and dataspace diff --git a/cps-rest/src/main/java/org/onap/cps/rest/controller/DataRestController.java b/cps-rest/src/main/java/org/onap/cps/rest/controller/DataRestController.java index 3d16539b3e..0c70a6c2e9 100755 --- a/cps-rest/src/main/java/org/onap/cps/rest/controller/DataRestController.java +++ b/cps-rest/src/main/java/org/onap/cps/rest/controller/DataRestController.java @@ -87,6 +87,13 @@ public class DataRestController implements CpsDataApi { return new ResponseEntity<>(HttpStatus.OK); } + @Override + public ResponseEntity<String> replaceListNodeElements(final String jsonData, final String parentNodeXpath, + final String dataspaceName, final String anchorName) { + cpsDataService.replaceListNodeData(dataspaceName, anchorName, parentNodeXpath, jsonData); + return new ResponseEntity<>(HttpStatus.OK); + } + private static boolean isRootXpath(final String xpath) { return ROOT_XPATH.equals(xpath); } diff --git a/cps-rest/src/test/groovy/org/onap/cps/rest/controller/DataRestControllerSpec.groovy b/cps-rest/src/test/groovy/org/onap/cps/rest/controller/DataRestControllerSpec.groovy index 18d20a8e20..344e603727 100755 --- a/cps-rest/src/test/groovy/org/onap/cps/rest/controller/DataRestControllerSpec.groovy +++ b/cps-rest/src/test/groovy/org/onap/cps/rest/controller/DataRestControllerSpec.groovy @@ -142,7 +142,6 @@ class DataRestControllerSpec extends Specification { response.status == HttpStatus.CREATED.value() then: 'the java API was called with the correct parameters' 1 * mockCpsDataService.saveListNodeData(dataspaceName, anchorName, parentNodeXpath, jsonData) - } def 'Get data node with leaves'() { @@ -230,4 +229,21 @@ class DataRestControllerSpec extends Specification { 'root node by choice' | '/' || '/' 'some xpath by parent' | '/some/xpath' || '/some/xpath' } + + def 'Replace list node child elements.'() { + given: 'parent node xpath and json data inputs' + def parentNodeXpath = 'parent node xpath' + def jsonData = 'json data' + when: 'patch is invoked list-node endpoint' + def response = mvc.perform( + patch("$dataNodeBaseEndpoint/anchors/$anchorName/list-node") + .contentType(MediaType.APPLICATION_JSON) + .param('xpath', parentNodeXpath) + .content(jsonData) + ).andReturn().response + then: 'a success response is returned' + response.status == HttpStatus.OK.value() + then: 'the java API was called with the correct parameters' + 1 * mockCpsDataService.replaceListNodeData(dataspaceName, anchorName, parentNodeXpath, jsonData) + } } |