import org.onap.cps.ncmp.api.inventory.CompositeStateBuilder
import spock.lang.Specification
+import java.util.concurrent.ConcurrentHashMap
+import java.util.concurrent.ConcurrentMap
+
class ModuleSyncWatchdogSpec extends Specification {
def mockInventoryPersistence = Mock(InventoryPersistence)
def mockModuleSyncService = Mock(ModuleSyncService)
+ def stubbedMap = Stub(ConcurrentMap)
+
def cmHandleState = CmHandleState.ADVISED
- def objectUnderTest = new ModuleSyncWatchdog(mockInventoryPersistence, mockSyncUtils, mockModuleSyncService)
+ def objectUnderTest = new ModuleSyncWatchdog(mockInventoryPersistence, mockSyncUtils, mockModuleSyncService, stubbedMap as ConcurrentHashMap)
def 'Schedule a Cm-Handle Sync for ADVISED Cm-Handles where #scenario'() {
given: 'cm handles in an advised state and a data sync state'
def yangModelCmHandle2 = new YangModelCmHandle(id: 'some-cm-handle-2', compositeState: compositeState2)
objectUnderTest.isGlobalDataSyncCacheEnabled = dataSyncCacheEnabled
and: 'sync utilities return a cm handle twice'
- mockSyncUtils.getAnAdvisedCmHandle() >>> [yangModelCmHandle1, yangModelCmHandle2, null]
+ mockSyncUtils.getAdvisedCmHandles() >> [yangModelCmHandle1, yangModelCmHandle2]
when: 'module sync poll is executed'
objectUnderTest.executeAdvisedCmHandlePoll()
then: 'the inventory persistence cm handle returns a composite state for the first cm handle'
def compositeState = new CompositeState(cmHandleState: cmHandleState)
def yangModelCmHandle = new YangModelCmHandle(id: 'some-cm-handle', compositeState: compositeState)
and: 'sync utilities return a cm handle'
- mockSyncUtils.getAnAdvisedCmHandle() >>> [yangModelCmHandle, null]
+ mockSyncUtils.getAdvisedCmHandles() >> [yangModelCmHandle]
when: 'module sync poll is executed'
objectUnderTest.executeAdvisedCmHandlePoll()
then: 'the inventory persistence cm handle returns a composite state for the cm handle'