- def 'Delete set by name and dataspace with #cascadeDeleteOption.'() {
- when: 'schema set deletion is requested'
- objectUnderTest.deleteSchemaSet(dataspaceName, schemaSetname, cascadeDeleteOption)
- then: 'persistence service method is invoked with same parameters'
- mockModuleStoreService.deleteSchemaSet(dataspaceName, schemaSetname, cascadeDeleteOption)
- where: 'following parameters are used'
- dataspaceName | schemaSetname | cascadeDeleteOption
- 'dataspace-1' | 'schemas-set-1' | CASCADE_DELETE_ALLOWED
- 'dataspace-2' | 'schemas-set-2' | CASCADE_DELETE_PROHIBITED
+ def 'Delete schema-set when cascade is prohibited.'() {
+ given: 'no anchors are associated with schemaset'
+ mockCpsAdminService.getAnchors('my-dataspace', 'my-schemaset') >> Collections.emptyList()
+ when: 'schema set deletion is requested with cascade allowed'
+ objectUnderTest.deleteSchemaSet('my-dataspace', 'my-schemaset', CASCADE_DELETE_PROHIBITED)
+ then: 'no anchors are deleted'
+ 0 * mockCpsAdminService.deleteAnchor(_, _)
+ and: 'persistence service method is invoked with same parameters'
+ 1 * mockModuleStoreService.deleteSchemaSet('my-dataspace', 'my-schemaset')
+ and: 'schema set will be removed from the cache'
+ 1 * mockYangTextSchemaSourceSetCache.removeFromCache('my-dataspace', 'my-schemaset')
+ and: 'orphan yang resources are deleted'
+ 1 * mockModuleStoreService.deleteUnusedYangResourceModules()
+ }
+
+ def 'Delete schema-set when cascade is prohibited and schema-set has anchors.'() {
+ given: '2 anchors are associated with schemaset'
+ mockCpsAdminService.getAnchors('my-dataspace', 'my-schemaset') >> createAnchors(2)
+ when: 'schema set deletion is requested with cascade allowed'
+ objectUnderTest.deleteSchemaSet('my-dataspace', 'my-schemaset', CASCADE_DELETE_PROHIBITED)
+ then: 'Schema-Set in Use exception is thrown'
+ thrown(SchemaSetInUseException)