summaryrefslogtreecommitdiffstats
path: root/cps-service/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'cps-service/src/test')
-rw-r--r--cps-service/src/test/groovy/org/onap/cps/api/impl/CpsAdminServiceImplSpec.groovy43
1 files changed, 9 insertions, 34 deletions
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
index d31a2f72d2..9e13c771d3 100644
--- 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
@@ -21,55 +21,30 @@
package org.onap.cps.api.impl
import org.onap.cps.spi.CpsAdminPersistenceService
-import org.onap.cps.spi.exceptions.DataspaceNotFoundException
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 anchor method invokes persistence service'() {
+ when: 'Create anchor method is invoked'
+ objectUnderTest.createAnchor('dummyDataspace', 'dummySchemaSet', 'dummyAnchorName')
+ then: 'The persistence service method is invoked with same parameters'
+ 1 * mockCpsAdminPersistenceService.createAnchor('dummyDataspace', 'dummySchemaSet', 'dummyAnchorName')
}
- 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
- }
-
- def 'Retrieve all anchors for an existing dataspace'() {
- given: 'that the dataspace exist and an anchor is associated with the dataspace'
- Collection<Anchor> anchorCollection = Arrays.asList(anchor)
+ def 'Retrieve all anchors for dataspace'() {
+ given: 'that anchor is associated with the dataspace'
+ Collection<Anchor> anchorCollection = Arrays.asList(new Anchor())
mockCpsAdminPersistenceService.getAnchors('dummyDataspace') >> { anchorCollection }
- expect: 'we try to retrieve an anchor, a collection of anchor is returned by the service'
+ expect: 'the collection provided by persistence service is returned as result'
objectUnderTest.getAnchors('dummyDataspace') == anchorCollection
}
- def 'Retrieve all anchors for a non existing dataspace'() {
- given: 'that the dataspace does not exist, service throws an exception'
- def exceptionThrownInPersistenceLayer = new DataspaceNotFoundException(_ as String)
- mockCpsAdminPersistenceService.getAnchors('dummyDataspace') >>
- { throw exceptionThrownInPersistenceLayer }
- when: 'we try to retrieve a anchor with a non-existant dataspace'
- objectUnderTest.getAnchors('dummyDataspace')
- then: 'the same exception is thrown by CPS'
- def exceptionThrownInServiceLayer = thrown(Exception)
- exceptionThrownInServiceLayer == exceptionThrownInPersistenceLayer
- }
}