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 2009/01/30 08:42:23 UTC

svn commit: r739198 - in /camel/trunk/camel-core/src: main/java/org/apache/camel/component/file/ main/java/org/apache/camel/component/file/strategy/ test/java/org/apache/camel/ test/java/org/apache/camel/component/file/

Author: davsclaus
Date: Fri Jan 30 07:42:22 2009
New Revision: 739198

URL: http://svn.apache.org/viewvc?rev=739198&view=rev
Log:
CAMEL-1241: Unit tests handling / or \ file paths

Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileEndpoint.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileLockExclusiveReadLockStrategy.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/TestSupport.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConfigureTest.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumeMultipleDirectoriesTest.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerBeginExpressionRenameStrategyTest.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerBeginRenameStrategyTest.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerCommitRenameStrategyTest.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerExpressionTest.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileProduceTempPrefixTest.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/NewFileConsumeTest.java

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileEndpoint.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileEndpoint.java?rev=739198&r1=739197&r2=739198&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileEndpoint.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileEndpoint.java Fri Jan 30 07:42:22 2009
@@ -50,16 +50,13 @@
     protected GenericFileOperations<T> operations;
     protected GenericFileConfiguration configuration;
 
-    // TODO: Consider remove setNames
-    // TODO: Consider filename should always be specified when producing (to get rid of auto generating with id as filename)
-    // TODO: bufferSize & append can be moved to NewFileEndpoint as FTP does not support it
-    // TODO: configuration.getfile/setfile is a bit cumbersome setting endpoint using spring bean (see FileConsumerExpressionTest)
-
     protected boolean directory = true;
     protected boolean autoCreate = true;
     protected int bufferSize = 128 * 1024;
     protected boolean append = true;
     protected boolean noop;
+    protected boolean recursive;
+    protected boolean delete;
     protected String tempPrefix;
     protected String moveNamePrefix;
     protected String moveNamePostfix;
@@ -67,10 +64,7 @@
     protected String preMoveNamePostfix;
     protected String excludedNamePrefix;
     protected String excludedNamePostfix;
-    protected boolean recursive;
     protected String regexPattern;
-    protected boolean setNames = true;
-    protected boolean delete;
     protected Expression expression;
     protected Expression preMoveExpression;
     protected boolean idempotent;
@@ -226,14 +220,6 @@
         this.regexPattern = regexPattern;
     }
 
-    public boolean isSetNames() {
-        return setNames;
-    }
-
-    public void setSetNames(boolean setNames) {
-        this.setNames = setNames;
-    }
-
     public boolean isDelete() {
         return delete;
     }

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileLockExclusiveReadLockStrategy.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileLockExclusiveReadLockStrategy.java?rev=739198&r1=739197&r2=739198&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileLockExclusiveReadLockStrategy.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileLockExclusiveReadLockStrategy.java Fri Jan 30 07:42:22 2009
@@ -37,8 +37,6 @@
     private static final transient Log LOG = LogFactory.getLog(FileLockExclusiveReadLockStrategy.class);
     private long timeout;
 
