Search in sources :

Example 1 with LoggingPSErrorHandler

use of com.helger.schematron.pure.errorhandler.LoggingPSErrorHandler in project ph-schematron by phax.

the class SchematronResourcePureTest method testResolveFunctXAreDistinctValuesQueryFunctions.

@Test
public void testResolveFunctXAreDistinctValuesQueryFunctions() throws Exception {
    final String sTest = "<?xml version='1.0' encoding='iso-8859-1'?>\n" + "<iso:schema xmlns='http://purl.oclc.org/dsdl/schematron' \n" + "         xmlns:iso='http://purl.oclc.org/dsdl/schematron' \n" + "         xmlns:sch='http://www.ascc.net/xml/schematron'\n" + "         queryBinding='xslt2'\n" + "         schemaVersion='ISO19757-3'>\n" + "  <iso:title>Test ISO schematron file. Introduction mode</iso:title>\n" + "  <iso:ns prefix='dp' uri='http://www.dpawson.co.uk/ns#' />\n" + "  <iso:ns prefix='fn' uri='http://www.w3.org/2005/xpath-functions' />\n" + "  <iso:ns prefix='functx' uri='http://www.functx.com' />\n" + "    <iso:pattern >\n" + "    <iso:title>A very simple pattern with a title</iso:title>\n" + "    <iso:rule context='chapter'>\n" + "      <iso:assert test='functx:are-distinct-values(para)'>Should have distinct values</iso:assert>\n" + "      </iso:rule>\n" + "  </iso:pattern>\n" + "</iso:schema>";
    final MapBasedXPathFunctionResolver aFunctionResolver = new XQueryAsXPathFunctionConverter().loadXQuery(ClassPathResource.getInputStream("xquery/functx-1.0-nodoc-2007-01.xq"));
    // Test with variable and function resolver
    final Document aTestDoc = DOMReader.readXMLDOM("<?xml version='1.0'?>" + "<chapter>" + "<title />" + "<para>100</para>" + "<para>200</para>" + "</chapter>");
    final CollectingPSErrorHandler aErrorHandler = new CollectingPSErrorHandler(new LoggingPSErrorHandler());
    final SchematronOutputType aOT = SchematronResourcePure.fromString(sTest, StandardCharsets.UTF_8).setFunctionResolver(aFunctionResolver).setErrorHandler(aErrorHandler).applySchematronValidationToSVRL(aTestDoc, null);
    assertNotNull(aOT);
    // XXX fails :(
    if (false)
        assertTrue(aErrorHandler.getAllErrors().toString(), aErrorHandler.isEmpty());
    assertEquals(0, SVRLHelper.getAllFailedAssertions(aOT).size());
}
Also used : SchematronOutputType(org.oclc.purl.dsdl.svrl.SchematronOutputType) LoggingPSErrorHandler(com.helger.schematron.pure.errorhandler.LoggingPSErrorHandler) MapBasedXPathFunctionResolver(com.helger.xml.xpath.MapBasedXPathFunctionResolver) XQueryAsXPathFunctionConverter(com.helger.schematron.xpath.XQueryAsXPathFunctionConverter) Document(org.w3c.dom.Document) CollectingPSErrorHandler(com.helger.schematron.pure.errorhandler.CollectingPSErrorHandler) Test(org.junit.Test)

Example 2 with LoggingPSErrorHandler

use of com.helger.schematron.pure.errorhandler.LoggingPSErrorHandler in project ph-schematron by phax.

the class Issue11Test method validateAndProduceSVRL.

public static void validateAndProduceSVRL(@Nonnull final File aSchematron, final File aXML) throws Exception {
    final SchematronResourcePure aSCH = SchematronResourcePure.fromFile(aSchematron);
    aSCH.setErrorHandler(new LoggingPSErrorHandler());
    assertTrue(aSCH.isValidSchematron());
    // Perform validation
    final SchematronOutputType aSVRL = aSCH.applySchematronValidationToSVRL(new FileSystemResource(aXML));
    assertNotNull(aSVRL);
    if (false)
        System.out.println(new SVRLMarshaller().getAsString(aSVRL));
}
Also used : SchematronOutputType(org.oclc.purl.dsdl.svrl.SchematronOutputType) LoggingPSErrorHandler(com.helger.schematron.pure.errorhandler.LoggingPSErrorHandler) SVRLMarshaller(com.helger.schematron.svrl.SVRLMarshaller) FileSystemResource(com.helger.commons.io.resource.FileSystemResource) SchematronResourcePure(com.helger.schematron.pure.SchematronResourcePure)

Example 3 with LoggingPSErrorHandler

use of com.helger.schematron.pure.errorhandler.LoggingPSErrorHandler in project ph-schematron by phax.

the class Issue36Test method testNestedExtends.

