Author: jstrachan
Date: Thu May  8 01:22:03 2008
New Revision: 654443

URL: http://svn.apache.org/viewvc?rev=654443&view=rev
Log:
added a new file test where we are polling a directory, which is deleted during 
the test - then we move an old file into the newly created directory and check 
that its detected and noticed by the file component

Added:
    
activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/MoveFilesToDirectoryTest.java
      - copied, changed from r654441, 
activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileRouteTest.java

Copied: 
activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/MoveFilesToDirectoryTest.java
 (from r654441, 
activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileRouteTest.java)
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/MoveFilesToDirectoryTest.java?p2=activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/MoveFilesToDirectoryTest.java&p1=activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileRouteTest.java&r1=654441&r2=654443&rev=654443&view=diff
==============================================================================
--- 
activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileRouteTest.java
 (original)
+++ 
activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/MoveFilesToDirectoryTest.java
 Thu May  8 01:22:03 2008
@@ -16,6 +16,8 @@
  */
 package org.apache.camel.component.file;
 
+import java.io.File;
+
 import org.apache.camel.ContextTestSupport;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
@@ -23,23 +25,55 @@
 /**
  * @version $Revision$
  */
-public class FileRouteTest extends ContextTestSupport {
+public class MoveFilesToDirectoryTest extends ContextTestSupport {
+    protected String testDirectory = "target/test/MoveFilesToDirectoryTest";
+    protected String inputDirectory = testDirectory + "/input";
+    protected String outputDirectory = testDirectory + "/output";
+    protected String fileName = "foo.txt";
     protected Object expectedBody = "Hello there!";
-    protected String uri = "file:target/test-default-inbox";
 
     public void testFileRoute() throws Exception {
+        template.sendBodyAndHeader("file:" + inputDirectory, expectedBody, 
FileComponent.HEADER_FILE_NAME, fileName);
+
         MockEndpoint result = getMockEndpoint("mock:result");
         result.expectedBodiesReceived(expectedBody);
         result.setResultWaitTime(5000);
 
-        template.sendBodyAndHeader(uri, expectedBody, "cheese", 123);
+        // now lets wait a bit and move that file
+        Thread.sleep(5000);
+
+        // lets delete the output directory
+        deleteDirectory(outputDirectory);
+
+        // now lets wait a bit for it to be polled
+        Thread.sleep(5000);
+
+        File file = new File(inputDirectory + "/" + fileName);
+        File newFile = new File(outputDirectory + "/" + fileName);
+
+        assertFileExists(file);
+        assertFileNotExists(newFile);
+
+        boolean answer = file.renameTo(newFile);
+        assertTrue("Move of file: " + file + " to " + newFile + " should have 
worked!", answer);
+
+        assertFileNotExists(file);
+        assertFileExists(newFile);
 
         assertMockEndpointsSatisifed();
     }
 
+    protected void assertFileNotExists(File file) {
+        assertFalse("File should not exist: " + file, file.exists());
+    }
+
+    protected void assertFileExists(File file) {
+        assertTrue("File should exist: " + file, file.exists());
+    }
+
     @Override
     protected void setUp() throws Exception {
-        deleteDirectory("target/test-default-inbox");
+        deleteDirectory(testDirectory);
         super.setUp();
     }
 
@@ -47,8 +81,8 @@
     protected RouteBuilder createRouteBuilder() {
         return new RouteBuilder() {
             public void configure() {
-                from(uri).to("mock:result");
+                from("file:" + outputDirectory).to("mock:result");
             }
         };
     }
-}
+}
\ No newline at end of file


Reply via email to