@Test public void testExecuteWithAddressParamsBillingNotRequiredSeparate() { MutableShoppingCart shoppingCart = new ShoppingCartImpl(); shoppingCart.initialise(ctx().getBean("amountCalculationStrategy", AmountCalculationStrategy.class)); final ShoppingCartCommandFactory commands = ctx().getBean("shoppingCartCommandFactory", ShoppingCartCommandFactory.class); final Address billing = context.mock(Address.class, "billing"); final Address delivery = context.mock(Address.class, "delivery"); context.checking(new Expectations() {{ allowing(billing).getAddressId(); will(returnValue(234L)); allowing(billing).getCountryCode(); will(returnValue("GB")); allowing(billing).getStateCode(); will(returnValue("GB-CAM")); allowing(delivery).getAddressId(); will(returnValue(345L)); allowing(delivery).getCountryCode(); will(returnValue("GB")); allowing(delivery).getStateCode(); will(returnValue("GB-CAM")); }}); assertNotNull(shoppingCart.getCarrierSlaId()); assertTrue(shoppingCart.getCarrierSlaId().isEmpty()); assertNull(shoppingCart.getOrderInfo().getBillingAddressId()); assertNull(shoppingCart.getOrderInfo().getDeliveryAddressId()); commands.execute(shoppingCart, new HashMap<String, Object>() {{ put(ShoppingCartCommand.CMD_CHANGECURRENCY, "EUR"); put(ShoppingCartCommand.CMD_CHANGELOCALE, "en"); put(ShoppingCartCommand.CMD_SETSHOP, "10"); put(ShoppingCartCommand.CMD_SEPARATEBILLING, "true"); put(ShoppingCartCommand.CMD_SETCARRIERSLA, "123"); put(ShoppingCartCommand.CMD_SETCARRIERSLA_P_BILLING_NOT_REQUIRED, Boolean.TRUE); put(ShoppingCartCommand.CMD_SETCARRIERSLA_P_DELIVERY_NOT_REQUIRED, Boolean.FALSE); put(ShoppingCartCommand.CMD_SETCARRIERSLA_P_BILLING_ADDRESS, billing); put(ShoppingCartCommand.CMD_SETCARRIERSLA_P_DELIVERY_ADDRESS, delivery); }}); assertEquals(123, shoppingCart.getCarrierSlaId().get("").intValue()); assertNull(shoppingCart.getOrderInfo().getBillingAddressId()); assertEquals(345, shoppingCart.getOrderInfo().getDeliveryAddressId().intValue()); assertTrue(shoppingCart.getOrderInfo().isBillingAddressNotRequired()); assertFalse(shoppingCart.getOrderInfo().isDeliveryAddressNotRequired()); assertNull(shoppingCart.getShoppingContext().getCountryCode()); assertNull(shoppingCart.getShoppingContext().getStateCode()); }
@Override public void execute(final MutableShoppingCart shoppingCart, final Map<String, Object> parameters) { if (parameters.containsKey(getCmdKey())) { final String slaIdsRaw = (String) parameters.get(getCmdKey()); final String[] slaIds = StringUtils.split(slaIdsRaw, '|'); if (slaIds != null && slaIds.length > 0) { final Map<String, Long> selection = new HashMap<>(); for (final String slaIdRaw : slaIds) { final int sepPos = slaIdRaw.indexOf('-'); final String[] slaId = sepPos == -1 ? new String[] { slaIdRaw } : new String[] { slaIdRaw.substring(0, sepPos), slaIdRaw.substring(sepPos + 1) }; final long slaPkvalue = NumberUtils.toLong(slaId[0]); final String supplier = slaId.length > 1 ? slaId[1] : ""; final Long current = shoppingCart.getCarrierSlaId().get(supplier); if ((slaPkvalue <= 0L && current != null && current > 0L) || (slaPkvalue > 0L && (current == null || !current.equals(slaPkvalue)))) { selection.put(supplier, slaPkvalue); } } if (!selection.isEmpty()) { for (final Map.Entry<String, Long> slaSelection : selection.entrySet()) { LOG.debug("Set carrier sla to {} for '{}'", slaSelection.getValue(), slaSelection.getKey()); if (slaSelection.getValue() <= 0L) { shoppingCart.getOrderInfo().putCarrierSlaId(slaSelection.getKey(), null); } else { shoppingCart.getOrderInfo().putCarrierSlaId(slaSelection.getKey(), slaSelection.getValue()); } } final boolean hasSelection = !shoppingCart.getCarrierSlaId().isEmpty(); setAddressNotRequiredFlags(shoppingCart, parameters); if (hasSelection) { setAddressParametersIfRequired(shoppingCart, parameters); } else { shoppingCart.getOrderInfo().setBillingAddressId(null); shoppingCart.getOrderInfo().setDeliveryAddressId(null); shoppingCart.getShoppingContext().setCountryCode(null); shoppingCart.getShoppingContext().setStateCode(null); } this.deliveryTimeEstimationVisitor.visit(shoppingCart); recalculate(shoppingCart); markDirty(shoppingCart); } } } }
SetCarrierSlaCartCommandImpl extends AbstractCartCommandImpl implements ShoppingCartCommand { @Override public void execute(final MutableShoppingCart shoppingCart, final Map<String, Object> parameters) { if (parameters.containsKey(getCmdKey())) { final String slaIdsRaw = (String) parameters.get(getCmdKey()); final String[] slaIds = StringUtils.split(slaIdsRaw, '|'); if (slaIds != null && slaIds.length > 0) { final Map<String, Long> selection = new HashMap<>(); for (final String slaIdRaw : slaIds) { final int sepPos = slaIdRaw.indexOf('-'); final String[] slaId = sepPos == -1 ? new String[] { slaIdRaw } : new String[] { slaIdRaw.substring(0, sepPos), slaIdRaw.substring(sepPos + 1) }; final long slaPkvalue = NumberUtils.toLong(slaId[0]); final String supplier = slaId.length > 1 ? slaId[1] : ""; final Long current = shoppingCart.getCarrierSlaId().get(supplier); if ((slaPkvalue <= 0L && current != null && current > 0L) || (slaPkvalue > 0L && (current == null || !current.equals(slaPkvalue)))) { selection.put(supplier, slaPkvalue); } } if (!selection.isEmpty()) { for (final Map.Entry<String, Long> slaSelection : selection.entrySet()) { LOG.debug("Set carrier sla to {} for '{}'", slaSelection.getValue(), slaSelection.getKey()); if (slaSelection.getValue() <= 0L) { shoppingCart.getOrderInfo().putCarrierSlaId(slaSelection.getKey(), null); } else { shoppingCart.getOrderInfo().putCarrierSlaId(slaSelection.getKey(), slaSelection.getValue()); } } final boolean hasSelection = !shoppingCart.getCarrierSlaId().isEmpty(); setAddressNotRequiredFlags(shoppingCart, parameters); if (hasSelection) { setAddressParametersIfRequired(shoppingCart, parameters); } else { shoppingCart.getOrderInfo().setBillingAddressId(null); shoppingCart.getOrderInfo().setDeliveryAddressId(null); shoppingCart.getShoppingContext().setCountryCode(null); shoppingCart.getShoppingContext().setStateCode(null); } this.deliveryTimeEstimationVisitor.visit(shoppingCart); recalculate(shoppingCart); markDirty(shoppingCart); } } } } }
SetCarrierSlaCartCommandImpl extends AbstractCartCommandImpl implements ShoppingCartCommand { @Override public void execute(final MutableShoppingCart shoppingCart, final Map<String, Object> parameters) { if (parameters.containsKey(getCmdKey())) { final String slaIdsRaw = (String) parameters.get(getCmdKey()); final String[] slaIds = StringUtils.split(slaIdsRaw, '|'); if (slaIds != null && slaIds.length > 0) { final Map<String, Long> selection = new HashMap<>(); for (final String slaIdRaw : slaIds) { final int sepPos = slaIdRaw.indexOf('-'); final String[] slaId = sepPos == -1 ? new String[] { slaIdRaw } : new String[] { slaIdRaw.substring(0, sepPos), slaIdRaw.substring(sepPos + 1) }; final long slaPkvalue = NumberUtils.toLong(slaId[0]); final String supplier = slaId.length > 1 ? slaId[1] : ""; final Long current = shoppingCart.getCarrierSlaId().get(supplier); if ((slaPkvalue <= 0L && current != null && current > 0L) || (slaPkvalue > 0L && (current == null || !current.equals(slaPkvalue)))) { selection.put(supplier, slaPkvalue); } } if (!selection.isEmpty()) { for (final Map.Entry<String, Long> slaSelection : selection.entrySet()) { LOG.debug("Set carrier sla to {} for '{}'", slaSelection.getValue(), slaSelection.getKey()); if (slaSelection.getValue() <= 0L) { shoppingCart.getOrderInfo().putCarrierSlaId(slaSelection.getKey(), null); } else { shoppingCart.getOrderInfo().putCarrierSlaId(slaSelection.getKey(), slaSelection.getValue()); } } final boolean hasSelection = !shoppingCart.getCarrierSlaId().isEmpty(); setAddressNotRequiredFlags(shoppingCart, parameters); if (hasSelection) { setAddressParametersIfRequired(shoppingCart, parameters); } else { shoppingCart.getOrderInfo().setBillingAddressId(null); shoppingCart.getOrderInfo().setDeliveryAddressId(null); shoppingCart.getShoppingContext().setCountryCode(null); shoppingCart.getShoppingContext().setStateCode(null); } this.deliveryTimeEstimationVisitor.visit(shoppingCart); recalculate(shoppingCart); markDirty(shoppingCart); } } } } SetCarrierSlaCartCommandImpl(final ShoppingCartCommandRegistry registry,
                                        final DeliveryTimeEstimationVisitor deliveryTimeEstimationVisitor); }
