2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2021 Nordix Foundation
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 * SPDX-License-Identifier: Apache-2.0
17 * ============LICENSE_END=========================================================
19 package org.onap.cps.spi.exceptions
21 import spock.lang.Specification
23 class CpsExceptionsSpec extends Specification {
24 def dataspaceName = 'some data space'
25 def anchorName = 'some anchor'
26 def schemaSetName = 'some schema set'
27 def rootCause = new Throwable()
28 def providedMessage = 'some message'
29 def providedDetails = 'some details'
31 def 'Creating an exception that the Anchor already exist.'() {
32 given: 'an exception dat the Anchor already exist is created'
33 def exception = new AnchorAlreadyDefinedException(dataspaceName, anchorName, rootCause)
34 expect: 'the exception details contains the correct message with Anchor name and Dataspace name'
35 exception.details == "Anchor with name ${anchorName} already exists for dataspace ${dataspaceName}."
36 and: 'the correct root cause is maintained'
37 exception.cause == rootCause
40 def 'Creating an exception that the dataspace already exists.'() {
41 given: 'an exception that the dataspace already exists is created'
42 def exception = new DataspaceAlreadyDefinedException(dataspaceName, rootCause)
43 expect: 'the exception details contains the correct message with dataspace name'
44 exception.details == "Dataspace with name ${dataspaceName} already exists."
45 and: 'the correct root cause is maintained'
46 exception.cause == rootCause
49 def 'Creating a exception that a dataspace is not found.'() {
50 expect: 'the exception details contains the correct message with dataspace name'
51 (new DataspaceNotFoundException(dataspaceName)).details
52 == "Dataspace with name ${dataspaceName} does not exist."
55 def'Creating a data validation exception.'() {
56 given: 'a data validation exception is created'
57 def exception = new DataValidationException(providedMessage, providedDetails, rootCause)
58 expect: 'the exception has the provided message'
59 exception.message == providedMessage
60 and: 'the exception has the provided details'
61 exception.details == providedDetails
62 and: 'the correct root cause is maintained'
63 exception.cause == rootCause
66 def'Creating a model validation exception.'() {
67 given: 'a data validation exception is created'
68 def exception = new ModelValidationException(providedMessage, providedDetails)
69 expect: 'the exception has the provided message'
70 exception.message == providedMessage
71 and: 'the exception has the provided details'
72 exception.details == providedDetails
75 def 'Creating a model validation exception with a root cause.'() {
76 given: 'a model validation exception is created'
77 def exception = new ModelValidationException(providedMessage, providedDetails, rootCause)
78 expect: 'the exception has the provided message'
79 exception.message == providedMessage
80 and: 'the exception has the provided details'
81 exception.details == providedDetails
82 and: 'the correct root cause is maintained'
83 exception.cause == rootCause
86 def 'Creating a exception for an object not found in a dataspace.'() {
87 def descriptionOfObject = 'some object'
88 expect: 'the exception details contains the correct message with dataspace name and description of the object'
89 (new NotFoundInDataspaceException(dataspaceName,descriptionOfObject)).details
90 == "${descriptionOfObject} does not exist in dataspace ${dataspaceName}."
93 def 'Creating an exception that the schema set already exists.'() {
94 given: 'an exception that the schema set already exists is created'
95 def exception = new SchemaSetAlreadyDefinedException(dataspaceName, schemaSetName, rootCause)
96 expect: 'the exception details contains the correct message with dataspace and schema set names'
97 exception.details == "Schema Set with name ${schemaSetName} already exists for dataspace ${dataspaceName}."
98 and: 'the correct root cause is maintained'
99 exception.cause == rootCause
102 def 'Creating a exception that a schema set cannot be found.'() {
103 expect: 'the exception details contains the correct message with dataspace and schema set names'
104 (new SchemaSetNotFoundException(dataspaceName,schemaSetName)).details
105 == "Schema Set with name ${schemaSetName} was not found for dataspace ${dataspaceName}."