ConsentSignedMessageHandler extends AbstractConsentMessageHandler { @Override public String handleMessage(String data) throws Throwable { logger.debug("Consent Signed Message Received: ConsentId" + new String(data)); final String messageId = generateMessageId(); final Long consentId = Long.parseLong(data); final SignedConsentDto consentDto = consentGetter .getSignedConsentDto(consentId); XdsSrcSubmitRsp response = null; try { response = spiritAdapter.submitSignedConsent( consentDto.getXacmlCcd(), consentDto.getSignedPdfConsent(), consentDto.getXacmlPdfConsentFrom(), consentDto.getXacmlPdfConsentTo(), consentDto.getXacmlCcdId(), consentDto.getPatientMrn(), "USA"); audit(messageId, consentDto, response); } catch (final Throwable e) { logger.error("Failed to save in xds.b repository", e); throw e; } if (response.getResponseDetail().getListSuccess().get(0) == null) { final String errorMessage = "Failed to save in XDS.b repository."; if (response.getResponseDetail().getListError() != null) { logger.error(response.getResponseDetail().getListError().get(0)); } logger.error(errorMessage); throw new Exception(errorMessage); } endpointStopper.setCounter(0); return "Saved in XDS.b repository"; } ConsentSignedMessageHandler(); @Override String handleMessage(String data);  }
@Test public void testHandleMessage_Successes_Given_XDS_Returns_Success_Response() throws Throwable { ReflectionTestUtils.setField(sut, "domainId", domainIdMock); SignedConsentDto simpleConsentDtoMock = mock(SignedConsentDto.class); String xacmlPolicyIdMock = "xacmlPolicyIdMock"; when(simpleConsentDtoMock.getPatientMrn()).thenReturn( patientLocalIdMock); when(simpleConsentDtoMock.getXacmlCcdId()) .thenReturn(xacmlPolicyIdMock); when(simpleConsentDtoMock.getXacmlCcd()).thenReturn(consentMock); when(simpleConsentDtoMock.getXacmlPdfConsentFrom()).thenReturn( pdfConsentFromXacmlMock); when(simpleConsentDtoMock.getXacmlPdfConsentTo()).thenReturn( pdfConsentToXacmlMock); when(simpleConsentDtoMock.getXacmlCcd()).thenReturn(consentMock); when(simpleConsentDtoMock.getSignedPdfConsent()).thenReturn( signedConsentPdfMock); when(consentGetterMock.getSignedConsentDto(1)).thenReturn( simpleConsentDtoMock); when(spiritAdapter.login()).thenReturn("stateid123"); SourceSubmissionClientDto sourceSubmissionClientDto = mock(SourceSubmissionClientDto.class); when(spiritAdapter.generatePolicyMetadata(anyString())).thenReturn( sourceSubmissionClientDto); List<DocumentClientDto> documentClientDtolistmock = new ArrayList<DocumentClientDto>(); DocumentClientDto documentClientDtomock = mock(DocumentClientDto.class); documentClientDtolistmock.add(documentClientDtomock); when(sourceSubmissionClientDto.getDocuments()).thenReturn( documentClientDtolistmock); List<EhrPatientClientDto> patientClientDtoList = new ArrayList<EhrPatientClientDto>(); EhrPatientClientDto patientClientDtomock = mock(EhrPatientClientDto.class); patientClientDtoList.add(patientClientDtomock); EhrPatientClientListDto ehrPatientClientListDto = mock(EhrPatientClientListDto.class); when(ehrPatientClientListDto.getEhrPatientClientListDto()).thenReturn( patientClientDtoList); when(ehrPatientClientListDto.getStateId()).thenReturn("stateid123"); when(spiritAdapter.queryPatientsWithPids(anyString(), anyString())) .thenReturn(ehrPatientClientListDto); XdsSrcSubmitRsp responsemock = mock(XdsSrcSubmitRsp.class); EhrResponseDetail responseDetailMock = mock(EhrResponseDetail.class); List<String> listSuccess = new ArrayList<String>(); listSuccess.add("Success 1"); when(responsemock.getResponseDetail()).thenReturn(responseDetailMock); when(responseDetailMock.getListSuccess()).thenReturn(listSuccess); when( spiritAdapter.submitSignedConsent(consentMock, signedConsentPdfMock, pdfConsentFromXacmlMock, pdfConsentToXacmlMock, xacmlPolicyIdMock, patientLocalIdMock, "USA")).thenReturn(responsemock); String response = sut.handleMessage(dataMock); assertEquals("Saved in XDS.b repository", response); verify(endpointStopperMock, times(1)).setCounter(0); }
@SuppressWarnings("unchecked") @Test(expected = Throwable.class) public void testHandleMessage_Throws_Exception_Given_XDS_Returns_Fail_Response() throws Throwable { ReflectionTestUtils.setField(sut, "domainId", domainIdMock); SignedConsentDto simpleConsentDtoMock = mock(SignedConsentDto.class); when(simpleConsentDtoMock.getPatientMrn()).thenReturn( patientLocalIdMock); when(simpleConsentDtoMock.getXacmlCcdId()).thenReturn("xacmlPolicyId"); when(simpleConsentDtoMock.getXacmlCcd()).thenReturn(consentMock); when(consentGetterMock.getSignedConsentDto(1)).thenReturn( simpleConsentDtoMock); when(spiritAdapter.login()).thenReturn("stateid123"); SourceSubmissionClientDto sourceSubmissionClientDto = mock(SourceSubmissionClientDto.class); when(spiritAdapter.generatePolicyMetadata(anyString())).thenReturn( sourceSubmissionClientDto); List<DocumentClientDto> documentClientDtolistmock = new ArrayList<DocumentClientDto>(); DocumentClientDto documentClientDtomock = mock(DocumentClientDto.class); documentClientDtolistmock.add(documentClientDtomock); when(sourceSubmissionClientDto.getDocuments()).thenReturn( documentClientDtolistmock); List<EhrPatientClientDto> patientClientDtoList = new ArrayList<EhrPatientClientDto>(); EhrPatientClientDto patientClientDtomock = mock(EhrPatientClientDto.class); patientClientDtoList.add(patientClientDtomock); EhrPatientClientListDto ehrPatientClientListDto = mock(EhrPatientClientListDto.class); when(ehrPatientClientListDto.getEhrPatientClientListDto()).thenReturn( patientClientDtoList); when(ehrPatientClientListDto.getStateId()).thenReturn("stateid123"); when(spiritAdapter.queryPatientsWithPids(anyString(), anyString())) .thenReturn(ehrPatientClientListDto); when( spiritAdapter.submitDocument(patientClientDtomock, sourceSubmissionClientDto, false, "stateid123")) .thenThrow(Throwable.class); sut.handleMessage(dataMock); }