summaryrefslogtreecommitdiffstats
path: root/cps-rest/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'cps-rest/src/test')
-rw-r--r--cps-rest/src/test/groovy/org/onap/cps/rest/controller/AdminRestControllerSpec.groovy38
-rw-r--r--cps-rest/src/test/groovy/org/onap/cps/rest/exceptions/CpsRestExceptionHandlerSpec.groovy18
2 files changed, 49 insertions, 7 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 0a61c7dd59..a95d606a35 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
@@ -23,8 +23,9 @@ package org.onap.cps.rest.controller
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.onap.cps.spi.exceptions.SchemaSetInUseException
+import org.onap.cps.spi.model.Anchor
import org.onap.cps.spi.model.SchemaSet
import org.spockframework.spring.SpringBean
import org.springframework.beans.factory.annotation.Autowired
@@ -33,12 +34,14 @@ import org.springframework.http.HttpStatus
import org.springframework.http.MediaType
import org.springframework.mock.web.MockMultipartFile
import org.springframework.test.web.servlet.MockMvc
-import org.springframework.test.web.servlet.request.MockMvcRequestBuilders
import org.springframework.util.LinkedMultiValueMap
import org.springframework.util.MultiValueMap
import spock.lang.Specification
+import static org.onap.cps.spi.CascadeDeleteAllowed.CASCADE_DELETE_PROHIBITED
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.multipart
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post
@WebMvcTest
@@ -105,11 +108,29 @@ class AdminRestControllerSpec extends Specification {
response.status == HttpStatus.BAD_REQUEST.value()
}
+ def 'Delete schema set.'() {
+ when: 'delete schema set endpoint is invoked'
+ def response = performDeleteRequest(schemaSetEndpoint)
+ then: 'associated service method is invoked with expected parameters'
+ 1 * mockCpsModuleService.deleteSchemaSet('test-dataspace', 'my_schema_set', CASCADE_DELETE_PROHIBITED)
+ and: 'response code indicates success'
+ response.status == HttpStatus.NO_CONTENT.value()
+ }
+
+ def 'Delete schema set which is in use.'() {
+ given: 'the service method throws an exception indicating the schema set is in use'
+ def thrownException = new SchemaSetInUseException('test-dataspace', 'my_schema_set')
+ mockCpsModuleService.deleteSchemaSet('test-dataspace', 'my_schema_set', CASCADE_DELETE_PROHIBITED) >>
+ { throw thrownException }
+ when: 'delete schema set endpoint is invoked'
+ def response = performDeleteRequest(schemaSetEndpoint)
+ then: 'schema set deletion fails with conflict response code'
+ response.status == HttpStatus.CONFLICT.value()
+ }
+
def performCreateDataspaceRequest(String dataspaceName) {
return mvc.perform(
- MockMvcRequestBuilders
- .post('/v1/dataspaces')
- .param('dataspace-name', dataspaceName)
+ post('/v1/dataspaces').param('dataspace-name', dataspaceName)
).andReturn().response
}
@@ -119,13 +140,16 @@ class AdminRestControllerSpec extends Specification {
def performCreateSchemaSetRequest(multipartFile) {
return mvc.perform(
- MockMvcRequestBuilders
- .multipart(schemaSetsEndpoint)
+ multipart(schemaSetsEndpoint)
.file(multipartFile)
.param('schema-set-name', 'test-schema-set')
).andReturn().response
}
+ def performDeleteRequest(String uri) {
+ return mvc.perform(delete(uri)).andReturn().response
+ }
+
def 'Get existing schema set'() {
given:
mockCpsModuleService.getSchemaSet('test-dataspace', 'my_schema_set') >>
diff --git a/cps-rest/src/test/groovy/org/onap/cps/rest/exceptions/CpsRestExceptionHandlerSpec.groovy b/cps-rest/src/test/groovy/org/onap/cps/rest/exceptions/CpsRestExceptionHandlerSpec.groovy
index 99ffbfd05a..d372d3c0b7 100644
--- a/cps-rest/src/test/groovy/org/onap/cps/rest/exceptions/CpsRestExceptionHandlerSpec.groovy
+++ b/cps-rest/src/test/groovy/org/onap/cps/rest/exceptions/CpsRestExceptionHandlerSpec.groovy
@@ -25,10 +25,12 @@ import org.onap.cps.api.CpsAdminService
import org.onap.cps.api.CpsModuleService
import org.onap.cps.spi.exceptions.AnchorAlreadyDefinedException
import org.onap.cps.spi.exceptions.CpsException
+import org.onap.cps.spi.exceptions.DataInUseException
import org.onap.cps.spi.exceptions.DataValidationException
import org.onap.cps.spi.exceptions.ModelValidationException
import org.onap.cps.spi.exceptions.NotFoundInDataspaceException
import org.onap.cps.spi.exceptions.SchemaSetAlreadyDefinedException
+import org.onap.cps.spi.exceptions.SchemaSetInUseException
import org.spockframework.spring.SpringBean
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest
@@ -38,6 +40,7 @@ import spock.lang.Specification
import spock.lang.Unroll
import static org.springframework.http.HttpStatus.BAD_REQUEST
+import static org.springframework.http.HttpStatus.CONFLICT
import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR
import static org.springframework.http.HttpStatus.NOT_FOUND
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get
@@ -133,6 +136,21 @@ class CpsRestExceptionHandlerSpec extends Specification {
new DataValidationException(errorMessage, errorDetails, null)]
}
+ @Unroll
+ def 'Delete request with a #exceptionThrown.class.simpleName returns HTTP Status Conflict'() {
+
+ when: 'CPS validation exception is thrown by the service'
+ setupTestException(exceptionThrown)
+ def response = performTestRequest()
+
+ then: 'an HTTP Conflict response is returned with correct message and details'
+ assertTestResponse(response, CONFLICT, exceptionThrown.getMessage(), exceptionThrown.getDetails())
+
+ where: 'the following exceptions are thrown'
+ exceptionThrown << [new DataInUseException(dataspaceName, existingObjectName),
+ new SchemaSetInUseException(dataspaceName, existingObjectName)]
+ }
+
/*
* NB. The test uses 'get JSON by id' endpoint and associated service method invocation
* to test the exception handling. The endpoint chosen is not a subject of test.