WorldpayB2BAcceleratorCheckoutFacadeDecorator extends DefaultB2BAcceleratorCheckoutFacade { @Override public <T extends AbstractOrderData> T placeOrder(PlaceOrderData placeOrderData) throws InvalidCartException { if (!placeOrderData.getTermsCheck().equals(Boolean.TRUE)) { throw new EntityValidationException(getLocalizedString(CART_CHECKOUT_TERM_UNCHECKED)); } isAuthorisedNow(placeOrderData); if (isValidCheckoutCart(placeOrderData)) { if (placeOrderData.getReplenishmentOrder() != null && placeOrderData.getReplenishmentOrder().equals(Boolean.TRUE)) { return handleReplenishment(placeOrderData); } return (T) b2BAcceleratorCheckoutFacade.placeOrder(); } return null; }  @Override T placeOrder(PlaceOrderData placeOrderData); @Required void setL10NService(final L10NService l10NService); @Required void setB2BAcceleratorCheckoutFacade(DefaultB2BAcceleratorCheckoutFacade b2BAcceleratorCheckoutFacade);  }
@Test public void placeOrderShouldPlaceOrderOnBuyNowWhenAuthorized() throws InvalidCartException { PlaceOrderData placeOrderData = createPlaceOrderData(false); PaymentTransactionEntryModel paymentTransactionEntryModelMock = Mockito.mock(PaymentTransactionEntryModel.class); PaymentTransactionModel paymentTransactionModelMock = Mockito.mock(PaymentTransactionModel.class); Mockito.when(paymentTransactionEntryModelMock.getType()).thenReturn(PaymentTransactionType.AUTHORIZATION); Mockito.when(paymentTransactionEntryModelMock.getTransactionStatus()).thenReturn(TransactionStatus.ACCEPTED.name()); Mockito.when(paymentTransactionModelMock.getEntries()).thenReturn(Collections.singletonList(paymentTransactionEntryModelMock)); mockPayByCard(); Mockito.when(cartModelMock.getPaymentTransactions()).thenReturn(Collections.singletonList(paymentTransactionModelMock)); testObj.placeOrder(placeOrderData); Mockito.verify(b2BAcceleratorCheckoutFacade, Mockito.times(1)).placeOrder(); }
@Test(expected = EntityValidationException.class) public void placeOrderShouldNotPlaceOrderOnBuyNowWhenNotAuthorized() throws InvalidCartException { PlaceOrderData placeOrderData = createPlaceOrderData(false); Mockito.when(cartModelMock.getPaymentType()).thenReturn(CheckoutPaymentType.CARD); testObj.placeOrder(placeOrderData); }
@Test public void placeOrderShouldNotPlaceOrderOnReplenishment() throws InvalidCartException { PlaceOrderData placeOrderData = createPlaceOrderData(true); mockPayByCard(); Mockito.when(triggerModelMock.getRelative()).thenReturn(Boolean.TRUE); testObj.placeOrder(placeOrderData); Mockito.verify(b2BAcceleratorCheckoutFacade, Mockito.times(0)).placeOrder(); }
@Test public void placeOrderShouldScheduleReplenishment() throws InvalidCartException { PlaceOrderData placeOrderData = createPlaceOrderData(true); mockPayByCard(); Mockito.when(triggerModelMock.getRelative()).thenReturn(Boolean.TRUE); testObj.placeOrder(placeOrderData); Mockito.verify(b2BAcceleratorCheckoutFacade, Mockito.times(1)).scheduleOrder(Matchers.any()); }