-    // TODO: We shall keep this with the GenericFileXX to support FileLock for java.io.File
-    
     public boolean acquireExclusiveReadLock(File file) {
         if (LOG.isTraceEnabled()) {
             LOG.trace("Waiting for exclusive read lock to file: " + file);

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/TestSupport.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/TestSupport.java?rev=739198&r1=739197&r2=739198&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/TestSupport.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/TestSupport.java Fri Jan 30 07:42:22 2009
@@ -30,7 +30,6 @@
 import org.apache.camel.util.ExchangeHelper;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.springframework.util.StringUtils;
 
 /**
  * A bunch of useful testing methods
@@ -367,7 +366,7 @@
      * To be used for folder/directory comparision that works across different platforms such
      * as Window, Mac and Linux.
      */
-    public static void assertDirectoryEquals(String expected, String actual) throws Exception {
+    public static void assertDirectoryEquals(String expected, String actual) {
         assertDirectoryEquals(null, expected, actual);
     }
 
@@ -375,10 +374,10 @@
      * To be used for folder/directory comparision that works across different platforms such
      * as Window, Mac and Linux.
      */
-    public static void assertDirectoryEquals(String message, String expected, String actual) throws Exception {
+    public static void assertDirectoryEquals(String message, String expected, String actual) {
         // must use single / as path seperators
-        String expectedPath = StringUtils.replace(expected, File.separator, "/");
-        String acutalPath = StringUtils.replace(actual, File.separator, "/");
+        String expectedPath = expected.replaceAll("\\\\", File.separator);
+        String acutalPath = actual.replaceAll("\\\\", File.separator);
 
         if (message != null) {
             assertEquals(message, expectedPath, acutalPath);

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConfigureTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConfigureTest.java?rev=739198&r1=739197&r2=739198&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConfigureTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConfigureTest.java Fri Jan 30 07:42:22 2009
@@ -32,11 +32,13 @@
 public class FileConfigureTest extends ContextTestSupport {
     private static final String EXPECT_PATH = "target" + File.separator + "foo" + File.separator + "bar";
     private static final String EXPECT_FILE = "some" + File.separator + "nested" + File.separator + "filename.txt";
+
     private static final Processor DUMMY_PROCESSOR = new Processor() {
         public void process(Exchange exchange) throws Exception {
             // Do nothing here
         }
     };
+
     public void testUriConfigurations() throws Exception {
         assertFileEndpoint("newfile://target/foo/bar", EXPECT_PATH);
         assertFileEndpoint("newfile://target/foo/bar?delete=true", EXPECT_PATH);
@@ -80,10 +82,10 @@
 
         File file = endpoint.getFile();
         String path = file.getPath();
-        assertEquals("For uri: " + endpointUri + " the file is not equal", expectedPath, path);
+        assertDirectoryEquals("For uri: " + endpointUri + " the file is not equal", expectedPath, path);
 
         file = new File(expectedPath + (expectedPath.endsWith(File.separator) ? "" : File.separator) + EXPECT_FILE);
-        GenericFile consumedFile = NewFileConsumer.asGenericFile(file);
+        GenericFile<File> consumedFile = NewFileConsumer.asGenericFile(file);
 
         Message message = new DefaultMessage();
         endpoint.configureMessage(consumedFile, message);

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumeMultipleDirectoriesTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumeMultipleDirectoriesTest.java?rev=739198&r1=739197&r2=739198&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumeMultipleDirectoriesTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumeMultipleDirectoriesTest.java Fri Jan 30 07:42:22 2009
@@ -46,25 +46,20 @@
 
         GenericFileExchange<File> exchange = (GenericFileExchange<File>) mock.getExchanges().get(0);
         File file = exchange.getGenericFile().getFile();
-        assertFilePath("target/multidir/bye.txt", file.getPath());
+        assertDirectoryEquals("target/multidir/bye.txt", file.getPath());
         assertEquals("bye.txt", file.getName());
 
         exchange = (GenericFileExchange<File>) mock.getExchanges().get(1);
         file = exchange.getGenericFile().getFile();
-        assertFilePath("target/multidir/sub/hello.txt", file.getPath());
+        assertDirectoryEquals("target/multidir/sub/hello.txt", file.getPath());
         assertEquals("hello.txt", file.getName());
 
         exchange = (GenericFileExchange<File>) mock.getExchanges().get(2);
         file = exchange.getGenericFile().getFile();
-        assertFilePath("target/multidir/sub/sub2/godday.txt", file.getPath());
+        assertDirectoryEquals("target/multidir/sub/sub2/godday.txt", file.getPath());
         assertEquals("godday.txt", file.getName());
     }
 
-    private static void assertFilePath(String expected, String actual) {
-        actual = actual.replaceAll("\\\\", "/");
-        assertEquals(expected, actual);
-    }
-
     protected RouteBuilder createRouteBuilder() throws Exception {
         return new RouteBuilder() {
             public void configure() throws Exception {

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerBeginExpressionRenameStrategyTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerBeginExpressionRenameStrategyTest.java?rev=739198&r1=739197&r2=739198&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerBeginExpressionRenameStrategyTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerBeginExpressionRenameStrategyTest.java Fri Jan 30 07:42:22 2009
@@ -53,9 +53,12 @@
         File file = new File("target/inprogress");
         file.mkdirs();
         FileWriter fw = new FileWriter("./target/inprogress/london.bak");
-        fw.write("I was there once in London");
-        fw.flush();
-        fw.close();
+        try {
+            fw.write("I was there once in London");
+            fw.flush();
+        } finally {
+            fw.close();
+        }
 
         MockEndpoint mock = getMockEndpoint("mock:report");
         mock.expectedBodiesReceived("Hello London");

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerBeginRenameStrategyTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerBeginRenameStrategyTest.java?rev=739198&r1=739197&r2=739198&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerBeginRenameStrategyTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerBeginRenameStrategyTest.java Fri Jan 30 07:42:22 2009
@@ -53,9 +53,12 @@
         File file = new File("target/inprogress");
         file.mkdirs();
         FileWriter fw = new FileWriter("./target/inprogress/london.txt");
-        fw.write("I was there once in London");
-        fw.flush();
-        fw.close();
+        try {
+            fw.write("I was there once in London");
+            fw.flush();
+        } finally {
+            fw.close();
+        }
 
         MockEndpoint mock = getMockEndpoint("mock:report");
         mock.expectedBodiesReceived("Hello London");

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerCommitRenameStrategyTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerCommitRenameStrategyTest.java?rev=739198&r1=739197&r2=739198&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerCommitRenameStrategyTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerCommitRenameStrategyTest.java Fri Jan 30 07:42:22 2009
@@ -63,9 +63,12 @@
         File file = new File("target/done");
         file.mkdirs();
         FileWriter fw = new FileWriter("./target/done/london.txt");
-        fw.write("I was there once in London");
-        fw.flush();
-        fw.close();
+        try {
+            fw.write("I was there once in London");
+            fw.flush();
+        } finally {
+            fw.close();
+        }
 
         MockEndpoint mock = getMockEndpoint("mock:report");
         mock.expectedBodiesReceived("Hello London");

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerExpressionTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerExpressionTest.java?rev=739198&r1=739197&r2=739198&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerExpressionTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerExpressionTest.java Fri Jan 30 07:42:22 2009
@@ -139,7 +139,6 @@
                 // configured by java using java beans setters
                 NewFileEndpoint endpoint = new NewFileEndpoint();
                 endpoint.setCamelContext(context);
-                endpoint.getConfiguration().setFile("target/filelanguage/report5.txt");
                 endpoint.setFile(new File("target/filelanguage/report5.txt"));
                 endpoint.setOperations(new NewFileOperations(endpoint));
                 endpoint.setDirectory(false);

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileProduceTempPrefixTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileProduceTempPrefixTest.java?rev=739198&r1=739197&r2=739198&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileProduceTempPrefixTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileProduceTempPrefixTest.java Fri Jan 30 07:42:22 2009
@@ -34,7 +34,7 @@
         GenericFileProducer producer = (GenericFileProducer) endpoint.createProducer();
 
         String tempFileName = producer.createTempFileName("target/tempandrename/claus.txt");
-        assertEquals("target" + File.separatorChar + "tempandrename" + File.separatorChar + "inprogress.claus.txt", tempFileName);
+        assertDirectoryEquals("target/tempandrename/inprogress.claus.txt", tempFileName);
     }
 
     public void testNoPathCreateTempFileName() throws Exception {
@@ -42,7 +42,7 @@
         GenericFileProducer producer = (GenericFileProducer) endpoint.createProducer();
 
         String tempFileName = producer.createTempFileName("claus.txt");
-        assertEquals("inprogress.claus.txt", tempFileName);
+        assertDirectoryEquals("inprogress.claus.txt", tempFileName);
     }
 
     public void testTempPrefix() throws Exception {

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/NewFileConsumeTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/NewFileConsumeTest.java?rev=739198&r1=739197&r2=739198&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/NewFileConsumeTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/NewFileConsumeTest.java Fri Jan 30 07:42:22 2009
@@ -48,8 +48,11 @@
         // create a file to consume
         createDirectory("target/consumefile");
         FileOutputStream fos = new FileOutputStream(new File("target/consumefile/hello.txt"));
-        fos.write("Hello World".getBytes());
-        fos.close();
+        try {
+            fos.write("Hello World".getBytes());
+        } finally {
+            fos.close();
+        }
 
         Endpoint endpoint = comp.createEndpoint("newfile://target/consumefile", "target/consumefile", new HashMap());
         Consumer consumer = endpoint.createConsumer(new Processor() {