ConsentServiceImpl implements ConsentService { @Override public String createConsentEmbeddedWidget(ConsentPdfDto consentPdfDto) { final Consent consent = consentRepository .findOne(consentPdfDto.getId()); final SignedPDFConsent signedPdfConsent = makeSignedPdfConsent(); final Patient patient = consent.getPatient(); final String patientEmail = patient.getEmail(); final EmbeddedWidgetCreationResult result = echoSignSignatureService .createEmbeddedWidget(consentPdfDto.getContent(), consentPdfDto.getFilename(), consentPdfDto.getConsentName(), null, patientEmail); signedPdfConsent.setDocumentId(result.getDocumentKey()); signedPdfConsent .setDocumentNameBySender(consentPdfDto.getConsentName()); signedPdfConsent .setDocumentMessageBySender("This is a hard-coded greeting to be replaced. Hi."); signedPdfConsent.setSignerEmail(patientEmail); signedPdfConsent.setDocumentSignedStatus("Unsigned"); consent.setSignedPdfConsent(signedPdfConsent); consentRepository.save(consent); return result.getJavascript(); } ConsentServiceImpl(
			String c2sDomainId,
			String c2sDomainType,
			ConsentRepository consentRepository,
			ConsentPdfGenerator consentPdfGenerator,
			PatientRepository patientRepository,
			IndividualProviderRepository individualProviderRepository,
			OrganizationalProviderRepository organizationalProviderRepository,
			ClinicalDocumentTypeCodeRepository clinicalDocumentTypeCodeRepository,
			MedicalSectionRepository medicalSectionRepository,
			ValueSetCategoryRepository valueSetCategoryRepository,
			PurposeOfUseCodeRepository purposeOfUseCodeRepository,
			EchoSignSignatureService echoSignSignatureService,
			UserContext userContext,
			AbstractConsentRevokationPdfGenerator consentRevokationPdfGenerator,
			ConsentExportService consentExportService,
			TryPolicyService tryPolicyService, ConsentBuilder consentBuilder,
			ConsentFactory consentFactory,
			ConsentCheckService consentCheckService,
			Set<ConsentAssertion> consentAssertions,
			PolicyIdService policyIdService, XmlTransformer xmlTransformer,
			DocumentXmlConverter documentXmlConverter,
			DocumentAccessor documentAccessor); @Override void addUnsignedConsentRevokationPdf(Long consentId,
			String revokationType); @Override @SuppressWarnings({ "rawtypes", "unchecked" }) boolean areThereDuplicatesInTwoSets(Set set1, Set set2); List<ConsentListDto> consentListToConsentListDtosConverter(
			List<Consent> consents); @Override long countAllConsents(); @Override String createConsentEmbeddedWidget(ConsentPdfDto consentPdfDto); @Override String createRevocationEmbeddedWidget(
			ConsentRevokationPdfDto consentRevokationPdfDto); @Override void deleteConsent(Consent consent); @Override boolean deleteConsent(Long consentId); @Override @Transactional(readOnly = true) List<Consent> findAllConsents(); @Override // @PreAuthorize("ROLE_USER") @Transactional(readOnly = true) List<ConsentListDto> findAllConsentsDtoByPatient(Long patientId); @Override @Transactional(readOnly = true) List<ConsentListDto> findAllConsentsDtoByUserName(String userName); @Override @Transactional(readOnly = true) Consent findConsent(Long id); @Override @Transactional(readOnly = true) ConsentDto findConsentById(Long consentId); @Override @Transactional(readOnly = true) AbstractPdfDto findConsentContentDto(Long consentId); @Override @Transactional(readOnly = true) List<Consent> findConsentEntries(int firstResult, int maxResults); @Override @Transactional(readOnly = true) ConsentPdfDto findConsentPdfDto(Long consentId); @Override @Transactional(readOnly = true) ConsentRevokationPdfDto findConsentRevokationPdfDto(Long consentId); @Override @Transactional(readOnly = true) String getConsentSignedStage(Long consentId); List<String> getIds(NodeList c32List); List<String> getIdsToTag(List<String> originalC32Ids,
			List<String> segmentedC32Ids); @Override String getTaggedC32(String originalC32, Long consentId,
			String purposeOfUse); @Override @Transactional(readOnly = true) byte[] getXacmlCcd(Long consentId); @Override @Transactional(readOnly = true) boolean isConsentBelongToThisUser(Long consentId, Long patientId); @Override Consent makeConsent(); @Override ConsentDto makeConsentDto(); @Override ArrayList<ConsentListDto> makeConsentListDtos(); @Override ConsentPdfDto makeConsentPdfDto(); @Override ConsentRevokationPdfDto makeConsentRevokationPdfDto(); @Override SignedPDFConsent makeSignedPdfConsent(); @Override SignedPDFConsentRevocation makeSignedPDFConsentRevocation(); @Override void saveConsent(Consent consent); @Override Object saveConsent(ConsentDto consentDto, long patientId); @Override boolean signConsent(ConsentPdfDto consentPdfDto); @Override void signConsentRevokation(
			ConsentRevokationPdfDto consentRevokationPdfDto); void tagC32Document(NodeList taggedC32List, List<String> taggedC32Ids); void tagSmartC32Document(NodeList taggedC32List,
			List<String> taggedC32Ids); @Override Consent updateConsent(Consent consent); @Override boolean validateConsentDate(Date startDate, Date endDate);  }
@Test public void testCreateConsentEmbeddedWidget() { Consent consent = mock(Consent.class); Patient patient = mock(Patient.class); when(consentRepository.findOne(anyLong())).thenReturn(consent); ConsentService spy = spy(cst); ConsentPdfDto consentPdfDto = mock(ConsentPdfDto.class); when(consentPdfDto.getContent()).thenReturn(DOCUMENT_BYTES); when(consentPdfDto.getFilename()).thenReturn(DOCUMENT_FILE_NAME); when(consentPdfDto.getConsentName()).thenReturn(DOCUMENT_NAME); when(consentPdfDto.getId()).thenReturn((long) 1); SignedPDFConsent signedPdfConsent = mock(SignedPDFConsent.class); when(spy.makeSignedPdfConsent()).thenReturn(signedPdfConsent); when(consent.getPatient()).thenReturn(patient); when(patient.getEmail()).thenReturn(EMAIL); EmbeddedWidgetCreationResult result = mock(EmbeddedWidgetCreationResult.class); when( echoSignSignatureService .createEmbeddedWidget(DOCUMENT_BYTES, DOCUMENT_FILE_NAME, DOCUMENT_NAME, null, EMAIL)).thenReturn(result); spy.createConsentEmbeddedWidget(consentPdfDto); verify(consentRepository).save(consent); }