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) {
}
}
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();
}
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());
}
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();
}
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();
}
Aggregations