+ objectUnderTest.getAnchors('someDataspace') == anchors
+ }
+
+ def 'Retrieve all anchors with an invalid dataspace name.'() {
+ when: 'get anchors is invoked with an invalid dataspace name'
+ objectUnderTest.getAnchors('Dataspace name with spaces')
+ then: 'a data validation exception is thrown'
+ thrown(DataValidationException)
+ and: 'cps admin persistence get anchors is not invoked'
+ 0 * mockCpsAdminPersistenceService.getAnchors(_)
+ }
+
+ def 'Retrieve all anchors for schema-set.'() {
+ given: 'that anchor is associated with the dataspace and schemaset'
+ def anchors = [new Anchor()]
+ mockCpsAdminPersistenceService.getAnchors('someDataspace', 'someSchemaSet') >> anchors
+ expect: 'the collection provided by persistence service is returned as result'
+ objectUnderTest.getAnchors('someDataspace', 'someSchemaSet') == anchors
+ }
+ def 'Retrieve all anchors for schema-set with invalid #scenario.'() {
+ when: 'the collection provided by persistence service is returned as result'
+ objectUnderTest.getAnchors(dataspaceName, schemaSetName)
+ then: 'a data validation exception is thrown'
+ thrown(DataValidationException)
+ and: 'cps admin persistence get anchors is not invoked'
+ 0 * mockCpsAdminPersistenceService.getAnchors(_, _)
+ where: 'the following parameters are used'
+ scenario | dataspaceName | schemaSetName
+ 'dataspace name' | 'dataspace names with spaces' | 'schemaSetName'
+ 'schema set name' | 'dataspaceName' | 'schema set name with spaces'
+ 'dataspace and schema set name' | 'dataspace name with spaces' | 'schema set name with spaces'
+ }
+
+
+ def 'Retrieve anchor for dataspace and provided anchor name.'() {
+ given: 'that anchor name is associated with the dataspace'
+ Anchor anchor = new Anchor()
+ mockCpsAdminPersistenceService.getAnchor('someDataspace','someAnchor') >> anchor
+ expect: 'the anchor provided by persistence service is returned as result'
+ assert objectUnderTest.getAnchor('someDataspace','someAnchor') == anchor
+ }
+
+ def 'Retrieve anchor with invalid #scenario.'() {
+ when: 'get anchors is invoked with an invalid dataspace name'
+ objectUnderTest.getAnchor(dataspaceName, anchorName)
+ then: 'a data validation exception is thrown'
+ thrown(DataValidationException)
+ and: 'cps admin persistence get anchor is not invoked'
+ 0 * mockCpsAdminPersistenceService.getAnchor(_, _)
+ where: 'the following parameters are used'
+ scenario | dataspaceName | anchorName
+ 'dataspace name' | 'dataspace names with spaces' | 'anchorName'
+ 'anchor name' | 'dataspaceName' | 'anchor name with spaces'
+ 'dataspace and anchor name' | 'dataspace name with spaces' | 'anchor name with spaces'
+ }
+
+ def 'Delete anchor.'() {
+ when: 'delete anchor is invoked'
+ objectUnderTest.deleteAnchor('someDataspace','someAnchor')
+ then: 'delete data nodes is invoked on the data service with expected parameters'
+ 1 * mockCpsDataService.deleteDataNodes('someDataspace','someAnchor', _ as OffsetDateTime )
+ and: 'the persistence service method is invoked with same parameters to delete anchor'
+ 1 * mockCpsAdminPersistenceService.deleteAnchor('someDataspace','someAnchor')
+ }
+
+ def 'Delete anchor with invalid #scenario.'() {
+ when: 'delete anchor is invoked'
+ objectUnderTest.deleteAnchor(dataspaceName, anchorName)
+ then: 'a data validation exception is thrown'
+ thrown(DataValidationException)
+ and: 'delete data nodes is invoked on the data service with expected parameters'
+ 0 * mockCpsDataService.deleteDataNodes(_,_, _ as OffsetDateTime )
+ and: 'the persistence service method is invoked with same parameters to delete anchor'
+ 0 * mockCpsAdminPersistenceService.deleteAnchor(_,_)
+ where: 'the following parameters are used'
+ scenario | dataspaceName | anchorName
+ 'dataspace name' | 'dataspace names with spaces' | 'anchorName'
+ 'anchor name' | 'dataspaceName' | 'anchor name with spaces'
+ 'dataspace and anchor name' | 'dataspace name with spaces' | 'anchor name with spaces'