summaryrefslogtreecommitdiffstats
path: root/cps-ncmp-service/src/test/groovy/org
diff options
context:
space:
mode:
authorToine Siebelink <toine.siebelink@est.tech>2022-07-01 08:08:14 +0000
committerGerrit Code Review <gerrit@onap.org>2022-07-01 08:08:14 +0000
commitb93d6df7f4304580e0f2029cbd449ba863d1ef02 (patch)
treeaf89db00274084686b4e4d695aa7ad0afd48cc72 /cps-ncmp-service/src/test/groovy/org
parent79dc74fd69086cf9937ed06241fed9a2772b0fba (diff)
parent884a5a0e8bf08cc47e0e0dbd7e20558212ca82b1 (diff)
Merge "Allow Module Re-Sync"
Diffstat (limited to 'cps-ncmp-service/src/test/groovy/org')
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncServiceSpec.groovy44
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncWatchdogSpec.groovy (renamed from cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncSpec.groovy)4
2 files changed, 46 insertions, 2 deletions
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncServiceSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncServiceSpec.groovy
index f93b3a73e..6a2fbe8e7 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncServiceSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncServiceSpec.groovy
@@ -1,5 +1,5 @@
/*
- * ============LICENSE_START=======================================================
+ * ============LICENSE_START=======================================================
* Copyright (C) 2022 Nordix Foundation
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -24,7 +24,11 @@ import org.onap.cps.api.CpsAdminService
import org.onap.cps.api.CpsModuleService
import org.onap.cps.ncmp.api.impl.operations.DmiModelOperations
import org.onap.cps.ncmp.api.impl.yangmodels.YangModelCmHandle
+import org.onap.cps.ncmp.api.inventory.CmHandleState
+import org.onap.cps.ncmp.api.inventory.CompositeState
import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle
+import org.onap.cps.spi.CascadeDeleteAllowed
+import org.onap.cps.spi.exceptions.SchemaSetNotFoundException
import org.onap.cps.spi.model.ModuleReference
import spock.lang.Specification
@@ -67,6 +71,44 @@ class ModuleSyncServiceSpec extends Specification {
'no new module' | [['module1' : '1'], ['module2' : '2']] | [] | [:] | [new ModuleReference(moduleName:'module1',revision:'1'), new ModuleReference(moduleName:'module2',revision:'2')]
}
+ def 'Delete Schema Set for CmHandle' () {
+ given: 'a CmHandle in the advised state'
+ def cmHandle = new YangModelCmHandle(id: 'some-cmhandle-id', compositeState: new CompositeState(cmHandleState: CmHandleState.ADVISED))
+ and: 'the Schema Set exists for the CmHandle'
+ 1 * mockCpsModuleService.deleteSchemaSet(_ as String, 'some-cmhandle-id',
+ CascadeDeleteAllowed.CASCADE_DELETE_ALLOWED)
+ when: 'delete schema set if exists is called'
+ objectUnderTest.deleteSchemaSetIfExists(cmHandle)
+ then: 'there are no exceptions'
+ noExceptionThrown()
+ }
+
+ def 'Delete a non-existing Schema Set for CmHandle' () {
+ given: 'a CmHandle in the advised state'
+ def cmHandle = new YangModelCmHandle(id: 'some-cmhandle-id', compositeState: new CompositeState(cmHandleState: CmHandleState.ADVISED))
+ and: 'the DB throws an exception because its Schema Set does not exist'
+ 1 * mockCpsModuleService.deleteSchemaSet(_ as String, 'some-cmhandle-id',
+ CascadeDeleteAllowed.CASCADE_DELETE_ALLOWED) >> { throw new SchemaSetNotFoundException('some-dataspace-name', 'some-cmhandle-id') }
+ when: 'delete schema set if exists is called'
+ objectUnderTest.deleteSchemaSetIfExists(cmHandle)
+ then: 'there are no exceptions'
+ noExceptionThrown()
+ }
+
+ def 'Delete Schema Set for CmHandle with other exception' () {
+ given: 'a CmHandle in the advised state'
+ def cmHandle = new YangModelCmHandle(id: 'some-cmhandle-id', compositeState: new CompositeState(cmHandleState: CmHandleState.ADVISED))
+ and: 'an exception other than SchemaSetNotFoundException is thrown'
+ UnsupportedOperationException unsupportedOperationException = new UnsupportedOperationException();
+ 1 * mockCpsModuleService.deleteSchemaSet(_ as String, 'some-cmhandle-id',
+ CascadeDeleteAllowed.CASCADE_DELETE_ALLOWED) >> { throw unsupportedOperationException }
+ when: 'delete schema set if exists is called'
+ objectUnderTest.deleteSchemaSetIfExists(cmHandle)
+ then: 'an exception is thrown'
+ def result = thrown(UnsupportedOperationException)
+ result == unsupportedOperationException
+ }
+
def toModuleReference(moduleReferenceAsMap) {
def moduleReferences = [].withDefault { [:] }
moduleReferenceAsMap.forEach(property ->
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncWatchdogSpec.groovy
index 0f89a428b..b7eb133bf 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncWatchdogSpec.groovy
@@ -29,7 +29,7 @@ import org.onap.cps.ncmp.api.inventory.LockReasonCategory
import org.onap.cps.ncmp.api.inventory.CompositeStateBuilder
import spock.lang.Specification
-class ModuleSyncSpec extends Specification {
+class ModuleSyncWatchdogSpec extends Specification {
def mockInventoryPersistence = Mock(InventoryPersistence)
@@ -53,6 +53,8 @@ class ModuleSyncSpec extends Specification {
objectUnderTest.executeAdvisedCmHandlePoll()
then: 'the inventory persistence cm handle returns a composite state for the first cm handle'
1 * mockInventoryPersistence.getCmHandleState('some-cm-handle') >> compositeState1
+ and: 'module sync service deletes schema set of cm handle if it exists'
+ 1 * mockModuleSyncService.deleteSchemaSetIfExists(yangModelCmHandle1)
and: 'module sync service syncs the first cm handle and creates a schema set'
1 * mockModuleSyncService.syncAndCreateSchemaSetAndAnchor(yangModelCmHandle1)
and: 'the composite state cm handle state is now READY'