You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2014/03/11 09:51:33 UTC

[6/9] git commit: Fixing test and polished.

Fixing test and polished.


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/d8017044
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/d8017044
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/d8017044

Branch: refs/heads/camel-2.12.x
Commit: d80170440f5a0d267b97d159cf51382c2e859760
Parents: 90fac66
Author: Claus Ibsen <da...@apache.org>
Authored: Tue Mar 11 09:15:26 2014 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Tue Mar 11 09:49:20 2014 +0100

----------------------------------------------------------------------
 .../dataformat/zipfile/ZipFileDataFormat.java   |  3 +-
 .../camel/dataformat/zipfile/ZipIterator.java   | 12 +++-----
 .../camel/dataformat/zipfile/ZipSplitter.java   |  1 -
 .../zipfile/ZipAggregationStrategyTest.java     | 32 ++++++++++++--------
 4 files changed, 24 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/d8017044/components/camel-zipfile/src/main/java/org/apache/camel/dataformat/zipfile/ZipFileDataFormat.java
----------------------------------------------------------------------
diff --git a/components/camel-zipfile/src/main/java/org/apache/camel/dataformat/zipfile/ZipFileDataFormat.java b/components/camel-zipfile/src/main/java/org/apache/camel/dataformat/zipfile/ZipFileDataFormat.java
index 78336f4..884c608 100644
--- a/components/camel-zipfile/src/main/java/org/apache/camel/dataformat/zipfile/ZipFileDataFormat.java
+++ b/components/camel-zipfile/src/main/java/org/apache/camel/dataformat/zipfile/ZipFileDataFormat.java
@@ -86,8 +86,7 @@ public class ZipFileDataFormat implements DataFormat {
 
                 entry = zis.getNextEntry();
                 if (entry != null) {
-                    throw new IllegalStateException(
-                            "Zip file has more than 1 entry.");
+                    throw new IllegalStateException("Zip file has more than 1 entry.");
                 }
 
                 return baos.toByteArray();

http://git-wip-us.apache.org/repos/asf/camel/blob/d8017044/components/camel-zipfile/src/main/java/org/apache/camel/dataformat/zipfile/ZipIterator.java
----------------------------------------------------------------------
diff --git a/components/camel-zipfile/src/main/java/org/apache/camel/dataformat/zipfile/ZipIterator.java b/components/camel-zipfile/src/main/java/org/apache/camel/dataformat/zipfile/ZipIterator.java
index d4ac227..dc8b714 100644
--- a/components/camel-zipfile/src/main/java/org/apache/camel/dataformat/zipfile/ZipIterator.java
+++ b/components/camel-zipfile/src/main/java/org/apache/camel/dataformat/zipfile/ZipIterator.java
@@ -26,6 +26,7 @@ import java.util.zip.ZipInputStream;
 import org.apache.camel.Exchange;
 import org.apache.camel.Message;
 import org.apache.camel.impl.DefaultMessage;
+import org.apache.camel.util.IOHelper;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -70,7 +71,7 @@ class ZipIterator implements Iterator<Message> {
             }
             return availableDataInCurrentEntry;            
         } catch (IOException e) {
-            LOGGER.error("Fail hasNext()", e);
+            LOGGER.warn("Fail hasNext()", e);
             return false;            
         }
     }
