WorldpayCancelOrderAction extends AbstractComponentWidgetAdapterAware implements CockpitAction<OrderModel, OrderModel> { @Override public boolean canPerform(final ActionContext<OrderModel> actionContext) { final OrderModel order = actionContext.getData(); if (order != null){ final PaymentTransactionModel paymentTransactionModel = order.getPaymentTransactions().get(0); if (paymentTransactionModel.getInfo() instanceof WorldpayAPMPaymentInfoModel) { return false; } boolean authPending = worldpayPaymentTransactionService.isPaymentTransactionPending(paymentTransactionModel, AUTHORIZATION); return nonNull(order.getEntries()) && !authPending && this.orderCancelService.isCancelPossible(order, userService.getCurrentUser(), true, true).isAllowed(); } return false; }  @Override boolean canPerform(final ActionContext<OrderModel> actionContext); @Override String getConfirmationMessage(ActionContext<OrderModel> actionContext); @Override boolean needsConfirmation(ActionContext<OrderModel> actionContext); @Override ActionResult<OrderModel> perform(ActionContext<OrderModel> actionContext);  }
@Test public void buttonShouldBeClickable() { final boolean result = testObj.canPerform(actionContextMock); assertTrue(result); }
@Test public void buttonShouldNotBeClickableIfOrderEntriesIsNull() { when(orderModelMock.getEntries()).thenReturn(null); final boolean result = testObj.canPerform(actionContextMock); assertFalse(result); }
@Test public void buttonShouldNotBeClickableIfOrderWasPaidWithAnAPM() { when(paymentTransactionModelMock.getInfo()).thenReturn(worldpayAPMPaymentInfoModelMock); final boolean result = testObj.canPerform(actionContextMock); assertFalse(result); }
@Test public void buttonShouldBeClickableIfOrderWasPaidWithACreditCard() { when(paymentTransactionModelMock.getInfo()).thenReturn(creditCardPaymentInfoModelMock); final boolean result = testObj.canPerform(actionContextMock); assertTrue(result); }
@Test public void buttonShouldNotBeClickableIfCancelIsNotPossible() { when(cancelDecisionMock.isAllowed()).thenReturn(false); final boolean result = testObj.canPerform(actionContextMock); assertFalse(result); }
@Test public void buttonShouldNotBeClickableIfAuthIsPending() throws Exception { when(worldpayPaymentTransactionServiceMock.isPaymentTransactionPending(paymentTransactionModelMock, AUTHORIZATION)).thenReturn(true); final boolean result = testObj.canPerform(actionContextMock); assertFalse(result); }
@Test public void buttonShouldBeClickableIfAuthIsNotPending() throws Exception { when(worldpayPaymentTransactionServiceMock.isPaymentTransactionPending(paymentTransactionModelMock, AUTHORIZATION)).thenReturn(false); final boolean result = testObj.canPerform(actionContextMock); assertTrue(result); }
@Test public void buttonShouldNotBeClickableIfOrderIsNull() throws Exception { when(actionContextMock.getData()).thenReturn(null); final boolean result = testObj.canPerform(actionContextMock); assertFalse(result); }