@Test public void testExecute() { MutableShoppingCart shoppingCart = new ShoppingCartImpl(); shoppingCart.initialise(ctx().getBean("amountCalculationStrategy", AmountCalculationStrategy.class)); final ShoppingCartCommandFactory commands = ctx().getBean("shoppingCartCommandFactory", ShoppingCartCommandFactory.class); assertNull(shoppingCart.getOrderInfo().getPaymentGatewayLabel()); Map params = new HashMap(); params.put(ShoppingCartCommand.CMD_SETORDERDETAILS, "detail1:001|detail2:002|detail3|:004"); commands.execute(shoppingCart, params); assertEquals(2, shoppingCart.getOrderInfo().getDetails().size()); assertEquals("001", shoppingCart.getOrderInfo().getDetailByKey("detail1")); assertEquals("002", shoppingCart.getOrderInfo().getDetailByKey("detail2")); params.put(ShoppingCartCommand.CMD_SETORDERDETAILS, "detail3:003"); commands.execute(shoppingCart, params); assertEquals(3, shoppingCart.getOrderInfo().getDetails().size()); assertEquals("001", shoppingCart.getOrderInfo().getDetailByKey("detail1")); assertEquals("002", shoppingCart.getOrderInfo().getDetailByKey("detail2")); assertEquals("003", shoppingCart.getOrderInfo().getDetailByKey("detail3")); params.put(ShoppingCartCommand.CMD_SETORDERDETAILS, "detail3:"); commands.execute(shoppingCart, params); assertEquals(2, shoppingCart.getOrderInfo().getDetails().size()); assertEquals("001", shoppingCart.getOrderInfo().getDetailByKey("detail1")); assertEquals("002", shoppingCart.getOrderInfo().getDetailByKey("detail2")); params.put(ShoppingCartCommand.CMD_SETORDERDETAILS, null); commands.execute(shoppingCart, params); assertTrue(shoppingCart.getOrderInfo().getDetails().isEmpty()); }
@Override public void execute(final MutableShoppingCart shoppingCart, final Map<String, Object> parameters) { if (parameters.containsKey(getCmdKey())) { final String values = (String) parameters.get(getCmdKey()); if (values == null) { shoppingCart.getOrderInfo().setDetails(null); markDirty(shoppingCart); } else { final String[] keyAndValues = StringUtils.split(values, '|'); if (keyAndValues != null) { boolean modified = false; for (final String keyAndValueRaw : keyAndValues) { final String[] keyAndValue = StringUtils.splitPreserveAllTokens(keyAndValueRaw, ":", 2); if (keyAndValue != null && keyAndValue.length == 2) { shoppingCart.getOrderInfo().putDetail(keyAndValue[0], keyAndValue[1]); modified = true; } } if (modified) { markDirty(shoppingCart); } } } } }
SetOrderInfoDetailsCommandImpl extends AbstractCartCommandImpl implements ShoppingCartCommand { @Override public void execute(final MutableShoppingCart shoppingCart, final Map<String, Object> parameters) { if (parameters.containsKey(getCmdKey())) { final String values = (String) parameters.get(getCmdKey()); if (values == null) { shoppingCart.getOrderInfo().setDetails(null); markDirty(shoppingCart); } else { final String[] keyAndValues = StringUtils.split(values, '|'); if (keyAndValues != null) { boolean modified = false; for (final String keyAndValueRaw : keyAndValues) { final String[] keyAndValue = StringUtils.splitPreserveAllTokens(keyAndValueRaw, ":", 2); if (keyAndValue != null && keyAndValue.length == 2) { shoppingCart.getOrderInfo().putDetail(keyAndValue[0], keyAndValue[1]); modified = true; } } if (modified) { markDirty(shoppingCart); } } } } } }
SetOrderInfoDetailsCommandImpl extends AbstractCartCommandImpl implements ShoppingCartCommand { @Override public void execute(final MutableShoppingCart shoppingCart, final Map<String, Object> parameters) { if (parameters.containsKey(getCmdKey())) { final String values = (String) parameters.get(getCmdKey()); if (values == null) { shoppingCart.getOrderInfo().setDetails(null); markDirty(shoppingCart); } else { final String[] keyAndValues = StringUtils.split(values, '|'); if (keyAndValues != null) { boolean modified = false; for (final String keyAndValueRaw : keyAndValues) { final String[] keyAndValue = StringUtils.splitPreserveAllTokens(keyAndValueRaw, ":", 2); if (keyAndValue != null && keyAndValue.length == 2) { shoppingCart.getOrderInfo().putDetail(keyAndValue[0], keyAndValue[1]); modified = true; } } if (modified) { markDirty(shoppingCart); } } } } } SetOrderInfoDetailsCommandImpl(final ShoppingCartCommandRegistry registry); }
SetOrderInfoDetailsCommandImpl extends AbstractCartCommandImpl implements ShoppingCartCommand { @Override public void execute(final MutableShoppingCart shoppingCart, final Map<String, Object> parameters) { if (parameters.containsKey(getCmdKey())) { final String values = (String) parameters.get(getCmdKey()); if (values == null) { shoppingCart.getOrderInfo().setDetails(null); markDirty(shoppingCart); } else { final String[] keyAndValues = StringUtils.split(values, '|'); if (keyAndValues != null) { boolean modified = false; for (final String keyAndValueRaw : keyAndValues) { final String[] keyAndValue = StringUtils.splitPreserveAllTokens(keyAndValueRaw, ":", 2); if (keyAndValue != null && keyAndValue.length == 2) { shoppingCart.getOrderInfo().putDetail(keyAndValue[0], keyAndValue[1]); modified = true; } } if (modified) { markDirty(shoppingCart); } } } } } SetOrderInfoDetailsCommandImpl(final ShoppingCartCommandRegistry registry); @Override String getCmdKey(); @Override void execute(final MutableShoppingCart shoppingCart, final Map<String, Object> parameters); }
SetOrderInfoDetailsCommandImpl extends AbstractCartCommandImpl implements ShoppingCartCommand { @Override public void execute(final MutableShoppingCart shoppingCart, final Map<String, Object> parameters) { if (parameters.containsKey(getCmdKey())) { final String values = (String) parameters.get(getCmdKey()); if (values == null) { shoppingCart.getOrderInfo().setDetails(null); markDirty(shoppingCart); } else { final String[] keyAndValues = StringUtils.split(values, '|'); if (keyAndValues != null) { boolean modified = false; for (final String keyAndValueRaw : keyAndValues) { final String[] keyAndValue = StringUtils.splitPreserveAllTokens(keyAndValueRaw, ":", 2); if (keyAndValue != null && keyAndValue.length == 2) { shoppingCart.getOrderInfo().putDetail(keyAndValue[0], keyAndValue[1]); modified = true; } } if (modified) { markDirty(shoppingCart); } } } } } SetOrderInfoDetailsCommandImpl(final ShoppingCartCommandRegistry registry); @Override String getCmdKey(); @Override void execute(final MutableShoppingCart shoppingCart, final Map<String, Object> parameters);  }