summaryrefslogtreecommitdiffstats
path: root/cps-service/src/test/groovy
diff options
context:
space:
mode:
Diffstat (limited to 'cps-service/src/test/groovy')
-rwxr-xr-x[-rw-r--r--]cps-service/src/test/groovy/org/onap/cps/api/impl/CpServiceImplSpec.groovy55
1 files changed, 55 insertions, 0 deletions
diff --git a/cps-service/src/test/groovy/org/onap/cps/api/impl/CpServiceImplSpec.groovy b/cps-service/src/test/groovy/org/onap/cps/api/impl/CpServiceImplSpec.groovy
index 5f42810bd5..3c51cca597 100644..100755
--- a/cps-service/src/test/groovy/org/onap/cps/api/impl/CpServiceImplSpec.groovy
+++ b/cps-service/src/test/groovy/org/onap/cps/api/impl/CpServiceImplSpec.groovy
@@ -21,8 +21,11 @@
package org.onap.cps.api.impl
import org.onap.cps.TestUtils
+import org.onap.cps.api.model.AnchorDetails
+import org.onap.cps.exceptions.CpsNotFoundException
import org.onap.cps.exceptions.CpsValidationException
import org.onap.cps.spi.DataPersistencyService
+import org.onap.cps.spi.FragmentPersistenceService
import org.opendaylight.yangtools.yang.common.Revision
import org.opendaylight.yangtools.yang.model.api.SchemaContext
import spock.lang.Specification
@@ -30,10 +33,12 @@ import spock.lang.Specification
class CpServiceImplSpec extends Specification {
def mockDataPersistencyService = Mock(DataPersistencyService)
+ def mockFragmentPersistenceService = Mock(FragmentPersistenceService)
def objectUnderTest = new CpServiceImpl()
def setup() {
objectUnderTest.dataPersistencyService = mockDataPersistencyService
+ objectUnderTest.fragmentPersistenceService = mockFragmentPersistenceService
}
def 'Cps Service provides to its client the id assigned by the system when storing a data structure'() {
@@ -113,4 +118,54 @@ class CpServiceImplSpec extends Specification {
then: 'the same exception is thrown by CPS'
thrown(IllegalStateException)
}
+
+ def 'Create an anchor with a non-existant dataspace'(){
+ given: 'that the dataspace does not exist service throws an exception'
+ AnchorDetails anchorDetails = new AnchorDetails()
+ anchorDetails.setDataspace('dummyDataspace')
+ mockFragmentPersistenceService.createAnchor(anchorDetails) >> {throw new CpsValidationException(_ as String, _ as String)}
+ when: 'we try to create a anchor with a non-existant dataspace'
+ objectUnderTest.createAnchor(anchorDetails)
+ 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'
+ AnchorDetails anchorDetails = new AnchorDetails()
+ anchorDetails.setDataspace('dummyDataspace')
+ anchorDetails.setNamespace('dummyNamespace')
+ anchorDetails.setRevision('dummyRevision')
+ mockFragmentPersistenceService.createAnchor(anchorDetails) >> {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(anchorDetails)
+ 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'
+ AnchorDetails anchorDetails = new AnchorDetails()
+ anchorDetails.setDataspace('dummyDataspace')
+ anchorDetails.setNamespace('dummyNamespace')
+ anchorDetails.setRevision('dummyRevision')
+ anchorDetails.setRevision('dummyAnchorName')
+ mockFragmentPersistenceService.createAnchor(anchorDetails) >> {throw new CpsValidationException(_ as String, _ as String)}
+ when: 'we try to create a duplicate anchor'
+ objectUnderTest.createAnchor(anchorDetails)
+ 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'
+ AnchorDetails anchorDetails = new AnchorDetails()
+ anchorDetails.setDataspace('dummyDataspace')
+ anchorDetails.setNamespace('dummyNamespace')
+ anchorDetails.setRevision('dummyRevision')
+ anchorDetails.setRevision('dummyAnchorName')
+ mockFragmentPersistenceService.createAnchor(anchorDetails) >> 'dummyAnchorName'
+ expect: 'anchor name is returned by service'
+ objectUnderTest.createAnchor(anchorDetails) == 'dummyAnchorName'
+ }
} \ No newline at end of file