aboutsummaryrefslogtreecommitdiffstats
path: root/cps-service/src
diff options
context:
space:
mode:
Diffstat (limited to 'cps-service/src')
-rw-r--r--cps-service/src/main/java/org/onap/cps/api/CpsModuleService.java14
-rw-r--r--cps-service/src/main/java/org/onap/cps/api/impl/CpsModuleServiceImpl.java8
-rw-r--r--cps-service/src/test/groovy/org/onap/cps/api/impl/CpsModuleServiceImplSpec.groovy19
3 files changed, 40 insertions, 1 deletions
diff --git a/cps-service/src/main/java/org/onap/cps/api/CpsModuleService.java b/cps-service/src/main/java/org/onap/cps/api/CpsModuleService.java
index 5f63f97f1e..75c6a78637 100644
--- a/cps-service/src/main/java/org/onap/cps/api/CpsModuleService.java
+++ b/cps-service/src/main/java/org/onap/cps/api/CpsModuleService.java
@@ -21,6 +21,8 @@ package org.onap.cps.api;
import java.util.Map;
import org.checkerframework.checker.nullness.qual.NonNull;
+import org.onap.cps.spi.CascadeDeleteAllowed;
+import org.onap.cps.spi.exceptions.DataInUseException;
import org.onap.cps.spi.model.SchemaSet;
/**
@@ -47,4 +49,16 @@ public interface CpsModuleService {
* @return a SchemaSet
*/
SchemaSet getSchemaSet(@NonNull String dataspaceName, @NonNull String schemaSetName);
+
+ /**
+ * Deletes Schema Set.
+ *
+ * @param dataspaceName dataspace name
+ * @param schemaSetName schema set name
+ * @param cascadeDeleteAllowed indicates the allowance to remove associated anchors and data if exist
+ * @throws DataInUseException if cascadeDeleteAllowed is set to CASCADE_DELETE_PROHIBITED and there
+ * is associated anchor record exists in database
+ */
+ void deleteSchemaSet(@NonNull String dataspaceName, @NonNull String schemaSetName,
+ @NonNull CascadeDeleteAllowed cascadeDeleteAllowed);
}
diff --git a/cps-service/src/main/java/org/onap/cps/api/impl/CpsModuleServiceImpl.java b/cps-service/src/main/java/org/onap/cps/api/impl/CpsModuleServiceImpl.java
index 04a6fe1cee..eac28a9f09 100644
--- a/cps-service/src/main/java/org/onap/cps/api/impl/CpsModuleServiceImpl.java
+++ b/cps-service/src/main/java/org/onap/cps/api/impl/CpsModuleServiceImpl.java
@@ -20,7 +20,9 @@
package org.onap.cps.api.impl;
import java.util.Map;
+import org.checkerframework.checker.nullness.qual.NonNull;
import org.onap.cps.api.CpsModuleService;
+import org.onap.cps.spi.CascadeDeleteAllowed;
import org.onap.cps.spi.CpsModulePersistenceService;
import org.onap.cps.spi.model.SchemaSet;
import org.onap.cps.yang.YangTextSchemaSourceSet;
@@ -55,4 +57,10 @@ public class CpsModuleServiceImpl implements CpsModuleService {
.moduleReferences(yangTextSchemaSourceSet.getModuleReferences())
.build();
}
+
+ @Override
+ public void deleteSchemaSet(final String dataspaceName, final String schemaSetName,
+ final CascadeDeleteAllowed cascadeDeleteAllowed) {
+ cpsModulePersistenceService.deleteSchemaSet(dataspaceName, schemaSetName, cascadeDeleteAllowed);
+ }
}
diff --git a/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsModuleServiceImplSpec.groovy b/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsModuleServiceImplSpec.groovy
index ebe4fe7bce..f380d106c7 100644
--- a/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsModuleServiceImplSpec.groovy
+++ b/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsModuleServiceImplSpec.groovy
@@ -21,10 +21,15 @@
package org.onap.cps.api.impl
import org.onap.cps.TestUtils
+import org.onap.cps.spi.CascadeDeleteAllowed
import org.onap.cps.spi.CpsModulePersistenceService;
import org.onap.cps.spi.exceptions.ModelValidationException
import org.onap.cps.spi.model.ModuleReference
import spock.lang.Specification
+import spock.lang.Unroll
+
+import static org.onap.cps.spi.CascadeDeleteAllowed.CASCADE_DELETE_ALLOWED
+import static org.onap.cps.spi.CascadeDeleteAllowed.CASCADE_DELETE_PROHIBITED
class CpsModuleServiceImplSpec extends Specification {
def mockModuleStoreService = Mock(CpsModulePersistenceService)
@@ -52,7 +57,7 @@ class CpsModuleServiceImplSpec extends Specification {
thrown(ModelValidationException.class)
}
- def 'Get schema set by name and namespace.'() {
+ def 'Get schema set by name and dataspace.'() {
given: 'an already present schema set'
def yangResourcesNameToContentMap = TestUtils.getYangResourcesAsMap('bookstore.yang')
mockModuleStoreService.getYangSchemaResources('someDataspace', 'someSchemaSet') >> yangResourcesNameToContentMap
@@ -63,4 +68,16 @@ class CpsModuleServiceImplSpec extends Specification {
result.getDataspaceName().contains('someDataspace')
result.getModuleReferences().contains(new ModuleReference('stores', 'org:onap:ccsdk:sample', '2020-09-15'))
}
+
+ @Unroll
+ 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
+ }
}