Search in sources :

Example 91 with Producer

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

the class TimerEndpointTest method testCreateProducer.

@Test
public void testCreateProducer() throws Exception {
    Producer producer = endpoint.createProducer();
    assertThat(producer, is(notNullValue()));
    assertThat(producer, is(instanceOf(TimerProducer.class)));
}
Also used : Producer(org.apache.camel.Producer) Test(org.junit.Test)

Example 92 with Producer

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

the class MinaFiltersTest method testFilter.

private void testFilter(final String uri) throws Exception {
    context.addRoutes(new RouteBuilder() {

        public void configure() throws Exception {
            from(uri).to("mock:result");
        }
    });
    MockEndpoint mock = this.getMockEndpoint("mock:result");
    mock.expectedBodiesReceived("Hello World");
    Endpoint endpoint = context.getEndpoint(uri);
    Exchange exchange = endpoint.createExchange();
    Producer producer = endpoint.createProducer();
    producer.start();
    // set input and execute it
    exchange.getIn().setBody("Hello World");
    producer.process(exchange);
    assertMockEndpointsSatisfied();
    assertEquals("The filter should have been called twice (producer and consumer)", 2, TestFilter.called);
    producer.stop();
}
Also used : Exchange(org.apache.camel.Exchange) RouteBuilder(org.apache.camel.builder.RouteBuilder) Endpoint(org.apache.camel.Endpoint) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Producer(org.apache.camel.Producer) MockEndpoint(org.apache.camel.component.mock.MockEndpoint)

Example 93 with Producer

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

the class MinaLoggerOptionTest method testNoLoggerOption.

@Test
public void testNoLoggerOption() throws Exception {
    final String uri = "mina:tcp://localhost:{{port}}?textline=true&sync=false";
    context.addRoutes(new RouteBuilder() {

        public void configure() throws Exception {
            from(uri).to("mock:result");
        }
    });
    MockEndpoint mock = this.getMockEndpoint("mock:result");
    mock.expectedBodiesReceived("Hello World");
    Endpoint endpoint = context.getEndpoint(uri);
    Exchange exchange = endpoint.createExchange();
    Producer producer = endpoint.createProducer();
    producer.start();
    // set input and execute it
    exchange.getIn().setBody("Hello World");
    producer.process(exchange);
    Field field = producer.getClass().getDeclaredField("session");
    field.setAccessible(true);
    IoSession session = (IoSession) field.get(producer);
    assertFalse("There should NOT default be a logger filter", session.getFilterChain().contains("logger"));
    producer.stop();
    assertMockEndpointsSatisfied();
}
Also used : Exchange(org.apache.camel.Exchange) Field(java.lang.reflect.Field) RouteBuilder(org.apache.camel.builder.RouteBuilder) Endpoint(org.apache.camel.Endpoint) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Producer(org.apache.camel.Producer) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) IoSession(org.apache.mina.common.IoSession) Test(org.junit.Test)

Example 94 with Producer

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

the class MinaLoggerOptionTest method testLoggerOptionFalse.

@Test
public void testLoggerOptionFalse() throws Exception {
    final String uri = "mina:tcp://localhost:{{port}}?textline=true&minaLogger=false&sync=false";
    context.addRoutes(new RouteBuilder() {

        public void configure() throws Exception {
            from(uri).to("mock:result");
        }
    });
    MockEndpoint mock = this.getMockEndpoint("mock:result");
    mock.expectedBodiesReceived("Hello World");
    Endpoint endpoint = context.getEndpoint(uri);
    Exchange exchange = endpoint.createExchange();
    Producer producer = endpoint.createProducer();
    producer.start();
    // set input and execute it
    exchange.getIn().setBody("Hello World");
    producer.process(exchange);
    Field field = producer.getClass().getDeclaredField("session");
    field.setAccessible(true);
    IoSession session = (IoSession) field.get(producer);
    assertFalse("There should NOT be a logger filter", session.getFilterChain().contains("logger"));
    producer.stop();
    assertMockEndpointsSatisfied();
}
Also used : Exchange(org.apache.camel.Exchange) Field(java.lang.reflect.Field) RouteBuilder(org.apache.camel.builder.RouteBuilder) Endpoint(org.apache.camel.Endpoint) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Producer(org.apache.camel.Producer) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) IoSession(org.apache.mina.common.IoSession) Test(org.junit.Test)

Example 95 with Producer

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

the class CounterEndpointTest method testCreateProducer.

@Test
public void testCreateProducer() throws Exception {
    Producer producer = endpoint.createProducer();
    assertThat(producer, is(notNullValue()));
    assertThat(producer, is(instanceOf(CounterProducer.class)));
}
Also used : Producer(org.apache.camel.Producer) Test(org.junit.Test)

Aggregations

Producer (org.apache.camel.Producer)198 Endpoint (org.apache.camel.Endpoint)140 Exchange (org.apache.camel.Exchange)138 Test (org.junit.Test)72 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)69 Processor (org.apache.camel.Processor)34 RouteBuilder (org.apache.camel.builder.RouteBuilder)23 Message (org.apache.camel.Message)21 CountDownLatch (java.util.concurrent.CountDownLatch)16 File (java.io.File)12 CamelContext (org.apache.camel.CamelContext)12 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)10 DefaultExchange (org.apache.camel.impl.DefaultExchange)9 Mockito.anyLong (org.mockito.Mockito.anyLong)9 Consumer (org.apache.camel.Consumer)8 FileDataSource (javax.activation.FileDataSource)7 AsyncProcessor (org.apache.camel.AsyncProcessor)7 DataHandler (javax.activation.DataHandler)6 Field (java.lang.reflect.Field)5 ExchangePattern (org.apache.camel.ExchangePattern)5