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 --- cps-nf-proxy-rest/docs/openapi/xnfProxy.yml | 1 + .../nfproxy/rest/controller/NfProxyController.java | 8 +++++-- .../rest/controller/NfProxyControllerSpec.groovy | 27 ++++++++++++++-------- 3 files changed, 24 insertions(+), 12 deletions(-) (limited to 'cps-nf-proxy-rest') diff --git a/cps-nf-proxy-rest/docs/openapi/xnfProxy.yml b/cps-nf-proxy-rest/docs/openapi/xnfProxy.yml index c39d2dff0..141e47258 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 93ed06580..680ca127b 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 queryNodesByCmHandleAndCpsPath(final String cmHandle, @Valid final String cpsPath) { - final Collection dataNodes = nfProxyDataService.queryDataNodes(cmHandle, cpsPath); + public ResponseEntity 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 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 742a643fa..a81411caf 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 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.'() { -- cgit 1.2.3-korg