aboutsummaryrefslogtreecommitdiffstats
path: root/cps-service/src/test/groovy
diff options
context:
space:
mode:
authorniamhcore <niamh.core@est.tech>2021-03-15 15:54:12 +0000
committerNiamh Core <niamh.core@est.tech>2021-03-24 09:19:24 +0000
commit63be201ed60ca0d0b16ebe5a1a9d3a8e3f7b8482 (patch)
tree91b34d99cf07d0d599801ea4d60ecfdbe46760ff /cps-service/src/test/groovy
parent840eecbf7210d0433d94da895a3a11b97d3a4e6f (diff)
Internal Server Error when creating the same data node twice
This change adds a generic exception handler class for a already defined object and handles a JsonSyntaxException. Issue-ID: CPS-290 Signed-off-by: niamhcore <niamh.core@est.tech> Change-Id: Ie645237b5dd5b8e2b1d074c5613e7da560f57484
Diffstat (limited to 'cps-service/src/test/groovy')
-rwxr-xr-xcps-service/src/test/groovy/org/onap/cps/spi/exceptions/CpsExceptionsSpec.groovy41
-rw-r--r--cps-service/src/test/groovy/org/onap/cps/utils/YangUtilsSpec.groovy1
2 files changed, 29 insertions, 13 deletions
diff --git a/cps-service/src/test/groovy/org/onap/cps/spi/exceptions/CpsExceptionsSpec.groovy b/cps-service/src/test/groovy/org/onap/cps/spi/exceptions/CpsExceptionsSpec.groovy
index a4a13ff4c9..d2f43c9362 100755
--- a/cps-service/src/test/groovy/org/onap/cps/spi/exceptions/CpsExceptionsSpec.groovy
+++ b/cps-service/src/test/groovy/org/onap/cps/spi/exceptions/CpsExceptionsSpec.groovy
@@ -31,18 +31,18 @@ class CpsExceptionsSpec extends Specification {
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
}
@@ -100,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
@@ -134,6 +125,30 @@ class CpsExceptionsSpec extends Specification {
== "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)
diff --git a/cps-service/src/test/groovy/org/onap/cps/utils/YangUtilsSpec.groovy b/cps-service/src/test/groovy/org/onap/cps/utils/YangUtilsSpec.groovy
index 826cdd8c71..0b00cbb835 100644
--- a/cps-service/src/test/groovy/org/onap/cps/utils/YangUtilsSpec.groovy
+++ b/cps-service/src/test/groovy/org/onap/cps/utils/YangUtilsSpec.groovy
@@ -54,6 +54,7 @@ class YangUtilsSpec extends Specification {
invalidJson | description
'{incomplete json' | 'incomplete json'
'{"test:bookstore": {"address": "Parnell st." }}' | 'json with un-modelled data'
+ '{" }' | 'json with syntax exception'
}
@Unroll