use of org.apache.camel.model.RouteDefinition in project camel by apache.
the class ErrorHandlerAdviceIssueTest method testErrorHandlerAdvice.
public void testErrorHandlerAdvice() throws Exception {
RouteDefinition foo = context.getRouteDefinition("foo");
foo.adviceWith(context, new RouteBuilder() {
@Override
public void configure() throws Exception {
interceptSendToEndpoint("seda:*").skipSendToOriginalEndpoint().throwException(new IllegalAccessException("Forced"));
}
});
RouteDefinition error = context.getRouteDefinition("error");
error.adviceWith(context, new RouteBuilder() {
@Override
public void configure() throws Exception {
interceptSendToEndpoint("file:*").skipSendToOriginalEndpoint().to("mock:file");
}
});
getMockEndpoint("mock:error").expectedMessageCount(1);
getMockEndpoint("mock:file").expectedMessageCount(1);
// should be intercepted
getMockEndpoint("mock:foo").expectedMessageCount(0);
context.stopRoute("timer");
template.sendBody("direct:start", "Hello World");
assertMockEndpointsSatisfied();
}
use of org.apache.camel.model.RouteDefinition in project camel by apache.
the class AdviceWithIssueTest method testAdviceWithOnCompletion.
public void testAdviceWithOnCompletion() throws Exception {
RouteDefinition route = context.getRouteDefinitions().get(0);
route.adviceWith(context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
onCompletion().to("mock:done");
}
});
getMockEndpoint("mock:result").expectedBodiesReceived("Hello World");
getMockEndpoint("mock:done").expectedBodiesReceived("Hello World");
template.sendBody("direct:start", "World");
assertMockEndpointsSatisfied();
}
use of org.apache.camel.model.RouteDefinition in project camel by apache.
the class AdviceWithIssueTest method testAdviceWithOnException.
public void testAdviceWithOnException() throws Exception {
RouteDefinition route = context.getRouteDefinitions().get(0);
route.adviceWith(context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
onException(IllegalArgumentException.class).handled(true).to("mock:error");
}
});
getMockEndpoint("mock:result").expectedBodiesReceived("Hello World");
getMockEndpoint("mock:error").expectedBodiesReceived("Kaboom");
template.sendBody("direct:start", "World");
template.sendBody("direct:start", "Kaboom");
assertMockEndpointsSatisfied();
}
use of org.apache.camel.model.RouteDefinition in project camel by apache.
the class AdviceWithIssueTest method testAdviceWithErrorHandler.
public void testAdviceWithErrorHandler() throws Exception {
RouteDefinition route = context.getRouteDefinitions().get(0);
try {
route.adviceWith(context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
errorHandler(deadLetterChannel("mock:dead"));
}
});
fail("Should have thrown exception");
} catch (IllegalArgumentException e) {
assertEquals("You can not advice with error handlers. Remove the error handlers from the route builder.", e.getMessage());
}
}
use of org.apache.camel.model.RouteDefinition in project camel by apache.
the class AdviceWithInterceptSendToEndpointWithLoadbalancerTest method testInterceptSendToEndpoint.
public void testInterceptSendToEndpoint() throws Exception {
context.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:start").loadBalance().failover().to("seda:end1", "seda:end2");
}
});
RouteDefinition route = context.getRouteDefinitions().get(0);
route.adviceWith(context, new RouteBuilder() {
public void configure() throws Exception {
interceptSendToEndpoint("seda:end1").skipSendToOriginalEndpoint().to("mock:end");
}
});
context.start();
getMockEndpoint("mock:end").expectedMessageCount(1);
template.sendBody("direct:start", "Hello World");
assertMockEndpointsSatisfied();
}
Aggregations