WorldpayCseCheckoutStepController extends AbstractWorldpayDirectCheckoutStepController { @RequestMapping(value = "/add-payment-address", method = POST) @RequireHardLogIn public String addPaymentAddress(final Model model, @Valid final PaymentDetailsForm paymentDetailsForm, final BindingResult bindingResult, final RedirectAttributes redirectAttrs) throws CMSItemNotFoundException { csePaymentDetailsFormValidator.validate(paymentDetailsForm, bindingResult); if (addGlobalErrors(model, bindingResult)) { model.addAttribute(PAYMENT_DETAILS_FORM, paymentDetailsForm); return handleFormErrors(model, paymentDetailsForm); } final String paymentMethod = paymentDetailsForm.getPaymentMethod(); handleAndSaveAddresses(paymentDetailsForm); if (paymentMethodIsOnline(paymentMethod)) { return REDIRECT_TO_CSE_PAGE; } redirectAttrs.addFlashAttribute(SHOPPER_BANK_CODE, paymentDetailsForm.getShopperBankCode()); redirectAttrs.addFlashAttribute(PAYMENT_METHOD_PARAM, paymentDetailsForm.getPaymentMethod()); return getRedirectToPaymentMethod(); }  @RequestMapping(value = {"/cse-data", "/tokenize"}, method = GET) @RequireHardLogIn String getCseDataPage(final Model model); @RequestMapping(value = "/add-payment-address", method = POST) @RequireHardLogIn String addPaymentAddress(final Model model, @Valid final PaymentDetailsForm paymentDetailsForm, final BindingResult bindingResult, final RedirectAttributes redirectAttrs); @RequestMapping(value = "/tokenize", method = POST) @RequireHardLogIn String addCseData(final HttpServletRequest request, final Model model, @Valid final B2BCSEPaymentForm b2bCSEPaymentForm, final BindingResult bindingResult); @GetMapping(value = "/DDCIframe") @RequireHardLogIn String getDDCIframeContent(final Model model); @GetMapping(value = "/challengeIframe") @RequireHardLogIn String getChallengeIframeContent(final Model model);  }
@Test public void shouldRedirectToCseDetailsIfNoErrorsInAddressFormAndPaymentMethodCreditCard() throws CMSItemNotFoundException { when(bindingResultMock.hasGlobalErrors()).thenReturn(false); when(paymentDetailsFormMock.getPaymentMethod()).thenReturn(ONLINE.getMethodCode()); final String result = testObj.addPaymentAddress(modelMock, paymentDetailsFormMock, bindingResultMock, redirectAttrsMock); assertEquals(REDIRECT_TO_CSE_PAGE, result); }
@Test public void shouldRedirectBackToPaymentDetailsIfGlobalErrorsInAddressForm() throws CMSItemNotFoundException { doReturn(true).when(testObj).addGlobalErrors(modelMock, bindingResultMock); final String result = testObj.addPaymentAddress(modelMock, paymentDetailsFormMock, bindingResultMock, redirectAttrsMock); assertEquals(BILLING_ERROR_VIEW, result); }
@Test public void shouldRedirectToPaymentMethodIfNotCreditCardAndNoErrors() throws CMSItemNotFoundException { when(bindingResultMock.hasErrors()).thenReturn(false); when(paymentDetailsFormMock.getPaymentMethod()).thenReturn(PAYPAL.getMethodCode()); doReturn(REDIRECT_TO_PAYMENT_METHOD).when(testObj).getRedirectToPaymentMethod(); final String result = testObj.addPaymentAddress(modelMock, paymentDetailsFormMock, bindingResultMock, redirectAttrsMock); verify(redirectAttrsMock).addFlashAttribute(SHOPPER_BANK_CODE, paymentDetailsFormMock.getShopperBankCode()); verify(redirectAttrsMock).addFlashAttribute(PAYMENT_METHOD_PARAM, PAYPAL.getMethodCode()); assertEquals(REDIRECT_TO_PAYMENT_METHOD, result); }
@Test public void shouldHandleFormErrorsWhenGlobalErrorsOccur() throws CMSItemNotFoundException { doReturn(true).when(testObj).addGlobalErrors(modelMock, bindingResultMock); testObj.addPaymentAddress(modelMock, paymentDetailsFormMock, bindingResultMock, redirectAttrsMock); verify(testObj).handleFormErrors(modelMock, paymentDetailsFormMock); }
@Test public void shouldSetBillingDetailsIfValidAddress() throws CMSItemNotFoundException { testObj.addPaymentAddress(modelMock, paymentDetailsFormMock, bindingResultMock, redirectAttrsMock); verify(testObj).handleAndSaveAddresses(paymentDetailsFormMock); }
@Test public void shouldValidatePaymentFormUsingCorrectValidator() throws CMSItemNotFoundException { testObj.addPaymentAddress(modelMock, paymentDetailsFormMock, bindingResultMock, redirectAttrsMock); verify(csePaymentDetailsFormValidatorMock).validate(paymentDetailsFormMock, bindingResultMock); }
@Test public void shouldHandleFormErrorsAndRedirectToErrorView() throws CMSItemNotFoundException { doReturn(true).when(testObj).addGlobalErrors(modelMock, bindingResultMock); final String result = testObj.addPaymentAddress(modelMock, paymentDetailsFormMock, bindingResultMock, redirectAttrsMock); verify(testObj).handleFormErrors(modelMock, paymentDetailsFormMock); assertEquals(BILLING_ERROR_VIEW, result); }