aboutsummaryrefslogtreecommitdiffstats
path: root/cps-rest
diff options
context:
space:
mode:
authordanielhanrahan <daniel.hanrahan@est.tech>2025-03-13 13:33:27 +0000
committerdanielhanrahan <daniel.hanrahan@est.tech>2025-03-13 14:52:11 +0000
commit6d5849d012c1a2fe2177d332610a1b99bd44fe40 (patch)
tree86601e1a701a438055604790d3e7015cae5bb835 /cps-rest
parent4f002a7da4001e2fc00d1ed37154112d9c13a828 (diff)
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: <title>Matilda</title><title>Dune</title> Issue-ID: CPS-2620 Signed-off-by: danielhanrahan <daniel.hanrahan@est.tech> Change-Id: Iab51fbe76281740b8dbde373e11864d3509696ef
Diffstat (limited to 'cps-rest')
-rw-r--r--cps-rest/src/test/groovy/org/onap/cps/rest/controller/QueryRestControllerSpec.groovy17
1 files changed, 17 insertions, 0 deletions
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 || '<prefixedPath><path><leaf>value</leaf></path></prefixedPath>'
}
+ 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 || '<myAttribute>value1</myAttribute><myAttribute>value2</myAttribute>'
+ }
+
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"