From 05701dda6edf6b8e7c06699a7b44247359c46cfb Mon Sep 17 00:00:00 2001 From: lukegleeson Date: Wed, 18 Aug 2021 09:49:32 +0100 Subject: [PATCH] Delete list-node p2 rest layer Issue-ID: CPS-361 Signed-off-by: lukegleeson Change-Id: I5fb8d202fc0a65679d10377cc2959a7f8f854ca7 --- .../onap/cps/rest/controller/DataRestController.java | 7 +++++++ cps-rest/src/main/resources/static/cpsData.yml | 20 ++++++++++++++++++++ .../rest/controller/DataRestControllerSpec.groovy | 15 +++++++++++++++ 3 files changed, 42 insertions(+) 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 bad66dd4e..5c79472a4 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 @@ -96,6 +96,13 @@ public class DataRestController implements CpsDataApi { return new ResponseEntity<>(HttpStatus.OK); } + @Override + public ResponseEntity deleteListNodeElements(final String dataspaceName, final String anchorName, + final String listNodeXpath) { + cpsDataService.deleteListNodeData(dataspaceName, anchorName, listNodeXpath); + return new ResponseEntity<>(HttpStatus.NO_CONTENT); + } + private static boolean isRootXpath(final String xpath) { return ROOT_XPATH.equals(xpath); } diff --git a/cps-rest/src/main/resources/static/cpsData.yml b/cps-rest/src/main/resources/static/cpsData.yml index 7e9f71d62..9c4f3334e 100644 --- a/cps-rest/src/main/resources/static/cpsData.yml +++ b/cps-rest/src/main/resources/static/cpsData.yml @@ -97,6 +97,26 @@ listNodeByDataspaceAndAnchor: '403': $ref: 'components.yml#/components/responses/Forbidden' + delete: + description: Delete list-node child elements under existing node for a given anchor and dataspace + tags: + - cps-data + summary: Delete list-node child element(s) under existing parent node + operationId: deleteListNodeElements + parameters: + - $ref: 'components.yml#/components/parameters/dataspaceNameInPath' + - $ref: 'components.yml#/components/parameters/anchorNameInPath' + - $ref: 'components.yml#/components/parameters/requiredXpathInQuery' + responses: + '204': + $ref: 'components.yml#/components/responses/NoContent' + '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/test/groovy/org/onap/cps/rest/controller/DataRestControllerSpec.groovy b/cps-rest/src/test/groovy/org/onap/cps/rest/controller/DataRestControllerSpec.groovy index 8675f42a5..d3d42e306 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 @@ -24,6 +24,7 @@ package org.onap.cps.rest.controller import static org.onap.cps.spi.FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS import static org.onap.cps.spi.FetchDescendantsOption.OMIT_DESCENDANTS +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.patch import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post @@ -235,4 +236,18 @@ class DataRestControllerSpec extends Specification { then: 'the java API was called with the correct parameters' 1 * mockCpsDataService.replaceListNodeData(dataspaceName, anchorName, parentNodeXpath, jsonData) } + + def 'Delete list node child elements.'() { + given: 'list node xpath' + def listNodeXpath = 'list node xpath' + when: 'delete is invoked list-node endpoint' + def response = mvc.perform( + delete("$dataNodeBaseEndpoint/anchors/$anchorName/list-node") + .param('xpath', listNodeXpath) + ).andReturn().response + then: 'a success response is returned' + response.status == HttpStatus.NO_CONTENT.value() + then: 'the java API was called with the correct parameters' + 1 * mockCpsDataService.deleteListNodeData(dataspaceName, anchorName, listNodeXpath) + } } -- 2.16.6