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