camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r888719 - in /camel/trunk/camel-core/src: main/java/org/apache/camel/model/CatchDefinition.java test/java/org/apache/camel/processor/TryCatchMustHaveExceptionConfiguredTest.java
Date Wed, 09 Dec 2009 07:39:50 GMT
Author: davsclaus
Date: Wed Dec  9 07:39:50 2009
New Revision: 888719

URL: http://svn.apache.org/viewvc?rev=888719&view=rev
Log:
CAMEL-2269: doCatch should validate at least one exception configured to catch.

Added:
    camel/trunk/camel-core/src/test/java/org/apache/camel/processor/TryCatchMustHaveExceptionConfiguredTest.java
      - copied, changed from r888706, camel/trunk/camel-core/src/test/java/org/apache/camel/processor/TryCatchContinueToRouteTest.java
Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/model/CatchDefinition.java

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/model/CatchDefinition.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/model/CatchDefinition.java?rev=888719&r1=888718&r2=888719&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/model/CatchDefinition.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/model/CatchDefinition.java Wed Dec
 9 07:39:50 2009
@@ -87,6 +87,11 @@
 
     @Override
     public CatchProcessor createProcessor(RouteContext routeContext) throws Exception {
+        // must have at least one exception
+        if (getExceptionClasses().isEmpty()) {
+            throw new IllegalArgumentException("At least one Exception must be configured
to catch");
+        }
+
         Processor childProcessor = routeContext.createProcessor(this);
 
         Predicate when = null;

Copied: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/TryCatchMustHaveExceptionConfiguredTest.java
(from r888706, camel/trunk/camel-core/src/test/java/org/apache/camel/processor/TryCatchContinueToRouteTest.java)
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/TryCatchMustHaveExceptionConfiguredTest.java?p2=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/TryCatchMustHaveExceptionConfiguredTest.java&p1=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/TryCatchContinueToRouteTest.java&r1=888706&r2=888719&rev=888719&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/processor/TryCatchContinueToRouteTest.java
(original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/processor/TryCatchMustHaveExceptionConfiguredTest.java
Wed Dec  9 07:39:50 2009
@@ -17,48 +17,39 @@
 package org.apache.camel.processor;
 
 import org.apache.camel.ContextTestSupport;
-import org.apache.camel.Exchange;
+import org.apache.camel.FailedToCreateRouteException;
 import org.apache.camel.builder.RouteBuilder;
 
 /**
  * @version $Revision$
  */
-public class TryCatchContinueToRouteTest extends ContextTestSupport {
+public class TryCatchMustHaveExceptionConfiguredTest extends ContextTestSupport {
 
-    public void testTryCatchContinueToRoute() throws Exception {
-        getMockEndpoint("mock:a").expectedBodiesReceived("Hello World");
-        getMockEndpoint("mock:b").expectedBodiesReceived("Hello World");
-        getMockEndpoint("mock:catch").expectedBodiesReceived("Hello World");
-        getMockEndpoint("mock:catch").message(0).property(Exchange.EXCEPTION_CAUGHT).isInstanceOf(IllegalArgumentException.class);
-        getMockEndpoint("mock:c").expectedBodiesReceived("Hello World");
-        getMockEndpoint("mock:c").message(0).property(Exchange.EXCEPTION_CAUGHT).isInstanceOf(IllegalArgumentException.class);
-
-        template.sendBody("direct:a", "Hello World");
-
-        assertMockEndpointsSatisfied();
-    }
-
-    @Override
-    protected RouteBuilder createRouteBuilder() throws Exception {
-        return new RouteBuilder() {
+    public void testTryCatchMustHaveExceptionConfigured() throws Exception {
+        context.addRoutes(new RouteBuilder() {
             @Override
             public void configure() throws Exception {
                 from("direct:a")
-                    .to("mock:a")
-                    .to("direct:b")
-                    .to("direct:c");
-
-                from("direct:b")
                     .doTry()
                         .to("mock:b")
                         .throwException(new IllegalArgumentException("Damn"))
-                    .doCatch(Exception.class)
+                    .doCatch()
                         .to("mock:catch")
                     .end();
-
-                from("direct:c")
-                    .to("mock:c");
             }
-        };
+        });
+
+        try {
+            context.start();
+            fail("Should throw exception");
+        } catch (FailedToCreateRouteException e) {
+            assertIsInstanceOf(IllegalArgumentException.class, e.getCause());
+            assertEquals("At least one Exception must be configured to catch", e.getCause().getMessage());
+        }
+    }
+
+    @Override
+    public boolean isUseRouteBuilder() {
+        return false;
     }
-}
+}
\ No newline at end of file



Mime
View raw message