Search in sources :

Example 6 with Order

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

the class PriceEngineImplTest method computePrice_ShouldThrowEx_whenOrderHasNoItems.

@Test
public void computePrice_ShouldThrowEx_whenOrderHasNoItems() {
    Order order = new Order();
    try {
        orderPriceEngine.computePrice(order);
        fail("Should have thrown ex");
    } catch (IllegalStateException e) {
    }
}
Also used : Order(org.rembx.jeeshop.order.model.Order) Test(org.junit.jupiter.api.Test)

Example 7 with Order

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

the class OrdersCT method create_shouldPersistOrderAndItsAddressesInCascade_SetCurrentUserToOrderForUserRole_AndProcessPayment.

@Test
public void create_shouldPersistOrderAndItsAddressesInCascade_SetCurrentUserToOrderForUserRole_AndProcessPayment() throws Exception {
    Address deliveryAddress = new Address("7 Rue des arbres", "Paris", "92800", "John", "Doe", "M.", null, "USA");
    Address billingAddress = new Address("8 Rue Toto", "Paris", "75001", "John", "Doe", "M.", null, "FRA");
    when(sessionContextMock.isUserInRole(JeeshopRoles.USER)).thenReturn(true);
    when(sessionContextMock.getUserPrincipal()).thenReturn(new BasicUserPrincipal(testOrder.firstOrdersUser().getLogin()));
    entityManager.getTransaction().begin();
    Order order = new Order(new HashSet<>(), new Address("7 Rue des arbres", "Paris", "92800", "John", "Doe", "M.", null, "USA"), new Address("8 Rue Toto", "Paris", "75001", "John", "Doe", "M.", null, "FRA"));
    order.setOrderDiscounts(new HashSet<>());
    service.create(sessionContextMock, order, null);
    entityManager.getTransaction().commit();
    verify(sessionContextMock).isUserInRole(JeeshopRoles.USER);
    // verify(mailerMock).sendMail(testMailTemplate.orderConfirmationMailTemplate().getSubject(), testOrder.firstOrdersUser().getLogin(), "<html><body>Hello M. John Doe. Your order has been registered...</body></html>");
    final Order persistedOrder = entityManager.find(Order.class, order.getId());
    assertThat(persistedOrder).isNotNull();
    assertThat(persistedOrder.getStatus()).isEqualTo(PAYMENT_VALIDATED);
    assertThat(persistedOrder.getUser()).isEqualTo(testOrder.firstOrdersUser());
    deliveryAddress.setId(persistedOrder.getDeliveryAddress().getId());
    billingAddress.setId(persistedOrder.getBillingAddress().getId());
    assertThat(persistedOrder.getBillingAddress()).isEqualTo(billingAddress);
    assertThat(persistedOrder.getDeliveryAddress()).isEqualTo(deliveryAddress);
    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) Address(org.rembx.jeeshop.user.model.Address) BasicUserPrincipal(org.apache.http.auth.BasicUserPrincipal) Test(org.junit.jupiter.api.Test)

Example 8 with Order

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

the class OrdersCT method findAll_whenClientHasUserRoleOnlyAndByLogin_shouldReturnSearchedOrder.

@Test
public void findAll_whenClientHasUserRoleOnlyAndByLogin_shouldReturnSearchedOrder() {
    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, testOrder.firstOrder().getUser().getLogin(), 0, 1, null, null, null, null, null);
    assertThat(orders).isNotEmpty();
    assertThat(orders).containsExactly(testOrder.firstOrder());
}
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 9 with Order

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

the class OrdersCT method create_shouldSetGivenUserByLoginInOrder_ForADMINRole.

@Test
public void create_shouldSetGivenUserByLoginInOrder_ForADMINRole() throws Exception {
    when(sessionContextMock.isUserInRole(JeeshopRoles.USER)).thenReturn(false);
    when(sessionContextMock.isUserInRole(JeeshopRoles.ADMIN)).thenReturn(true);
    entityManager.getTransaction().begin();
    Order order = new Order(new HashSet<>(), 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, "test@test.com");
    entityManager.getTransaction().commit();
    verify(sessionContextMock).isUserInRole(JeeshopRoles.USER);
    verify(sessionContextMock).isUserInRole(JeeshopRoles.ADMIN);
    final Order persistedOrder = entityManager.find(Order.class, order.getId());
    assertThat(persistedOrder).isNotNull();
    assertThat(persistedOrder.getStatus()).isEqualTo(PAYMENT_VALIDATED);
    assertThat(persistedOrder.getUser()).isEqualTo(testOrder.firstOrdersUser());
    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) Address(org.rembx.jeeshop.user.model.Address) Test(org.junit.jupiter.api.Test)

Example 10 with Order

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

the class OrdersCT method delete_shouldRemove.

@Test
public void delete_shouldRemove() {
    entityManager.getTransaction().begin();
    Order order = new Order();
    order.setUser(testUser.firstUser());
    order.setStatus(OrderStatus.VALIDATED);
    entityManager.persist(order);
    entityManager.getTransaction().commit();
    entityManager.getTransaction().begin();
    service.delete(order.getId());
    entityManager.getTransaction().commit();
    assertThat(entityManager.find(Order.class, order.getId())).isNull();
}
Also used : Order(org.rembx.jeeshop.order.model.Order) TestOrder(org.rembx.jeeshop.order.test.TestOrder) Test(org.junit.jupiter.api.Test)

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