SetCarrierSlaCartCommandImpl extends AbstractCartCommandImpl implements ShoppingCartCommand { @Override public void execute(final MutableShoppingCart shoppingCart, final Map<String, Object> parameters) { if (parameters.containsKey(getCmdKey())) { final String slaIdsRaw = (String) parameters.get(getCmdKey()); final String[] slaIds = StringUtils.split(slaIdsRaw, '|'); if (slaIds != null && slaIds.length > 0) { final Map<String, Long> selection = new HashMap<>(); for (final String slaIdRaw : slaIds) { final int sepPos = slaIdRaw.indexOf('-'); final String[] slaId = sepPos == -1 ? new String[] { slaIdRaw } : new String[] { slaIdRaw.substring(0, sepPos), slaIdRaw.substring(sepPos + 1) }; final long slaPkvalue = NumberUtils.toLong(slaId[0]); final String supplier = slaId.length > 1 ? slaId[1] : ""; final Long current = shoppingCart.getCarrierSlaId().get(supplier); if ((slaPkvalue <= 0L && current != null && current > 0L) || (slaPkvalue > 0L && (current == null || !current.equals(slaPkvalue)))) { selection.put(supplier, slaPkvalue); } } if (!selection.isEmpty()) { for (final Map.Entry<String, Long> slaSelection : selection.entrySet()) { LOG.debug("Set carrier sla to {} for '{}'", slaSelection.getValue(), slaSelection.getKey()); if (slaSelection.getValue() <= 0L) { shoppingCart.getOrderInfo().putCarrierSlaId(slaSelection.getKey(), null); } else { shoppingCart.getOrderInfo().putCarrierSlaId(slaSelection.getKey(), slaSelection.getValue()); } } final boolean hasSelection = !shoppingCart.getCarrierSlaId().isEmpty(); setAddressNotRequiredFlags(shoppingCart, parameters); if (hasSelection) { setAddressParametersIfRequired(shoppingCart, parameters); } else { shoppingCart.getOrderInfo().setBillingAddressId(null); shoppingCart.getOrderInfo().setDeliveryAddressId(null); shoppingCart.getShoppingContext().setCountryCode(null); shoppingCart.getShoppingContext().setStateCode(null); } this.deliveryTimeEstimationVisitor.visit(shoppingCart); recalculate(shoppingCart); markDirty(shoppingCart); } } } } SetCarrierSlaCartCommandImpl(final ShoppingCartCommandRegistry registry,
                                        final DeliveryTimeEstimationVisitor deliveryTimeEstimationVisitor); @Override String getCmdKey(); @Override void execute(final MutableShoppingCart shoppingCart, final Map<String, Object> parameters); }
