diff options
author | danielhanrahan <daniel.hanrahan@est.tech> | 2024-11-22 09:20:03 +0000 |
---|---|---|
committer | danielhanrahan <daniel.hanrahan@est.tech> | 2024-11-22 10:19:20 +0000 |
commit | d378e7b4321bf940424079440461eb0b874ad096 (patch) | |
tree | 7d208329ce03aeb339bdd89644b6cdb72e29a035 /cps-rest/src/test | |
parent | 225626a21199cbb8fbab976169785313b3aeceb7 (diff) |
Make Content-Type header default to JSON for CPS APIs
Recent changes for XML support have made Content-Type header
mandatory, where before it was not. This change makes CPS
default to JSON if Content-Type is not specified.
Issue-ID: CPS-2517
Signed-off-by: danielhanrahan <daniel.hanrahan@est.tech>
Change-Id: Ic3718bfe7aedd6fe9dbd978f520179b184c9c932
Diffstat (limited to 'cps-rest/src/test')
-rwxr-xr-x | cps-rest/src/test/groovy/org/onap/cps/rest/controller/DataRestControllerSpec.groovy | 17 |
1 files changed, 17 insertions, 0 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 27738b07c6..72ae4c7f91 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 @@ -328,6 +328,23 @@ class DataRestControllerSpec extends Specification { assert numberOfDataTrees == 2 } + def 'Get all the data trees using V2 without Content-Type defaults to json'() { + given: 'the service returns all data node leaves' + def xpath = '/' + def endpoint = "$dataNodeBaseEndpointV2/anchors/$anchorName/node" + mockCpsDataService.getDataNodes(dataspaceName, anchorName, xpath, OMIT_DESCENDANTS) >> [dataNodeWithLeavesNoChildren, dataNodeWithLeavesNoChildren2] + when: 'V2 of get request is performed through REST API without specifying content-type header' + def response = + mvc.perform(get(endpoint) + .param('xpath', xpath)) + .andReturn().response + then: 'a success response is returned' + response.status == HttpStatus.OK.value() + and: 'the response contains the datanode in json array format' + response.getContentAsString() == '[{"parent-1":{"leaf":"value","leafList":["leaveListElement1","leaveListElement2"]}},' + + '{"parent-2":{"leaf":"value"}}]' + } + def 'Get all the data trees as XML with root node xPath using V2'() { given: 'the service returns all data node leaves' def xpath = '/' |