WorldpayAuthorizePaymentAction extends AbstractSimpleDecisionAction<ReplenishmentProcessModel> { @Override public Transition executeAction(final ReplenishmentProcessModel process) { final BusinessProcessParameterModel clonedCartParameter = processParameterHelper.getProcessParameterByName(process, "cart"); final CartModel clonedCart = (CartModel) clonedCartParameter.getValue(); getModelService().refresh(clonedCart); final ImpersonationContext context = new ImpersonationContext(); context.setOrder(clonedCart); return impersonationService.executeInContext(context, (ImpersonationService.Executor<Transition, ImpersonationService.Nothing>) () -> { if (clonedCart.getPaymentInfo() instanceof CreditCardPaymentInfoModel) { return authoriseRecurringPaymentWithCreditCard(clonedCart); } return Transition.OK; }); }  @Override Transition executeAction(final ReplenishmentProcessModel process); @Required void setImpersonationService(final ImpersonationService impersonationService); @Required void setWorldpayDirectOrderFacade(final WorldpayDirectOrderFacade worldpayDirectOrderFacade); @Required void setWorldpayMerchantInfoService(final WorldpayMerchantInfoService worldpayMerchantInfoService);  }
@Test public void executeActionShouldReturnOKWhenAuthorized() { when(directResponseData.getTransactionStatus()).thenReturn(TransactionStatus.AUTHORISED); AbstractSimpleDecisionAction.Transition transition = testObj.executeAction(processModel); assertEquals(AbstractSimpleDecisionAction.Transition.OK, transition); verify(modelServiceMock).refresh(clonedCart); }
@Test public void executeActionShouldReturnNOKWhenNotAuthorized() { when(directResponseData.getTransactionStatus()).thenReturn(TransactionStatus.REFUSED); AbstractSimpleDecisionAction.Transition transition = testObj.executeAction(processModel); assertEquals(AbstractSimpleDecisionAction.Transition.NOK, transition); }