use of org.broadleafcommerce.core.order.domain.OrderItem in project BroadleafCommerce by BroadleafCommerce.
the class OrderTest method updateItemsInOrder.
@Test(groups = { "updateItemsInOrder" }, dependsOnGroups = { "getItemsForOrder" })
@Transactional
public void updateItemsInOrder() throws UpdateCartException, RemoveFromCartException {
// Grab the order and the first OrderItem
Order order = orderService.findOrderById(orderId);
List<OrderItem> orderItems = order.getOrderItems();
assert orderItems.size() > 0;
OrderItem item = orderItems.get(0);
// Set the quantity of the first OrderItem to 10
OrderItemRequestDTO orderItemRequestDTO = new OrderItemRequestDTO();
orderItemRequestDTO.setOrderItemId(item.getId());
orderItemRequestDTO.setQuantity(10);
order = orderService.updateItemQuantity(order.getId(), orderItemRequestDTO, true);
// Assert that the quantity has changed
OrderItem updatedItem = orderItemService.readOrderItemById(item.getId());
assert updatedItem != null;
assert updatedItem.getQuantity() == 10;
// Assert that the appropriate fulfillment group item has changed
assert order.getFulfillmentGroups().size() == 1;
FulfillmentGroup fg = order.getFulfillmentGroups().get(0);
assert fg.getFulfillmentGroupItems().size() == 1;
boolean fgItemUpdated = false;
for (FulfillmentGroupItem fgi : fg.getFulfillmentGroupItems()) {
if (fgi.getOrderItem().equals(updatedItem)) {
assert fgi.getQuantity() == 10;
fgItemUpdated = true;
}
}
assert fgItemUpdated;
// Set the quantity of the first OrderItem to 5
orderItemRequestDTO = new OrderItemRequestDTO();
orderItemRequestDTO.setOrderItemId(item.getId());
orderItemRequestDTO.setQuantity(5);
order = orderService.updateItemQuantity(order.getId(), orderItemRequestDTO, true);
// Assert that the quantity has changed - going to a smaller quantity is also ok
updatedItem = orderItemService.readOrderItemById(item.getId());
assert updatedItem != null;
assert updatedItem.getQuantity() == 5;
// Assert that the appropriate fulfillment group item has changed
assert order.getFulfillmentGroups().size() == 1;
fg = order.getFulfillmentGroups().get(0);
assert fg.getFulfillmentGroupItems().size() == 1;
fgItemUpdated = false;
for (FulfillmentGroupItem fgi : fg.getFulfillmentGroupItems()) {
if (fgi.getOrderItem().equals(updatedItem)) {
assert fgi.getQuantity() == 5;
fgItemUpdated = true;
}
}
assert fgItemUpdated;
// Setting the quantity to 0 should in fact remove the item completely
int startingSize = order.getOrderItems().size();
orderItemRequestDTO = new OrderItemRequestDTO();
orderItemRequestDTO.setOrderItemId(item.getId());
orderItemRequestDTO.setQuantity(0);
order = orderService.updateItemQuantity(order.getId(), orderItemRequestDTO, true);
// Assert that the item has been removed
updatedItem = orderItemService.readOrderItemById(item.getId());
assert updatedItem == null;
assert order.getOrderItems().size() == startingSize - 1;
// Assert that the appropriate fulfillment group item has been removed
assert order.getFulfillmentGroups().size() == 0;
/*
TODO Since we commented out some tests above, there is no longer an additional item
in the cart, hence the fulfillment group is removed
fg = order.getFulfillmentGroups().get(0);
assert fg.getFulfillmentGroupItems().size() == startingSize - 1;
boolean fgItemRemoved = true;
for (FulfillmentGroupItem fgi : fg.getFulfillmentGroupItems()) {
if (fgi.getOrderItem().equals(updatedItem)) {
fgItemRemoved = false;
}
}
assert fgItemRemoved;*/
}
use of org.broadleafcommerce.core.order.domain.OrderItem in project BroadleafCommerce by BroadleafCommerce.
the class OrderTest method testIllegalUpdateScenarios.
@Test(groups = { "testIllegalUpdateScenarios" }, dependsOnGroups = { "addItemToOrder" })
@Transactional
public void testIllegalUpdateScenarios() throws UpdateCartException, AddToCartException, RemoveFromCartException {
Order order = orderService.findOrderById(orderId);
assert order != null;
Product activeProduct = addTestProduct("mug", "cups", true);
Product inactiveProduct = addTestProduct("cup", "cups", false);
// Inactive skus should not be added
OrderItemRequestDTO itemRequest = new OrderItemRequestDTO().setQuantity(1).setSkuId(activeProduct.getDefaultSku().getId());
boolean addSuccessful = true;
try {
order = orderService.addItem(orderId, itemRequest, true);
} catch (AddToCartException e) {
addSuccessful = false;
}
assert addSuccessful;
// should not be able to update to negative quantity
OrderItem item = orderService.findLastMatchingItem(order, activeProduct.getDefaultSku().getId(), activeProduct.getId());
itemRequest = new OrderItemRequestDTO().setQuantity(-3).setOrderItemId(item.getId());
boolean updateSuccessful = true;
try {
orderService.updateItemQuantity(orderId, itemRequest, true);
} catch (UpdateCartException e) {
updateSuccessful = false;
}
assert !updateSuccessful;
// shouldn't be able to update the quantity of a DOI inside of a bundle
ProductBundle bundle = addProductBundle();
itemRequest = new OrderItemRequestDTO().setQuantity(1).setProductId(bundle.getId()).setSkuId(bundle.getDefaultSku().getId());
addSuccessful = true;
try {
order = orderService.addItem(orderId, itemRequest, true);
} catch (AddToCartException e) {
addSuccessful = false;
}
assert addSuccessful;
BundleOrderItem bundleItem = (BundleOrderItem) orderService.findLastMatchingItem(order, bundle.getDefaultSku().getId(), bundle.getId());
// should just be a single DOI inside the bundle
DiscreteOrderItem doi = bundleItem.getDiscreteOrderItems().get(0);
itemRequest = new OrderItemRequestDTO().setQuantity(4).setOrderItemId(doi.getId());
try {
orderService.updateItemQuantity(orderId, itemRequest, true);
} catch (UpdateCartException e) {
updateSuccessful = false;
}
assert !updateSuccessful;
}
use of org.broadleafcommerce.core.order.domain.OrderItem in project BroadleafCommerce by BroadleafCommerce.
the class OrderTest method removeItemFromOrder.
@Test(groups = { "removeItemFromOrder" }, dependsOnGroups = { "getItemsForOrder" })
@Transactional
public void removeItemFromOrder() throws RemoveFromCartException {
// Grab the order and the first OrderItem
Order order = orderService.findOrderById(orderId);
List<OrderItem> orderItems = order.getOrderItems();
assert orderItems.size() > 0;
int startingSize = orderItems.size();
OrderItem item = orderItems.get(0);
Long itemId = item.getId();
assert item != null;
// Remove the item
order = orderService.removeItem(order.getId(), item.getId(), true);
List<OrderItem> items = order.getOrderItems();
OrderItem updatedItem = orderItemService.readOrderItemById(item.getId());
// Assert that the item has been removed
assert items != null;
assert items.size() == startingSize - 1;
assert updatedItem == null;
}
use of org.broadleafcommerce.core.order.domain.OrderItem in project BroadleafCommerce by BroadleafCommerce.
the class OrderTest method removeBundleFromOrder.
@Test(groups = { "removeBundleFromOrder" }, dependsOnGroups = { "addBundleToOrder" })
@Rollback(false)
@Transactional
public void removeBundleFromOrder() throws RemoveFromCartException {
Order order = orderService.findOrderById(orderId);
List<OrderItem> orderItems = order.getOrderItems();
assert orderItems.size() == numOrderItems;
int startingSize = orderItems.size();
BundleOrderItem bundleOrderItem = (BundleOrderItem) orderItemService.readOrderItemById(bundleOrderItemId);
assert bundleOrderItem != null;
assert bundleOrderItem.getDiscreteOrderItems() != null;
assert bundleOrderItem.getDiscreteOrderItems().size() == 1;
order = orderService.removeItem(order.getId(), bundleOrderItem.getId(), true);
List<OrderItem> items = order.getOrderItems();
assert items != null;
assert items.size() == startingSize - 1;
}
use of org.broadleafcommerce.core.order.domain.OrderItem in project BroadleafCommerce by BroadleafCommerce.
the class OrderTest method getItemsForOrder.
@Test(groups = { "getItemsForOrder" }, dependsOnGroups = { "removeBundleFromOrder" })
@Transactional
public void getItemsForOrder() {
Order order = orderService.findOrderById(orderId);
List<OrderItem> orderItems = order.getOrderItems();
assert orderItems != null;
assert orderItems.size() == numOrderItems - 1;
}
Aggregations