CAMEL-10791-added option to handle empty directories while unzipping
Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/c35b72e0 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/c35b72e0 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/c35b72e0 Branch: refs/heads/master Commit: c35b72e05fec2e83e3cae104488b25b4c12eadeb Parents: 033bb9d Author: onders86 <ondersez...@gmail.com> Authored: Mon Mar 13 11:07:55 2017 +0300 Committer: Claus Ibsen <davscl...@apache.org> Committed: Tue Mar 14 18:29:38 2017 +0100 ---------------------------------------------------------------------- .../zipfile/ZipFileDataFormatTest.java | 30 +++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/c35b72e0/components/camel-zipfile/src/test/java/org/apache/camel/dataformat/zipfile/ZipFileDataFormatTest.java ---------------------------------------------------------------------- diff --git a/components/camel-zipfile/src/test/java/org/apache/camel/dataformat/zipfile/ZipFileDataFormatTest.java b/components/camel-zipfile/src/test/java/org/apache/camel/dataformat/zipfile/ZipFileDataFormatTest.java index 7273179..7563abf 100644 --- a/components/camel-zipfile/src/test/java/org/apache/camel/dataformat/zipfile/ZipFileDataFormatTest.java +++ b/components/camel-zipfile/src/test/java/org/apache/camel/dataformat/zipfile/ZipFileDataFormatTest.java @@ -21,6 +21,9 @@ import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.Iterator; import java.util.concurrent.TimeUnit; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; @@ -53,6 +56,8 @@ public class ZipFileDataFormatTest extends CamelTestSupport { + "With horsemen riding royally."; private static final File TEST_DIR = new File("target/zip"); + + private ZipFileDataFormat zip; @Test public void testZipAndStreamCaching() throws Exception { @@ -102,6 +107,24 @@ public class ZipFileDataFormatTest extends CamelTestSupport { assertMockEndpointsSatisfied(); } + + @Test + public void testUnzipWithEmptyDirectorySupported() throws Exception { + deleteDirectory(new File("hello_out")); + zip.setUsingIterator(true); + zip.setSupportEmptyDirectory(true); + template.sendBody("direct:unzipWithEmptyDirectory", new File("src/test/resources/hello.odt")); + assertTrue(Files.exists(Paths.get("hello_out/Configurations2"))); + } + + @Test + public void testUnzipWithEmptyDirectoryUnsupported() throws Exception { + deleteDirectory(new File("hello_out")); + zip.setUsingIterator(true); + zip.setSupportEmptyDirectory(false); + template.sendBody("direct:unzipWithEmptyDirectory", new File("src/test/resources/hello.odt")); + assertTrue(!Files.exists(Paths.get("hello_out/Configurations2"))); + } @Test public void testZipAndUnzip() throws Exception { @@ -195,10 +218,15 @@ public class ZipFileDataFormatTest extends CamelTestSupport { public void configure() throws Exception { interceptSendToEndpoint("file:*").to("mock:intercepted"); - ZipFileDataFormat zip = new ZipFileDataFormat(); + zip = new ZipFileDataFormat(); from("direct:zip").marshal(zip).to("mock:zip"); from("direct:unzip").unmarshal(zip).to("mock:unzip"); + from("direct:unzipWithEmptyDirectory").unmarshal(zip) + .split(body(Iterator.class)) + .streaming() + .to("file:hello_out?autoCreate=true") + .end(); from("direct:zipAndUnzip").marshal(zip).unmarshal(zip).to("mock:zipAndUnzip"); from("direct:zipToFile").marshal(zip).to("file:" + TEST_DIR.getPath()).to("mock:zipToFile"); from("direct:dslZip").marshal().zipFile().to("mock:dslZip");