use of org.apache.camel.builder.AdviceWithRouteBuilder in project camel by apache.
the class AdviceWithTasksSelectTest method testSelectRangeOneTwo.
public void testSelectRangeOneTwo() throws Exception {
context.getRouteDefinitions().get(0).adviceWith(context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
// should match the 2nd and 3rd (0-based)
weaveById("gold*").selectRange(1, 2).replace().multicast().to("mock:a").to("mock:b");
}
});
getMockEndpoint("mock:foo").expectedMessageCount(1);
getMockEndpoint("mock:bar").expectedMessageCount(0);
getMockEndpoint("mock:baz").expectedMessageCount(0);
getMockEndpoint("mock:a").expectedMessageCount(2);
getMockEndpoint("mock:b").expectedMessageCount(2);
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 AdviceWithTwoRoutesTest method testAdviceWithA.
public void testAdviceWithA() throws Exception {
RouteDefinition route = context.getRouteDefinition("a");
route.adviceWith(context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
interceptSendToEndpoint("mock://a").skipSendToOriginalEndpoint().to("mock:detour");
}
});
getMockEndpoint("mock:a").expectedMessageCount(0);
getMockEndpoint("mock:detour").expectedMessageCount(1);
template.sendBody("direct:a", "Hello World");
assertMockEndpointsSatisfied();
}
use of org.apache.camel.builder.AdviceWithRouteBuilder in project camel by apache.
the class AdviceWithTypeTest method testRemove.
public void testRemove() throws Exception {
// START SNIPPET: e2
context.getRouteDefinitions().get(0).adviceWith(context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
// weave the type in the route and remove it
weaveByType(TransformDefinition.class).remove();
}
});
// END SNIPPET: e2
getMockEndpoint("mock:result").expectedBodiesReceived("World");
template.sendBody("direct:start", "World");
assertMockEndpointsSatisfied();
}
use of org.apache.camel.builder.AdviceWithRouteBuilder in project camel by apache.
the class AdviceWithTypeTest method testUnknownType.
public void testUnknownType() throws Exception {
try {
context.getRouteDefinitions().get(0).adviceWith(context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
weaveByType(SplitDefinition.class).replace().to("mock:xxx");
}
});
fail("Should hve thrown exception");
} catch (IllegalArgumentException e) {
assertTrue(e.getMessage(), e.getMessage().startsWith("There are no outputs which matches: SplitDefinition in the route"));
}
}
Aggregations