WorldpayCseCheckoutStepController extends AbstractWorldpayDirectCheckoutStepController { @RequestMapping(value = "/place-order", method = POST) @RequireHardLogIn public String addCseData(final HttpServletRequest request, final Model model, @Valid final CSEPaymentForm csePaymentForm, final BindingResult bindingResult, final HttpServletResponse response) throws CMSItemNotFoundException { cseFormValidator.validate(csePaymentForm, bindingResult); if (addGlobalErrors(model, bindingResult)) { return getErrorView(model); } final CSEAdditionalAuthInfo cseAdditionalAuthInfo = createCSEAdditionalAuthInfo(csePaymentForm); final WorldpayAdditionalInfoData worldpayAdditionalInfoData = createWorldpayAdditionalInfo(request, csePaymentForm.getCvc(), cseAdditionalAuthInfo); return authoriseAndHandleResponse(model, cseAdditionalAuthInfo, worldpayAdditionalInfoData, response); }  @RequestMapping(value = {"/cse-data", "/place-order"}, 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 = "/place-order", method = POST) @RequireHardLogIn String addCseData(final HttpServletRequest request, final Model model, @Valid final CSEPaymentForm csePaymentForm, final BindingResult bindingResult, final HttpServletResponse response); @GetMapping(value = "/DDCIframe") @RequireHardLogIn String getDDCIframeContent(final Model model); @GetMapping(value = "/challengeIframe") @RequireHardLogIn String getChallengeIframeContent(final Model model);  }
@Test public void addCseData_shouldRedirectToOrderConfirmation_WhenThereIsNotExceptionsOrErrors() throws CMSItemNotFoundException, WorldpayException, InvalidCartException { doReturn(CHECKOUT_ORDER_CONFIRMATION).when(testObj).handleDirectResponse(modelMock, directResponseDataMock, responseMock); when(worldpayDirectOrderFacadeMock.authoriseAndTokenize(eq(worldpayAdditionalInfoDataMock), any(CSEAdditionalAuthInfo.class))).thenReturn(directResponseDataMock); final String result = testObj.addCseData(httpServletRequestMock, modelMock, csePaymentFormMock, bindingResultMock, responseMock); assertEquals(CHECKOUT_ORDER_CONFIRMATION, result); }
@Test public void addCseData_ShouldRedirectToError_WhenAnExceptionIsThrownByFacade() throws CMSItemNotFoundException, InvalidCartException, WorldpayException { when(worldpayDirectOrderFacadeMock.authoriseAndTokenize(eq(worldpayAdditionalInfoDataMock), any(CSEAdditionalAuthInfo.class))).thenThrow(new WorldpayException("errorMessage")); final String result = testObj.addCseData(httpServletRequestMock, modelMock, csePaymentFormMock, bindingResultMock, responseMock); assertEquals(CSE_PAYMENT_DETAILS_PAGE, result); }
@Test public void addCseData_ShouldDisplayCsePaymentPage_WhenThereIsAnErrorAuthorisingPayment() throws CMSItemNotFoundException, InvalidCartException, WorldpayException { when(worldpayDirectOrderFacadeMock.authoriseAndTokenize(eq(worldpayAdditionalInfoDataMock), any(CSEAdditionalAuthInfo.class))).thenThrow(new WorldpayException("errorMessage")); testObj.addCseData(httpServletRequestMock, modelMock, csePaymentFormMock, bindingResultMock, responseMock); verify(modelMock).addAttribute(eq(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, csePaymentFormMock, bindingResultMock, responseMock); verify(cseFormValidatorMock).validate(csePaymentFormMock, bindingResultMock); assertEquals(CSE_PAYMENT_DETAILS_PAGE, result); }