DefaultWorldpayHostedOrderFacade implements WorldpayHostedOrderFacade { @Override public boolean validateRedirectResponse(final Map<String, String> worldpayResponse) { final String merchantCode = sessionService.getAttribute(WORLDPAY_MERCHANT_CODE); try { final MerchantInfo merchantInfo = worldpayMerchantInfoService.getMerchantInfoByCode(merchantCode); return worldpayRedirectOrderService.validateRedirectResponse(merchantInfo, worldpayResponse); } catch (final WorldpayConfigurationException e) { LOG.error(MessageFormat.format("There was an error getting the configuration for the merchants: [{0}]", e.getMessage()), e); } return false; } DefaultWorldpayHostedOrderFacade(final SessionService sessionService, final WorldpayRedirectOrderService worldpayRedirectOrderService,
                                            final WorldpayMerchantInfoService worldpayMerchantInfoService, final CartService cartService,
                                            final WorldpayOrderInfoStrategy worldpayOrderInfoStrategy,
                                            final WorldpayMerchantConfigDataFacade worldpayMerchantConfigDataFacade,
                                            final OrderInquiryService orderInquiryService,
                                            final APMConfigurationLookupService apmConfigurationLookupService,
                                            final WorldpayOrderService worldpayOrderService); @Override PaymentData redirectAuthorise(final AdditionalAuthInfo additionalAuthInfo); @Override void completeRedirectAuthorise(final RedirectAuthoriseResult result); @Override boolean validateRedirectResponse(final Map<String, String> worldpayResponse); @Override RedirectAuthoriseResult inquiryPaymentStatus();  }
@Test public void shouldReturnTrueWhenRedirectResponseIsValid() throws WorldpayConfigurationException { when(worldpayMerchantInfoServiceMock.getMerchantInfoByCode(MERCHANT_CODE)).thenReturn(merchantInfoMock); when(worldpayRedirectOrderServiceMock.validateRedirectResponse(eq(merchantInfoMock), eq(WORLDPAY_RESPONSE))).thenReturn(true); assertTrue(testObj.validateRedirectResponse(WORLDPAY_RESPONSE)); }
@Test public void shouldReturnFalseWhenRedirectResponseIsNotValid() { when(worldpayRedirectOrderServiceMock.validateRedirectResponse(eq(merchantInfoMock), eq(WORLDPAY_RESPONSE))).thenReturn(false); assertFalse(testObj.validateRedirectResponse(WORLDPAY_RESPONSE)); }