Author: davsclaus
Date: Tue Oct 23 12:18:26 2012
New Revision: 1401264

URL: http://svn.apache.org/viewvc?rev=1401264&view=rev
Log:
CAMEL-5737: Fixed issue with localWorkDirectory option on camel-ftp.

Added:
    
camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerLocalWorkDirectoryDirectTest.java
      - copied, changed from r1401180, 
camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerLocalWorkDirectoryTest.java
Modified:
    
camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileOperations.java

Modified: 
camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileOperations.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileOperations.java?rev=1401264&r1=1401263&r2=1401264&view=diff
==============================================================================
--- 
camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileOperations.java
 (original)
+++ 
camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileOperations.java
 Tue Oct 23 12:18:26 2012
@@ -201,19 +201,21 @@ public class FileOperations implements G
 
             // we can optimize and use file based if no charset must be used, 
and the input body is a file
             File source = null;
+            boolean fileBased = false;
             if (charset == null) {
                 // if no charset, then we can try using file directly 
(optimized)
                 Object body = exchange.getIn().getBody();
                 if (body instanceof WrappedFile) {
                     body = ((WrappedFile<?>) body).getFile();
+                    fileBased = true;
                 }
                 if (body instanceof File) {
                     source = (File) body;
                 }
             }
 
-            if (source != null) {
-                // okay we know the body is a file type
+            if (fileBased) {
+                // okay we know the body is a file based
 
                 // so try to see if we can optimize by renaming the local work 
path file instead of doing
                 // a full file to file copy, as the local work copy is to be 
deleted afterwards anyway
@@ -230,7 +232,7 @@ public class FileOperations implements G
                         // to the target.
                         return true;
                     }
-                } else if (source.exists()) {
+                } else if (source != null && source.exists()) {
                     // no there is no local work file so use file to file copy 
if the source exists
                     writeFileByFile(source, file);
                     // try to keep last modified timestamp if configured to do 
so

Copied: 
camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerLocalWorkDirectoryDirectTest.java
 (from r1401180, 
camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerLocalWorkDirectoryTest.java)
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerLocalWorkDirectoryDirectTest.java?p2=camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerLocalWorkDirectoryDirectTest.java&p1=camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerLocalWorkDirectoryTest.java&r1=1401180&r2=1401264&rev=1401264&view=diff
==============================================================================
--- 
camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerLocalWorkDirectoryTest.java
 (original)
+++ 
camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerLocalWorkDirectoryDirectTest.java
 Tue Oct 23 12:18:26 2012
@@ -20,19 +20,17 @@ import java.io.File;
 
 import org.apache.camel.Endpoint;
 import org.apache.camel.Exchange;
-import org.apache.camel.Processor;
 import org.apache.camel.Producer;
+import org.apache.camel.builder.NotifyBuilder;
 import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.converter.IOConverter;
-import org.apache.camel.util.FileUtil;
 import org.junit.Before;
 import org.junit.Test;
 
 /**
  * @version 
  */
-public class FtpConsumerLocalWorkDirectoryTest extends FtpServerTestSupport {
+public class FtpConsumerLocalWorkDirectoryDirectTest extends 
FtpServerTestSupport {
 
     protected String getFtpUrl() {
         return "ftp://admin@localhost:"; + getPort()
@@ -64,14 +62,8 @@ public class FtpConsumerLocalWorkDirecto
 
     @Test
     public void testLocalWorkDirectory() throws Exception {
-        MockEndpoint mock = getMockEndpoint("mock:result");
-        mock.expectedBodiesReceived("Hello World");
-        mock.expectedMessageCount(1);
-
-        assertMockEndpointsSatisfied();
-
-        // give test some time to close file resources
-        Thread.sleep(6000);
+        NotifyBuilder notify = new NotifyBuilder(context).whenDone(1).create();
+        assertTrue("Should process one file", notify.matchesMockWaitTime());
 
         // and the out file should exists
         File out = new File("target/out/hello.txt").getAbsoluteFile();
@@ -86,14 +78,7 @@ public class FtpConsumerLocalWorkDirecto
     protected RouteBuilder createRouteBuilder() throws Exception {
         return new RouteBuilder() {
             public void configure() throws Exception {
-                from(getFtpUrl()).process(new Processor() {
-                    public void process(Exchange exchange) throws Exception {
-                        File body = exchange.getIn().getBody(File.class);
-                        assertNotNull(body);
-                        assertTrue("Local work file should exists", 
body.exists());
-                        
assertEquals(FileUtil.normalizePath("target/lwd/hello.txt"), body.getPath());
-                    }
-                }).to("mock:result", "file://target/out");
+                from(getFtpUrl()).to("file://target/out");
             }
         };
     }


Reply via email to