Search in sources :

Example 11 with User

use of org.rembx.jeeshop.user.model.User in project jeeshop by remibantos.

the class UsersCT method modifyUser_ShouldModifyUser.

@Test
public void modifyUser_ShouldModifyUser() {
    User detachedUserToModify = new User("test2@test.com", "test", "John", "Doe", "+33616161616", null, new Date(), "fr_FR", null);
    detachedUserToModify.setId(testUser.firstUser().getId());
    service.modify(sessionContextMock, detachedUserToModify);
}
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 12 with User

use of org.rembx.jeeshop.user.model.User in project jeeshop by remibantos.

the class UsersCT method delete_shouldRemove.

@Test
public void delete_shouldRemove() {
    entityManager.getTransaction().begin();
    User user = new User("test4@test.com", "test", "John", "Doe", "+33616161616", null, new Date(), "fr_FR", null);
    user.setGender("M.");
    entityManager.persist(user);
    entityManager.getTransaction().commit();
    entityManager.getTransaction().begin();
    service.delete(user.getId());
    entityManager.getTransaction().commit();
    assertThat(entityManager.find(User.class, user.getId())).isNull();
}
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 13 with User

use of org.rembx.jeeshop.user.model.User in project jeeshop by remibantos.

the class EligibleDiscounts method findEligible.

@GET
@Produces(MediaType.APPLICATION_JSON)
@RolesAllowed(JeeshopRoles.USER)
public List<Discount> findEligible(@QueryParam("locale") String locale) {
    User currentUser = userFinder.findByLogin(sessionContext.getCallerPrincipal().getName());
    Long completedOrders = orderFinder.countUserCompletedOrders(currentUser);
    return discountFinder.findEligibleOrderDiscounts(locale, completedOrders);
}
Also used : User(org.rembx.jeeshop.user.model.User) RolesAllowed(javax.annotation.security.RolesAllowed) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 14 with User

use of org.rembx.jeeshop.user.model.User in project jeeshop by remibantos.

the class Orders method assignOrderToUser.

private void assignOrderToUser(Order order, String userLogin) {
    User user;
    if (sessionContext.isCallerInRole(USER)) {
        user = userFinder.findByLogin(sessionContext.getCallerPrincipal().getName());
        order.setUser(user);
    }
    if (sessionContext.isCallerInRole(ADMIN)) {
        user = userFinder.findByLogin(userLogin);
        order.setUser(user);
    }
}
Also used : User(org.rembx.jeeshop.user.model.User)

Example 15 with User

use of org.rembx.jeeshop.user.model.User in project jeeshop by remibantos.

the class OrdersCT method find_whenClientHasUserRoleAndOrderBelongsToAnotherUser_ShouldThrowException.

@Test
public void find_whenClientHasUserRoleAndOrderBelongsToAnotherUser_ShouldThrowException() throws Exception {
    entityManager.getTransaction().begin();
    User user = new User("777@test.com", "test", "M.", "John", "Doe", "+33616161616", null, null, "fr_FR", null);
    entityManager.persist(user);
    entityManager.getTransaction().commit();
    when(sessionContextMock.isUserInRole(JeeshopRoles.USER)).thenReturn(true);
    when(sessionContextMock.isUserInRole(JeeshopRoles.ADMIN)).thenReturn(false);
    when(sessionContextMock.getUserPrincipal()).thenReturn(new BasicUserPrincipal("777@test.com"));
    try {
        service.find(sessionContextMock, 1L, null);
        fail("should have thrown ex");
    } catch (WebApplicationException e) {
        assertThat(e.getResponse().getStatusInfo()).isEqualTo(Response.Status.UNAUTHORIZED);
    } finally {
        entityManager.getTransaction().begin();
        entityManager.remove(user);
        entityManager.persist(user);
    }
}
Also used : TestUser(org.rembx.jeeshop.user.test.TestUser) User(org.rembx.jeeshop.user.model.User) BasicUserPrincipal(org.apache.http.auth.BasicUserPrincipal) 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