@Test public void testCalculateSingleNoBucket() throws Exception { final CarrierSlaService carrierSlaService = context.mock(CarrierSlaService.class, "carrierSlaService"); final MutableShoppingCart cart = context.mock(MutableShoppingCart.class, "cart"); final PricingPolicyProvider pricingPolicyProvider = context.mock(PricingPolicyProvider.class, "pricingPolicyProvider"); final PricingPolicyProvider.PricingPolicy pricingPolicy = context.mock(PricingPolicyProvider.PricingPolicy.class, "pricingPolicy"); final DeliveryCostRegionalPriceResolver deliveryCostRegionalPriceResolver = context.mock(DeliveryCostRegionalPriceResolver.class, "deliveryCostRegionalPriceResolver"); final SkuPrice cost = context.mock(SkuPrice.class, "cost"); final DeliveryBucket bucket1 = context.mock(DeliveryBucket.class, "bucket1"); context.checking(new Expectations() {{ allowing(cart).getCarrierSlaId(); will(returnValue(Collections.singletonMap("Main", 123L))); oneOf(cart).getCartItemMap(); will(returnValue(Collections.singletonMap(bucket1, Collections.emptyMap()))); oneOf(bucket1).getSupplier(); will(returnValue("")); }}); final Total delTotal = new FreeDeliveryCostCalculationStrategy(carrierSlaService, pricingPolicyProvider, deliveryCostRegionalPriceResolver).calculate(cart); assertNull(delTotal); context.assertIsSatisfied(); }
@Override public Total calculate(final MutableShoppingCart cart) { if (!cart.getCarrierSlaId().isEmpty()) { Total total = null; final Set<DeliveryBucket> cartBuckets = new HashSet<>(cart.getCartItemMap().keySet()); final Set<DeliveryBucket> supplierBuckets = new HashSet<>(); for (final Map.Entry<String, Long> supplierCarrierSla : cart.getCarrierSlaId().entrySet()) { final String supplier = supplierCarrierSla.getKey(); supplierBuckets.clear(); for (final DeliveryBucket bucket : cartBuckets) { if (bucket.getSupplier().equals(supplier)) { supplierBuckets.add(bucket); } } if (supplierBuckets.isEmpty()) { continue; } final CarrierSla carrierSla = carrierSlaService.getById(supplierCarrierSla.getValue()); if (carrierSla != null && isCarrierSlaTypeApplicable(carrierSla)) { final String carrierSlaGUID = carrierSla.getGuid(); final String carrierSlaName = new FailoverStringI18NModel( carrierSla.getDisplayName(), carrierSla.getName()).getValue(cart.getCurrentLocale()); final PricingPolicyProvider.PricingPolicy policy = pricingPolicyProvider.determinePricingPolicy( cart.getShoppingContext().getShopCode(), cart.getCurrencyCode(), cart.getCustomerEmail(), cart.getShoppingContext().getCountryCode(), cart.getShoppingContext().getStateCode() ); final BigDecimal qty = QTY; final SkuPrice price = getSkuPrice(cart, carrierSlaGUID, policy, supplier, qty); if (price != null && price.getSkuPriceId() > 0L) { final BigDecimal listPrice = ZERO; final BigDecimal deliveryListCost = ZERO; for (final DeliveryBucket bucket : supplierBuckets) { setShippingBucketCost(cart, bucket, carrierSlaGUID, carrierSlaName, qty, listPrice); } total = new TotalImpl( Total.ZERO, Total.ZERO, Total.ZERO, Total.ZERO, false, null, Total.ZERO, Total.ZERO, Total.ZERO, deliveryListCost, deliveryListCost, false, null, Total.ZERO, deliveryListCost, deliveryListCost, Total.ZERO, deliveryListCost, deliveryListCost ); } } } return total; } return null; }
FreeDeliveryCostCalculationStrategy implements DeliveryCostCalculationStrategy { @Override public Total calculate(final MutableShoppingCart cart) { if (!cart.getCarrierSlaId().isEmpty()) { Total total = null; final Set<DeliveryBucket> cartBuckets = new HashSet<>(cart.getCartItemMap().keySet()); final Set<DeliveryBucket> supplierBuckets = new HashSet<>(); for (final Map.Entry<String, Long> supplierCarrierSla : cart.getCarrierSlaId().entrySet()) { final String supplier = supplierCarrierSla.getKey(); supplierBuckets.clear(); for (final DeliveryBucket bucket : cartBuckets) { if (bucket.getSupplier().equals(supplier)) { supplierBuckets.add(bucket); } } if (supplierBuckets.isEmpty()) { continue; } final CarrierSla carrierSla = carrierSlaService.getById(supplierCarrierSla.getValue()); if (carrierSla != null && isCarrierSlaTypeApplicable(carrierSla)) { final String carrierSlaGUID = carrierSla.getGuid(); final String carrierSlaName = new FailoverStringI18NModel( carrierSla.getDisplayName(), carrierSla.getName()).getValue(cart.getCurrentLocale()); final PricingPolicyProvider.PricingPolicy policy = pricingPolicyProvider.determinePricingPolicy( cart.getShoppingContext().getShopCode(), cart.getCurrencyCode(), cart.getCustomerEmail(), cart.getShoppingContext().getCountryCode(), cart.getShoppingContext().getStateCode() ); final BigDecimal qty = QTY; final SkuPrice price = getSkuPrice(cart, carrierSlaGUID, policy, supplier, qty); if (price != null && price.getSkuPriceId() > 0L) { final BigDecimal listPrice = ZERO; final BigDecimal deliveryListCost = ZERO; for (final DeliveryBucket bucket : supplierBuckets) { setShippingBucketCost(cart, bucket, carrierSlaGUID, carrierSlaName, qty, listPrice); } total = new TotalImpl( Total.ZERO, Total.ZERO, Total.ZERO, Total.ZERO, false, null, Total.ZERO, Total.ZERO, Total.ZERO, deliveryListCost, deliveryListCost, false, null, Total.ZERO, deliveryListCost, deliveryListCost, Total.ZERO, deliveryListCost, deliveryListCost ); } } } return total; } return null; } }
FreeDeliveryCostCalculationStrategy implements DeliveryCostCalculationStrategy { @Override public Total calculate(final MutableShoppingCart cart) { if (!cart.getCarrierSlaId().isEmpty()) { Total total = null; final Set<DeliveryBucket> cartBuckets = new HashSet<>(cart.getCartItemMap().keySet()); final Set<DeliveryBucket> supplierBuckets = new HashSet<>(); for (final Map.Entry<String, Long> supplierCarrierSla : cart.getCarrierSlaId().entrySet()) { final String supplier = supplierCarrierSla.getKey(); supplierBuckets.clear(); for (final DeliveryBucket bucket : cartBuckets) { if (bucket.getSupplier().equals(supplier)) { supplierBuckets.add(bucket); } } if (supplierBuckets.isEmpty()) { continue; } final CarrierSla carrierSla = carrierSlaService.getById(supplierCarrierSla.getValue()); if (carrierSla != null && isCarrierSlaTypeApplicable(carrierSla)) { final String carrierSlaGUID = carrierSla.getGuid(); final String carrierSlaName = new FailoverStringI18NModel( carrierSla.getDisplayName(), carrierSla.getName()).getValue(cart.getCurrentLocale()); final PricingPolicyProvider.PricingPolicy policy = pricingPolicyProvider.determinePricingPolicy( cart.getShoppingContext().getShopCode(), cart.getCurrencyCode(), cart.getCustomerEmail(), cart.getShoppingContext().getCountryCode(), cart.getShoppingContext().getStateCode() ); final BigDecimal qty = QTY; final SkuPrice price = getSkuPrice(cart, carrierSlaGUID, policy, supplier, qty); if (price != null && price.getSkuPriceId() > 0L) { final BigDecimal listPrice = ZERO; final BigDecimal deliveryListCost = ZERO; for (final DeliveryBucket bucket : supplierBuckets) { setShippingBucketCost(cart, bucket, carrierSlaGUID, carrierSlaName, qty, listPrice); } total = new TotalImpl( Total.ZERO, Total.ZERO, Total.ZERO, Total.ZERO, false, null, Total.ZERO, Total.ZERO, Total.ZERO, deliveryListCost, deliveryListCost, false, null, Total.ZERO, deliveryListCost, deliveryListCost, Total.ZERO, deliveryListCost, deliveryListCost ); } } } return total; } return null; } FreeDeliveryCostCalculationStrategy(final CarrierSlaService carrierSlaService,
                                               final PricingPolicyProvider pricingPolicyProvider,
                                               final DeliveryCostRegionalPriceResolver deliveryCostRegionalPriceResolver); }
