You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@daffodil.apache.org by "stevedlawrence (via GitHub)" <gi...@apache.org> on 2023/08/04 15:00:46 UTC

[GitHub] [daffodil] stevedlawrence commented on a diff in pull request #1064: Allow changing blob attributes when full/custom validation is enabled

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


##########
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:
   Makes sense, will add.



-- 
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: commits-unsubscribe@daffodil.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org