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/exceptions/CpsRestExceptionHandlerSpec.groovy20
1 files changed, 2 insertions, 18 deletions
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 05bd41d305..fb4037271b 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
@@ -86,33 +86,27 @@ class CpsRestExceptionHandlerSpec extends Specification {
def 'Get request with runtime exception returns HTTP Status Internal Server Error'() {
-
when: 'runtime exception is thrown by the service'
setupTestException(new IllegalStateException(errorMessage))
def response = performTestRequest()
-
then: 'an HTTP Internal Server Error response is returned with correct message and details'
assertTestResponse(response, INTERNAL_SERVER_ERROR, errorMessage, null)
}
def 'Get request with generic CPS exception returns HTTP Status Internal Server Error'() {
-
when: 'generic CPS exception is thrown by the service'
setupTestException(new CpsException(errorMessage, errorDetails))
def response = performTestRequest()
-
then: 'an HTTP Internal Server Error response is returned with correct message and details'
assertTestResponse(response, INTERNAL_SERVER_ERROR, errorMessage, errorDetails)
}
def 'Get request with no data found CPS exception returns HTTP Status Not Found'() {
-
when: 'no data found CPS exception is thrown by the service'
def dataspaceName = 'MyDataSpace'
def descriptionOfObject = 'Description'
setupTestException(new NotFoundInDataspaceException(dataspaceName, descriptionOfObject))
def response = performTestRequest()
-
then: 'an HTTP Not Found response is returned with correct message and details'
assertTestResponse(response, NOT_FOUND, 'Object not found',
'Description does not exist in dataspace MyDataSpace.')
@@ -120,11 +114,9 @@ class CpsRestExceptionHandlerSpec extends Specification {
@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 response = performTestRequest()
-
then: 'an HTTP Bad Request response is returned with correct message an details'
assertTestResponse(response, BAD_REQUEST,
"Duplicate ${expectedObjectTypeInMessage}",
@@ -138,14 +130,11 @@ class CpsRestExceptionHandlerSpec extends Specification {
@Unroll
def 'Get request with a #exceptionThrown.class.simpleName returns HTTP Status Bad Request'() {
-
when: 'CPS validation exception is thrown by the service'
setupTestException(exceptionThrown)
def response = performTestRequest()
-
then: 'an HTTP Bad Request response is returned with correct message and details'
assertTestResponse(response, BAD_REQUEST, errorMessage, errorDetails)
-
where: 'the following exceptions are thrown'
exceptionThrown << [new ModelValidationException(errorMessage, errorDetails, null),
new DataValidationException(errorMessage, errorDetails, null),
@@ -154,24 +143,20 @@ class CpsRestExceptionHandlerSpec extends Specification {
@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
+ * NB. The test uses 'get anchors' endpoint and associated service method invocation
* to test the exception handling. The endpoint chosen is not a subject of test.
*/
-
def setupTestException(exception) {
mockCpsAdminService.getAnchors(_) >> { throw exception }
}
@@ -182,8 +167,7 @@ class CpsRestExceptionHandlerSpec extends Specification {
.andReturn().response
}
- void assertTestResponse(response, expectedStatus,
- expectedErrorMessage, expectedErrorDetails) {
+ static void assertTestResponse(response, expectedStatus, expectedErrorMessage, expectedErrorDetails) {
assert response.status == expectedStatus.value()
def content = new JsonSlurper().parseText(response.contentAsString)
assert content['status'] == expectedStatus.toString()