Search in sources :

Example 6 with SchematronOutputType

use of org.oclc.purl.dsdl.svrl.SchematronOutputType 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 7 with SchematronOutputType

use of org.oclc.purl.dsdl.svrl.SchematronOutputType 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 8 with SchematronOutputType

use of org.oclc.purl.dsdl.svrl.SchematronOutputType 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 9 with SchematronOutputType

use of org.oclc.purl.dsdl.svrl.SchematronOutputType 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 10 with SchematronOutputType

use of org.oclc.purl.dsdl.svrl.SchematronOutputType in project ph-schematron by phax.

the class Issue44Test method validateAndProduceSVRL.

public static void validateAndProduceSVRL(@Nonnull final File aSchematron, final File aXML) throws Exception {
    // SchematronResourcePure fails!
    ISchematronResource aSCH = SchematronResourcePure.fromFile(aSchematron);
    // Parsing Schematron works!
    aSCH = SchematronResourceSCH.fromFile(aSchematron);
    // Perform validation
    final SchematronOutputType aSVRL = aSCH.applySchematronValidationToSVRL(new FileSystemResource(aXML));
    assertNotNull(aSVRL);
    if (false)
        System.out.println(new SVRLMarshaller().getAsString(aSVRL));
    assertEquals(3, SVRLHelper.getAllFailedAssertionsAndSuccessfulReports(aSVRL).size());
}
Also used : SchematronOutputType(org.oclc.purl.dsdl.svrl.SchematronOutputType) ISchematronResource(com.helger.schematron.ISchematronResource) SVRLMarshaller(com.helger.schematron.svrl.SVRLMarshaller) FileSystemResource(com.helger.commons.io.resource.FileSystemResource)

Aggregations

SchematronOutputType (org.oclc.purl.dsdl.svrl.SchematronOutputType)41 Test (org.junit.Test)20 SVRLMarshaller (com.helger.schematron.svrl.SVRLMarshaller)18 FileSystemResource (com.helger.commons.io.resource.FileSystemResource)17 SchematronResourcePure (com.helger.schematron.pure.SchematronResourcePure)15 ClassPathResource (com.helger.commons.io.resource.ClassPathResource)14 IReadableResource (com.helger.commons.io.resource.IReadableResource)11 Document (org.w3c.dom.Document)8 AbstractSchematronResource (com.helger.schematron.AbstractSchematronResource)6 LoggingPSErrorHandler (com.helger.schematron.pure.errorhandler.LoggingPSErrorHandler)6 ISchematronResource (com.helger.schematron.ISchematronResource)5 SchematronResourceSCH (com.helger.schematron.xslt.SchematronResourceSCH)5 MapBasedXPathFunctionResolver (com.helger.xml.xpath.MapBasedXPathFunctionResolver)5 SVRLFailedAssert (com.helger.schematron.svrl.SVRLFailedAssert)4 File (java.io.File)4 XQueryAsXPathFunctionConverter (com.helger.schematron.xpath.XQueryAsXPathFunctionConverter)3 Nonnull (javax.annotation.Nonnull)3 Nullable (javax.annotation.Nullable)3 CollectingPSErrorHandler (com.helger.schematron.pure.errorhandler.CollectingPSErrorHandler)2 PSReader (com.helger.schematron.pure.exchange.PSReader)2