Internal Server Error when creating the same data node twice
[cps.git] / cps-service / src / test / groovy / org / onap / cps / spi / exceptions / CpsExceptionsSpec.groovy
index 914a395..d2f43c9 100755 (executable)
@@ -27,21 +27,22 @@ class CpsExceptionsSpec extends Specification {
     def rootCause = new Throwable()
     def providedMessage = 'some message'
     def providedDetails = 'some details'
+    def xpath = 'some xpath'
 
     def 'Creating an exception that the Anchor already exist.'() {
         given: 'an exception dat the Anchor already exist is created'
-            def exception = new AnchorAlreadyDefinedException(dataspaceName, anchorName, rootCause)
+            def exception = new AlreadyDefinedException('Anchor', anchorName, dataspaceName, rootCause)
         expect: 'the exception details contains the correct message with Anchor name and Dataspace name'
-            exception.details == "Anchor with name ${anchorName} already exists for dataspace ${dataspaceName}."
+            exception.details == "Anchor with name ${anchorName} already exists for ${dataspaceName}."
         and: 'the correct root cause is maintained'
             exception.cause == rootCause
     }
 
     def 'Creating an exception that the dataspace already exists.'() {
         given: 'an exception that the dataspace already exists is created'
-            def exception = new DataspaceAlreadyDefinedException(dataspaceName, rootCause)
+            def exception = new AlreadyDefinedException(dataspaceName, rootCause)
         expect: 'the exception details contains the correct message with dataspace name'
-            exception.details == "Dataspace with name ${dataspaceName} already exists."
+            exception.details == "${dataspaceName} already exists."
         and: 'the correct root cause is maintained'
             exception.cause == rootCause
     }
@@ -52,7 +53,7 @@ class CpsExceptionsSpec extends Specification {
                     == "Dataspace with name ${dataspaceName} does not exist."
     }
 
-    def 'Creating a data validation exception.'() {
+    def 'Creating a data validation exception with root cause.'() {
         given: 'a data validation exception is created'
             def exception = new DataValidationException(providedMessage, providedDetails, rootCause)
         expect: 'the exception has the provided message'
@@ -63,6 +64,15 @@ class CpsExceptionsSpec extends Specification {
             exception.cause == rootCause
     }
 
+    def 'Creating a data validation exception.'() {
+        given: 'a data validation exception is created'
+            def exception = new DataValidationException(providedMessage, providedDetails)
+        expect: 'the exception has the provided message'
+            exception.message == providedMessage
+        and: 'the exception has the provided details'
+            exception.details == providedDetails
+    }
+
     def 'Creating a model validation exception.'() {
         given: 'a data validation exception is created'
             def exception = new ModelValidationException(providedMessage, providedDetails)
@@ -90,15 +100,6 @@ class CpsExceptionsSpec extends Specification {
                     == "${descriptionOfObject} does not exist in dataspace ${dataspaceName}."
     }
 
-    def 'Creating an exception that the schema set already exists.'() {
-        given: 'an exception that the schema set already exists is created'
-            def exception = new SchemaSetAlreadyDefinedException(dataspaceName, schemaSetName, rootCause)
-        expect: 'the exception details contains the correct message with dataspace and schema set names'
-            exception.details == "Schema Set with name ${schemaSetName} already exists for dataspace ${dataspaceName}."
-        and: 'the correct root cause is maintained'
-            exception.cause == rootCause
-    }
-
     def 'Creating a exception that a schema set cannot be found.'() {
         expect: 'the exception details contains the correct message with dataspace and schema set names'
             (new SchemaSetNotFoundException(dataspaceName, schemaSetName)).details
@@ -117,4 +118,43 @@ class CpsExceptionsSpec extends Specification {
                     == ("Schema Set with name ${schemaSetName} in dataspace ${dataspaceName} is having "
                     + "Anchor records associated.")
     }
+
+    def 'Creating a exception that a datanode does not exist.'() {
+        expect: 'the exception details contains the correct message with dataspace name and xpath.'
+            (new DataNodeNotFoundException(dataspaceName, anchorName, xpath)).details
+                    == "DataNode with xpath ${xpath} was not found for anchor ${anchorName} and dataspace ${dataspaceName}."
+    }
+
+    def 'Creating a exception that a dataspace already exists.'() {
+        expect: 'the exception details contains the correct message with dataspace name.'
+            (AlreadyDefinedException.forDataspace(dataspaceName, rootCause)).details
+                    == "${dataspaceName} already exists."
+    }
+
+    def 'Creating a exception that a anchor already exists.'() {
+        expect: 'the exception details contains the correct message with anchor name and dataspace name.'
+            (AlreadyDefinedException.forAnchor(anchorName, dataspaceName, rootCause)).details
+                    == "Anchor with name ${anchorName} already exists for ${dataspaceName}."
+    }
+
+    def 'Creating a exception that a data node already exists.'() {
+        expect: 'the exception details contains the correct message with xpath and dataspace name.'
+            (AlreadyDefinedException.forDataNode(xpath, dataspaceName, rootCause)).details
+                    == "Data node with name ${xpath} already exists for ${dataspaceName}."
+    }
+
+    def 'Creating a exception that a schema set already exists.'() {
+        expect: 'the exception details contains the correct message with schema set and dataspace name.'
+            (AlreadyDefinedException.forSchemaSet(schemaSetName, dataspaceName, rootCause)).details
+                    == "Schema Set with name ${schemaSetName} already exists for ${dataspaceName}."
+    }
+
+    def 'Creating a cps path exception.'() {
+        given: 'a cps path exception is created'
+            def exception = new CpsPathException(providedMessage, providedDetails)
+        expect: 'the exception has the provided message'
+            exception.message == providedMessage
+        and: 'the exception has the provided details'
+            exception.details == providedDetails
+    }
 }
\ No newline at end of file