aboutsummaryrefslogtreecommitdiffstats
path: root/cps-ncmp-rest
diff options
context:
space:
mode:
authorRuslan Kashapov <ruslan.kashapov@pantheon.tech>2021-04-20 11:14:30 +0300
committerRishi Chail <rishi.chail@est.tech>2021-04-21 13:01:53 +0000
commitd07ebc86b474e0eb8e8f2f2ba24db4ef46f13b79 (patch)
tree662c6a5b25fca95dffe5565eb5285414ca20c435 /cps-ncmp-rest
parentcf37a74874074ab0de9ab4eac8143387355f1afe (diff)
Create child data node (part 2): NCMP service + REST
Issue-ID: CPS-337 Change-Id: Icf703f6f375e5f280058d58c781eac081f3dd161 Signed-off-by: Ruslan Kashapov <ruslan.kashapov@pantheon.tech>
Diffstat (limited to 'cps-ncmp-rest')
-rw-r--r--cps-ncmp-rest/docs/openapi/ncmproxy.yml28
-rw-r--r--cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NetworkCmProxyController.java7
-rw-r--r--cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyControllerSpec.groovy40
3 files changed, 67 insertions, 8 deletions
diff --git a/cps-ncmp-rest/docs/openapi/ncmproxy.yml b/cps-ncmp-rest/docs/openapi/ncmproxy.yml
index 2a70d70a6..1bbc096f0 100644
--- a/cps-ncmp-rest/docs/openapi/ncmproxy.yml
+++ b/cps-ncmp-rest/docs/openapi/ncmproxy.yml
@@ -1,5 +1,6 @@
# ============LICENSE_START=======================================================
# Modification (C) 2021 Nordix Foundation
+# Modification (C) 2021 Pantheon.tech
# ================================================================================
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -64,6 +65,33 @@ nodesByCmHandleAndCpsPath:
$ref: 'components.yaml#/components/responses/NotFound'
nodesByCmHandleAndXpath:
+ post:
+ description: Create a node with descendants for the given CM Handle; top level or under existing node (requires xpath)
+ tags:
+ - network-cm-proxy
+ summary: Create a node with descendants
+ operationId: createNode
+ parameters:
+ - $ref: 'components.yaml#/components/parameters/cmHandleInPath'
+ - $ref: 'components.yaml#/components/parameters/xpathInQuery'
+ requestBody:
+ required: true
+ content:
+ application/json:
+ schema:
+ type: string
+ responses:
+ 201:
+ $ref: 'components.yaml#/components/responses/Created'
+ 400:
+ $ref: 'components.yaml#/components/responses/BadRequest'
+ 401:
+ $ref: 'components.yaml#/components/responses/Unauthorized'
+ 403:
+ $ref: 'components.yaml#/components/responses/Forbidden'
+ 404:
+ $ref: 'components.yaml#/components/responses/NotFound'
+
patch:
description: Update node leaves for the given cps path and cm Handle
tags:
diff --git a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NetworkCmProxyController.java b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NetworkCmProxyController.java
index acbbdd939..fccfb712a 100644
--- a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NetworkCmProxyController.java
+++ b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NetworkCmProxyController.java
@@ -48,6 +48,13 @@ public class NetworkCmProxyController implements NetworkCmProxyApi {
private NetworkCmProxyDataService networkCmProxyDataService;
@Override
+ public ResponseEntity<String> createNode(final String jsonData, final String cmHandle,
+ final String parentNodeXpath) {
+ networkCmProxyDataService.createDataNode(cmHandle, parentNodeXpath, jsonData);
+ return new ResponseEntity<>(HttpStatus.CREATED);
+ }
+
+ @Override
public ResponseEntity<Object> getNodeByCmHandleAndXpath(final String cmHandle, @Valid final String xpath,
@Valid final Boolean includeDescendants) {
if (XPATH_ROOT.equals(xpath)) {
diff --git a/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyControllerSpec.groovy b/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyControllerSpec.groovy
index aa9fa86d1..f0a3d09c2 100644
--- a/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyControllerSpec.groovy
+++ b/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyControllerSpec.groovy
@@ -21,6 +21,12 @@
package org.onap.cps.ncmp.rest.controller
+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
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.patch
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put
import com.google.gson.Gson
import org.onap.cps.ncmp.api.NetworkCmProxyDataService
@@ -35,10 +41,6 @@ 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.*
-
@WebMvcTest
class NetworkCmProxyControllerSpec extends Specification {
@@ -78,10 +80,32 @@ class NetworkCmProxyControllerSpec extends Specification {
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
+ scenario | includeDescendantsOption || expectedCpsDataServiceOption
+ 'no descendants by default' | '' || OMIT_DESCENDANTS
+ 'no descendant explicitly' | 'false' || OMIT_DESCENDANTS
+ 'descendants' | 'true' || INCLUDE_ALL_DESCENDANTS
+ }
+
+ @Unroll
+ def 'Create data node: #scenario.'() {
+ given: 'json data'
+ def jsonData = 'json data'
+ when: 'post request is performed'
+ def response = mvc.perform(
+ post("$dataNodeBaseEndpoint/cm-handles/$cmHandle/nodes")
+ .contentType(MediaType.APPLICATION_JSON)
+ .content(jsonData)
+ .param('xpath', reqXpath)
+ ).andReturn().response
+ then: 'the service method is invoked once with expected parameters'
+ 1 * mockNetworkCmProxyDataService.createDataNode(cmHandle, usedXpath, jsonData)
+ and: 'response status indicates success'
+ response.status == HttpStatus.CREATED.value()
+ where: 'following parameters were used'
+ scenario | reqXpath || usedXpath
+ 'no xpath parameter' | '' || '/'
+ 'root xpath' | '/' || '/'
+ 'parent node xpath' | '/xpath' || '/xpath'
}
def 'Update data node leaves.'() {