SetCarrierSlaCartCommandImpl extends AbstractCartCommandImpl implements ShoppingCartCommand { @Override public void execute(final MutableShoppingCart shoppingCart, final Map<String, Object> parameters) { if (parameters.containsKey(getCmdKey())) { final String slaIdsRaw = (String) parameters.get(getCmdKey()); final String[] slaIds = StringUtils.split(slaIdsRaw, '|'); if (slaIds != null && slaIds.length > 0) { final Map<String, Long> selection = new HashMap<>(); for (final String slaIdRaw : slaIds) { final int sepPos = slaIdRaw.indexOf('-'); final String[] slaId = sepPos == -1 ? new String[] { slaIdRaw } : new String[] { slaIdRaw.substring(0, sepPos), slaIdRaw.substring(sepPos + 1) }; final long slaPkvalue = NumberUtils.toLong(slaId[0]); final String supplier = slaId.length > 1 ? slaId[1] : ""; final Long current = shoppingCart.getCarrierSlaId().get(supplier); if ((slaPkvalue <= 0L && current != null && current > 0L) || (slaPkvalue > 0L && (current == null || !current.equals(slaPkvalue)))) { selection.put(supplier, slaPkvalue); } } if (!selection.isEmpty()) { for (final Map.Entry<String, Long> slaSelection : selection.entrySet()) { LOG.debug("Set carrier sla to {} for '{}'", slaSelection.getValue(), slaSelection.getKey()); if (slaSelection.getValue() <= 0L) { shoppingCart.getOrderInfo().putCarrierSlaId(slaSelection.getKey(), null); } else { shoppingCart.getOrderInfo().putCarrierSlaId(slaSelection.getKey(), slaSelection.getValue()); } } final boolean hasSelection = !shoppingCart.getCarrierSlaId().isEmpty(); setAddressNotRequiredFlags(shoppingCart, parameters); if (hasSelection) { setAddressParametersIfRequired(shoppingCart, parameters); } else { shoppingCart.getOrderInfo().setBillingAddressId(null); shoppingCart.getOrderInfo().setDeliveryAddressId(null); shoppingCart.getShoppingContext().setCountryCode(null); shoppingCart.getShoppingContext().setStateCode(null); } this.deliveryTimeEstimationVisitor.visit(shoppingCart); recalculate(shoppingCart); markDirty(shoppingCart); } } } } SetCarrierSlaCartCommandImpl(final ShoppingCartCommandRegistry registry,
                                        final DeliveryTimeEstimationVisitor deliveryTimeEstimationVisitor); @Override String getCmdKey(); @Override void execute(final MutableShoppingCart shoppingCart, final Map<String, Object> parameters);  }