use of org.apache.camel.builder.AdviceWithRouteBuilder in project camel by apache.
the class AdviceWithWeaveFirstLastTest method testWeaveAddLast.
public void testWeaveAddLast() throws Exception {
// START SNIPPET: e2
context.getRouteDefinitions().get(0).adviceWith(context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
// insert at the end of the existing route, the given piece of route
weaveAddLast().to("mock:a").transform(constant("Bye World"));
}
});
// END SNIPPET: e2
getMockEndpoint("mock:a").expectedBodiesReceived("Hello World");
getMockEndpoint("mock:foo").expectedBodiesReceived("Hello World");
getMockEndpoint("mock:bar").expectedBodiesReceived("Hello World");
getMockEndpoint("mock:result").expectedBodiesReceived("Hello World");
Object out = template.requestBody("direct:start", "Hello World");
assertEquals("Bye World", out);
assertMockEndpointsSatisfied();
}
use of org.apache.camel.builder.AdviceWithRouteBuilder in project camel by apache.
the class AdviceWithWeaveLastCBRTest method testWeaveByToUriAndAddLast.
public void testWeaveByToUriAndAddLast() throws Exception {
context.getRouteDefinitions().get(0).adviceWith(context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
weaveByToUri("mock:foo").replace().to("mock:foo2");
// insert at the end of the existing route, the given piece of route
weaveAddLast().to("mock:last");
}
});
getMockEndpoint("mock:foo").expectedMessageCount(0);
getMockEndpoint("mock:foo2").expectedMessageCount(1);
getMockEndpoint("mock:bar").expectedMessageCount(0);
getMockEndpoint("mock:last").expectedMessageCount(1);
template.sendBodyAndHeader("direct:start", "Hello World", "foo", "yeah");
assertMockEndpointsSatisfied();
}
use of org.apache.camel.builder.AdviceWithRouteBuilder in project camel by apache.
the class AdviceWithWeaveToUriAndAddLastTest method testWeaveByToUriAndAddLast.
public void testWeaveByToUriAndAddLast() throws Exception {
context.getRouteDefinitions().get(0).adviceWith(context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
weaveByToUri("mock:foo").replace().to("mock:foo2");
// insert at the end of the existing route, the given piece of route
weaveAddLast().to("mock:last");
}
});
getMockEndpoint("mock:foo").expectedMessageCount(0);
getMockEndpoint("mock:foo2").expectedMessageCount(1);
getMockEndpoint("mock:last").expectedMessageCount(1);
template.sendBodyAndHeader("direct:start", "Hello World", "foo", "yeah");
assertMockEndpointsSatisfied();
}
use of org.apache.camel.builder.AdviceWithRouteBuilder in project camel by apache.
the class AdviceWithTwoRoutesOnExceptionTest 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().throwException(new IllegalArgumentException("Forced"));
}
});
getMockEndpoint("mock:a").expectedMessageCount(0);
getMockEndpoint("mock:error").expectedMessageCount(1);
getMockEndpoint("mock:error").message(0).exchangeProperty(Exchange.EXCEPTION_CAUGHT).isInstanceOf(IllegalArgumentException.class);
template.sendBody("direct:a", "Hello World");
assertMockEndpointsSatisfied();
}
use of org.apache.camel.builder.AdviceWithRouteBuilder in project camel by apache.
the class AdviceWithTwoRoutesTest 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().to("mock:detour");
}
});
getMockEndpoint("mock:b").expectedMessageCount(0);
getMockEndpoint("mock:detour").expectedMessageCount(1);
template.sendBody("direct:b", "Hello World");
assertMockEndpointsSatisfied();
}
Aggregations