From 6d5849d012c1a2fe2177d332610a1b99bd44fe40 Mon Sep 17 00:00:00 2001 From: danielhanrahan Date: Thu, 13 Mar 2025 13:33:27 +0000 Subject: Add attribute-axis to CPS query nodes rest API Support attribute-axis in query nodes api for both JSON and XML: /cps/v2/dataspaces/{dataspace}/anchors/{anchor}/nodes/query It allows such queries as: //books/@title which returns a JSON response like: [{"title":"Matilda"},{"title":"Dune"}] and an XML response like: MatildaDune Issue-ID: CPS-2620 Signed-off-by: danielhanrahan Change-Id: Iab51fbe76281740b8dbde373e11864d3509696ef --- .../cps/rest/controller/QueryRestControllerSpec.groovy | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'cps-rest') diff --git a/cps-rest/src/test/groovy/org/onap/cps/rest/controller/QueryRestControllerSpec.groovy b/cps-rest/src/test/groovy/org/onap/cps/rest/controller/QueryRestControllerSpec.groovy index 5f6de2ec4c..b49afb4798 100644 --- a/cps-rest/src/test/groovy/org/onap/cps/rest/controller/QueryRestControllerSpec.groovy +++ b/cps-rest/src/test/groovy/org/onap/cps/rest/controller/QueryRestControllerSpec.groovy @@ -94,6 +94,23 @@ class QueryRestControllerSpec extends Specification { 'descendants XML' | '2' | MediaType.APPLICATION_XML || 2 || 'value' } + def 'Query data node (v2) by cps path for given dataspace and anchor with attribute-axis and #scenario'() { + given: 'the query endpoint' + def dataNodeEndpointV2 = "$basePath/v2/dataspaces/my_dataspace/anchors/my_anchor/nodes/query" + when: 'query data nodes API is invoked' + def response = mvc.perform(get(dataNodeEndpointV2).contentType(contentType).param('cps-path', '/my/path/@myAttribute').param('descendants', '0')) + .andReturn().response + then: 'the call is delegated to the cps service facade which returns a list containing two attributes as maps' + 1 * mockCpsFacade.executeAnchorQuery('my_dataspace', 'my_anchor', '/my/path/@myAttribute', OMIT_DESCENDANTS) >> [['myAttribute':'value1'], ['myAttribute':'value2']] + and: 'the response contains the datanode in the expected format' + assert response.status == HttpStatus.OK.value() + assert response.getContentAsString() == expectedOutput + where: 'the following options for content type are provided in the request' + scenario | contentType || expectedOutput + 'JSON' | MediaType.APPLICATION_JSON || '[{"myAttribute":"value1"},{"myAttribute":"value2"}]' + 'XML' | MediaType.APPLICATION_XML || 'value1value2' + } + def 'Query data node by cps path for given dataspace across all anchors'() { given: 'the query endpoint' def dataNodeEndpoint = "$basePath/v2/dataspaces/my_dataspace/nodes/query" -- cgit