camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r749569 - in /camel/trunk/camel-core/src: main/java/org/apache/camel/component/file/ test/java/org/apache/camel/component/file/
Date Tue, 03 Mar 2009 09:37:09 GMT
Author: davsclaus
Date: Tue Mar  3 09:37:08 2009
New Revision: 749569

URL: http://svn.apache.org/viewvc?rev=749569&view=rev
Log:
Fix to GenericFile to handle changing name from absolute to relative.

Added:
    camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerAbsolutePathWithAbsoluteMoveTest.java
      - copied, changed from r749565, camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerAbsolutePathTest.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerAbsolutePathWithRelativeMoveTest.java
  (with props)
Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFile.java

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFile.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFile.java?rev=749569&r1=749568&r2=749569&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFile.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFile.java
Tue Mar  3 09:37:08 2009
@@ -99,6 +99,7 @@
             setAbsoluteFileName(newName);
             // no relative filename for absolute files
             setRelativeFileName(null);
+            setCanonicalFileName(null);
             String fileName = newName.substring(newName.lastIndexOf(getFileSeparator()) +
1);
             setFileName(fileName);
             return;
@@ -107,6 +108,7 @@
         // the rest is complex relative path computation
         setAbsolute(false);
         setAbsoluteFileName(getParent() + getFileSeparator() + newName);
+        setCanonicalFileName(null);
 
         // relative name is a bit more complex to set as newName itself can contain
         // folders we need to consider as well
@@ -116,7 +118,7 @@
             newName = newName.substring(newName.lastIndexOf(getFileSeparator()) + 1);
         }
 
-        if (relativeFileName.indexOf(getFileSeparator()) != -1) {
+        if (relativeFileName != null && relativeFileName.indexOf(getFileSeparator())
!= -1) {
             String relative = relativeFileName.substring(0, relativeFileName.lastIndexOf(File.separator));
             if (baseNewName != null) {
                 setRelativeFileName(relative + getFileSeparator() + baseNewName + getFileSeparator()
+ newName);

Copied: camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerAbsolutePathWithAbsoluteMoveTest.java
(from r749565, camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerAbsolutePathTest.java)
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerAbsolutePathWithAbsoluteMoveTest.java?p2=camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerAbsolutePathWithAbsoluteMoveTest.java&p1=camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerAbsolutePathTest.java&r1=749565&r2=749569&rev=749569&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerAbsolutePathTest.java
(original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerAbsolutePathWithAbsoluteMoveTest.java
Tue Mar  3 09:37:08 2009
@@ -26,7 +26,7 @@
 /**
  * Unit test for consuming from an absolute path
  */
-public class FileConsumerAbsolutePathTest extends ContextTestSupport {
+public class FileConsumerAbsolutePathWithAbsoluteMoveTest extends ContextTestSupport {
 
     private String base;
 
@@ -41,6 +41,7 @@
     public void testConsumeFromAbsolutePath() throws Exception {
         MockEndpoint mock = getMockEndpoint("mock:report");
         mock.expectedBodiesReceived("Hello Paris");
+        mock.expectedFileExists(base + "/done/paris.txt");
 
         template.sendBodyAndHeader("file:target/reports", "Hello Paris", Exchange.FILE_NAME,
"paris.txt");
 
@@ -50,7 +51,7 @@
     protected RouteBuilder createRouteBuilder() throws Exception {
         return new RouteBuilder() {
             public void configure() throws Exception {
-                from("file://" + base + "?delete=true").to("mock:report");
+                from("file://" + base + "?moveExpression=" + base + "/done/${file:name}").to("mock:report");
             }
         };
     }

Added: camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerAbsolutePathWithRelativeMoveTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerAbsolutePathWithRelativeMoveTest.java?rev=749569&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerAbsolutePathWithRelativeMoveTest.java
(added)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerAbsolutePathWithRelativeMoveTest.java
Tue Mar  3 09:37:08 2009
@@ -0,0 +1,58 @@
+/**
+ * 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.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+
+/**
+ * Unit test for consuming from an absolute path
+ */
+public class FileConsumerAbsolutePathWithRelativeMoveTest extends ContextTestSupport {
+
+    private String base;
+
+    @Override
+    protected void setUp() throws Exception {
+        deleteDirectory("target/reports");
+        deleteDirectory("target/done");
+        // use current dir as base as aboslute path
+        base = new File("").getAbsolutePath() + "/target/reports";
+        super.setUp();
+    }
+
+    public void testConsumeFromAbsolutePath() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:report");
+        mock.expectedBodiesReceived("Hello Paris");
+        mock.expectedFileExists(base + "/../done/paris.txt");
+
+        template.sendBodyAndHeader("file:target/reports", "Hello Paris", Exchange.FILE_NAME,
"paris.txt");
+        mock.assertIsSatisfied();
+    }
+
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            public void configure() throws Exception {
+                from("file://" + base + "?moveExpression=../done/${file:name}").to("mock:report");
+            }
+        };
+    }
+}
\ No newline at end of file

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

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



Mime
View raw message