summaryrefslogtreecommitdiffstats
path: root/cps-rest/src
diff options
context:
space:
mode:
authorPriyank Maheshwari <priyank.maheshwari@est.tech>2024-11-29 10:28:06 +0000
committerGerrit Code Review <gerrit@onap.org>2024-11-29 10:28:06 +0000
commita27a62c1ca4f87d126cb5e40cc797aed9aa590db (patch)
tree3fdcba0ecc089065040ed54db84d12b9586dcfef /cps-rest/src
parentb97d522cb3d08b596241aea88aafe3bd08b4ef77 (diff)
parentdfcc95236daf7d45687fa42446a7d236ac12637e (diff)
Merge "XML content support on Replace list content"
Diffstat (limited to 'cps-rest/src')
-rwxr-xr-xcps-rest/src/main/java/org/onap/cps/rest/controller/DataRestController.java10
-rw-r--r--cps-rest/src/main/java/org/onap/cps/rest/controller/QueryRestController.java2
-rwxr-xr-xcps-rest/src/test/groovy/org/onap/cps/rest/controller/DataRestControllerSpec.groovy23
3 files changed, 29 insertions, 6 deletions
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 dda88e019c..3efb6b421c 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
@@ -173,9 +173,11 @@ public class DataRestController implements CpsDataApi {
@Override
public ResponseEntity<Object> replaceListContent(final String apiVersion, final String dataspaceName,
final String anchorName, final String parentNodeXpath,
- final Object jsonData, final String observedTimestamp) {
+ final String nodeData, final String observedTimestamp,
+ final String contentTypeInHeader) {
+ final ContentType contentType = ContentType.fromString(contentTypeInHeader);
cpsDataService.replaceListContent(dataspaceName, anchorName, parentNodeXpath,
- jsonObjectMapper.asJsonString(jsonData), toOffsetDateTime(observedTimestamp));
+ nodeData, toOffsetDateTime(observedTimestamp), contentType);
return new ResponseEntity<>(HttpStatus.OK);
}
@@ -225,10 +227,10 @@ public class DataRestController implements CpsDataApi {
return new ResponseEntity<>(jsonObjectMapper.asJsonString(deltaBetweenAnchors), HttpStatus.OK);
}
- ResponseEntity<Object> buildResponseEntity(final List<Map<String, Object>> dataMaps,
+ private ResponseEntity<Object> buildResponseEntity(final List<Map<String, Object>> dataMaps,
final ContentType contentType) {
final String responseData;
- if (contentType == ContentType.XML) {
+ if (ContentType.XML.equals(contentType)) {
responseData = XmlFileUtils.convertDataMapsToXml(dataMaps);
} else {
responseData = jsonObjectMapper.asJsonString(dataMaps);
diff --git a/cps-rest/src/main/java/org/onap/cps/rest/controller/QueryRestController.java b/cps-rest/src/main/java/org/onap/cps/rest/controller/QueryRestController.java
index 55a1886ce7..ec71c30a75 100644
--- a/cps-rest/src/main/java/org/onap/cps/rest/controller/QueryRestController.java
+++ b/cps-rest/src/main/java/org/onap/cps/rest/controller/QueryRestController.java
@@ -151,7 +151,7 @@ public class QueryRestController implements CpsQueryApi {
private ResponseEntity<Object> buildResponseEntity(final List<Map<String, Object>> dataNodesAsListOfMaps,
final ContentType contentType) {
final String responseData;
- if (contentType == ContentType.XML) {
+ if (ContentType.XML.equals(contentType)) {
responseData = XmlFileUtils.convertDataMapsToXml(dataNodesAsListOfMaps);
} else {
responseData = jsonObjectMapper.asJsonString(dataNodesAsListOfMaps);
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 72ae4c7f91..892963c827 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
@@ -576,7 +576,28 @@ class DataRestControllerSpec extends Specification {
response.status == expectedHttpStatus.value()
and: 'the java API was called with the correct parameters'
expectedApiCount * mockCpsDataService.replaceListContent(dataspaceName, anchorName, 'parent xpath', expectedJsonData,
- { it == DateTimeUtility.toOffsetDateTime(observedTimestamp) })
+ { it == DateTimeUtility.toOffsetDateTime(observedTimestamp) }, ContentType.JSON)
+ where:
+ scenario | observedTimestamp || expectedApiCount | expectedHttpStatus
+ 'with observed-timestamp' | '2021-03-03T23:59:59.999-0400' || 1 | HttpStatus.OK
+ 'without observed-timestamp' | null || 1 | HttpStatus.OK
+ 'with invalid observed-timestamp' | 'invalid' || 0 | HttpStatus.BAD_REQUEST
+ }
+
+ def 'Replace list XML content #scenario.'() {
+ when: 'list-nodes endpoint is invoked with put (update) operation'
+ def putRequestBuilder = put("$dataNodeBaseEndpointV1/anchors/$anchorName/list-nodes")
+ .contentType(MediaType.APPLICATION_XML)
+ .param('xpath', 'parent xpath')
+ .content(requestBodyXml)
+ 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.replaceListContent(dataspaceName, anchorName, 'parent xpath', expectedXmlData,
+ { it == DateTimeUtility.toOffsetDateTime(observedTimestamp) }, ContentType.XML)
where:
scenario | observedTimestamp || expectedApiCount | expectedHttpStatus
'with observed-timestamp' | '2021-03-03T23:59:59.999-0400' || 1 | HttpStatus.OK