use of org.simbasecurity.core.domain.user.EmailAddress in project simba-os by cegeka.
the class ResetPasswordServiceTest method sendMessageForNewUser_WillTriggerAuditloggingForNewUser.
@Test
public void sendMessageForNewUser_WillTriggerAuditloggingForNewUser() throws Exception {
EmailAddress email = emailFactory.email("something@mail.com");
User user = aDefaultUser().withUserName("otherTest").withEmail(email).withLanguage(en_US).build();
Token token = Token.generateToken();
when(tokenManagerMock.generateToken(user, newUserReason)).thenReturn(token);
URL link = new URL("http://www.google.com");
List<URL> links = Collections.singletonList(link);
when(linkGeneratorMock.generateResetPasswordLinks(email, token)).thenReturn(links);
when(templateServiceMock.createMailBodyWithLink(new TemplateWithLinks(newUserReason.getTemplate(), links), en_US)).thenReturn("someBody");
when(templateServiceMock.createMailSubject(newUserReason.getSubjectTemplate(), en_US)).thenReturn("New user");
ArgumentCaptor<AuditLogEvent> logCaptor = ArgumentCaptor.forClass(AuditLogEvent.class);
resetPasswordService.sendResetPasswordMessageTo(user, newUserReason);
verify(mailServiceMock).sendMail(mail().from(emailFactory.email("bla@hotmail.com")).to(email).subject("New user").body("someBody"));
verify(auditMock).log(logCaptor.capture());
assertThat(logCaptor.getValue()).extracting(AuditLogEvent::getUsername, AuditLogEvent::getMessage, AuditLogEvent::getCategory).containsExactly("otherTest", "Email has been sent to user for following reason: NewUser", AUTHENTICATION);
}
use of org.simbasecurity.core.domain.user.EmailAddress in project simba-os by cegeka.
the class UserDatabaseRepositoryTest method findUserByMail_WillReturnUser_IfPresentInDatabase.
@Test
public void findUserByMail_WillReturnUser_IfPresentInDatabase() throws Exception {
EmailAddress email = emailFactory.email("alfred@wayneindustries.com");
User expectedUser = aDefaultUser().withEmail(email).build();
persistAndRefresh(expectedUser);
User user = userDatabaseRepository.findByEmail(email);
Assertions.assertThat(user).isEqualTo(expectedUser);
}
use of org.simbasecurity.core.domain.user.EmailAddress in project simba-os by cegeka.
the class UserDatabaseRepositoryTest method findUserByMailCaseInsensitive_WillReturnUser_IfPresentInDatabase.
@Test
public void findUserByMailCaseInsensitive_WillReturnUser_IfPresentInDatabase() throws Exception {
EmailAddress email = emailFactory.email("alfred@wayneindustries.com");
EmailAddress otherEmail = emailFactory.email("Alfred@WayneIndustries.com");
User expectedUser = aDefaultUser().withEmail(email).build();
persistAndRefresh(expectedUser);
User user = userDatabaseRepository.findByEmail(otherEmail);
Assertions.assertThat(user).isEqualTo(expectedUser);
}
use of org.simbasecurity.core.domain.user.EmailAddress in project simba-os by cegeka.
the class CredentialServiceImplTest method findUserByMail_NoUserFoundForGivenEmail_ReturnsEmptyOptional.
@Test
public void findUserByMail_NoUserFoundForGivenEmail_ReturnsEmptyOptional() throws Exception {
EmailAddress email = emailFactory.email("bruce@wayneindustries.com");
when(mockUserRepository.findByEmail(email)).thenReturn(null);
Optional<User> maybeUser = credentialService.findUserByMail(email);
assertThat(maybeUser).isEmpty();
}
use of org.simbasecurity.core.domain.user.EmailAddress in project simba-os by cegeka.
the class UserDatabaseRepositoryTest method findUserByMail_WillReturnUser_IfPresentInDatabase_AndActiveOrBlocked.
@Test
public void findUserByMail_WillReturnUser_IfPresentInDatabase_AndActiveOrBlocked() throws Exception {
EmailAddress email = emailFactory.email("alfred@wayneindustries.com");
User expectedUser = aDefaultUser().withEmail(email).withStatus(Status.ACTIVE).build();
persistAndRefresh(expectedUser);
User user = userDatabaseRepository.findByEmail(email);
Assertions.assertThat(user).isEqualTo(expectedUser);
}
Aggregations