stevedlawrence commented on code in PR #1358:
URL: https://github.com/apache/daffodil/pull/1358#discussion_r1828197685
##########
daffodil-japi/src/test/java/org/apache/daffodil/example/TestJavaAPI.java:
##########
@@ -23,10 +23,9 @@
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.IOException;
+import java.io.*;
Review Comment:
I think we generally try to avoid these star imports.
##########
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:
I see, can you add a comment to that affect? Also, in that case I think this
needs a `fail()` and the end of the try block in case the exception isn't
thrown. It might be a bit cleaner to rewrite it like this:
```scala
try {
assertFalse(pf.isError)
// delete file needed by Xerces for full validation
tempFile.delete()
// should throw FileNotFoundException because ...
pf.onPath("/")
// fail if exception was not thrown
fail()
} catch (Exception e) {
assertTrue(e.getMessage().contains(...))
} finally {
if (tempFile.exists) tempFile.delete()
}
```
Removes the conditionals to make it a bit easier to see what's expected.
--
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]