aboutsummaryrefslogtreecommitdiffstats
path: root/cps-service/src/test
diff options
context:
space:
mode:
authorRishi.Chail <rishi.chail@est.tech>2020-11-09 03:28:44 +0000
committerRishi.Chail <rishi.chail@est.tech>2020-11-18 13:30:01 +0000
commit48830f146f6776afa180fefa101788b169bc841a (patch)
tree6154165d4a3d8f464511c39544cf62d0923964a3 /cps-service/src/test
parente40f4d2dce4c4adf57b99c3daf524b14204279b9 (diff)
VSE: Create an anchor in the given dataspace
Issue-ID: CPS-42 https://jira.onap.org/browse/CPS-42 Signed-off-by: Rishi Chail <rishi.chail@est.tech> Change-Id: If67be6f13889808da4d9fe830595766af67e4fdf
Diffstat (limited to 'cps-service/src/test')
-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