@Test(expected = IllegalArgumentException.class) public void testSignup_Throws_Exception_Given_Valid_Link_Url_And_Given_No_Email_Address() throws MessagingException, UsernameNotExistException, EmailAddressNotExistException, Hl7v3TransformerException { final String linkUrl = "linkUrl"; SignupDto signupDto = mock(SignupDto.class); when(signupDto.getUsername()).thenReturn("username"); when(signupDto.getBirthDate()).thenReturn(new Date()); PixManagerBean pixManagerBeanMock = mock(PixManagerBean.class); when(pixService.addPatient(any(PixPatientDto.class))).thenReturn( pixManagerBeanMock); when(passwordEncoder.encode(any(CharSequence.class))).thenReturn( "encodedPassword"); sut.signup(signupDto, linkUrl); }
@Override @Transactional public void signup(SignupDto signupDto, String linkUrl) throws MessagingException, UsernameNotExistException, EmailAddressNotExistException { String eid = null; final String mrn = generateMrn(); try { PixManagerBean pixManagerBean = pixService.addPatient(TypeConverter .signupDtoToPixPatientDto(signupDto, mrn)); Assert.isTrue( pixManagerBean.isSuccess(), "Patient cannot be added to MPI! Error: " + pixManagerBean.getAddMessage()); eid = pixService.getEid(mrn); Assert.hasText(eid, "EID cannot be retrieved from MPI!"); } catch (IllegalArgumentException e) { logger.error(e.getMessage(), e); throw e; } if (!StringUtils.hasText(linkUrl)) { throw new IllegalArgumentException("Email link is required."); } String encodedPassword = passwordEncoder .encode(signupDto.getPassword()); Patient patient = new Patient(); patient.setMedicalRecordNumber(mrn); patient.setEnterpriseIdentifier(eid); patient.setFirstName(signupDto.getFirstName()); patient.setLastName(signupDto.getLastName()); patient.setUsername(signupDto.getUsername()); patient.setEmail(signupDto.getEmail()); patient.setBirthDay(signupDto.getBirthDate()); if (StringUtils.hasText(signupDto.getGenderCode())) { patient.setAdministrativeGenderCode(administrativeGenderCodeRepository .findByCode(signupDto.getGenderCode())); } patientRepository.save(patient); Set<GrantedAuthority> authorities = UsersAuthorityUtils .createAuthoritySet("ROLE_USER"); String username = signupDto.getUsername(); Users user = new Users(username, encodedPassword, false, true, true, authorities); usersRepository.createUser(user); userContext.setCurrentUser(signupDto.getUsername()); String token = createEmailToken(signupDto.getUsername(), signupDto.getEmail()); emailSender.sendMessage( signupDto.getFirstName() + " " + signupDto.getLastName(), signupDto.getEmail(), EmailType.SIGNUP_VERIFICATION, linkUrl, token); }
AccountServiceImpl implements AccountService { @Override @Transactional public void signup(SignupDto signupDto, String linkUrl) throws MessagingException, UsernameNotExistException, EmailAddressNotExistException { String eid = null; final String mrn = generateMrn(); try { PixManagerBean pixManagerBean = pixService.addPatient(TypeConverter .signupDtoToPixPatientDto(signupDto, mrn)); Assert.isTrue( pixManagerBean.isSuccess(), "Patient cannot be added to MPI! Error: " + pixManagerBean.getAddMessage()); eid = pixService.getEid(mrn); Assert.hasText(eid, "EID cannot be retrieved from MPI!"); } catch (IllegalArgumentException e) { logger.error(e.getMessage(), e); throw e; } if (!StringUtils.hasText(linkUrl)) { throw new IllegalArgumentException("Email link is required."); } String encodedPassword = passwordEncoder .encode(signupDto.getPassword()); Patient patient = new Patient(); patient.setMedicalRecordNumber(mrn); patient.setEnterpriseIdentifier(eid); patient.setFirstName(signupDto.getFirstName()); patient.setLastName(signupDto.getLastName()); patient.setUsername(signupDto.getUsername()); patient.setEmail(signupDto.getEmail()); patient.setBirthDay(signupDto.getBirthDate()); if (StringUtils.hasText(signupDto.getGenderCode())) { patient.setAdministrativeGenderCode(administrativeGenderCodeRepository .findByCode(signupDto.getGenderCode())); } patientRepository.save(patient); Set<GrantedAuthority> authorities = UsersAuthorityUtils .createAuthoritySet("ROLE_USER"); String username = signupDto.getUsername(); Users user = new Users(username, encodedPassword, false, true, true, authorities); usersRepository.createUser(user); userContext.setCurrentUser(signupDto.getUsername()); String token = createEmailToken(signupDto.getUsername(), signupDto.getEmail()); emailSender.sendMessage( signupDto.getFirstName() + " " + signupDto.getLastName(), signupDto.getEmail(), EmailType.SIGNUP_VERIFICATION, linkUrl, token); } }
AccountServiceImpl implements AccountService { @Override @Transactional public void signup(SignupDto signupDto, String linkUrl) throws MessagingException, UsernameNotExistException, EmailAddressNotExistException { String eid = null; final String mrn = generateMrn(); try { PixManagerBean pixManagerBean = pixService.addPatient(TypeConverter .signupDtoToPixPatientDto(signupDto, mrn)); Assert.isTrue( pixManagerBean.isSuccess(), "Patient cannot be added to MPI! Error: " + pixManagerBean.getAddMessage()); eid = pixService.getEid(mrn); Assert.hasText(eid, "EID cannot be retrieved from MPI!"); } catch (IllegalArgumentException e) { logger.error(e.getMessage(), e); throw e; } if (!StringUtils.hasText(linkUrl)) { throw new IllegalArgumentException("Email link is required."); } String encodedPassword = passwordEncoder .encode(signupDto.getPassword()); Patient patient = new Patient(); patient.setMedicalRecordNumber(mrn); patient.setEnterpriseIdentifier(eid); patient.setFirstName(signupDto.getFirstName()); patient.setLastName(signupDto.getLastName()); patient.setUsername(signupDto.getUsername()); patient.setEmail(signupDto.getEmail()); patient.setBirthDay(signupDto.getBirthDate()); if (StringUtils.hasText(signupDto.getGenderCode())) { patient.setAdministrativeGenderCode(administrativeGenderCodeRepository .findByCode(signupDto.getGenderCode())); } patientRepository.save(patient); Set<GrantedAuthority> authorities = UsersAuthorityUtils .createAuthoritySet("ROLE_USER"); String username = signupDto.getUsername(); Users user = new Users(username, encodedPassword, false, true, true, authorities); usersRepository.createUser(user); userContext.setCurrentUser(signupDto.getUsername()); String token = createEmailToken(signupDto.getUsername(), signupDto.getEmail()); emailSender.sendMessage( signupDto.getFirstName() + " " + signupDto.getLastName(), signupDto.getEmail(), EmailType.SIGNUP_VERIFICATION, linkUrl, token); } AccountServiceImpl(
			Integer accountVerificationTokenExpireInHours,
			PatientRepository patientRepository,
			AdministrativeGenderCodeRepository administrativeGenderCodeRepository,
			PasswordEncoder passwordEncoder, UserContext userContext,
			EmailSender emailSender, TokenGenerator tokenGenerator,
			EmailTokenRepository emailTokenRepository,
			UsersRepository usersRepository, MrnService mrnService,
			PixService pixService); }
