CAMEL-10297 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/c4bfbe4b Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/c4bfbe4b Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/c4bfbe4b Branch: refs/heads/master Commit: c4bfbe4b13acc16981546eff4a391fa23e44a530 Parents: e04d343 Author: Andrea Cosentino <anco...@gmail.com> Authored: Wed Sep 7 13:11:00 2016 +0200 Committer: Andrea Cosentino <anco...@gmail.com> Committed: Thu Sep 8 08:17:36 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/c4bfbe4b/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/c4bfbe4b/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/c4bfbe4b/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