SpiritAdapterImpl implements SpiritAdapter { @Override public EhrPolicyUpdateRsp updatePolicies(List<byte[]> policyList) throws SpiritAdapterException { Assert.notEmpty(policyList, "'policyList' cannot be empty."); logger.debug("updatePolicies: START"); EhrPolicyUpdateRsp ehrPolicyUpdateRsp = null; try { String stateId = login(); EhrPolicyUpdateRq ehrPolicyUpdateRq = new EhrPolicyUpdateRq(); ehrPolicyUpdateRq.setStateID(stateId); ehrPolicyUpdateRq.getPolicyList().addAll(policyList); ehrPolicyUpdateRsp = getWebService().updatePolicies( ehrPolicyUpdateRq); logger.debug("updatePolicies: SUCCESS"); logout(stateId); } catch (Exception e) { logger.error("updatePolicies: FAILED", e); throw new SpiritAdapterException(e); } return ehrPolicyUpdateRsp; } 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 testUpdatePolicies() throws SpiritAdapterException, EhrException_Exception { List<byte[]> policyListMock = Arrays.asList(new byte[1]); EhrPolicyUpdateRsp expectedResponse = mock(EhrPolicyUpdateRsp.class); when(webService.updatePolicies(any(EhrPolicyUpdateRq.class))) .thenReturn(expectedResponse); EhrPolicyUpdateRsp actualResponse = sat.updatePolicies(policyListMock); verify(webService, times(1)).updatePolicies( argThat(new UpdatePoliciesArgumentMatcher(policyListMock))); assertEquals(expectedResponse, actualResponse); }
@SuppressWarnings("unchecked") @Test public void testUpdatePolicies_Throws_SpiritAdapterException() throws SpiritAdapterException, EhrException_Exception { List<byte[]> policyListMock = Arrays.asList(new byte[1]); when(webService.updatePolicies(any(EhrPolicyUpdateRq.class))) .thenThrow(EhrException_Exception.class); thrown.expect(SpiritAdapterException.class); @SuppressWarnings("unused") EhrPolicyUpdateRsp actualResponse = sat.updatePolicies(policyListMock); }