AccountServiceImpl implements AccountService { @Override @Transactional public void signup(SignupDto signupDto, String linkUrl) throws MessagingException, UsernameNotExistException, EmailAddressNotExistException { String eid = null; final String mrn = generateMrn(); try { PixManagerBean pixManagerBean = pixService.addPatient(TypeConverter .signupDtoToPixPatientDto(signupDto, mrn)); Assert.isTrue( pixManagerBean.isSuccess(), "Patient cannot be added to MPI! Error: " + pixManagerBean.getAddMessage()); eid = pixService.getEid(mrn); Assert.hasText(eid, "EID cannot be retrieved from MPI!"); } catch (IllegalArgumentException e) { logger.error(e.getMessage(), e); throw e; } if (!StringUtils.hasText(linkUrl)) { throw new IllegalArgumentException("Email link is required."); } String encodedPassword = passwordEncoder .encode(signupDto.getPassword()); Patient patient = new Patient(); patient.setMedicalRecordNumber(mrn); patient.setEnterpriseIdentifier(eid); patient.setFirstName(signupDto.getFirstName()); patient.setLastName(signupDto.getLastName()); patient.setUsername(signupDto.getUsername()); patient.setEmail(signupDto.getEmail()); patient.setBirthDay(signupDto.getBirthDate()); if (StringUtils.hasText(signupDto.getGenderCode())) { patient.setAdministrativeGenderCode(administrativeGenderCodeRepository .findByCode(signupDto.getGenderCode())); } patientRepository.save(patient); Set<GrantedAuthority> authorities = UsersAuthorityUtils .createAuthoritySet("ROLE_USER"); String username = signupDto.getUsername(); Users user = new Users(username, encodedPassword, false, true, true, authorities); usersRepository.createUser(user); userContext.setCurrentUser(signupDto.getUsername()); String token = createEmailToken(signupDto.getUsername(), signupDto.getEmail()); emailSender.sendMessage( signupDto.getFirstName() + " " + signupDto.getLastName(), signupDto.getEmail(), EmailType.SIGNUP_VERIFICATION, linkUrl, token); } AccountServiceImpl(
			Integer accountVerificationTokenExpireInHours,
			PatientRepository patientRepository,
			AdministrativeGenderCodeRepository administrativeGenderCodeRepository,
			PasswordEncoder passwordEncoder, UserContext userContext,
			EmailSender emailSender, TokenGenerator tokenGenerator,
			EmailTokenRepository emailTokenRepository,
			UsersRepository usersRepository, MrnService mrnService,
			PixService pixService); @Override @Transactional void signup(SignupDto signupDto, String linkUrl); @Override String createEmailToken(String username, String emailAddress); @Override Users findUserByUsername(String username); @Override String recoverUsername(String firstName, String lastName,
			String birthDay, String email); }
