@Test
public void testHandleMessage_Successes_Given_XDS_Returns_Success_Response()
		throws Throwable {

	// Arrange
	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);
	// Act
	String response = sut.handleMessage(dataMock);
	// Assert
	assertEquals("Saved in XDS.b repository", response);
	verify(endpointStopperMock, times(1)).setCounter(0);
}