import org.onap.cps.ncmp.api.inventory.CompositeState
import org.onap.cps.ncmp.api.inventory.InventoryPersistence
import org.onap.cps.ncmp.api.inventory.DataStoreSyncState
+import spock.lang.Shared
import spock.lang.Specification
class DataSyncSpec extends Specification {
def mockSyncUtils = Mock(SyncUtils)
+ @Shared
def jsonString = '{"stores:bookstore":{"categories":[{"code":"01"}]}}'
def objectUnderTest = new DataSyncWatchdog(mockInventoryPersistence, mockCpsDataService, mockSyncUtils)
def 'Schedule Data Sync for Cm Handle State in READY and Operational Sync State in UNSYNCHRONIZED'() {
given: 'sample resource data'
- def resourceData = jsonString;
+ def resourceData = jsonString
and: 'sync utilities return a cm handle twice'
mockSyncUtils.getAnUnSynchronizedReadyCmHandle() >>> [yangModelCmHandle1, yangModelCmHandle2, null]
when: 'data sync poll is executed'
1 * mockInventoryPersistence.saveCmHandleState('some-cm-handle-2', compositeState)
}
- def 'Schedule Data Sync for Cm Handle State in READY and Operational Sync State in UNSYNCHRONIZED which return empty data from Node'() {
- given: 'cm handles in an ready state and operational sync state in unsynchronized'
- and: 'sync utilities return a cm handle twice'
- mockSyncUtils.getAnUnSynchronizedReadyCmHandle() >>> [yangModelCmHandle1, null]
+ def 'Schedule Data Sync for Cm Handle State in READY and Operational Sync State in UNSYNCHRONIZED which return empty data from Node because #scenario'() {
+ given: 'a yang model cm handle'
+ def yangModelCmHandle = new YangModelCmHandle(id: 'some-cm-handle', compositeState: new CompositeState(dataSyncEnabled: dataSyncEnabled))
+ and: 'sync utilities returns a single cm handle'
+ mockSyncUtils.getAnUnSynchronizedReadyCmHandle() >>> [yangModelCmHandle, null]
when: 'data sync poll is executed'
objectUnderTest.executeUnSynchronizedReadyCmHandlePoll()
then: 'the inventory persistence cm handle returns a composite state for the first cm handle'
- 1 * mockInventoryPersistence.getCmHandleState('some-cm-handle-1') >> compositeState
+ 1 * mockInventoryPersistence.getCmHandleState('some-cm-handle') >> compositeState
and: 'the sync util returns first resource data'
- 1 * mockSyncUtils.getResourceData('some-cm-handle-1') >> null
+ 1 * mockSyncUtils.getResourceData('some-cm-handle') >> resourceData
and: 'the cm-handle data is not saved'
0 * mockCpsDataService.saveData('NFP-Operational', 'some-cm-handle-1', jsonString, _)
+ where:
+ scenario | dataSyncEnabled | resourceData
+ 'data sync is not enabled' | false | jsonString
+ 'resource data is null' | true | null
+ 'data sync is not enabled and resource data is null' | false | null
}
def createSampleYangModelCmHandle(cmHandleId) {
def getCompositeState() {
def cmHandleState = CmHandleState.READY
- def compositeState = new CompositeState(cmHandleState: cmHandleState)
+ def compositeState = new CompositeState(cmHandleState: cmHandleState, dataSyncEnabled: true)
compositeState.setDataStores(CompositeState.DataStores.builder()
.operationalDataStore(CompositeState.Operational.builder().dataStoreSyncState(DataStoreSyncState.SYNCHRONIZED)
.build()).build())