From 32446dce35b5bf9d2c84751718cb4ece7f96fa72 Mon Sep 17 00:00:00 2001 From: niamhcore Date: Mon, 1 Mar 2021 13:25:13 +0000 Subject: CPS-265 - updating cps path to support include-descendants option. Issue-ID: CPS-265 Signed-off-by: niamhcore Change-Id: I9e9b84760dbc8b5eb4b31ab972fdb2d186c6bb48 --- .../rest/controller/QueryRestControllerSpec.groovy | 27 ++++++++++++++-------- 1 file changed, 18 insertions(+), 9 deletions(-) (limited to 'cps-rest/src/test') 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 4d9a558ef..0927c9d1e 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 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 -- cgit 1.2.3-korg