stevedlawrence commented on code in PR #1358:
URL: https://github.com/apache/daffodil/pull/1358#discussion_r1827817449


##########
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:
   Is this supposed to fail? Looks to me like testJavaAPI.schema should exist, 
so `compileSource` and `onPath` should succeed. Feels like this `catch` block 
wants to just contain `fail();`, or alternatively just remove the try/catch so 
that any thrown exceptions will cause the test to fail. Maybe we just need a 
`finally` block to delete the tmp file?



##########
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("/");

Review Comment:
   Should this have `withValidationMode(full)` so that we make sure full 
validation mode works when the URI has a `file` scheme? I assume that's what 
this test is checking for?



-- 
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]

Reply via email to