From 24bf350947acb7fcb62878932d520387bc922a96 Mon Sep 17 00:00:00 2001 From: Ruslan Kashapov Date: Mon, 19 Apr 2021 12:40:01 +0300 Subject: Create child data node (part 1): CPS service + REST Issue-ID: CPS-337 Change-Id: I9c5c62d144b5301ac80e2b82a5cc66a980dad011 Signed-off-by: Ruslan Kashapov --- .../rest/controller/DataRestControllerSpec.groovy | 33 ++++++++++++++++++++-- 1 file changed, 30 insertions(+), 3 deletions(-) (limited to 'cps-rest/src/test') 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 ef43641ea..713dda140 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 -- cgit 1.2.3-korg