Repository: camel
Updated Branches:
  refs/heads/ftpfix 9ffbfc489 -> 91f6eb36f


Added a unit Test and use byteArray instead of InputStream


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

Branch: refs/heads/ftpfix
Commit: 91f6eb36fc539f07b06148fa6a7291c7e52721b3
Parents: f5e9397
Author: Andrea Cosentino <anco...@gmail.com>
Authored: Wed Sep 7 13:11:00 2016 +0200
Committer: Andrea Cosentino <anco...@gmail.com>
Committed: Wed Sep 7 13:12:14 2016 +0200

----------------------------------------------------------------------
 .../component/file/remote/FtpOperations.java    |  4 +-
 .../src/test/data/ftptextfile/textexample.txt   |  3 +
 .../file/remote/FtpConsumerFileSplitTest.java   | 72 ++++++++++++++++++++
 3 files changed, 76 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/91f6eb36/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpOperations.java
----------------------------------------------------------------------
diff --git 
a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpOperations.java
 
b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpOperations.java
index db58a9c..f2447ff 100644
--- 
a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpOperations.java
+++ 
b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpOperations.java
@@ -370,9 +370,7 @@ public class FtpOperations implements 
RemoteFileOperations<FTPFile> {
                 // close the stream after done
                 IOHelper.close(bos);
 
-                // and then set the body as an input stream so we can read the 
content easily
-                InputStream is = new ByteArrayInputStream(bos.toByteArray());
-                target.setBody(is);
+                target.setBody(bos.toByteArray());
             }
 
             // store client reply information after the operation

http://git-wip-us.apache.org/repos/asf/camel/blob/91f6eb36/components/camel-ftp/src/test/data/ftptextfile/textexample.txt
----------------------------------------------------------------------
diff --git a/components/camel-ftp/src/test/data/ftptextfile/textexample.txt 
b/components/camel-ftp/src/test/data/ftptextfile/textexample.txt
new file mode 100644
index 0000000..83db48f
--- /dev/null
+++ b/components/camel-ftp/src/test/data/ftptextfile/textexample.txt
@@ -0,0 +1,3 @@
+line1
+line2
+line3

http://git-wip-us.apache.org/repos/asf/camel/blob/91f6eb36/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerFileSplitTest.java
----------------------------------------------------------------------
diff --git 
a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerFileSplitTest.java
 
b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerFileSplitTest.java
new file mode 100644
index 0000000..3f2bf76
--- /dev/null
+++ 
b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerFileSplitTest.java
@@ -0,0 +1,72 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.file.remote;
+
+import java.io.File;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @version 
+ */
+public class FtpConsumerFileSplitTest extends FtpServerTestSupport {
+
+    private String getFtpUrl() {
+        return "ftp://admin@localhost:"; + getPort() + 
"/incoming/?password=admin"
+                + "&recursive=false";
+    }
+
+    @Override
+    @Before
+    public void setUp() throws Exception {
+        super.setUp();
+        prepareFtpServer();
+    }
+
+    @Test
+    public void testFtpRoute() throws Exception {
+        MockEndpoint resultEndpoint = getMockEndpoint("mock:result");
+        resultEndpoint.expectedMessageCount(3);
+        resultEndpoint.expectedBodiesReceived("line1","line2");
+        resultEndpoint.assertIsSatisfied();
+
+        // assert the file
+        File file = new File("target/ftptest/textexample.txt");
+        assertTrue("The text file should exists", file.exists());
+    }
+
+    private void prepareFtpServer() throws Exception {
+        // prepares the FTP Server by creating a file on the server that we 
want to unit
+        // test that we can pool and store as a local file
+        template.sendBodyAndHeader(getFtpUrl(), new 
File("src/test/data/ftptextfile/textexample.txt"), Exchange.FILE_NAME, 
"textexample.txt");
+    }
+    
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            public void configure() throws Exception {
+                from(getFtpUrl())
+                .log("${body}")
+                .split(body().tokenize("\n"))
+                .to("mock:result");
+            }
+        };
+    }
+}
\ No newline at end of file

Reply via email to