SpiritAdapterImpl implements SpiritAdapter { @Override public XdsSrcSubmitRsp deprecatePolicy(String documentUniqueId, String patientId, byte[] revokedPdfConsent) throws SpiritAdapterException { Assert.hasText(documentUniqueId, "'documentUniqueId' cannot be null and it must have a text."); Assert.hasText(patientId, "'patientId' cannot be null and it must have a text."); Assert.notNull(revokedPdfConsent, "'revokedPdfConsent' cannot be null."); Assert.isTrue(revokedPdfConsent.length > 0, "revokedPdfConsent cannot be empty."); String stateId = login(); EhrPatientClientListDto ehrPatientClientListDto = queryPatientsWithPids( patientId, stateId); stateId = ehrPatientClientListDto.getStateId(); EhrPatientClientDto patient = ehrPatientClientListDto .getEhrPatientClientListDto().get(0); EhrXdsQRsp ehrXdsQRsp = queryPatientContent(patient, stateId); PatientContentClientDto patientContentClientDto = ehrXdsQRsp .getResponseData(); stateId = ehrXdsQRsp.getStateID(); List<DocumentClientDto> documents = patientContentClientDto .getDocuments(); DocumentClientDto oldDocument = null; for (DocumentClientDto document : documents) { if (document.getUniqueId().equals( SpiritConstants.URN_PREFIX_PDF_SIGNED + toXdsUniqueId(documentUniqueId))) { oldDocument = document; break; } } Assert.notNull(oldDocument, "The signedConsentPdf cannot be found!"); appendRevokedPdfConsent(patient, oldDocument, documentUniqueId, revokedPdfConsent); List<String> documentsToDeprecateId = new ArrayList<String>(); documentsToDeprecateId.add(SpiritConstants.URN_PREFIX_PDF_SIGNED + toXdsUniqueId(documentUniqueId)); XdsSrcSubmitRsp response = deprecateDocuments(documentsToDeprecateId, patient, patientContentClientDto, stateId); stateId = response.getStateID(); EhrPolicyDiscardRsp discardPolicyResponse = discardPolicy( documentUniqueId, stateId); stateId = discardPolicyResponse.getStateID(); logout(stateId); return response; } SpiritAdapterImpl(String endpointUrl, String org, String pwd,
			String rol, String user, String domainId, String c2sDomainId,
			String c2sDomainType, String c2sEnvType);  SpiritAdapterImpl(String endpointUrl, String org, String pwd,
			String rol, String user, String domainId, String c2sDomainId,
			String c2sDomainType, String c2sEnvType,
			SpiritEhrWsClientRqRspInterface webService); @Override SpiritUserResponse usrOrgRoleLogin(); @Override String login(); @Override void logout(String stateId); @Override PatientDto createPatientByPDQ(PatientDto patientDto); @Override PatientDto updatePatientByLocId(PatientDto patientDto); @Override XdsSrcSubmitRsp submitSignedConsent(byte[] xacmlPolicy,
			byte[] signedConsentPdf, byte[] pdfConsentFromXacml,
			byte[] pdfConsentToXacml, String xacmlPolicyId, String patientId,
			String country); @Override EhrPatientClientListDto queryPatientsWithPids(String patientId,
			String stateId); EhrPatientRsp insertPatient(EhrPatientRq arg0); @Override XdsSrcSubmitRsp submitDocument(EhrPatientClientDto submitForPatient,
			SourceSubmissionClientDto sourceSubmission, Boolean withFolder,
			String stateId); @Override XdsSrcSubmitRsp submitDocument(EhrPatientClientDto submitForPatient,
			SourceSubmissionClientDto sourceSubmission, Boolean withFolder); @Override EhrXdsQRsp queryPatientContent(EhrPatientClientDto patient,
			String stateId); @Override EhrXdsRetrRsp retrieveDocument(DocumentClientDto wantedDocument); @Override EhrPatientClientDto updateDocument(
			XdsSrcUpdateReq xdsSrcUpdateRequest); @Override SourceSubmissionClientDto generatePolicyMetadata(String document); @Override DocumentClientDto queryDocumentsByUid(String patientId,
			String documentUniqueId, String stateId); @Override XdsSrcSubmitRsp deprecateDocument(String documentUniqueId,
			String patientId, String stateId); @Override XdsSrcSubmitRsp deprecateDocuments(
			List<String> documentUniqueIdList, String patientId, String stateId); @Override XdsSrcSubmitRsp deprecateDocuments(
			List<String> documentUniqueIdList, EhrPatientClientDto patient,
			PatientContentClientDto patientContentClientDto, String stateId); @Override String deleteDocuments(FolderClientDto folder,
			List<DocumentClientDto> documentList, EhrPatientClientDto patient,
			String stateId); @Override XdsSrcSubmitRsp deleteDocument(FolderClientDto folder,
			DocumentClientDto document, EhrPatientClientDto patient,
			String stateId); @Override XdsSrcSubmitRsp deprecatePolicy(String documentUniqueId,
			String patientId, byte[] revokedPdfConsent); XdsSrcSubmitRsp appendDocument(EhrPatientClientDto patient,
			DocumentClientDto oldDocument, DocumentClientDto documentToAppend,
			String stateId); @Override EhrPolicySubmitRsp submitPolicy(byte[] policy); @Override EhrPolicySubmitRsp submitPolicies(List<byte[]> policyList); @Override EhrPolicySubmitOrUpdateRsp submitOrUpdatePolicy(byte[] policy,
			String stateId); @Override EhrPolicySubmitOrUpdateRsp submitOrUpdatePolicies(
			List<byte[]> policyList, String stateId); @Override EhrPolicyUpdateRsp updatePolicy(byte[] policy); @Override EhrPolicyUpdateRsp updatePolicies(List<byte[]> policyList); @Override byte[] retrievePolicy(String policyId); @Override List<byte[]> retrievePolicies(List<String> listPolicySetIds,
			List<String> listPolicyIds); @Override EhrPolicyDiscardRsp discardPolicy(String policyId, String stateId); @Override EhrPolicyDiscardRsp discardPolicies(List<String> listPolicySetIds,
			List<String> listPolicyIds, String stateId); EhrPapCfgRsp loadPapConfiguration(); @Override XdsSrcSubmitRsp submitC32(byte[] c32file); @Override SourceSubmissionClientDto generateC32Metadata(String document);  }
