use of com.helger.commons.io.resource.IReadableResource in project ph-schematron by phax.
the class PSPreprocessorTest method testWithTitle.
@Test
public void testWithTitle() throws SchematronException {
final PSPreprocessor aPreprocessor = new PSPreprocessor(PSXPathQueryBinding.getInstance()).setKeepTitles(true).setKeepDiagnostics(true);
final IReadableResource aRes = new ClassPathResource("test-sch/example-3-5.sch");
final IMicroDocument aDoc = SchematronHelper.getWithResolvedSchematronIncludes(aRes);
final PSReader aReader = new PSReader(aRes);
final PSSchema aSchema = aReader.readSchemaFromXML(aDoc.getDocumentElement());
final PSSchema aPreprocessedSchema = aPreprocessor.getAsPreprocessedSchema(aSchema);
assertNotNull(aPreprocessedSchema);
assertTrue(aPreprocessedSchema.isValid(new DoNothingPSErrorHandler()));
// Because titles are not in minimal mode
assertFalse(aPreprocessedSchema.isMinimal());
}
use of com.helger.commons.io.resource.IReadableResource in project ph-schematron by phax.
the class PSPreprocessorTest method testBasic.
@Test
public void testBasic() throws Exception {
final PSPreprocessor aPreprocessor = new PSPreprocessor(PSXPathQueryBinding.getInstance());
for (final IReadableResource aRes : SchematronTestHelper.getAllValidSchematronFiles()) {
// Resolve all includes
final IMicroDocument aDoc = SchematronHelper.getWithResolvedSchematronIncludes(aRes);
assertNotNull(aDoc);
// Read to domain object
final PSReader aReader = new PSReader(aRes);
final PSSchema aSchema = aReader.readSchemaFromXML(aDoc.getDocumentElement());
assertNotNull(aSchema);
// Ensure the schema is valid
final CollectingPSErrorHandler aErrHdl = new CollectingPSErrorHandler();
assertTrue(aRes.getPath(), aSchema.isValid(aErrHdl));
assertTrue(aErrHdl.isEmpty());
// Convert to minified schema if not-yet minimal
final PSSchema aPreprocessedSchema = aPreprocessor.getAsMinimalSchema(aSchema);
assertNotNull(aPreprocessedSchema);
if (false) {
final String sXML = MicroWriter.getNodeAsString(aPreprocessedSchema.getAsMicroElement());
SimpleFileIO.writeFile(new File("test-minified", FilenameHelper.getWithoutPath(aRes.getPath()) + ".min-pure.sch"), sXML, XMLWriterSettings.DEFAULT_XML_CHARSET_OBJ);
}
// Ensure it is still valid and minimal
assertTrue(aRes.getPath(), aPreprocessedSchema.isValid(aErrHdl));
assertTrue(aRes.getPath(), aPreprocessedSchema.isMinimal());
}
}
use of com.helger.commons.io.resource.IReadableResource in project ph-schematron by phax.
the class Issue20140523Test method validateAndProduceSVRL.
public static void validateAndProduceSVRL(final File schematron, final File xml) throws Exception {
final IReadableResource aSchematron = new FileSystemResource(schematron.getAbsoluteFile());
final IReadableResource anXMLSource = new FileSystemResource(xml.getAbsoluteFile());
final AbstractSchematronResource pure = new SchematronResourcePure(aSchematron);
final SchematronOutputType aSVRL = pure.applySchematronValidationToSVRL(anXMLSource);
assertNotNull(aSVRL);
if (false)
System.out.println(new SVRLMarshaller().getAsString(aSVRL));
}
use of com.helger.commons.io.resource.IReadableResource in project ph-schematron by phax.
the class PSXPathBoundSchemaTest method testBindAllValidSchematrons.
@Test
public void testBindAllValidSchematrons() throws SchematronException {
for (final IReadableResource aRes : SchematronTestHelper.getAllValidSchematronFiles()) {
// Parse the schema
final PSSchema aSchema = new PSReader(aRes).readSchema();
assertNotNull(aSchema);
CommonsTestHelper.testToStringImplementation(aSchema);
final CollectingPSErrorHandler aLogger = new CollectingPSErrorHandler();
assertTrue(aRes.getPath(), aSchema.isValid(aLogger));
assertTrue(aLogger.isEmpty());
// Create a compiled schema
final String sPhaseID = null;
final IPSErrorHandler aErrorHandler = null;
final IPSBoundSchema aBoundSchema = PSXPathQueryBinding.getInstance().bind(aSchema, sPhaseID, aErrorHandler);
assertNotNull(aBoundSchema);
}
}
use of com.helger.commons.io.resource.IReadableResource in project ph-schematron by phax.
the class Issue25Test method testIssue25Invalid.
@Test
public void testIssue25Invalid() throws Exception {
final IReadableResource aSCH = new ClassPathResource("test-sch/xfront/example05/check-classifications.sch");
final IReadableResource aXML = new ClassPathResource("test-sch/xfront/example05/invalid-document.xml");
final SchematronOutputType aSOT = SchematronHelper.applySchematron(new SchematronResourcePure(aSCH), aXML);
assertNotNull(aSOT);
assertTrue(SVRLHelper.getAllFailedAssertions(aSOT).isNotEmpty());
}
Aggregations