summaryrefslogtreecommitdiffstats
path: root/cps-rest/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'cps-rest/src/test')
-rw-r--r--cps-rest/src/test/groovy/org/onap/cps/rest/controller/QueryRestControllerSpec.groovy27
1 files changed, 18 insertions, 9 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 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