use of org.rembx.jeeshop.user.model.User in project jeeshop by remibantos.
the class UsersCT method create_shouldThrowBadRequestExWhenUserHasAnId.
@Test
public void create_shouldThrowBadRequestExWhenUserHasAnId() throws Exception {
User user = new User();
user.setId(777L);
try {
service.create(sessionContextMock, user);
fail("should have thrown ex");
} catch (WebApplicationException e) {
assertThat(e.getResponse().getStatusInfo()).isEqualTo(Response.Status.BAD_REQUEST);
}
}
use of org.rembx.jeeshop.user.model.User in project jeeshop by remibantos.
the class UsersCT method create_shouldPersistEndUserAndRetrieveUserRegistrationMailTemplateAndSendMail.
@Test
public void create_shouldPersistEndUserAndRetrieveUserRegistrationMailTemplateAndSendMail() throws Exception {
User user = new User("register3@test.com", "test", "John", "Doe", "+33616161616", null, new Date(), "fr_FR", null);
user.setGender("M.");
when(sessionContextMock.isUserInRole(JeeshopRoles.ADMIN)).thenReturn(false);
entityManager.getTransaction().begin();
service.create(sessionContextMock, user);
entityManager.getTransaction().commit();
verify(sessionContextMock).isUserInRole(JeeshopRoles.ADMIN);
verify(mailerMock).sendMail(testMailTemplate.userRegistrationMailTemplate().getSubject(), user.getLogin(), "<html><body>Welcome M. John Doe</body></html>");
assertThat(entityManager.find(User.class, user.getId())).isNotNull();
assertThat(user.getActivated()).isFalse();
assertThat(user.getActionToken()).isNotNull();
entityManager.remove(user);
}
use of org.rembx.jeeshop.user.model.User in project jeeshop by remibantos.
the class UsersCT method resetPassword_shouldUpdateUserPasswordForAuthenticatedADMINUser.
@Test
public void resetPassword_shouldUpdateUserPasswordForAuthenticatedADMINUser() throws Exception {
User user = notActivatedTestUser();
when(sessionContextMock.isUserInRole(JeeshopRoles.ADMIN)).thenReturn(true);
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_shouldThrowBadRequestExceptionExWhenUserAddressHasAnId.
@Test
public void create_shouldThrowBadRequestExceptionExWhenUserAddressHasAnId() throws Exception {
User user = new User();
user.setLogin("toto@toto.com");
Address address = new Address();
address.setId(1L);
user.setAddress(address);
try {
service.create(sessionContextMock, user);
fail("should have thrown ex");
} catch (WebApplicationException e) {
assertThat(e.getResponse().getStatusInfo()).isEqualTo(Response.Status.BAD_REQUEST);
}
}
use of org.rembx.jeeshop.user.model.User in project jeeshop by remibantos.
the class UsersCT method create_shouldThrowBadRequestExceptionExWhenUsersCountryIsNotAvailable.
@Test
public void create_shouldThrowBadRequestExceptionExWhenUsersCountryIsNotAvailable() throws Exception {
User user = new User();
user.setLogin("toto@toto.com");
Address address = new Address();
address.setCountryIso3Code("ZZZ");
user.setAddress(address);
try {
service.create(sessionContextMock, user);
fail("should have thrown ex");
} catch (WebApplicationException e) {
assertThat(e.getResponse().getStatusInfo()).isEqualTo(Response.Status.BAD_REQUEST);
}
}
Aggregations