Internal Server Error when creating the same data node twice
[cps.git] / cps-rest / src / test / groovy / org / onap / cps / rest / exceptions / CpsRestExceptionHandlerSpec.groovy
index fb40372..30d5b62 100644 (file)
@@ -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