use of org.apache.camel.model.RouteDefinition in project camel by apache.
the class AdviceWithIssueTest method testAdviceWithInterceptSendToEndpoint.
public void testAdviceWithInterceptSendToEndpoint() throws Exception {
RouteDefinition route = context.getRouteDefinitions().get(0);
route.adviceWith(context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
interceptSendToEndpoint("mock:result").to("mock:to");
}
});
getMockEndpoint("mock:result").expectedBodiesReceived("Hello World");
getMockEndpoint("mock:to").expectedBodiesReceived("Hello World");
getMockEndpoint("mock:to").expectedHeaderReceived(Exchange.INTERCEPTED_ENDPOINT, "mock://result");
template.sendBody("direct:start", "World");
assertMockEndpointsSatisfied();
}
use of org.apache.camel.model.RouteDefinition in project camel by apache.
the class AdviceWithOnExceptionAndInterceptTest method testFailover.
public void testFailover() throws Exception {
context.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:a").loadBalance().failover(IOException.class).to("mock:a").to("mock:b").end();
}
});
RouteDefinition routeDefinition = context.getRouteDefinitions().get(0);
routeDefinition.adviceWith(context, new AdviceWithRouteBuilder());
context.start();
getMockEndpoint("mock:a").expectedMessageCount(0);
getMockEndpoint("mock:b").expectedBodiesReceived("Intercepted SQL!");
template.sendBody("direct:a", "foo");
assertMockEndpointsSatisfied();
}
use of org.apache.camel.model.RouteDefinition in project camel by apache.
the class AdviceWithOnExceptionTest method testAdviceWithOnException.
public void testAdviceWithOnException() throws Exception {
RouteDefinition route = context.getRouteDefinitions().get(0);
route.adviceWith(context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
weaveById("b").after().to("mock:result");
}
});
context.start();
getMockEndpoint("mock:a").expectedMessageCount(1);
getMockEndpoint("mock:b").expectedMessageCount(1);
getMockEndpoint("mock:result").expectedMessageCount(1);
template.sendBody("direct:start", "Hello World");
assertMockEndpointsSatisfied();
}
use of org.apache.camel.model.RouteDefinition in project camel by apache.
the class AdviceWithPolicyTest method testAdviceWithPolicy.
public void testAdviceWithPolicy() throws Exception {
RouteDefinition route = context.getRouteDefinitions().get(0);
route.adviceWith(context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
weaveById("b").after().to("mock:result");
}
});
context.start();
getMockEndpoint("mock:a").expectedMessageCount(1);
getMockEndpoint("mock:b").expectedMessageCount(1);
getMockEndpoint("mock:result").expectedMessageCount(1);
template.sendBody("direct:start", "Hello World");
assertMockEndpointsSatisfied();
}
use of org.apache.camel.model.RouteDefinition in project camel by apache.
the class AdviceWithRoutePolicyTest method testAdviceRoutePolicyRemoved.
public void testAdviceRoutePolicyRemoved() throws Exception {
RouteDefinition route = context.getRouteDefinitions().get(0);
route.adviceWith(context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
// remove the route policy so we can test without it
getOriginalRoute().setRoutePolicies(null);
}
});
getMockEndpoint("mock:foo").expectedBodiesReceived("Hello World");
getMockEndpoint("mock:foo").message(0).header("MyRoutePolicy").isNull();
getMockEndpoint("mock:bar").expectedBodiesReceived("Hello World");
getMockEndpoint("mock:bar").message(0).header("MyRoutePolicy").isNull();
template.sendBody("direct:start", "Hello World");
assertMockEndpointsSatisfied();
}
Aggregations