OrderSplittingStrategyImpl implements OrderSplittingStrategy { void groupDeliveriesIntoMixedIfNecessary(final Map<DeliveryBucket, List<CartItem>> deliveryGroups, final Map<String, Boolean> onePhysicalDelivery) { final Map<String, Integer> deliveryQty = getPhysicalDeliveriesQty(deliveryGroups); final List<DeliveryBucket> removeBuckets = new ArrayList<>(); final Map<DeliveryBucket, List<CartItem>> collectors = new HashMap<>(); final Set<String> splitGroups = getSplitItemGroups(deliveryGroups); for (Map.Entry<DeliveryBucket, List<CartItem>> entry : deliveryGroups.entrySet()) { final String group = entry.getKey().getGroup(); final String supplier = entry.getKey().getSupplier(); final Boolean forceSingleDelivery = onePhysicalDelivery.get(supplier); if (forceSingleDelivery != null && forceSingleDelivery && deliveryQty.get(supplier) > 1) { if (!CustomerOrderDelivery.ELECTRONIC_DELIVERY_GROUP.equals(group) && !CustomerOrderDelivery.NOSTOCK_DELIVERY_GROUP.equals(group) && !CustomerOrderDelivery.OFFLINE_DELIVERY_GROUP.equals(group)) { final DeliveryBucket mix = new DeliveryBucketImpl(CustomerOrderDelivery.MIX_DELIVERY_GROUP, supplier); List<CartItem> collector = collectors.computeIfAbsent(mix, k -> new ArrayList<>()); removeBuckets.add(entry.getKey()); collector.addAll(entry.getValue()); } } else if (CollectionUtils.isNotEmpty(splitGroups)) { final Iterator<CartItem> lineIt = entry.getValue().iterator(); while (lineIt.hasNext()) { final CartItem line = lineIt.next(); if (splitGroups.contains(line.getItemGroup())) { final DeliveryBucket mix = new DeliveryBucketImpl(CustomerOrderDelivery.MIX_DELIVERY_GROUP, supplier); List<CartItem> collector = collectors.computeIfAbsent(mix, k -> new ArrayList<>()); collector.add(line); lineIt.remove(); if (entry.getValue().isEmpty()) { removeBuckets.add(entry.getKey()); } } } } } deliveryGroups.putAll(collectors); deliveryGroups.keySet().removeAll(removeBuckets); } OrderSplittingStrategyImpl(final ShopService shopService,
                                      final ProductService productService,
                                      final WarehouseService warehouseService,
                                      final InventoryResolver inventoryResolver); @Override DeliveryBucket determineDeliveryBucket(final CartItem item,
                                                  final ShoppingCart cart); @Override Map<DeliveryBucket, List<CartItem>> determineDeliveryBuckets(final long shopId,
                                                                        final Collection<CartItem> items,
                                                                        final Map<String, Boolean> onePhysicalDelivery); @Override Map<String, Boolean> isMultipleDeliveriesAllowed(final long shopId, final Collection<CartItem> items);  }
