camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject svn commit: r959183 - in /camel/trunk: camel-core/src/main/java/org/apache/camel/component/file/ camel-core/src/test/java/org/apache/camel/component/file/ components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/
Date Wed, 30 Jun 2010 03:58:30 GMT
Author: ningjiang
Date: Wed Jun 30 03:58:30 2010
New Revision: 959183

URL: http://svn.apache.org/viewvc?rev=959183&view=rev
Log:
CAMEL-2878 Throw exception to avoid specifying the delete=true&moveFailed=xxx for the
FileEndpoint at the same time

Added:
    camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerDeleteAndMoveFailureTest.java
  (with props)
Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileEndpoint.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerMoveFailureTest.java
    camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileEndpoint.java

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileEndpoint.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileEndpoint.java?rev=959183&r1=959182&r2=959183&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileEndpoint.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileEndpoint.java
Wed Jun 30 03:58:30 2010
@@ -67,8 +67,8 @@ public class FileEndpoint extends Generi
 
         FileConsumer result = new FileConsumer(this, processor, operations);
 
-        if (isDelete() && getMove() != null) {
-            throw new IllegalArgumentException("You cannot set both delete=true and move
options");
+        if (isDelete() && (getMove() != null || getMoveFailed() != null)) {
+            throw new IllegalArgumentException("You cannot set both delete=true and move
or moveFailed options");
         }
 
         // if noop=true then idempotent should also be configured

Added: camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerDeleteAndMoveFailureTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerDeleteAndMoveFailureTest.java?rev=959183&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerDeleteAndMoveFailureTest.java
(added)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerDeleteAndMoveFailureTest.java
Wed Jun 30 03:58:30 2010
@@ -0,0 +1,67 @@
+/**
+ * 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.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+
+/**
+ * @version $Revision$
+ */
+public class FileConsumerDeleteAndMoveFailureTest extends ContextTestSupport {
+
+    @Override
+    protected void setUp() throws Exception {
+        deleteDirectory("target/failed");
+        super.setUp();
+    }
+
+    public void testMoveFailed() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:result");
+        mock.expectedBodiesReceived("Hello World IS processed!");
+        
+        mock.expectedFileExists("target/failed/error/bye.txt", "Kabom");
+
+        template.sendBodyAndHeader("file://target/failed", "Hello World", Exchange.FILE_NAME,
"hello.txt");
+        template.sendBodyAndHeader("file://target/failed", "Kabom", Exchange.FILE_NAME, "bye.txt");
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                onException(IllegalArgumentException.class).useOriginalMessage().to("file://target/failed/error");
+                from("file://target/failed?delete=true")
+                    .setBody(simple("${body} IS processed!"))
+                    .process(new Processor() {
+                        public void process(Exchange exchange) throws Exception {
+                            String body = exchange.getIn().getBody(String.class);
+                            if (body != null && body.startsWith("Kabom")) {
+                                throw new IllegalArgumentException("Forced");
+                            }
+                        }
+                    }).to("mock:result");
+            }
+        };
+    }
+}

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

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

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerMoveFailureTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerMoveFailureTest.java?rev=959183&r1=959182&r2=959183&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerMoveFailureTest.java
(original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerMoveFailureTest.java
Wed Jun 30 03:58:30 2010
@@ -33,33 +33,49 @@ public class FileConsumerMoveFailureTest
         super.setUp();
     }
 
-    public void testMoveFailed() throws Exception {
+    public void testMoveFailedWithOnException() throws Exception {
         MockEndpoint mock = getMockEndpoint("mock:result");
-        mock.expectedBodiesReceived("Hello World");
-
-        mock.expectedFileExists("target/failed/.camel/hello.txt", "Hello World");
-        mock.expectedFileExists("target/failed/error/bye-error.txt", "Kabom");
+        mock.expectedBodiesReceived("Hello World IS processed!");
+        
+        mock.expectedFileExists("target/failed/error/bye.txt", "Kabom");
 
         template.sendBodyAndHeader("file://target/failed", "Hello World", Exchange.FILE_NAME,
"hello.txt");
         template.sendBodyAndHeader("file://target/failed", "Kabom", Exchange.FILE_NAME, "bye.txt");
 
         assertMockEndpointsSatisfied();
     }
+    
+    public void testDeletAndMoveFailedOption() throws Exception {
+        try {
+            context.addRoutes(new RouteBuilder() {
+                public void configure() throws Exception {
+                    from("file://target/test?delete=true&moveFailed=target/failed/error").to("mock:failed");
+                }
+            });
+            fail("Expect an exception here");
+        } catch (IllegalArgumentException ex) {
+            // expect the error here
+            ex.getMessage().startsWith("You cannot set both deleted=true and move");
+        }
+        
+    }
 
     @Override
     protected RouteBuilder createRouteBuilder() throws Exception {
         return new RouteBuilder() {
             @Override
             public void configure() throws Exception {
-                from("file://target/failed?moveFailed=error/${file:name.noext}-error.txt")
+                onException(IllegalArgumentException.class).useOriginalMessage().to("file://target/failed/error");
+                from("file://target/failed?delete=true")
+                    .setBody(simple("${body} IS processed!"))
                     .process(new Processor() {
                         public void process(Exchange exchange) throws Exception {
                             String body = exchange.getIn().getBody(String.class);
-                            if ("Kabom".equals(body)) {
+                            if (body != null && body.startsWith("Kabom")) {
                                 throw new IllegalArgumentException("Forced");
                             }
                         }
-                    }).convertBodyTo(String.class).to("mock:result");
+                    }).to("mock:result");
             }
         };
     }

Modified: camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileEndpoint.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileEndpoint.java?rev=959183&r1=959182&r2=959183&view=diff
==============================================================================
--- camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileEndpoint.java
(original)
+++ camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileEndpoint.java
Wed Jun 30 03:58:30 2010
@@ -63,8 +63,8 @@ public abstract class RemoteFileEndpoint
         afterPropertiesSet();
         RemoteFileConsumer<T> consumer = buildConsumer(processor);
 
-        if (isDelete() && getMove() != null) {
-            throw new IllegalArgumentException("You cannot both set delete=true and move
options");
+        if (isDelete() && (getMove() != null || getMoveFailed() != null)) {
+            throw new IllegalArgumentException("You cannot both set delete=true and move
or moveFailed options");
         }
         // if noop=true then idempotent should also be configured
         if (isNoop() && !isIdempotent()) {



Mime
View raw message