@@ -114,13 +115,8 @@ class ZipIterator implements Iterator<Message> {
 
     public void checkNullAnswer(Message answer) {
         if (answer == null && zipInputStream != null) {
-            try {
-                zipInputStream.close();
-            } catch (IOException ignore) {
-                // Do nothing here
-            } finally {
-                zipInputStream = null;
-            }            
+            IOHelper.close(zipInputStream);
+            zipInputStream = null;
         }
     }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/d8017044/components/camel-zipfile/src/main/java/org/apache/camel/dataformat/zipfile/ZipSplitter.java
----------------------------------------------------------------------
diff --git a/components/camel-zipfile/src/main/java/org/apache/camel/dataformat/zipfile/ZipSplitter.java b/components/camel-zipfile/src/main/java/org/apache/camel/dataformat/zipfile/ZipSplitter.java
index df195f2..04e7ec6 100644
--- a/components/camel-zipfile/src/main/java/org/apache/camel/dataformat/zipfile/ZipSplitter.java
+++ b/components/camel-zipfile/src/main/java/org/apache/camel/dataformat/zipfile/ZipSplitter.java
@@ -25,7 +25,6 @@ import org.apache.camel.Message;
  * Based on the thread <a href=
  * "http://camel.465427.n5.nabble.com/zip-file-best-practices-td5713437.html"
  * >zip file best practices</a>
- * 
  */
 public class ZipSplitter implements Expression {
 

http://git-wip-us.apache.org/repos/asf/camel/blob/d8017044/components/camel-zipfile/src/test/java/org/apache/camel/processor/aggregate/zipfile/ZipAggregationStrategyTest.java
----------------------------------------------------------------------
diff --git a/components/camel-zipfile/src/test/java/org/apache/camel/processor/aggregate/zipfile/ZipAggregationStrategyTest.java b/components/camel-zipfile/src/test/java/org/apache/camel/processor/aggregate/zipfile/ZipAggregationStrategyTest.java
index be473fe..9141984 100644
--- a/components/camel-zipfile/src/test/java/org/apache/camel/processor/aggregate/zipfile/ZipAggregationStrategyTest.java
+++ b/components/camel-zipfile/src/test/java/org/apache/camel/processor/aggregate/zipfile/ZipAggregationStrategyTest.java
@@ -16,35 +16,40 @@
  */
 package org.apache.camel.processor.aggregate.zipfile;
 
-
 import java.io.File;
 import java.io.FileInputStream;
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipInputStream;
 
-import org.apache.camel.Exchange;
 import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.component.file.GenericFileMessage;
 import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.test.junit4.CamelTestSupport;
+import org.apache.camel.util.IOHelper;
 import org.junit.Test;
 
 public class ZipAggregationStrategyTest extends CamelTestSupport {
 
     private static final int EXPECTED_NO_FILES = 3;
 
+    @Override
+    public void setUp() throws Exception {
+        deleteDirectory("target/out");
+        super.setUp();
+    }
+
     @Test
     public void testSplitter() throws Exception {
-        MockEndpoint aggregateToZipEntry = getMockEndpoint("mock:aggregateToZipEntry");
-        aggregateToZipEntry.expectedMessageCount(1);
+        MockEndpoint mock = getMockEndpoint("mock:aggregateToZipEntry");
+        mock.expectedMessageCount(1);
+
         assertMockEndpointsSatisfied();
 
-        Exchange out = aggregateToZipEntry.getExchanges().get(0);
-        assertTrue("Result message does not contain GenericFileMessage", GenericFileMessage.class.isAssignableFrom(out.getIn().getClass()));
-        File resultFile = out.getIn().getBody(File.class);
-        assertNotNull(resultFile);
-        assertTrue("Zip file should exist", resultFile.isFile());
-        assertTrue("Result file name does not end with .zip", resultFile.getName().endsWith(".zip"));
+        Thread.sleep(500);
+
+        File[] files = new File("target/out").listFiles();
+        assertTrue("Should be a file in target/out directory", files.length > 0);
+
+        File resultFile = files[0];
 
         ZipInputStream zin = new ZipInputStream(new FileInputStream(resultFile));
         try {
@@ -55,7 +60,7 @@ public class ZipAggregationStrategyTest extends CamelTestSupport {
             assertTrue("Zip file should contains " + ZipAggregationStrategyTest.EXPECTED_NO_FILES + " files",
                        fileCount == ZipAggregationStrategyTest.EXPECTED_NO_FILES);
         } finally {
-            zin.close();
+            IOHelper.close(zin);
         }
     }
 
@@ -70,8 +75,9 @@ public class ZipAggregationStrategyTest extends CamelTestSupport {
                         .constant(true)
                         .completionFromBatchConsumer()
                         .eagerCheckCompletion()
+                    .to("file:target/out")
                     .to("mock:aggregateToZipEntry")
-                    .log("Done processing big file: ${header.CamelFileName}");
+                    .log("Done processing zip file: ${header.CamelFileName}");
             }
         };