use of org.apache.camel.builder.AdviceWithRouteBuilder in project camel by apache.
the class AdviceWithTwoRoutesTest 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().to("mock:detour");
}
});
route = context.getRouteDefinition("b");
route.adviceWith(context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
interceptSendToEndpoint("mock://b").skipSendToOriginalEndpoint().to("mock:detour");
}
});
getMockEndpoint("mock:a").expectedMessageCount(0);
getMockEndpoint("mock:b").expectedMessageCount(0);
getMockEndpoint("mock:detour").expectedMessageCount(2);
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 AdviceWithTypeTest 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 by type in the route
// and replace it with the following route path
weaveByType(LogDefinition.class).replace().multicast().to("mock:a").to("mock:b");
}
});
// END SNIPPET: e1
getMockEndpoint("mock:a").expectedMessageCount(1);
getMockEndpoint("mock:b").expectedMessageCount(1);
getMockEndpoint("mock:result").expectedBodiesReceived("Hello World");
template.sendBody("direct:start", "World");
assertMockEndpointsSatisfied();
}
use of org.apache.camel.builder.AdviceWithRouteBuilder in project camel by apache.
the class AdviceWithTypeTest 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 type in the route and remove it
// and insert the following route path after the adviced node
weaveByType(ToDefinition.class).after().transform(constant("Bye World"));
}
});
// END SNIPPET: e4
getMockEndpoint("mock:result").expectedBodiesReceived("Hello World");
Object out = template.requestBody("direct:start", "World");
assertEquals("Bye World", out);
assertMockEndpointsSatisfied();
}
use of org.apache.camel.builder.AdviceWithRouteBuilder in project camel by apache.
the class AdviceWithTypeTest method testBefore.
public void testBefore() throws Exception {
// START SNIPPET: e3
context.getRouteDefinitions().get(0).adviceWith(context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
// weave the type in the route and remove it
// and insert the following route path before the adviced node
weaveByType(ToDefinition.class).before().transform(constant("Bye World"));
}
});
// END SNIPPET: e3
getMockEndpoint("mock:result").expectedBodiesReceived("Bye World");
template.sendBody("direct:start", "World");
assertMockEndpointsSatisfied();
}
use of org.apache.camel.builder.AdviceWithRouteBuilder in project camel by apache.
the class AdviceWithWeaveAfterLastSplitTest method testAfterLastSplit.
public void testAfterLastSplit() throws Exception {
context.getRouteDefinitions().get(0).adviceWith(context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
weaveAddLast().log("weaveAddLast: ${body}").to("mock:result");
}
});
context.start();
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedMessageCount(1);
template.sendBody("direct:input", "1,2");
mock.assertIsSatisfied();
}
Aggregations