use of org.apache.camel.model.RouteDefinition in project camel by apache.
the class PropertiesComponentAdviceWithInterceptSendToEndpointTest method testAdviceWithInterceptSendToEndpoint.
public void testAdviceWithInterceptSendToEndpoint() throws Exception {
RouteDefinition route = context.getRouteDefinition("foo");
route.adviceWith(context, new RouteBuilder() {
@Override
public void configure() throws Exception {
interceptSendToEndpoint("{{cool.mock}}:res*").to("mock:foo");
}
});
getMockEndpoint("mock:foo").expectedMessageCount(1);
getMockEndpoint("mock:result").expectedMessageCount(1);
template.sendBody("direct:start", "Hello World");
assertMockEndpointsSatisfied();
}
use of org.apache.camel.model.RouteDefinition in project camel by apache.
the class CamelContextAddRouteDefinitionsFromXmlTest method testAddRouteDefinitionsFromXml2.
public void testAddRouteDefinitionsFromXml2() throws Exception {
RouteDefinition route = loadRoute("route2.xml");
assertNotNull(route);
assertEquals("foo", route.getId());
assertEquals(0, context.getRoutes().size());
context.addRouteDefinition(route);
assertEquals(1, context.getRoutes().size());
assertTrue("Route should be stopped", context.getRouteStatus("foo").isStopped());
context.startRoute("foo");
assertTrue("Route should be started", context.getRouteStatus("foo").isStarted());
getMockEndpoint("mock:result").expectedBodiesReceived("Hello World");
template.sendBody("direct:start", "Hello World");
assertMockEndpointsSatisfied();
}
use of org.apache.camel.model.RouteDefinition in project camel by apache.
the class TwoRouteScopedOnExceptionWithInterceptSendToEndpointIssueWithPredicateTest method testIssue.
public void testIssue() throws Exception {
final Predicate fail = PredicateBuilder.or(header(Exchange.REDELIVERY_COUNTER).isNull(), header(Exchange.REDELIVERY_COUNTER).isLessThan(5));
RouteDefinition route = context.getRouteDefinitions().get(0);
route.adviceWith(context, new RouteBuilder() {
@Override
public void configure() throws Exception {
interceptSendToEndpoint("seda:*").skipSendToOriginalEndpoint().process(new Processor() {
public void process(Exchange exchange) throws Exception {
invoked.incrementAndGet();
if (fail.matches(exchange)) {
throw new ConnectException("Forced");
}
}
}).to("mock:ok");
}
});
getMockEndpoint("mock:global").expectedMessageCount(0);
getMockEndpoint("mock:ok").expectedMessageCount(1);
getMockEndpoint("mock:exhausted").expectedMessageCount(0);
template.sendBody("direct:start", "Hello World");
assertMockEndpointsSatisfied();
// 5 retry + 1 ok
assertEquals(6, invoked.get());
}
use of org.apache.camel.model.RouteDefinition in project camel by apache.
the class RandomLoadBalanceJavaDSLBuilderTest method testNavigateRouteAsJavaDSL.
public void testNavigateRouteAsJavaDSL() throws Exception {
// this one navigate using the route definition
StringBuilder sb = new StringBuilder();
RouteDefinition route = context.getRouteDefinitions().get(0);
// the start of the route
sb.append("from(\"" + route.getInputs().get(0).getUri() + "\")");
// navigate the route and add Java DSL to the sb
navigateDefinition(route, sb);
// output the Java DSL
assertEquals("from(\"direct://start\").loadBalance().random().to(\"mock://x\").to(\"mock://y\").to(\"mock://z\")", sb.toString());
}
use of org.apache.camel.model.RouteDefinition in project camel by apache.
the class XmlRouteContextImportTest method verifyRouteContext.
@Test
public void verifyRouteContext() {
assertThat("Route context is incorrect!", routes, hasSize(1));
RouteDefinition route = routes.get(0);
assertThat("Route input is incorrect!", route.getInputs(), hasSize(1));
assertThat("Route is incorrect!", route.getInputs().get(0).getEndpointUri(), is(equalTo("direct:inbound")));
}
Aggregations