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");
}
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));
}
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);
}
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);
}
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());
}
Aggregations