@Test public void testGroupDeliveriesIntoMixedIfNecessaryOnlyElectronicSingleTrue() throws Exception { final CartItem d4 = context.mock(CartItem.class, "d4"); context.checking(new Expectations() {{ allowing(d4).getItemGroup(); will(returnValue(null)); }}); final Map<DeliveryBucket, List<CartItem>> groups = new TreeMap<>(); groups.put(new DeliveryBucketImpl(CustomerOrderDelivery.ELECTRONIC_DELIVERY_GROUP, "S001"), Collections.<CartItem>singletonList(d4)); new OrderSplittingStrategyImpl(null, null, null, null).groupDeliveriesIntoMixedIfNecessary(groups, Collections.singletonMap("S001", Boolean.TRUE)); assertEquals(1, groups.size()); final List<CartItem> electronic = groups.get(new DeliveryBucketImpl(CustomerOrderDelivery.ELECTRONIC_DELIVERY_GROUP, "S001")); assertNotNull(electronic); assertEquals(1, electronic.size()); assertSame(d4, electronic.get(0)); }
@Test public void testGroupDeliveriesIntoMixedIfNecessaryOnlyElectronicSingleFalse() throws Exception { final CartItem d4 = context.mock(CartItem.class, "d4"); context.checking(new Expectations() {{ allowing(d4).getItemGroup(); will(returnValue(null)); }}); final Map<DeliveryBucket, List<CartItem>> groups = new TreeMap<>(); groups.put(new DeliveryBucketImpl(CustomerOrderDelivery.ELECTRONIC_DELIVERY_GROUP, "S001"), Collections.<CartItem>singletonList(d4)); new OrderSplittingStrategyImpl(null, null, null, null).groupDeliveriesIntoMixedIfNecessary(groups, Collections.singletonMap("S001", Boolean.FALSE)); assertEquals(1, groups.size()); final List<CartItem> electronic = groups.get(new DeliveryBucketImpl(CustomerOrderDelivery.ELECTRONIC_DELIVERY_GROUP, "S001")); assertNotNull(electronic); assertEquals(1, electronic.size()); assertSame(d4, electronic.get(0)); }
@Test public void testGroupDeliveriesIntoMixedIfNecessaryOnlyElectronicTwoSuppliersSingleTrue() throws Exception { final CartItem d4_1 = context.mock(CartItem.class, "d4_1"); final CartItem d4_2 = context.mock(CartItem.class, "d4_2"); context.checking(new Expectations() {{ allowing(d4_1).getItemGroup(); will(returnValue(null)); allowing(d4_2).getItemGroup(); will(returnValue(null)); }}); final Map<DeliveryBucket, List<CartItem>> groups = new TreeMap<>(); groups.put(new DeliveryBucketImpl(CustomerOrderDelivery.ELECTRONIC_DELIVERY_GROUP, "S001"), Collections.<CartItem>singletonList(d4_1)); groups.put(new DeliveryBucketImpl(CustomerOrderDelivery.ELECTRONIC_DELIVERY_GROUP, "S002"), Collections.<CartItem>singletonList(d4_2)); new OrderSplittingStrategyImpl(null, null, null, null).groupDeliveriesIntoMixedIfNecessary(groups, new HashMap<String, Boolean>() {{ put("S001", Boolean.TRUE); put("S002", Boolean.TRUE); }}); assertEquals(2, groups.size()); final List<CartItem> electronic_1 = groups.get(new DeliveryBucketImpl(CustomerOrderDelivery.ELECTRONIC_DELIVERY_GROUP, "S001")); assertNotNull(electronic_1); assertEquals(1, electronic_1.size()); assertSame(d4_1, electronic_1.get(0)); final List<CartItem> electronic_2 = groups.get(new DeliveryBucketImpl(CustomerOrderDelivery.ELECTRONIC_DELIVERY_GROUP, "S002")); assertNotNull(electronic_2); assertEquals(1, electronic_2.size()); assertSame(d4_2, electronic_2.get(0)); }
@Test public void testGroupDeliveriesIntoMixedIfNecessaryOnlyElectronicTwoSuppliersSingleFalse() throws Exception { final CartItem d4_1 = context.mock(CartItem.class, "d4_1"); final CartItem d4_2 = context.mock(CartItem.class, "d4_2"); context.checking(new Expectations() {{ allowing(d4_1).getItemGroup(); will(returnValue(null)); allowing(d4_2).getItemGroup(); will(returnValue(null)); }}); final Map<DeliveryBucket, List<CartItem>> groups = new TreeMap<>(); groups.put(new DeliveryBucketImpl(CustomerOrderDelivery.ELECTRONIC_DELIVERY_GROUP, "S001"), Collections.<CartItem>singletonList(d4_1)); groups.put(new DeliveryBucketImpl(CustomerOrderDelivery.ELECTRONIC_DELIVERY_GROUP, "S002"), Collections.<CartItem>singletonList(d4_2)); new OrderSplittingStrategyImpl(null, null, null, null).groupDeliveriesIntoMixedIfNecessary(groups, new HashMap<String, Boolean>() {{ put("S001", Boolean.FALSE); put("S002", Boolean.FALSE); }}); assertEquals(2, groups.size()); final List<CartItem> electronic_1 = groups.get(new DeliveryBucketImpl(CustomerOrderDelivery.ELECTRONIC_DELIVERY_GROUP, "S001")); assertNotNull(electronic_1); assertEquals(1, electronic_1.size()); assertSame(d4_1, electronic_1.get(0)); final List<CartItem> electronic_2 = groups.get(new DeliveryBucketImpl(CustomerOrderDelivery.ELECTRONIC_DELIVERY_GROUP, "S002")); assertNotNull(electronic_2); assertEquals(1, electronic_2.size()); assertSame(d4_2, electronic_2.get(0)); }
@Test public void testGroupDeliveriesIntoMixedIfNecessaryWithElectronicSingleTrue() throws Exception { final CartItem d1 = context.mock(CartItem.class, "d1"); final CartItem d2 = context.mock(CartItem.class, "d2"); final CartItem d3 = context.mock(CartItem.class, "d3"); final CartItem d4 = context.mock(CartItem.class, "d4"); context.checking(new Expectations() {{ allowing(d1).getItemGroup(); will(returnValue(null)); allowing(d2).getItemGroup(); will(returnValue(null)); allowing(d3).getItemGroup(); will(returnValue(null)); allowing(d4).getItemGroup(); will(returnValue(null)); }}); final Map<DeliveryBucket, List<CartItem>> groups = new TreeMap<>(); groups.put(new DeliveryBucketImpl(CustomerOrderDelivery.STANDARD_DELIVERY_GROUP, "S001"), Collections.<CartItem>singletonList(d1)); groups.put(new DeliveryBucketImpl(CustomerOrderDelivery.DATE_WAIT_DELIVERY_GROUP, "S001"), Collections.<CartItem>singletonList(d2)); groups.put(new DeliveryBucketImpl(CustomerOrderDelivery.INVENTORY_WAIT_DELIVERY_GROUP, "S001"), Collections.<CartItem>singletonList(d3)); groups.put(new DeliveryBucketImpl(CustomerOrderDelivery.ELECTRONIC_DELIVERY_GROUP, "S001"), Collections.<CartItem>singletonList(d4)); new OrderSplittingStrategyImpl(null, null, null, null).groupDeliveriesIntoMixedIfNecessary(groups, Collections.singletonMap("S001", Boolean.TRUE)); assertEquals(2, groups.size()); final List<CartItem> electronic = groups.get(new DeliveryBucketImpl(CustomerOrderDelivery.ELECTRONIC_DELIVERY_GROUP, "S001")); final List<CartItem> mixed = groups.get(new DeliveryBucketImpl(CustomerOrderDelivery.MIX_DELIVERY_GROUP, "S001")); assertNotNull(electronic); assertEquals(1, electronic.size()); assertSame(d4, electronic.get(0)); assertNotNull(mixed); assertEquals(3, mixed.size()); assertSame(d1, mixed.get(0)); assertSame(d2, mixed.get(1)); assertSame(d3, mixed.get(2)); }
@Test public void testGroupDeliveriesIntoMixedIfNecessaryWithElectronicSingleFalse() throws Exception { final CartItem d1 = context.mock(CartItem.class, "d1"); final CartItem d2 = context.mock(CartItem.class, "d2"); final CartItem d3 = context.mock(CartItem.class, "d3"); final CartItem d4 = context.mock(CartItem.class, "d4"); context.checking(new Expectations() {{ allowing(d1).getItemGroup(); will(returnValue(null)); allowing(d2).getItemGroup(); will(returnValue(null)); allowing(d3).getItemGroup(); will(returnValue(null)); allowing(d4).getItemGroup(); will(returnValue(null)); }}); final Map<DeliveryBucket, List<CartItem>> groups = new TreeMap<>(); groups.put(new DeliveryBucketImpl(CustomerOrderDelivery.STANDARD_DELIVERY_GROUP, "S001"), Collections.<CartItem>singletonList(d1)); groups.put(new DeliveryBucketImpl(CustomerOrderDelivery.DATE_WAIT_DELIVERY_GROUP, "S001"), Collections.<CartItem>singletonList(d2)); groups.put(new DeliveryBucketImpl(CustomerOrderDelivery.INVENTORY_WAIT_DELIVERY_GROUP, "S001"), Collections.<CartItem>singletonList(d3)); groups.put(new DeliveryBucketImpl(CustomerOrderDelivery.ELECTRONIC_DELIVERY_GROUP, "S001"), Collections.<CartItem>singletonList(d4)); new OrderSplittingStrategyImpl(null, null, null, null).groupDeliveriesIntoMixedIfNecessary(groups, Collections.singletonMap("S001", Boolean.FALSE)); assertEquals(4, groups.size()); final List<CartItem> std = groups.get(new DeliveryBucketImpl(CustomerOrderDelivery.STANDARD_DELIVERY_GROUP, "S001")); final List<CartItem> date = groups.get(new DeliveryBucketImpl(CustomerOrderDelivery.DATE_WAIT_DELIVERY_GROUP, "S001")); final List<CartItem> inv = groups.get(new DeliveryBucketImpl(CustomerOrderDelivery.INVENTORY_WAIT_DELIVERY_GROUP, "S001")); final List<CartItem> electronic = groups.get(new DeliveryBucketImpl(CustomerOrderDelivery.ELECTRONIC_DELIVERY_GROUP, "S001")); assertNotNull(std); assertEquals(1, std.size()); assertSame(d1, std.get(0)); assertNotNull(date); assertEquals(1, date.size()); assertSame(d2, date.get(0)); assertNotNull(inv); assertEquals(1, inv.size()); assertSame(d3, inv.get(0)); assertNotNull(electronic); assertEquals(1, electronic.size()); assertSame(d4, electronic.get(0)); }
@Test public void testGroupDeliveriesIntoMixedIfNecessaryWithElectronicTwoSuppliersSingleTrue() throws Exception { final CartItem d1 = context.mock(CartItem.class, "d1"); final CartItem d2 = context.mock(CartItem.class, "d2"); final CartItem d3 = context.mock(CartItem.class, "d3"); final CartItem d4 = context.mock(CartItem.class, "d4"); context.checking(new Expectations() {{ allowing(d1).getItemGroup(); will(returnValue(null)); allowing(d2).getItemGroup(); will(returnValue(null)); allowing(d3).getItemGroup(); will(returnValue(null)); allowing(d4).getItemGroup(); will(returnValue(null)); }}); final Map<DeliveryBucket, List<CartItem>> groups = new TreeMap<>(); groups.put(new DeliveryBucketImpl(CustomerOrderDelivery.STANDARD_DELIVERY_GROUP, "S002"), Collections.<CartItem>singletonList(d1)); groups.put(new DeliveryBucketImpl(CustomerOrderDelivery.DATE_WAIT_DELIVERY_GROUP, "S001"), Collections.<CartItem>singletonList(d2)); groups.put(new DeliveryBucketImpl(CustomerOrderDelivery.INVENTORY_WAIT_DELIVERY_GROUP, "S001"), Collections.<CartItem>singletonList(d3)); groups.put(new DeliveryBucketImpl(CustomerOrderDelivery.ELECTRONIC_DELIVERY_GROUP, "S001"), Collections.<CartItem>singletonList(d4)); new OrderSplittingStrategyImpl(null, null, null, null).groupDeliveriesIntoMixedIfNecessary(groups, new HashMap<String, Boolean>() {{ put("S002", Boolean.TRUE); put("S001", Boolean.TRUE); }}); assertEquals(3, groups.size()); final List<CartItem> electronic = groups.get(new DeliveryBucketImpl(CustomerOrderDelivery.ELECTRONIC_DELIVERY_GROUP, "S001")); final List<CartItem> mixed = groups.get(new DeliveryBucketImpl(CustomerOrderDelivery.MIX_DELIVERY_GROUP, "S001")); final List<CartItem> standard2 = groups.get(new DeliveryBucketImpl(CustomerOrderDelivery.STANDARD_DELIVERY_GROUP, "S002")); assertNotNull(electronic); assertEquals(1, electronic.size()); assertSame(d4, electronic.get(0)); assertNotNull(mixed); assertEquals(2, mixed.size()); assertSame(d2, mixed.get(0)); assertSame(d3, mixed.get(1)); assertNotNull(standard2); assertEquals(1, standard2.size()); assertSame(d1, standard2.get(0)); }
@Test public void testGroupDeliveriesIntoMixedIfNecessaryWithElectronicTwoSuppliersSingleFalse() throws Exception { final CartItem d1 = context.mock(CartItem.class, "d1"); final CartItem d2 = context.mock(CartItem.class, "d2"); final CartItem d3 = context.mock(CartItem.class, "d3"); final CartItem d4 = context.mock(CartItem.class, "d4"); context.checking(new Expectations() {{ allowing(d1).getItemGroup(); will(returnValue(null)); allowing(d2).getItemGroup(); will(returnValue(null)); allowing(d3).getItemGroup(); will(returnValue(null)); allowing(d4).getItemGroup(); will(returnValue(null)); }}); final Map<DeliveryBucket, List<CartItem>> groups = new TreeMap<>(); groups.put(new DeliveryBucketImpl(CustomerOrderDelivery.STANDARD_DELIVERY_GROUP, "S002"), Collections.<CartItem>singletonList(d1)); groups.put(new DeliveryBucketImpl(CustomerOrderDelivery.DATE_WAIT_DELIVERY_GROUP, "S001"), Collections.<CartItem>singletonList(d2)); groups.put(new DeliveryBucketImpl(CustomerOrderDelivery.INVENTORY_WAIT_DELIVERY_GROUP, "S001"), Collections.<CartItem>singletonList(d3)); groups.put(new DeliveryBucketImpl(CustomerOrderDelivery.ELECTRONIC_DELIVERY_GROUP, "S001"), Collections.<CartItem>singletonList(d4)); new OrderSplittingStrategyImpl(null, null, null, null).groupDeliveriesIntoMixedIfNecessary(groups, new HashMap<String, Boolean>() {{ put("S002", Boolean.FALSE); put("S001", Boolean.FALSE); }}); assertEquals(4, groups.size()); final List<CartItem> date = groups.get(new DeliveryBucketImpl(CustomerOrderDelivery.DATE_WAIT_DELIVERY_GROUP, "S001")); final List<CartItem> inv = groups.get(new DeliveryBucketImpl(CustomerOrderDelivery.INVENTORY_WAIT_DELIVERY_GROUP, "S001")); final List<CartItem> electronic = groups.get(new DeliveryBucketImpl(CustomerOrderDelivery.ELECTRONIC_DELIVERY_GROUP, "S001")); final List<CartItem> standard2 = groups.get(new DeliveryBucketImpl(CustomerOrderDelivery.STANDARD_DELIVERY_GROUP, "S002")); assertNotNull(date); assertEquals(1, date.size()); assertSame(d2, date.get(0)); assertNotNull(inv); assertEquals(1, inv.size()); assertSame(d3, inv.get(0)); assertNotNull(electronic); assertEquals(1, electronic.size()); assertSame(d4, electronic.get(0)); assertNotNull(standard2); assertEquals(1, standard2.size()); assertSame(d1, standard2.get(0)); }
@Test public void testGroupDeliveriesIntoMixedIfNecessaryWithElectronicTwoSuppliersSingleMixed1() throws Exception { final CartItem d1 = context.mock(CartItem.class, "d1"); final CartItem d2 = context.mock(CartItem.class, "d2"); final CartItem d3 = context.mock(CartItem.class, "d3"); final CartItem d4 = context.mock(CartItem.class, "d4"); context.checking(new Expectations() {{ allowing(d1).getItemGroup(); will(returnValue(null)); allowing(d2).getItemGroup(); will(returnValue(null)); allowing(d3).getItemGroup(); will(returnValue(null)); allowing(d4).getItemGroup(); will(returnValue(null)); }}); final Map<DeliveryBucket, List<CartItem>> groups = new TreeMap<>(); groups.put(new DeliveryBucketImpl(CustomerOrderDelivery.STANDARD_DELIVERY_GROUP, "S002"), Collections.<CartItem>singletonList(d1)); groups.put(new DeliveryBucketImpl(CustomerOrderDelivery.DATE_WAIT_DELIVERY_GROUP, "S002"), Collections.<CartItem>singletonList(d2)); groups.put(new DeliveryBucketImpl(CustomerOrderDelivery.INVENTORY_WAIT_DELIVERY_GROUP, "S001"), Collections.<CartItem>singletonList(d3)); groups.put(new DeliveryBucketImpl(CustomerOrderDelivery.ELECTRONIC_DELIVERY_GROUP, "S001"), Collections.<CartItem>singletonList(d4)); new OrderSplittingStrategyImpl(null, null, null, null).groupDeliveriesIntoMixedIfNecessary(groups, new HashMap<String, Boolean>() {{ put("S002", Boolean.TRUE); put("S001", Boolean.FALSE); }}); assertEquals(3, groups.size()); final List<CartItem> electronic = groups.get(new DeliveryBucketImpl(CustomerOrderDelivery.ELECTRONIC_DELIVERY_GROUP, "S001")); final List<CartItem> inv = groups.get(new DeliveryBucketImpl(CustomerOrderDelivery.INVENTORY_WAIT_DELIVERY_GROUP, "S001")); final List<CartItem> mixed2 = groups.get(new DeliveryBucketImpl(CustomerOrderDelivery.MIX_DELIVERY_GROUP, "S002")); assertNotNull(electronic); assertEquals(1, electronic.size()); assertSame(d4, electronic.get(0)); assertNotNull(inv); assertEquals(1, inv.size()); assertSame(d3, inv.get(0)); assertNotNull(mixed2); assertEquals(2, mixed2.size()); assertSame(d1, mixed2.get(0)); assertSame(d2, mixed2.get(1)); }
@Test public void testGroupDeliveriesIntoMixedIfNecessaryWithElectronicTwoSuppliersSingleMixed2() throws Exception { final CartItem d1 = context.mock(CartItem.class, "d1"); final CartItem d2 = context.mock(CartItem.class, "d2"); final CartItem d3 = context.mock(CartItem.class, "d3"); final CartItem d4 = context.mock(CartItem.class, "d4"); context.checking(new Expectations() {{ allowing(d1).getItemGroup(); will(returnValue(null)); allowing(d2).getItemGroup(); will(returnValue(null)); allowing(d3).getItemGroup(); will(returnValue(null)); allowing(d4).getItemGroup(); will(returnValue(null)); }}); final Map<DeliveryBucket, List<CartItem>> groups = new TreeMap<>(); groups.put(new DeliveryBucketImpl(CustomerOrderDelivery.STANDARD_DELIVERY_GROUP, "S002"), Collections.<CartItem>singletonList(d1)); groups.put(new DeliveryBucketImpl(CustomerOrderDelivery.DATE_WAIT_DELIVERY_GROUP, "S002"), Collections.<CartItem>singletonList(d2)); groups.put(new DeliveryBucketImpl(CustomerOrderDelivery.INVENTORY_WAIT_DELIVERY_GROUP, "S001"), Collections.<CartItem>singletonList(d3)); groups.put(new DeliveryBucketImpl(CustomerOrderDelivery.ELECTRONIC_DELIVERY_GROUP, "S001"), Collections.<CartItem>singletonList(d4)); new OrderSplittingStrategyImpl(null, null, null, null).groupDeliveriesIntoMixedIfNecessary(groups, new HashMap<String, Boolean>() {{ put("S002", Boolean.FALSE); put("S001", Boolean.TRUE); }}); assertEquals(4, groups.size()); final List<CartItem> electronic = groups.get(new DeliveryBucketImpl(CustomerOrderDelivery.ELECTRONIC_DELIVERY_GROUP, "S001")); final List<CartItem> inv = groups.get(new DeliveryBucketImpl(CustomerOrderDelivery.INVENTORY_WAIT_DELIVERY_GROUP, "S001")); final List<CartItem> standard2 = groups.get(new DeliveryBucketImpl(CustomerOrderDelivery.STANDARD_DELIVERY_GROUP, "S002")); final List<CartItem> date2 = groups.get(new DeliveryBucketImpl(CustomerOrderDelivery.DATE_WAIT_DELIVERY_GROUP, "S002")); assertNotNull(electronic); assertEquals(1, electronic.size()); assertSame(d4, electronic.get(0)); assertNotNull(inv); assertEquals(1, inv.size()); assertSame(d3, inv.get(0)); assertNotNull(standard2); assertEquals(1, standard2.size()); assertSame(d1, standard2.get(0)); assertNotNull(date2); assertEquals(1, date2.size()); assertSame(d2, date2.get(0)); }
@Test public void testGroupDeliveriesIntoMixedIfNecessarySingleTrue() throws Exception { final CartItem d1 = context.mock(CartItem.class, "d1"); final CartItem d2 = context.mock(CartItem.class, "d2"); final CartItem d3 = context.mock(CartItem.class, "d3"); context.checking(new Expectations() {{ allowing(d1).getItemGroup(); will(returnValue(null)); allowing(d2).getItemGroup(); will(returnValue(null)); allowing(d3).getItemGroup(); will(returnValue(null)); }}); final Map<DeliveryBucket, List<CartItem>> groups = new TreeMap<>(); groups.put(new DeliveryBucketImpl(CustomerOrderDelivery.STANDARD_DELIVERY_GROUP, "S001"), Collections.<CartItem>singletonList(d1)); groups.put(new DeliveryBucketImpl(CustomerOrderDelivery.DATE_WAIT_DELIVERY_GROUP, "S001"), Collections.<CartItem>singletonList(d2)); groups.put(new DeliveryBucketImpl(CustomerOrderDelivery.INVENTORY_WAIT_DELIVERY_GROUP, "S001"), Collections.<CartItem>singletonList(d3)); new OrderSplittingStrategyImpl(null, null, null, null).groupDeliveriesIntoMixedIfNecessary(groups, Collections.singletonMap("S001", Boolean.TRUE)); assertEquals(1, groups.size()); final List<CartItem> mixed = groups.get(new DeliveryBucketImpl(CustomerOrderDelivery.MIX_DELIVERY_GROUP, "S001")); assertNotNull(mixed); assertEquals(3, mixed.size()); assertSame(d1, mixed.get(0)); assertSame(d2, mixed.get(1)); assertSame(d3, mixed.get(2)); }
@Test public void testGroupDeliveriesIntoMixedIfNecessarySingleFalse() throws Exception { final CartItem d1 = context.mock(CartItem.class, "d1"); final CartItem d2 = context.mock(CartItem.class, "d2"); final CartItem d3 = context.mock(CartItem.class, "d3"); context.checking(new Expectations() {{ allowing(d1).getItemGroup(); will(returnValue(null)); allowing(d2).getItemGroup(); will(returnValue(null)); allowing(d3).getItemGroup(); will(returnValue(null)); }}); final Map<DeliveryBucket, List<CartItem>> groups = new TreeMap<>(); groups.put(new DeliveryBucketImpl(CustomerOrderDelivery.STANDARD_DELIVERY_GROUP, "S001"), Collections.<CartItem>singletonList(d1)); groups.put(new DeliveryBucketImpl(CustomerOrderDelivery.DATE_WAIT_DELIVERY_GROUP, "S001"), Collections.<CartItem>singletonList(d2)); groups.put(new DeliveryBucketImpl(CustomerOrderDelivery.INVENTORY_WAIT_DELIVERY_GROUP, "S001"), Collections.<CartItem>singletonList(d3)); new OrderSplittingStrategyImpl(null, null, null, null).groupDeliveriesIntoMixedIfNecessary(groups, Collections.singletonMap("S001", Boolean.FALSE)); assertEquals(3, groups.size()); final List<CartItem> std = groups.get(new DeliveryBucketImpl(CustomerOrderDelivery.STANDARD_DELIVERY_GROUP, "S001")); final List<CartItem> date = groups.get(new DeliveryBucketImpl(CustomerOrderDelivery.DATE_WAIT_DELIVERY_GROUP, "S001")); final List<CartItem> inv = groups.get(new DeliveryBucketImpl(CustomerOrderDelivery.INVENTORY_WAIT_DELIVERY_GROUP, "S001")); assertNotNull(std); assertEquals(1, std.size()); assertSame(d1, std.get(0)); assertNotNull(date); assertEquals(1, date.size()); assertSame(d2, date.get(0)); assertNotNull(inv); assertEquals(1, inv.size()); assertSame(d3, inv.get(0)); }
@Test public void testGroupDeliveriesIntoMixedIfNecessaryMultipleSuppliersSingleTrue() throws Exception { final CartItem d1_1 = context.mock(CartItem.class, "d1_1"); final CartItem d2_1 = context.mock(CartItem.class, "d2_1"); final CartItem d3_1 = context.mock(CartItem.class, "d3_1"); final CartItem d1_2 = context.mock(CartItem.class, "d1_2"); final CartItem d2_2 = context.mock(CartItem.class, "d2_2"); final CartItem d3_2 = context.mock(CartItem.class, "d3_2"); final CartItem d1_3 = context.mock(CartItem.class, "d1_3"); final CartItem d2_3 = context.mock(CartItem.class, "d2_3"); final CartItem d3_3 = context.mock(CartItem.class, "d3_3"); context.checking(new Expectations() {{ allowing(d1_1).getItemGroup(); will(returnValue(null)); allowing(d2_1).getItemGroup(); will(returnValue(null)); allowing(d3_1).getItemGroup(); will(returnValue(null)); allowing(d1_2).getItemGroup(); will(returnValue(null)); allowing(d2_2).getItemGroup(); will(returnValue(null)); allowing(d3_2).getItemGroup(); will(returnValue(null)); allowing(d1_3).getItemGroup(); will(returnValue(null)); allowing(d2_3).getItemGroup(); will(returnValue(null)); allowing(d3_3).getItemGroup(); will(returnValue(null)); }}); final Map<DeliveryBucket, List<CartItem>> groups = new TreeMap<>(); groups.put(new DeliveryBucketImpl(CustomerOrderDelivery.STANDARD_DELIVERY_GROUP, "S001"), Collections.<CartItem>singletonList(d1_1)); groups.put(new DeliveryBucketImpl(CustomerOrderDelivery.DATE_WAIT_DELIVERY_GROUP, "S001"), Collections.<CartItem>singletonList(d2_1)); groups.put(new DeliveryBucketImpl(CustomerOrderDelivery.INVENTORY_WAIT_DELIVERY_GROUP, "S001"), Collections.<CartItem>singletonList(d3_1)); groups.put(new DeliveryBucketImpl(CustomerOrderDelivery.STANDARD_DELIVERY_GROUP, "S002"), Collections.<CartItem>singletonList(d1_2)); groups.put(new DeliveryBucketImpl(CustomerOrderDelivery.DATE_WAIT_DELIVERY_GROUP, "S002"), Collections.<CartItem>singletonList(d2_2)); groups.put(new DeliveryBucketImpl(CustomerOrderDelivery.INVENTORY_WAIT_DELIVERY_GROUP, "S002"), Collections.<CartItem>singletonList(d3_2)); groups.put(new DeliveryBucketImpl(CustomerOrderDelivery.STANDARD_DELIVERY_GROUP, "S003"), Collections.<CartItem>singletonList(d1_3)); groups.put(new DeliveryBucketImpl(CustomerOrderDelivery.DATE_WAIT_DELIVERY_GROUP, "S003"), Collections.<CartItem>singletonList(d2_3)); groups.put(new DeliveryBucketImpl(CustomerOrderDelivery.INVENTORY_WAIT_DELIVERY_GROUP, "S003"), Collections.<CartItem>singletonList(d3_3)); new OrderSplittingStrategyImpl(null, null, null, null).groupDeliveriesIntoMixedIfNecessary(groups, new HashMap<String, Boolean>() {{ put("S001", Boolean.TRUE); put("S002", Boolean.TRUE); put("S003", Boolean.TRUE); }}); assertEquals(3, groups.size()); final List<CartItem> mixed_1 = groups.get(new DeliveryBucketImpl(CustomerOrderDelivery.MIX_DELIVERY_GROUP, "S001")); assertNotNull(mixed_1); assertEquals(3, mixed_1.size()); assertSame(d1_1, mixed_1.get(0)); assertSame(d2_1, mixed_1.get(1)); assertSame(d3_1, mixed_1.get(2)); final List<CartItem> mixed_2 = groups.get(new DeliveryBucketImpl(CustomerOrderDelivery.MIX_DELIVERY_GROUP, "S002")); assertNotNull(mixed_2); assertEquals(3, mixed_2.size()); assertSame(d1_2, mixed_2.get(0)); assertSame(d2_2, mixed_2.get(1)); assertSame(d3_2, mixed_2.get(2)); final List<CartItem> mixed_3 = groups.get(new DeliveryBucketImpl(CustomerOrderDelivery.MIX_DELIVERY_GROUP, "S003")); assertNotNull(mixed_3); assertEquals(3, mixed_3.size()); assertSame(d1_3, mixed_3.get(0)); assertSame(d2_3, mixed_3.get(1)); assertSame(d3_3, mixed_3.get(2)); }
@Test public void testGroupDeliveriesIntoMixedIfNecessaryMultipleSuppliersSingleFalse() throws Exception { final CartItem d1_1 = context.mock(CartItem.class, "d1_1"); final CartItem d2_1 = context.mock(CartItem.class, "d2_1"); final CartItem d3_1 = context.mock(CartItem.class, "d3_1"); final CartItem d1_2 = context.mock(CartItem.class, "d1_2"); final CartItem d2_2 = context.mock(CartItem.class, "d2_2"); final CartItem d3_2 = context.mock(CartItem.class, "d3_2"); final CartItem d1_3 = context.mock(CartItem.class, "d1_3"); final CartItem d2_3 = context.mock(CartItem.class, "d2_3"); final CartItem d3_3 = context.mock(CartItem.class, "d3_3"); context.checking(new Expectations() {{ allowing(d1_1).getItemGroup(); will(returnValue(null)); allowing(d2_1).getItemGroup(); will(returnValue(null)); allowing(d3_1).getItemGroup(); will(returnValue(null)); allowing(d1_2).getItemGroup(); will(returnValue(null)); allowing(d2_2).getItemGroup(); will(returnValue(null)); allowing(d3_2).getItemGroup(); will(returnValue(null)); allowing(d1_3).getItemGroup(); will(returnValue(null)); allowing(d2_3).getItemGroup(); will(returnValue(null)); allowing(d3_3).getItemGroup(); will(returnValue(null)); }}); final Map<DeliveryBucket, List<CartItem>> groups = new TreeMap<>(); groups.put(new DeliveryBucketImpl(CustomerOrderDelivery.STANDARD_DELIVERY_GROUP, "S001"), Collections.<CartItem>singletonList(d1_1)); groups.put(new DeliveryBucketImpl(CustomerOrderDelivery.DATE_WAIT_DELIVERY_GROUP, "S001"), Collections.<CartItem>singletonList(d2_1)); groups.put(new DeliveryBucketImpl(CustomerOrderDelivery.INVENTORY_WAIT_DELIVERY_GROUP, "S001"), Collections.<CartItem>singletonList(d3_1)); groups.put(new DeliveryBucketImpl(CustomerOrderDelivery.STANDARD_DELIVERY_GROUP, "S002"), Collections.<CartItem>singletonList(d1_2)); groups.put(new DeliveryBucketImpl(CustomerOrderDelivery.DATE_WAIT_DELIVERY_GROUP, "S002"), Collections.<CartItem>singletonList(d2_2)); groups.put(new DeliveryBucketImpl(CustomerOrderDelivery.INVENTORY_WAIT_DELIVERY_GROUP, "S002"), Collections.<CartItem>singletonList(d3_2)); groups.put(new DeliveryBucketImpl(CustomerOrderDelivery.STANDARD_DELIVERY_GROUP, "S003"), Collections.<CartItem>singletonList(d1_3)); groups.put(new DeliveryBucketImpl(CustomerOrderDelivery.DATE_WAIT_DELIVERY_GROUP, "S003"), Collections.<CartItem>singletonList(d2_3)); groups.put(new DeliveryBucketImpl(CustomerOrderDelivery.INVENTORY_WAIT_DELIVERY_GROUP, "S003"), Collections.<CartItem>singletonList(d3_3)); new OrderSplittingStrategyImpl(null, null, null, null).groupDeliveriesIntoMixedIfNecessary(groups, new HashMap<String, Boolean>() {{ put("S001", Boolean.FALSE); put("S002", Boolean.FALSE); put("S003", Boolean.FALSE); }}); assertEquals(9, groups.size()); final List<CartItem> std_1 = groups.get(new DeliveryBucketImpl(CustomerOrderDelivery.STANDARD_DELIVERY_GROUP, "S001")); final List<CartItem> date_1 = groups.get(new DeliveryBucketImpl(CustomerOrderDelivery.DATE_WAIT_DELIVERY_GROUP, "S001")); final List<CartItem> inv_1 = groups.get(new DeliveryBucketImpl(CustomerOrderDelivery.INVENTORY_WAIT_DELIVERY_GROUP, "S001")); assertNotNull(std_1); assertEquals(1, std_1.size()); assertSame(d1_1, std_1.get(0)); assertNotNull(date_1); assertEquals(1, date_1.size()); assertSame(d2_1, date_1.get(0)); assertNotNull(inv_1); assertEquals(1, inv_1.size()); assertSame(d3_1, inv_1.get(0)); final List<CartItem> std_2 = groups.get(new DeliveryBucketImpl(CustomerOrderDelivery.STANDARD_DELIVERY_GROUP, "S002")); final List<CartItem> date_2 = groups.get(new DeliveryBucketImpl(CustomerOrderDelivery.DATE_WAIT_DELIVERY_GROUP, "S002")); final List<CartItem> inv_2 = groups.get(new DeliveryBucketImpl(CustomerOrderDelivery.INVENTORY_WAIT_DELIVERY_GROUP, "S002")); assertNotNull(std_2); assertEquals(1, std_2.size()); assertSame(d1_2, std_2.get(0)); assertNotNull(date_2); assertEquals(1, date_2.size()); assertSame(d2_2, date_2.get(0)); assertNotNull(inv_2); assertEquals(1, inv_2.size()); assertSame(d3_2, inv_2.get(0)); final List<CartItem> std_3 = groups.get(new DeliveryBucketImpl(CustomerOrderDelivery.STANDARD_DELIVERY_GROUP, "S003")); final List<CartItem> date_3 = groups.get(new DeliveryBucketImpl(CustomerOrderDelivery.DATE_WAIT_DELIVERY_GROUP, "S003")); final List<CartItem> inv_3 = groups.get(new DeliveryBucketImpl(CustomerOrderDelivery.INVENTORY_WAIT_DELIVERY_GROUP, "S003")); assertNotNull(std_3); assertEquals(1, std_3.size()); assertSame(d1_3, std_3.get(0)); assertNotNull(date_3); assertEquals(1, date_3.size()); assertSame(d2_3, date_3.get(0)); assertNotNull(inv_3); assertEquals(1, inv_3.size()); assertSame(d3_3, inv_3.get(0)); }
@Test public void testGroupDeliveriesIntoMixedIfNecessaryMultipleSuppliersSingleMixed() throws Exception { final CartItem d1_1 = context.mock(CartItem.class, "d1_1"); final CartItem d2_1 = context.mock(CartItem.class, "d2_1"); final CartItem d3_1 = context.mock(CartItem.class, "d3_1"); final CartItem d1_2 = context.mock(CartItem.class, "d1_2"); final CartItem d2_2 = context.mock(CartItem.class, "d2_2"); final CartItem d3_2 = context.mock(CartItem.class, "d3_2"); final CartItem d1_3 = context.mock(CartItem.class, "d1_3"); final CartItem d2_3 = context.mock(CartItem.class, "d2_3"); final CartItem d3_3 = context.mock(CartItem.class, "d3_3"); context.checking(new Expectations() {{ allowing(d1_1).getItemGroup(); will(returnValue(null)); allowing(d2_1).getItemGroup(); will(returnValue(null)); allowing(d3_1).getItemGroup(); will(returnValue(null)); allowing(d1_2).getItemGroup(); will(returnValue(null)); allowing(d2_2).getItemGroup(); will(returnValue(null)); allowing(d3_2).getItemGroup(); will(returnValue(null)); allowing(d1_3).getItemGroup(); will(returnValue(null)); allowing(d2_3).getItemGroup(); will(returnValue(null)); allowing(d3_3).getItemGroup(); will(returnValue(null)); }}); final Map<DeliveryBucket, List<CartItem>> groups = new TreeMap<>(); groups.put(new DeliveryBucketImpl(CustomerOrderDelivery.STANDARD_DELIVERY_GROUP, "S001"), Collections.<CartItem>singletonList(d1_1)); groups.put(new DeliveryBucketImpl(CustomerOrderDelivery.DATE_WAIT_DELIVERY_GROUP, "S001"), Collections.<CartItem>singletonList(d2_1)); groups.put(new DeliveryBucketImpl(CustomerOrderDelivery.INVENTORY_WAIT_DELIVERY_GROUP, "S001"), Collections.<CartItem>singletonList(d3_1)); groups.put(new DeliveryBucketImpl(CustomerOrderDelivery.STANDARD_DELIVERY_GROUP, "S002"), Collections.<CartItem>singletonList(d1_2)); groups.put(new DeliveryBucketImpl(CustomerOrderDelivery.DATE_WAIT_DELIVERY_GROUP, "S002"), Collections.<CartItem>singletonList(d2_2)); groups.put(new DeliveryBucketImpl(CustomerOrderDelivery.INVENTORY_WAIT_DELIVERY_GROUP, "S002"), Collections.<CartItem>singletonList(d3_2)); groups.put(new DeliveryBucketImpl(CustomerOrderDelivery.STANDARD_DELIVERY_GROUP, "S003"), Collections.<CartItem>singletonList(d1_3)); groups.put(new DeliveryBucketImpl(CustomerOrderDelivery.DATE_WAIT_DELIVERY_GROUP, "S003"), Collections.<CartItem>singletonList(d2_3)); groups.put(new DeliveryBucketImpl(CustomerOrderDelivery.INVENTORY_WAIT_DELIVERY_GROUP, "S003"), Collections.<CartItem>singletonList(d3_3)); new OrderSplittingStrategyImpl(null, null, null, null).groupDeliveriesIntoMixedIfNecessary(groups, new HashMap<String, Boolean>() {{ put("S001", Boolean.TRUE); put("S002", Boolean.FALSE); put("S003", Boolean.TRUE); }}); assertEquals(5, groups.size()); final List<CartItem> mixed_1 = groups.get(new DeliveryBucketImpl(CustomerOrderDelivery.MIX_DELIVERY_GROUP, "S001")); assertNotNull(mixed_1); assertEquals(3, mixed_1.size()); assertSame(d1_1, mixed_1.get(0)); assertSame(d2_1, mixed_1.get(1)); assertSame(d3_1, mixed_1.get(2)); final List<CartItem> std_2 = groups.get(new DeliveryBucketImpl(CustomerOrderDelivery.STANDARD_DELIVERY_GROUP, "S002")); final List<CartItem> date_2 = groups.get(new DeliveryBucketImpl(CustomerOrderDelivery.DATE_WAIT_DELIVERY_GROUP, "S002")); final List<CartItem> inv_2 = groups.get(new DeliveryBucketImpl(CustomerOrderDelivery.INVENTORY_WAIT_DELIVERY_GROUP, "S002")); assertNotNull(std_2); assertEquals(1, std_2.size()); assertSame(d1_2, std_2.get(0)); assertNotNull(date_2); assertEquals(1, date_2.size()); assertSame(d2_2, date_2.get(0)); assertNotNull(inv_2); assertEquals(1, inv_2.size()); assertSame(d3_2, inv_2.get(0)); final List<CartItem> mixed_3 = groups.get(new DeliveryBucketImpl(CustomerOrderDelivery.MIX_DELIVERY_GROUP, "S003")); assertNotNull(mixed_3); assertEquals(3, mixed_3.size()); assertSame(d1_3, mixed_3.get(0)); assertSame(d2_3, mixed_3.get(1)); assertSame(d3_3, mixed_3.get(2)); }
@Test public void testGroupDeliveriesIntoMixedIfNecessaryMultipleSuppliersSingleMixedWithGroupped() throws Exception { final CartItem d1_1 = context.mock(CartItem.class, "d1_1"); final CartItem d2_1 = context.mock(CartItem.class, "d2_1"); final CartItem d3_1 = context.mock(CartItem.class, "d3_1"); final CartItem d1_2 = context.mock(CartItem.class, "d1_2"); final CartItem d2_2 = context.mock(CartItem.class, "d2_2"); final CartItem d3_2 = context.mock(CartItem.class, "d3_2"); final CartItem d1_3 = context.mock(CartItem.class, "d1_3"); final CartItem d2_3 = context.mock(CartItem.class, "d2_3"); final CartItem d3_3 = context.mock(CartItem.class, "d3_3"); context.checking(new Expectations() {{ allowing(d1_1).getItemGroup(); will(returnValue("grp1")); allowing(d2_1).getItemGroup(); will(returnValue("grp1")); allowing(d3_1).getItemGroup(); will(returnValue(null)); allowing(d1_2).getItemGroup(); will(returnValue("grp2")); allowing(d2_2).getItemGroup(); will(returnValue(null)); allowing(d3_2).getItemGroup(); will(returnValue("grp2")); allowing(d1_3).getItemGroup(); will(returnValue("grp3")); allowing(d2_3).getItemGroup(); will(returnValue(null)); allowing(d3_3).getItemGroup(); will(returnValue("grp3")); }}); final Map<DeliveryBucket, List<CartItem>> groups = new TreeMap<>(); groups.put(new DeliveryBucketImpl(CustomerOrderDelivery.STANDARD_DELIVERY_GROUP, "S001"), new ArrayList<>(Collections.<CartItem>singletonList(d1_1))); groups.put(new DeliveryBucketImpl(CustomerOrderDelivery.DATE_WAIT_DELIVERY_GROUP, "S001"), new ArrayList<>(Collections.<CartItem>singletonList(d2_1))); groups.put(new DeliveryBucketImpl(CustomerOrderDelivery.INVENTORY_WAIT_DELIVERY_GROUP, "S001"), new ArrayList<>(Collections.<CartItem>singletonList(d3_1))); groups.put(new DeliveryBucketImpl(CustomerOrderDelivery.STANDARD_DELIVERY_GROUP, "S002"), new ArrayList<>(Collections.<CartItem>singletonList(d1_2))); groups.put(new DeliveryBucketImpl(CustomerOrderDelivery.DATE_WAIT_DELIVERY_GROUP, "S002"), new ArrayList<>(Collections.<CartItem>singletonList(d2_2))); groups.put(new DeliveryBucketImpl(CustomerOrderDelivery.INVENTORY_WAIT_DELIVERY_GROUP, "S002"), new ArrayList<>(Collections.<CartItem>singletonList(d3_2))); groups.put(new DeliveryBucketImpl(CustomerOrderDelivery.STANDARD_DELIVERY_GROUP, "S003"), new ArrayList<>(Collections.<CartItem>singletonList(d1_3))); groups.put(new DeliveryBucketImpl(CustomerOrderDelivery.DATE_WAIT_DELIVERY_GROUP, "S003"), new ArrayList<>(Collections.<CartItem>singletonList(d2_3))); groups.put(new DeliveryBucketImpl(CustomerOrderDelivery.INVENTORY_WAIT_DELIVERY_GROUP, "S003"), new ArrayList<>(Collections.<CartItem>singletonList(d3_3))); new OrderSplittingStrategyImpl(null, null, null, null).groupDeliveriesIntoMixedIfNecessary(groups, new HashMap<String, Boolean>() {{ put("S001", Boolean.FALSE); put("S002", Boolean.FALSE); put("S003", Boolean.TRUE); }}); assertEquals(5, groups.size()); final List<CartItem> mixed_1 = groups.get(new DeliveryBucketImpl(CustomerOrderDelivery.MIX_DELIVERY_GROUP, "S001")); assertNotNull(mixed_1); assertEquals(2, mixed_1.size()); assertSame(d1_1, mixed_1.get(0)); assertSame(d2_1, mixed_1.get(1)); final List<CartItem> inv_1 = groups.get(new DeliveryBucketImpl(CustomerOrderDelivery.INVENTORY_WAIT_DELIVERY_GROUP, "S001")); assertNotNull(inv_1); assertEquals(1, inv_1.size()); assertSame(d3_1, inv_1.get(0)); final List<CartItem> mix_2 = groups.get(new DeliveryBucketImpl(CustomerOrderDelivery.MIX_DELIVERY_GROUP, "S002")); final List<CartItem> date_2 = groups.get(new DeliveryBucketImpl(CustomerOrderDelivery.DATE_WAIT_DELIVERY_GROUP, "S002")); assertNotNull(mix_2); assertEquals(2, mix_2.size()); assertSame(d1_2, mix_2.get(0)); assertSame(d3_2, mix_2.get(1)); assertNotNull(date_2); assertEquals(1, date_2.size()); assertSame(d2_2, date_2.get(0)); final List<CartItem> mixed_3 = groups.get(new DeliveryBucketImpl(CustomerOrderDelivery.MIX_DELIVERY_GROUP, "S003")); assertNotNull(mixed_3); assertEquals(3, mixed_3.size()); assertSame(d1_3, mixed_3.get(0)); assertSame(d2_3, mixed_3.get(1)); assertSame(d3_3, mixed_3.get(2)); }
@Test public void testGroupDeliveriesIntoMixedIfNecessaryStandard() throws Exception { final Map<DeliveryBucket, List<CartItem>> buckets = new HashMap<>(); final DeliveryBucket d1 = context.mock(DeliveryBucket.class, "d1"); buckets.put(d1, Collections.<CartItem>emptyList()); context.checking(new Expectations() {{ allowing(d1).getSupplier(); will(returnValue("s1")); allowing(d1).getGroup(); will(returnValue(CustomerOrderDelivery.STANDARD_DELIVERY_GROUP)); }}); new OrderSplittingStrategyImpl(null, null, null, null).groupDeliveriesIntoMixedIfNecessary(buckets, Collections.singletonMap("s1", Boolean.TRUE)); assertNotNull(buckets); assertEquals(1, buckets.size()); }
@Test public void testGroupDeliveriesIntoMixedIfNecessaryPreorder() throws Exception { final Map<DeliveryBucket, List<CartItem>> buckets = new HashMap<>(); final DeliveryBucket d2 = context.mock(DeliveryBucket.class, "d2"); buckets.put(d2, Collections.<CartItem>emptyList()); context.checking(new Expectations() {{ allowing(d2).getSupplier(); will(returnValue("s1")); allowing(d2).getGroup(); will(returnValue(CustomerOrderDelivery.DATE_WAIT_DELIVERY_GROUP)); }}); new OrderSplittingStrategyImpl(null, null, null, null).groupDeliveriesIntoMixedIfNecessary(buckets, Collections.singletonMap("s1", Boolean.TRUE)); assertNotNull(buckets); assertEquals(1, buckets.size()); }
@Test public void testGroupDeliveriesIntoMixedIfNecessaryBackorder() throws Exception { final Map<DeliveryBucket, List<CartItem>> buckets = new HashMap<>(); final DeliveryBucket d3 = context.mock(DeliveryBucket.class, "d3"); buckets.put(d3, Collections.<CartItem>emptyList()); context.checking(new Expectations() {{ allowing(d3).getSupplier(); will(returnValue("s1")); allowing(d3).getGroup(); will(returnValue(CustomerOrderDelivery.INVENTORY_WAIT_DELIVERY_GROUP)); }}); new OrderSplittingStrategyImpl(null, null, null, null).groupDeliveriesIntoMixedIfNecessary(buckets, Collections.singletonMap("s1", Boolean.TRUE)); assertNotNull(buckets); assertEquals(1, buckets.size()); }
@Test public void testGroupDeliveriesIntoMixedIfNecessaryElectronic() throws Exception { final Map<DeliveryBucket, List<CartItem>> buckets = new HashMap<>(); final DeliveryBucket d4 = context.mock(DeliveryBucket.class, "d4"); buckets.put(d4, Collections.<CartItem>emptyList()); context.checking(new Expectations() {{ allowing(d4).getSupplier(); will(returnValue("s1")); allowing(d4).getGroup(); will(returnValue(CustomerOrderDelivery.ELECTRONIC_DELIVERY_GROUP)); }}); new OrderSplittingStrategyImpl(null, null, null, null).groupDeliveriesIntoMixedIfNecessary(buckets, Collections.singletonMap("s1", Boolean.TRUE)); assertNotNull(buckets); assertEquals(1, buckets.size()); }
@Test public void testGroupDeliveriesIntoMixedIfNecessaryNoStock() throws Exception { final Map<DeliveryBucket, List<CartItem>> buckets = new HashMap<>(); final DeliveryBucket oos = context.mock(DeliveryBucket.class, "oos"); buckets.put(oos, Collections.<CartItem>emptyList()); context.checking(new Expectations() {{ allowing(oos).getSupplier(); will(returnValue("s1")); allowing(oos).getGroup(); will(returnValue(CustomerOrderDelivery.NOSTOCK_DELIVERY_GROUP)); }}); new OrderSplittingStrategyImpl(null, null, null, null).groupDeliveriesIntoMixedIfNecessary(buckets, Collections.singletonMap("s1", Boolean.TRUE)); assertNotNull(buckets); assertEquals(1, buckets.size()); }
@Test public void testGroupDeliveriesIntoMixedIfNecessaryOffline() throws Exception { final Map<DeliveryBucket, List<CartItem>> buckets = new HashMap<>(); final DeliveryBucket off = context.mock(DeliveryBucket.class, "off"); buckets.put(off, Collections.<CartItem>emptyList()); context.checking(new Expectations() {{ allowing(off).getSupplier(); will(returnValue("s1")); allowing(off).getGroup(); will(returnValue(CustomerOrderDelivery.OFFLINE_DELIVERY_GROUP)); }}); new OrderSplittingStrategyImpl(null, null, null, null).groupDeliveriesIntoMixedIfNecessary(buckets, Collections.singletonMap("s1", Boolean.TRUE)); assertNotNull(buckets); assertEquals(1, buckets.size()); }
@Test public void testGroupDeliveriesIntoMixedIfNecessaryMixSingleTrue() throws Exception { final Map<DeliveryBucket, List<CartItem>> buckets = new HashMap<>(); final DeliveryBucket d1 = context.mock(DeliveryBucket.class, "d1"); final DeliveryBucket d2 = context.mock(DeliveryBucket.class, "d2"); final DeliveryBucket d3 = context.mock(DeliveryBucket.class, "d3"); final DeliveryBucket d4 = context.mock(DeliveryBucket.class, "d4"); final DeliveryBucket oos = context.mock(DeliveryBucket.class, "oos"); final DeliveryBucket off = context.mock(DeliveryBucket.class, "off"); buckets.put(d1, Collections.<CartItem>emptyList()); buckets.put(d2, Collections.<CartItem>emptyList()); buckets.put(d3, Collections.<CartItem>emptyList()); buckets.put(d4, Collections.<CartItem>emptyList()); buckets.put(oos, Collections.<CartItem>emptyList()); buckets.put(off, Collections.<CartItem>emptyList()); context.checking(new Expectations() {{ allowing(d1).getSupplier(); will(returnValue("s1")); allowing(d1).getGroup(); will(returnValue(CustomerOrderDelivery.STANDARD_DELIVERY_GROUP)); allowing(d2).getSupplier(); will(returnValue("s1")); allowing(d2).getGroup(); will(returnValue(CustomerOrderDelivery.DATE_WAIT_DELIVERY_GROUP)); allowing(d3).getSupplier(); will(returnValue("s1")); allowing(d3).getGroup(); will(returnValue(CustomerOrderDelivery.INVENTORY_WAIT_DELIVERY_GROUP)); allowing(d4).getSupplier(); will(returnValue("s1")); allowing(d4).getGroup(); will(returnValue(CustomerOrderDelivery.ELECTRONIC_DELIVERY_GROUP)); allowing(oos).getSupplier(); will(returnValue("s1")); allowing(oos).getGroup(); will(returnValue(CustomerOrderDelivery.NOSTOCK_DELIVERY_GROUP)); allowing(off).getSupplier(); will(returnValue("s1")); allowing(off).getGroup(); will(returnValue(CustomerOrderDelivery.OFFLINE_DELIVERY_GROUP)); }}); new OrderSplittingStrategyImpl(null, null, null, null).groupDeliveriesIntoMixedIfNecessary(buckets, Collections.singletonMap("s1", Boolean.TRUE)); assertNotNull(buckets); assertEquals(4, buckets.size()); final Set<String> expected = new HashSet<>(Arrays.asList( CustomerOrderDelivery.ELECTRONIC_DELIVERY_GROUP, CustomerOrderDelivery.NOSTOCK_DELIVERY_GROUP, CustomerOrderDelivery.OFFLINE_DELIVERY_GROUP, CustomerOrderDelivery.MIX_DELIVERY_GROUP )); for (final DeliveryBucket key : buckets.keySet()) { assertTrue(expected.contains(key.getGroup())); } }
@Test public void testGroupDeliveriesIntoMixedIfNecessaryMixSingleFalse() throws Exception { final Map<DeliveryBucket, List<CartItem>> buckets = new HashMap<>(); final DeliveryBucket d1 = context.mock(DeliveryBucket.class, "d1"); final DeliveryBucket d2 = context.mock(DeliveryBucket.class, "d2"); final DeliveryBucket d3 = context.mock(DeliveryBucket.class, "d3"); final DeliveryBucket d4 = context.mock(DeliveryBucket.class, "d4"); final DeliveryBucket oos = context.mock(DeliveryBucket.class, "oos"); final DeliveryBucket off = context.mock(DeliveryBucket.class, "off"); buckets.put(d1, Collections.<CartItem>emptyList()); buckets.put(d2, Collections.<CartItem>emptyList()); buckets.put(d3, Collections.<CartItem>emptyList()); buckets.put(d4, Collections.<CartItem>emptyList()); buckets.put(oos, Collections.<CartItem>emptyList()); buckets.put(off, Collections.<CartItem>emptyList()); context.checking(new Expectations() {{ allowing(d1).getSupplier(); will(returnValue("s1")); allowing(d1).getGroup(); will(returnValue(CustomerOrderDelivery.STANDARD_DELIVERY_GROUP)); allowing(d2).getSupplier(); will(returnValue("s1")); allowing(d2).getGroup(); will(returnValue(CustomerOrderDelivery.DATE_WAIT_DELIVERY_GROUP)); allowing(d3).getSupplier(); will(returnValue("s1")); allowing(d3).getGroup(); will(returnValue(CustomerOrderDelivery.INVENTORY_WAIT_DELIVERY_GROUP)); allowing(d4).getSupplier(); will(returnValue("s1")); allowing(d4).getGroup(); will(returnValue(CustomerOrderDelivery.ELECTRONIC_DELIVERY_GROUP)); allowing(oos).getSupplier(); will(returnValue("s1")); allowing(oos).getGroup(); will(returnValue(CustomerOrderDelivery.NOSTOCK_DELIVERY_GROUP)); allowing(off).getSupplier(); will(returnValue("s1")); allowing(off).getGroup(); will(returnValue(CustomerOrderDelivery.OFFLINE_DELIVERY_GROUP)); }}); new OrderSplittingStrategyImpl(null, null, null, null).groupDeliveriesIntoMixedIfNecessary(buckets, Collections.singletonMap("s1", Boolean.FALSE)); assertNotNull(buckets); assertEquals(6, buckets.size()); final Set<String> expected = new HashSet<>(Arrays.asList( CustomerOrderDelivery.STANDARD_DELIVERY_GROUP, CustomerOrderDelivery.DATE_WAIT_DELIVERY_GROUP, CustomerOrderDelivery.INVENTORY_WAIT_DELIVERY_GROUP, CustomerOrderDelivery.ELECTRONIC_DELIVERY_GROUP, CustomerOrderDelivery.NOSTOCK_DELIVERY_GROUP, CustomerOrderDelivery.OFFLINE_DELIVERY_GROUP )); for (final DeliveryBucket key : buckets.keySet()) { assertTrue(expected.contains(key.getGroup())); } }
@Test public void testGroupDeliveriesIntoMixedIfNecessaryStandardMultipleSuppliersSingleTrue() throws Exception { final Map<DeliveryBucket, List<CartItem>> buckets = new HashMap<>(); final DeliveryBucket d1 = context.mock(DeliveryBucket.class, "d1"); final DeliveryBucket d2 = context.mock(DeliveryBucket.class, "d2"); final DeliveryBucket d3 = context.mock(DeliveryBucket.class, "d3"); final DeliveryBucket d4 = context.mock(DeliveryBucket.class, "d4"); final DeliveryBucket oos = context.mock(DeliveryBucket.class, "oos"); final DeliveryBucket off = context.mock(DeliveryBucket.class, "off"); buckets.put(d1, Collections.<CartItem>emptyList()); buckets.put(d2, Collections.<CartItem>emptyList()); buckets.put(d3, Collections.<CartItem>emptyList()); buckets.put(d4, Collections.<CartItem>emptyList()); buckets.put(oos, Collections.<CartItem>emptyList()); buckets.put(off, Collections.<CartItem>emptyList()); context.checking(new Expectations() {{ allowing(d1).getSupplier(); will(returnValue("s2")); allowing(d1).getGroup(); will(returnValue(CustomerOrderDelivery.STANDARD_DELIVERY_GROUP)); allowing(d2).getSupplier(); will(returnValue("s1")); allowing(d2).getGroup(); will(returnValue(CustomerOrderDelivery.DATE_WAIT_DELIVERY_GROUP)); allowing(d3).getSupplier(); will(returnValue("s2")); allowing(d3).getGroup(); will(returnValue(CustomerOrderDelivery.INVENTORY_WAIT_DELIVERY_GROUP)); allowing(d4).getSupplier(); will(returnValue("s1")); allowing(d4).getGroup(); will(returnValue(CustomerOrderDelivery.ELECTRONIC_DELIVERY_GROUP)); allowing(oos).getSupplier(); will(returnValue("s3")); allowing(oos).getGroup(); will(returnValue(CustomerOrderDelivery.NOSTOCK_DELIVERY_GROUP)); allowing(off).getSupplier(); will(returnValue("s1")); allowing(off).getGroup(); will(returnValue(CustomerOrderDelivery.OFFLINE_DELIVERY_GROUP)); }}); new OrderSplittingStrategyImpl(null, null, null, null).groupDeliveriesIntoMixedIfNecessary(buckets, new HashMap<String, Boolean>() {{ put("s1", Boolean.TRUE); put("s2", Boolean.TRUE); put("s3", Boolean.TRUE); }}); assertNotNull(buckets); assertEquals(5, buckets.size()); final Map<String, Set<String>> expected = new HashMap<String, Set<String>>() {{ put("s1", new HashSet<>(Arrays.asList( CustomerOrderDelivery.ELECTRONIC_DELIVERY_GROUP, CustomerOrderDelivery.OFFLINE_DELIVERY_GROUP, CustomerOrderDelivery.DATE_WAIT_DELIVERY_GROUP ))); put("s2", new HashSet<>(Collections.singletonList( CustomerOrderDelivery.MIX_DELIVERY_GROUP ))); put("s3", new HashSet<>(Collections.singletonList( CustomerOrderDelivery.NOSTOCK_DELIVERY_GROUP ))); }}; for (final DeliveryBucket key : buckets.keySet()) { assertTrue("Bucket not expected " + key, expected.get(key.getSupplier()).contains(key.getGroup())); } }
@Test public void testGroupDeliveriesIntoMixedIfNecessaryStandardMultipleSuppliersSingleFalse() throws Exception { final Map<DeliveryBucket, List<CartItem>> buckets = new HashMap<>(); final DeliveryBucket d1 = context.mock(DeliveryBucket.class, "d1"); final DeliveryBucket d2 = context.mock(DeliveryBucket.class, "d2"); final DeliveryBucket d3 = context.mock(DeliveryBucket.class, "d3"); final DeliveryBucket d4 = context.mock(DeliveryBucket.class, "d4"); final DeliveryBucket oos = context.mock(DeliveryBucket.class, "oos"); final DeliveryBucket off = context.mock(DeliveryBucket.class, "off"); buckets.put(d1, Collections.<CartItem>emptyList()); buckets.put(d2, Collections.<CartItem>emptyList()); buckets.put(d3, Collections.<CartItem>emptyList()); buckets.put(d4, Collections.<CartItem>emptyList()); buckets.put(oos, Collections.<CartItem>emptyList()); buckets.put(off, Collections.<CartItem>emptyList()); context.checking(new Expectations() {{ allowing(d1).getSupplier(); will(returnValue("s2")); allowing(d1).getGroup(); will(returnValue(CustomerOrderDelivery.STANDARD_DELIVERY_GROUP)); allowing(d2).getSupplier(); will(returnValue("s1")); allowing(d2).getGroup(); will(returnValue(CustomerOrderDelivery.DATE_WAIT_DELIVERY_GROUP)); allowing(d3).getSupplier(); will(returnValue("s2")); allowing(d3).getGroup(); will(returnValue(CustomerOrderDelivery.INVENTORY_WAIT_DELIVERY_GROUP)); allowing(d4).getSupplier(); will(returnValue("s1")); allowing(d4).getGroup(); will(returnValue(CustomerOrderDelivery.ELECTRONIC_DELIVERY_GROUP)); allowing(oos).getSupplier(); will(returnValue("s3")); allowing(oos).getGroup(); will(returnValue(CustomerOrderDelivery.NOSTOCK_DELIVERY_GROUP)); allowing(off).getSupplier(); will(returnValue("s1")); allowing(off).getGroup(); will(returnValue(CustomerOrderDelivery.OFFLINE_DELIVERY_GROUP)); }}); new OrderSplittingStrategyImpl(null, null, null, null).groupDeliveriesIntoMixedIfNecessary(buckets, new HashMap<String, Boolean>() {{ put("s1", Boolean.FALSE); put("s2", Boolean.FALSE); put("s3", Boolean.FALSE); }}); assertNotNull(buckets); assertEquals(6, buckets.size()); final Map<String, Set<String>> expected = new HashMap<String, Set<String>>() {{ put("s1", new HashSet<>(Arrays.asList( CustomerOrderDelivery.ELECTRONIC_DELIVERY_GROUP, CustomerOrderDelivery.OFFLINE_DELIVERY_GROUP, CustomerOrderDelivery.DATE_WAIT_DELIVERY_GROUP ))); put("s2", new HashSet<>(Arrays.asList( CustomerOrderDelivery.STANDARD_DELIVERY_GROUP, CustomerOrderDelivery.INVENTORY_WAIT_DELIVERY_GROUP ))); put("s3", new HashSet<>(Collections.singletonList( CustomerOrderDelivery.NOSTOCK_DELIVERY_GROUP ))); }}; for (final DeliveryBucket key : buckets.keySet()) { assertTrue("Bucket not expected " + key, expected.get(key.getSupplier()).contains(key.getGroup())); } }
@Test public void testGroupDeliveriesIntoMixedIfNecessaryStandardMultipleSuppliersSingleMix() throws Exception { final Map<DeliveryBucket, List<CartItem>> buckets = new HashMap<>(); final DeliveryBucket d1 = context.mock(DeliveryBucket.class, "d1"); final DeliveryBucket d2 = context.mock(DeliveryBucket.class, "d2"); final DeliveryBucket d3 = context.mock(DeliveryBucket.class, "d3"); final DeliveryBucket d4 = context.mock(DeliveryBucket.class, "d4"); final DeliveryBucket oos = context.mock(DeliveryBucket.class, "oos"); final DeliveryBucket off = context.mock(DeliveryBucket.class, "off"); buckets.put(d1, Collections.<CartItem>emptyList()); buckets.put(d2, Collections.<CartItem>emptyList()); buckets.put(d3, Collections.<CartItem>emptyList()); buckets.put(d4, Collections.<CartItem>emptyList()); buckets.put(oos, Collections.<CartItem>emptyList()); buckets.put(off, Collections.<CartItem>emptyList()); context.checking(new Expectations() {{ allowing(d1).getSupplier(); will(returnValue("s2")); allowing(d1).getGroup(); will(returnValue(CustomerOrderDelivery.STANDARD_DELIVERY_GROUP)); allowing(d2).getSupplier(); will(returnValue("s1")); allowing(d2).getGroup(); will(returnValue(CustomerOrderDelivery.DATE_WAIT_DELIVERY_GROUP)); allowing(d3).getSupplier(); will(returnValue("s2")); allowing(d3).getGroup(); will(returnValue(CustomerOrderDelivery.INVENTORY_WAIT_DELIVERY_GROUP)); allowing(d4).getSupplier(); will(returnValue("s1")); allowing(d4).getGroup(); will(returnValue(CustomerOrderDelivery.ELECTRONIC_DELIVERY_GROUP)); allowing(oos).getSupplier(); will(returnValue("s3")); allowing(oos).getGroup(); will(returnValue(CustomerOrderDelivery.NOSTOCK_DELIVERY_GROUP)); allowing(off).getSupplier(); will(returnValue("s1")); allowing(off).getGroup(); will(returnValue(CustomerOrderDelivery.OFFLINE_DELIVERY_GROUP)); }}); new OrderSplittingStrategyImpl(null, null, null, null).groupDeliveriesIntoMixedIfNecessary(buckets, new HashMap<String, Boolean>() {{ put("s1", Boolean.FALSE); put("s2", Boolean.TRUE); put("s3", Boolean.FALSE); }}); assertNotNull(buckets); assertEquals(5, buckets.size()); final Map<String, Set<String>> expected = new HashMap<String, Set<String>>() {{ put("s1", new HashSet<>(Arrays.asList( CustomerOrderDelivery.ELECTRONIC_DELIVERY_GROUP, CustomerOrderDelivery.OFFLINE_DELIVERY_GROUP, CustomerOrderDelivery.DATE_WAIT_DELIVERY_GROUP ))); put("s2", new HashSet<>(Collections.singletonList( CustomerOrderDelivery.MIX_DELIVERY_GROUP ))); put("s3", new HashSet<>(Collections.singletonList( CustomerOrderDelivery.NOSTOCK_DELIVERY_GROUP ))); }}; for (final DeliveryBucket key : buckets.keySet()) { assertTrue("Bucket not expected " + key, expected.get(key.getSupplier()).contains(key.getGroup())); } }