@Test public void shouldFailOnBrokenSchema() { JAXPValidator v = new JAXPValidator(Languages.W3C_XML_SCHEMA_NS_URI); v.setSchemaSource(new StreamSource(this.getClass().getResourceAsStream("/broken.xsd"))); ValidationResult r = v.validateSchema(); assertFalse(r.isValid()); assertTrue(r.getProblems().iterator().hasNext()); }
@Test public void shouldSuccessfullyValidateInstance() { JAXPValidator v = new JAXPValidator(Languages.W3C_XML_SCHEMA_NS_URI); v.setSchemaSource(new StreamSource(this.getClass().getResourceAsStream("/Book.xsd"))); ValidationResult r = v.validateInstance( new StreamSource(this.getClass().getResourceAsStream("/BookXsdGenerated.xml"))); assertTrue(r.isValid()); assertFalse(r.getProblems().iterator().hasNext()); }
@Test public void shouldThrowWhenValidatingInstanceAndSchemaIsNotThere() { JAXPValidator v = new JAXPValidator(Languages.W3C_XML_SCHEMA_NS_URI); v.setSchemaSource(new StreamSource(this.getClass().getResourceAsStream("/foo.xsd"))); try { v.validateInstance( new StreamSource(this.getClass().getResourceAsStream("/BookXsdGenerated.xml"))); fail("should have thrown an exception"); } catch (Exception e) { assertThat(e, instanceOf(XMLUnitException.class)); } }