Search in sources :

Example 11 with SchematronOutputType

use of com.helger.schematron.svrl.jaxb.SchematronOutputType in project ph-schematron by phax.

the class Issue126Test method _validateAndProduceSVRL.

private static void _validateAndProduceSVRL(@Nonnull final File aSchematron, @Nonnull final File aXML) throws Exception {
    final SchematronResourceSCH aSCH = SchematronResourceSCH.fromFile(aSchematron);
    aSCH.setAllowForeignElements(true);
    // Perform validation
    final SchematronOutputType aSVRL = aSCH.applySchematronValidationToSVRL(new FileSystemResource(aXML));
    assertNotNull(aSVRL);
    final String sSVRL = new SVRLMarshaller().getAsString(aSVRL);
    assertNotNull(sSVRL);
    if (true)
        LOGGER.info("SVRL:\n" + sSVRL);
    assertEquals(1, SVRLHelper.getAllFailedAssertionsAndSuccessfulReports(aSVRL).size());
}
Also used : SchematronOutputType(com.helger.schematron.svrl.jaxb.SchematronOutputType) SchematronResourceSCH(com.helger.schematron.sch.SchematronResourceSCH) SVRLMarshaller(com.helger.schematron.svrl.SVRLMarshaller) FileSystemResource(com.helger.commons.io.resource.FileSystemResource)

Example 12 with SchematronOutputType

use of com.helger.schematron.svrl.jaxb.SchematronOutputType in project ph-schematron by phax.

the class SchematronHelperTest method testReadValidSchematronValidXMLFromFile.

@Test
public void testReadValidSchematronValidXMLFromFile() throws Exception {
    final ISchematronResource aSchematron = SchematronResourcePure.fromClassPath(VALID_SCHEMATRON);
    final IReadableResource aXML = new ClassPathResource(VALID_XMLINSTANCE);
    final SchematronOutputType aSO = aSchematron.applySchematronValidationToSVRL(TransformSourceFactory.create(aXML));
    assertNotNull("Failed to parse Schematron output", aSO);
}
Also used : SchematronOutputType(com.helger.schematron.svrl.jaxb.SchematronOutputType) ISchematronResource(com.helger.schematron.ISchematronResource) IReadableResource(com.helger.commons.io.resource.IReadableResource) ClassPathResource(com.helger.commons.io.resource.ClassPathResource) Test(org.junit.Test)

Example 13 with SchematronOutputType

use of com.helger.schematron.svrl.jaxb.SchematronOutputType in project ph-schematron by phax.

the class SchematronResourcePureTest method testFunctXAreDistinctValuesWithXSD.

@Test
public void testFunctXAreDistinctValuesWithXSD() throws Exception {
    final String sTest = "<?xml version='1.0' encoding='iso-8859-1'?>\n" + "<schema xmlns='http://purl.oclc.org/dsdl/schematron'>\n" + "  <ns prefix=\"xs\" uri=\"http://www.w3.org/2001/XMLSchema\"/>\n" + "  <ns prefix='fn' uri='http://www.w3.org/2005/xpath-functions' />\n" + "  <ns prefix='functx' uri='http://www.functx.com' />\n" + "  <pattern name='toto'>\n" + "    <title>A very simple pattern with a title</title>\n" + "    <rule context='chapter'>\n" + "      <assert test='fn:count(fn:distinct-values(para)) = fn:count(para)'>Should have distinct values</assert>\n" + "      </rule>\n" + "  </pattern>\n" + "</schema>";
    final MapBasedXPathFunctionResolver aFunctionResolver = new XQueryAsXPathFunctionConverter().loadXQuery(ClassPathResource.getInputStream("xquery/functx-1.0-nodoc-2007-01.xq"));
    final Schema aSchema = XMLSchemaCache.getInstance().getSchema(new ClassPathResource("issues/20141124/chapter.xsd"));
    final Document aTestDoc = DOMReader.readXMLDOM("<?xml version='1.0'?>" + "<chapter>" + " <title />" + " <para>09</para>" + " <para>9</para>" + "</chapter>", new DOMReaderSettings().setSchema(aSchema));
    final IXPathConfig aXPathConfig = new XPathConfigBuilder().setXPathFunctionResolver(aFunctionResolver).build();
    final SchematronOutputType aOT = SchematronResourcePure.fromByteArray(sTest.getBytes(StandardCharsets.UTF_8)).setXPathConfig(aXPathConfig).applySchematronValidationToSVRL(aTestDoc, null);
    assertNotNull(aOT);
    if (SVRLHelper.getAllFailedAssertions(aOT).isNotEmpty()) {
        LOGGER.info(SVRLHelper.getAllFailedAssertions(aOT).get(0).getText());
    }
    assertTrue(SVRLHelper.getAllFailedAssertions(aOT).isEmpty());
}
Also used : SchematronOutputType(com.helger.schematron.svrl.jaxb.SchematronOutputType) Schema(javax.xml.validation.Schema) MapBasedXPathFunctionResolver(com.helger.xml.xpath.MapBasedXPathFunctionResolver) XQueryAsXPathFunctionConverter(com.helger.schematron.pure.xpath.XQueryAsXPathFunctionConverter) XPathConfigBuilder(com.helger.schematron.pure.xpath.XPathConfigBuilder) DOMReaderSettings(com.helger.xml.serialize.read.DOMReaderSettings) Document(org.w3c.dom.Document) IXPathConfig(com.helger.schematron.pure.xpath.IXPathConfig) ClassPathResource(com.helger.commons.io.resource.ClassPathResource) Test(org.junit.Test)

Example 14 with SchematronOutputType

use of com.helger.schematron.svrl.jaxb.SchematronOutputType in project ph-schematron by phax.

