use of org.rembx.jeeshop.order.model.Order in project jeeshop by remibantos.
the class Orders method find.
@GET
@Path("/{orderId}")
@Produces(MediaType.APPLICATION_JSON)
@RolesAllowed({ ADMIN, ADMIN_READONLY, USER })
public Order find(@PathParam("orderId") @NotNull Long orderId, @QueryParam("enhanced") Boolean enhanced) {
Order order = entityManager.find(Order.class, orderId);
if (sessionContext.isCallerInRole(USER) && !sessionContext.isCallerInRole(ADMIN)) {
User authenticatedUser = userFinder.findByLogin(sessionContext.getCallerPrincipal().getName());
if (!order.getUser().equals(authenticatedUser)) {
throw new WebApplicationException(Response.Status.UNAUTHORIZED);
}
}
if (enhanced != null && enhanced) {
orderFinder.enhanceOrder(order);
}
checkNotNull(order);
return order;
}
use of org.rembx.jeeshop.order.model.Order in project jeeshop by remibantos.
the class Orders method find.
@GET
@Path("/{orderId}")
@Produces(MediaType.APPLICATION_JSON)
@RolesAllowed({ ADMIN, ADMIN_READONLY, USER })
public Order find(@Context SecurityContext securityContext, @PathParam("orderId") @NotNull Long orderId, @QueryParam("enhanced") Boolean enhanced) {
Order order = entityManager.find(Order.class, orderId);
if (securityContext.isUserInRole(USER) && !securityContext.isUserInRole(ADMIN)) {
User authenticatedUser = userFinder.findByLogin(securityContext.getUserPrincipal().getName());
if (!order.getUser().equals(authenticatedUser)) {
throw new WebApplicationException(Response.Status.UNAUTHORIZED);
}
}
if (enhanced != null && enhanced) {
orderFinder.enhanceOrder(order);
}
checkNotNull(order);
return order;
}
use of org.rembx.jeeshop.order.model.Order in project jeeshop by remibantos.
the class TestOrder method getInstance.
public static TestOrder getInstance() {
if (instance != null)
return instance;
testUser = TestUser.getInstance();
EntityManager entityManager = Persistence.createEntityManagerFactory(UserPersistenceUnit.NAME).createEntityManager();
entityManager.getTransaction().begin();
Address deliveryAddress = new Address("21 Blue street", "Chicago", "78801", "John", "Doe", "M.", null, "FRA");
Address billingAddress = new Address("53 Green street", "Chicago", "78801", "John", "Doe", "M.", null, "FRA");
entityManager.persist(deliveryAddress);
entityManager.persist(billingAddress);
order1 = new Order(testUser.firstUser(), null, deliveryAddress, billingAddress, OrderStatus.PAYMENT_VALIDATED);
orderItem1 = new OrderItem(1L, 1L, 2);
orderItem1.setOrder(order1);
order1.setItems(Sets.newHashSet(orderItem1));
entityManager.persist(order1);
order2 = new Order(testUser.firstUser(), null, null, null, OrderStatus.CREATED);
entityManager.persist(order2);
entityManager.getTransaction().commit();
instance = new TestOrder();
entityManager.close();
return instance;
}
use of org.rembx.jeeshop.order.model.Order in project jeeshop by remibantos.
the class PriceEngineImplTest method computePrice_ShouldAddPriceOfEachOrderItemsMultipliedByQuantityWithFixedDeliveryFee.
@Test
public void computePrice_ShouldAddPriceOfEachOrderItemsMultipliedByQuantityWithFixedDeliveryFee() {
SKU sku = new SKU();
sku.setPrice(10.0);
SKU sku2 = new SKU();
sku2.setPrice(20.0);
when(entityManager.find(SKU.class, 1L)).thenReturn(sku);
when(entityManager.find(SKU.class, 2L)).thenReturn(sku2);
when(orderConfiguration.getFixedDeliveryFee()).thenReturn(11.0);
Order order = new Order();
Set<OrderItem> items = new HashSet<>();
items.add(new OrderItem(1L, 1L, 1));
items.add(new OrderItem(2L, 2L, 2));
order.setItems(items);
orderPriceEngine.computePrice(order);
verify(entityManager).find(SKU.class, 1L);
verify(entityManager).find(SKU.class, 2L);
verify(orderConfiguration).getFixedDeliveryFee();
assertThat(order.getPrice()).isEqualTo(61.0);
}
use of org.rembx.jeeshop.order.model.Order in project jeeshop by remibantos.
the class PriceEngineImplTest method computePrice_ShouldAddPriceOfEachOrderItemsMultipliedByQuantity.
@Test
public void computePrice_ShouldAddPriceOfEachOrderItemsMultipliedByQuantity() {
SKU sku = new SKU();
sku.setPrice(10.0);
SKU sku2 = new SKU();
sku2.setPrice(20.0);
when(entityManager.find(SKU.class, 1L)).thenReturn(sku);
when(entityManager.find(SKU.class, 2L)).thenReturn(sku2);
when(orderConfiguration.getFixedDeliveryFee()).thenReturn(null);
Order order = new Order();
Set<OrderItem> items = new HashSet<>();
items.add(new OrderItem(1L, 1L, 1));
items.add(new OrderItem(2L, 2L, 2));
order.setItems(items);
orderPriceEngine.computePrice(order);
verify(entityManager).find(SKU.class, 1L);
verify(entityManager).find(SKU.class, 2L);
verify(orderConfiguration).getFixedDeliveryFee();
assertThat(order.getPrice()).isEqualTo(50.0);
for (OrderItem item : order.getItems()) {
if (item.getSkuId().equals(1L))
assertThat(item.getPrice()).isEqualTo(10.0);
else
assertThat(item.getPrice()).isEqualTo(20.0);
}
}
Aggregations