AccountServiceImpl implements AccountService { @Override @Transactional public void signup(SignupDto signupDto, String linkUrl) throws MessagingException, UsernameNotExistException, EmailAddressNotExistException { String eid = null; final String mrn = generateMrn(); try { PixManagerBean pixManagerBean = pixService.addPatient(TypeConverter .signupDtoToPixPatientDto(signupDto, mrn)); Assert.isTrue( pixManagerBean.isSuccess(), "Patient cannot be added to MPI! Error: " + pixManagerBean.getAddMessage()); eid = pixService.getEid(mrn); Assert.hasText(eid, "EID cannot be retrieved from MPI!"); } catch (IllegalArgumentException e) { logger.error(e.getMessage(), e); throw e; } if (!StringUtils.hasText(linkUrl)) { throw new IllegalArgumentException("Email link is required."); } String encodedPassword = passwordEncoder .encode(signupDto.getPassword()); Patient patient = new Patient(); patient.setMedicalRecordNumber(mrn); patient.setEnterpriseIdentifier(eid); patient.setFirstName(signupDto.getFirstName()); patient.setLastName(signupDto.getLastName()); patient.setUsername(signupDto.getUsername()); patient.setEmail(signupDto.getEmail()); patient.setBirthDay(signupDto.getBirthDate()); if (StringUtils.hasText(signupDto.getGenderCode())) { patient.setAdministrativeGenderCode(administrativeGenderCodeRepository .findByCode(signupDto.getGenderCode())); } patientRepository.save(patient); Set<GrantedAuthority> authorities = UsersAuthorityUtils .createAuthoritySet("ROLE_USER"); String username = signupDto.getUsername(); Users user = new Users(username, encodedPassword, false, true, true, authorities); usersRepository.createUser(user); userContext.setCurrentUser(signupDto.getUsername()); String token = createEmailToken(signupDto.getUsername(), signupDto.getEmail()); emailSender.sendMessage( signupDto.getFirstName() + " " + signupDto.getLastName(), signupDto.getEmail(), EmailType.SIGNUP_VERIFICATION, linkUrl, token); } AccountServiceImpl(
			Integer accountVerificationTokenExpireInHours,
			PatientRepository patientRepository,
			AdministrativeGenderCodeRepository administrativeGenderCodeRepository,
			PasswordEncoder passwordEncoder, UserContext userContext,
			EmailSender emailSender, TokenGenerator tokenGenerator,
			EmailTokenRepository emailTokenRepository,
			UsersRepository usersRepository, MrnService mrnService,
			PixService pixService); @Override @Transactional void signup(SignupDto signupDto, String linkUrl); @Override String createEmailToken(String username, String emailAddress); @Override Users findUserByUsername(String username); @Override String recoverUsername(String firstName, String lastName,
			String birthDay, String email);  }