the class PSXPathBoundSchemaTest method testSchematronValidation.

@Test
public void testSchematronValidation() throws SchematronException {
    for (int i = 0; i < SCH.length; ++i) {
        final IReadableResource aSchRes = new ClassPathResource("test-sch/" + SCH[i]);
        final IReadableResource aXmlRes = new ClassPathResource("test-xml/" + XML[i]);
        // Resolve all includes
        final IMicroDocument aDoc = SchematronHelper.getWithResolvedSchematronIncludes(aSchRes, new LoggingPSErrorHandler());
        assertNotNull(aDoc);
        // Read to domain object
        final PSReader aReader = new PSReader(aSchRes);
        final PSSchema aSchema = aReader.readSchemaFromXML(aDoc.getDocumentElement());
        assertNotNull(aSchema);
        // Create a compiled schema
        final IPSBoundSchema aBoundSchema = PSXPathQueryBinding.getInstance().bind(aSchema);
        // Validate completely
        final SchematronOutputType aSVRL = aBoundSchema.validateComplete(DOMReader.readXMLDOM(aXmlRes), aXmlRes.getAsURL().toExternalForm());
        assertNotNull(aSVRL);
        if (false)
            LOGGER.info(new SVRLMarshaller().getAsString(aSVRL));
    }
}
Also used : SchematronOutputType(com.helger.schematron.svrl.jaxb.SchematronOutputType) LoggingPSErrorHandler(com.helger.schematron.pure.errorhandler.LoggingPSErrorHandler) IPSBoundSchema(com.helger.schematron.pure.bound.IPSBoundSchema) IReadableResource(com.helger.commons.io.resource.IReadableResource) SVRLMarshaller(com.helger.schematron.svrl.SVRLMarshaller) IMicroDocument(com.helger.xml.microdom.IMicroDocument) PSReader(com.helger.schematron.pure.exchange.PSReader) PSSchema(com.helger.schematron.pure.model.PSSchema) ClassPathResource(com.helger.commons.io.resource.ClassPathResource) Test(org.junit.Test)

Example 15 with SchematronOutputType

use of com.helger.schematron.svrl.jaxb.SchematronOutputType in project ph-schematron by phax.

the class SchematronResourcePureTest method testResolveXQueryFunctions.

@Test
public void testResolveXQueryFunctions() 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='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='title'>Chapter should have a title</iso:assert>\n" + "      <iso:report test='count(para) = 2'>\n" + "      Node kind: <iso:value-of select='functx:node-kind(para)'/> - end</iso:report>\n" + "    </iso:rule>\n" + "  </iso:pattern>\n" + "\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>First para</para>" + "<para>Second para</para>" + "</chapter>");
    final IXPathConfig aXPathConfig = new XPathConfigBuilder().setXPathFunctionResolver(aFunctionResolver).build();
    final SchematronOutputType aOT = SchematronResourcePure.fromByteArray(sTest.getBytes(StandardCharsets.UTF_8)).setXPathConfig(aXPathConfig).applySchematronValidationToSVRL(aTestDoc, null);
    assertNotNull(aOT);
    assertEquals(0, SVRLHelper.getAllFailedAssertions(aOT).size());
    assertEquals(1, SVRLHelper.getAllSuccessfulReports(aOT).size());
    // Note: the text contains all whitespaces!
    assertEquals("\n      Node kind: element - end".trim(), SVRLHelper.getAllSuccessfulReports(aOT).get(0).getText());
}
Also used : SchematronOutputType(com.helger.schematron.svrl.jaxb.SchematronOutputType) MapBasedXPathFunctionResolver(com.helger.xml.xpath.MapBasedXPathFunctionResolver) XQueryAsXPathFunctionConverter(com.helger.schematron.pure.xpath.XQueryAsXPathFunctionConverter) XPathConfigBuilder(com.helger.schematron.pure.xpath.XPathConfigBuilder) Document(org.w3c.dom.Document) IXPathConfig(com.helger.schematron.pure.xpath.IXPathConfig) Test(org.junit.Test)

Aggregations

SchematronOutputType (com.helger.schematron.svrl.jaxb.SchematronOutputType)56 SVRLMarshaller (com.helger.schematron.svrl.SVRLMarshaller)31 FileSystemResource (com.helger.commons.io.resource.FileSystemResource)30 Test (org.junit.Test)21 SchematronResourcePure (com.helger.schematron.pure.SchematronResourcePure)18 ClassPathResource (com.helger.commons.io.resource.ClassPathResource)15 IReadableResource (com.helger.commons.io.resource.IReadableResource)13 ISchematronResource (com.helger.schematron.ISchematronResource)10 SchematronResourceSCH (com.helger.schematron.sch.SchematronResourceSCH)10 AbstractSchematronResource (com.helger.schematron.AbstractSchematronResource)9 Document (org.w3c.dom.Document)9 LoggingPSErrorHandler (com.helger.schematron.pure.errorhandler.LoggingPSErrorHandler)7 IXPathConfig (com.helger.schematron.pure.xpath.IXPathConfig)6 XPathConfigBuilder (com.helger.schematron.pure.xpath.XPathConfigBuilder)6 SVRLFailedAssert (com.helger.schematron.svrl.SVRLFailedAssert)4 MapBasedXPathFunctionResolver (com.helger.xml.xpath.MapBasedXPathFunctionResolver)4 File (java.io.File)4 Nonnull (javax.annotation.Nonnull)4 LoggingPSValidationHandler (com.helger.schematron.pure.validation.LoggingPSValidationHandler)3 XQueryAsXPathFunctionConverter (com.helger.schematron.pure.xpath.XQueryAsXPathFunctionConverter)3