RemoveSkuFromWishListEventCommandImpl extends AbstractSkuCartCommandImpl { @Override protected void execute(final MutableShoppingCart shoppingCart, final ProductSku productSku, final String skuCode, final String supplier, final String itemGroup, final BigDecimal qty, final Map<String, Object> parameters) { if (ShoppingCart.LOGGED_IN == shoppingCart.getLogonState()) { final Long pk = getItemIdValue(parameters); if (pk != null) { removeWishListItem(shoppingCart, pk); LOG.debug("Removed one item of sku code {} from wishlist", productSku.getCode()); } } } RemoveSkuFromWishListEventCommandImpl(final ShoppingCartCommandRegistry registry,
                                                 final PriceResolver priceResolver,
                                                 final PricingPolicyProvider pricingPolicyProvider,
                                                 final ProductService productService,
                                                 final ShopService shopService,
                                                 final CustomerService customerService,
                                                 final CustomerWishListService customerWishListService); @Override String getCmdKey();  }
@Test public void testExecute() { ShopService shopService = (ShopService) ctx().getBean(ServiceSpringKeys.SHOP_SERVICE); Shop shop = shopService.getById(10L); final Customer customer = createCustomer(); final CustomerWishListService customerWishListService = ctx().getBean("customerWishListService", CustomerWishListService.class); MutableShoppingCart shoppingCart = new ShoppingCartImpl(); shoppingCart.getShoppingContext().setShopCode(shop.getCode()); shoppingCart.getShoppingContext().setShopId(shop.getShopId()); shoppingCart.initialise(ctx().getBean("amountCalculationStrategy", AmountCalculationStrategy.class)); final ShoppingCartCommandFactory commands = ctx().getBean("shoppingCartCommandFactory", ShoppingCartCommandFactory.class); assertEquals(ShoppingCart.NOT_LOGGED, shoppingCart.getLogonState()); Map<String, String> params = new HashMap<>(); params.put(ShoppingCartCommand.CMD_LOGIN_P_EMAIL, customer.getEmail()); params.put(ShoppingCartCommand.CMD_LOGIN_P_PASS, "rawpassword"); params.put(LoginCommandImpl.CMD_LOGIN, "1"); commands.execute(shoppingCart, (Map) params); assertEquals(ShoppingCart.LOGGED_IN, shoppingCart.getLogonState()); commands.execute(shoppingCart, (Map) singletonMap(ShoppingCartCommand.CMD_SETSHOP, 10)); commands.execute(shoppingCart, (Map) singletonMap(ShoppingCartCommand.CMD_CHANGECURRENCY, "EUR")); List<CustomerWishList> wishList = customerWishListService.findWishListByCustomerId(customer.getCustomerId()); assertNotNull(wishList); assertTrue(wishList.isEmpty()); params.clear(); params.put(ShoppingCartCommand.CMD_ADDTOWISHLIST, "CC_TEST1"); params.put(ShoppingCartCommand.CMD_P_SUPPLIER, "WAREHOUSE_1"); params.put(ShoppingCartCommand.CMD_ADDTOWISHLIST_P_TAGS, "mine"); commands.execute(shoppingCart, (Map) params); wishList = customerWishListService.findWishListByCustomerId(customer.getCustomerId()); assertNotNull(wishList); assertEquals(1, wishList.size()); CustomerWishList item1 = wishList.get(0); assertEquals(CustomerWishList.PRIVATE, item1.getVisibility()); assertEquals(CustomerWishList.SIMPLE_WISH_ITEM, item1.getWlType()); assertEquals("CC_TEST1", item1.getSkuCode()); assertEquals("mine", item1.getTag()); assertEquals(1, item1.getQuantity().intValue()); assertEquals("19.99", item1.getRegularPriceWhenAdded().toString()); params.clear(); params.put(ShoppingCartCommand.CMD_REMOVEFROMWISHLIST, "CC_TEST1"); params.put(ShoppingCartCommand.CMD_REMOVEFROMWISHLIST_P_ID, String.valueOf(item1.getCustomerwishlistId())); commands.execute(shoppingCart, (Map) params); wishList = customerWishListService.findWishListByCustomerId(customer.getCustomerId()); assertNotNull(wishList); assertTrue(wishList.isEmpty()); }