Search in sources :

Example 16 with Order

use of org.rembx.jeeshop.order.model.Order in project jeeshop by remibantos.

the class OrdersCT method findAll_whenClientHasUserRoleAndByStatusCREATED_shouldReturnOrdersWithThisStatus.

@Test
public void findAll_whenClientHasUserRoleAndByStatusCREATED_shouldReturnOrdersWithThisStatus() {
    when(sessionContextMock.isUserInRole(JeeshopRoles.USER)).thenReturn(true);
    when(sessionContextMock.isUserInRole(JeeshopRoles.ADMIN)).thenReturn(false);
    when(sessionContextMock.getUserPrincipal()).thenReturn(new BasicUserPrincipal(testOrder.firstOrdersUser().getLogin()));
    List<Order> orders = service.findAll(sessionContextMock, null, 0, 1, null, null, OrderStatus.CREATED, null, null);
    assertThat(orders).isNotEmpty();
    assertThat(orders).containsExactly(testOrder.secondOrder());
}
Also used : Order(org.rembx.jeeshop.order.model.Order) TestOrder(org.rembx.jeeshop.order.test.TestOrder) BasicUserPrincipal(org.apache.http.auth.BasicUserPrincipal) Test(org.junit.jupiter.api.Test)

Example 17 with Order

use of org.rembx.jeeshop.order.model.Order in project jeeshop by remibantos.

the class OrdersCT method create_shouldPersistOrderWithOrderItems_computePrice_andProcessPayment.

@Test
public void create_shouldPersistOrderWithOrderItems_computePrice_andProcessPayment() throws Exception {
    Set<OrderItem> orderItems = new HashSet<>();
    orderItems.add(new OrderItem(1L, 1L, 2));
    orderItems.add(new OrderItem(2L, 2L, 3));
    when(sessionContextMock.isUserInRole(JeeshopRoles.USER)).thenReturn(true);
    when(sessionContextMock.getUserPrincipal()).thenReturn(new BasicUserPrincipal(testOrder.firstOrdersUser().getLogin()));
    entityManager.getTransaction().begin();
    Order order = new Order(orderItems, new Address("7 Rue des arbres", "Paris", "92800", "John", "Doe", "M.", null, "USA"), new Address("7 Rue des arbres", "Paris", "92800", "John", "Doe", "M.", null, "USA"));
    order.setOrderDiscounts(new HashSet<>());
    service.create(sessionContextMock, order, null);
    entityManager.getTransaction().commit();
    verify(sessionContextMock).isUserInRole(JeeshopRoles.USER);
    verify(priceEngineMock).computePrice(order);
    final Order persistedOrder = entityManager.find(Order.class, order.getId());
    assertThat(persistedOrder).isNotNull();
    assertThat(persistedOrder.getStatus()).isEqualTo(PAYMENT_VALIDATED);
    assertThat(persistedOrder.getUser()).isEqualTo(testOrder.firstOrdersUser());
    assertThat(persistedOrder.getItems()).hasSize(2);
    entityManager.getTransaction().begin();
    entityManager.remove(order);
    entityManager.getTransaction().commit();
}
Also used : Order(org.rembx.jeeshop.order.model.Order) TestOrder(org.rembx.jeeshop.order.test.TestOrder) BasicUserPrincipal(org.apache.http.auth.BasicUserPrincipal) Address(org.rembx.jeeshop.user.model.Address) OrderItem(org.rembx.jeeshop.order.model.OrderItem) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 18 with Order

use of org.rembx.jeeshop.order.model.Order in project jeeshop by remibantos.

the class Orders method delete.

@DELETE
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@RolesAllowed(ADMIN)
@Path("/{orderId}")
public void delete(@PathParam("orderId") Long orderId) {
    Order order = entityManager.find(Order.class, orderId);
    checkNotNull(order);
    entityManager.remove(order);
}
Also used : Order(org.rembx.jeeshop.order.model.Order) RolesAllowed(javax.annotation.security.RolesAllowed)

Example 19 with Order

use of org.rembx.jeeshop.order.model.Order in project jeeshop by remibantos.

the class Orders method modify.

@PUT
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@RolesAllowed(ADMIN)
public Order modify(@NotNull Order order) {
    Order existingOrder = entityManager.find(Order.class, order.getId());
    checkNotNull(existingOrder);
    order.setUser(existingOrder.getUser());
    order.getItems().forEach(orderItem -> orderItem.setOrder(order));
    return entityManager.merge(order);
}
Also used : Order(org.rembx.jeeshop.order.model.Order) RolesAllowed(javax.annotation.security.RolesAllowed)

Aggregations

Order (org.rembx.jeeshop.order.model.Order)19 Test (org.junit.jupiter.api.Test)14 TestOrder (org.rembx.jeeshop.order.test.TestOrder)11 BasicUserPrincipal (org.apache.http.auth.BasicUserPrincipal)6 OrderItem (org.rembx.jeeshop.order.model.OrderItem)5 Address (org.rembx.jeeshop.user.model.Address)5 RolesAllowed (javax.annotation.security.RolesAllowed)4 WebApplicationException (org.rembx.jeeshop.rest.WebApplicationException)4 HashSet (java.util.HashSet)3 SKU (org.rembx.jeeshop.catalog.model.SKU)2 User (org.rembx.jeeshop.user.model.User)2 EntityManager (javax.persistence.EntityManager)1