Search in sources :

Example 6 with Address

use of org.rembx.jeeshop.user.model.Address 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 7 with Address

use of org.rembx.jeeshop.user.model.Address 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 8 with Address

use of org.rembx.jeeshop.user.model.Address 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

Address (org.rembx.jeeshop.user.model.Address)8 Test (org.junit.jupiter.api.Test)7 Order (org.rembx.jeeshop.order.model.Order)5 TestOrder (org.rembx.jeeshop.order.test.TestOrder)4 OrderItem (org.rembx.jeeshop.order.model.OrderItem)3 WebApplicationException (org.rembx.jeeshop.rest.WebApplicationException)3 User (org.rembx.jeeshop.user.model.User)3 TestUser (org.rembx.jeeshop.user.test.TestUser)3 BasicUserPrincipal (org.apache.http.auth.BasicUserPrincipal)2 Date (java.util.Date)1 HashSet (java.util.HashSet)1 EntityManager (javax.persistence.EntityManager)1