@Test public void testValidate() throws IOException { Source testXml = new StreamSource(getClass().getResourceAsStream("/schematron/schematron-test.xml")); v.validate(testXml, new SchematronProfile("/schematron/schematron-test-rules.xml")); }
public void validate(String message, CombinedXmlValidationProfile profile) throws ValidationException { requireNonNull(profile, "validation profile must be not null"); // check whether the root element name is valid String rootElementName = rootElementName(requireNonNull(message, "message must be not null")); if (! profile.isValidRootElement(rootElementName)) { throw new ValidationException("Invalid root element '" + rootElementName + "'"); } // XSD validation String xsdPath = profile.getXsdPath(rootElementName); if (xsdPath != null) { XSD_VALIDATOR.validate(source(message), xsdPath); } // Schematron validation String schematronPath = profile.getSchematronPath(rootElementName); if (schematronPath != null) { SchematronProfile schematronProfile = new SchematronProfile( schematronPath, profile.getCustomSchematronParameters(rootElementName)); SCHEMATRON_VALIDATOR.validate(source(message), schematronProfile); } } }
@Test public void testValidateFail() throws IOException { Source testXml = new StreamSource(getClass().getResourceAsStream( "/schematron/schematron-test-fail.xml")); try { v.validate(testXml, new SchematronProfile("/schematron/schematron-test-rules.xml")); fail("This line shall be not reachable"); } catch (SchematronValidationException e) { Throwable[] cause = e.getCauses(); assertEquals(3, cause.length); assertEquals(10, e.getSvrl().getActivePatternAndFiredRuleAndFailedAssert().size()); } }
@Override public void configure() throws Exception { onException(ValidationException.class).to("mock:error"); from("direct:validator-test").process( helper.validator("testValidator").staticProfile("correct")); from("direct:validator-xml-test").process( helper.xsdValidator().staticProfile("/xsd/test.xsd")).setBody() .constant("passed"); from("direct:validator-schematron-test").process( helper.schematronValidator().staticProfile( new SchematronProfile( "/schematron/schematron-test-rules.xml"))) .setBody().constant("passed"); }