diff options
Diffstat (limited to 'cps-rest')
3 files changed, 24 insertions, 11 deletions
diff --git a/cps-rest/docs/api/swagger/cpsQuery.yml b/cps-rest/docs/api/swagger/cpsQuery.yml index 91a4bdbfa1..779c9a0948 100644 --- a/cps-rest/docs/api/swagger/cpsQuery.yml +++ b/cps-rest/docs/api/swagger/cpsQuery.yml @@ -9,6 +9,7 @@ nodesByDataspaceAndAnchorAndCpsPath: - $ref: 'components.yml#/components/parameters/dataspaceNameInPath' - $ref: 'components.yml#/components/parameters/anchorNameInPath' - $ref: 'components.yml#/components/parameters/cpsPathInQuery' + - $ref: 'components.yml#/components/parameters/includeDescendantsOptionInQuery' responses: '200': $ref: 'components.yml#/components/responses/Ok' 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 a8816f02b4..c6b5284fbd 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 @@ -24,6 +24,7 @@ import java.util.Collection; 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.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; @@ -40,9 +41,11 @@ public class QueryRestController implements CpsQueryApi { @Override public ResponseEntity<Object> getNodesByDataspaceAndAnchorAndCpsPath(final String dataspaceName, - final String anchorName, @Valid final String cpsPath) { + final String anchorName, @Valid final String cpsPath, @Valid final Boolean includeDescendants) { + final FetchDescendantsOption fetchDescendantsOption = Boolean.TRUE.equals(includeDescendants) + ? FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS : FetchDescendantsOption.OMIT_DESCENDANTS; final Collection<DataNode> dataNodes = - cpsQueryService.queryDataNodes(dataspaceName, anchorName, cpsPath); + cpsQueryService.queryDataNodes(dataspaceName, anchorName, cpsPath, fetchDescendantsOption); return new ResponseEntity<>(new Gson().toJson(dataNodes), 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 4d9a558ef0..0927c9d1e8 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 @@ -19,7 +19,7 @@ package org.onap.cps.rest.controller -import com.google.common.collect.ImmutableMap + import com.google.gson.Gson import org.modelmapper.ModelMapper import org.onap.cps.api.CpsAdminService @@ -36,7 +36,10 @@ import org.springframework.http.HttpStatus import org.springframework.test.web.servlet.MockMvc import spock.lang.Shared import spock.lang.Specification +import spock.lang.Unroll +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 @WebMvcTest @@ -63,22 +66,28 @@ class QueryRestControllerSpec extends Specification { @Value('${rest.api.cps-base-path}') def basePath - def 'Query data node by cps path for the given dataspace and anchor.'() { + @Unroll + 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 dataspaceName = 'my_dataspace' def anchorName = 'my_anchor' - def cpsPath = '/xpath/leaves[@leaf=\'value\']' - def dataNode = new DataNodeBuilder().withXpath("/xpath") - .withLeaves(ImmutableMap.of("leaf", "value")).build() - ArrayList<DataNode> dataNodeList = new ArrayList(); - dataNodeList.add(dataNode) - mockCpsQueryService.queryDataNodes(dataspaceName, anchorName, cpsPath) >> dataNodeList + def cpsPath = 'some cps-path' + mockCpsQueryService.queryDataNodes(dataspaceName, anchorName, cpsPath, expectedCpsDataServiceOption) >> [dataNode] and: 'the query endpoint' def dataNodeEndpoint = "$basePath/v1/dataspaces/$dataspaceName/anchors/$anchorName/nodes/query" when: 'query data nodes API is invoked' - def response = mvc.perform(get(dataNodeEndpoint).param('cps-path', cpsPath)).andReturn().response + def response = mvc.perform(get(dataNodeEndpoint) + .param('cps-path', cpsPath) + .param('include-descendants', includeDescendantsOption)) + .andReturn().response then: 'the response contains the the datanode in json format' response.status == HttpStatus.OK.value() response.getContentAsString().contains(new Gson().toJson(dataNode)) + where: 'the following options for include descendants are provided in the request' + scenario | includeDescendantsOption || expectedCpsDataServiceOption + 'no descendants by default' | '' || OMIT_DESCENDANTS + 'no descendant explicitly' | 'false' || OMIT_DESCENDANTS + 'descendants' | 'true' || INCLUDE_ALL_DESCENDANTS } }
\ No newline at end of file |