FreeDeliveryCostCalculationStrategy implements DeliveryCostCalculationStrategy { @Override public Total calculate(final MutableShoppingCart cart) { if (!cart.getCarrierSlaId().isEmpty()) { Total total = null; final Set<DeliveryBucket> cartBuckets = new HashSet<>(cart.getCartItemMap().keySet()); final Set<DeliveryBucket> supplierBuckets = new HashSet<>(); for (final Map.Entry<String, Long> supplierCarrierSla : cart.getCarrierSlaId().entrySet()) { final String supplier = supplierCarrierSla.getKey(); supplierBuckets.clear(); for (final DeliveryBucket bucket : cartBuckets) { if (bucket.getSupplier().equals(supplier)) { supplierBuckets.add(bucket); } } if (supplierBuckets.isEmpty()) { continue; } final CarrierSla carrierSla = carrierSlaService.getById(supplierCarrierSla.getValue()); if (carrierSla != null && isCarrierSlaTypeApplicable(carrierSla)) { final String carrierSlaGUID = carrierSla.getGuid(); final String carrierSlaName = new FailoverStringI18NModel( carrierSla.getDisplayName(), carrierSla.getName()).getValue(cart.getCurrentLocale()); final PricingPolicyProvider.PricingPolicy policy = pricingPolicyProvider.determinePricingPolicy( cart.getShoppingContext().getShopCode(), cart.getCurrencyCode(), cart.getCustomerEmail(), cart.getShoppingContext().getCountryCode(), cart.getShoppingContext().getStateCode() ); final BigDecimal qty = QTY; final SkuPrice price = getSkuPrice(cart, carrierSlaGUID, policy, supplier, qty); if (price != null && price.getSkuPriceId() > 0L) { final BigDecimal listPrice = ZERO; final BigDecimal deliveryListCost = ZERO; for (final DeliveryBucket bucket : supplierBuckets) { setShippingBucketCost(cart, bucket, carrierSlaGUID, carrierSlaName, qty, listPrice); } total = new TotalImpl( Total.ZERO, Total.ZERO, Total.ZERO, Total.ZERO, false, null, Total.ZERO, Total.ZERO, Total.ZERO, deliveryListCost, deliveryListCost, false, null, Total.ZERO, deliveryListCost, deliveryListCost, Total.ZERO, deliveryListCost, deliveryListCost ); } } } return total; } return null; } FreeDeliveryCostCalculationStrategy(final CarrierSlaService carrierSlaService,
                                               final PricingPolicyProvider pricingPolicyProvider,
                                               final DeliveryCostRegionalPriceResolver deliveryCostRegionalPriceResolver); @Override Total calculate(final MutableShoppingCart cart); }
