Added: activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpRemoteFileSortByNestedExpressionTest.java URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpRemoteFileSortByNestedExpressionTest.java?rev=729480&view=auto ============================================================================== --- activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpRemoteFileSortByNestedExpressionTest.java (added) +++ activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpRemoteFileSortByNestedExpressionTest.java Fri Dec 26 02:53:10 2008 @@ -0,0 +1,87 @@ +/** + * 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 org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.file.FileComponent; +import org.apache.camel.component.mock.MockEndpoint; + +/** + * Unit test to verify remotefile sortby option. + */ +public class FromFtpRemoteFileSortByNestedExpressionTest extends FtpServerTestSupport { + + private int port = 20092; + + private String ftpUrl = "ftp://ad...@localhost:" + port + "/sortbynested?password=admin&consumer.delay=5000"; + + public int getPort() { + return port; + } + + @Override + protected void setUp() throws Exception { + super.setUp(); + prepareFtpServer(); + } + + @Override + public boolean isUseRouteBuilder() { + return false; + } + + public void testSortFiles() throws Exception { + context.addRoutes(new RouteBuilder() { + @Override + public void configure() throws Exception { + from(ftpUrl + "&sortBy=file:name.ext;file:name").to("mock:result"); + } + }); + context.start(); + + MockEndpoint mock = getMockEndpoint("mock:result"); + mock.expectedBodiesReceived("Hello Dublin", "Hello London", "Hello Paris", "Hello Copenhagen"); + + assertMockEndpointsSatisfied(); + } + + public void testSortFilesReverse() throws Exception { + context.addRoutes(new RouteBuilder() { + @Override + public void configure() throws Exception { + from(ftpUrl + "&sortBy=file:name.ext;reverse:file:name").to("mock:reverse"); + } + }); + context.start(); + + MockEndpoint reverse = getMockEndpoint("mock:reverse"); + reverse.expectedBodiesReceived("Hello Paris", "Hello London", "Hello Dublin", "Hello Copenhagen"); + + assertMockEndpointsSatisfied(); + } + + private void prepareFtpServer() throws Exception { + // prepares the FTP Server by creating files on the server that we want to unit + // test that we can pool + String ftpUrl = "ftp://ad...@localhost:" + port + "/sortbynested/?password=admin"; + template.sendBodyAndHeader(ftpUrl, "Hello Paris", FileComponent.HEADER_FILE_NAME, "paris.txt"); + template.sendBodyAndHeader(ftpUrl, "Hello London", FileComponent.HEADER_FILE_NAME, "london.txt"); + template.sendBodyAndHeader(ftpUrl, "Hello Copenhagen", FileComponent.HEADER_FILE_NAME, "copenhagen.xml"); + template.sendBodyAndHeader(ftpUrl, "Hello Dublin", FileComponent.HEADER_FILE_NAME, "dublin.txt"); + } + +} \ No newline at end of file
Added: activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpRemoteFileSorterTest.java URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpRemoteFileSorterTest.java?rev=729480&view=auto ============================================================================== --- activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpRemoteFileSorterTest.java (added) +++ activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpRemoteFileSorterTest.java Fri Dec 26 02:53:10 2008 @@ -0,0 +1,86 @@ +/** + * 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.util.Comparator; + +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.file.FileComponent; +import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.impl.JndiRegistry; + +/** + * Unit test to verify remotefile sorter option. + */ +public class FromFtpRemoteFileSorterTest extends FtpServerTestSupport { + + private int port = 20095; + + private String ftpUrl = "ftp://ad...@localhost:" + port + "/sorter?password=admin&sorter=#mySorter"; + + @Override + protected JndiRegistry createRegistry() throws Exception { + JndiRegistry jndi = super.createRegistry(); + jndi.bind("mySorter", new MyRemoteFileSorter()); + return jndi; + } + + public void testFtpSorter() throws Exception { + MockEndpoint mock = getMockEndpoint("mock:result"); + mock.expectedMessageCount(3); + mock.expectedBodiesReceived("Hello Copenhagen", "Hello London", "Hello Paris"); + mock.assertIsSatisfied(); + } + + public int getPort() { + return port; + } + + @Override + protected void setUp() throws Exception { + super.setUp(); + prepareFtpServer(); + } + + private void prepareFtpServer() throws Exception { + // prepares the FTP Server by creating files on the server that we want to unit + // test that we can pool + String ftpUrl = "ftp://ad...@localhost:" + port + "/sorter/?password=admin"; + template.sendBodyAndHeader(ftpUrl, "Hello Paris", FileComponent.HEADER_FILE_NAME, "paris.txt"); + template.sendBodyAndHeader(ftpUrl, "Hello London", FileComponent.HEADER_FILE_NAME, "london.txt"); + template.sendBodyAndHeader(ftpUrl, "Hello Copenhagen", FileComponent.HEADER_FILE_NAME, "copenhagen.txt"); + } + + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + public void configure() throws Exception { + from(ftpUrl).to("mock:result"); + } + }; + } + + // START SNIPPET: e1 + public class MyRemoteFileSorter implements Comparator<RemoteFile> { + + public int compare(RemoteFile o1, RemoteFile o2) { + return o1.getFileName().compareTo(o2.getFileName()); + } + } + // END SNIPPET: e1 + + +} \ No newline at end of file Modified: activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpSetNamesWithMultiDirectoriesTest.java URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpSetNamesWithMultiDirectoriesTest.java?rev=729480&r1=729479&r2=729480&view=diff ============================================================================== --- activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpSetNamesWithMultiDirectoriesTest.java (original) +++ activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpSetNamesWithMultiDirectoriesTest.java Fri Dec 26 02:53:10 2008 @@ -36,7 +36,7 @@ // must user "consumer." prefix on the parameters to the file component private String ftpUrl = "ftp://ad...@localhost:" + port + "/incoming?password=admin&binary=true" - + "&consumer.delay=2000&consumer.recursive=true&consumer.setNames=true"; + + "&consumer.delay=2000&recursive=true&setNames=true"; public void testFtpRoute() throws Exception { MockEndpoint resultEndpoint = getMockEndpoint("mock:result"); Modified: activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpToBinaryFileTest.java URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpToBinaryFileTest.java?rev=729480&r1=729479&r2=729480&view=diff ============================================================================== --- activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpToBinaryFileTest.java (original) +++ activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpToBinaryFileTest.java Fri Dec 26 02:53:10 2008 @@ -34,7 +34,7 @@ private int port = 20014; // must user "consumer." prefix on the parameters to the file component private String ftpUrl = "ftp://ad...@localhost:" + port + "/tmp4/camel?password=admin&binary=true" - + "&consumer.delay=2000&consumer.recursive=false"; + + "&consumer.delay=5000&recursive=false"; public void testFtpRoute() throws Exception { MockEndpoint resultEndpoint = getMockEndpoint("mock:result"); @@ -45,7 +45,7 @@ assertTrue("Logo size wrong", bytes.length > 10000); // wait until the file producer has written the file - Thread.sleep(1000); + Thread.sleep(2 * 1000); // assert the file File file = new File("target/ftptest/deleteme.jpg"); @@ -63,6 +63,7 @@ @Override protected void setUp() throws Exception { super.setUp(); + deleteDirectory("./res/home"); prepareFtpServer(); } @@ -82,7 +83,7 @@ protected RouteBuilder createRouteBuilder() throws Exception { return new RouteBuilder() { public void configure() throws Exception { - String fileUrl = "file:target/ftptest/?noop=true"; + String fileUrl = "file:target/ftptest/?noop=true&append=false"; from(ftpUrl).setHeader(FileComponent.HEADER_FILE_NAME, constant("deleteme.jpg")) .to(fileUrl, "mock:result"); } Modified: activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpToBinaryFilesTest.java URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpToBinaryFilesTest.java?rev=729480&r1=729479&r2=729480&view=diff ============================================================================== --- activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpToBinaryFilesTest.java (original) +++ activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpToBinaryFilesTest.java Fri Dec 26 02:53:10 2008 @@ -34,7 +34,7 @@ private int port = 20015; // must user "consumer." prefix on the parameters to the file component private String ftpUrl = "ftp://ad...@localhost:" + port + "/incoming?password=admin&binary=true" - + "&consumer.delay=2000&consumer.recursive=true"; + + "&consumer.delay=2000&recursive=true"; public void testFtpRoute() throws Exception { MockEndpoint resultEndpoint = getMockEndpoint("mock:result"); @@ -45,20 +45,17 @@ assertTrue("Logo size wrong", bytes.length > 10000); // wait until the file producer has written the file - Thread.sleep(1000); + Thread.sleep(2000); // assert the file - File file = new File("target/ftptest/a/logo1.jpeg"); - assertTrue("The binary file should exists", file.exists()); + File file = new File("target/ftptest/logo.jpeg"); + assertTrue(" The binary file should exists", file.exists()); assertTrue("Logo size wrong", file.length() > 10000); // assert the file - file = new File("target/ftptest/logo.jpeg"); - assertTrue(" The binary file should exists", file.exists()); + file = new File("target/ftptest/a/logo1.jpeg"); + assertTrue("The binary file should exists", file.exists()); assertTrue("Logo size wrong", file.length() > 10000); - - // let some time pass to let the consumer etc. properly do its business before closing - Thread.sleep(1000); } public int getPort() { @@ -75,7 +72,7 @@ // 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 String ftpUrl = "ftp://ad...@localhost:" + port + "/incoming?password=admin&binary=true" - + "&consumer.delay=2000&consumer.recursive=false&consumer.append=false"; + + "&consumer.delay=2000&recursive=false"; Endpoint endpoint = context.getEndpoint(ftpUrl); Exchange exchange = endpoint.createExchange(); exchange.getIn().setBody(IOConverter.toFile("src/test/data/ftpbinarytest/logo.jpeg")); @@ -84,8 +81,9 @@ producer.start(); producer.process(exchange); producer.stop(); + ftpUrl = "ftp://ad...@localhost:" + port + "/incoming/a?password=admin&binary=true" - + "&consumer.delay=2000&consumer.recursive=false&consumer.append=false"; + + "&consumer.delay=2000&recursive=false"; endpoint = context.getEndpoint(ftpUrl); exchange = endpoint.createExchange(); exchange.getIn().setBody(IOConverter.toFile("src/test/data/ftpbinarytest/logo1.jpeg")); Modified: activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpToMockTest.java URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpToMockTest.java?rev=729480&r1=729479&r2=729480&view=diff ============================================================================== --- activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpToMockTest.java (original) +++ activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpToMockTest.java Fri Dec 26 02:53:10 2008 @@ -26,25 +26,15 @@ protected MockEndpoint resultEndpoint; protected String expectedBody = "Hello there!"; protected int port = 2001; - protected String ftpUrl = "ftp://ad...@localhost:" + port + "/tmp/camel?password=admin&consumer.recursive=true"; + protected String ftpUrl = "ftp://ad...@localhost:" + port + "/tmp/camel?password=admin&recursive=true"; public void testFtpRoute() throws Exception { MockEndpoint resultEndpoint = getMockEndpoint("mock:result"); resultEndpoint.expectedBodiesReceived(expectedBody); - // TODO when we support multiple marshallers for messages - // we can support passing headers over files using serialized/XML files - //resultEndpoint.message(0).header("cheese").isEqualTo(123); - template.sendBodyAndHeader(ftpUrl, expectedBody, "cheese", 123); - // let some time pass to let the consumer etc. properly do its business before closing - Thread.sleep(1000); resultEndpoint.assertIsSatisfied(); - - Thread.sleep(1000); - - } protected RouteBuilder createRouteBuilder() throws Exception { Modified: activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromQueueThenConsumeFtpToMockTest.java URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromQueueThenConsumeFtpToMockTest.java?rev=729480&r1=729479&r2=729480&view=diff ============================================================================== --- activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromQueueThenConsumeFtpToMockTest.java (original) +++ activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromQueueThenConsumeFtpToMockTest.java Fri Dec 26 02:53:10 2008 @@ -16,12 +16,9 @@ */ package org.apache.camel.component.file.remote; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; - -import org.apache.camel.Consumer; import org.apache.camel.Endpoint; import org.apache.camel.Exchange; +import org.apache.camel.PollingConsumer; import org.apache.camel.Processor; import org.apache.camel.Producer; import org.apache.camel.builder.RouteBuilder; @@ -92,24 +89,18 @@ // create a ftp endpoint Endpoint ftp = context.getEndpoint(url); - // use this latch to wait for completion of the consumer - final CountDownLatch latch = new CountDownLatch(1); + // create a polling consumer where we can poll the myfile from the ftp server + PollingConsumer consumer = ftp.createPollingConsumer(); - // create a consumer and process the result using the processor - Consumer consumer = ftp.createConsumer(new Processor() { - public void process(Exchange result) throws Exception { - // the result is the response from the FTP consumer (the downloaded file) - // replace the outher exchange with the content from the downloaded file - exchange.getIn().setBody(result.getIn().getBody()); - // signal we are complete - latch.countDown(); - } - }); - // start the consumer + // must start the consumer before we can receive consumer.start(); - // wait for the completion or timeout after 30 seconds - latch.await(30, TimeUnit.SECONDS); + // poll the file from the ftp server + Exchange result = consumer.receive(); + + // the result is the response from the FTP consumer (the downloaded file) + // replace the outher exchange with the content from the downloaded file + exchange.getIn().setBody(result.getIn().getBody()); // stop the consumer consumer.stop(); Copied: activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerBodyAsStringTest.java (from r727937, activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFileToFtpTest.java) URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerBodyAsStringTest.java?p2=activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerBodyAsStringTest.java&p1=activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFileToFtpTest.java&r1=727937&r2=729480&rev=729480&view=diff ============================================================================== --- activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFileToFtpTest.java (original) +++ activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerBodyAsStringTest.java Fri Dec 26 02:53:10 2008 @@ -16,38 +16,65 @@ */ package org.apache.camel.component.file.remote; +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.RouteBuilder; +import org.apache.camel.component.file.FileComponent; import org.apache.camel.component.mock.MockEndpoint; /** * @version $Revision$ */ -public class FromFileToFtpTest extends FtpServerTestSupport { +public class FtpConsumerBodyAsStringTest extends FtpServerTestSupport { - private int port = 20011; - private String ftpUrl = "ftp://ad...@localhost:" + port + "/tmp2/camel?password=admin"; + private int port = 20012; + private String ftpUrl = "ftp://ad...@localhost:" + port + "/tmp4/camel?password=admin&consumer.delay=5000"; - public void testFromFileToFtp() throws Exception { - MockEndpoint resultEndpoint = getMockEndpoint("mock:result"); - resultEndpoint.expectedMinimumMessageCount(1); - resultEndpoint.assertIsSatisfied(); + public int getPort() { + return port; + } - // let some time pass to let the consumer etc. properly do its business before closing - Thread.sleep(1000); + @Override + protected void setUp() throws Exception { + super.setUp(); + prepareFtpServer(); } - public int getPort() { - return port; + 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 + Endpoint endpoint = context.getEndpoint(ftpUrl); + Exchange exchange = endpoint.createExchange(); + exchange.getIn().setBody("Hello World"); + exchange.getIn().setHeader(FileComponent.HEADER_FILE_NAME, "hello.txt"); + Producer producer = endpoint.createProducer(); + producer.start(); + producer.process(exchange); + producer.stop(); + } + + public void testSingleFileTest() throws Exception { + MockEndpoint mock = getMockEndpoint("mock:result"); + mock.expectedBodiesReceived("Hello World"); + mock.expectedMessageCount(1); + + assertMockEndpointsSatisfied(); } protected RouteBuilder createRouteBuilder() throws Exception { return new RouteBuilder() { public void configure() throws Exception { - from("file:src/main/data?noop=true").to(ftpUrl); - - from(ftpUrl).to("mock:result"); + from(ftpUrl).process(new Processor() { + public void process(Exchange exchange) throws Exception { + String body = exchange.getIn().getBody(String.class); + assertNotNull(body); + assertEquals("Hello World", body); + } + }).to("mock:result"); } }; } -} +} \ No newline at end of file Propchange: activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerBodyAsStringTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerBodyAsStringTest.java ------------------------------------------------------------------------------ svn:keywords = Rev Date Propchange: activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerBodyAsStringTest.java ------------------------------------------------------------------------------ svn:mergeinfo = Modified: activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerDeleteNoWritePermissionTest.java URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerDeleteNoWritePermissionTest.java?rev=729480&r1=729479&r2=729480&view=diff ============================================================================== --- activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerDeleteNoWritePermissionTest.java (original) +++ activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerDeleteNoWritePermissionTest.java Fri Dec 26 02:53:10 2008 @@ -28,17 +28,19 @@ private int port = 20087; private String ftpUrl = "ftp://du...@localhost:" + port + "/deletenoperm?password=foo" - + "&consumer.deleteFile=true"; + + "&delete=true&consumer.delay=5000"; public void testExludePreAndPostfixes() throws Exception { PollingConsumer consumer = context.getEndpoint(ftpUrl).createPollingConsumer(); consumer.start(); Exchange out = consumer.receive(3000); - assertNull("Should not get the file", out); + assertNotNull("Should get the file", out); try { + // give consumer time to try to delete the file + Thread.sleep(1000); consumer.stop(); - } catch (FtpOperationFailedException fofe) { + } catch (RemoteFileOperationFailedException fofe) { // expected, ignore } } Modified: activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerDirectoriesNotMatchedTest.java URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerDirectoriesNotMatchedTest.java?rev=729480&r1=729479&r2=729480&view=diff ============================================================================== --- activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerDirectoriesNotMatchedTest.java (original) +++ activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerDirectoriesNotMatchedTest.java Fri Dec 26 02:53:10 2008 @@ -28,7 +28,7 @@ private int port = 20055; private String ftpUrl = "ftp://ad...@localhost:" + port + "/dirnotmatched/?password=admin" - + "&consumer.recursive=true&consumer.regexPattern=.*txt$"; + + "&recursive=true®exPattern=.*txt$"; public void testSkipDirectories() throws Exception { MockEndpoint mock = getMockEndpoint("mock:result"); Modified: activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerExcludeNameTest.java URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerExcludeNameTest.java?rev=729480&r1=729479&r2=729480&view=diff ============================================================================== --- activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerExcludeNameTest.java (original) +++ activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerExcludeNameTest.java Fri Dec 26 02:53:10 2008 @@ -28,7 +28,7 @@ private int port = 20095; private String ftpUrl = "ftp://ad...@localhost:" + port + "/excludename?password=admin" - + "&consumer.excludedNamePrefix=secret&consumer.excludedNamePostfix=xml"; + + "&excludedNamePrefix=secret&excludedNamePostfix=xml"; public void testExludePreAndPostfixes() throws Exception { MockEndpoint mock = getMockEndpoint("mock:result"); Modified: activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerExpressionTest.java URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerExpressionTest.java?rev=729480&r1=729479&r2=729480&view=diff ============================================================================== --- activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerExpressionTest.java (original) +++ activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerExpressionTest.java Fri Dec 26 02:53:10 2008 @@ -32,7 +32,7 @@ private int port = 20063; - private String ftpUrl = "ftp://ad...@localhost:" + port + "/filelanguage?password=admin"; + private String ftpUrl = "ftp://ad...@localhost:" + port + "/filelanguage?password=admin&consumer.delay=5000"; public int getPort() { return port; Added: activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerMultipleDirectoriesTest.java URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerMultipleDirectoriesTest.java?rev=729480&view=auto ============================================================================== --- activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerMultipleDirectoriesTest.java (added) +++ activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerMultipleDirectoriesTest.java Fri Dec 26 02:53:10 2008 @@ -0,0 +1,81 @@ +/** + * 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 org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.file.FileComponent; +import org.apache.camel.component.mock.MockEndpoint; + +/** + * @version $Revision$ + */ +public class FtpConsumerMultipleDirectoriesTest extends FtpServerTestSupport { + + private int port = 20044; + private String ftpUrl = "ftp://ad...@localhost:" + port + "/multidir/?password=admin&recursive=true&consumer.delay=5000&sortBy=file:path"; + + public int getPort() { + return port; + } + + @Override + protected void setUp() throws Exception { + super.setUp(); + deleteDirectory("./res/home/multidir"); + prepareFtpServer(); + } + + private void prepareFtpServer() throws Exception { + template.sendBodyAndHeader(ftpUrl, "Bye World", FileComponent.HEADER_FILE_NAME, "bye.txt"); + template.sendBodyAndHeader(ftpUrl, "Hello World", FileComponent.HEADER_FILE_NAME, "sub/hello.txt"); + template.sendBodyAndHeader(ftpUrl, "Godday World", FileComponent.HEADER_FILE_NAME, "sub/sub2/godday.txt"); + } + + public void testMultiDir() throws Exception { + MockEndpoint mock = getMockEndpoint("mock:result"); + mock.expectedBodiesReceived("Bye World", "Hello World", "Godday World"); + + assertMockEndpointsSatisfied(); + + RemoteFileExchange exchange = (RemoteFileExchange) mock.getExchanges().get(0); + RemoteFile file = exchange.getRemoteFile(); + assertEquals("multidir/bye.txt", file.getAbsolutelFileName()); + assertEquals("bye.txt", file.getRelativeFileName()); + assertEquals("bye.txt", file.getFileName()); + + exchange = (RemoteFileExchange) mock.getExchanges().get(1); + file = exchange.getRemoteFile(); + assertEquals("multidir/sub/hello.txt", file.getAbsolutelFileName()); + assertEquals("sub/hello.txt", file.getRelativeFileName()); + assertEquals("hello.txt", file.getFileName()); + + exchange = (RemoteFileExchange) mock.getExchanges().get(2); + file = exchange.getRemoteFile(); + assertEquals("multidir/sub/sub2/godday.txt", file.getAbsolutelFileName()); + assertEquals("sub/sub2/godday.txt", file.getRelativeFileName()); + assertEquals("godday.txt", file.getFileName()); + } + + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + public void configure() throws Exception { + from(ftpUrl).to("mock:result"); + } + }; + } + +} \ No newline at end of file Modified: activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerUsingFTPClientConfigTest.java URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerUsingFTPClientConfigTest.java?rev=729480&r1=729479&r2=729480&view=diff ============================================================================== --- activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerUsingFTPClientConfigTest.java (original) +++ activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerUsingFTPClientConfigTest.java Fri Dec 26 02:53:10 2008 @@ -29,7 +29,7 @@ private int port = 20066; - private String ftpUrl = "ftp://ad...@localhost:" + port + "/clientconfig?password=admin&ftpClientConfig=myConfig"; + private String ftpUrl = "ftp://ad...@localhost:" + port + "/clientconfig?password=admin&ftpClientConfig=#myConfig"; @Override protected JndiRegistry createRegistry() throws Exception { Added: activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpIllegalOptionsTest.java URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpIllegalOptionsTest.java?rev=729480&view=auto ============================================================================== --- activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpIllegalOptionsTest.java (added) +++ activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpIllegalOptionsTest.java Fri Dec 26 02:53:10 2008 @@ -0,0 +1,56 @@ +/** + * 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 org.apache.camel.ContextTestSupport; +import org.apache.camel.Exchange; +import org.apache.camel.Processor; + +public class FtpIllegalOptionsTest extends ContextTestSupport { + + public void testIllegalOptions() throws Exception { + try { + context.getEndpoint("ftp://target?expression=../done/${file:name}&delete=true").createConsumer(new Processor() { + public void process(Exchange exchange) throws Exception { + } + }); + fail("Should have thrown an exception"); + } catch (IllegalArgumentException e) { + // ok + } + + try { + context.getEndpoint("file://target?moveNamePrefix=../done/&delete=true").createConsumer(new Processor() { + public void process(Exchange exchange) throws Exception { + } + }); + fail("Should have thrown an exception"); + } catch (IllegalArgumentException e) { + // ok + } + + try { + context.getEndpoint("file://target?moveNamePostfix=.bak&delete=true").createConsumer(new Processor() { + public void process(Exchange exchange) throws Exception { + } + }); + fail("Should have thrown an exception"); + } catch (IllegalArgumentException e) { + // ok + } + } +} Modified: activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpLoginTest.java URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpLoginTest.java?rev=729480&r1=729479&r2=729480&view=diff ============================================================================== --- activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpLoginTest.java (original) +++ activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpLoginTest.java Fri Dec 26 02:53:10 2008 @@ -43,8 +43,8 @@ public void testBadLogin() throws Exception { try { uploadFile("dummy", "cantremeber"); - fail("Should have thrown a FtpOperationFailedException"); - } catch (FtpOperationFailedException e) { + fail("Should have thrown a RemoteFileOperationFailedException"); + } catch (RemoteFileOperationFailedException e) { // expected assertEquals(530, e.getCode()); } @@ -68,6 +68,8 @@ } private void uploadFile(String username, String password) throws Exception { + RemoteFileComponent component = new RemoteFileComponent(context); + RemoteFileConfiguration config = new RemoteFileConfiguration(); config.setBinary(false); config.setUsername(username); @@ -78,11 +80,9 @@ config.setProtocol("ftp"); config.setFile("login"); - RemoteFileComponent component = new RemoteFileComponent(context); - component.setConfiguration(config); + FtpRemoteFileOperations remoteFileOperations = new FtpRemoteFileOperations(); + RemoteFileEndpoint endpoint = new RemoteFileEndpoint(ftpUrl, component, remoteFileOperations, config); - RemoteFileEndpoint endpoint = new FtpEndpoint(ftpUrl, component, config); - Exchange exchange = endpoint.createExchange(); exchange.getIn().setBody("Hello World from FTPServer"); exchange.getIn().setHeader(FileComponent.HEADER_FILE_NAME, "report.txt"); Modified: activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpProducerBuildDirectoryTest.java URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpProducerBuildDirectoryTest.java?rev=729480&r1=729479&r2=729480&view=diff ============================================================================== --- activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpProducerBuildDirectoryTest.java (original) +++ activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpProducerBuildDirectoryTest.java Fri Dec 26 02:53:10 2008 @@ -22,7 +22,7 @@ import org.apache.camel.converter.IOConverter; /** - * Unit test to verify that Camel can build remote directory on FTP server if missing (full or part of). + * Unit test to verify that Camel can builde remote directory on FTP server if missing (full or part of). */ public class FtpProducerBuildDirectoryTest extends FtpServerTestSupport { Modified: activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpProducerTempPrefixTest.java URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpProducerTempPrefixTest.java?rev=729480&r1=729479&r2=729480&view=diff ============================================================================== --- activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpProducerTempPrefixTest.java (original) +++ activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpProducerTempPrefixTest.java Fri Dec 26 02:53:10 2008 @@ -36,7 +36,7 @@ public void testCreateTempFileName() throws Exception { Endpoint endpoint = context.getEndpoint(ftpUrl); - FtpProducer producer = (FtpProducer) endpoint.createProducer(); + RemoteFileProducer producer = (RemoteFileProducer) endpoint.createProducer(); String fileName = "somepath/someuser/claus.txt"; String tempFileName = producer.createTempFileName(fileName); @@ -45,7 +45,7 @@ public void testNoPathCreateTempFileName() throws Exception { Endpoint endpoint = context.getEndpoint(ftpUrl); - FtpProducer producer = (FtpProducer) endpoint.createProducer(); + RemoteFileProducer producer = (RemoteFileProducer) endpoint.createProducer(); String fileName = "claus.txt"; String tempFileName = producer.createTempFileName(fileName); Modified: activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpServerTestSupport.java URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpServerTestSupport.java?rev=729480&r1=729479&r2=729480&view=diff ============================================================================== --- activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpServerTestSupport.java (original) +++ activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpServerTestSupport.java Fri Dec 26 02:53:10 2008 @@ -34,17 +34,13 @@ protected void setUp() throws Exception { super.setUp(); initFtpServer(); - if (ftpServer.isStopped()) { - ftpServer.start(); - } + ftpServer.start(); } protected void tearDown() throws Exception { super.tearDown(); - if (!ftpServer.isStopped()) { - ftpServer.getServerContext().dispose(); - ftpServer.stop(); - } + ftpServer.stop(); + ftpServer = null; } protected void initFtpServer() throws Exception { Modified: activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/UriConfigurationTest.java URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/UriConfigurationTest.java?rev=729480&r1=729479&r2=729480&view=diff ============================================================================== --- activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/UriConfigurationTest.java (original) +++ activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/UriConfigurationTest.java Fri Dec 26 02:53:10 2008 @@ -30,10 +30,10 @@ public void testFtpConfigurationDefaults() { Endpoint endpoint = context.getEndpoint("ftp://hostname"); - assertTrue("Endpoint not an FtpEndpoint: " + endpoint, endpoint instanceof FtpEndpoint); - FtpEndpoint ftpEndpoint = (FtpEndpoint) endpoint; + assertIsInstanceOf(RemoteFileEndpoint.class, endpoint); + RemoteFileEndpoint ftpEndpoint = (RemoteFileEndpoint) endpoint; RemoteFileConfiguration config = ftpEndpoint.getConfiguration(); - + assertEquals("ftp", config.getProtocol()); assertEquals("hostname", config.getHost()); assertEquals(21, config.getPort()); @@ -45,10 +45,10 @@ public void testSftpConfigurationDefaults() { Endpoint endpoint = context.getEndpoint("sftp://hostname"); - assertTrue("Endpoint not an SftpEndpoint: " + endpoint, endpoint instanceof SftpEndpoint); - SftpEndpoint sftpEndpoint = (SftpEndpoint) endpoint; + assertIsInstanceOf(RemoteFileEndpoint.class, endpoint); + RemoteFileEndpoint sftpEndpoint = (RemoteFileEndpoint) endpoint; RemoteFileConfiguration config = sftpEndpoint.getConfiguration(); - + assertEquals("sftp", config.getProtocol()); assertEquals("hostname", config.getHost()); assertEquals(22, config.getPort()); @@ -60,10 +60,10 @@ public void testFtpExplicitConfiguration() { Endpoint endpoint = context.getEndpoint("ftp://u...@hostname:1021/some/file?password=secret&binary=true&directory=false"); - assertTrue("Endpoint not an FtpEndpoint: " + endpoint, endpoint instanceof FtpEndpoint); - FtpEndpoint ftpEndpoint = (FtpEndpoint) endpoint; + assertIsInstanceOf(RemoteFileEndpoint.class, endpoint); + RemoteFileEndpoint ftpEndpoint = (RemoteFileEndpoint) endpoint; RemoteFileConfiguration config = ftpEndpoint.getConfiguration(); - + assertEquals("ftp", config.getProtocol()); assertEquals("hostname", config.getHost()); assertEquals(1021, config.getPort()); @@ -75,10 +75,10 @@ public void testSftpExplicitConfiguration() { Endpoint endpoint = context.getEndpoint("sftp://u...@hostname:1021/some/file?password=secret&binary=true&directory=false"); - assertTrue("Endpoint not an SftpEndpoint: " + endpoint, endpoint instanceof SftpEndpoint); - SftpEndpoint sftpEndpoint = (SftpEndpoint) endpoint; + assertIsInstanceOf(RemoteFileEndpoint.class, endpoint); + RemoteFileEndpoint sftpEndpoint = (RemoteFileEndpoint) endpoint; RemoteFileConfiguration config = sftpEndpoint.getConfiguration(); - + assertEquals("sftp", config.getProtocol()); assertEquals("hostname", config.getHost()); assertEquals(1021, config.getPort()); @@ -107,12 +107,12 @@ assertEquals("For uri: " + endpointUri + " the file is not equal", expectedFile, file); } - public void testSftpKnownHostsConfiguration() { - Endpoint endpoint = context.getEndpoint("sftp://u...@hostname:1021/some/file?password=secret&binary=true&directory=false&knownHosts=/home/janstey/.ssh/known_hosts"); - assertTrue("Endpoint not an SftpEndpoint: " + endpoint, endpoint instanceof SftpEndpoint); - SftpEndpoint sftpEndpoint = (SftpEndpoint) endpoint; + public void testSftpKnownHostsFileConfiguration() { + Endpoint endpoint = context.getEndpoint("sftp://u...@hostname:1021/some/file?password=secret&binary=true&directory=false&knownHostsFile=/home/janstey/.ssh/known_hosts"); + assertIsInstanceOf(RemoteFileEndpoint.class, endpoint); + RemoteFileEndpoint sftpEndpoint = (RemoteFileEndpoint) endpoint; RemoteFileConfiguration config = sftpEndpoint.getConfiguration(); - + assertEquals("sftp", config.getProtocol()); assertEquals("hostname", config.getHost()); assertEquals(1021, config.getPort()); @@ -120,6 +120,6 @@ assertEquals("secret", config.getPassword()); assertEquals(true, config.isBinary()); assertEquals(false, config.isDirectory()); - assertEquals("/home/janstey/.ssh/known_hosts", config.getKnownHosts()); + assertEquals("/home/janstey/.ssh/known_hosts", config.getKnownHostsFile()); } } Modified: activemq/camel/trunk/components/camel-ftp/src/test/resources/log4j.properties URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-ftp/src/test/resources/log4j.properties?rev=729480&r1=729479&r2=729480&view=diff ============================================================================== --- activemq/camel/trunk/components/camel-ftp/src/test/resources/log4j.properties (original) +++ activemq/camel/trunk/components/camel-ftp/src/test/resources/log4j.properties Fri Dec 26 02:53:10 2008 @@ -22,9 +22,10 @@ # uncomment the following to enable camel debugging log4j.logger.org.apache.camel.component.file=TRACE +#log4j.logger.org.apache.camel=DEBUG log4j.logger.org.apache.mina=WARN log4j.logger.org.apache.ftpserver=WARN -log4j.logger.org.apache.commons.net=TRACE +#log4j.logger.org.apache.commons.net=TRACE # CONSOLE appender not used by default log4j.appender.out=org.apache.log4j.ConsoleAppender