@Test public void testDeprecatePolicy() throws SpiritAdapterException, EhrException_Exception { String documentUniqueIdMock = "documentUniqueIdMock"; String patientIdMock = "patientIdMock"; byte[] revokedPdfConsentMock = new byte[1]; EhrPatientRsp ehrPatientRspMock = mock(EhrPatientRsp.class); List<EhrPatientClientDto> ehrPatientClientDtoList = new LinkedList<EhrPatientClientDto>(); EhrPatientClientDto ehrPatientClientDtoMock = mock(EhrPatientClientDto.class); ehrPatientClientDtoList.add(ehrPatientClientDtoMock); when(ehrPatientRspMock.getResponseData()).thenReturn( ehrPatientClientDtoList); when(webService.queryPatients(isA(EhrPatientRq.class))).thenReturn( ehrPatientRspMock); EhrXdsQRsp ehrXdsQRspMock = mock(EhrXdsQRsp.class); when(webService.queryPatientContent(isA(EhrXdsQGetAllRq.class))) .thenReturn(ehrXdsQRspMock); PatientContentClientDto patientContentClientDtoMock = mock(PatientContentClientDto.class); when(ehrXdsQRspMock.getResponseData()).thenReturn( patientContentClientDtoMock); List<DocumentClientDto> documentClientDtoList = new LinkedList<DocumentClientDto>(); DocumentClientDto documentClientDtoMockXacml = mock(DocumentClientDto.class); DocumentClientDto documentClientDtoMockSignedPdf = mock(DocumentClientDto.class); documentClientDtoList.add(documentClientDtoMockXacml); documentClientDtoList.add(documentClientDtoMockSignedPdf); when(patientContentClientDtoMock.getDocuments()).thenReturn( documentClientDtoList); when(documentClientDtoMockXacml.getUniqueId()).thenReturn( SpiritConstants.URN_PREFIX_XACML + documentUniqueIdMock); when(documentClientDtoMockSignedPdf.getUniqueId()).thenReturn( SpiritConstants.URN_PREFIX_PDF_SIGNED + documentUniqueIdMock); XdsSrcSubmitRsp xdsSrcSubmitRspMock = mock(XdsSrcSubmitRsp.class); when(webService.appendDocument(isA(XdsSrcApRpReq.class))).thenReturn( xdsSrcSubmitRspMock); XdsSrcSubmitRsp xdsSrcSubmitRspMockDeprecate = mock(XdsSrcSubmitRsp.class); when(webService.deprecateDocument(isA(XdsSrcDeprecateReq.class))) .thenReturn(xdsSrcSubmitRspMockDeprecate); EhrPolicyDiscardRsp ehrPolicyDiscardRspMock = mock(EhrPolicyDiscardRsp.class); when(webService.discardPolicies(isA(EhrPolicyDiscardRq.class))) .thenReturn(ehrPolicyDiscardRspMock); SubmissionSetClientDto submissionSetClientDto = mock(SubmissionSetClientDto.class); when(documentClientDtoMockSignedPdf.getSubmissionSet()).thenReturn( submissionSetClientDto); AuthorMetadataClientDto authorMetadataClientDto = new AuthorMetadataClientDto(); authorMetadataClientDto.setPerson("authorPerson"); IheClassificationClientDto classCode = new IheClassificationClientDto(); classCode.setNodeRepresentation("classCode"); classCode.setValue("classCode"); IheClassificationClientDto formatCode = new IheClassificationClientDto(); formatCode.setNodeRepresentation("formatCode"); formatCode.setValue("formatCode"); IheClassificationClientDto typeCode = new IheClassificationClientDto(); typeCode.setNodeRepresentation("typeCode"); typeCode.setValue("typeCode"); IheClassificationClientDto confidentialityCode = new IheClassificationClientDto(); confidentialityCode.setNodeRepresentation("confidentialityCode"); confidentialityCode.setValue("confidentialityCode"); IheClassificationClientDto healthcareFacilityCode = new IheClassificationClientDto(); healthcareFacilityCode.setNodeRepresentation("healthcareFacilityCode"); healthcareFacilityCode.setValue("healthcareFacilityCode"); IheClassificationClientDto practiceSettingCode = new IheClassificationClientDto(); practiceSettingCode.setNodeRepresentation("practiceSettingCode"); practiceSettingCode.setValue("practiceSettingCode"); IheClassificationClientDto contentTypeCode = new IheClassificationClientDto(); contentTypeCode.setNodeRepresentation("contentTypeCode"); contentTypeCode.setValue("contentTypeCode"); when(submissionSetClientDto.getAuthor()).thenReturn( Arrays.asList(authorMetadataClientDto)); when(documentClientDtoMockSignedPdf.getClassCode()).thenReturn( classCode); when(documentClientDtoMockSignedPdf.getFormatCode()).thenReturn( formatCode); when(documentClientDtoMockSignedPdf.getTypeCode()).thenReturn(typeCode); when(documentClientDtoMockSignedPdf.getConfidentialityCode()) .thenReturn(confidentialityCode); when(documentClientDtoMockSignedPdf.getHealthcareFacilityCode()) .thenReturn(healthcareFacilityCode); when(documentClientDtoMockSignedPdf.getPracticeSettingCode()) .thenReturn(practiceSettingCode); when(submissionSetClientDto.getContentTypeCode()).thenReturn( contentTypeCode); XdsSrcSubmitRsp actualResponse = sat.deprecatePolicy( documentUniqueIdMock, patientIdMock, revokedPdfConsentMock); verify(webService, times(1)).deprecateDocument( isA(XdsSrcDeprecateReq.class)); verify(webService, times(1)).discardPolicies( isA(EhrPolicyDiscardRq.class)); verify(webService, times(1)).appendDocument( argThat(new AppendDocumentArgumentMatcher( authorMetadataClientDto, classCode, formatCode, typeCode, confidentialityCode, healthcareFacilityCode, practiceSettingCode, contentTypeCode))); assertEquals(xdsSrcSubmitRspMockDeprecate, actualResponse); }