public void testCloneCartAction() throws Exception { Assert.assertNotNull("cart not null", cartService.getSessionCart()); Assert.assertNotNull("user not null", cartService.getSessionCart().getUser()); Assert.assertEquals("DC S No", cartService.getSessionCart().getUser().getUid()); final ReplenishmentProcessModel replenishmentProcessModel = createReplenishmentProcess(); cloneCartAction.executeAction(replenishmentProcessModel); this.modelService.save(replenishmentProcessModel); Assert.assertNotNull( processParameterHelper.getProcessParameterByName(replenishmentProcessModel, "cart")); }
public void testRecalculateCartAction() throws Exception { Assert.assertNotNull("cart not null", cartService.getSessionCart()); Assert.assertNotNull("user not null", cartService.getSessionCart().getUser()); Assert.assertEquals("DC S No", cartService.getSessionCart().getUser().getUid()); final ReplenishmentProcessModel replenishmentProcessModel = createReplenishmentProcess(); Assert.assertFalse(processParameterHelper.containsParameter(replenishmentProcessModel, "cart")); processParameterHelper.setProcessParameter( replenishmentProcessModel, "cart", cartService.getSessionCart()); modelService.save(replenishmentProcessModel); Assert.assertTrue(processParameterHelper.containsParameter(replenishmentProcessModel, "cart")); calculateCartAction.executeAction(replenishmentProcessModel); }
/** * HW2110-0019(base product): 381.64 Euro, and HW2200-0561(partner product): 86.80 Euro. The * ProductOneToOnePerfectPartnerPromotion will be fired if both of them are in the cart and the * price is 700 Euro. * * <ul> * <li>adds the HW2110-0019 in cart, and tests the total price, * <li>updates with the ProductOneToOnePerfectPartnerPromotion, and checks the total price, * <li>now adds the HW2200-0561, and checks the total price, * <li>updates with the ProductOneToOnePerfectPartnerPromotion that should be fired now, and * checks the total price. * </ul> */ @Test public void testProductOneToOnePerfectPartnerPromotion() throws CalculationException { cart = cartService.getSessionCart(); cartService.addNewEntry(cart, baseProduct, 1, baseProduct.getUnit()); modelService.save(cart); calculationService.calculate(cart); assertEquals( "before updatePromotions(ProductOneToOnePerfectPartnerPromotion)", 381.64d, cart.getTotalPrice().doubleValue(), 0.01); promotionGroup = promotionsService.getPromotionGroup("prGroup5"); final Collection<PromotionGroupModel> promotionGroups = new ArrayList<PromotionGroupModel>(); promotionGroups.add(promotionGroup); promotionsService.updatePromotions( promotionGroups, cart, false, AutoApplyMode.APPLY_ALL, AutoApplyMode.APPLY_ALL, new Date()); modelService.refresh(cart); assertEquals("without partner product", 381.64d, cart.getTotalPrice().doubleValue(), 0.01); cartService.addNewEntry(cart, partnerProduct, 1, partnerProduct.getUnit()); modelService.saveAll(); calculationService.calculate(cart); assertEquals( "with partner product, but without promotion", 468.44d, cart.getTotalPrice().doubleValue(), 0.01); promotionsService.updatePromotions( promotionGroups, cart, false, AutoApplyMode.APPLY_ALL, AutoApplyMode.APPLY_ALL, new Date()); modelService.refresh(cart); assertEquals("with partner product now", 400.00d, cart.getTotalPrice().doubleValue(), 0.01); }
public void testAuthorizePaymentAction() throws Exception { Assert.assertNotNull("cart not null", cartService.getSessionCart()); Assert.assertNotNull("user not null", cartService.getSessionCart().getUser()); Assert.assertEquals("DC S No", cartService.getSessionCart().getUser().getUid()); Assert.assertNotNull(cartService.getSessionCart().getPaymentInfo()); Assert.assertThat( cartService.getSessionCart().getPaymentInfo(), instanceOf(CreditCardPaymentInfoModel.class)); final ReplenishmentProcessModel replenishmentProcessModel = createReplenishmentProcess(); Assert.assertFalse(processParameterHelper.containsParameter(replenishmentProcessModel, "cart")); processParameterHelper.setProcessParameter( replenishmentProcessModel, "cart", cartService.getSessionCart()); modelService.save(replenishmentProcessModel); Assert.assertTrue(processParameterHelper.containsParameter(replenishmentProcessModel, "cart")); Assert.assertEquals( AbstractSimpleDecisionAction.Transition.OK, authorizePaymentAction.executeAction(replenishmentProcessModel)); }
private void prepareData() { catVersion = catalogVersionService.getCatalogVersion("hwcatalog", "Online"); catalogVersionService.addSessionCatalogVersion(catVersion); user = userService.getUserForUID("ariel"); userService.setCurrentUser(user); cart = cartService.getSessionCart(); commonI18NService.setCurrentCurrency(commonI18NService.getCurrency("EUR")); product1 = productService.getProductForCode(catVersion, "HW2110-0012"); }
public void testConfirmationAction() throws Exception { Assert.assertNotNull(mockEventService); confirmationAction.setEventService(mockEventService); final CartModel sessionCart = cartService.getSessionCart(); modelService.refresh(sessionCart); sessionCart.setCalculated(Boolean.TRUE); modelService.save(sessionCart); Assert.assertEquals(Boolean.TRUE, sessionCart.getCalculated()); Assert.assertNotNull("cart not null", sessionCart); Assert.assertNotNull("user not null", sessionCart.getUser()); Assert.assertEquals("DC S No", sessionCart.getUser().getUid()); Assert.assertNotNull(sessionCart.getPaymentInfo()); final ReplenishmentProcessModel replenishmentProcessModel = createReplenishmentProcess(); Assert.assertFalse( processParameterHelper.containsParameter(replenishmentProcessModel, "order")); processParameterHelper.setProcessParameter( replenishmentProcessModel, "order", commerceCheckoutService.placeOrder(cartService.getSessionCart())); modelService.save(replenishmentProcessModel); Assert.assertTrue(processParameterHelper.containsParameter(replenishmentProcessModel, "order")); confirmationAction.executeAction(replenishmentProcessModel); }
@Test public void testOnEvent() throws Exception { // get admin user final UserModel user = userService.getAdminUser(); // create session cart, anonymous user is set on cart cartService.getSessionCart(); // set admin user as current userService.setCurrentUser(user); // AfterSessionUserChangeEvent processed in background // .... // get current cart final CartModel cart = cartService.getSessionCart(); // refresh cart to ensure that cart user is persisted modelService.refresh(cart); assertNotNull("Cart is null.", cart); assertNotNull("Cart user is null.", cart.getUser()); assertEquals("Cart user differs.", user, cart.getUser()); }
@Before public void setUp() { MockitoAnnotations.initMocks(this); strategy = new PickUpInStoreCheckoutFlowStrategy(); strategy.setDefaultStrategy(defaultStrategy); strategy.setMultiStepCheckoutFlowStrategy(multiStepCheckoutFlowStrategy); strategy.setPickupStrategy(pickupStrategy); given(pickupStrategy.getPickupInStoreMode()).willReturn(PickupInStoreMode.BUY_AND_COLLECT); given(multiStepCheckoutFlowStrategy.getCheckoutFlow()).willReturn(CheckoutFlowEnum.MULTISTEP); given(defaultStrategy.getCheckoutFlow()).willReturn(CheckoutFlowEnum.MULTISTEP); given(cartService.getSessionCart()).willReturn(cartModel); given(cartModel.getEntries()).willReturn(Collections.singletonList(cartEntry)); }
public void testPlaceOrderAction() throws Exception { final CartModel sessionCart = cartService.getSessionCart(); modelService.refresh(sessionCart); sessionCart.setCalculated(Boolean.TRUE); modelService.save(sessionCart); Assert.assertEquals(Boolean.TRUE, sessionCart.getCalculated()); Assert.assertNotNull("cart not null", sessionCart); Assert.assertNotNull("user not null", sessionCart.getUser()); Assert.assertEquals("DC S No", sessionCart.getUser().getUid()); Assert.assertNotNull(sessionCart.getPaymentInfo()); Assert.assertThat(sessionCart.getPaymentInfo(), instanceOf(CreditCardPaymentInfoModel.class)); final ReplenishmentProcessModel replenishmentProcessModel = createReplenishmentProcess(); Assert.assertFalse(processParameterHelper.containsParameter(replenishmentProcessModel, "cart")); processParameterHelper.setProcessParameter(replenishmentProcessModel, "cart", sessionCart); modelService.save(replenishmentProcessModel); Assert.assertTrue(processParameterHelper.containsParameter(replenishmentProcessModel, "cart")); placeOrderAction.execute(replenishmentProcessModel); }
@Before public void beforeTest() throws Exception { MockitoAnnotations.initMocks(this); // inject a mock payment provider cardPaymentService.setCommandFactoryRegistry(mockupCommandFactoryRegistry); paymentService.setCardPaymentService(cardPaymentService); commerceCheckoutService.setPaymentService(paymentService); createCoreData(); createDefaultCatalog(); importCsv("/energizercore/test/testOrganizations.csv", "utf-8"); importCsv("/energizercore/test/testB2BCommerceCart.csv", "utf-8"); final CartModel modelByExample = new CartModel(); modelByExample.setCode("dc_shhCart_b2bas"); final CartModel cart = flexibleSearchService.getModelByExample(modelByExample); Assert.assertNotNull(cart); cartService.setSessionCart(cart); userService.setCurrentUser(cart.getUser()); if (flexibleSearchService .search( "SELECT {" + ServicelayerJobModel.PK + "} FROM {" + ServicelayerJobModel._TYPECODE + "} WHERE " + "{" + ServicelayerJobModel.SPRINGID + "}=?springid", Collections.singletonMap("springid", "b2bAcceleratorCartToOrderJob")) .getResult() .isEmpty()) { final ServicelayerJobModel servicelayerJobModel = modelService.create(ServicelayerJobModel.class); servicelayerJobModel.setCode("b2bAcceleratorCartToOrderJob"); servicelayerJobModel.setSpringId("b2bAcceleratorCartToOrderJob"); modelService.save(servicelayerJobModel); } final Date startDate = new Date(); final Integer day = Integer.valueOf(5); final Integer week = Integer.valueOf(2); final List<DayOfWeek> days = new ArrayList<DayOfWeek>(); days.add(DayOfWeek.TUESDAY); days.add(DayOfWeek.FRIDAY); triggerModel = modelService.create(TriggerModel.class); triggerModel.setRelative(Boolean.TRUE); triggerModel.setActivationTime(startDate); triggerModel.setDay(day); triggerModel.setWeekInterval(week); triggerModel.setDaysOfWeek(days); cartToOrderCronJob = modelService.create(CartToOrderCronJobModel.class); cartToOrderCronJob.setCart(cartService.getSessionCart()); cartToOrderCronJob.setDeliveryAddress(userService.getCurrentUser().getDefaultShipmentAddress()); cartToOrderCronJob.setPaymentAddress(userService.getCurrentUser().getDefaultPaymentAddress()); cartToOrderCronJob.setPaymentInfo(cartService.getSessionCart().getPaymentInfo()); setCronJobToTrigger(cartToOrderCronJob, Collections.singletonList(triggerModel)); cartToOrderCronJob.setJob(cronJobService.getJob("b2bAcceleratorCartToOrderJob")); modelService.save(cartToOrderCronJob); final BaseSiteModel site = baseSiteService.getBaseSiteForUID("b2bstoretemplate"); Assert.assertNotNull("no site found for id 'site'", site); baseSiteService.setCurrentBaseSite(site, false); }
protected OrderModel placeTestOrder(final boolean valid) throws InvalidCartException, CalculationException { final CartModel cart = cartService.getSessionCart(); final UserModel user = userService.getCurrentUser(); cartService.addNewEntry(cart, productService.getProductForCode("testProduct1"), 1, null); cartService.addNewEntry(cart, productService.getProductForCode("testProduct2"), 2, null); cartService.addNewEntry(cart, productService.getProductForCode("testProduct3"), 3, null); final AddressModel deliveryAddress = new AddressModel(); deliveryAddress.setOwner(user); deliveryAddress.setFirstname("Der"); deliveryAddress.setLastname("Buck"); deliveryAddress.setTown("Muenchen"); deliveryAddress.setCountry(commonI18NService.getCountry("DE")); modelService.save(deliveryAddress); final DebitPaymentInfoModel paymentInfo = new DebitPaymentInfoModel(); paymentInfo.setOwner(cart); paymentInfo.setBank("MeineBank"); paymentInfo.setUser(user); paymentInfo.setAccountNumber("34434"); paymentInfo.setBankIDNumber("1111112"); paymentInfo.setBaOwner("Ich"); paymentInfo.setCode("testPaymentInfo1"); modelService.save(paymentInfo); cart.setDeliveryMode(deliveryService.getDeliveryModeForCode("free")); cart.setDeliveryAddress(deliveryAddress); cart.setPaymentInfo(paymentInfo); final CardInfo card = new CardInfo(); card.setCardType(CreditCardType.VISA); card.setCardNumber("4111111111111111"); card.setExpirationMonth(Integer.valueOf(12)); if (valid) { card.setExpirationYear(Integer.valueOf(Calendar.getInstance().get(Calendar.YEAR) + 2)); } else { card.setExpirationYear(Integer.valueOf(Calendar.getInstance().get(Calendar.YEAR) - 2)); } final PaymentTransactionModel paymentTransaction = paymentService .authorize( "code4" + codeNo++, BigDecimal.ONE, Currency.getInstance("EUR"), deliveryAddress, deliveryAddress, card) .getPaymentTransaction(); cart.setPaymentTransactions(Collections.singletonList(paymentTransaction)); modelService.save(cart); calculationService.calculate(cart); final CommerceCheckoutParameter parameter = new CommerceCheckoutParameter(); parameter.setEnableHooks(true); parameter.setCart(cart); parameter.setSalesApplication(SalesApplication.WEB); return commerceCheckoutService.placeOrder(parameter).getOrder(); }