olabusayoT commented on code in PR #1358:
URL: https://github.com/apache/daffodil/pull/1358#discussion_r1828139468
##########
daffodil-japi/src/test/java/org/apache/daffodil/example/TestJavaAPI.java:
##########
@@ -1444,5 +1443,45 @@ public void testJavaAPICompileResource() throws
IOException, ClassNotFoundExcept
}
}
+ @Test
+ public void testJavaAPICompileSource1() throws IOException,
URISyntaxException, InvalidUsageException {
+ org.apache.daffodil.japi.Compiler c = Daffodil.compiler();
+ URI uri = new URI("/test/japi/mySchema1.dfdl.xsd");
+ ProcessorFactory pf = c.compileSource(uri);
+ DataProcessor dp =
pf.onPath("/").withValidationMode(ValidationMode.Full);
+
+ java.io.File file = getResource("/test/japi/myDataBroken.dat");
+ java.io.FileInputStream fis = new java.io.FileInputStream(file);
+ try (InputSourceDataInputStream dis = new
InputSourceDataInputStream(fis)) {
+ JDOMInfosetOutputter outputter = new JDOMInfosetOutputter();
+ ParseResult res = dp.parse(dis, outputter);
+ assertTrue(res.isError());
+
+ Diagnostic d = res.getDiagnostics().get(0);
+ LocationInSchemaFile loc = d.getLocationsInSchemaFiles().get(0);
+ assertTrue(loc.toString().replace("\\", "/").contains("in " +
uri.getPath()));
+ }
+ }
+
+ @Test
+ public void testJavaAPICompileSource2() throws IOException {
+ org.apache.daffodil.japi.Compiler c = Daffodil.compiler();
+ File tempFile = File.createTempFile("testJavaAPI", ".schema");
+ File schemaFile = getResource("/test/japi/mySchema2.dfdl.xsd");
+ FileUtils.copyFile(schemaFile, tempFile);
+ ProcessorFactory pf = c.compileSource(tempFile.toURI());
+ try {
+ if (!pf.isError()) {
+ tempFile.delete();
+ pf.onPath("/");
+ } else {
+ tempFile.delete();
+ fail();
+ }
+ } catch (Exception e) {
+ assertTrue(e.getMessage().contains("Could not find file or
resource"));
Review Comment:
So this test is intended to test the case where compileSource succeeds, but
onPath can't find the file when it tries to resolve the schemaLocation. It's
mainly a coverage test. That's also why we don't call withValidationMode(Full)
here, since onPath is where we do the resolution
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]