use of com.helger.commons.io.resource.ClassPathResource in project ph-schematron by phax.
the class SchematronResourcePureTest method testFunctXAreDistinctValuesWithXSD.
@Test
public void testFunctXAreDistinctValuesWithXSD() throws Exception {
final String sTest = "<?xml version='1.0' encoding='iso-8859-1'?>\n" + "<schema xmlns='http://purl.oclc.org/dsdl/schematron'>\n" + " <ns prefix=\"xs\" uri=\"http://www.w3.org/2001/XMLSchema\"/>\n" + " <ns prefix='fn' uri='http://www.w3.org/2005/xpath-functions' />\n" + " <ns prefix='functx' uri='http://www.functx.com' />\n" + " <pattern name='toto'>\n" + " <title>A very simple pattern with a title</title>\n" + " <rule context='chapter'>\n" + " <assert test='fn:count(fn:distinct-values(para)) = fn:count(para)'>Should have distinct values</assert>\n" + " </rule>\n" + " </pattern>\n" + "</schema>";
final MapBasedXPathFunctionResolver aFunctionResolver = new XQueryAsXPathFunctionConverter().loadXQuery(ClassPathResource.getInputStream("xquery/functx-1.0-nodoc-2007-01.xq"));
final Schema aSchema = XMLSchemaCache.getInstance().getSchema(new ClassPathResource("issues/20141124/chapter.xsd"));
final Document aTestDoc = DOMReader.readXMLDOM("<?xml version='1.0'?>" + "<chapter>" + " <title />" + " <para>09</para>" + " <para>9</para>" + "</chapter>", new DOMReaderSettings().setSchema(aSchema));
final SchematronOutputType aOT = SchematronResourcePure.fromString(sTest, StandardCharsets.UTF_8).setFunctionResolver(aFunctionResolver).applySchematronValidationToSVRL(aTestDoc, null);
assertNotNull(aOT);
if (SVRLHelper.getAllFailedAssertions(aOT).size() != 0) {
System.out.println(SVRLHelper.getAllFailedAssertions(aOT).get(0).getText());
}
assertTrue(SVRLHelper.getAllFailedAssertions(aOT).isEmpty());
}
use of com.helger.commons.io.resource.ClassPathResource 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));
}
}
use of com.helger.commons.io.resource.ClassPathResource 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");
}
}
use of com.helger.commons.io.resource.ClassPathResource in project ph-schematron by phax.
the class SchematronHelperTest method testReadInvalidSchematronValidXML.
@Test
public void testReadInvalidSchematronValidXML() {
final SchematronOutputType aSO = SchematronHelper.applySchematron(SchematronResourceSCH.fromClassPath(VALID_SCHEMATRON + ".does.not.exist"), new ClassPathResource(VALID_XMLINSTANCE));
assertNull("Invalid Schematron", aSO);
}
use of com.helger.commons.io.resource.ClassPathResource in project ph-schematron by phax.
the class SchematronHelperTest method testReadValidSchematronValidXML.
@Test
public void testReadValidSchematronValidXML() {
final ISchematronResource aSchematron = SchematronResourceSCH.fromClassPath(VALID_SCHEMATRON);
final IReadableResource aXML = new ClassPathResource(VALID_XMLINSTANCE);
final SchematronOutputType aSO = SchematronHelper.applySchematron(aSchematron, aXML);
assertNotNull("Failed to parse Schematron output", aSO);
}
Aggregations