use of org.rembx.jeeshop.user.model.User in project jeeshop by remibantos.
the class UsersCT method resetPassword_shouldUpdateUserPasswordForAuthenticatedUser.
@Test
public void resetPassword_shouldUpdateUserPasswordForAuthenticatedUser() throws Exception {
User user = notActivatedTestUser();
when(sessionContextMock.isUserInRole(JeeshopRoles.USER)).thenReturn(true);
when(sessionContextMock.getUserPrincipal()).thenReturn(new BasicUserPrincipal(user.getLogin()));
service.resetPassword(sessionContextMock, user.getLogin(), null, "newPassword");
final User updatedUser = entityManager.find(User.class, user.getId());
assertThat(updatedUser).isNotNull();
assertThat(updatedUser.getPassword()).isEqualTo(hashSha256Base64("newPassword"));
verify(mailerMock).sendMail(testMailTemplate.changePasswordMailTpl().getSubject(), user.getLogin(), testMailTemplate.changePasswordMailTpl().getContent());
removeTestUser(user);
}
use of org.rembx.jeeshop.user.model.User in project jeeshop by remibantos.
the class UsersCT method create_shouldJustPersistEndUserEvenWhenExceptionDuringMailSending.
@Test
public void create_shouldJustPersistEndUserEvenWhenExceptionDuringMailSending() throws Exception {
User user = new User("register1@test.com", "test", "John", "Doe", "+33616161616", null, new Date(), "fr_FR", null);
user.setGender("M.");
Address address = new Address("7 blue street", "Nowhere", "00001", "John", "Doe", "M.", null, "FRA");
user.setAddress(address);
when(sessionContextMock.isUserInRole(JeeshopRoles.ADMIN)).thenReturn(false);
entityManager.getTransaction().begin();
service.create(sessionContextMock, user);
entityManager.getTransaction().commit();
doThrow(new IllegalStateException("Test Exception")).when(mailerMock).sendMail(testMailTemplate.userRegistrationMailTemplate().getSubject(), user.getLogin(), testMailTemplate.userRegistrationMailTemplate().getContent());
verify(sessionContextMock).isUserInRole(JeeshopRoles.ADMIN);
verify(mailerMock).sendMail(testMailTemplate.userRegistrationMailTemplate().getSubject(), user.getLogin(), "<html><body>Welcome M. John Doe</body></html>");
final User persistedUser = entityManager.find(User.class, user.getId());
assertThat(persistedUser).isNotNull();
assertThat(persistedUser.getAddress()).isEqualTo(address);
entityManager.remove(user);
}
use of org.rembx.jeeshop.user.model.User in project jeeshop by remibantos.
the class UsersCT method modify_ShouldThrowUnauthorizedError_WhenAuthenticatedUserDoesNotMatchLogin.
@Test
public void modify_ShouldThrowUnauthorizedError_WhenAuthenticatedUserDoesNotMatchLogin() throws Exception {
User detachedUserToModify = new User("test2@test.com", "test", "John", "Doe", "+33616161616", null, new Date(), "fr_FR", null);
try {
when(sessionContextMock.isUserInRole(JeeshopRoles.USER)).thenReturn(true);
when(sessionContextMock.getUserPrincipal()).thenReturn(new BasicUserPrincipal(testUser.firstUser().getLogin()));
service.modify(sessionContextMock, detachedUserToModify);
fail("should have thrown ex");
} catch (WebApplicationException e) {
assertThat(e.getResponse().getStatusInfo()).isEqualTo(Response.Status.UNAUTHORIZED);
}
}
use of org.rembx.jeeshop.user.model.User in project jeeshop by remibantos.
the class UsersCT method create_shouldThrowConflictExWhenUserWithGivenLoginAlreadyExists.
@Test
public void create_shouldThrowConflictExWhenUserWithGivenLoginAlreadyExists() throws Exception {
User user = new User();
user.setLogin("test@test.com");
try {
service.create(sessionContextMock, user);
fail("should have thrown ex");
} catch (WebApplicationException e) {
assertThat(e.getResponse().getStatusInfo()).isEqualTo(Response.Status.CONFLICT);
}
}
use of org.rembx.jeeshop.user.model.User in project jeeshop by remibantos.
the class UsersCT method activate_shouldActivateUserAndClearActionToken.
@Test
public void activate_shouldActivateUserAndClearActionToken() throws Exception {
User user = new User("activate1@test.com", "test", "John", "Doe", "+33616161616", null, new Date(), "fr_FR", null);
user.setGender("M.");
final UUID actionToken = UUID.randomUUID();
user.setActionToken(actionToken);
user.setActivated(false);
entityManager.getTransaction().begin();
entityManager.persist(user);
entityManager.getTransaction().commit();
service.activate(user.getLogin(), actionToken.toString());
final User modifiedUser = entityManager.find(User.class, user.getId());
assertThat(modifiedUser).isNotNull();
assertThat(modifiedUser.getActivated()).isTrue();
assertThat(modifiedUser.getActionToken()).isNull();
}
Aggregations