import com.fasterxml.jackson.databind.ObjectMapper
import org.onap.cps.api.CpsModuleService
import org.onap.cps.ncmp.api.NetworkCmProxyCmHandlerQueryService
+import org.onap.cps.ncmp.api.impl.event.lcm.LcmEventsCmHandleStateHandler
import org.onap.cps.ncmp.api.impl.exception.DmiRequestException
import org.onap.cps.ncmp.api.impl.operations.DmiDataOperations
import org.onap.cps.ncmp.api.impl.yangmodels.YangModelCmHandle
def mockNetworkCmProxyDataServicePropertyHandler = Mock(NetworkCmProxyDataServicePropertyHandler)
def mockInventoryPersistence = Mock(InventoryPersistence)
def stubbedNetworkCmProxyCmHandlerQueryService = Stub(NetworkCmProxyCmHandlerQueryService)
+ def mockLcmEventsCmHandleStateHandler = Mock(LcmEventsCmHandleStateHandler)
def objectUnderTest = getObjectUnderTest()
def 'DMI Registration: Create, Update & Delete operations are processed in the right order'() {
{ if (!schemaSetExist) { throw new SchemaSetNotFoundException("", "") } }
when: 'registration is updated to delete cmhandle'
def response = objectUnderTest.updateDmiRegistrationAndSyncModule(dmiPluginRegistration)
- then: 'delete list or list element is called'
+ then: 'the cmHandle state is updated to "DELETING"'
+ 1 * mockLcmEventsCmHandleStateHandler.updateCmHandleState(_, CmHandleState.DELETING)
+ and: 'method to delete relevant schema set is called once'
+ 1 * mockInventoryPersistence.deleteSchemaSetWithCascade(_)
+ and: 'method to delete relevant list/list element is called once'
1 * mockInventoryPersistence.deleteListOrListElement(_)
and: 'successful response is received'
assert response.getRemovedCmHandles().size() == 1
assert it.status == Status.SUCCESS
assert it.cmHandle == 'cmhandle'
}
+ and: 'the cmHandle state is updated to "DELETED"'
+ 1 * mockLcmEventsCmHandleStateHandler.updateCmHandleState(_, CmHandleState.DELETED)
where:
scenario | schemaSetExist
'schema-set exists and can be deleted successfully' | true
noExceptionThrown()
and: 'cm-handle is not deleted'
0 * mockInventoryPersistence.deleteListOrListElement(_)
+ and: 'the cmHandle state is not updated to "DELETED"'
+ 0 * mockLcmEventsCmHandleStateHandler.updateCmHandleState(_, CmHandleState.DELETED)
and: 'a failure response is received'
assert response.getRemovedCmHandles().size() == 1
with(response.getRemovedCmHandles().get(0)) {
mockInventoryPersistence.deleteListOrListElement(_) >> { throw deleteListElementException }
when: 'registration is updated to delete cmhandle'
def response = objectUnderTest.updateDmiRegistrationAndSyncModule(dmiPluginRegistration)
- then: 'no exception is thrown'
- noExceptionThrown()
- and: 'a failure response is received'
+ then: 'a failure response is received'
assert response.getRemovedCmHandles().size() == 1
with(response.getRemovedCmHandles().get(0)) {
assert it.status == Status.FAILURE
assert it.registrationError == expectedError
assert it.errorText == expectedErrorText
}
+ and: 'the cm handle state is not updated to "DELETED"'
+ 0 * mockLcmEventsCmHandleStateHandler.updateCmHandleState(_, CmHandleState.DELETED)
where:
scenario | cmHandleId | deleteListElementException || expectedError | expectedErrorText
'cm-handle does not exist' | 'cmhandle' | new DataNodeNotFoundException("", "", "") || CM_HANDLE_DOES_NOT_EXIST | 'cm-handle does not exist'
def getObjectUnderTest() {
return Spy(new NetworkCmProxyDataServiceImpl(spiedJsonObjectMapper, mockDmiDataOperations,
- mockNetworkCmProxyDataServicePropertyHandler, mockInventoryPersistence, stubbedNetworkCmProxyCmHandlerQueryService))
+ mockNetworkCmProxyDataServicePropertyHandler, mockInventoryPersistence, stubbedNetworkCmProxyCmHandlerQueryService,
+ mockLcmEventsCmHandleStateHandler))
}
}