You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ni...@apache.org on 2010/09/02 07:10:45 UTC

svn commit: r991814 - in /camel/trunk/camel-core/src: main/java/org/apache/camel/component/file/ main/java/org/apache/camel/language/simple/ test/java/org/apache/camel/component/file/

Author: ningjiang
Date: Thu Sep  2 05:10:44 2010
New Revision: 991814

URL: http://svn.apache.org/viewvc?rev=991814&view=rev
Log:
CAMEL-3100  should return 0 instead of null if the file length is zero

Added:
    camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerIntercepEmptyFileTest.java   (with props)
Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFile.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/language/simple/SimpleLanguage.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=991814&r1=991813&r2=991814&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 Thu Sep  2 05:10:44 2010
@@ -122,7 +122,8 @@ public class GenericFile<T>  {
             message.setHeader("CamelFileRelativePath", getRelativeFilePath());
             message.setHeader(Exchange.FILE_PARENT, getParent());
     
-            if (getFileLength() > 0) {
+            if (getFileLength() >= 0) {
+                System.out.println("The file length is " + getFileLength());
                 message.setHeader("CamelFileLength", getFileLength());
             }
             if (getLastModified() > 0) {

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/language/simple/SimpleLanguage.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/language/simple/SimpleLanguage.java?rev=991814&r1=991813&r2=991814&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/language/simple/SimpleLanguage.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/language/simple/SimpleLanguage.java Thu Sep  2 05:10:44 2010
@@ -72,6 +72,7 @@ import org.apache.camel.util.StringHelpe
  *   <li><tt>file:absolute</tt> is the file regarded as absolute or relative</li>
  *   <li><tt>file:absolute.path</tt> to access the absolute file path name</li>
  *   <li><tt>file:length</tt> to access the file length as a Long type</li>
+ *   <li><tt>file:size</tt> to access the file length as a Long type</li>
  *   <li><tt>file:modified</tt> to access the file last modified as a Date type</li>
  *   <li><tt>date:&lt;command&gt;:&lt;pattern&gt;</tt> for date formatting using the {@link java.text.SimpleDateFormat} patterns.
  *     Additional Supported commands are: <tt>file</tt> for the last modified timestamp of the file.

Added: camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerIntercepEmptyFileTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerIntercepEmptyFileTest.java?rev=991814&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerIntercepEmptyFileTest.java (added)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerIntercepEmptyFileTest.java Thu Sep  2 05:10:44 2010
@@ -0,0 +1,63 @@
+/**
+ * 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 org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+
+/**
+ * Unit test that file consumer will exclude pre and postfixes
+ */
+public class FileConsumerIntercepEmptyFileTest extends ContextTestSupport {
+
+    public void testExludePreAndPostfixes() throws Exception {
+        deleteDirectory("./target/exclude");
+        
+        MockEndpoint mock1 = getMockEndpoint("mock:result");
+        mock1.expectedMessageCount(4);
+        
+        MockEndpoint mock2 = getMockEndpoint("mock:skip");
+        mock2.expectedMessageCount(2);
+        
+        prepareFiles();
+        
+        
+        
+        assertMockEndpointsSatisfied();
+    }
+
+    private void prepareFiles() throws Exception {
+        String url = "file://target/exclude";
+        template.sendBodyAndHeader(url, "Hello World", Exchange.FILE_NAME, "hello.xml");
+        template.sendBodyAndHeader(url, "", Exchange.FILE_NAME, "empty1.txt");
+        template.sendBodyAndHeader(url, "Bye World", Exchange.FILE_NAME, "secret.txt");
+        template.sendBodyAndHeader(url, "", Exchange.FILE_NAME, "empty2.txt");
+    }
+
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            public void configure() throws Exception {
+                interceptFrom().when(simple("${file:length} == 0")).to("mock:skip");
+                from("file://target/exclude/")
+                    .convertBodyTo(String.class).to("log:test").to("mock:result");
+            }
+        };
+    }
+
+}

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

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