@Test public void testExecuteWithAddressParamsBillingNotRequiredOverwriteSeparate() { 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")); }}); shoppingCart.getOrderInfo().setBillingAddressId(234L); shoppingCart.getOrderInfo().setDeliveryAddressId(345L); assertNotNull(shoppingCart.getOrderInfo().getBillingAddressId()); assertNotNull(shoppingCart.getOrderInfo().getDeliveryAddressId()); shoppingCart.getOrderInfo().setBillingAddressNotRequired(true); 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_SETADDRESES, "1"); put(ShoppingCartCommand.CMD_SETADDRESES_P_BILLING_ADDRESS, billing); put(ShoppingCartCommand.CMD_SETADDRESES_P_DELIVERY_ADDRESS, delivery); }}); assertNull(shoppingCart.getOrderInfo().getBillingAddressId()); assertEquals(345, shoppingCart.getOrderInfo().getDeliveryAddressId().intValue()); assertNull(shoppingCart.getShoppingContext().getCountryCode()); assertNull(shoppingCart.getShoppingContext().getStateCode()); }
@Override public void execute(final MutableShoppingCart shoppingCart, final Map<String, Object> parameters) { if (parameters.containsKey(getCmdKey())) { boolean changed = false; if (parameters.containsKey(CMD_SETADDRESES_P_BILLING_ADDRESS)) { final boolean notRequired = shoppingCart.getOrderInfo().isBillingAddressNotRequired(); if (notRequired) { if (shoppingCart.getOrderInfo().getBillingAddressId() != null) { shoppingCart.getOrderInfo().setBillingAddressId(null); shoppingCart.getShoppingContext().setCountryCode(null); shoppingCart.getShoppingContext().setStateCode(null); changed = true; } } else { final Address billing = (Address) parameters.get(CMD_SETADDRESES_P_BILLING_ADDRESS); if (billing != null) { if (!Long.valueOf(billing.getAddressId()).equals(shoppingCart.getOrderInfo().getBillingAddressId())) { shoppingCart.getOrderInfo().setBillingAddressId(billing.getAddressId()); shoppingCart.getShoppingContext().setCountryCode(billing.getCountryCode()); shoppingCart.getShoppingContext().setStateCode(billing.getStateCode()); changed = true; } } else if (shoppingCart.getOrderInfo().getBillingAddressId() != null) { shoppingCart.getOrderInfo().setBillingAddressId(null); shoppingCart.getShoppingContext().setCountryCode(null); shoppingCart.getShoppingContext().setStateCode(null); changed = true; } } } if (parameters.containsKey(CMD_SETADDRESES_P_DELIVERY_ADDRESS)) { final boolean notRequired = shoppingCart.getOrderInfo().isDeliveryAddressNotRequired(); if (notRequired) { if (shoppingCart.getOrderInfo().getDeliveryAddressId() != null) { shoppingCart.getOrderInfo().setDeliveryAddressId(null); changed = true; } if (!shoppingCart.isSeparateBillingAddress() && !shoppingCart.isBillingAddressNotRequired()) { final Address delivery = (Address) parameters.get(CMD_SETADDRESES_P_DELIVERY_ADDRESS); if (delivery != null) { if (!Long.valueOf(delivery.getAddressId()).equals(shoppingCart.getOrderInfo().getBillingAddressId())) { shoppingCart.getOrderInfo().setBillingAddressId(delivery.getAddressId()); shoppingCart.getShoppingContext().setCountryCode(delivery.getCountryCode()); shoppingCart.getShoppingContext().setStateCode(delivery.getStateCode()); changed = true; } } } } else { final Address delivery = (Address) parameters.get(CMD_SETADDRESES_P_DELIVERY_ADDRESS); if (delivery != null) { if (!Long.valueOf(delivery.getAddressId()).equals(shoppingCart.getOrderInfo().getDeliveryAddressId())) { shoppingCart.getOrderInfo().setDeliveryAddressId(delivery.getAddressId()); if (!shoppingCart.isSeparateBillingAddress() && !shoppingCart.isBillingAddressNotRequired()) { shoppingCart.getOrderInfo().setBillingAddressId(delivery.getAddressId()); shoppingCart.getShoppingContext().setCountryCode(delivery.getCountryCode()); shoppingCart.getShoppingContext().setStateCode(delivery.getStateCode()); } changed = true; } } else if (shoppingCart.getOrderInfo().getDeliveryAddressId() != null) { shoppingCart.getOrderInfo().setDeliveryAddressId(null); changed = true; } } } if (changed) { recalculate(shoppingCart); markDirty(shoppingCart); } } }
SetAddressesCartCommandImpl extends AbstractCartCommandImpl implements ShoppingCartCommand { @Override public void execute(final MutableShoppingCart shoppingCart, final Map<String, Object> parameters) { if (parameters.containsKey(getCmdKey())) { boolean changed = false; if (parameters.containsKey(CMD_SETADDRESES_P_BILLING_ADDRESS)) { final boolean notRequired = shoppingCart.getOrderInfo().isBillingAddressNotRequired(); if (notRequired) { if (shoppingCart.getOrderInfo().getBillingAddressId() != null) { shoppingCart.getOrderInfo().setBillingAddressId(null); shoppingCart.getShoppingContext().setCountryCode(null); shoppingCart.getShoppingContext().setStateCode(null); changed = true; } } else { final Address billing = (Address) parameters.get(CMD_SETADDRESES_P_BILLING_ADDRESS); if (billing != null) { if (!Long.valueOf(billing.getAddressId()).equals(shoppingCart.getOrderInfo().getBillingAddressId())) { shoppingCart.getOrderInfo().setBillingAddressId(billing.getAddressId()); shoppingCart.getShoppingContext().setCountryCode(billing.getCountryCode()); shoppingCart.getShoppingContext().setStateCode(billing.getStateCode()); changed = true; } } else if (shoppingCart.getOrderInfo().getBillingAddressId() != null) { shoppingCart.getOrderInfo().setBillingAddressId(null); shoppingCart.getShoppingContext().setCountryCode(null); shoppingCart.getShoppingContext().setStateCode(null); changed = true; } } } if (parameters.containsKey(CMD_SETADDRESES_P_DELIVERY_ADDRESS)) { final boolean notRequired = shoppingCart.getOrderInfo().isDeliveryAddressNotRequired(); if (notRequired) { if (shoppingCart.getOrderInfo().getDeliveryAddressId() != null) { shoppingCart.getOrderInfo().setDeliveryAddressId(null); changed = true; } if (!shoppingCart.isSeparateBillingAddress() && !shoppingCart.isBillingAddressNotRequired()) { final Address delivery = (Address) parameters.get(CMD_SETADDRESES_P_DELIVERY_ADDRESS); if (delivery != null) { if (!Long.valueOf(delivery.getAddressId()).equals(shoppingCart.getOrderInfo().getBillingAddressId())) { shoppingCart.getOrderInfo().setBillingAddressId(delivery.getAddressId()); shoppingCart.getShoppingContext().setCountryCode(delivery.getCountryCode()); shoppingCart.getShoppingContext().setStateCode(delivery.getStateCode()); changed = true; } } } } else { final Address delivery = (Address) parameters.get(CMD_SETADDRESES_P_DELIVERY_ADDRESS); if (delivery != null) { if (!Long.valueOf(delivery.getAddressId()).equals(shoppingCart.getOrderInfo().getDeliveryAddressId())) { shoppingCart.getOrderInfo().setDeliveryAddressId(delivery.getAddressId()); if (!shoppingCart.isSeparateBillingAddress() && !shoppingCart.isBillingAddressNotRequired()) { shoppingCart.getOrderInfo().setBillingAddressId(delivery.getAddressId()); shoppingCart.getShoppingContext().setCountryCode(delivery.getCountryCode()); shoppingCart.getShoppingContext().setStateCode(delivery.getStateCode()); } changed = true; } } else if (shoppingCart.getOrderInfo().getDeliveryAddressId() != null) { shoppingCart.getOrderInfo().setDeliveryAddressId(null); changed = true; } } } if (changed) { recalculate(shoppingCart); markDirty(shoppingCart); } } } }
SetAddressesCartCommandImpl extends AbstractCartCommandImpl implements ShoppingCartCommand { @Override public void execute(final MutableShoppingCart shoppingCart, final Map<String, Object> parameters) { if (parameters.containsKey(getCmdKey())) { boolean changed = false; if (parameters.containsKey(CMD_SETADDRESES_P_BILLING_ADDRESS)) { final boolean notRequired = shoppingCart.getOrderInfo().isBillingAddressNotRequired(); if (notRequired) { if (shoppingCart.getOrderInfo().getBillingAddressId() != null) { shoppingCart.getOrderInfo().setBillingAddressId(null); shoppingCart.getShoppingContext().setCountryCode(null); shoppingCart.getShoppingContext().setStateCode(null); changed = true; } } else { final Address billing = (Address) parameters.get(CMD_SETADDRESES_P_BILLING_ADDRESS); if (billing != null) { if (!Long.valueOf(billing.getAddressId()).equals(shoppingCart.getOrderInfo().getBillingAddressId())) { shoppingCart.getOrderInfo().setBillingAddressId(billing.getAddressId()); shoppingCart.getShoppingContext().setCountryCode(billing.getCountryCode()); shoppingCart.getShoppingContext().setStateCode(billing.getStateCode()); changed = true; } } else if (shoppingCart.getOrderInfo().getBillingAddressId() != null) { shoppingCart.getOrderInfo().setBillingAddressId(null); shoppingCart.getShoppingContext().setCountryCode(null); shoppingCart.getShoppingContext().setStateCode(null); changed = true; } } } if (parameters.containsKey(CMD_SETADDRESES_P_DELIVERY_ADDRESS)) { final boolean notRequired = shoppingCart.getOrderInfo().isDeliveryAddressNotRequired(); if (notRequired) { if (shoppingCart.getOrderInfo().getDeliveryAddressId() != null) { shoppingCart.getOrderInfo().setDeliveryAddressId(null); changed = true; } if (!shoppingCart.isSeparateBillingAddress() && !shoppingCart.isBillingAddressNotRequired()) { final Address delivery = (Address) parameters.get(CMD_SETADDRESES_P_DELIVERY_ADDRESS); if (delivery != null) { if (!Long.valueOf(delivery.getAddressId()).equals(shoppingCart.getOrderInfo().getBillingAddressId())) { shoppingCart.getOrderInfo().setBillingAddressId(delivery.getAddressId()); shoppingCart.getShoppingContext().setCountryCode(delivery.getCountryCode()); shoppingCart.getShoppingContext().setStateCode(delivery.getStateCode()); changed = true; } } } } else { final Address delivery = (Address) parameters.get(CMD_SETADDRESES_P_DELIVERY_ADDRESS); if (delivery != null) { if (!Long.valueOf(delivery.getAddressId()).equals(shoppingCart.getOrderInfo().getDeliveryAddressId())) { shoppingCart.getOrderInfo().setDeliveryAddressId(delivery.getAddressId()); if (!shoppingCart.isSeparateBillingAddress() && !shoppingCart.isBillingAddressNotRequired()) { shoppingCart.getOrderInfo().setBillingAddressId(delivery.getAddressId()); shoppingCart.getShoppingContext().setCountryCode(delivery.getCountryCode()); shoppingCart.getShoppingContext().setStateCode(delivery.getStateCode()); } changed = true; } } else if (shoppingCart.getOrderInfo().getDeliveryAddressId() != null) { shoppingCart.getOrderInfo().setDeliveryAddressId(null); changed = true; } } } if (changed) { recalculate(shoppingCart); markDirty(shoppingCart); } } } SetAddressesCartCommandImpl(final ShoppingCartCommandRegistry registry); }
SetAddressesCartCommandImpl extends AbstractCartCommandImpl implements ShoppingCartCommand { @Override public void execute(final MutableShoppingCart shoppingCart, final Map<String, Object> parameters) { if (parameters.containsKey(getCmdKey())) { boolean changed = false; if (parameters.containsKey(CMD_SETADDRESES_P_BILLING_ADDRESS)) { final boolean notRequired = shoppingCart.getOrderInfo().isBillingAddressNotRequired(); if (notRequired) { if (shoppingCart.getOrderInfo().getBillingAddressId() != null) { shoppingCart.getOrderInfo().setBillingAddressId(null); shoppingCart.getShoppingContext().setCountryCode(null); shoppingCart.getShoppingContext().setStateCode(null); changed = true; } } else { final Address billing = (Address) parameters.get(CMD_SETADDRESES_P_BILLING_ADDRESS); if (billing != null) { if (!Long.valueOf(billing.getAddressId()).equals(shoppingCart.getOrderInfo().getBillingAddressId())) { shoppingCart.getOrderInfo().setBillingAddressId(billing.getAddressId()); shoppingCart.getShoppingContext().setCountryCode(billing.getCountryCode()); shoppingCart.getShoppingContext().setStateCode(billing.getStateCode()); changed = true; } } else if (shoppingCart.getOrderInfo().getBillingAddressId() != null) { shoppingCart.getOrderInfo().setBillingAddressId(null); shoppingCart.getShoppingContext().setCountryCode(null); shoppingCart.getShoppingContext().setStateCode(null); changed = true; } } } if (parameters.containsKey(CMD_SETADDRESES_P_DELIVERY_ADDRESS)) { final boolean notRequired = shoppingCart.getOrderInfo().isDeliveryAddressNotRequired(); if (notRequired) { if (shoppingCart.getOrderInfo().getDeliveryAddressId() != null) { shoppingCart.getOrderInfo().setDeliveryAddressId(null); changed = true; } if (!shoppingCart.isSeparateBillingAddress() && !shoppingCart.isBillingAddressNotRequired()) { final Address delivery = (Address) parameters.get(CMD_SETADDRESES_P_DELIVERY_ADDRESS); if (delivery != null) { if (!Long.valueOf(delivery.getAddressId()).equals(shoppingCart.getOrderInfo().getBillingAddressId())) { shoppingCart.getOrderInfo().setBillingAddressId(delivery.getAddressId()); shoppingCart.getShoppingContext().setCountryCode(delivery.getCountryCode()); shoppingCart.getShoppingContext().setStateCode(delivery.getStateCode()); changed = true; } } } } else { final Address delivery = (Address) parameters.get(CMD_SETADDRESES_P_DELIVERY_ADDRESS); if (delivery != null) { if (!Long.valueOf(delivery.getAddressId()).equals(shoppingCart.getOrderInfo().getDeliveryAddressId())) { shoppingCart.getOrderInfo().setDeliveryAddressId(delivery.getAddressId()); if (!shoppingCart.isSeparateBillingAddress() && !shoppingCart.isBillingAddressNotRequired()) { shoppingCart.getOrderInfo().setBillingAddressId(delivery.getAddressId()); shoppingCart.getShoppingContext().setCountryCode(delivery.getCountryCode()); shoppingCart.getShoppingContext().setStateCode(delivery.getStateCode()); } changed = true; } } else if (shoppingCart.getOrderInfo().getDeliveryAddressId() != null) { shoppingCart.getOrderInfo().setDeliveryAddressId(null); changed = true; } } } if (changed) { recalculate(shoppingCart); markDirty(shoppingCart); } } } SetAddressesCartCommandImpl(final ShoppingCartCommandRegistry registry); @Override String getCmdKey(); @Override void execute(final MutableShoppingCart shoppingCart, final Map<String, Object> parameters); }
SetAddressesCartCommandImpl extends AbstractCartCommandImpl implements ShoppingCartCommand { @Override public void execute(final MutableShoppingCart shoppingCart, final Map<String, Object> parameters) { if (parameters.containsKey(getCmdKey())) { boolean changed = false; if (parameters.containsKey(CMD_SETADDRESES_P_BILLING_ADDRESS)) { final boolean notRequired = shoppingCart.getOrderInfo().isBillingAddressNotRequired(); if (notRequired) { if (shoppingCart.getOrderInfo().getBillingAddressId() != null) { shoppingCart.getOrderInfo().setBillingAddressId(null); shoppingCart.getShoppingContext().setCountryCode(null); shoppingCart.getShoppingContext().setStateCode(null); changed = true; } } else { final Address billing = (Address) parameters.get(CMD_SETADDRESES_P_BILLING_ADDRESS); if (billing != null) { if (!Long.valueOf(billing.getAddressId()).equals(shoppingCart.getOrderInfo().getBillingAddressId())) { shoppingCart.getOrderInfo().setBillingAddressId(billing.getAddressId()); shoppingCart.getShoppingContext().setCountryCode(billing.getCountryCode()); shoppingCart.getShoppingContext().setStateCode(billing.getStateCode()); changed = true; } } else if (shoppingCart.getOrderInfo().getBillingAddressId() != null) { shoppingCart.getOrderInfo().setBillingAddressId(null); shoppingCart.getShoppingContext().setCountryCode(null); shoppingCart.getShoppingContext().setStateCode(null); changed = true; } } } if (parameters.containsKey(CMD_SETADDRESES_P_DELIVERY_ADDRESS)) { final boolean notRequired = shoppingCart.getOrderInfo().isDeliveryAddressNotRequired(); if (notRequired) { if (shoppingCart.getOrderInfo().getDeliveryAddressId() != null) { shoppingCart.getOrderInfo().setDeliveryAddressId(null); changed = true; } if (!shoppingCart.isSeparateBillingAddress() && !shoppingCart.isBillingAddressNotRequired()) { final Address delivery = (Address) parameters.get(CMD_SETADDRESES_P_DELIVERY_ADDRESS); if (delivery != null) { if (!Long.valueOf(delivery.getAddressId()).equals(shoppingCart.getOrderInfo().getBillingAddressId())) { shoppingCart.getOrderInfo().setBillingAddressId(delivery.getAddressId()); shoppingCart.getShoppingContext().setCountryCode(delivery.getCountryCode()); shoppingCart.getShoppingContext().setStateCode(delivery.getStateCode()); changed = true; } } } } else { final Address delivery = (Address) parameters.get(CMD_SETADDRESES_P_DELIVERY_ADDRESS); if (delivery != null) { if (!Long.valueOf(delivery.getAddressId()).equals(shoppingCart.getOrderInfo().getDeliveryAddressId())) { shoppingCart.getOrderInfo().setDeliveryAddressId(delivery.getAddressId()); if (!shoppingCart.isSeparateBillingAddress() && !shoppingCart.isBillingAddressNotRequired()) { shoppingCart.getOrderInfo().setBillingAddressId(delivery.getAddressId()); shoppingCart.getShoppingContext().setCountryCode(delivery.getCountryCode()); shoppingCart.getShoppingContext().setStateCode(delivery.getStateCode()); } changed = true; } } else if (shoppingCart.getOrderInfo().getDeliveryAddressId() != null) { shoppingCart.getOrderInfo().setDeliveryAddressId(null); changed = true; } } } if (changed) { recalculate(shoppingCart); markDirty(shoppingCart); } } } SetAddressesCartCommandImpl(final ShoppingCartCommandRegistry registry); @Override String getCmdKey(); @Override void execute(final MutableShoppingCart shoppingCart, final Map<String, Object> parameters);  }