Search in sources :

Example 16 with User

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);
    }
}
Also used : TestUser(org.rembx.jeeshop.user.test.TestUser) User(org.rembx.jeeshop.user.model.User) WebApplicationException(org.rembx.jeeshop.rest.WebApplicationException) Test(org.junit.jupiter.api.Test)

Example 17 with User

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);
}
Also used : TestUser(org.rembx.jeeshop.user.test.TestUser) User(org.rembx.jeeshop.user.model.User) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Example 18 with 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);
}
Also used : TestUser(org.rembx.jeeshop.user.test.TestUser) User(org.rembx.jeeshop.user.model.User) Test(org.junit.jupiter.api.Test)

Example 19 with 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);
    }
}
Also used : TestUser(org.rembx.jeeshop.user.test.TestUser) User(org.rembx.jeeshop.user.model.User) Address(org.rembx.jeeshop.user.model.Address) WebApplicationException(org.rembx.jeeshop.rest.WebApplicationException) Test(org.junit.jupiter.api.Test)

Example 20 with User

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);
    }
}
Also used : TestUser(org.rembx.jeeshop.user.test.TestUser) User(org.rembx.jeeshop.user.model.User) Address(org.rembx.jeeshop.user.model.Address) WebApplicationException(org.rembx.jeeshop.rest.WebApplicationException) Test(org.junit.jupiter.api.Test)

Aggregations

User (org.rembx.jeeshop.user.model.User)28 Test (org.junit.jupiter.api.Test)18 TestUser (org.rembx.jeeshop.user.test.TestUser)18 Date (java.util.Date)9 WebApplicationException (org.rembx.jeeshop.rest.WebApplicationException)9 RolesAllowed (javax.annotation.security.RolesAllowed)4 BasicUserPrincipal (org.apache.http.auth.BasicUserPrincipal)3 Address (org.rembx.jeeshop.user.model.Address)3 UUID (java.util.UUID)2 GET (javax.ws.rs.GET)2 Produces (javax.ws.rs.Produces)2 Order (org.rembx.jeeshop.order.model.Order)2 JPAQueryFactory (com.querydsl.jpa.impl.JPAQueryFactory)1 Configuration (freemarker.template.Configuration)1 Template (freemarker.template.Template)1 StringWriter (java.io.StringWriter)1 Discount (org.rembx.jeeshop.catalog.model.Discount)1 Product (org.rembx.jeeshop.catalog.model.Product)1 SKU (org.rembx.jeeshop.catalog.model.SKU)1 MailTemplate (org.rembx.jeeshop.user.model.MailTemplate)1