aboutsummaryrefslogtreecommitdiffstats
path: root/cps-rest/src/test
diff options
context:
space:
mode:
authorRudrangi Anupriya <ra00745022@techmahindra.com>2024-12-02 15:37:07 +0530
committerRudrangi Anupriya <ra00745022@techmahindra.com>2024-12-12 07:18:23 +0000
commit7bc7ca3004adc6a7c1bbcee62e32e1906f2976d1 (patch)
tree6621a8adc49182c5d04738104df201e85dd1d8f4 /cps-rest/src/test
parent29061930922eeb686da7f91ec7852b7ee875c739 (diff)
Implementation of Data validation feature in CPS APIs
Added support to validate JSON/XML data without the need of persisting it in the database. - added "dryRunInQuery" flag as a new query parameter in update/Replace/Add APIs - added new method as part of CpsDataService layer to perform data validation Issue-ID: CPS-2516 Change-Id: I87bb33dd6021567d0fac606d5c4b0168d107311c Signed-off-by: Rudrangi Anupriya <ra00745022@techmahindra.com>
Diffstat (limited to 'cps-rest/src/test')
-rwxr-xr-xcps-rest/src/test/groovy/org/onap/cps/rest/controller/DataRestControllerSpec.groovy95
1 files changed, 88 insertions, 7 deletions
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 915fbdecf5..ca89fafe83 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
@@ -168,16 +168,17 @@ class DataRestControllerSpec extends Specification {
given: 'an endpoint to create a node'
def endpoint = "$dataNodeBaseEndpointV1/anchors/$anchorName/nodes"
def parentNodeXpath = '/'
+ and: 'dryRunEnabled flag is set to true'
def dryRunEnabled = 'true'
when: 'post is invoked with json data and dry-run flag enabled'
def response =
- mvc.perform(
- post(endpoint)
- .contentType(MediaType.APPLICATION_JSON)
- .param('xpath', parentNodeXpath)
- .param('dry-run', dryRunEnabled)
- .content(requestBodyJson)
- ).andReturn().response
+ mvc.perform(
+ post(endpoint)
+ .contentType(MediaType.APPLICATION_JSON)
+ .param('xpath', parentNodeXpath)
+ .param('dry-run', dryRunEnabled)
+ .content(requestBodyJson)
+ ).andReturn().response
then: 'a 200 OK response is returned'
response.status == HttpStatus.OK.value()
then: 'the service was called with correct parameters'
@@ -263,6 +264,26 @@ class DataRestControllerSpec extends Specification {
'Content type XML with invalid observed-timestamp' | 'invalid' | MediaType.APPLICATION_XML | requestBodyXml || 0 | HttpStatus.BAD_REQUEST | expectedXmlData | ContentType.XML
}
+ def 'Validate data using Save list elements API'() {
+ given: 'endpoint to save list elements'
+ def endpoint = "$dataNodeBaseEndpointV1/anchors/$anchorName/list-nodes"
+ and: 'dryRunEnabled flag is set to true'
+ def dryRunEnabled = 'true'
+ when: 'post request is performed'
+ def response =
+ mvc.perform(
+ post(endpoint)
+ .contentType(MediaType.APPLICATION_JSON)
+ .param('xpath', '/')
+ .content(requestBodyJson)
+ .param('dry-run', dryRunEnabled)
+ ).andReturn().response
+ then: 'a 200 OK response is returned'
+ response.status == HttpStatus.OK.value()
+ then: 'the service was called with correct parameters'
+ 1 * mockCpsDataService.validateData(dataspaceName, anchorName, '/', requestBodyJson, ContentType.JSON)
+ }
+
def 'Get data node with leaves'() {
given: 'the service returns data node leaves'
def xpath = 'parent-1'
@@ -515,6 +536,26 @@ class DataRestControllerSpec extends Specification {
'with invalid observed-timestamp' | 'invalid' || 0 | HttpStatus.BAD_REQUEST
}
+ def 'Validate data using Update a node API'() {
+ given: 'endpoint to update a node leaves'
+ def endpoint = "$dataNodeBaseEndpointV1/anchors/$anchorName/nodes"
+ and: 'dryRunEnabled flag is set to true'
+ def dryRunEnabled = 'true'
+ when: 'patch request is performed'
+ def response =
+ mvc.perform(
+ patch(endpoint)
+ .contentType(MediaType.APPLICATION_JSON)
+ .content(requestBodyJson)
+ .param('xpath', '/')
+ .param('dry-run', dryRunEnabled)
+ ).andReturn().response
+ then: 'a 200 OK response is returned'
+ response.status == HttpStatus.OK.value()
+ then: 'the service was called with correct parameters'
+ 1 * mockCpsDataService.validateData(dataspaceName, anchorName, '/', requestBodyJson, ContentType.JSON)
+ }
+
def 'Replace data node tree: #scenario.'() {
given: 'endpoint to replace node'
def endpoint = "$dataNodeBaseEndpointV1/anchors/$anchorName/nodes"
@@ -540,6 +581,26 @@ class DataRestControllerSpec extends Specification {
'XML content: some xpath by parent' | '/some/xpath' | MediaType.APPLICATION_XML || '/some/xpath' | requestBodyXml | expectedXmlData | ContentType.XML
}
+ def 'Validate data using Replace data node API'() {
+ given: 'endpoint to replace node'
+ def endpoint = "$dataNodeBaseEndpointV1/anchors/$anchorName/nodes"
+ and: 'dryRunEnabled flag is set to true'
+ def dryRunEnabled = 'true'
+ when: 'put request is performed'
+ def response =
+ mvc.perform(
+ put(endpoint)
+ .contentType(MediaType.APPLICATION_JSON)
+ .content(requestBodyJson)
+ .param('xpath', '/')
+ .param('dry-run', dryRunEnabled)
+ ).andReturn().response
+ then: 'a 200 OK response is returned'
+ response.status == HttpStatus.OK.value()
+ then: 'the service was called with correct parameters'
+ 1 * mockCpsDataService.validateData(dataspaceName, anchorName, '/', requestBodyJson, ContentType.JSON)
+ }
+
def 'Update data node and descendants with observedTimestamp.'() {
given: 'endpoint to replace node'
def endpoint = "$dataNodeBaseEndpointV1/anchors/$anchorName/nodes"
@@ -605,6 +666,26 @@ class DataRestControllerSpec extends Specification {
'with invalid observed-timestamp' | 'invalid' || 0 | HttpStatus.BAD_REQUEST
}
+ def 'Validate data using Replace list content API'() {
+ given: 'endpoint to replace list-nodes'
+ def endpoint = "$dataNodeBaseEndpointV1/anchors/$anchorName/list-nodes"
+ and: 'dryRunEnabled flag is set to true'
+ def dryRunEnabled = 'true'
+ when: 'put request is performed'
+ def response =
+ mvc.perform(
+ put(endpoint)
+ .contentType(MediaType.APPLICATION_JSON)
+ .param('xpath', '/')
+ .content(requestBodyJson)
+ .param('dry-run', dryRunEnabled)
+ ).andReturn().response
+ then: 'a 200 OK response is returned'
+ response.status == HttpStatus.OK.value()
+ then: 'the service was called with correct parameters'
+ 1 * mockCpsDataService.validateData(dataspaceName, anchorName, '/', requestBodyJson, ContentType.JSON)
+ }
+
def 'Delete list element #scenario.'() {
when: 'list-nodes endpoint is invoked with delete operation'
def deleteRequestBuilder = delete("$dataNodeBaseEndpointV1/anchors/$anchorName/list-nodes")