camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r1151107 - /camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumeAlterFileNameHeaderIssueTest.java
Date Tue, 26 Jul 2011 14:16:55 GMT
Author: davsclaus
Date: Tue Jul 26 14:16:54 2011
New Revision: 1151107

URL: http://svn.apache.org/viewvc?rev=1151107&view=rev
Log:
CAMEL-4270: Added unit test

Added:
    camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumeAlterFileNameHeaderIssueTest.java
      - copied, changed from r1151087, camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumeCharsetTest.java

Copied: camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumeAlterFileNameHeaderIssueTest.java
(from r1151087, camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumeCharsetTest.java)
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumeAlterFileNameHeaderIssueTest.java?p2=camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumeAlterFileNameHeaderIssueTest.java&p1=camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumeCharsetTest.java&r1=1151087&r2=1151107&rev=1151107&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumeCharsetTest.java
(original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumeAlterFileNameHeaderIssueTest.java
Tue Jul 26 14:16:54 2011
@@ -24,35 +24,125 @@ import org.apache.camel.builder.RouteBui
 import org.apache.camel.component.mock.MockEndpoint;
 
 /**
- * Unit test for consuming the same filename only.
+ *
  */
-public class FileConsumeCharsetTest extends ContextTestSupport {
+public class FileConsumeAlterFileNameHeaderIssueTest extends ContextTestSupport {
 
     @Override
     protected void setUp() throws Exception {
         deleteDirectory("target/files");
         super.setUp();
-        template.sendBodyAndHeader("file://target/files?charset=UTF-8", "Hello World \u4f60\u597d",
Exchange.FILE_NAME, "report.txt");
     }
 
-    public void testConsumeAndDelete() throws Exception {
+    @Override
+    public boolean isUseRouteBuilder() {
+        return false;
+    }
+
+    public void testConsumeAndDeleteRemoveAllHeaders() throws Exception {
+        context.addRoutes(new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("file://target/files?delete=true")
+                    // remove all headers
+                    .removeHeaders("*")
+                    .to("mock:result");
+            }
+        });
+        context.start();
+
         MockEndpoint mock = getMockEndpoint("mock:result");
-        mock.expectedBodiesReceived("Hello World \u4f60\u597d");
+        mock.expectedBodiesReceived("Hello World");
+
+        template.sendBodyAndHeader("file://target/files", "Hello World", Exchange.FILE_NAME,
"hello.txt");
 
         assertMockEndpointsSatisfied();
+        oneExchangeDone.matchesMockWaitTime();
+
+        assertFalse("Headers should have been removed", mock.getExchanges().get(0).getIn().hasHeaders());
+
+        // the original file should have been deleted, as the file consumer should be resilient
against
+        // end users deleting headers
+        assertFalse("File should been deleted", new File("target/files/hello.txt").getAbsoluteFile().exists());
+    }
+
+    public void testConsumeAndDeleteChangeFileHeader() throws Exception {
+        context.addRoutes(new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("file://target/files?delete=true")
+                    // change file header
+                    .setHeader(Exchange.FILE_NAME, constant("bye.txt"))
+                    .to("mock:result");
+            }
+        });
+        context.start();
+
+        MockEndpoint mock = getMockEndpoint("mock:result");
+        mock.expectedBodiesReceived("Hello World");
+        mock.expectedHeaderReceived(Exchange.FILE_NAME, "bye.txt");
+
+        template.sendBodyAndHeader("file://target/files", "Hello World", Exchange.FILE_NAME,
"hello.txt");
 
+        assertMockEndpointsSatisfied();
         oneExchangeDone.matchesMockWaitTime();
 
-        // file should not exists
-        assertFalse("File should been deleted", new File("target/files/report.txt").getAbsoluteFile().exists());
+        // the original file should have been deleted, as the file consumer should be resilient
against
+        // end users changing headers
+        assertFalse("File should been deleted", new File("target/files/hello.txt").getAbsoluteFile().exists());
     }
 
-    @Override
-    protected RouteBuilder createRouteBuilder() throws Exception {
-        return new RouteBuilder() {
+    public void testConsumeAndMoveRemoveAllHeaders() throws Exception {
+        context.addRoutes(new RouteBuilder() {
+            @Override
             public void configure() throws Exception {
-                from("file://target/files/?fileName=report.txt&delete=true&charset=UTF-8").convertBodyTo(String.class).to("mock:result");
+                from("file://target/files")
+                    // remove all headers
+                    .removeHeaders("*")
+                    .to("mock:result");
             }
-        };
+        });
+        context.start();
+
+        MockEndpoint mock = getMockEndpoint("mock:result");
+        mock.expectedBodiesReceived("Hello World");
+
+        template.sendBodyAndHeader("file://target/files", "Hello World", Exchange.FILE_NAME,
"hello.txt");
+
+        assertMockEndpointsSatisfied();
+        oneExchangeDone.matchesMockWaitTime();
+
+        assertFalse("Headers should have been removed", mock.getExchanges().get(0).getIn().hasHeaders());
+
+        // the original file should have been moved, as the file consumer should be resilient
against
+        // end users deleting headers
+        assertTrue("File should been moved", new File("target/files/.camel/hello.txt").getAbsoluteFile().exists());
     }
+
+    public void testConsumeAndMoveChangeFileHeader() throws Exception {
+        context.addRoutes(new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("file://target/files")
+                    // change file header
+                    .setHeader(Exchange.FILE_NAME, constant("bye.txt"))
+                    .to("mock:result");
+            }
+        });
+        context.start();
+
+        MockEndpoint mock = getMockEndpoint("mock:result");
+        mock.expectedBodiesReceived("Hello World");
+        mock.expectedHeaderReceived(Exchange.FILE_NAME, "bye.txt");
+
+        template.sendBodyAndHeader("file://target/files", "Hello World", Exchange.FILE_NAME,
"hello.txt");
+
+        assertMockEndpointsSatisfied();
+        oneExchangeDone.matchesMockWaitTime();
+
+        // the original file should have been moved, as the file consumer should be resilient
against
+        // end users changing headers
+        assertTrue("File should been moved", new File("target/files/.camel/hello.txt").getAbsoluteFile().exists());
+    }
+
 }



Mime
View raw message