FreeDeliveryCostCalculationStrategy implements DeliveryCostCalculationStrategy { @Override public Total calculate(final MutableShoppingCart cart) { if (!cart.getCarrierSlaId().isEmpty()) { Total total = null; final Set<DeliveryBucket> cartBuckets = new HashSet<>(cart.getCartItemMap().keySet()); final Set<DeliveryBucket> supplierBuckets = new HashSet<>(); for (final Map.Entry<String, Long> supplierCarrierSla : cart.getCarrierSlaId().entrySet()) { final String supplier = supplierCarrierSla.getKey(); supplierBuckets.clear(); for (final DeliveryBucket bucket : cartBuckets) { if (bucket.getSupplier().equals(supplier)) { supplierBuckets.add(bucket); } } if (supplierBuckets.isEmpty()) { continue; } final CarrierSla carrierSla = carrierSlaService.getById(supplierCarrierSla.getValue()); if (carrierSla != null && isCarrierSlaTypeApplicable(carrierSla)) { final String carrierSlaGUID = carrierSla.getGuid(); final String carrierSlaName = new FailoverStringI18NModel( carrierSla.getDisplayName(), carrierSla.getName()).getValue(cart.getCurrentLocale()); final PricingPolicyProvider.PricingPolicy policy = pricingPolicyProvider.determinePricingPolicy( cart.getShoppingContext().getShopCode(), cart.getCurrencyCode(), cart.getCustomerEmail(), cart.getShoppingContext().getCountryCode(), cart.getShoppingContext().getStateCode() ); final BigDecimal qty = QTY; final SkuPrice price = getSkuPrice(cart, carrierSlaGUID, policy, supplier, qty); if (price != null && price.getSkuPriceId() > 0L) { final BigDecimal listPrice = ZERO; final BigDecimal deliveryListCost = ZERO; for (final DeliveryBucket bucket : supplierBuckets) { setShippingBucketCost(cart, bucket, carrierSlaGUID, carrierSlaName, qty, listPrice); } total = new TotalImpl( Total.ZERO, Total.ZERO, Total.ZERO, Total.ZERO, false, null, Total.ZERO, Total.ZERO, Total.ZERO, deliveryListCost, deliveryListCost, false, null, Total.ZERO, deliveryListCost, deliveryListCost, Total.ZERO, deliveryListCost, deliveryListCost ); } } } return total; } return null; } FreeDeliveryCostCalculationStrategy(final CarrierSlaService carrierSlaService,
                                               final PricingPolicyProvider pricingPolicyProvider,
                                               final DeliveryCostRegionalPriceResolver deliveryCostRegionalPriceResolver); @Override Total calculate(final MutableShoppingCart cart);  }