use of org.apache.camel.builder.AdviceWithRouteBuilder in project camel by apache.
the class AdviceWithTasksTest 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 the node in the route which has id = bar
// and replace it with the following route path
weaveById("bar").replace().multicast().to("mock:a").to("mock:b");
}
});
// END SNIPPET: e1
getMockEndpoint("mock:foo").expectedMessageCount(1);
getMockEndpoint("mock:bar").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 AdviceWithTasksToStringPatternTest method testRemove.
public void testRemove() throws Exception {
context.getRouteDefinitions().get(0).adviceWith(context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
weaveByToString(".*bar.*").remove();
}
});
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 AdviceWithTasksToStringPatternTest method testBefore.
public void testBefore() throws Exception {
context.getRouteDefinitions().get(0).adviceWith(context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
weaveByToString(".*bar.*").before().to("mock:a").transform(constant("Bye World"));
}
});
getMockEndpoint("mock:foo").expectedBodiesReceived("Hello World");
getMockEndpoint("mock:a").expectedBodiesReceived("Hello World");
getMockEndpoint("mock:bar").expectedBodiesReceived("Bye 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 AdviceWithAutoStartupTest method testAdvised.
public void testAdvised() throws Exception {
assertFalse(context.getRouteStatus("foo").isStarted());
assertFalse(context.getRouteStatus("bar").isStarted());
context.getRouteDefinition("bar").adviceWith(context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
replaceFromWith("seda:newBar");
}
});
assertFalse(context.getRouteStatus("foo").isStarted());
assertFalse(context.getRouteStatus("bar").isStarted());
context.startRoute("foo");
context.startRoute("bar");
assertTrue(context.getRouteStatus("foo").isStarted());
assertTrue(context.getRouteStatus("bar").isStarted());
getMockEndpoint("mock:newBar").expectedMessageCount(1);
template.sendBody("direct:start", "Hello World");
assertMockEndpointsSatisfied();
}
use of org.apache.camel.builder.AdviceWithRouteBuilder in project camel by apache.
the class AdviceWithMockEndpointsHavingParameterTest method testAdvisedMockEndpoints.
public void testAdvisedMockEndpoints() throws Exception {
// advice the first route using the inlined AdviceWith route builder
// which has extended capabilities than the regular route builder
context.getRouteDefinitions().get(1).adviceWith(context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
// mock all endpoints (will mock in all routes)
mockEndpoints();
}
});
getMockEndpoint("mock:result").expectedBodiesReceived("Hello World");
getMockEndpoint("mock:foo").expectedBodiesReceived("Bye World");
getMockEndpoint("mock:direct:start").expectedBodiesReceived("Hello World");
getMockEndpoint("mock:log:start").expectedBodiesReceived("Hello World");
getMockEndpoint("mock:seda:foo").expectedBodiesReceived("Hello World");
template.sendBody("direct:start", "Hello World");
assertMockEndpointsSatisfied();
// additional test to ensure correct endpoints in registry
assertNotNull(context.hasEndpoint("direct:start"));
assertNotNull(context.hasEndpoint("seda:foo"));
assertNotNull(context.hasEndpoint("log:foo?showHeaders=false"));
assertNotNull(context.hasEndpoint("log:start?showAll=true"));
assertNotNull(context.hasEndpoint("mock:result"));
// all the endpoints was mocked
assertNotNull(context.hasEndpoint("mock:direct:start"));
assertNotNull(context.hasEndpoint("mock:seda:foo"));
assertNotNull(context.hasEndpoint("mock:log:start"));
assertNotNull(context.hasEndpoint("mock:log:foo"));
}
Aggregations