Search in sources :

Example 1 with ClassPathResource

use of com.helger.commons.io.resource.ClassPathResource 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 SchematronOutputType aOT = SchematronResourcePure.fromString(sTest, StandardCharsets.UTF_8).setFunctionResolver(aFunctionResolver).applySchematronValidationToSVRL(aTestDoc, null);
    assertNotNull(aOT);
    if (SVRLHelper.getAllFailedAssertions(aOT).size() != 0) {
        System.out.println(SVRLHelper.getAllFailedAssertions(aOT).get(0).getText());
    }
    assertTrue(SVRLHelper.getAllFailedAssertions(aOT).isEmpty());
}
Also used : SchematronOutputType(org.oclc.purl.dsdl.svrl.SchematronOutputType) Schema(javax.xml.validation.Schema) MapBasedXPathFunctionResolver(com.helger.xml.xpath.MapBasedXPathFunctionResolver) XQueryAsXPathFunctionConverter(com.helger.schematron.xpath.XQueryAsXPathFunctionConverter) DOMReaderSettings(com.helger.xml.serialize.read.DOMReaderSettings) Document(org.w3c.dom.Document) ClassPathResource(com.helger.commons.io.resource.ClassPathResource) Test(org.junit.Test)

Example 2 with ClassPathResource

use of com.helger.commons.io.resource.ClassPathResource in project ph-schematron by phax.

the class PSXPathBoundSchemaTest method testSchematronValidation.

@Test
public void testSchematronValidation() throws SAXException, 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);
        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 String sPhaseID = null;
        final IPSErrorHandler aErrorHandler = null;
        final IPSBoundSchema aBoundSchema = PSXPathQueryBinding.getInstance().bind(aSchema, sPhaseID, aErrorHandler);
        // Validate completely
        final SchematronOutputType aSVRL = aBoundSchema.validateComplete(DOMReader.readXMLDOM(aXmlRes), aXmlRes.getAsURL().toExternalForm());
        assertNotNull(aSVRL);
        if (false)
            System.out.println(new SVRLMarshaller().getAsString(aSVRL));
    }
}
Also used : IPSErrorHandler(com.helger.schematron.pure.errorhandler.IPSErrorHandler) SchematronOutputType(org.oclc.purl.dsdl.svrl.SchematronOutputType) 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 3 with ClassPathResource

use of com.helger.commons.io.resource.ClassPathResource in project ph-schematron by phax.

the class Issue16Test method testIssue16.

@Test
@Ignore
public void testIssue16() throws Exception {
    final File schematronFile = new ClassPathResource("issues/github16/sample_schematron.sch").getAsFile();
    final File xmlFile = new ClassPathResource("issues/github16/test.xml").getAsFile();
    final SchematronOutputType outputType = SchematronUtil.validateXMLViaXSLTSchematronFull(schematronFile, xmlFile);
    if (outputType == null)
        throw new Exception("SchematronOutputType null");
    final List<SVRLSuccessfulReport> succeededList = SVRLHelper.getAllSuccessfulReports(outputType);
    for (final SVRLSuccessfulReport succeededReport : succeededList) {
        System.out.println(succeededReport.getTest());
    }
    int i = 1;
    final List<SVRLFailedAssert> failedList = SVRLHelper.getAllFailedAssertions(outputType);
    for (final SVRLFailedAssert failedAssert : failedList) {
        System.out.println(i++ + ". Location:" + failedAssert.getLocation());
        System.out.println("Test: " + failedAssert.getTest());
        System.out.println("Text: " + failedAssert.getText());
        final List<DiagnosticReference> diagnisticReferences = failedAssert.getDiagnisticReferences();
        for (final DiagnosticReference diagnisticRef : diagnisticReferences) {
            System.out.println("Diag ref: " + diagnisticRef.getDiagnostic());
            System.out.println("Diag text: " + diagnisticRef.getText());
        }
    }
    if (failedList.isEmpty()) {
        System.out.println("PASS");
    } else {
        System.out.println("FAIL");
    }
}
Also used : SchematronOutputType(org.oclc.purl.dsdl.svrl.SchematronOutputType) SVRLFailedAssert(com.helger.schematron.svrl.SVRLFailedAssert) DiagnosticReference(org.oclc.purl.dsdl.svrl.DiagnosticReference) SVRLSuccessfulReport(com.helger.schematron.svrl.SVRLSuccessfulReport) File(java.io.File) ClassPathResource(com.helger.commons.io.resource.ClassPathResource) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 4 with ClassPathResource

use of com.helger.commons.io.resource.ClassPathResource in project ph-schematron by phax.

the class SchematronHelperTest method testReadInvalidSchematronValidXML.

@Test
public void testReadInvalidSchematronValidXML() {
    final SchematronOutputType aSO = SchematronHelper.applySchematron(SchematronResourceSCH.fromClassPath(VALID_SCHEMATRON + ".does.not.exist"), new ClassPathResource(VALID_XMLINSTANCE));
    assertNull("Invalid Schematron", aSO);
}
Also used : SchematronOutputType(org.oclc.purl.dsdl.svrl.SchematronOutputType) ClassPathResource(com.helger.commons.io.resource.ClassPathResource) Test(org.junit.Test)

Example 5 with ClassPathResource

use of com.helger.commons.io.resource.ClassPathResource in project ph-schematron by phax.

the class SchematronHelperTest method testReadValidSchematronValidXML.

@Test
public void testReadValidSchematronValidXML() {
    final ISchematronResource aSchematron = SchematronResourceSCH.fromClassPath(VALID_SCHEMATRON);
    final IReadableResource aXML = new ClassPathResource(VALID_XMLINSTANCE);
    final SchematronOutputType aSO = SchematronHelper.applySchematron(aSchematron, aXML);
    assertNotNull("Failed to parse Schematron output", aSO);
}
Also used : SchematronOutputType(org.oclc.purl.dsdl.svrl.SchematronOutputType) IReadableResource(com.helger.commons.io.resource.IReadableResource) ClassPathResource(com.helger.commons.io.resource.ClassPathResource) Test(org.junit.Test)

Aggregations

ClassPathResource (com.helger.commons.io.resource.ClassPathResource)35 Test (org.junit.Test)33 IReadableResource (com.helger.commons.io.resource.IReadableResource)18 SchematronOutputType (org.oclc.purl.dsdl.svrl.SchematronOutputType)14 CascadingStyleSheet (com.helger.css.decl.CascadingStyleSheet)13 LoggingCSSParseErrorHandler (com.helger.css.reader.errorhandler.LoggingCSSParseErrorHandler)12 CSSWriter (com.helger.css.writer.CSSWriter)8 CSSReaderSettings (com.helger.css.reader.CSSReaderSettings)6 Document (org.w3c.dom.Document)6 ISchematronResource (com.helger.schematron.ISchematronResource)4 SchematronResourcePure (com.helger.schematron.pure.SchematronResourcePure)3 IMicroDocument (com.helger.xml.microdom.IMicroDocument)3 File (java.io.File)3 Ignore (org.junit.Ignore)3 PSReader (com.helger.schematron.pure.exchange.PSReader)2 PSSchema (com.helger.schematron.pure.model.PSSchema)2 SVRLFailedAssert (com.helger.schematron.svrl.SVRLFailedAssert)2 SVRLMarshaller (com.helger.schematron.svrl.SVRLMarshaller)2 ValueEnforcer (com.helger.commons.ValueEnforcer)1 Nonempty (com.helger.commons.annotation.Nonempty)1