aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoraditya puthuparambil <aditya.puthuparambil@bell.ca>2021-08-11 16:40:36 +0000
committerGerrit Code Review <gerrit@onap.org>2021-08-11 16:40:36 +0000
commit2ff8b7c6c11e56f6104ed529cc858f5fc128ea25 (patch)
treedcda7ca95851e65de4d424e881ba87a09e356d1a
parentbe21595d53636e2c9b912bfbe8dfdefb81edc70f (diff)
parent4802d46c0d3e7d65a9dcfbf6c168c6466d55c0b2 (diff)
Merge "Update response query format"
-rw-r--r--cps-rest/src/main/java/org/onap/cps/rest/controller/QueryRestController.java10
-rw-r--r--cps-rest/src/test/groovy/org/onap/cps/rest/controller/QueryRestControllerSpec.groovy9
2 files changed, 15 insertions, 4 deletions
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 b7fc9f7950..8aa65a0057 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
@@ -21,12 +21,16 @@
package org.onap.cps.rest.controller;
import com.google.gson.Gson;
+import java.util.ArrayList;
import java.util.Collection;
+import java.util.List;
+import java.util.Map;
import javax.validation.Valid;
import org.onap.cps.api.CpsQueryService;
import org.onap.cps.rest.api.CpsQueryApi;
import org.onap.cps.spi.FetchDescendantsOption;
import org.onap.cps.spi.model.DataNode;
+import org.onap.cps.utils.DataMapUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
@@ -47,6 +51,10 @@ public class QueryRestController implements CpsQueryApi {
? FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS : FetchDescendantsOption.OMIT_DESCENDANTS;
final Collection<DataNode> dataNodes =
cpsQueryService.queryDataNodes(dataspaceName, anchorName, cpsPath, fetchDescendantsOption);
- return new ResponseEntity<>(new Gson().toJson(dataNodes), HttpStatus.OK);
+ final List<Map<String, Object>> dataNodeList = new ArrayList<>();
+ for (final DataNode dataNode : dataNodes) {
+ dataNodeList.add(DataMapUtils.toDataMap(dataNode));
+ }
+ return new ResponseEntity<>(new Gson().toJson(dataNodeList), HttpStatus.OK);
}
}
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 d43e02b316..550dec972e 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
@@ -22,6 +22,8 @@
package org.onap.cps.rest.controller
+import org.onap.cps.spi.model.DataNode
+
import static org.onap.cps.spi.FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS
import static org.onap.cps.spi.FetchDescendantsOption.OMIT_DESCENDANTS
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get
@@ -55,11 +57,12 @@ class QueryRestControllerSpec extends Specification {
def 'Query data node by cps path for the given dataspace and anchor with #scenario.'() {
given: 'service method returns a list containing a data node'
- def dataNode = new DataNodeBuilder().withXpath('/xpath').build()
+ def dataNode1 = new DataNodeBuilder().withXpath('/xpath')
+ .withLeaves([leaf: 'value', leafList: ['leaveListElement1', 'leaveListElement2']]).build()
def dataspaceName = 'my_dataspace'
def anchorName = 'my_anchor'
def cpsPath = 'some cps-path'
- mockCpsQueryService.queryDataNodes(dataspaceName, anchorName, cpsPath, expectedCpsDataServiceOption) >> [dataNode]
+ mockCpsQueryService.queryDataNodes(dataspaceName, anchorName, cpsPath, expectedCpsDataServiceOption) >> [dataNode1, dataNode1]
and: 'the query endpoint'
def dataNodeEndpoint = "$basePath/v1/dataspaces/$dataspaceName/anchors/$anchorName/nodes/query"
when: 'query data nodes API is invoked'
@@ -71,7 +74,7 @@ class QueryRestControllerSpec extends Specification {
.andReturn().response
then: 'the response contains the the datanode in json format'
response.status == HttpStatus.OK.value()
- response.getContentAsString().contains(new Gson().toJson(dataNode))
+ response.getContentAsString() == '[{"leaf":"value","leafList":["leaveListElement1","leaveListElement2"]},{"leaf":"value","leafList":["leaveListElement1","leaveListElement2"]}]'
where: 'the following options for include descendants are provided in the request'
scenario | includeDescendantsOption || expectedCpsDataServiceOption
'no descendants by default' | '' || OMIT_DESCENDANTS