aboutsummaryrefslogtreecommitdiffstats
path: root/cps-rest
diff options
context:
space:
mode:
authorRuslan Kashapov <ruslan.kashapov@pantheon.tech>2020-12-10 10:49:59 +0200
committerRuslan Kashapov <ruslan.kashapov@pantheon.tech>2021-01-06 15:03:59 +0200
commit5a8718b84dbd3c6fa78aa644a4695274a0a1ab5d (patch)
tree4dbd96f90aee895053036d5616a00b9912dcde82 /cps-rest
parentec3e17505d12785586fc2418438c3d45b63d7dbd (diff)
Create dataspace
Issue-ID: CPS-134 Change-Id: Ie7f00f9c322a12a6c2a71c1407f6970a7dd24d2d Signed-off-by: Ruslan Kashapov <ruslan.kashapov@pantheon.tech>
Diffstat (limited to 'cps-rest')
-rwxr-xr-xcps-rest/docs/api/swagger/openapi.yml29
-rw-r--r--cps-rest/src/main/java/org/onap/cps/rest/controller/AdminRestController.java6
-rw-r--r--cps-rest/src/test/groovy/org/onap/cps/rest/controller/AdminRestControllerSpec.groovy28
3 files changed, 63 insertions, 0 deletions
diff --git a/cps-rest/docs/api/swagger/openapi.yml b/cps-rest/docs/api/swagger/openapi.yml
index d76ec5ecd5..d2c720e01c 100755
--- a/cps-rest/docs/api/swagger/openapi.yml
+++ b/cps-rest/docs/api/swagger/openapi.yml
@@ -9,6 +9,35 @@ tags:
- name: cps-rest
description: cps Resource
paths:
+ /v1/dataspaces:
+ post:
+ tags:
+ - cps-admin
+ summary: Create a new dataspace
+ operationId: createDataspace
+ parameters:
+ - name: dataspace-name
+ in: query
+ description: dataspace-name
+ required: true
+ schema:
+ type: string
+ responses:
+ 201:
+ description: Created
+ content:
+ application/json:
+ schema:
+ type: string
+ 400:
+ description: Bad Request
+ content: { }
+ 401:
+ description: Unauthorized
+ content: { }
+ 403:
+ description: Forbidden
+ content: { }
/v1/dataspaces/{dataspace-name}/:
delete:
tags:
diff --git a/cps-rest/src/main/java/org/onap/cps/rest/controller/AdminRestController.java b/cps-rest/src/main/java/org/onap/cps/rest/controller/AdminRestController.java
index 6dc2cee72a..9549580bac 100644
--- a/cps-rest/src/main/java/org/onap/cps/rest/controller/AdminRestController.java
+++ b/cps-rest/src/main/java/org/onap/cps/rest/controller/AdminRestController.java
@@ -47,6 +47,12 @@ public class AdminRestController implements CpsAdminApi {
private ModelMapper modelMapper;
@Override
+ public ResponseEntity<String> createDataspace(final String dataspaceName) {
+ cpsAdminService.createDataspace(dataspaceName);
+ return new ResponseEntity<>(dataspaceName, HttpStatus.CREATED);
+ }
+
+ @Override
public ResponseEntity<String> createSchemaSet(final String schemaSetName, final MultipartFile multipartFile,
final String dataspaceName) {
cpsModuleService.createSchemaSet(dataspaceName, schemaSetName, extractYangResourcesMap(multipartFile));
diff --git a/cps-rest/src/test/groovy/org/onap/cps/rest/controller/AdminRestControllerSpec.groovy b/cps-rest/src/test/groovy/org/onap/cps/rest/controller/AdminRestControllerSpec.groovy
index ed87e3c95a..9919649cb0 100644
--- a/cps-rest/src/test/groovy/org/onap/cps/rest/controller/AdminRestControllerSpec.groovy
+++ b/cps-rest/src/test/groovy/org/onap/cps/rest/controller/AdminRestControllerSpec.groovy
@@ -24,6 +24,7 @@ import org.modelmapper.ModelMapper
import org.onap.cps.api.CpsAdminService
import org.onap.cps.api.CpsModuleService
import org.onap.cps.spi.model.Anchor
+import org.onap.cps.spi.exceptions.DataspaceAlreadyDefinedException
import org.spockframework.spring.SpringBean
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc
@@ -60,6 +61,25 @@ class AdminRestControllerSpec extends Specification {
def anchor = new Anchor(name: 'my_anchor')
def anchorList = [anchor]
+ def 'Create new dataspace'() {
+ when:
+ def response = performCreateDataspaceRequest("new-dataspace")
+ then: 'Service method is invoked with expected parameters'
+ 1 * mockCpsAdminService.createDataspace("new-dataspace")
+ and:
+ response.status == HttpStatus.CREATED.value()
+ }
+
+ def 'Create dataspace over existing with same name'() {
+ given:
+ def thrownException = new DataspaceAlreadyDefinedException("", new RuntimeException())
+ mockCpsAdminService.createDataspace("existing-dataspace") >> { throw thrownException }
+ when:
+ def response = performCreateDataspaceRequest("existing-dataspace")
+ then:
+ response.status == HttpStatus.BAD_REQUEST.value()
+ }
+
def 'Create schema set from yang file'() {
def yangResourceMapCapture
given:
@@ -83,6 +103,14 @@ class AdminRestControllerSpec extends Specification {
response.status == HttpStatus.BAD_REQUEST.value()
}
+ def performCreateDataspaceRequest(String dataspaceName) {
+ return mvc.perform(
+ MockMvcRequestBuilders
+ .post('/v1/dataspaces')
+ .param('dataspace-name', dataspaceName)
+ ).andReturn().response
+ }
+
def createMultipartFile(filename, content) {
return new MockMultipartFile("file", filename, "text/plain", content.getBytes())
}