summaryrefslogtreecommitdiffstats
path: root/cps-service/src/test/groovy
diff options
context:
space:
mode:
authorToineSiebelink <toine.siebelink@est.tech>2020-12-08 12:08:31 +0000
committerToineSiebelink <toine.siebelink@est.tech>2020-12-10 10:11:53 +0000
commit098a93c84aae8d8d74e7589518a576b84c38ca27 (patch)
tree97ef75d4be28415dbc71d093db1d8d27d6ac3f4c /cps-service/src/test/groovy
parent9647834359b168ed8091cecaecd363cb87abe874 (diff)
Improve CPS Exception handling
- Removing unnecessary level of CPS(Validation)Exception - Moved exception inside spi package - Rename exceptions are per agreed new exception hierarchy - Use new exceptions - Added SchemaSetAlreadDefined Exception - Added AnchorAlreadyDefined Exception - Ensure unique serialVersionUIDs - Fixed CpsAdmin(Persistence)ServiceImplSpec tests (there was a mix-up about what this class was testing) - Replaced exception builder with dedicated exception (constructors) Issue-ID: CPS-8 Change-Id: I9cb80af4951e69ee7b0e99303853955de9d4399f Signed-off-by: ToineSiebelink <toine.siebelink@est.tech>
Diffstat (limited to 'cps-service/src/test/groovy')
-rw-r--r--cps-service/src/test/groovy/org/onap/cps/api/impl/CpsAdminPersistenceServiceImplSpec.groovy86
-rw-r--r--cps-service/src/test/groovy/org/onap/cps/api/impl/CpsAdminServiceImplSpec.groovy55
-rw-r--r--cps-service/src/test/groovy/org/onap/cps/api/impl/CpsModulePersistenceServiceImplSpec.groovy4
3 files changed, 57 insertions, 88 deletions
diff --git a/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsAdminPersistenceServiceImplSpec.groovy b/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsAdminPersistenceServiceImplSpec.groovy
deleted file mode 100644
index 465badd0c2..0000000000
--- a/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsAdminPersistenceServiceImplSpec.groovy
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * Copyright (C) 2020 Nordix Foundation
- * Modifications Copyright (C) 2020 Bell Canada. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.cps.api.impl
-
-import org.onap.cps.exceptions.CpsValidationException
-import org.onap.cps.spi.CpsAdminPersistenceService
-import org.onap.cps.spi.model.Anchor
-import spock.lang.Specification
-
-class CpsAdminPersistenceServiceImplSpec extends Specification {
- def mockCpsAdminService = Mock(CpsAdminPersistenceService)
- def objectUnderTest = new CpsAdminServiceImpl()
-
- def setup() {
- objectUnderTest.cpsAdminPersistenceService = mockCpsAdminService
- }
-
- def 'Create an anchor with a non-existant dataspace'() {
- given: 'that the dataspace does not exist service throws an exception'
- Anchor anchor = new Anchor()
- anchor.setDataspaceName('dummyDataspace')
- mockCpsAdminService.createAnchor(anchor) >> { throw new CpsValidationException(_ as String, _ as String) }
- when: 'we try to create a anchor with a non-existant dataspace'
- objectUnderTest.createAnchor(anchor)
- then: 'the same exception is thrown by CPS'
- thrown(CpsValidationException)
- }
-
- def 'Create an anchor with invalid dataspace, namespace and revision'() {
- given: 'that the dataspace, namespace and revison combination does not exist service throws an exception'
- Anchor anchor = new Anchor()
- anchor.setDataspaceName('dummyDataspace')
- anchor.setNamespace('dummyNamespace')
- anchor.setRevision('dummyRevision')
- mockCpsAdminService.createAnchor(anchor) >> { throw new CpsValidationException(_ as String, _ as String) }
- when: 'we try to create a anchor with a non-existant dataspace, namespace and revison combination'
- objectUnderTest.createAnchor(anchor)
- then: 'the same exception is thrown by CPS'
- thrown(CpsValidationException)
- }
-
- def 'Create a duplicate anchor'() {
- given: 'that the anchor already exist service throws an exception'
- Anchor anchor = new Anchor()
- anchor.setDataspaceName('dummyDataspace')
- anchor.setNamespace('dummyNamespace')
- anchor.setRevision('dummyRevision')
- anchor.setRevision('dummyAnchorName')
- mockCpsAdminService.createAnchor(anchor) >> { throw new CpsValidationException(_ as String, _ as String) }
- when: 'we try to create a duplicate anchor'
- objectUnderTest.createAnchor(anchor)
- then: 'the same exception is thrown by CPS'
- thrown(CpsValidationException)
- }
-
- def 'Create an anchor with supplied anchor name, dataspace, namespace and revision'() {
- given: 'that the anchor does not pre-exist service creates an anchor'
- Anchor anchor = new Anchor()
- anchor.setDataspaceName('dummyDataspace')
- anchor.setNamespace('dummyNamespace')
- anchor.setRevision('dummyRevision')
- anchor.setRevision('dummyAnchorName')
- mockCpsAdminService.createAnchor(anchor) >> 'dummyAnchorName'
- expect: 'anchor name is returned by service'
- objectUnderTest.createAnchor(anchor) == 'dummyAnchorName'
- }
-
-}
diff --git a/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsAdminServiceImplSpec.groovy b/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsAdminServiceImplSpec.groovy
new file mode 100644
index 0000000000..65a8e71bca
--- /dev/null
+++ b/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsAdminServiceImplSpec.groovy
@@ -0,0 +1,55 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020 Nordix Foundation
+ * Modifications Copyright (C) 2020 Bell Canada. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.cps.api.impl
+
+
+import org.onap.cps.spi.CpsAdminPersistenceService
+import org.onap.cps.spi.model.Anchor
+import spock.lang.Specification
+
+class CpsAdminServiceImplSpec extends Specification {
+ def mockCpsAdminPersistenceService = Mock(CpsAdminPersistenceService)
+ def objectUnderTest = new CpsAdminServiceImpl()
+ def anchor = new Anchor()
+
+ def setup() {
+ objectUnderTest.cpsAdminPersistenceService = mockCpsAdminPersistenceService
+ }
+
+ def 'Create an anchor'() {
+ given: 'that the persistence service returns the name of the anchor'
+ def anchorName = 'some anchor name'
+ mockCpsAdminPersistenceService.createAnchor(_) >> anchorName
+ expect: 'the same anchor name is returned by CPS Admin service'
+ objectUnderTest.createAnchor(anchor) == anchorName
+ }
+
+ def 'Create an anchor with some exception in the persistence layer'() {
+ given: 'that the persistence service throws some exception'
+ def exceptionThrownInPersistenceLayer = new RuntimeException()
+ mockCpsAdminPersistenceService.createAnchor(_) >> { throw exceptionThrownInPersistenceLayer }
+ when: 'we try to create an anchor'
+ objectUnderTest.createAnchor(anchor)
+ then: 'the same exception is thrown by the CPS Admin Service'
+ def exceptionThrownInServiceLayer = thrown(Exception)
+ exceptionThrownInServiceLayer == exceptionThrownInPersistenceLayer
+ }
+}
diff --git a/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsModulePersistenceServiceImplSpec.groovy b/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsModulePersistenceServiceImplSpec.groovy
index 79b981b2a2..da2df404eb 100644
--- a/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsModulePersistenceServiceImplSpec.groovy
+++ b/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsModulePersistenceServiceImplSpec.groovy
@@ -21,8 +21,8 @@
package org.onap.cps.api.impl
import org.onap.cps.TestUtils
-import org.onap.cps.exceptions.CpsValidationException
import org.onap.cps.spi.CpsModulePersistenceService
+import org.onap.cps.spi.exceptions.CpsException
import org.opendaylight.yangtools.yang.common.Revision
import org.opendaylight.yangtools.yang.model.api.SchemaContext
import spock.lang.Specification
@@ -65,7 +65,7 @@ class CpsModulePersistenceServiceImplSpec extends Specification {
when: 'the model is parsed and validated'
objectUnderTest.parseAndValidateModel(file)
then: 'a CpsValidationException is thrown'
- thrown(CpsValidationException)
+ thrown(CpsException)
}
def 'Store a SchemaContext'() {