@Test public void validateInstanceTranslatesSAXParseExceptionIntoValidationError() throws Exception { doThrow(new SAXParseException("foo", new LocatorImpl())) .when(validator).validate(any(Source.class)); JAXPValidator v = new JAXPValidator(Languages.W3C_XML_SCHEMA_NS_URI, fac); v.setSchemaSource(new StreamSource(BOOK_XSD)); ValidationResult r = v.validateInstance(new StreamSource(new File(TEST_RESOURCE_DIR + "BookXsdGenerated.xml"))); assertFalse(r.isValid()); assertTrue(r.getProblems().iterator().hasNext()); }
@Override public ValidationResult validateInstance(Source s) { Schema schema; try { schema = getSchema(); } catch (SAXException e) { throw new XMLUnitException("The schema is invalid", e); } ValidationHandler v = new ValidationHandler(); javax.xml.validation.Validator val = schema.newValidator(); val.setErrorHandler(v); try { val.validate(s); } catch (SAXParseException e) { v.error((SAXParseException) e); } catch (SAXException e) { throw new XMLUnitException(e); } catch (java.io.IOException e) { throw new XMLUnitException(e); } return v.getResult(); }
JAXPValidator extends Validator { @Override public ValidationResult validateInstance(Source s) { Schema schema; try { schema = getSchema(); } catch (SAXException e) { throw new XMLUnitException("The schema is invalid", e); } ValidationHandler v = new ValidationHandler(); javax.xml.validation.Validator val = schema.newValidator(); val.setErrorHandler(v); try { val.validate(s); } catch (SAXParseException e) { v.error((SAXParseException) e); } catch (SAXException e) { throw new XMLUnitException(e); } catch (java.io.IOException e) { throw new XMLUnitException(e); } return v.getResult(); } }
JAXPValidator extends Validator { @Override public ValidationResult validateInstance(Source s) { Schema schema; try { schema = getSchema(); } catch (SAXException e) { throw new XMLUnitException("The schema is invalid", e); } ValidationHandler v = new ValidationHandler(); javax.xml.validation.Validator val = schema.newValidator(); val.setErrorHandler(v); try { val.validate(s); } catch (SAXParseException e) { v.error((SAXParseException) e); } catch (SAXException e) { throw new XMLUnitException(e); } catch (java.io.IOException e) { throw new XMLUnitException(e); } return v.getResult(); } JAXPValidator(String language);  JAXPValidator(String language, SchemaFactory factory); }
JAXPValidator extends Validator { @Override public ValidationResult validateInstance(Source s) { Schema schema; try { schema = getSchema(); } catch (SAXException e) { throw new XMLUnitException("The schema is invalid", e); } ValidationHandler v = new ValidationHandler(); javax.xml.validation.Validator val = schema.newValidator(); val.setErrorHandler(v); try { val.validate(s); } catch (SAXParseException e) { v.error((SAXParseException) e); } catch (SAXException e) { throw new XMLUnitException(e); } catch (java.io.IOException e) { throw new XMLUnitException(e); } return v.getResult(); } JAXPValidator(String language);  JAXPValidator(String language, SchemaFactory factory); final void setSchema(Schema s); @Override ValidationResult validateSchema(); @Override ValidationResult validateInstance(Source s); }
JAXPValidator extends Validator { @Override public ValidationResult validateInstance(Source s) { Schema schema; try { schema = getSchema(); } catch (SAXException e) { throw new XMLUnitException("The schema is invalid", e); } ValidationHandler v = new ValidationHandler(); javax.xml.validation.Validator val = schema.newValidator(); val.setErrorHandler(v); try { val.validate(s); } catch (SAXParseException e) { v.error((SAXParseException) e); } catch (SAXException e) { throw new XMLUnitException(e); } catch (java.io.IOException e) { throw new XMLUnitException(e); } return v.getResult(); } JAXPValidator(String language);  JAXPValidator(String language, SchemaFactory factory); final void setSchema(Schema s); @Override ValidationResult validateSchema(); @Override ValidationResult validateInstance(Source s);  }