use of org.apache.camel.Route in project camel by apache.
the class RouteBuilderTest method testSimpleRouteWithChoice.
public void testSimpleRouteWithChoice() throws Exception {
List<Route> routes = buildSimpleRouteWithChoice();
log.debug("Created routes: " + routes);
assertEquals("Number routes created", 1, routes.size());
for (Route route : routes) {
Endpoint key = route.getEndpoint();
assertEquals("From endpoint", "direct://a", key.getEndpointUri());
EventDrivenConsumerRoute consumer = assertIsInstanceOf(EventDrivenConsumerRoute.class, route);
Channel channel = unwrapChannel(consumer.getProcessor());
ChoiceProcessor choiceProcessor = assertIsInstanceOf(ChoiceProcessor.class, channel.getNextProcessor());
List<FilterProcessor> filters = choiceProcessor.getFilters();
assertEquals("Should be two when clauses", 2, filters.size());
Processor filter1 = filters.get(0);
assertSendTo(unwrapChannel(((FilterProcessor) filter1).getProcessor()).getNextProcessor(), "direct://b");
Processor filter2 = filters.get(1);
assertSendTo(unwrapChannel(((FilterProcessor) filter2).getProcessor()).getNextProcessor(), "direct://c");
assertSendTo(unwrapChannel(choiceProcessor.getOtherwise()).getNextProcessor(), "direct://d");
}
}
use of org.apache.camel.Route in project camel by apache.
the class ErrorHandlerTest method testConfigureDeadLetterChannel.
public void testConfigureDeadLetterChannel() throws Exception {
// START SNIPPET: e3
RouteBuilder builder = new RouteBuilder() {
public void configure() {
// using dead letter channel with a seda queue for errors
errorHandler(deadLetterChannel("seda:errors"));
// here is our route
from("seda:a").to("seda:b");
}
};
// END SNIPPET: e3
List<Route> list = getRouteList(builder);
assertEquals("Number routes created" + list, 1, list.size());
for (Route route : list) {
Endpoint key = route.getEndpoint();
assertEquals("From endpoint", "seda://a", key.getEndpointUri());
EventDrivenConsumerRoute consumerRoute = assertIsInstanceOf(EventDrivenConsumerRoute.class, route);
Channel channel = unwrapChannel(consumerRoute.getProcessor());
assertIsInstanceOf(SendProcessor.class, channel.getNextProcessor());
}
}
use of org.apache.camel.Route in project camel by apache.
the class ContextErrorHandlerTest method testGetTheDefaultErrorHandlerFromContext.
public void testGetTheDefaultErrorHandlerFromContext() throws Exception {
RouteBuilder builder = new RouteBuilder() {
public void configure() {
from("seda:a").to("seda:b");
from("direct:c").to("direct:d");
}
};
List<Route> list = getRouteListWithCurrentContext(builder);
assertEquals("Number routes created" + list, 2, list.size());
for (Route route : list) {
EventDrivenConsumerRoute consumerRoute = assertIsInstanceOf(EventDrivenConsumerRoute.class, route);
Processor processor = consumerRoute.getProcessor();
Channel channel = unwrapChannel(processor);
DeadLetterChannel deadLetterChannel = assertIsInstanceOf(DeadLetterChannel.class, channel.getErrorHandler());
RedeliveryPolicy redeliveryPolicy = deadLetterChannel.getRedeliveryPolicy();
assertEquals("getMaximumRedeliveries()", 1, redeliveryPolicy.getMaximumRedeliveries());
assertEquals("isUseExponentialBackOff()", true, redeliveryPolicy.isUseExponentialBackOff());
}
}
use of org.apache.camel.Route in project camel by apache.
the class RouteSedaSuspendResumeTest method testSuspendResume.
public void testSuspendResume() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedBodiesReceived("A");
template.sendBody("seda:foo", "A");
assertMockEndpointsSatisfied();
log.info("Suspending");
// now suspend and dont expect a message to be routed
resetMocks();
mock.expectedMessageCount(0);
context.suspendRoute("foo");
assertEquals("Suspended", context.getRouteStatus("foo").name());
Route route = context.getRoute("foo");
if (route instanceof StatefulService) {
assertEquals("Suspended", ((StatefulService) route).getStatus().name());
}
// need to give seda consumer thread time to idle
Thread.sleep(500);
template.sendBody("seda:foo", "B");
mock.assertIsSatisfied(1000);
log.info("Resuming");
// now resume and expect the previous message to be routed
resetMocks();
mock.expectedBodiesReceived("B");
context.resumeRoute("foo");
assertMockEndpointsSatisfied();
assertEquals("Started", context.getRouteStatus("foo").name());
route = context.getRoute("foo");
if (route instanceof StatefulService) {
assertEquals("Started", ((StatefulService) route).getStatus().name());
}
}
use of org.apache.camel.Route in project camel by apache.
the class LoadRouteFromXmlWithNamespaceTest method testLoadRouteWithNamespaceFromXml.
public void testLoadRouteWithNamespaceFromXml() throws Exception {
InputStream inputStream = getClass().getResourceAsStream("routeWithNamespace.xml");
RoutesDefinition routes = context.loadRoutesDefinition(inputStream);
context.addRouteDefinitions(routes.getRoutes());
context.start();
Route routeWithNamespace = context.getRoute("routeWithNamespace");
assertNotNull("Expected to find route with id: routeWithNamespace", routeWithNamespace);
MockEndpoint bar = context.getEndpoint("mock:bar", MockEndpoint.class);
bar.expectedBodiesReceived("Hello from foo");
// Make sure loaded route can process a XML payload with namespaces attached
context.createProducerTemplate().sendBody("direct:foo", "<?xml version='1.0'?><foo xmlns='http://foo'><bar>cheese</bar></foo>");
bar.assertIsSatisfied();
}
Aggregations