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/12/05 20:44:09 UTC

svn commit: r723835 - in /activemq/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/component/file/

Author: davsclaus
Date: Fri Dec  5 11:44:08 2008
New Revision: 723835

URL: http://svn.apache.org/viewvc?rev=723835&view=rev
Log:
CAMEL-1148: Added options pre move options to move file before processing

Added:
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerBeginAndCommitExpressionRenameStrategyTest.java
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerBeginAndCommitRenameStrategyTest.java
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerBeginExpressionRenameStrategyTest.java
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerBeginRenameStrategyTest.java
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerCommitRenameStrategyTest.java   (contents, props changed)
      - copied, changed from r723792, activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileProducerRenameStrategyTest.java
Removed:
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileProducerRenameStrategyTest.java
Modified:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileConsumer.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileEndpoint.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileExchange.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileProcessStrategyFactory.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/RenameFileProcessStrategy.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=723835&r1=723834&r2=723835&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 Dec  5 11:44:08 2008
@@ -124,10 +124,10 @@
      * @param exchange  the file exchange
      */
     protected void processExchange(final FileExchange exchange) {
-        final File file = exchange.getFile();
+        final File target = exchange.getFile();
 
         if (LOG.isTraceEnabled()) {
-            LOG.trace("Processing file: " + file);
+            LOG.trace("Processing file: " + target);
         }
 
         try {
@@ -135,18 +135,20 @@
 
             // is we use excluse read then acquire the exclusive read (waiting until we got it)
             if (exclusiveReadLock) {
-                acquireExclusiveReadLock(file);
+                acquireExclusiveReadLock(target);
             }
 
             if (LOG.isDebugEnabled()) {
-                LOG.debug("About to process file: " + file + " using exchange: " + exchange);
+                LOG.debug("About to process file: " + target + " using exchange: " + exchange);
             }
-            if (processStrategy.begin(endpoint, exchange, file)) {
+            if (processStrategy.begin(endpoint, exchange, target)) {
 
                 // Use the async processor interface so that processing of
                 // the exchange can happen asynchronously
                 getAsyncProcessor().process(exchange, new AsyncCallback() {
                     public void done(boolean sync) {
+                        // must use file from exchange as it can be updated due the preMoveNamePrefix/preMoveNamePostfix options
+                        final File file = exchange.getFile();
                         boolean failed = exchange.isFailed();
                         boolean handled = DeadLetterChannel.isFailureHandled(exchange);
 
@@ -173,7 +175,7 @@
                 });
 
             } else {
-                LOG.warn(endpoint + " can not process file: " + file);
+                LOG.warn(endpoint + " can not process file: " + target);
             }
         } catch (Exception e) {
             handleException(e);

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileEndpoint.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileEndpoint.java?rev=723835&r1=723834&r2=723835&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileEndpoint.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileEndpoint.java Fri Dec  5 11:44:08 2008
@@ -64,11 +64,14 @@
     private boolean append = true;
     private String moveNamePrefix;
     private String moveNamePostfix;
+    private String preMoveNamePrefix;
+    private String preMoveNamePostfix;
     private String excludedNamePrefix;
     private String excludedNamePostfix;
     private int bufferSize = 128 * 1024;
     private boolean ignoreFileNameHeader;
     private Expression expression;
+    private Expression preMoveExpression;
     private String tempPrefix;
     private boolean idempotent;
     private IdempotentRepository idempotentRepository;
@@ -99,6 +102,10 @@
 
     public Consumer createConsumer(Processor processor) throws Exception {
         Consumer result = new FileConsumer(this, processor);
+
+        if (isDelete() && (getMoveNamePrefix() != null || getMoveNamePostfix() != null || getExpression() != null)) {
+            throw new IllegalArgumentException("You cannot set delet and a moveNamePrefix, moveNamePostfix or expression option");
+        }
         
         // if noop=true then idempotent should also be configured
         if (isNoop() && !isIdempotent()) {
@@ -239,6 +246,31 @@
         this.moveNamePrefix = moveNamePrefix;
     }
 
+    public String getPreMoveNamePrefix() {
+        return preMoveNamePrefix;
+    }
+
+    public void setPreMoveNamePrefix(String preMoveNamePrefix) {
+        this.preMoveNamePrefix = preMoveNamePrefix;
+    }
+
+    /**
+     * Sets the name prefix appended to pre moved files. For example to move
+     * files before processing into a inprogress directory called <tt>.inprogress</tt> set this value to
+     * <tt>.inprogress/</tt>
+     */
+    public String getPreMoveNamePostfix() {
+        return preMoveNamePostfix;
+    }
+
+    /**
+     * Sets the name postfix appended to pre moved files. For example to rename
+     * files before processing from <tt>*</tt> to <tt>*.inprogress</tt> set this value to <tt>.inprogress</tt>
+     */
+    public void setPreMoveNamePostfix(String preMoveNamePostfix) {
+        this.preMoveNamePostfix = preMoveNamePostfix;
+    }
+
     public boolean isNoop() {
         return noop;
     }
@@ -318,6 +350,21 @@
         this.expression = FileLanguage.file(fileLanguageExpression);
     }
 
+    public Expression getPreMoveExpression() {
+        return preMoveExpression;
+    }
+
+    public void setPreMoveExpression(Expression expression) {
+        this.preMoveExpression = expression;
+    }
+
+    /**
+     * Sets the pre move expression based on {@link FileLanguage}
+     */
+    public void setPreMoveExpression(String fileLanguageExpression) {
+        this.preMoveExpression = FileLanguage.file(fileLanguageExpression);
+    }
+
     public String getTempPrefix() {
         return tempPrefix;
     }
@@ -429,9 +476,18 @@
         if (moveNamePostfix != null) {
             params.put("moveNamePostfix", moveNamePostfix);
         }
+        if (preMoveNamePrefix != null) {
+            params.put("preMoveNamePrefix", preMoveNamePrefix);
+        }
+        if (preMoveNamePostfix != null) {
+            params.put("preMoveNamePostfix", preMoveNamePostfix);
+        }
         if (expression != null) {
             params.put("expression", expression);
         }
+        if (preMoveExpression != null) {
+            params.put("preMoveExpression", preMoveExpression);
+        }
 
         return params;
     }

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileExchange.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileExchange.java?rev=723835&r1=723834&r2=723835&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileExchange.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileExchange.java Fri Dec  5 11:44:08 2008
@@ -35,9 +35,29 @@
 
     public FileExchange(CamelContext camelContext, ExchangePattern pattern, File file) {
         super(camelContext, pattern);
+        setFile(file);
+    }
+
+    public FileExchange(DefaultExchange parent, File file) {
+        super(parent);
+        setFile(file);
+    }
+
+    public File getFile() {
+        return this.file;
+    }
+
+    public void setFile(File file) {
         setIn(new FileMessage(file));
         this.file = file;
+        populateHeaders(file);
+    }
+
+    public Exchange newInstance() {
+        return new FileExchange(this, getFile());
+    }
 
+    private void populateHeaders(File file) {
         // set additional headers with file information
         if (file != null) {
             getIn().setHeader("CamelFileName", file.getName());
@@ -58,21 +78,4 @@
         }
     }
 
-    public FileExchange(DefaultExchange parent, File file) {
-        super(parent);
-        this.file = file;
-    }
-
-    public File getFile() {
-        return this.file;
-    }
-
-    public void setFile(File file) {
-        this.file = file;
-    }
-
-    public Exchange newInstance() {
-        return new FileExchange(this, getFile());
-    }
-
 }

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileProcessStrategyFactory.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileProcessStrategyFactory.java?rev=723835&r1=723834&r2=723835&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileProcessStrategyFactory.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileProcessStrategyFactory.java Fri Dec  5 11:44:08 2008
@@ -40,26 +40,41 @@
         boolean isLock = params.get("lock") != null;
         String moveNamePrefix = (String) params.get("moveNamePrefix");
         String moveNamePostfix = (String) params.get("moveNamePostfix");
+        String preMoveNamePrefix = (String) params.get("preMoveNamePrefix");
+        String preMoveNamePostfix = (String) params.get("preMoveNamePostfix");
         Expression expression = (Expression) params.get("expression");
+        Expression preMoveExpression = (Expression) params.get("preMoveExpression");
+        boolean move = moveNamePrefix != null || moveNamePostfix != null;
+        boolean preMove = preMoveNamePrefix != null || preMoveNamePostfix != null;
 
         if (params.containsKey("noop")) {
             return new NoOpFileProcessStrategy(isLock);
-        } else if (moveNamePostfix != null || moveNamePrefix != null) {
-            if (isDelete) {
-                throw new IllegalArgumentException("You cannot set the deleteFiles property "
-                    + "and a moveFilenamePostfix or moveFilenamePrefix");
+        } else if (move || preMove) {
+            RenameFileProcessStrategy strategy = new RenameFileProcessStrategy(isLock);
+            if (move) {
+                strategy.setCommitRenamer(new DefaultFileRenamer(moveNamePrefix, moveNamePostfix));
             }
-            return new RenameFileProcessStrategy(isLock, moveNamePrefix, moveNamePostfix);
-        } else if (expression != null) {
-            FileExpressionRenamer renamer = new FileExpressionRenamer();
-            renamer.setExpression(expression);
-
+            if (preMove) {
+                strategy.setBeginRenamer(new DefaultFileRenamer(preMoveNamePrefix, preMoveNamePostfix));
+            }
+            return strategy;
+        } else if (expression != null || preMoveExpression != null) {
             RenameFileProcessStrategy strategy = new RenameFileProcessStrategy(isLock);
-            strategy.setRenamer(renamer);
+            if (expression != null) {
+                FileExpressionRenamer renamer = new FileExpressionRenamer();
+                renamer.setExpression(expression);
+                strategy.setCommitRenamer(renamer);
+            }
+            if (preMoveExpression != null) {
+                FileExpressionRenamer renamer = new FileExpressionRenamer();
+                renamer.setExpression(preMoveExpression);
+                strategy.setBeginRenamer(renamer);
+            }
             return strategy;
         } else if (isDelete) {
             return new DeleteFileProcessStrategy(isLock);
         } else {
+            // default strategy will move to .camel subfolder
             return new RenameFileProcessStrategy(isLock);
         }
     }

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/RenameFileProcessStrategy.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/RenameFileProcessStrategy.java?rev=723835&r1=723834&r2=723835&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/RenameFileProcessStrategy.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/RenameFileProcessStrategy.java Fri Dec  5 11:44:08 2008
@@ -31,7 +31,8 @@
  */
 public class RenameFileProcessStrategy extends FileProcessStrategySupport {
     private static final transient Log LOG = LogFactory.getLog(RenameFileProcessStrategy.class);
-    private FileRenamer renamer;
+    private FileRenamer beginRenamer;
+    private FileRenamer commitRenamer;
 
     public RenameFileProcessStrategy() {
         this(true);
@@ -42,42 +43,85 @@
     }
 
     public RenameFileProcessStrategy(boolean lock, String namePrefix, String namePostfix) {
-        this(lock, new DefaultFileRenamer(namePrefix, namePostfix));
+        this(lock, new DefaultFileRenamer(namePrefix, namePostfix), null);
     }
 
-    public RenameFileProcessStrategy(boolean lock, FileRenamer renamer) {
+    public RenameFileProcessStrategy(boolean lock, String namePrefix, String namePostfix, String preNamePrefix, String preNamePostfix) {
+        this(lock, new DefaultFileRenamer(namePrefix, namePostfix), new DefaultFileRenamer(preNamePrefix, preNamePostfix));
+    }
+
+    public RenameFileProcessStrategy(boolean lock, FileRenamer commitRenamer, FileRenamer beginRenamer) {
         super(lock);
-        this.renamer = renamer;
+        this.commitRenamer = commitRenamer;
+        this.beginRenamer = beginRenamer;
+    }
+
+    @Override
+    public boolean begin(FileEndpoint endpoint, FileExchange exchange, File file) throws Exception {
+        boolean answer = super.begin(endpoint, exchange, file);
+
+        if (beginRenamer != null) {
+            File newName = beginRenamer.renameFile(exchange, file);
+            // deleting any existing files before renaming
+            File to = renameFile(file, newName);
+            exchange.setFile(to);
+        }
+
+        return answer;
     }
 
     @Override
     public void commit(FileEndpoint endpoint, FileExchange exchange, File file) throws Exception {
-        File newName = renamer.renameFile(exchange, file);
+        File newName = commitRenamer.renameFile(exchange, file);
+        renameFile(file, newName);
+
+        // must commit to release the lock
+        super.commit(endpoint, exchange, file);
+    }
+
+    private static File renameFile(File from, File to) throws IOException {
         // deleting any existing files before renaming
-        if (newName.exists()) {
-            newName.delete();
+        if (to.exists()) {
+            to.delete();
         }
 
         // make parent folder if missing
-        newName.getParentFile().mkdirs();
+        File parent = to.getParentFile();
+        if (!parent.exists()) {
+            if (LOG.isDebugEnabled()) {
+                LOG.debug("Creating directory: " + parent);
+            }
+            boolean mkdir = parent.mkdirs();
+            if (!mkdir) {
+                throw new IOException("Can not create directory: " + parent);
+            }
+        }
 
         if (LOG.isDebugEnabled()) {
-            LOG.debug("Renaming file: " + file + " to: " + newName);
+            LOG.debug("Renaming file: " + from + " to: " + to);
         }
-        boolean renamed = file.renameTo(newName);
+        boolean renamed = from.renameTo(to);
         if (!renamed) {
-            throw new IOException("Can not rename file from: " + file + " to: " + newName);
+            throw new IOException("Can not rename file from: " + from + " to: " + to);
         }
 
-        // must commit to release the lock
-        super.commit(endpoint, exchange, file);
+        return to;
     }
 
-    public FileRenamer getRenamer() {
-        return renamer;
+    public FileRenamer getBeginRenamer() {
+        return beginRenamer;
     }
 
-    public void setRenamer(FileRenamer renamer) {
-        this.renamer = renamer;
+    public void setBeginRenamer(FileRenamer beginRenamer) {
+        this.beginRenamer = beginRenamer;
     }
+
+    public FileRenamer getCommitRenamer() {
+        return commitRenamer;
+    }
+
+    public void setCommitRenamer(FileRenamer commitRenamer) {
+        this.commitRenamer = commitRenamer;
+    }
+
 }
\ No newline at end of file

Added: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerBeginAndCommitExpressionRenameStrategyTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerBeginAndCommitExpressionRenameStrategyTest.java?rev=723835&view=auto
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerBeginAndCommitExpressionRenameStrategyTest.java (added)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerBeginAndCommitExpressionRenameStrategyTest.java Fri Dec  5 11:44:08 2008
@@ -0,0 +1,82 @@
+/**
+ * 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;
+
+import java.io.File;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.converter.IOConverter;
+
+/**
+ * Unit test for the FileRenameStrategy using preMoveExpression and expression options
+ */
+public class FileConsumerBeginAndCommitExpressionRenameStrategyTest extends ContextTestSupport {
+
+    public void testRenameSuccess() throws Exception {
+        deleteDirectory("target/inprogress");
+        deleteDirectory("target/done");
+        deleteDirectory("target/reports");
+
+        MockEndpoint mock = getMockEndpoint("mock:report");
+        mock.expectedMessageCount(1);
+        mock.expectedBodiesReceived("Hello Paris");
+
+        template.sendBodyAndHeader("file:target/reports", "Hello Paris", FileComponent.HEADER_FILE_NAME, "paris.txt");
+
+        mock.assertIsSatisfied();
+
+        // sleep to let the file consumer do its renaming
+        Thread.sleep(100);
+
+        // content of file should be Hello Paris
+        String content = IOConverter.toString(new File("./target/done/paris.bak"));
+        assertEquals("The file should have been renamed", "Hello Paris", content);
+    }
+
+    public void testIllegalOptions() throws Exception {
+        try {
+            context.getEndpoint("file://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
+        }
+    }
+
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            public void configure() throws Exception {
+                from("file://target/reports?preMoveExpression=../inprogress/${file:name.noext}.bak&expression=../done/${file:name}&consumer.delay=5000")
+                        .process(new Processor() {
+                            public void process(Exchange exchange) throws Exception {
+                                FileExchange fe = (FileExchange) exchange;
+                                assertEquals("The file should have been move to inprogress",
+                                        "inprogress", fe.getFile().getParentFile().getName());
+                            }
+                        })
+                        .to("mock:report");
+            }
+        };
+    }
+
+}
\ No newline at end of file

Added: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerBeginAndCommitRenameStrategyTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerBeginAndCommitRenameStrategyTest.java?rev=723835&view=auto
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerBeginAndCommitRenameStrategyTest.java (added)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerBeginAndCommitRenameStrategyTest.java Fri Dec  5 11:44:08 2008
@@ -0,0 +1,92 @@
+/**
+ * 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;
+
+import java.io.File;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.converter.IOConverter;
+
+/**
+ * Unit test for the FileRenameStrategy using preMove and move options
+ */
+public class FileConsumerBeginAndCommitRenameStrategyTest extends ContextTestSupport {
+
+    public void testRenameSuccess() throws Exception {
+        deleteDirectory("target/inprogress");
+        deleteDirectory("target/done");
+        deleteDirectory("target/reports");
+
+        MockEndpoint mock = getMockEndpoint("mock:report");
+        mock.expectedMessageCount(1);
+        mock.expectedBodiesReceived("Hello Paris");
+
+        template.sendBodyAndHeader("file:target/reports", "Hello Paris", FileComponent.HEADER_FILE_NAME, "paris.txt");
+
+        mock.assertIsSatisfied();
+
+        // sleep to let the file consumer do its renaming
+        Thread.sleep(100);
+
+        // content of file should be Hello Paris
+        String content = IOConverter.toString(new File("./target/done/paris.txt"));
+        assertEquals("The file should have been renamed", "Hello Paris", content);
+    }
+
+    public void testIllegalOptions() throws Exception {
+        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?expression=${file:name.noext}.bak&delete=true").createConsumer(new Processor() {
+                public void process(Exchange exchange) throws Exception {
+                }
+            });
+            fail("Should have thrown an exception");
+        } catch (IllegalArgumentException e) {
+            // ok
+        }
+    }
+
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            public void configure() throws Exception {
+                from("file://target/reports?preMoveNamePrefix=../inprogress/&moveNamePrefix=../done/&consumer.delay=5000")
+                        .process(new Processor() {
+                            public void process(Exchange exchange) throws Exception {
+                                FileExchange fe = (FileExchange) exchange;
+                                assertEquals("The file should have been move to inprogress",
+                                        "inprogress", fe.getFile().getParentFile().getName());
+                            }
+                        })
+                        .to("mock:report");
+            }
+        };
+    }
+
+}
\ No newline at end of file

