import org.onap.cps.ncmp.api.impl.yangmodels.YangModelCmHandle
+import org.onap.cps.ncmp.api.inventory.CmHandleState
import spock.lang.Specification
class ModuleSyncSpec extends Specification {
def mockSyncUtils = Mock(SyncUtils)
- def objectUnderTest = new ModuleSyncWatchdog(mockSyncUtils)
+ def mockModuleSyncService = Mock(ModuleSyncService)
+
+ def cmHandleState = CmHandleState.ADVISED
+
+ def objectUnderTest = new ModuleSyncWatchdog(mockSyncUtils, mockModuleSyncService)
def 'Schedule a Cm-Handle Sync for ADVISED Cm-Handles'() {
- given: 'a cm handle'
- def yangModelCmHandle1 = new YangModelCmHandle()
- def yangModelCmHandle2 = new YangModelCmHandle()
+ given: 'cm handles in an advised state'
+ def yangModelCmHandle1 = new YangModelCmHandle(cmHandleState: cmHandleState)
+ def yangModelCmHandle2 = new YangModelCmHandle(cmHandleState: cmHandleState)
and: 'sync utilities return a cm handle twice'
mockSyncUtils.getAnAdvisedCmHandle() >>> [yangModelCmHandle1, yangModelCmHandle2, null]
when: 'module sync poll is executed'
objectUnderTest.executeAdvisedCmHandlePoll()
- then: 'each cm handle is updated to state "READY"'
- 1 * mockSyncUtils.updateCmHandleState(yangModelCmHandle1, 'READY')
- 1 * mockSyncUtils.updateCmHandleState(yangModelCmHandle2, 'READY')
+ then: 'module sync service syncs the first cm handle and creates a schema set'
+ 1 * mockModuleSyncService.syncAndCreateSchemaSet(yangModelCmHandle1)
+ and: 'the first cm handle is updated to state "READY" from "ADVISED"'
+ 1 * mockSyncUtils.updateCmHandleState(yangModelCmHandle1, CmHandleState.READY)
+ then: 'module sync service syncs the second cm handle and creates a schema set'
+ 1 * mockModuleSyncService.syncAndCreateSchemaSet(yangModelCmHandle2)
+ then: 'the second cm handle is updated to state "READY" from "ADVISED"'
+ 1 * mockSyncUtils.updateCmHandleState(yangModelCmHandle2, CmHandleState.READY)
}
}