diff options
author | Rudrangi Anupriya <ra00745022@techmahindra.com> | 2024-11-27 23:49:42 +0530 |
---|---|---|
committer | Rudrangi Anupriya <ra00745022@techmahindra.com> | 2024-11-28 12:30:33 +0530 |
commit | dfcc95236daf7d45687fa42446a7d236ac12637e (patch) | |
tree | ca81405d08597548b80c844a7eb12aa46598d736 /cps-rest/src | |
parent | 05e97441ad192b69051fbb67263284eb99ee1c41 (diff) |
XML content support on Replace list content
Here to bring Support for XML Response Entity in Replace List content
- Add ContentTypeInheadr in cpsData.yml to support application/xml
- Add contentTypeInHeader parameter to accept xml in DataRestController.java
- Modify the code return xml Data
- written testcase for above changes made
Issue-ID: CPS-2411
Change-Id: Ibb7ffb66ccdd03703266123c6d5c2eade0e7cb4a
Signed-off-by: Rudrangi Anupriya <ra00745022@techmahindra.com>
Diffstat (limited to 'cps-rest/src')
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 b425333f9e..c419a81245 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 @@ -160,7 +160,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 |