Search in sources :

Example 61 with Route

use of org.apache.camel.Route in project camel by apache.

the class RouteBuilderTest method testThreads.

public void testThreads() throws Exception {
    List<Route> routes = buildThreads();
    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());
        Pipeline line = assertIsInstanceOf(Pipeline.class, channel.getNextProcessor());
        Iterator<?> it = line.getProcessors().iterator();
        assertIsInstanceOf(ThreadsProcessor.class, it.next());
        // output should be wrapped in a pipeline
        Pipeline threadsLine = assertIsInstanceOf(Pipeline.class, it.next());
        Iterator<Processor> it2 = threadsLine.getProcessors().iterator();
        assertIsInstanceOf(SendProcessor.class, unwrapChannel(it2.next()).getNextProcessor());
        assertIsInstanceOf(SendProcessor.class, unwrapChannel(it2.next()).getNextProcessor());
    }
}
Also used : DelegateProcessor(org.apache.camel.DelegateProcessor) Processor(org.apache.camel.Processor) MulticastProcessor(org.apache.camel.processor.MulticastProcessor) FilterProcessor(org.apache.camel.processor.FilterProcessor) EvaluateExpressionProcessor(org.apache.camel.processor.EvaluateExpressionProcessor) ThreadsProcessor(org.apache.camel.processor.ThreadsProcessor) SendProcessor(org.apache.camel.processor.SendProcessor) ChoiceProcessor(org.apache.camel.processor.ChoiceProcessor) Endpoint(org.apache.camel.Endpoint) Channel(org.apache.camel.Channel) DeadLetterChannel(org.apache.camel.processor.DeadLetterChannel) EventDrivenConsumerRoute(org.apache.camel.impl.EventDrivenConsumerRoute) Route(org.apache.camel.Route) EventDrivenConsumerRoute(org.apache.camel.impl.EventDrivenConsumerRoute) Pipeline(org.apache.camel.processor.Pipeline)

Example 62 with Route

use of org.apache.camel.Route in project camel by apache.

the class RouteBuilderTest method testSimpleRouteWithHeaderPredicate.

public void testSimpleRouteWithHeaderPredicate() throws Exception {
    List<Route> routes = buildSimpleRouteWithHeaderPredicate();
    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());
        FilterProcessor filterProcessor = assertIsInstanceOf(FilterProcessor.class, channel.getNextProcessor());
        SendProcessor sendProcessor = assertIsInstanceOf(SendProcessor.class, unwrapChannel(filterProcessor).getNextProcessor());
        assertEquals("Endpoint URI", "direct://b", sendProcessor.getDestination().getEndpointUri());
    }
}
Also used : Endpoint(org.apache.camel.Endpoint) FilterProcessor(org.apache.camel.processor.FilterProcessor) Channel(org.apache.camel.Channel) DeadLetterChannel(org.apache.camel.processor.DeadLetterChannel) EventDrivenConsumerRoute(org.apache.camel.impl.EventDrivenConsumerRoute) SendProcessor(org.apache.camel.processor.SendProcessor) Route(org.apache.camel.Route) EventDrivenConsumerRoute(org.apache.camel.impl.EventDrivenConsumerRoute)

Example 63 with Route

use of org.apache.camel.Route in project camel by apache.

the class RouteBuilderTest method testRouteDynamicReceipentList.

public void testRouteDynamicReceipentList() throws Exception {
    List<Route> routes = buildDynamicRecipientList();
    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());
        Pipeline line = assertIsInstanceOf(Pipeline.class, channel.getNextProcessor());
        Iterator<?> it = line.getProcessors().iterator();
        // EvaluateExpressionProcessor should be wrapped in error handler
        Object first = it.next();
        first = assertIsInstanceOf(DeadLetterChannel.class, first).getOutput();
        assertIsInstanceOf(EvaluateExpressionProcessor.class, first);
        // and the second should NOT be wrapped in error handler
        Object second = it.next();
        assertIsInstanceOf(RecipientList.class, second);
    }
}
Also used : Endpoint(org.apache.camel.Endpoint) Channel(org.apache.camel.Channel) DeadLetterChannel(org.apache.camel.processor.DeadLetterChannel) EventDrivenConsumerRoute(org.apache.camel.impl.EventDrivenConsumerRoute) Route(org.apache.camel.Route) EventDrivenConsumerRoute(org.apache.camel.impl.EventDrivenConsumerRoute) Pipeline(org.apache.camel.processor.Pipeline)

Example 64 with Route

use of org.apache.camel.Route in project camel by apache.

the class RouteBuilderTest method testCustomProcessor.

public void testCustomProcessor() throws Exception {
    List<Route> routes = buildCustomProcessor();
    assertEquals("Number routes created", 1, routes.size());
    for (Route route : routes) {
        Endpoint key = route.getEndpoint();
        assertEquals("From endpoint", "direct://a", key.getEndpointUri());
    }
}
Also used : Endpoint(org.apache.camel.Endpoint) Route(org.apache.camel.Route) EventDrivenConsumerRoute(org.apache.camel.impl.EventDrivenConsumerRoute)

Example 65 with Route

use of org.apache.camel.Route in project camel by apache.

the class RouteBuilderTest method testIdempotentConsumer.

public void testIdempotentConsumer() throws Exception {
    List<Route> routes = buildIdempotentConsumer();
    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());
        IdempotentConsumer idempotentConsumer = assertIsInstanceOf(IdempotentConsumer.class, channel.getNextProcessor());
        assertEquals("messageIdExpression", "header(myMessageId)", idempotentConsumer.getMessageIdExpression().toString());
        assertIsInstanceOf(MemoryIdempotentRepository.class, idempotentConsumer.getIdempotentRepository());
        SendProcessor sendProcessor = assertIsInstanceOf(SendProcessor.class, unwrapChannel(idempotentConsumer.getProcessor()).getNextProcessor());
        assertEquals("Endpoint URI", "direct://b", sendProcessor.getDestination().getEndpointUri());
    }
}
Also used : Endpoint(org.apache.camel.Endpoint) Channel(org.apache.camel.Channel) DeadLetterChannel(org.apache.camel.processor.DeadLetterChannel) EventDrivenConsumerRoute(org.apache.camel.impl.EventDrivenConsumerRoute) IdempotentConsumer(org.apache.camel.processor.idempotent.IdempotentConsumer) SendProcessor(org.apache.camel.processor.SendProcessor) Route(org.apache.camel.Route) EventDrivenConsumerRoute(org.apache.camel.impl.EventDrivenConsumerRoute)

Aggregations

Route (org.apache.camel.Route)90 EventDrivenConsumerRoute (org.apache.camel.impl.EventDrivenConsumerRoute)27 Endpoint (org.apache.camel.Endpoint)24 Channel (org.apache.camel.Channel)17 DeadLetterChannel (org.apache.camel.processor.DeadLetterChannel)15 Processor (org.apache.camel.Processor)13 ArrayList (java.util.ArrayList)12 SendProcessor (org.apache.camel.processor.SendProcessor)11 CamelContext (org.apache.camel.CamelContext)10 ShutdownRoute (org.apache.camel.ShutdownRoute)8 FilterProcessor (org.apache.camel.processor.FilterProcessor)7 RoutePolicy (org.apache.camel.spi.RoutePolicy)6 HashMap (java.util.HashMap)5 Service (org.apache.camel.Service)5 LinkedHashMap (java.util.LinkedHashMap)4 Map (java.util.Map)4 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)4 DelegateProcessor (org.apache.camel.DelegateProcessor)4 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)4 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)4