WorldpayCseCheckoutStepController extends AbstractWorldpayDirectCheckoutStepController { @RequestMapping(value = "/tokenize", method = POST) @RequireHardLogIn public String addCseData(final HttpServletRequest request, final Model model, @Valid final B2BCSEPaymentForm b2bCSEPaymentForm, final BindingResult bindingResult) throws CMSItemNotFoundException { cseFormValidator.validate(b2bCSEPaymentForm, bindingResult); getSessionService().setAttribute(SAVED_CARD_SELECTED_ATTRIBUTE, Boolean.FALSE); if (addGlobalErrors(model, bindingResult)) { return getErrorView(model); } final CSEAdditionalAuthInfo cseAdditionalAuthInfo = createCSEAdditionalAuthInfo(b2bCSEPaymentForm); final WorldpayAdditionalInfoData worldpayAdditionalInfoData = createWorldpayAdditionalInfo(request, b2bCSEPaymentForm.getCvc(), cseAdditionalAuthInfo); return handleResponse(model, cseAdditionalAuthInfo, worldpayAdditionalInfoData); }  @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 shouldRedirectToSummaryIfNoException() throws CMSItemNotFoundException { final String result = testObj.addCseData(httpServletRequestMock, modelMock, b2bCSEPaymentFormMock, bindingResultMock); assertEquals(REDIRECT_TO_SUMMARY_PAGE, result); }
@Test public void shouldRedirectToErrorIfExceptionThrownByFacade() throws CMSItemNotFoundException, WorldpayException { doThrow(new WorldpayException("errorMessage")).when(worldpayDirectOrderFacadeMock).tokenize(any(CSEAdditionalAuthInfo.class), eq(worldpayAdditionalInfoDataMock)); final String result = testObj.addCseData(httpServletRequestMock, modelMock, b2bCSEPaymentFormMock, bindingResultMock); assertEquals(CSE_PAYMENT_DETAILS_PAGE, result); }
@Test public void shouldDisplayCsePaymentPageIfErrorTokenizing() throws CMSItemNotFoundException, WorldpayException { doThrow(new WorldpayException("errorMessage")).when(worldpayDirectOrderFacadeMock).tokenize(any(CSEAdditionalAuthInfo.class), eq(worldpayAdditionalInfoDataMock)); testObj.addCseData(httpServletRequestMock, modelMock, b2bCSEPaymentFormMock, bindingResultMock); verify(modelMock).addAttribute(eq(B2B_CSE_PAYMENT_FORM), any(CSEPaymentForm.class)); }
@Test public void shouldValidateCseFormAndRedirectToCseForm() throws CMSItemNotFoundException { doReturn(true).when(testObj).addGlobalErrors(modelMock, bindingResultMock); final String result = testObj.addCseData(httpServletRequestMock, modelMock, b2bCSEPaymentFormMock, bindingResultMock); verify(cseFormValidatorMock).validate(b2bCSEPaymentFormMock, bindingResultMock); assertEquals(CSE_PAYMENT_DETAILS_PAGE, result); }