WorldpayCloneCartAction extends AbstractProceduralAction<ReplenishmentProcessModel> { @Override public void executeAction(final ReplenishmentProcessModel process) { final CartToOrderCronJobModel cartToOrderCronJob = process.getCartToOrderCronJob(); final CartModel cronJobCart = cartToOrderCronJob.getCart(); userService.setCurrentUser(cronJobCart.getUser()); final CartModel clonedCart = cartService.clone(typeService.getComposedTypeForClass(CartModel.class), typeService.getComposedTypeForClass(CartEntryModel.class), cronJobCart, keyGenerator.generate().toString()); clonedCart.setPaymentAddress(cartToOrderCronJob.getPaymentAddress()); clonedCart.setDeliveryAddress(cartToOrderCronJob.getDeliveryAddress()); clonedCart.setPaymentInfo(cartToOrderCronJob.getPaymentInfo()); clonedCart.setStatus(OrderStatus.CREATED); clonedCart.setAllPromotionResults(Collections.emptySet()); clonedCart.setPaymentTransactions(Collections.emptyList()); clonedCart.setPermissionResults(Collections.emptyList()); clonedCart.setGuid(guidKeyGenerator.generate().toString()); this.modelService.save(clonedCart); processParameterHelper.setProcessParameter(process, "cart", clonedCart); }  @Override void executeAction(final ReplenishmentProcessModel process); @Required void setKeyGenerator(KeyGenerator keyGenerator); @Required void setGuidKeyGenerator(KeyGenerator guidKeyGenerator); @Required void setCartService(final CartService cartService); @Required void setTypeService(final TypeService typeService); @Required void setUserService(final UserService userService);  }
@Test public void executeActionShouldAddCloneToProcess() { testObj.executeAction(processModel); Assert.assertEquals(processModel, businessProcessParameterModel.getProcess()); Assert.assertEquals("cart", businessProcessParameterModel.getName()); Assert.assertEquals(clonedCart, businessProcessParameterModel.getValue()); }
@Test public void executeActionShouldCreateCloneOfCart() { testObj.executeAction(processModel); Mockito.verify(cartService).clone(composedTypeForCart, composedTypeForCartEntry, cronJobCart, GENERATED_CODE); Assert.assertEquals(paymentAddress, clonedCart.getPaymentAddress()); Assert.assertEquals(deliveryAddress, clonedCart.getDeliveryAddress()); Assert.assertEquals(paymentInfoModel, clonedCart.getPaymentInfo()); Assert.assertEquals(GENERATED_GUID, clonedCart.getGuid()); }