def mockLcmEventsCreator = Mock(LcmEventsCreator)
def mockLcmEventsService = Mock(LcmEventsService)
- def objectUnderTest = new LcmEventsCmHandleStateHandlerImpl(mockInventoryPersistence, mockLcmEventsCreator, mockLcmEventsService)
+ def lcmEventsCmHandleStateHandlerAsyncHelper = new LcmEventsCmHandleStateHandlerAsyncHelper(mockLcmEventsCreator, mockLcmEventsService)
+ def objectUnderTest = new LcmEventsCmHandleStateHandlerImpl(mockInventoryPersistence, lcmEventsCmHandleStateHandlerAsyncHelper)
def cmHandleId = 'cmhandle-id-1'
def compositeState
then: 'state is saved using inventory persistence'
expectedCallsToInventoryPersistence * mockInventoryPersistence.saveCmHandleState(cmHandleId, _)
and: 'event service is called to publish event'
- expectedCallsToEventService * mockLcmEventsService.publishLcmEvent(cmHandleId, _)
+ expectedCallsToEventService * mockLcmEventsService.publishLcmEvent(cmHandleId, _, _)
where: 'state change parameters are provided'
stateChange | fromCmHandleState | toCmHandleState || expectedCallsToInventoryPersistence | expectedCallsToEventService
'ADVISED to READY' | ADVISED | READY || 1 | 1
'ADVISED to ADVISED' | ADVISED | ADVISED || 0 | 0
'READY to READY' | READY | READY || 0 | 0
'LOCKED to LOCKED' | LOCKED | LOCKED || 0 | 0
-
+ 'DELETED to ADVISED' | DELETED | ADVISED || 0 | 1
}
def 'Update and Publish Events on State Change from NO_EXISTING state to ADVISED'() {
then: 'state is saved using inventory persistence'
1 * mockInventoryPersistence.saveCmHandle(yangModelCmHandle)
and: 'event service is called to publish event'
- 1 * mockLcmEventsService.publishLcmEvent(cmHandleId, _)
+ 1 * mockLcmEventsService.publishLcmEvent(cmHandleId, _, _)
}
def 'Update and Publish Events on State Change from LOCKED to ADVISED'() {
}
}
and: 'event service is called to publish event'
- 1 * mockLcmEventsService.publishLcmEvent(cmHandleId, _)
+ 1 * mockLcmEventsService.publishLcmEvent(cmHandleId, _, _)
+ }
+
+ def 'Update and Publish Events on State Change from DELETING to ADVISED'() {
+ given: 'Cm Handle represented as YangModelCmHandle in DELETING state'
+ yangModelCmHandle = new YangModelCmHandle(id: cmHandleId, dmiProperties: [], publicProperties: [], compositeState: compositeState)
+ when: 'update state is invoked'
+ objectUnderTest.updateCmHandleState(yangModelCmHandle, ADVISED)
+ then: 'the cm handle is saved using inventory persistence'
+ 1 * mockInventoryPersistence.saveCmHandle(yangModelCmHandle)
+ and: 'event service is called to publish event'
+ 1 * mockLcmEventsService.publishLcmEvent(cmHandleId, _, _)
}
def 'Update and Publish Events on State Change to READY'() {
}
}
and: 'event service is called to publish event'
- 1 * mockLcmEventsService.publishLcmEvent(cmHandleId, _)
+ 1 * mockLcmEventsService.publishLcmEvent(cmHandleId, _, _)
}
def 'Update cmHandle state to "DELETING"' (){
and: 'method to persist cm handle state is called once'
1 * mockInventoryPersistence.saveCmHandleState(yangModelCmHandle.getId(), yangModelCmHandle.getCompositeState())
and: 'the method to publish Lcm event is called once'
- 1 * mockLcmEventsService.publishLcmEvent(cmHandleId, _)
+ 1 * mockLcmEventsService.publishLcmEvent(cmHandleId, _, _)
}
def 'Update cmHandle state to "DELETED"' (){
then: 'the cm handle state is as expected'
yangModelCmHandle.getCompositeState().getCmHandleState() == DELETED
and: 'the method to publish Lcm event is called once'
- 1 * mockLcmEventsService.publishLcmEvent(cmHandleId, _)
+ 1 * mockLcmEventsService.publishLcmEvent(cmHandleId, _, _)
}
def 'No state change and no event to be published'() {
assert (args[0] as Collection<YangModelCmHandle>).id.containsAll('cmhandle1', 'cmhandle2')
}
}
- and: 'event service is called to publish event'
- 2 * mockLcmEventsService.publishLcmEvent(_, _)
+ and: 'event service is called to publish events'
+ 2 * mockLcmEventsService.publishLcmEvent(_, _, _)
}
assert (args[0] as Map<String, CompositeState>).keySet().containsAll(['cmhandle1','cmhandle2'])
}
}
- and: 'event service is called to publish event'
- 2 * mockLcmEventsService.publishLcmEvent(_, _)
+ and: 'event service is called to publish events'
+ 2 * mockLcmEventsService.publishLcmEvent(_, _, _)
+ }
+ def 'Batch of existing cm handles is deleted'() {
+ given: 'A batch of deleted cm handles'
+ def cmHandleStateMap = setupBatch('DELETED')
+ when: 'updating a batch of changes'
+ objectUnderTest.updateCmHandleStateBatch(cmHandleStateMap)
+ then : 'existing cm handles composite state is persisted'
+ 1 * mockInventoryPersistence.saveCmHandleStateBatch(_) >> {
+ args -> {
+ assert (args[0] as Map<String, CompositeState>).isEmpty()
+ }
+ }
+ and: 'event service is called to publish events'
+ 2 * mockLcmEventsService.publishLcmEvent(_, _, _)
}
def setupBatch(type) {
return [(yangModelCmHandle1): ADVISED, (yangModelCmHandle2): ADVISED]
}
+ if ('DELETED' == type) {
+ yangModelCmHandle1.compositeState = new CompositeState(cmHandleState: READY)
+ yangModelCmHandle2.compositeState = new CompositeState(cmHandleState: READY)
+ return [(yangModelCmHandle1): DELETED, (yangModelCmHandle2): DELETED]
+ }
+
if ('UPDATE' == type) {
yangModelCmHandle1.compositeState = new CompositeState(cmHandleState: ADVISED)
yangModelCmHandle2.compositeState = new CompositeState(cmHandleState: READY)
return [(yangModelCmHandle1): ADVISED, (yangModelCmHandle2): READY]
}
}
-}
\ No newline at end of file
+}