Search in sources :

Example 11 with Order

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

the class OrdersCT method findAll_whenClientHasUserRoleOnlyAndByStatus_shouldReturnOrdersWithMatchingStatus.

@Test
public void findAll_whenClientHasUserRoleOnlyAndByStatus_shouldReturnOrdersWithMatchingStatus() {
    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.PAYMENT_VALIDATED, 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 12 with Order

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

the class OrdersCT method modifyUnknownCatalog_ShouldThrowNotFoundException.

@Test
public void modifyUnknownCatalog_ShouldThrowNotFoundException() {
    Order detachedOrder = new Order();
    detachedOrder.setId(9999L);
    try {
        service.modify(detachedOrder);
        fail("should have thrown ex");
    } catch (WebApplicationException e) {
        assertThat(e.getResponse().getStatusInfo()).isEqualTo(Response.Status.NOT_FOUND);
    }
}
Also used : Order(org.rembx.jeeshop.order.model.Order) TestOrder(org.rembx.jeeshop.order.test.TestOrder) WebApplicationException(org.rembx.jeeshop.rest.WebApplicationException) Test(org.junit.jupiter.api.Test)

Example 13 with Order

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

the class OrdersCT method findAll_whenClientHasUserRoleOnlyAndwithPagination_shouldReturnNoneEmptyListPaginated.

@Test
public void findAll_whenClientHasUserRoleOnlyAndwithPagination_shouldReturnNoneEmptyListPaginated() {
    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, 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 14 with Order

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

the class OrdersCT method find_withEnhanceResult_shouldReturnEnhancedOrder.

@Test
public void find_withEnhanceResult_shouldReturnEnhancedOrder() throws Exception {
    Order enhancedOrder = service.find(sessionContextMock, 1L, true);
    assertThat(enhancedOrder).isEqualTo(testOrder.firstOrder());
    assertThatOrderIsEnhanced(enhancedOrder);
}
Also used : Order(org.rembx.jeeshop.order.model.Order) TestOrder(org.rembx.jeeshop.order.test.TestOrder) Test(org.junit.jupiter.api.Test)

Example 15 with Order

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

the class OrdersCT method create_shouldThrowBadRequestWhenParametersHaveId.

@Test
public void create_shouldThrowBadRequestWhenParametersHaveId() throws Exception {
    Address address = new Address("7 Rue des arbres", "Paris", "92800", "John", "Doe", "M.", null, "USA");
    address.setId(777L);
    OrderItem orderItemWithId = new OrderItem();
    orderItemWithId.setId(777L);
    Set<OrderItem> orderItems = Collections.singleton(orderItemWithId);
    try {
        Order order = new Order(null, address, new Address("7 Rue des arbres", "Paris", "92800", "John", "Doe", "M.", null, "USA"));
        service.create(sessionContextMock, order, null);
        fail("should have thrown ex");
    } catch (WebApplicationException e) {
        assertThat(e.getResponse().getStatusInfo()).isEqualTo(Response.Status.BAD_REQUEST);
    }
    try {
        Order order = new Order(null, new Address("7 Rue des arbres", "Paris", "92800", "John", "Doe", "M.", null, "USA"), address);
        service.create(sessionContextMock, order, null);
        fail("should have thrown ex");
    } catch (WebApplicationException e) {
        assertThat(e.getResponse().getStatusInfo()).isEqualTo(Response.Status.BAD_REQUEST);
    }
    try {
        Order order = new Order(orderItems, new Address("7 Rue des arbres", "Paris", "92800", "John", "Doe", "M.", null, "USA"), address);
        service.create(sessionContextMock, order, null);
        fail("should have thrown ex");
    } catch (WebApplicationException e) {
        assertThat(e.getResponse().getStatusInfo()).isEqualTo(Response.Status.BAD_REQUEST);
    }
}
Also used : Order(org.rembx.jeeshop.order.model.Order) TestOrder(org.rembx.jeeshop.order.test.TestOrder) Address(org.rembx.jeeshop.user.model.Address) WebApplicationException(org.rembx.jeeshop.rest.WebApplicationException) OrderItem(org.rembx.jeeshop.order.model.OrderItem) 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