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 2008/09/19 20:53:02 UTC

svn commit: r697185 - in /activemq/camel/trunk: camel-core/src/main/java/org/apache/camel/component/file/ camel-core/src/test/java/org/apache/camel/component/file/ components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/

Author: davsclaus
Date: Fri Sep 19 11:53:02 2008
New Revision: 697185

URL: http://svn.apache.org/viewvc?rev=697185&view=rev
Log:
CAMEL-920: File and FTP consumer only performs file name matching on files and NOT directories

Added:
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerDirectoryNotMatchedTest.java   (contents, props changed)
      - copied, changed from r697142, activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerSkipDotFilesTest.java
    activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerDirectoriesNotMatchedTest.java   (contents, props changed)
      - copied, changed from r697142, activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerSkipDotFilesTest.java
Modified:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileConsumer.java

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileConsumer.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileConsumer.java?rev=697185&r1=697184&r2=697185&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileConsumer.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileConsumer.java Fri Sep 19 11:53:02 2008
@@ -332,6 +332,11 @@
             return false;
         }
 
+        // directories so far is always regarded as matched (matching on the name is only for files)
+        if (file.isDirectory()) {
+            return true;
+        }
+
         if (regexPattern != null && regexPattern.length() > 0) {
             if (!name.matches(regexPattern)) {
                 return false;

Copied: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerDirectoryNotMatchedTest.java (from r697142, activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerSkipDotFilesTest.java)
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerDirectoryNotMatchedTest.java?p2=activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerDirectoryNotMatchedTest.java&p1=activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerSkipDotFilesTest.java&r1=697142&r2=697185&rev=697185&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerSkipDotFilesTest.java (original)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerDirectoryNotMatchedTest.java Fri Sep 19 11:53:02 2008
@@ -21,39 +21,33 @@
 import org.apache.camel.component.mock.MockEndpoint;
 
 /**
- * Unit test that file consumer will skip any files starting with a dot
+ * Unit test that file consumer will not match directories (CAMEL-920)
  */
-public class FileConsumerSkipDotFilesTest extends ContextTestSupport {
+public class FileConsumerDirectoryNotMatchedTest extends ContextTestSupport {
 
-    private String fileUrl = "file://target/dotfiles/";
+    private String fileUrl = "file://target/dirnotmatched/?consumer.recursive=true&consumer.regexPattern=.*\\.txt$";
 
     @Override
     protected void setUp() throws Exception {
         super.setUp();
-        deleteDirectory("target/dotfiles");
-    }
-
-    public void testSkipDotFiles() throws Exception {
-        MockEndpoint mock = getMockEndpoint("mock:result");
-        mock.expectedMessageCount(0);
+        deleteDirectory("target/dirnotmatched");
 
-        template.sendBodyAndHeader("file:target/dotfiles/", "This is a dot file",
+        template.sendBodyAndHeader("file:target/dirnotmatched/", "This is a dot file",
             FileComponent.HEADER_FILE_NAME, ".skipme");
 
-        mock.setResultWaitTime(5000);
-        mock.assertIsSatisfied();
-    }
+        template.sendBodyAndHeader("file:target/dirnotmatched/", "This is a web file",
+            FileComponent.HEADER_FILE_NAME, "index.html");
 
-    public void testSkipDotFilesWithARegularFile() throws Exception {
-        MockEndpoint mock = getMockEndpoint("mock:result");
-        mock.expectedMessageCount(1);
-        mock.expectedBodiesReceived("Hello World");
+        template.sendBodyAndHeader("file:target/dirnotmatched/2007", "2007 report",
+            FileComponent.HEADER_FILE_NAME, "report2007.txt");
 
-        template.sendBodyAndHeader("file:target/dotfiles/", "This is a dot file",
-            FileComponent.HEADER_FILE_NAME, ".skipme");
+        template.sendBodyAndHeader("file:target/dirnotmatched/2008", "2008 report",
+            FileComponent.HEADER_FILE_NAME, "report2008.txt");
+    }
 
-        template.sendBodyAndHeader("file:target/dotfiles/", "Hello World",
-            FileComponent.HEADER_FILE_NAME, "hello.txt");
+    public void testSkipDirectories() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:result");
+        mock.expectedMessageCount(2);
 
         mock.assertIsSatisfied();
     }

Propchange: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerDirectoryNotMatchedTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerDirectoryNotMatchedTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerDirectoryNotMatchedTest.java
------------------------------------------------------------------------------
    svn:mergeinfo = 

Copied: activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerDirectoriesNotMatchedTest.java (from r697142, activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerSkipDotFilesTest.java)
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerDirectoriesNotMatchedTest.java?p2=activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerDirectoriesNotMatchedTest.java&p1=activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerSkipDotFilesTest.java&r1=697142&r2=697185&rev=697185&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerSkipDotFilesTest.java (original)
+++ activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerDirectoriesNotMatchedTest.java Fri Sep 19 11:53:02 2008
@@ -21,18 +21,18 @@
 import org.apache.camel.component.mock.MockEndpoint;
 
 /**
- * Unit test that ftp consumer will skip any files starting with a dot
+ * Unit test that ftp consumer will not match directories (CAMEL-920)
  */
-public class FtpConsumerSkipDotFilesTest extends FtpServerTestSupport {
+public class FtpConsumerDirectoriesNotMatchedTest extends FtpServerTestSupport {
 
-    private int port = 20096;
+    private int port = 20055;
 
-    private String ftpUrl = "ftp://admin@localhost:" + port + "/dotfiles?password=admin";
+    private String ftpUrl = "ftp://admin@localhost:" + port + "/dirnotmatched/?password=admin" +
+            "&consumer.recursive=true&consumer.regexPattern=.*txt$";
 
-    public void testSkipDotFiles() throws Exception {
+    public void testSkipDirectories() throws Exception {
         MockEndpoint mock = getMockEndpoint("mock:result");
-        mock.expectedMessageCount(2);
-        mock.expectedBodiesReceived("Reports", "Reports");
+        mock.expectedMessageCount(3);
         mock.assertIsSatisfied();
     }
 
@@ -49,11 +49,17 @@
     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 and store as a local file
-        String ftpUrl = "ftp://admin@localhost:" + port + "/dotfiles/?password=admin";
-        template.sendBodyAndHeader(ftpUrl, "Hello World", FileComponent.HEADER_FILE_NAME, ".skipme");
-        template.sendBodyAndHeader(ftpUrl, "Reports", FileComponent.HEADER_FILE_NAME, "report1.txt");
-        template.sendBodyAndHeader(ftpUrl, "Bye World", FileComponent.HEADER_FILE_NAME, ".camel");
-        template.sendBodyAndHeader(ftpUrl, "Reports", FileComponent.HEADER_FILE_NAME, "report2.txt");
+        String ftpUrl = "ftp://admin@localhost:" + port + "/dirnotmatched";
+        template.sendBodyAndHeader(ftpUrl + "/?password=admin", "This is a dot file",
+                FileComponent.HEADER_FILE_NAME, ".skipme");
+        template.sendBodyAndHeader(ftpUrl + "/?password=admin", "This is a web file",
+                FileComponent.HEADER_FILE_NAME, "index.html");
+        template.sendBodyAndHeader(ftpUrl + "/?password=admin", "This is a readme file",
+                FileComponent.HEADER_FILE_NAME, "readme.txt");
+        template.sendBodyAndHeader(ftpUrl + "/2007/?password=admin", "2007 report",
+                FileComponent.HEADER_FILE_NAME, "report2007.txt");
+        template.sendBodyAndHeader(ftpUrl + "/2008/?password=admin", "2008 report",
+                FileComponent.HEADER_FILE_NAME, "report2008.txt");
     }
 
     protected RouteBuilder createRouteBuilder() throws Exception {
@@ -64,4 +70,4 @@
         };
     }
 
-}
+}
\ No newline at end of file

Propchange: activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerDirectoriesNotMatchedTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerDirectoriesNotMatchedTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerDirectoriesNotMatchedTest.java
------------------------------------------------------------------------------
    svn:mergeinfo =