summaryrefslogtreecommitdiffstats
path: root/cps-ncmp-service/src/test/groovy/org
diff options
context:
space:
mode:
Diffstat (limited to 'cps-ncmp-service/src/test/groovy/org')
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/event/NcmpEventsServiceSpec.groovy21
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncSpec.groovy17
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/SyncUtilsSpec.groovy22
3 files changed, 49 insertions, 11 deletions
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/event/NcmpEventsServiceSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/event/NcmpEventsServiceSpec.groovy
index e265fef05..52806a867 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/event/NcmpEventsServiceSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/event/NcmpEventsServiceSpec.groovy
@@ -30,17 +30,25 @@ class NcmpEventsServiceSpec extends Specification {
def mockInventoryPersistence = Mock(InventoryPersistence)
def mockNcmpEventsPublisher = Mock(NcmpEventsPublisher)
- def mockNcmpEventsMapper = Mock(NcmpEventsCreator)
+ def mockNcmpEventsCreator = Mock(NcmpEventsCreator)
- def objectUnderTest = new NcmpEventsService(mockInventoryPersistence, mockNcmpEventsPublisher, mockNcmpEventsMapper)
+ def objectUnderTest = new NcmpEventsService(mockInventoryPersistence, mockNcmpEventsPublisher, mockNcmpEventsCreator)
- def 'Create and Publish event for #operation'() {
+ def 'Create and Publish ncmp event where events are #scenario'() {
given: 'a cm handle id and operation and responses are mocked'
mockResponses('test-cm-handle-id', 'test-topic')
+ and: 'notifications enabled is #notificationsEnabled'
+ objectUnderTest.notificationsEnabled = notificationsEnabled
when: 'service is called to publish ncmp event'
objectUnderTest.publishNcmpEvent('test-cm-handle-id')
- then: 'no exception is thrown'
- noExceptionThrown()
+ then: 'creator is called #expectedTimesMethodCalled times'
+ expectedTimesMethodCalled * mockNcmpEventsCreator.populateNcmpEvent('test-cm-handle-id', _)
+ and: 'publisher is called #expectedTimesMethodCalled times'
+ expectedTimesMethodCalled * mockNcmpEventsPublisher.publishEvent(*_)
+ where: 'the following values are used'
+ scenario | notificationsEnabled|| expectedTimesMethodCalled
+ 'enabled' | true || 1
+ 'disabled' | false || 0
}
def mockResponses(cmHandleId, topicName) {
@@ -50,9 +58,8 @@ class NcmpEventsServiceSpec extends Specification {
def ncmpServiceCmhandle = YangDataConverter.convertYangModelCmHandleToNcmpServiceCmHandle(yangModelCmHandle)
mockInventoryPersistence.getYangModelCmHandle(cmHandleId) >> yangModelCmHandle
- mockNcmpEventsMapper.populateNcmpEvent(cmHandleId, ncmpServiceCmhandle) >> ncmpEvent
+ mockNcmpEventsCreator.populateNcmpEvent(cmHandleId, ncmpServiceCmhandle) >> ncmpEvent
mockNcmpEventsPublisher.publishEvent(topicName, cmHandleId, ncmpEvent) >> {}
}
-
}
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/ModuleSyncSpec.groovy
index 614783efd..0f89a428b 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/ModuleSyncSpec.groovy
@@ -90,16 +90,25 @@ class ModuleSyncSpec extends Specification {
}
- def 'Schedule a Cm-Handle Sync for LOCKED with reason LOCKED_MISBEHAVING Cm-Handles '() {
+ def 'Schedule a Cm-Handle Sync for LOCKED with reason LOCKED_MISBEHAVING Cm-Handles with #scenario'() {
given: 'cm handles in an locked state'
def compositeState = new CompositeStateBuilder().withCmHandleState(CmHandleState.LOCKED)
- .withLockReason(LockReasonCategory.LOCKED_MISBEHAVING, '').build()
+ .withLockReason(LockReasonCategory.LOCKED_MISBEHAVING, '').withLastUpdatedTimeNow().build()
def yangModelCmHandle = new YangModelCmHandle(id: 'some-cm-handle', compositeState: compositeState)
and: 'sync utilities return a cm handle twice'
mockSyncUtils.getLockedMisbehavingYangModelCmHandles() >> [yangModelCmHandle, yangModelCmHandle]
+ and: 'inventory persistence returns the composite state of the cm handle'
+ mockInventoryPersistence.getCmHandleState(yangModelCmHandle.getId()) >> compositeState
+ and: 'sync utils retry locked cm handle returns #isReadyForRetry'
+ mockSyncUtils.isReadyForRetry(compositeState) >>> isReadyForRetry
when: 'module sync poll is executed'
- objectUnderTest.executeLockedMisbehavingCmHandlePoll()
+ objectUnderTest.executeLockedCmHandlePoll()
then: 'the first cm handle is updated to state "ADVISED" from "READY"'
- 2 * mockInventoryPersistence.saveCmHandleState(yangModelCmHandle.id, compositeState)
+ expectedNumberOfInvocationsToSaveCmHandleState * mockInventoryPersistence.saveCmHandleState(yangModelCmHandle.id, compositeState)
+ where:
+ scenario | isReadyForRetry || expectedNumberOfInvocationsToSaveCmHandleState
+ 'retry locked cm handle once' | [true, false] || 1
+ 'retry locked cm handle twice' | [true, true] || 2
+ 'do not retry locked cm handle' | [false, false] || 0
}
}
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/SyncUtilsSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/SyncUtilsSpec.groovy
index 2c45ab769..dd299146f 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/SyncUtilsSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/SyncUtilsSpec.groovy
@@ -27,6 +27,7 @@ import org.onap.cps.ncmp.api.impl.operations.DmiDataOperations
import org.onap.cps.ncmp.api.impl.operations.DmiOperations
import org.onap.cps.ncmp.api.inventory.CmHandleState
import org.onap.cps.ncmp.api.inventory.CompositeState
+import org.onap.cps.ncmp.api.inventory.CompositeStateBuilder
import org.onap.cps.ncmp.api.inventory.InventoryPersistence
import org.onap.cps.ncmp.api.inventory.LockReasonCategory
import org.onap.cps.ncmp.api.inventory.SyncState
@@ -38,6 +39,9 @@ import org.springframework.http.ResponseEntity
import spock.lang.Shared
import spock.lang.Specification
+import java.time.OffsetDateTime
+import java.time.format.DateTimeFormatter
+
class SyncUtilsSpec extends Specification{
def mockInventoryPersistence = Mock(InventoryPersistence)
@@ -49,6 +53,9 @@ class SyncUtilsSpec extends Specification{
def objectUnderTest = new SyncUtils(mockInventoryPersistence, mockDmiDataOperations, jsonObjectMapper)
@Shared
+ def formattedDateAndTime = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSZ").format(OffsetDateTime.now())
+
+ @Shared
def dataNode = new DataNode(leaves: ['id': 'cm-handle-123'])
def 'Get an advised Cm-Handle where ADVISED cm handle #scenario'() {
@@ -94,6 +101,21 @@ class SyncUtilsSpec extends Specification{
result[0].id == 'cm-handle-123'
}
+ def 'Retry Locked Cm-Handle where the last update time is #scenario'() {
+ when: 'retry locked cm handle is invoked'
+ def result = objectUnderTest.isReadyForRetry(new CompositeStateBuilder()
+ .withLockReason(LockReasonCategory.LOCKED_MISBEHAVING, details)
+ .withLastUpdatedTime(lastUpdateTime).build())
+ then: 'result returns #expectedResult'
+ result == expectedResult
+ where:
+ scenario | lastUpdateTime | details || expectedResult
+ 'is the first attempt' | '1900-01-01T00:00:00.000+0100' | 'First Attempt' || true
+ 'is greater than one minute' | '1900-01-01T00:00:00.000+0100' | 'Attempt #1 failed:' || true
+ 'is less than eight minutes' | formattedDateAndTime | 'Attempt #3 failed:' || false
+ }
+
+
def 'Get a Cm-Handle where Operational Sync state is UnSynchronized and Cm-handle state is READY and #scenario'() {
given: 'the inventory persistence service returns a collection of data nodes'
mockInventoryPersistence.getCmHandlesByOperationalSyncState(SyncState.UNSYNCHRONIZED) >> unSynchronizedDataNodes