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 2014/04/03 09:55:39 UTC

[2/3] git commit: CAMEL-6458: Add tests for renameUsingCopy option

CAMEL-6458: Add tests for renameUsingCopy option

Signed-off-by: Gregor Zurowski <gr...@zurowski.org>

Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/daed640e
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/daed640e
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/daed640e

Branch: refs/heads/master
Commit: daed640eb32c40a291482fb2a1b5015aeffb07f6
Parents: 0f35396
Author: Gregor Zurowski <gr...@zurowski.org>
Authored: Sat Mar 29 14:48:10 2014 -0400
Committer: Gregor Zurowski <gr...@zurowski.org>
Committed: Sat Mar 29 14:48:10 2014 -0400

----------------------------------------------------------------------
 .../file/FileProducerRenameUsingCopyTest.java   | 56 ++++++++++++++++++++
 .../org/apache/camel/util/FileUtilTest.java     | 11 ++++
 2 files changed, 67 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/daed640e/camel-core/src/test/java/org/apache/camel/component/file/FileProducerRenameUsingCopyTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/file/FileProducerRenameUsingCopyTest.java b/camel-core/src/test/java/org/apache/camel/component/file/FileProducerRenameUsingCopyTest.java
new file mode 100644
index 0000000..c5dbfb6
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/component/file/FileProducerRenameUsingCopyTest.java
@@ -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;
+
+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;
+
+public class FileProducerRenameUsingCopyTest extends ContextTestSupport {
+
+    @Override
+    protected void setUp() throws Exception {
+        deleteDirectory("target/file");
+        super.setUp();
+    }
+
+    public void testMove() throws Exception {
+        final String body = "Hello Camel";
+        template.sendBodyAndHeader("file://target/file", body, Exchange.FILE_NAME, "hello.txt");
+
+        MockEndpoint mock = getMockEndpoint("mock:result");
+        mock.expectedMessageCount(1);
+        mock.expectedFileExists("target/file/done/hello.txt", body);
+        assertMockEndpointsSatisfied();
+
+        assertTrue("File not copied", new File("target/file/done/hello.txt").exists());
+        assertFalse("File not deleted", new File("target/file/hello.txt").exists());
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("file://target/file?renameUsingCopy=true&move=done").convertBodyTo(String.class).to("mock:result");
+            }
+        };
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/daed640e/camel-core/src/test/java/org/apache/camel/util/FileUtilTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/util/FileUtilTest.java b/camel-core/src/test/java/org/apache/camel/util/FileUtilTest.java
index 1ef3b1e..89446e9 100644
--- a/camel-core/src/test/java/org/apache/camel/util/FileUtilTest.java
+++ b/camel-core/src/test/java/org/apache/camel/util/FileUtilTest.java
@@ -221,4 +221,15 @@ public class FileUtilTest extends TestCase {
         assertFalse(tmpDir.exists());
     }
 
+    public void testRenameUsingDelete() throws Exception {
+        File file = new File("target/foo.txt");
+        if (!file.exists()) {
+            FileUtil.createNewFile(file);
+        }
+        
+        File target = new File("target/bar.txt");
+        FileUtil.renameFileUsingCopy(file, target);
+        assertTrue("File not copied", target.exists());
+        assertFalse("File not deleted", file.exists());
+    }
 }