/*
* ============LICENSE_START=======================================================
* Copyright (C) 2022 Bell Canada
+ * Modifications Copyright (C) 2022-2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
package org.onap.cps.ncmp.api.inventory
+import org.onap.cps.ncmp.api.impl.inventory.CmHandleState
+import org.onap.cps.ncmp.api.impl.inventory.CompositeState
+import org.onap.cps.ncmp.api.impl.inventory.CompositeStateBuilder
+import org.onap.cps.ncmp.api.impl.inventory.DataStoreSyncState
+import org.onap.cps.ncmp.api.impl.inventory.LockReasonCategory
import org.onap.cps.spi.model.DataNode
import org.onap.cps.spi.model.DataNodeBuilder
import spock.lang.Specification
def static cmHandleId = 'myHandle1'
def static cmHandleXpath = "/dmi-registry/cm-handles[@id='${cmHandleId}/state']"
def static stateDataNodes = [new DataNodeBuilder().withXpath("/dmi-registry/cm-handles[@id='${cmHandleId}']/state/lock-reason")
- .withLeaves(['reason': 'lock reason', 'details': 'lock details']).build(),
+ .withLeaves(['reason': 'MODULE_SYNC_FAILED', 'details': 'lock details']).build(),
new DataNodeBuilder().withXpath("/dmi-registry/cm-handles[@id='${cmHandleId}']/state/datastores")
.withChildDataNodes(Arrays.asList(new DataNodeBuilder()
.withXpath("/dmi-registry/cm-handles[@id='${cmHandleId}']/state/datastores/operational")
def "Composite State Specification"() {
when: 'using composite state builder '
def compositeState = new CompositeStateBuilder().withCmHandleState(CmHandleState.ADVISED)
- .withLockReason("lock-reason","").withOperationalDataStores("UNSYNCHRONIZED",
- formattedDateAndTime.toString()).withLastUpdatedTime(formattedDateAndTime).build();
+ .withLockReason(LockReasonCategory.MODULE_SYNC_FAILED,"").withOperationalDataStores(DataStoreSyncState.UNSYNCHRONIZED,
+ formattedDateAndTime.toString()).withLastUpdatedTime(formattedDateAndTime).build()
then: 'it matches expected cm handle state and data store sync state'
- assert compositeState.getCmhandleState() == CmHandleState.ADVISED
- assert compositeState.dataStores.operationalDataStore.syncState == 'UNSYNCHRONIZED'
+ assert compositeState.cmHandleState == CmHandleState.ADVISED
+ assert compositeState.dataStores.operationalDataStore.dataStoreSyncState == DataStoreSyncState.UNSYNCHRONIZED
}
def "Build composite state from DataNode "() {
given: "a Data Node "
- def dataNode = new DataNode(leaves: ['cm-handle-state': 'ADVISED'])
+ new DataNode(leaves: ['cm-handle-state': 'ADVISED'])
when: 'build from data node function is invoked'
def compositeState = new CompositeStateBuilder().fromDataNode(cmHandleDataNode).build()
then: 'it matches expected state model as JSON'
- assert compositeState.cmhandleState == CmHandleState.ADVISED
+ assert compositeState.cmHandleState == CmHandleState.ADVISED
+ }
+
+ def 'CompositeStateBuilder build'() {
+ given: 'A CompositeStateBuilder with all private fields set'
+ def finalCompositeStateBuilder = new CompositeStateBuilder()
+ .withCmHandleState(CmHandleState.ADVISED)
+ .withLastUpdatedTime(formattedDateAndTime.toString())
+ .withLockReason(LockReasonCategory.MODULE_SYNC_FAILED, 'locked details')
+ .withOperationalDataStores(DataStoreSyncState.SYNCHRONIZED, formattedDateAndTime)
+ when: 'build is called'
+ def result = finalCompositeStateBuilder.build()
+ then: 'result is of the correct type'
+ assert result.class == CompositeState.class
+ and: 'built result should have correct values'
+ assert !result.getDataSyncEnabled()
+ assert result.getLastUpdateTime() == formattedDateAndTime
+ assert result.getLockReason().getLockReasonCategory() == LockReasonCategory.MODULE_SYNC_FAILED
+ assert result.getLockReason().getDetails() == 'locked details'
+ assert result.getCmHandleState() == CmHandleState.ADVISED
+ assert result.getDataStores().getOperationalDataStore().getDataStoreSyncState() == DataStoreSyncState.SYNCHRONIZED
+ assert result.getDataStores().getOperationalDataStore().getLastSyncTime() == formattedDateAndTime
}
}