@Test
public void testNestedExtends() throws Exception {
    final SchematronResourcePure aResPure = SchematronResourcePure.fromFile("src/test/resources/issues/github36/test2.sch");
    aResPure.setErrorHandler(new LoggingPSErrorHandler());
    final SchematronOutputType aSOT = aResPure.applySchematronValidationToSVRL(new FileSystemResource("src/test/resources/issues/github36/test.xml"));
    assertNotNull(aSOT);
    assertFalse(SVRLHelper.getAllFailedAssertions(aSOT).isEmpty());
}
Also used : SchematronOutputType(org.oclc.purl.dsdl.svrl.SchematronOutputType) LoggingPSErrorHandler(com.helger.schematron.pure.errorhandler.LoggingPSErrorHandler) FileSystemResource(com.helger.commons.io.resource.FileSystemResource) SchematronResourcePure(com.helger.schematron.pure.SchematronResourcePure) Test(org.junit.Test)

Example 4 with LoggingPSErrorHandler

use of com.helger.schematron.pure.errorhandler.LoggingPSErrorHandler in project ph-schematron by phax.

the class Issue36Test method test.

@Test
public void test() throws Exception {
    final SchematronResourcePure aResPure = SchematronResourcePure.fromFile("src/test/resources/issues/github36/test.sch");
    aResPure.setErrorHandler(new LoggingPSErrorHandler());
    final SchematronOutputType aSOT = aResPure.applySchematronValidationToSVRL(new FileSystemResource("src/test/resources/issues/github36/test.xml"));
    assertNotNull(aSOT);
    assertFalse(SVRLHelper.getAllFailedAssertions(aSOT).isEmpty());
}
Also used : SchematronOutputType(org.oclc.purl.dsdl.svrl.SchematronOutputType) LoggingPSErrorHandler(com.helger.schematron.pure.errorhandler.LoggingPSErrorHandler) FileSystemResource(com.helger.commons.io.resource.FileSystemResource) SchematronResourcePure(com.helger.schematron.pure.SchematronResourcePure) Test(org.junit.Test)

Example 5 with LoggingPSErrorHandler

use of com.helger.schematron.pure.errorhandler.LoggingPSErrorHandler in project ph-schematron by phax.

the class Issue6Test method validateAndProduceSVRL.

@SuppressFBWarnings("BC_IMPOSSIBLE_INSTANCEOF")
public static void validateAndProduceSVRL(final File schematron, final File xml) throws Exception {
    final IReadableResource aSchematron = new FileSystemResource(schematron.getAbsoluteFile());
    final IReadableResource anXMLSource = new FileSystemResource(xml.getAbsoluteFile());
    final AbstractSchematronResource aSCH = new SchematronResourceSCH(aSchematron);
    if (aSCH instanceof SchematronResourcePure)
        ((SchematronResourcePure) aSCH).setErrorHandler(new LoggingPSErrorHandler());
    else
        System.out.println(XMLWriter.getNodeAsString(((SchematronResourceSCH) aSCH).getXSLTProvider().getXSLTDocument()));
    final SchematronOutputType aSVRL = aSCH.applySchematronValidationToSVRL(anXMLSource);
    assertNotNull(aSVRL);
    if (false)
        System.out.println(new SVRLMarshaller().getAsString(aSVRL));
}
Also used : SchematronOutputType(org.oclc.purl.dsdl.svrl.SchematronOutputType) SchematronResourceSCH(com.helger.schematron.xslt.SchematronResourceSCH) LoggingPSErrorHandler(com.helger.schematron.pure.errorhandler.LoggingPSErrorHandler) IReadableResource(com.helger.commons.io.resource.IReadableResource) SVRLMarshaller(com.helger.schematron.svrl.SVRLMarshaller) FileSystemResource(com.helger.commons.io.resource.FileSystemResource) AbstractSchematronResource(com.helger.schematron.AbstractSchematronResource) SchematronResourcePure(com.helger.schematron.pure.SchematronResourcePure) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Aggregations

LoggingPSErrorHandler (com.helger.schematron.pure.errorhandler.LoggingPSErrorHandler)7 SchematronResourcePure (com.helger.schematron.pure.SchematronResourcePure)6 SchematronOutputType (org.oclc.purl.dsdl.svrl.SchematronOutputType)6 FileSystemResource (com.helger.commons.io.resource.FileSystemResource)5 Test (org.junit.Test)4 SVRLMarshaller (com.helger.schematron.svrl.SVRLMarshaller)2 IReadableResource (com.helger.commons.io.resource.IReadableResource)1 AbstractSchematronResource (com.helger.schematron.AbstractSchematronResource)1 CollectingPSErrorHandler (com.helger.schematron.pure.errorhandler.CollectingPSErrorHandler)1 XQueryAsXPathFunctionConverter (com.helger.schematron.xpath.XQueryAsXPathFunctionConverter)1 SchematronResourceSCH (com.helger.schematron.xslt.SchematronResourceSCH)1 MapBasedXPathFunctionResolver (com.helger.xml.xpath.MapBasedXPathFunctionResolver)1 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 File (java.io.File)1 Document (org.w3c.dom.Document)1