summaryrefslogtreecommitdiffstats
path: root/cps-rest
diff options
context:
space:
mode:
Diffstat (limited to 'cps-rest')
-rwxr-xr-xcps-rest/docs/api/swagger/cpsData.yml1
-rwxr-xr-xcps-rest/src/main/java/org/onap/cps/rest/controller/DataRestController.java20
-rwxr-xr-xcps-rest/src/test/groovy/org/onap/cps/rest/controller/DataRestControllerSpec.groovy33
3 files changed, 45 insertions, 9 deletions
diff --git a/cps-rest/docs/api/swagger/cpsData.yml b/cps-rest/docs/api/swagger/cpsData.yml
index 24644899a4..54c89661b9 100755
--- a/cps-rest/docs/api/swagger/cpsData.yml
+++ b/cps-rest/docs/api/swagger/cpsData.yml
@@ -33,6 +33,7 @@ nodesByDataspaceAndAnchor:
parameters:
- $ref: 'components.yml#/components/parameters/dataspaceNameInPath'
- $ref: 'components.yml#/components/parameters/anchorNameInPath'
+ - $ref: 'components.yml#/components/parameters/xpathInQuery'
requestBody:
required: true
content:
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 f466ebcef0..3385f35fe8 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
@@ -21,8 +21,6 @@
package org.onap.cps.rest.controller;
-import javax.validation.Valid;
-import javax.validation.constraints.NotNull;
import org.onap.cps.api.CpsDataService;
import org.onap.cps.rest.api.CpsDataApi;
import org.onap.cps.spi.FetchDescendantsOption;
@@ -38,13 +36,19 @@ import org.springframework.web.bind.annotation.RestController;
@RequestMapping("${rest.api.cps-base-path}")
public class DataRestController implements CpsDataApi {
+ private static final String ROOT_XPATH = "/";
+
@Autowired
private CpsDataService cpsDataService;
@Override
- public ResponseEntity<String> createNode(@Valid final String jsonData, @NotNull final String dataspaceName,
- @NotNull @Valid final String anchorName) {
- cpsDataService.saveData(dataspaceName, anchorName, jsonData);
+ public ResponseEntity<String> createNode(final String jsonData, final String dataspaceName, final String anchorName,
+ final String parentNodeXpath) {
+ if (isRootXpath(parentNodeXpath)) {
+ cpsDataService.saveData(dataspaceName, anchorName, jsonData);
+ } else {
+ cpsDataService.saveData(dataspaceName, anchorName, parentNodeXpath, jsonData);
+ }
return new ResponseEntity<>(HttpStatus.CREATED);
}
@@ -56,7 +60,7 @@ public class DataRestController implements CpsDataApi {
@Override
public ResponseEntity<Object> getNodeByDataspaceAndAnchor(final String dataspaceName, final String anchorName,
final String xpath, final Boolean includeDescendants) {
- if ("/".equals(xpath)) {
+ if (isRootXpath(xpath)) {
return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
}
final FetchDescendantsOption fetchDescendantsOption = Boolean.TRUE.equals(includeDescendants)
@@ -79,4 +83,8 @@ public class DataRestController implements CpsDataApi {
cpsDataService.replaceNodeTree(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 ef43641ea8..713dda1403 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
@@ -90,7 +90,8 @@ class DataRestControllerSpec extends Specification {
dataNodeBaseEndpoint = "$basePath/v1/dataspaces/$dataspaceName"
}
- def 'Create a node.'() {
+ @Unroll
+ def 'Create a node: #scenario.'() {
given: 'some json to create a data node'
def endpoint = "$dataNodeBaseEndpoint/anchors/$anchorName/nodes"
def json = 'some json (this is not validated)'
@@ -98,12 +99,38 @@ class DataRestControllerSpec extends Specification {
def response =
mvc.perform(
post(endpoint)
- .contentType(MediaType.APPLICATION_JSON).content(json))
- .andReturn().response
+ .contentType(MediaType.APPLICATION_JSON)
+ .param('xpath', parentNodeXpath)
+ .content(json)
+ ).andReturn().response
then: 'a created response is returned'
response.status == HttpStatus.CREATED.value()
then: 'the java API was called with the correct parameters'
1 * mockCpsDataService.saveData(dataspaceName, anchorName, json)
+ where: 'following xpath parameters are are used'
+ scenario | parentNodeXpath
+ 'no xpath parameter' | ''
+ 'xpath parameter point root' | '/'
+ }
+
+ def 'Create a child node'() {
+ given: 'some json to create a data node'
+ def endpoint = "$dataNodeBaseEndpoint/anchors/$anchorName/nodes"
+ def json = 'some json (this is not validated)'
+ and: 'parent node xpath'
+ def parentNodeXpath = 'some xpath'
+ when: 'post is invoked with datanode endpoint and json'
+ def response =
+ mvc.perform(
+ post(endpoint)
+ .contentType(MediaType.APPLICATION_JSON)
+ .param('xpath', parentNodeXpath)
+ .content(json)
+ ).andReturn().response
+ then: 'a created response is returned'
+ response.status == HttpStatus.CREATED.value()
+ then: 'the java API was called with the correct parameters'
+ 1 * mockCpsDataService.saveData(dataspaceName, anchorName, parentNodeXpath, json)
}
@Unroll