Added: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerBeginExpressionRenameStrategyTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerBeginExpressionRenameStrategyTest.java?rev=723835&view=auto
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerBeginExpressionRenameStrategyTest.java (added)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerBeginExpressionRenameStrategyTest.java Fri Dec  5 11:44:08 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;
+
+import java.io.File;
+import java.io.FileWriter;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+
+/**
+ * Unit test for the FileRenameStrategy using preMoveExpression options
+ */
+public class FileConsumerBeginExpressionRenameStrategyTest extends ContextTestSupport {
+
+    public void testRenameSuccess() throws Exception {
+        deleteDirectory("target/inprogress");
+        deleteDirectory("target/reports");
+
+        MockEndpoint mock = getMockEndpoint("mock:report");
+        mock.expectedMessageCount(1);
+        mock.expectedBodiesReceived("Hello Paris");
+
+        template.sendBodyAndHeader("file:target/reports", "Hello Paris", FileComponent.HEADER_FILE_NAME, "paris.txt");
+
+        Thread.sleep(100);
+
+        mock.assertIsSatisfied();
+    }
+
+    public void testRenameFileExists() throws Exception {
+        deleteDirectory("target/inprogress");
+        deleteDirectory("target/reports");
+
+        // create a file in inprogress to let there be a duplicate file
+        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();
+
+        MockEndpoint mock = getMockEndpoint("mock:report");
+        mock.expectedBodiesReceived("Hello London");
+
+        template.sendBodyAndHeader("file:target/reports", "Hello London", FileComponent.HEADER_FILE_NAME, "london.txt");
+
+        Thread.sleep(100);
+
+        mock.assertIsSatisfied();
+    }
+
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            public void configure() throws Exception {
+                from("file://target/reports?preMoveExpression=../inprogress/${file:name.noext}.bak&consumer.delay=5000")
+                        .process(new Processor() {
+                            public void process(Exchange exchange) throws Exception {
+                                FileExchange fe = (FileExchange) exchange;
+                                assertEquals("The file should have been move to inprogress",
+                                        "inprogress", fe.getFile().getParentFile().getName());
+                            }
+                        })
+                        .to("mock:report");
+            }
+        };
+    }
+
+}
\ No newline at end of file

