Search in sources :

Example 21 with ClassPathResource

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

the class SchematronResourceSCHCacheTest method testInvalidSchematron.

@Test
public void testInvalidSchematron() {
    assertFalse(new SchematronResourceSCH(new ClassPathResource("test-sch/invalid01.sch")).isValidSchematron());
    assertFalse(new SchematronResourceSCH(new ClassPathResource("test-sch/this.file.does.not.exists")).isValidSchematron());
    assertFalse(new SchematronResourceSCH(new FileSystemResource("src/test/resources/test-sch/invalid01.sch")).isValidSchematron());
    assertFalse(new SchematronResourceSCH(new FileSystemResource("src/test/resources/test-sch/this.file.does.not.exists")).isValidSchematron());
}
Also used : FileSystemResource(com.helger.commons.io.resource.FileSystemResource) ClassPathResource(com.helger.commons.io.resource.ClassPathResource) Test(org.junit.Test)

Example 22 with ClassPathResource

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

the class SchematronResourceSCHCacheTest method testValidSynchronous.

@Test
public void testValidSynchronous() throws Exception {
    // Ensure that the Schematron is cached
    SchematronResourceSCH.fromClassPath(VALID_SCHEMATRON);
    final long nStart = System.nanoTime();
    for (int i = 0; i < RUNS; ++i) {
        final ISchematronResource aSV = SchematronResourceSCH.fromClassPath(VALID_SCHEMATRON);
        final Document aDoc = aSV.applySchematronValidation(new ClassPathResource(VALID_XMLINSTANCE));
        assertNotNull(aDoc);
        if (false)
            s_aLogger.info(XMLWriter.getNodeAsString(aDoc));
    }
    final long nEnd = System.nanoTime();
    s_aLogger.info("Sync Total: " + ((nEnd - nStart) / 1000) + " microsecs btw. " + ((nEnd - nStart) / 1000 / RUNS) + " microsecs/run");
}
Also used : ISchematronResource(com.helger.schematron.ISchematronResource) Document(org.w3c.dom.Document) ClassPathResource(com.helger.commons.io.resource.ClassPathResource) Test(org.junit.Test)

Example 23 with ClassPathResource

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

the class SchematronHelperTest method testReadNull.

@Test
public void testReadNull() {
    try {
        // null-Schematron not allowed
        SchematronHelper.applySchematron(null, new ClassPathResource(VALID_XMLINSTANCE));
        fail();
    } catch (final NullPointerException ex) {
    /* expected */
    }
    try {
        // null-XML not allowed
        SchematronHelper.applySchematron(SchematronResourceSCH.fromClassPath(VALID_SCHEMATRON), (IReadableResource) null);
        fail();
    } catch (final NullPointerException ex) {
    /* expected */
    }
    try {
        // null-XML not allowed
        SchematronHelper.applySchematron(SchematronResourceSCH.fromClassPath(VALID_SCHEMATRON), (Source) null);
        fail();
    } catch (final NullPointerException ex) {
    /* expected */
    }
}
Also used : ClassPathResource(com.helger.commons.io.resource.ClassPathResource) Test(org.junit.Test)

Example 24 with ClassPathResource

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

the class SchematronHelperTest method testReadValidSchematronInvalidXML.

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

Example 25 with ClassPathResource

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

the class SchematronHelperTest method testReadInvalidSchematronInvalidXML.

@Test
public void testReadInvalidSchematronInvalidXML() {
    final SchematronOutputType aSO = SchematronHelper.applySchematron(SchematronResourceSCH.fromClassPath(VALID_SCHEMATRON + ".does.not.exist"), new ClassPathResource(VALID_XMLINSTANCE + ".does.not.exist"));
    assertNull("Invalid Schematron and XML", aSO);
}
Also used : SchematronOutputType(org.oclc.purl.dsdl.svrl.SchematronOutputType) 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