use of org.apache.camel.builder.AdviceWithRouteBuilder in project camel by apache.
the class AdviceWithTasksSelectTest method testSelectIndexZero.
public void testSelectIndexZero() throws Exception {
context.getRouteDefinitions().get(0).adviceWith(context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
// should match the first index (0 based)
weaveById("gold*").selectIndex(0).replace().multicast().to("mock:a").to("mock:b");
}
});
getMockEndpoint("mock:foo").expectedMessageCount(0);
getMockEndpoint("mock:bar").expectedMessageCount(1);
getMockEndpoint("mock:baz").expectedMessageCount(1);
getMockEndpoint("mock:a").expectedMessageCount(1);
getMockEndpoint("mock:b").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 AdviceWithTasksSelectTest method testSelectIndexOutOfBounds.
public void testSelectIndexOutOfBounds() throws Exception {
try {
context.getRouteDefinitions().get(0).adviceWith(context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
// should be out of bounds
weaveById("gold*").selectIndex(3).replace().multicast().to("mock:a").to("mock:b");
}
});
fail("Should hve thrown exception");
} catch (IllegalArgumentException e) {
assertTrue(e.getMessage(), e.getMessage().startsWith("There are no outputs which matches: gold* in the route"));
}
}
use of org.apache.camel.builder.AdviceWithRouteBuilder in project camel by apache.
the class AdviceWithTasksSelectTest method testSelectLast.
public void testSelectLast() throws Exception {
context.getRouteDefinitions().get(0).adviceWith(context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
// should only match the last
weaveById("gold*").selectLast().replace().multicast().to("mock:a").to("mock:b");
}
});
getMockEndpoint("mock:foo").expectedMessageCount(1);
getMockEndpoint("mock:bar").expectedMessageCount(1);
getMockEndpoint("mock:baz").expectedMessageCount(0);
getMockEndpoint("mock:a").expectedMessageCount(1);
getMockEndpoint("mock:b").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 AdviceWithTasksTest 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 node in the route which has id = bar and remove it
weaveById("bar").remove();
}
});
// END SNIPPET: e2
getMockEndpoint("mock:foo").expectedMessageCount(1);
getMockEndpoint("mock:result").expectedMessageCount(1);
template.sendBody("direct:start", "Hello World");
assertMockEndpointsSatisfied();
assertTrue("Should have removed mock:bar endpoint", context.hasEndpoint("mock:bar") == null);
}
use of org.apache.camel.builder.AdviceWithRouteBuilder in project camel by apache.
the class AdviceWithTasksTest method testUnknownId.
public void testUnknownId() throws Exception {
try {
context.getRouteDefinitions().get(0).adviceWith(context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
weaveById("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"));
}
}
Aggregations