+ def 'Update CM-Handle: Update Operation Response is added to the response'() {
+ given: 'a registration to update CmHandles'
+ def dmiPluginRegistration = new DmiPluginRegistration(dmiPlugin: 'my-server',
+ updatedCmHandles: [{}])
+ and: 'cm-handle updates can be processed successfully'
+ def updateOperationResponse = [CmHandleRegistrationResponse.createSuccessResponse('cm-handle-1'),
+ CmHandleRegistrationResponse.createFailureResponse('cm-handle-2', new Exception("Failed")),
+ CmHandleRegistrationResponse.createFailureResponse('cm-handle-3', CM_HANDLE_DOES_NOT_EXIST)]
+ mockNetworkCmProxyDataServicePropertyHandler.updateCmHandleProperties(_) >> updateOperationResponse
+ when: 'registration is updated'
+ def response = objectUnderTest.updateDmiRegistrationAndSyncModule(dmiPluginRegistration)
+ then: 'the response contains updateOperationResponse'
+ assert response.getUpdatedCmHandles().size() == 3
+ assert response.getUpdatedCmHandles().containsAll(updateOperationResponse)
+ }
+
+ def 'Remove CmHandle Successfully: #scenario'() {
+ given: 'a registration'
+ def dmiPluginRegistration = new DmiPluginRegistration(dmiPlugin: 'my-server',
+ removedCmHandles: ['cmhandle'])
+ and: '#scenario'
+ mockCpsModuleService.deleteSchemaSet(_, 'cmhandle', CASCADE_DELETE_ALLOWED) >>
+ { 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'
+ 1 * mockCpsDataService.deleteListOrListElement(_, _, _, _)
+ and: 'successful response is received'
+ assert response.getRemovedCmHandles().size() == 1
+ with(response.getRemovedCmHandles().get(0)) {
+ assert it.status == CmHandleRegistrationResponse.Status.SUCCESS
+ assert it.cmHandle == 'cmhandle'
+ }
+ where:
+ scenario | schemaSetExist
+ 'schema-set exists and can be deleted successfully' | true
+ 'schema-set does not exist' | false
+ }
+
+ def 'Remove CmHandle: All cm-handles delete requests are processed'() {
+ given: 'a registration with three cm-handles to be deleted'
+ def dmiPluginRegistration = new DmiPluginRegistration(dmiPlugin: 'my-server',
+ removedCmHandles: ['cmhandle1', 'cmhandle2', 'cmhandle3'])
+ and: 'cm-handle deletion is successful for 1st and 3rd; failed for 2nd'
+ mockCpsDataService.deleteListOrListElement(_, _, _, _) >> {} >> { throw new RuntimeException("Failed") } >> {}
+ when: 'registration is updated to delete cmhandles'
+ def response = objectUnderTest.updateDmiRegistrationAndSyncModule(dmiPluginRegistration)
+ then: 'a response is received for all cm-handles'
+ response.getRemovedCmHandles().size() == 3
+ and: '1st and 3rd cm-handle deletes successfully'
+ with(response.getRemovedCmHandles().get(0)) {
+ assert it.status == CmHandleRegistrationResponse.Status.SUCCESS
+ }
+ with(response.getRemovedCmHandles().get(2)) {
+ assert it.status == CmHandleRegistrationResponse.Status.SUCCESS
+ }
+ and: '2nd cmhandle deletion fails'
+ with(response.getRemovedCmHandles().get(1)) {
+ assert it.status == CmHandleRegistrationResponse.Status.FAILURE
+ assert it.registrationError == UNKNOWN_ERROR
+ assert it.errorText == 'Failed'
+ }
+ }
+
+ def 'Remove CmHandle Error Handling: Schema Set Deletion failed'() {
+ given: 'a registration'
+ def dmiPluginRegistration = new DmiPluginRegistration(dmiPlugin: 'my-server',
+ removedCmHandles: ['cmhandle'])
+ and: 'schema set deletion failed with unknown error'
+ mockCpsModuleService.deleteSchemaSet(_, _, _) >> { throw new RuntimeException('Failed') }
+ when: 'registration is updated to delete cmhandle'
+ def response = objectUnderTest.updateDmiRegistrationAndSyncModule(dmiPluginRegistration)