summaryrefslogtreecommitdiffstats
path: root/cps-rest/src/test/groovy
diff options
context:
space:
mode:
Diffstat (limited to 'cps-rest/src/test/groovy')
-rwxr-xr-xcps-rest/src/test/groovy/org/onap/cps/rest/controller/AdminRestControllerSpec.groovy6
-rwxr-xr-xcps-rest/src/test/groovy/org/onap/cps/rest/controller/DataRestControllerSpec.groovy12
-rw-r--r--cps-rest/src/test/groovy/org/onap/cps/rest/exceptions/CpsRestExceptionHandlerSpec.groovy23
3 files changed, 18 insertions, 23 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 5b5be1c161..3387fb4e1e 100755
--- 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
@@ -32,7 +32,7 @@ import org.onap.cps.api.CpsAdminService
import org.onap.cps.api.CpsDataService
import org.onap.cps.api.CpsModuleService
import org.onap.cps.api.CpsQueryService
-import org.onap.cps.spi.exceptions.DataspaceAlreadyDefinedException
+import org.onap.cps.spi.exceptions.AlreadyDefinedException
import org.onap.cps.spi.exceptions.SchemaSetInUseException
import org.onap.cps.spi.model.Anchor
import org.onap.cps.spi.model.SchemaSet
@@ -98,7 +98,7 @@ class AdminRestControllerSpec extends Specification {
given: 'an endpoint'
def createDataspaceEndpoint = "$basePath/v1/dataspaces";
and: 'the service method throws an exception indicating the dataspace is already defined'
- def thrownException = new DataspaceAlreadyDefinedException("", new RuntimeException())
+ def thrownException = new AlreadyDefinedException(dataspaceName, new RuntimeException())
mockCpsAdminService.createDataspace(dataspaceName) >> { throw thrownException }
when: 'post is invoked'
def response =
@@ -107,7 +107,7 @@ class AdminRestControllerSpec extends Specification {
.param('dataspace-name', dataspaceName))
.andReturn().response
then: 'dataspace creation fails'
- response.status == HttpStatus.BAD_REQUEST.value()
+ response.status == HttpStatus.CONFLICT.value()
}
def 'Create schema set from yang file.'() {
diff --git a/cps-rest/src/test/groovy/org/onap/cps/rest/controller/DataRestControllerSpec.groovy b/cps-rest/src/test/groovy/org/onap/cps/rest/controller/DataRestControllerSpec.groovy
index 15627d5982..5794f88ed8 100755
--- a/cps-rest/src/test/groovy/org/onap/cps/rest/controller/DataRestControllerSpec.groovy
+++ b/cps-rest/src/test/groovy/org/onap/cps/rest/controller/DataRestControllerSpec.groovy
@@ -33,6 +33,7 @@ import org.onap.cps.api.CpsAdminService
import org.onap.cps.api.CpsDataService
import org.onap.cps.api.CpsModuleService
import org.onap.cps.api.CpsQueryService
+import org.onap.cps.spi.exceptions.AlreadyDefinedException
import org.onap.cps.spi.exceptions.AnchorNotFoundException
import org.onap.cps.spi.exceptions.DataNodeNotFoundException
import org.onap.cps.spi.exceptions.DataspaceNotFoundException
@@ -159,11 +160,12 @@ class DataRestControllerSpec extends Specification {
then: 'a success response is returned'
response.status == httpStatus.value()
where:
- scenario | xpath | exception || httpStatus
- 'no dataspace' | '/x-path' | new DataspaceNotFoundException('') || HttpStatus.BAD_REQUEST
- 'no anchor' | '/x-path' | new AnchorNotFoundException('', '') || HttpStatus.BAD_REQUEST
- 'no data' | '/x-path' | new DataNodeNotFoundException('', '', '') || HttpStatus.NOT_FOUND
- 'empty path' | '' | new IllegalStateException() || HttpStatus.NOT_IMPLEMENTED
+ scenario | xpath | exception || httpStatus
+ 'no dataspace' | '/x-path' | new DataspaceNotFoundException('') || HttpStatus.BAD_REQUEST
+ 'no anchor' | '/x-path' | new AnchorNotFoundException('', '') || HttpStatus.BAD_REQUEST
+ 'no data' | '/x-path' | new DataNodeNotFoundException('', '', '') || HttpStatus.NOT_FOUND
+ 'empty path' | '' | new IllegalStateException() || HttpStatus.NOT_IMPLEMENTED
+ 'already defined' | '/x-path' | new AlreadyDefinedException('', '') || HttpStatus.CONFLICT
}
@Unroll
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 fb4037271b..30d5b62a26 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
@@ -33,14 +33,13 @@ import org.onap.cps.api.CpsAdminService
import org.onap.cps.api.CpsDataService
import org.onap.cps.api.CpsModuleService
import org.onap.cps.api.CpsQueryService
-import org.onap.cps.spi.exceptions.AnchorAlreadyDefinedException
+import org.onap.cps.spi.exceptions.AlreadyDefinedException
import org.onap.cps.spi.exceptions.CpsException
import org.onap.cps.spi.exceptions.CpsPathException
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
@@ -112,20 +111,14 @@ class CpsRestExceptionHandlerSpec extends Specification {
'Description does not exist in dataspace MyDataSpace.')
}
- @Unroll
- def 'request with an expectedObjectTypeInMessage object already defined exception returns HTTP Status Bad Request'() {
- when: 'no data found CPS exception is thrown by the service'
- setupTestException(exceptionThrown)
+ def 'Request with an object already defined exception returns HTTP Status Conflict.'() {
+ when: 'AlreadyDefinedException exception is thrown by the service'
+ setupTestException(new AlreadyDefinedException("Anchor", existingObjectName, dataspaceName, new Throwable()))
def response = performTestRequest()
- then: 'an HTTP Bad Request response is returned with correct message an details'
- assertTestResponse(response, BAD_REQUEST,
- "Duplicate ${expectedObjectTypeInMessage}",
- "${expectedObjectTypeInMessage} with name ${existingObjectName} " +
- 'already exists for dataspace MyDataSpace.')
- where: 'the following exceptions are thrown'
- exceptionThrown || expectedObjectTypeInMessage
- new SchemaSetAlreadyDefinedException(dataspaceName, existingObjectName, null) || 'Schema Set'
- new AnchorAlreadyDefinedException(dataspaceName, existingObjectName, null) || 'Anchor'
+ then: 'a HTTP conflict response is returned with correct message an details'
+ assertTestResponse(response, CONFLICT,
+ "Already defined exception",
+ "Anchor with name ${existingObjectName} already exists for ${dataspaceName}.")
}
@Unroll