From 14d6a9b990005965307bbab66b0ffe15327a8758 Mon Sep 17 00:00:00 2001 From: Rudrangi Anupriya Date: Sat, 2 Nov 2024 00:16:58 +0530 Subject: XML content support on get a node Here to bring Support for XML Response Entity In GET A NODE - Made changes in components.yml to support contentType as application/xml - Add ContentTypeInheadr in cpsDataV2.yml to support application/xml - Add contentTypeInHeader parameter to accept xml in DataRestController.java - Implemented Logic to convert DataMaps To XML Data - written testcase for above changes made Issue-ID: CPS-2280 Change-Id: Ibe7ffb66ccbb03703626132c6d5c2eade0e7ab4b Signed-off-by: Rudrangi Anupriya --- .../rest/controller/DataRestControllerSpec.groovy | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'cps-rest/src/test/groovy') 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 705c2fee91..27738b07c6 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 @@ -314,7 +314,9 @@ class DataRestControllerSpec extends Specification { mockCpsDataService.getDataNodes(dataspaceName, anchorName, xpath, OMIT_DESCENDANTS) >> [dataNodeWithLeavesNoChildren, dataNodeWithLeavesNoChildren2] when: 'V2 of get request is performed through REST API' def response = - mvc.perform(get(endpoint).param('xpath', xpath)) + mvc.perform(get(endpoint) + .contentType(MediaType.APPLICATION_JSON) + .param('xpath', xpath)) .andReturn().response then: 'a success response is returned' response.status == HttpStatus.OK.value() @@ -326,6 +328,21 @@ class DataRestControllerSpec extends Specification { assert numberOfDataTrees == 2 } + def 'Get all the data trees as XML with root node xPath using V2'() { + given: 'the service returns all data node leaves' + def xpath = '/' + def endpoint = "$dataNodeBaseEndpointV2/anchors/$anchorName/node" + mockCpsDataService.getDataNodes(dataspaceName, anchorName, xpath, OMIT_DESCENDANTS) >> [dataNodeWithLeavesNoChildren] + when: 'V2 of get request is performed through REST API with XML content type' + def response = + mvc.perform(get(endpoint).contentType(MediaType.APPLICATION_XML).param('xpath', xpath)) + .andReturn().response + then: 'a success response is returned' + response.status == HttpStatus.OK.value() + and: 'the response contains the datanode in XML format' + response.getContentAsString() == 'valueleaveListElement1leaveListElement2' + } + def 'Get data node with #scenario using V2.'() { given: 'the service returns data nodes with #scenario' def xpath = 'some xPath' @@ -335,6 +352,7 @@ class DataRestControllerSpec extends Specification { def response = mvc.perform( get(endpoint) + .contentType(MediaType.APPLICATION_JSON) .param('xpath', xpath) .param('descendants', includeDescendantsOption)) .andReturn().response @@ -361,6 +379,7 @@ class DataRestControllerSpec extends Specification { def response = mvc.perform( get(endpoint) + .contentType(MediaType.APPLICATION_JSON) .param('xpath', xpath) .param('descendants', '2')) .andReturn().response -- cgit