use of org.apache.camel.builder.AdviceWithRouteBuilder in project camel by apache.
the class AdviceWithTasksTest method testAfter.
public void testAfter() throws Exception {
// START SNIPPET: e4
context.getRouteDefinitions().get(0).adviceWith(context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
// weave the node in the route which has id = bar
// and insert the following route path after the advice node
weaveById("bar").after().to("mock:a").transform(constant("Bye World"));
}
});
// END SNIPPET: e4
getMockEndpoint("mock:foo").expectedBodiesReceived("Hello World");
getMockEndpoint("mock:a").expectedBodiesReceived("Hello World");
getMockEndpoint("mock:bar").expectedBodiesReceived("Hello World");
getMockEndpoint("mock:result").expectedBodiesReceived("Bye World");
template.sendBody("direct:start", "Hello World");
assertMockEndpointsSatisfied();
}
use of org.apache.camel.builder.AdviceWithRouteBuilder in project camel by apache.
the class AdviceWithTasksToStringPatternTest method testReplace.
public void testReplace() throws Exception {
// START SNIPPET: e1
context.getRouteDefinitions().get(0).adviceWith(context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
// weave nodes in the route which has foo anywhere in their to string representation
// and replace them with the following route path
weaveByToString(".*foo.*").replace().multicast().to("mock:a").to("mock:b");
}
});
// END SNIPPET: e1
getMockEndpoint("mock:foo").expectedMessageCount(0);
getMockEndpoint("mock:a").expectedMessageCount(1);
getMockEndpoint("mock:b").expectedMessageCount(1);
getMockEndpoint("mock:bar").expectedMessageCount(1);
getMockEndpoint("mock:result").expectedMessageCount(1);
template.sendBody("direct:start", "Hello World");
assertMockEndpointsSatisfied();
}
use of org.apache.camel.builder.AdviceWithRouteBuilder in project camel by apache.
the class AdviceWithTasksToStringPatternTest method testUnknownId.
public void testUnknownId() throws Exception {
try {
context.getRouteDefinitions().get(0).adviceWith(context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
weaveByToString("xxx").replace().to("mock:xxx");
}
});
fail("Should hve thrown exception");
} catch (IllegalArgumentException e) {
assertTrue(e.getMessage(), e.getMessage().startsWith("There are no outputs which matches: xxx in the route"));
}
}
use of org.apache.camel.builder.AdviceWithRouteBuilder in project camel by apache.
the class AdviceWithTasksToStringPatternTest method testAfter.
public void testAfter() throws Exception {
context.getRouteDefinitions().get(0).adviceWith(context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
weaveByToString(".*bar.*").after().to("mock:a").transform(constant("Bye World"));
}
});
getMockEndpoint("mock:foo").expectedBodiesReceived("Hello World");
getMockEndpoint("mock:a").expectedBodiesReceived("Hello World");
getMockEndpoint("mock:bar").expectedBodiesReceived("Hello World");
getMockEndpoint("mock:result").expectedBodiesReceived("Bye World");
template.sendBody("direct:start", "Hello World");
assertMockEndpointsSatisfied();
}
use of org.apache.camel.builder.AdviceWithRouteBuilder in project camel by apache.
the class AdviceWithTryCatchTest method testTryCatch.
public void testTryCatch() throws Exception {
context.getRouteDefinitions().get(0).adviceWith(context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
weaveById("foo").replace().process(new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
throw new IllegalArgumentException("Kaboom");
}
});
}
});
getMockEndpoint("mock:before").expectedMessageCount(1);
getMockEndpoint("mock:after").expectedMessageCount(1);
getMockEndpoint("mock:error").expectedMessageCount(1);
template.sendBody("direct:start", "Hello World");
assertMockEndpointsSatisfied();
}
Aggregations