mbeckerle commented on code in PR #1064:
URL: https://github.com/apache/daffodil/pull/1064#discussion_r1284453713
##########
daffodil-japi/src/test/java/org/apache/daffodil/example/TestJavaAPI.java:
##########
@@ -1308,4 +1309,36 @@ public void doXMLTextEscapeStyleTest(String expect,
String data, String schemaTy
assertFalse(err);
assertEquals(expect, value);
}
+
+ @Test
+ public void testJavaAPIBlob1() throws IOException, ClassNotFoundException,
InvalidUsageException {
+ org.apache.daffodil.japi.Compiler c = Daffodil.compiler();
+ java.io.File schemaFile = getResource("/test/japi/blob.dfdl.xsd");
+ ProcessorFactory pf = c.compileFile(schemaFile);
+ DataProcessor dp = pf.onPath("/");
+ dp = dp.withValidationMode(ValidationMode.Full);
+
+ byte[] data = new byte[] { 0x00, 0x00, 0x00, 0x04, 0x01, 0x02, 0x03,
0x04 };
+ ByteArrayInputStream bis = new ByteArrayInputStream(data);
+ InputSourceDataInputStream input = new
InputSourceDataInputStream(data);
+
+ Path blobRoot = Paths.get(System.getProperty("java.io.tmpdir"),
"daffodil", "japi");
+ Files.createDirectories(blobRoot);
+ Path blobDir = Files.createTempDirectory(blobRoot, "blob-");
+
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ XMLTextInfosetOutputter output = new XMLTextInfosetOutputter(bos,
true);
+ output.setBlobAttributes(blobDir, "pre-", ".suf");
+
+ ParseResult res = dp.parse(input, output);
+ assertFalse(res.isError());
+
+ List<Path> blobPaths =
JavaConverters.seqAsJavaList(output.getBlobPaths());
+ assertTrue(blobPaths.size() == 1);
+ assertTrue(blobPaths.get(0).toString().contains("blob-"));
+ assertTrue(blobPaths.get(0).toString().contains("pre-"));
+ assertTrue(blobPaths.get(0).toString().contains(".suf"));
+ Files.delete(blobPaths.get(0));
+ Files.delete(blobDir);
Review Comment:
If this test fails it will leave files/dirs around? Do you want a
try-finally here to ensure they are cleaned up?
It doesn't much matter since the test should not fail.
It's just a matter of "what if someone copies this code to model their blob
usage?". Then it would be better if the code had the try-finally.
(Same comment for the Scala API test file.)
--
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]