DefaultWorldpayXMLValidator implements WorldpayXMLValidator { @Override public void validate(final PaymentService paymentService) throws WorldpayValidationException { try { final JAXBSource source = new JAXBSource(WorldpayConstants.JAXB_CONTEXT, paymentService); final Validator validator = SCHEMA.newValidator(); validator.setErrorHandler(new WorldpayErrorHandler()); validator.validate(source); } catch (final JAXBException e) { throw new WorldpayValidationException("XML context or source building failure while validating xml model", e); } catch (final SAXException e) { throw new WorldpayValidationException("Validation error against paymentService xsd", e); } catch (final IOException e) { throw new WorldpayValidationException("Unable to parse or validate against paymentService xsd", e); } }  @Override void validate(final PaymentService paymentService);  }
@Test public void testValidate() throws WorldpayValidationException, WorldpayModelTransformationException { final List<PaymentType> includedPTs = singletonList(ONLINE); final Shopper shopper = new Shopper(EMAIL_ADDRESS, AUTH_SHOPPER_ID, null, null); final AuthoriseRequestParameters authoriseRequestParameters = AuthoriseRequestParameters.AuthoriseRequestParametersBuilder.getInstance() .withMerchantInfo(merchantInfo) .withOrderInfo(basicOrderInfo) .withOrderContent(ORDER_CONTENT) .withIncludedPTs(includedPTs) .withShopper(shopper) .withShippingAddress(shippingAddress) .withBillingAddress(billingAddress) .withStatementNarrative(STATEMENT_NARRATIVE_TEXT) .build(); final AuthoriseServiceRequest request = RedirectAuthoriseServiceRequest.createRedirectAuthoriseRequest(authoriseRequestParameters); final PaymentService paymentService = testObj.transform(request); VALIDATOR.validate(paymentService); }
@Test public void testValidateXMLWithCreateTokenWithShopperScope() throws WorldpayValidationException, WorldpayModelTransformationException { final List<PaymentType> includedPTs = singletonList(ONLINE); final Shopper shopper = new Shopper(EMAIL_ADDRESS, AUTH_SHOPPER_ID, null, null); final TokenRequest tokenRequest = new TokenRequest(TOKEN_REFERENCE, TOKEN_REASON, false); final AuthoriseRequestParameters authoriseRequestParameters = getAuthoriseRequestParameters(includedPTs, shopper, tokenRequest); final AuthoriseServiceRequest request = RedirectAuthoriseServiceRequest.createRedirectAuthoriseRequest(authoriseRequestParameters); final PaymentService paymentService = testObj.transform(request); VALIDATOR.validate(paymentService); }
@Test public void testValidateXMLWithCreateTokenWithMerchantScope() throws WorldpayValidationException, WorldpayModelTransformationException { final List<PaymentType> includedPTs = singletonList(ONLINE); final Shopper shopper = new Shopper(EMAIL_ADDRESS, AUTH_SHOPPER_ID, null, null); final TokenRequest tokenRequest = new TokenRequest(TOKEN_REFERENCE, TOKEN_REASON, true); final AuthoriseRequestParameters authoriseRequestParameters = getAuthoriseRequestParameters(includedPTs, shopper, tokenRequest); final AuthoriseServiceRequest request = RedirectAuthoriseServiceRequest.createRedirectAuthoriseRequest(authoriseRequestParameters); final PaymentService paymentService = testObj.transform(request); VALIDATOR.validate(paymentService); }