summaryrefslogtreecommitdiffstats
path: root/cps-nf-proxy-rest
diff options
context:
space:
mode:
authorniamhcore <niamh.core@est.tech>2021-03-01 13:25:13 +0000
committerNiamh Core <niamh.core@est.tech>2021-03-02 11:13:25 +0000
commit32446dce35b5bf9d2c84751718cb4ece7f96fa72 (patch)
tree03a0fb6b16c6c6e692bc54db74440d005c501573 /cps-nf-proxy-rest
parent7c981df521c9d8eb6f340b2b118491eeeb21ae59 (diff)
CPS-265 - updating cps path to support include-descendants option.
Issue-ID: CPS-265 Signed-off-by: niamhcore <niamh.core@est.tech> Change-Id: I9e9b84760dbc8b5eb4b31ab972fdb2d186c6bb48
Diffstat (limited to 'cps-nf-proxy-rest')
-rw-r--r--cps-nf-proxy-rest/docs/openapi/xnfProxy.yml1
-rw-r--r--cps-nf-proxy-rest/src/main/java/org/onap/cps/nfproxy/rest/controller/NfProxyController.java8
-rw-r--r--cps-nf-proxy-rest/src/test/groovy/org/onap/cps/nfproxy/rest/controller/NfProxyControllerSpec.groovy27
3 files changed, 24 insertions, 12 deletions
diff --git a/cps-nf-proxy-rest/docs/openapi/xnfProxy.yml b/cps-nf-proxy-rest/docs/openapi/xnfProxy.yml
index c39d2dff02..141e472582 100644
--- a/cps-nf-proxy-rest/docs/openapi/xnfProxy.yml
+++ b/cps-nf-proxy-rest/docs/openapi/xnfProxy.yml
@@ -33,6 +33,7 @@ nodesByCmHandleAndCpsPath:
parameters:
- $ref: 'components.yaml#/components/parameters/cmHandleInPath'
- $ref: 'components.yaml#/components/parameters/cpsPathInQuery'
+ - $ref: 'components.yaml#/components/parameters/includeDescendantsOptionInQuery'
responses:
200:
$ref: 'components.yaml#/components/responses/Ok'
diff --git a/cps-nf-proxy-rest/src/main/java/org/onap/cps/nfproxy/rest/controller/NfProxyController.java b/cps-nf-proxy-rest/src/main/java/org/onap/cps/nfproxy/rest/controller/NfProxyController.java
index 93ed06580b..680ca127b8 100644
--- a/cps-nf-proxy-rest/src/main/java/org/onap/cps/nfproxy/rest/controller/NfProxyController.java
+++ b/cps-nf-proxy-rest/src/main/java/org/onap/cps/nfproxy/rest/controller/NfProxyController.java
@@ -60,8 +60,12 @@ public class NfProxyController implements NfProxyApi {
}
@Override
- public ResponseEntity<Object> queryNodesByCmHandleAndCpsPath(final String cmHandle, @Valid final String cpsPath) {
- final Collection<DataNode> dataNodes = nfProxyDataService.queryDataNodes(cmHandle, cpsPath);
+ public ResponseEntity<Object> queryNodesByCmHandleAndCpsPath(final String cmHandle, @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 =
+ nfProxyDataService.queryDataNodes(cmHandle, cpsPath, fetchDescendantsOption);
return new ResponseEntity<>(GSON.toJson(dataNodes), HttpStatus.OK);
}
diff --git a/cps-nf-proxy-rest/src/test/groovy/org/onap/cps/nfproxy/rest/controller/NfProxyControllerSpec.groovy b/cps-nf-proxy-rest/src/test/groovy/org/onap/cps/nfproxy/rest/controller/NfProxyControllerSpec.groovy
index 742a643fa6..a81411caf0 100644
--- a/cps-nf-proxy-rest/src/test/groovy/org/onap/cps/nfproxy/rest/controller/NfProxyControllerSpec.groovy
+++ b/cps-nf-proxy-rest/src/test/groovy/org/onap/cps/nfproxy/rest/controller/NfProxyControllerSpec.groovy
@@ -21,10 +21,9 @@
package org.onap.cps.nfproxy.rest.controller
-import com.google.common.collect.ImmutableMap
+
import com.google.gson.Gson
import org.onap.cps.nfproxy.api.NfProxyDataService
-import org.onap.cps.spi.model.DataNode
import org.onap.cps.spi.model.DataNodeBuilder
import org.spockframework.spring.SpringBean
import org.springframework.beans.factory.annotation.Autowired
@@ -34,7 +33,9 @@ import org.springframework.http.HttpStatus
import org.springframework.http.MediaType
import org.springframework.test.web.servlet.MockMvc
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.*
@@ -59,22 +60,28 @@ class NfProxyControllerSpec extends Specification {
def cmHandle = 'some handle'
def xpath = 'some xpath'
- def 'Query data node by cps path for the given cm handle.'() {
+ @Unroll
+ def 'Query data node by cps path for the given cm handle with #scenario.'() {
given: 'service method returns a list containing a data node'
- 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)
- mockNfProxyDataService.queryDataNodes(cmHandle, cpsPath) >> dataNodeList
+ def dataNode = new DataNodeBuilder().withXpath('/xpath').build()
+ def cpsPath = 'some cps-path'
+ mockNfProxyDataService.queryDataNodes(cmHandle, cpsPath, expectedCpsDataServiceOption) >> [dataNode]
and: 'the query endpoint'
def dataNodeEndpoint = "$dataNodeBaseEndpoint/cm-handles/$cmHandle/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()
def expectedJsonContent = new Gson().toJson(dataNode)
response.getContentAsString().contains(expectedJsonContent)
+ 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
}
def 'Update data node leaves.'() {