Search in sources :

Example 6 with ClassPathResource

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

the class SchematronResourceSCHCacheTest method testValidAsynchronous.

@Test
public void testValidAsynchronous() throws Exception {
    // Ensure that the Schematron is cached
    SchematronResourceSCH.fromClassPath(VALID_SCHEMATRON);
    // Create Thread pool with fixed number of threads
    final ExecutorService aSenderThreadPool = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors() * 2);
    final long nStart = System.nanoTime();
    for (int i = 0; i < RUNS; ++i) {
        aSenderThreadPool.submit(() -> {
            try {
                final ISchematronResource aSV = SchematronResourceSCH.fromClassPath(VALID_SCHEMATRON);
                final Document aDoc = aSV.applySchematronValidation(new ClassPathResource(VALID_XMLINSTANCE));
                assertNotNull(aDoc);
            } catch (final Exception ex) {
                throw new IllegalStateException(ex);
            }
        });
    }
    ExecutorServiceHelper.shutdownAndWaitUntilAllTasksAreFinished(aSenderThreadPool);
    final long nEnd = System.nanoTime();
    s_aLogger.info("Async Total: " + ((nEnd - nStart) / 1000) + " microsecs btw. " + ((nEnd - nStart) / 1000 / RUNS) + " microsecs/run");
}
Also used : ISchematronResource(com.helger.schematron.ISchematronResource) ExecutorService(java.util.concurrent.ExecutorService) Document(org.w3c.dom.Document) ClassPathResource(com.helger.commons.io.resource.ClassPathResource) Test(org.junit.Test)

Example 7 with ClassPathResource

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

the class SVRLMarshallerTest method testWriteValid.

@Test
public void testWriteValid() throws Exception {
    final Document aDoc = SchematronResourceSCH.fromClassPath(VALID_SCHEMATRON).applySchematronValidation(new ClassPathResource(VALID_XMLINSTANCE));
    assertNotNull(aDoc);
    final SchematronOutputType aSO = new SVRLMarshaller().read(aDoc);
    // Create XML
    final Document aDoc2 = new SVRLMarshaller().getAsDocument(aSO);
    assertNotNull(aDoc2);
    assertEquals(CSVRL.SVRL_NAMESPACE_URI, aDoc2.getDocumentElement().getNamespaceURI());
    // Create String
    final String sDoc2 = new SVRLMarshaller().getAsString(aSO);
    assertTrue(StringHelper.hasText(sDoc2));
    assertTrue(sDoc2.contains(CSVRL.SVRL_NAMESPACE_URI));
}
Also used : SchematronOutputType(org.oclc.purl.dsdl.svrl.SchematronOutputType) Document(org.w3c.dom.Document) ClassPathResource(com.helger.commons.io.resource.ClassPathResource) Test(org.junit.Test)

Example 8 with ClassPathResource

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

the class SVRLMarshallerTest method testReadInvalidSchematron.

@Test
public void testReadInvalidSchematron() {
    try {
        // Read null
        new SVRLMarshaller().read((Node) null);
        fail();
    } catch (final NullPointerException ex) {
    }
    try {
        // Read empty XML
        new SVRLMarshaller().read(XMLFactory.newDocument());
        fail();
    } catch (final NullPointerException ex) {
    }
    // Read XML that is not SVRL
    final SchematronOutputType aSVRL = new SVRLMarshaller().read(new ClassPathResource("test-xml/goodOrder01.xml"));
    assertNull(aSVRL);
}
Also used : SchematronOutputType(org.oclc.purl.dsdl.svrl.SchematronOutputType) ClassPathResource(com.helger.commons.io.resource.ClassPathResource) Test(org.junit.Test)

Example 9 with ClassPathResource

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

the class Issue17Test method testIssue.

@Test
public void testIssue() {
    // Multiple errors contained
    final IReadableResource aRes = new ClassPathResource("testfiles/css30/bad_but_browsercompliant/issue17.css");
    assertTrue(aRes.exists());
    final CascadingStyleSheet aCSS = CSSReader.readFromStream(aRes, new CSSReaderSettings().setFallbackCharset(StandardCharsets.UTF_8).setCSSVersion(ECSSVersion.CSS30).setCustomErrorHandler(new LoggingCSSParseErrorHandler()).setBrowserCompliantMode(true));
    assertNotNull(aCSS);
}
Also used : CascadingStyleSheet(com.helger.css.decl.CascadingStyleSheet) IReadableResource(com.helger.commons.io.resource.IReadableResource) CSSReaderSettings(com.helger.css.reader.CSSReaderSettings) ClassPathResource(com.helger.commons.io.resource.ClassPathResource) LoggingCSSParseErrorHandler(com.helger.css.reader.errorhandler.LoggingCSSParseErrorHandler) Test(org.junit.Test)

Example 10 with ClassPathResource

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

the class Issue21Test method testIssue.

@Test
public void testIssue() {
    // Multiple errors contained
    final IReadableResource aRes = new ClassPathResource("testfiles/css30/good/issue21.css");
    assertTrue(aRes.exists());
    final CascadingStyleSheet aCSS = CSSReader.readFromStream(aRes, new CSSReaderSettings().setFallbackCharset(StandardCharsets.UTF_8).setCustomErrorHandler(new LoggingCSSParseErrorHandler()).setBrowserCompliantMode(true));
    assertNotNull(aCSS);
    if (false)
        System.out.println(new CSSWriter(ECSSVersion.CSS30).getCSSAsString(aCSS));
    assertEquals(2, aCSS.getRuleCount());
    assertEquals(2, aCSS.getStyleRuleCount());
}
Also used : CascadingStyleSheet(com.helger.css.decl.CascadingStyleSheet) IReadableResource(com.helger.commons.io.resource.IReadableResource) CSSWriter(com.helger.css.writer.CSSWriter) CSSReaderSettings(com.helger.css.reader.CSSReaderSettings) ClassPathResource(com.helger.commons.io.resource.ClassPathResource) LoggingCSSParseErrorHandler(com.helger.css.reader.errorhandler.LoggingCSSParseErrorHandler) 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