Search in sources :

Example 51 with RouteBuilder

use of org.apache.camel.builder.RouteBuilder in project camel by apache.

the class DirectClientAPITest method testDirectCallFromCamelWithConversion.

@Test
public void testDirectCallFromCamelWithConversion() throws Exception {
    new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("direct:source").to("direct:stream").setBody().simple("after stream: ${body}").to("mock:dest");
        }
    }.addRoutesToCamelContext(context);
    context.start();
    camel.process("direct:stream", Integer.class, p -> Flowable.fromPublisher(p).map(i -> -i));
    for (int i = 1; i <= 3; i++) {
        template.sendBody("direct:source", i);
    }
    MockEndpoint mock = getMockEndpoint("mock:dest");
    mock.expectedMessageCount(3);
    mock.assertIsSatisfied();
    int id = 1;
    for (Exchange ex : mock.getExchanges()) {
        String content = ex.getIn().getBody(String.class);
        assertEquals("after stream: " + (-id++), content);
    }
}
Also used : TimeUnit(java.util.concurrent.TimeUnit) Flowable(io.reactivex.Flowable) ReactiveStreamsTestSupport(org.apache.camel.component.reactive.streams.support.ReactiveStreamsTestSupport) RouteBuilder(org.apache.camel.builder.RouteBuilder) Publisher(org.reactivestreams.Publisher) LinkedBlockingDeque(java.util.concurrent.LinkedBlockingDeque) BlockingQueue(java.util.concurrent.BlockingQueue) Exchange(org.apache.camel.Exchange) Test(org.junit.Test) JndiRegistry(org.apache.camel.impl.JndiRegistry) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Exchange(org.apache.camel.Exchange) RouteBuilder(org.apache.camel.builder.RouteBuilder) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Test(org.junit.Test)

Example 52 with RouteBuilder

use of org.apache.camel.builder.RouteBuilder in project camel by apache.

the class EventTypeTest method testOnCompleteHeaderForwarded.

@Test
public void testOnCompleteHeaderForwarded() throws Exception {
    new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("reactive-streams:numbers?forwardOnComplete=true").to("mock:endpoint");
        }
    }.addRoutesToCamelContext(context);
    Subscriber<Integer> numbers = CamelReactiveStreams.get(context).streamSubscriber("numbers", Integer.class);
    context.start();
    Flowable.<Integer>empty().subscribe(numbers);
    MockEndpoint endpoint = getMockEndpoint("mock:endpoint");
    endpoint.expectedMessageCount(1);
    endpoint.expectedHeaderReceived(ReactiveStreamsConstants.REACTIVE_STREAMS_EVENT_TYPE, "onComplete");
    endpoint.expectedBodiesReceived(new Object[] { null });
    endpoint.assertIsSatisfied();
}
Also used : RouteBuilder(org.apache.camel.builder.RouteBuilder) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Test(org.junit.Test)

Example 53 with RouteBuilder

use of org.apache.camel.builder.RouteBuilder in project camel by apache.

the class BeanCallTest method beanCallTest.

@Test
public void beanCallTest() throws Exception {
    new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            onException(Throwable.class).to("direct:handle").handled(true);
            from("direct:num").bean(BeanCallTest.this, "processBody").process(// Can be removed?
            new UnwrapStreamProcessor()).to("mock:endpoint");
            from("direct:handle").setBody().constant("ERR").to("mock:endpoint");
        }
    }.addRoutesToCamelContext(context);
    MockEndpoint mock = getMockEndpoint("mock:endpoint");
    mock.expectedMessageCount(1);
    context.start();
    template.sendBody("direct:num", 1);
    mock.assertIsSatisfied();
    Exchange exchange = mock.getExchanges().get(0);
    assertEquals("HelloBody 1", exchange.getIn().getBody());
}
Also used : Exchange(org.apache.camel.Exchange) UnwrapStreamProcessor(org.apache.camel.component.reactive.streams.util.UnwrapStreamProcessor) RouteBuilder(org.apache.camel.builder.RouteBuilder) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Test(org.junit.Test)

Example 54 with RouteBuilder

use of org.apache.camel.builder.RouteBuilder in project camel by apache.

the class BeanCallTest method beanCallWithErrorTest.

@Test
public void beanCallWithErrorTest() throws Exception {
    new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            onException(Throwable.class).to("direct:handle").handled(true);
            from("direct:num").bean(BeanCallTest.this, "processBodyWrongType").process(// Can be removed?
            new UnwrapStreamProcessor()).to("mock:endpoint");
            from("direct:handle").setBody().constant("ERR").to("mock:endpoint");
        }
    }.addRoutesToCamelContext(context);
    MockEndpoint mock = getMockEndpoint("mock:endpoint");
    mock.expectedMessageCount(1);
    context.start();
    template.sendBody("direct:num", 1);
    mock.assertIsSatisfied();
    Exchange exchange = mock.getExchanges().get(0);
    assertEquals("ERR", exchange.getIn().getBody());
}
Also used : Exchange(org.apache.camel.Exchange) UnwrapStreamProcessor(org.apache.camel.component.reactive.streams.util.UnwrapStreamProcessor) RouteBuilder(org.apache.camel.builder.RouteBuilder) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Test(org.junit.Test)

Example 55 with RouteBuilder

use of org.apache.camel.builder.RouteBuilder in project camel by apache.

the class BeanCallTest method beanCallEmptyPublisherTest.

@Test
public void beanCallEmptyPublisherTest() throws Exception {
    new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            onException(Throwable.class).to("direct:handle").handled(true);
            from("direct:num").bean(BeanCallTest.this, "processBodyEmpty").process(// Can be removed?
            new UnwrapStreamProcessor()).to("mock:endpoint");
            from("direct:handle").setBody().constant("ERR").to("mock:endpoint");
        }
    }.addRoutesToCamelContext(context);
    MockEndpoint mock = getMockEndpoint("mock:endpoint");
    mock.expectedMessageCount(1);
    context.start();
    template.sendBody("direct:num", 1);
    mock.assertIsSatisfied();
    Exchange exchange = mock.getExchanges().get(0);
    Object body = exchange.getIn().getBody();
    // unchanged
    assertEquals(new Integer(1), body);
}
Also used : Exchange(org.apache.camel.Exchange) UnwrapStreamProcessor(org.apache.camel.component.reactive.streams.util.UnwrapStreamProcessor) RouteBuilder(org.apache.camel.builder.RouteBuilder) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Test(org.junit.Test)

Aggregations

RouteBuilder (org.apache.camel.builder.RouteBuilder)1759 Exchange (org.apache.camel.Exchange)628 Processor (org.apache.camel.Processor)545 Test (org.junit.Test)476 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)341 CamelExecutionException (org.apache.camel.CamelExecutionException)135 FailedToCreateRouteException (org.apache.camel.FailedToCreateRouteException)119 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)104 File (java.io.File)68 CamelContext (org.apache.camel.CamelContext)64 IOException (java.io.IOException)61 ResolveEndpointFailedException (org.apache.camel.ResolveEndpointFailedException)42 HashMap (java.util.HashMap)35 Path (org.apache.hadoop.fs.Path)34 CountDownLatch (java.util.concurrent.CountDownLatch)32 Configuration (org.apache.hadoop.conf.Configuration)32 Endpoint (org.apache.camel.Endpoint)30 ArrayFile (org.apache.hadoop.io.ArrayFile)30 SequenceFile (org.apache.hadoop.io.SequenceFile)30 RuntimeCamelException (org.apache.camel.RuntimeCamelException)26