You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ha...@apache.org on 2011/06/01 19:21:48 UTC
svn commit: r1130232 -
/camel/trunk/camel-core/src/test/java/org/apache/camel/issues/ExceptionTest.java
Author: hadrian
Date: Wed Jun 1 17:21:47 2011
New Revision: 1130232
URL: http://svn.apache.org/viewvc?rev=1130232&view=rev
Log:
CAMEL-4022. Added test showing the problem. The resolution will depend on feedback
Modified:
camel/trunk/camel-core/src/test/java/org/apache/camel/issues/ExceptionTest.java
Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/issues/ExceptionTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/issues/ExceptionTest.java?rev=1130232&r1=1130231&r2=1130232&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/issues/ExceptionTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/issues/ExceptionTest.java Wed Jun 1 17:21:47 2011
@@ -21,6 +21,8 @@ import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
+import org.junit.Ignore;
+import org.junit.Test;
/**
* @version
@@ -89,12 +91,43 @@ public class ExceptionTest extends Conte
assertMockEndpointsSatisfied();
}
+ public void testExceptionWithFatalException() throws Exception {
+ MockEndpoint resultEndpoint = getMockEndpoint("mock:result");
+ MockEndpoint exceptionEndpoint = getMockEndpoint("mock:exception");
+ MockEndpoint fatalEndpoint = getMockEndpoint("mock:fatal");
+ MockEndpoint errorEndpoint = getMockEndpoint("mock:error");
+
+ fatalEndpoint.expectedMessageCount(0);
+ exceptionEndpoint.expectedMessageCount(0);
+ resultEndpoint.expectedMessageCount(0);
+ errorEndpoint.expectedMessageCount(1);
+ // TODO: CAMEL-4022. Message should probably not go to DLC for this scenario
+ // We need agree on a solution and implement it. See jira for more details.
+ errorEndpoint.expectedBodiesReceived("<some-value/>");
+
+ try {
+ template.sendBody("direct:start2", "<body/>");
+ } catch (Exception e) {
+ // expected
+ }
+
+ assertMockEndpointsSatisfied();
+ }
+
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
final Processor exceptionThrower = new Processor() {
public void process(Exchange exchange) throws Exception {
- exchange.getIn().setBody("<exception/>");
- throw new IllegalArgumentException("Exception thrown intentionally.");
+ String body = exchange.getIn().getBody(String.class);
+ body = body.substring(1, body.length() - 2);
+ boolean fatal = body.equals("exception") || body.indexOf(' ') != -1;
+ String message = fatal ? "FATAL " : "";
+ body = fatal ? message + body : "exception";
+
+ // TODO: CAMEL-4022. Set a breakpoint here and see the body growing "FATAl FATAL ... Exception thrown"
+ // See discussion in the issue above for solution found (which will probably lead to changing this test
+ exchange.getIn().setBody("<" + body + "/>");
+ throw new IllegalArgumentException(message + "Exception thrown");
}
};
@@ -109,6 +142,9 @@ public class ExceptionTest extends Conte
} else if (getName().endsWith("WithHandler")) {
log.debug("Using exception handler");
onException(IllegalArgumentException.class).to("mock:exception");
+ } else if (getName().endsWith("WithFatalException")) {
+ log.debug("Using fatal exception");
+ onException(IllegalArgumentException.class).process(exceptionThrower).to("mock:fatal");
}
from("direct:start").process(exceptionThrower).to("mock:result");
from("direct:start2").to("direct:intermediate").to("mock:result");