EasyMock.expect(multishipOptionServiceMock.findOrderMultishipOptions(EasyMock.isA(Long.class))).andAnswer(new IAnswer<List<OrderMultishipOption>>() {
@Override
public List<OrderMultishipOption> answer() throws Throwable {
List<OrderMultishipOption> options = new ArrayList<OrderMultishipOption>();
PromotableOrder order = dataProvider.createBasicPromotableOrder();
for (FulfillmentGroup fg : order.getOrder().getFulfillmentGroups()) {
Address address = fg.getAddress();
for (FulfillmentGroupItem fgItem : fg.getFulfillmentGroupItems()) {
for (int j=0;j<fgItem.getQuantity();j++) {
OrderMultishipOption option = new OrderMultishipOptionImpl();
option.setOrder(order.getOrder());
option.setAddress(address);
option.setOrderItem(fgItem.getOrderItem());
options.add(option);
}
}
}
return options;
}
}).anyTimes();
multishipOptionServiceMock.deleteAllOrderMultishipOptions(EasyMock.isA(Order.class));
EasyMock.expectLastCall().anyTimes();
EasyMock.expect(fgServiceMock.collapseToOneShippableFulfillmentGroup(EasyMock.isA(Order.class), EasyMock.eq(false))).andAnswer(new IAnswer<Order>() {
@Override
public Order answer() throws Throwable {
Order order = (Order) EasyMock.getCurrentArguments()[0];
order.getFulfillmentGroups().get(0).getFulfillmentGroupItems().addAll(order.getFulfillmentGroups().get(1).getFulfillmentGroupItems());
order.getFulfillmentGroups().remove(order.getFulfillmentGroups().get(1));
return order;
}
}).anyTimes();
EasyMock.expect(fgItemDaoMock.create()).andAnswer(OfferDataItemProvider.getCreateFulfillmentGroupItemAnswer()).anyTimes();
fgItemDaoMock.delete(EasyMock.isA(FulfillmentGroupItem.class));
EasyMock.expectLastCall().anyTimes();
EasyMock.expect(offerTimeZoneProcessorMock.getTimeZone(EasyMock.isA(OfferImpl.class))).andReturn(TimeZone.getTimeZone("CST")).anyTimes();
replay();
PromotableOrder promotableOrder = dataProvider.createBasicPromotableOrder();
Order order = promotableOrder.getOrder();
myOrder.set(promotableOrder.getOrder());
List<PromotableCandidateFulfillmentGroupOffer> qualifiedOffers = new ArrayList<PromotableCandidateFulfillmentGroupOffer>();
List<Offer> offers = dataProvider.createFGBasedOffer("order.subTotal.getAmount()>20", "fulfillmentGroup.address.postalCode==75244", OfferDiscountType.PERCENT_OFF);
offers.addAll(dataProvider.createFGBasedOfferWithItemCriteria("order.subTotal.getAmount()>20", "fulfillmentGroup.address.postalCode==75244", OfferDiscountType.PERCENT_OFF, "([MVEL.eval(\"toUpperCase()\",\"test1\")] contains MVEL.eval(\"toUpperCase()\", discreteOrderItem.category.name))"));
offers.get(1).setName("secondOffer");
offers.addAll(dataProvider.createItemBasedOfferWithItemCriteria(
"order.subTotal.getAmount()>20",
OfferDiscountType.PERCENT_OFF,
"([MVEL.eval(\"toUpperCase()\",\"test1\"), MVEL.eval(\"toUpperCase()\",\"test2\")] contains MVEL.eval(\"toUpperCase()\", discreteOrderItem.category.name))",
"([MVEL.eval(\"toUpperCase()\",\"test1\"), MVEL.eval(\"toUpperCase()\",\"test2\")] contains MVEL.eval(\"toUpperCase()\", discreteOrderItem.category.name))"
));
offerService.applyAndSaveOffersToOrder(offers, promotableOrder.getOrder());
offers.get(0).setTotalitarianOffer(true);
offerService.applyFulfillmentGroupOffersToOrder(offers, promotableOrder.getOrder());
int fgAdjustmentCount = 0;
for (FulfillmentGroup fg : order.getFulfillmentGroups()) {
fgAdjustmentCount += fg.getFulfillmentGroupAdjustments().size();
}
//The totalitarian offer that applies to both fg's is not combinable and is a worse offer than the order item offers
// - it is therefore ignored
//However, the second combinable fg offer is allowed to be applied.
assertTrue(fgAdjustmentCount == 1);
promotableOrder = dataProvider.createBasicPromotableOrder();
myOrder.set(promotableOrder.getOrder());
offers.get(2).setValue(new BigDecimal("1"));
offerService.applyAndSaveOffersToOrder(offers, promotableOrder.getOrder());
offerService.applyFulfillmentGroupOffersToOrder(offers, promotableOrder.getOrder());
fgAdjustmentCount = 0;
order = promotableOrder.getOrder();
for (FulfillmentGroup fg : order.getFulfillmentGroups()) {
fgAdjustmentCount += fg.getFulfillmentGroupAdjustments().size();
}
//The totalitarian fg offer is now a better deal than the order item offers, therefore the totalitarian fg offer is applied