aboutsummaryrefslogtreecommitdiffstats
path: root/cps-rest
diff options
context:
space:
mode:
Diffstat (limited to 'cps-rest')
-rw-r--r--cps-rest/docs/openapi/cpsData.yml22
-rw-r--r--cps-rest/docs/openapi/openapi.yml2
-rwxr-xr-xcps-rest/src/main/java/org/onap/cps/rest/controller/DataRestController.java16
-rwxr-xr-xcps-rest/src/test/groovy/org/onap/cps/rest/controller/DataRestControllerSpec.groovy45
4 files changed, 40 insertions, 45 deletions
diff --git a/cps-rest/docs/openapi/cpsData.yml b/cps-rest/docs/openapi/cpsData.yml
index d456f44e6c..ca21df53db 100644
--- a/cps-rest/docs/openapi/cpsData.yml
+++ b/cps-rest/docs/openapi/cpsData.yml
@@ -46,13 +46,13 @@ nodeByDataspaceAndAnchor:
$ref: 'components.yml#/components/responses/NotFound'
x-codegen-request-body-name: xpath
-listNodeByDataspaceAndAnchor:
+listElementByDataspaceAndAnchor:
post:
- description: Add list-node child elements to existing node for a given anchor and dataspace
+ description: Add list element(s) to a list for a given anchor and dataspace
tags:
- cps-data
- summary: Add list-node child element(s) under existing parent node
- operationId: addListNodeElements
+ summary: Add list element(s)
+ operationId: addListElements
parameters:
- $ref: 'components.yml#/components/parameters/dataspaceNameInPath'
- $ref: 'components.yml#/components/parameters/anchorNameInPath'
@@ -75,11 +75,11 @@ listNodeByDataspaceAndAnchor:
$ref: 'components.yml#/components/responses/Forbidden'
put:
- description: Replace list-node child elements under existing node for a given anchor and dataspace
+ description: Replace list content under a given parent, anchor and dataspace
tags:
- cps-data
- summary: Replace list-node child element(s) under existing parent node
- operationId: replaceListNodeElements
+ summary: Replace list content
+ operationId: replaceListContent
parameters:
- $ref: 'components.yml#/components/parameters/dataspaceNameInPath'
- $ref: 'components.yml#/components/parameters/anchorNameInPath'
@@ -102,11 +102,11 @@ listNodeByDataspaceAndAnchor:
$ref: 'components.yml#/components/responses/Forbidden'
delete:
- description: Delete list-node child elements under existing node for a given anchor and dataspace
+ description: Delete one or all list element(s) for a given anchor and dataspace
tags:
- cps-data
- summary: Delete list-node child element(s) under existing parent node
- operationId: deleteListNodeElements
+ summary: Delete one or all list element(s)
+ operationId: deleteListOrListElement
parameters:
- $ref: 'components.yml#/components/parameters/dataspaceNameInPath'
- $ref: 'components.yml#/components/parameters/anchorNameInPath'
@@ -202,4 +202,4 @@ nodesByDataspaceAndAnchor:
'401':
$ref: 'components.yml#/components/responses/Unauthorized'
'403':
- $ref: 'components.yml#/components/responses/Forbidden' \ No newline at end of file
+ $ref: 'components.yml#/components/responses/Forbidden'
diff --git a/cps-rest/docs/openapi/openapi.yml b/cps-rest/docs/openapi/openapi.yml
index f9881fb151..76bdb80c23 100644
--- a/cps-rest/docs/openapi/openapi.yml
+++ b/cps-rest/docs/openapi/openapi.yml
@@ -66,7 +66,7 @@ paths:
$ref: 'cpsData.yml#/nodesByDataspaceAndAnchor'
/v1/dataspaces/{dataspace-name}/anchors/{anchor-name}/list-nodes:
- $ref: 'cpsData.yml#/listNodeByDataspaceAndAnchor'
+ $ref: 'cpsData.yml#/listElementByDataspaceAndAnchor'
/v1/dataspaces/{dataspace-name}/anchors/{anchor-name}/nodes/query:
$ref: 'cpsQuery.yml#/nodesByDataspaceAndAnchorAndCpsPath'
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 7db4e5a1b6..f29ead9e9f 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
@@ -60,9 +60,9 @@ public class DataRestController implements CpsDataApi {
}
@Override
- public ResponseEntity<String> addListNodeElements(final String parentNodeXpath,
+ public ResponseEntity<String> addListElements(final String parentNodeXpath,
final String dataspaceName, final String anchorName, final String jsonData, final String observedTimestamp) {
- cpsDataService.saveListNodeData(dataspaceName, anchorName, parentNodeXpath, jsonData,
+ cpsDataService.saveListElements(dataspaceName, anchorName, parentNodeXpath, jsonData,
toOffsetDateTime(observedTimestamp));
return new ResponseEntity<>(HttpStatus.CREATED);
}
@@ -94,19 +94,19 @@ public class DataRestController implements CpsDataApi {
}
@Override
- public ResponseEntity<String> replaceListNodeElements(final String parentNodeXpath,
+ public ResponseEntity<String> replaceListContent(final String parentNodeXpath,
final String dataspaceName, final String anchorName, final String jsonData,
final String observedTimestamp) {
- cpsDataService.replaceListNodeData(dataspaceName, anchorName, parentNodeXpath, jsonData,
+ cpsDataService.replaceListContent(dataspaceName, anchorName, parentNodeXpath, jsonData,
toOffsetDateTime(observedTimestamp));
return new ResponseEntity<>(HttpStatus.OK);
}
@Override
- public ResponseEntity<Void> deleteListNodeElements(final String dataspaceName, final String anchorName,
- final String listNodeXpath, final String observedTimestamp) {
+ public ResponseEntity<Void> deleteListOrListElement(final String dataspaceName, final String anchorName,
+ final String listElementXpath, final String observedTimestamp) {
cpsDataService
- .deleteListNodeData(dataspaceName, anchorName, listNodeXpath, toOffsetDateTime(observedTimestamp));
+ .deleteListOrListElement(dataspaceName, anchorName, listElementXpath, toOffsetDateTime(observedTimestamp));
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
@@ -114,7 +114,7 @@ public class DataRestController implements CpsDataApi {
return ROOT_XPATH.equals(xpath);
}
- private OffsetDateTime toOffsetDateTime(final String datetTimestamp) {
+ private static OffsetDateTime toOffsetDateTime(final String datetTimestamp) {
try {
return StringUtils.isEmpty(datetTimestamp)
? null : OffsetDateTime.parse(datetTimestamp, ISO_TIMESTAMP_FORMATTER);
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 a54f3bc95d..06f2f5795f 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
@@ -22,14 +22,6 @@
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
-import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put
-
import org.onap.cps.api.CpsDataService
import org.onap.cps.spi.model.DataNode
import org.onap.cps.spi.model.DataNodeBuilder
@@ -44,6 +36,14 @@ import org.springframework.test.web.servlet.MockMvc
import spock.lang.Shared
import spock.lang.Specification
+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
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put
+
@WebMvcTest(DataRestController)
class DataRestControllerSpec extends Specification {
@@ -145,11 +145,11 @@ class DataRestControllerSpec extends Specification {
'without observed-timestamp' | null
}
- def 'Create list node child elements #scenario.'() {
+ def 'Save list elements #scenario.'() {
given: 'parent node xpath and json data inputs'
def parentNodeXpath = 'parent node xpath'
def jsonData = 'json data'
- when: 'post is invoked list-node endpoint'
+ when: 'list-node endpoint is invoked with post (create) operation'
def postRequestBuilder = post("$dataNodeBaseEndpoint/anchors/$anchorName/list-nodes")
.contentType(MediaType.APPLICATION_JSON)
.param('xpath', parentNodeXpath)
@@ -160,7 +160,7 @@ class DataRestControllerSpec extends Specification {
then: 'a created response is returned'
response.status == expectedHttpStatus.value()
then: 'the java API was called with the correct parameters'
- expectedApiCount * mockCpsDataService.saveListNodeData(dataspaceName, anchorName, parentNodeXpath, jsonData,
+ expectedApiCount * mockCpsDataService.saveListElements(dataspaceName, anchorName, parentNodeXpath, jsonData,
{ it == DateTimeUtility.toOffsetDateTime(observedTimestamp) })
where:
scenario | observedTimestamp || expectedApiCount | expectedHttpStatus
@@ -303,22 +303,19 @@ class DataRestControllerSpec extends Specification {
'with invalid observed-timestamp' | 'invalid' || 0 | HttpStatus.BAD_REQUEST
}
- def 'Replace list node child elements.'() {
- given: 'parent node xpath and json data inputs'
- def parentNodeXpath = 'parent node xpath'
- def jsonData = 'json data'
- when: 'put is invoked list-node endpoint'
+ def 'Replace list content #scenario.'() {
+ when: 'list-nodes endpoint is invoked with put (update) operation'
def putRequestBuilder = put("$dataNodeBaseEndpoint/anchors/$anchorName/list-nodes")
.contentType(MediaType.APPLICATION_JSON)
- .param('xpath', parentNodeXpath)
- .content(jsonData)
+ .param('xpath', 'parent xpath')
+ .content('json data')
if (observedTimestamp != null)
putRequestBuilder.param('observed-timestamp', observedTimestamp)
def response = mvc.perform(putRequestBuilder).andReturn().response
then: 'a success response is returned'
response.status == expectedHttpStatus.value()
and: 'the java API was called with the correct parameters'
- expectedApiCount * mockCpsDataService.replaceListNodeData(dataspaceName, anchorName, parentNodeXpath, jsonData,
+ expectedApiCount * mockCpsDataService.replaceListContent(dataspaceName, anchorName, 'parent xpath', 'json data',
{ it == DateTimeUtility.toOffsetDateTime(observedTimestamp) })
where:
scenario | observedTimestamp || expectedApiCount | expectedHttpStatus
@@ -327,19 +324,17 @@ class DataRestControllerSpec extends Specification {
'with invalid observed-timestamp' | 'invalid' || 0 | HttpStatus.BAD_REQUEST
}
- def 'Delete list node child elements. #scenario'() {
- given: 'list node xpath'
- def listNodeXpath = 'list node xpath'
- when: 'delete is invoked list-node endpoint'
+ def 'Delete list element #scenario.'() {
+ when: 'list-nodes endpoint is invoked with delete operation'
def deleteRequestBuilder = delete("$dataNodeBaseEndpoint/anchors/$anchorName/list-nodes")
- .param('xpath', listNodeXpath)
+ .param('xpath', 'list element xpath')
if (observedTimestamp != null)
deleteRequestBuilder.param('observed-timestamp', observedTimestamp)
def response = mvc.perform(deleteRequestBuilder).andReturn().response
then: 'a success response is returned'
response.status == expectedHttpStatus.value()
and: 'the java API was called with the correct parameters'
- expectedApiCount * mockCpsDataService.deleteListNodeData(dataspaceName, anchorName, listNodeXpath,
+ expectedApiCount * mockCpsDataService.deleteListOrListElement(dataspaceName, anchorName, 'list element xpath',
{ it == DateTimeUtility.toOffsetDateTime(observedTimestamp) })
where:
scenario | observedTimestamp || expectedApiCount | expectedHttpStatus