use of org.apache.camel.builder.AdviceWithRouteBuilder in project camel by apache.
the class AdviceWithTwoRoutesOnExceptionTest method testAdviceWithB.
public void testAdviceWithB() throws Exception {
RouteDefinition route = context.getRouteDefinition("b");
route.adviceWith(context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
interceptSendToEndpoint("mock://b").skipSendToOriginalEndpoint().throwException(new IllegalArgumentException("Forced"));
}
});
getMockEndpoint("mock:b").expectedMessageCount(0);
getMockEndpoint("mock:error").expectedMessageCount(1);
getMockEndpoint("mock:error").message(0).exchangeProperty(Exchange.EXCEPTION_CAUGHT).isInstanceOf(IllegalArgumentException.class);
template.sendBody("direct:b", "Hello World");
assertMockEndpointsSatisfied();
}
use of org.apache.camel.builder.AdviceWithRouteBuilder in project camel by apache.
the class AdviceWithTwoRoutesOnExceptionTest method testAdviceWithAB.
public void testAdviceWithAB() throws Exception {
RouteDefinition route = context.getRouteDefinition("a");
route.adviceWith(context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
interceptSendToEndpoint("mock://a").skipSendToOriginalEndpoint().throwException(new IllegalArgumentException("Forced"));
}
});
route = context.getRouteDefinition("b");
route.adviceWith(context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
interceptSendToEndpoint("mock://b").skipSendToOriginalEndpoint().throwException(new IllegalArgumentException("Forced"));
}
});
getMockEndpoint("mock:a").expectedMessageCount(0);
getMockEndpoint("mock:b").expectedMessageCount(0);
getMockEndpoint("mock:error").expectedMessageCount(2);
getMockEndpoint("mock:error").message(0).exchangeProperty(Exchange.EXCEPTION_CAUGHT).isInstanceOf(IllegalArgumentException.class);
getMockEndpoint("mock:error").message(1).exchangeProperty(Exchange.EXCEPTION_CAUGHT).isInstanceOf(IllegalArgumentException.class);
template.sendBody("direct:a", "Hello World");
template.sendBody("direct:b", "Bye World");
assertMockEndpointsSatisfied();
}
use of org.apache.camel.builder.AdviceWithRouteBuilder in project camel by apache.
the class AdviceWithMockEndpointsTest method testAdvisedMockEndpoints.
// START SNIPPET: e1
// tag::e1[]
public void testAdvisedMockEndpoints() throws Exception {
// advice the first route using the inlined AdviceWith route builder
// which has extended capabilities than the regular route builder
context.getRouteDefinitions().get(0).adviceWith(context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
// mock all endpoints
mockEndpoints();
}
});
getMockEndpoint("mock:direct:start").expectedBodiesReceived("Hello World");
getMockEndpoint("mock:direct:foo").expectedBodiesReceived("Hello World");
getMockEndpoint("mock:log:foo").expectedBodiesReceived("Bye World");
getMockEndpoint("mock:result").expectedBodiesReceived("Bye World");
template.sendBody("direct:start", "Hello World");
assertMockEndpointsSatisfied();
// additional test to ensure correct endpoints in registry
assertNotNull(context.hasEndpoint("direct:start"));
assertNotNull(context.hasEndpoint("direct:foo"));
assertNotNull(context.hasEndpoint("log:foo"));
assertNotNull(context.hasEndpoint("mock:result"));
// all the endpoints was mocked
assertNotNull(context.hasEndpoint("mock:direct:start"));
assertNotNull(context.hasEndpoint("mock:direct:foo"));
assertNotNull(context.hasEndpoint("mock:log:foo"));
}
use of org.apache.camel.builder.AdviceWithRouteBuilder in project camel by apache.
the class AdviceWithMockEndpointsWithSkipTest method testAdvisedMockEndpointsWithSkip.
// START SNIPPET: e1
public void testAdvisedMockEndpointsWithSkip() throws Exception {
// advice the first route using the inlined AdviceWith route builder
// which has extended capabilities than the regular route builder
context.getRouteDefinitions().get(0).adviceWith(context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
// mock sending to direct:foo and skip send to it
mockEndpointsAndSkip("direct:foo");
}
});
getMockEndpoint("mock:result").expectedBodiesReceived("Hello World");
getMockEndpoint("mock:direct:foo").expectedMessageCount(1);
template.sendBody("direct:start", "Hello World");
assertMockEndpointsSatisfied();
// the message was not send to the direct:foo route and thus not sent to the seda endpoint
SedaEndpoint seda = context.getEndpoint("seda:foo", SedaEndpoint.class);
assertEquals(0, seda.getCurrentQueueSize());
}
use of org.apache.camel.builder.AdviceWithRouteBuilder in project camel by apache.
the class AdviceWithRecipientListMockEndpointsTest method testAdvisedMockEndpoints.
public void testAdvisedMockEndpoints() throws Exception {
// advice the second route using the inlined AdviceWith route builder
// which has extended capabilities than the regular route builder
context.getRouteDefinitions().get(1).adviceWith(context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
// mock all endpoints
mockEndpoints("log*");
}
});
// log:bar is a dynamic endpoint created on-the-fly (eg not in the route)
getMockEndpoint("mock:log:bar").expectedMessageCount(1);
// log:foo is in the route
getMockEndpoint("mock:log:foo").expectedMessageCount(1);
getMockEndpoint("mock:result").expectedMessageCount(1);
template.sendBodyAndHeader("direct:start", "Hello World", "foo", "log:bar,direct:foo");
assertMockEndpointsSatisfied();
}
Aggregations