use of org.springframework.mail.SimpleMailMessage in project molgenis by molgenis.
the class AccountServiceImplTest method createUser.
@Test
public void createUser() throws URISyntaxException, UsernameAlreadyExistsException, EmailAlreadyExistsException {
when(idGenerator.generateId(SECURE_RANDOM)).thenReturn("3541db68-435b-416b-8c2c-cf2edf6ba435");
accountService.createUser(user, "http://molgenis.org/activate");
ArgumentCaptor<User> argument = ArgumentCaptor.forClass(User.class);
verify(dataService).add(eq(USER), argument.capture());
verify(argument.getValue()).setActive(false);
SimpleMailMessage expected = new SimpleMailMessage();
expected.setTo("jan.jansen@activation.nl");
expected.setSubject("User registration for Molgenis title");
expected.setText("User registration for Molgenis title\n" + "User name: jansenj Full name: Jan Jansen\n" + "In order to activate the user visit the following URL:\n" + "http://molgenis.org/activate/3541db68-435b-416b-8c2c-cf2edf6ba435\n\n");
verify(mailSender).send(expected);
}
use of org.springframework.mail.SimpleMailMessage in project molgenis by molgenis.
the class FeedbackControllerTest method submitErrorWhileSendingMail.
@Test
public void submitErrorWhileSendingMail() throws Exception {
List<String> adminEmails = Collections.singletonList("molgenis@molgenis.org");
when(userService.getSuEmailAddresses()).thenReturn(adminEmails);
SimpleMailMessage expected = new SimpleMailMessage();
expected.setTo("molgenis@molgenis.org");
expected.setCc("user@domain.com");
expected.setReplyTo("user@domain.com");
expected.setSubject("[feedback-app123] Feedback form");
expected.setText("Feedback from First Last (user@domain.com):\n\n" + "Feedback.\nLine two.");
doThrow(new MailSendException("ERRORRR!")).when(mailSender).send(expected);
mockMvcFeedback.perform(MockMvcRequestBuilders.post(FeedbackController.URI).param("name", "First Last").param("subject", "Feedback form").param("email", "user@domain.com").param("feedback", "Feedback.\nLine two.").param("captcha", "validCaptcha")).andExpect(status().isOk()).andExpect(view().name("view-feedback")).andExpect(model().attribute("feedbackForm", hasProperty("submitted", equalTo(false)))).andExpect(model().attribute("feedbackForm", hasProperty("errorMessage", equalTo("Unfortunately, we were unable to send the mail containing " + "your feedback. Please contact the administrator."))));
verify(captchaService, times(1)).validateCaptcha("validCaptcha");
}
use of org.springframework.mail.SimpleMailMessage in project molgenis by molgenis.
the class AccountServiceImpl method activateUser.
@Override
@RunAsSystem
public void activateUser(String activationCode) {
User user = dataService.query(USER, User.class).eq(ACTIVE, false).and().eq(ACTIVATIONCODE, activationCode).findOne();
if (user != null) {
user.setActive(true);
dataService.update(USER, user);
// send activated email to user
SimpleMailMessage mailMessage = new SimpleMailMessage();
mailMessage.setTo(user.getEmail());
mailMessage.setSubject("Your registration request for " + appSettings.getTitle());
mailMessage.setText(createActivatedEmailText(user, appSettings.getTitle()));
mailSender.send(mailMessage);
} else {
throw new MolgenisUserException("Invalid activation code or account already activated.");
}
}
use of org.springframework.mail.SimpleMailMessage in project molgenis by molgenis.
the class AccountServiceImpl method resetPassword.
@Override
@RunAsSystem
public void resetPassword(String userEmail) {
User user = dataService.query(USER, User.class).eq(EMAIL, userEmail).findOne();
if (user != null) {
String newPassword = idGenerator.generateId(SHORT_SECURE_RANDOM);
user.setPassword(newPassword);
user.setChangePassword(true);
dataService.update(USER, user);
// send password reseted email to user
SimpleMailMessage mailMessage = new SimpleMailMessage();
mailMessage.setTo(user.getEmail());
mailMessage.setSubject("Your new password request");
mailMessage.setText(createPasswordResettedEmailText(newPassword));
mailSender.send(mailMessage);
} else {
throw new MolgenisUserException("Invalid email address.");
}
}
use of org.springframework.mail.SimpleMailMessage in project molgenis by molgenis.
the class ProgressImplTest method testMailSuccess.
@Test
public void testMailSuccess() {
jobExecution.setSuccessEmail("a@b.c,d@e.f");
progress.start();
progress.status("Working....");
progress.success();
System.out.println(jobExecution.getLog());
assertTrue(jobExecution.getLog().contains("- Execution started." + System.lineSeparator()));
assertTrue(jobExecution.getLog().contains("- Working...." + System.lineSeparator()));
assertTrue(jobExecution.getLog().contains("- Execution successful. Time spent: "));
SimpleMailMessage mail = new SimpleMailMessage();
mail.setTo(new String[] { "a@b.c", "d@e.f" });
mail.setSubject("Annotator job succeeded.");
mail.setText(jobExecution.getLog());
Mockito.verify(mailSender).send(mail);
}
Aggregations