Added: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerBeginRenameStrategyTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerBeginRenameStrategyTest.java?rev=723835&view=auto
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerBeginRenameStrategyTest.java (added)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerBeginRenameStrategyTest.java Fri Dec  5 11:44:08 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;
+
+import java.io.File;
+import java.io.FileWriter;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+
+/**
+ * Unit test for the FileRenameStrategy using preMove options
+ */
+public class FileConsumerBeginRenameStrategyTest extends ContextTestSupport {
+
+    public void testRenameSuccess() throws Exception {
+        deleteDirectory("target/inprogress");
+        deleteDirectory("target/reports");
+
+        MockEndpoint mock = getMockEndpoint("mock:report");
+        mock.expectedMessageCount(1);
+        mock.expectedBodiesReceived("Hello Paris");
+
+        template.sendBodyAndHeader("file:target/reports", "Hello Paris", FileComponent.HEADER_FILE_NAME, "paris.txt");
+
+        Thread.sleep(100);
+
+        mock.assertIsSatisfied();
+    }
+
+    public void testRenameFileExists() throws Exception {
+        deleteDirectory("target/inprogress");
+        deleteDirectory("target/reports");
+
+        // create a file in inprogress to let there be a duplicate file
+        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();
+
+        MockEndpoint mock = getMockEndpoint("mock:report");
+        mock.expectedBodiesReceived("Hello London");
+
+        template.sendBodyAndHeader("file:target/reports", "Hello London", FileComponent.HEADER_FILE_NAME, "london.txt");
+
+        Thread.sleep(100);
+
+        mock.assertIsSatisfied();
+    }
+
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            public void configure() throws Exception {
+                from("file://target/reports?preMoveNamePrefix=../inprogress/&consumer.delay=5000")
+                        .process(new Processor() {
+                            public void process(Exchange exchange) throws Exception {
+                                FileExchange fe = (FileExchange) exchange;
+                                assertEquals("The file should have been move to inprogress", 
+                                        "inprogress", fe.getFile().getParentFile().getName());
+                            }
+                        })
+                        .to("mock:report");
+            }
+        };
+    }
+
+}
\ No newline at end of file

Copied: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerCommitRenameStrategyTest.java (from r723792, activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileProducerRenameStrategyTest.java)
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerCommitRenameStrategyTest.java?p2=activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerCommitRenameStrategyTest.java&p1=activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileProducerRenameStrategyTest.java&r1=723792&r2=723835&rev=723835&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileProducerRenameStrategyTest.java (original)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerCommitRenameStrategyTest.java Fri Dec  5 11:44:08 2008
@@ -25,9 +25,9 @@
 import org.apache.camel.converter.IOConverter;
 
 /**
- * Unit test for the FileRenameStrategy
+ * Unit test for the FileRenameStrategy using move options
  */
-public class FileProducerRenameStrategyTest extends ContextTestSupport {
+public class FileConsumerCommitRenameStrategyTest extends ContextTestSupport {
 
     @Override
     protected void tearDown() throws Exception {

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

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