Search in sources :

Example 76 with ProducerTemplate

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

the class PojoDualCamelContextConsumerTest method testCamel1RecipientList.

public void testCamel1RecipientList() throws Exception {
    String body = "<hello>world!</hello>";
    // seda:foo has no consumer in camel-1 so we should not expect any messages to be routed to result/foo
    MockEndpoint result = camel1.getEndpoint("mock:result", MockEndpoint.class);
    result.expectedMessageCount(0);
    ProducerTemplate template = camel1.createProducerTemplate();
    template.start();
    template.sendBody("seda:foo", body);
    template.stop();
    Thread.sleep(200);
    result.assertIsSatisfied();
}
Also used : ProducerTemplate(org.apache.camel.ProducerTemplate) MockEndpoint(org.apache.camel.component.mock.MockEndpoint)

Example 77 with ProducerTemplate

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

the class ContainerWideInterceptorTest method testOne.

public void testOne() throws Exception {
    int start = myInterceptor.getCount();
    MockEndpoint result = camel1.getEndpoint("mock:result", MockEndpoint.class);
    result.expectedBodiesReceived("Hello World");
    ProducerTemplate template = camel1.createProducerTemplate();
    template.start();
    template.sendBody("direct:one", "Hello World");
    template.stop();
    result.assertIsSatisfied();
    // lets see if the counter is +1 since last (has 1 step in the route)
    int delta = myInterceptor.getCount() - start;
    assertEquals("Should have been counted +1", 1, delta);
}
Also used : ProducerTemplate(org.apache.camel.ProducerTemplate) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) MockEndpoint(org.apache.camel.component.mock.MockEndpoint)

Example 78 with ProducerTemplate

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

the class ProducerTemplateMaximumCacheSizeTest method testTemplateMaximumCache.

@Test
public void testTemplateMaximumCache() throws Exception {
    assertNotNull("Should have injected a producer template", template);
    ProducerTemplate lookup = context.getRegistry().lookupByNameAndType("template", ProducerTemplate.class);
    assertNotNull("Should lookup producer template", lookup);
    assertEquals(50, template.getMaximumCacheSize());
    assertEquals("Size should be 0", 0, template.getCurrentCacheSize());
    // test that we cache at most 50 producers to avoid it eating to much memory
    for (int i = 0; i < 53; i++) {
        Endpoint e = context.getEndpoint("seda:queue:" + i);
        template.sendBody(e, "Hello");
    }
    // the eviction is async so force cleanup
    template.cleanUp();
    assertEquals("Size should be 50", 50, template.getCurrentCacheSize());
    template.stop();
    // should be 0
    assertEquals("Size should be 0", 0, template.getCurrentCacheSize());
}
Also used : ProducerTemplate(org.apache.camel.ProducerTemplate) Endpoint(org.apache.camel.Endpoint) Endpoint(org.apache.camel.Endpoint) Test(org.junit.Test)

Example 79 with ProducerTemplate

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

the class RouteAutoStartupPropertiesTest method testAutoStartupTrue.

public void testAutoStartupTrue() throws Exception {
    ac = new ClassPathXmlApplicationContext("org/apache/camel/spring/config/RouteAutoStartupTrueTest.xml");
    SpringCamelContext camel = ac.getBeansOfType(SpringCamelContext.class).values().iterator().next();
    assertEquals(true, camel.getRouteStatus("bar").isStarted());
    // and now we can send a message to the route and see that it works
    MockEndpoint mock = camel.getEndpoint("mock:result", MockEndpoint.class);
    mock.expectedMessageCount(1);
    ProducerTemplate template = camel.createProducerTemplate();
    template.start();
    template.sendBody("direct:start", "Hello World");
    template.stop();
    mock.assertIsSatisfied();
}
Also used : ProducerTemplate(org.apache.camel.ProducerTemplate) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) SpringCamelContext(org.apache.camel.spring.SpringCamelContext)

Example 80 with ProducerTemplate

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

the class SqlProducerOutputTypeSelectOneTest method testSelectOneWithClass.

@Test
public void testSelectOneWithClass() throws Exception {
    camel1.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("direct:start").to("sql:select * from projects where id=3?outputType=SelectOne&outputClass=org.apache.camel.component.sql.ProjectModel").to("mock:result");
        }
    });
    camel1.start();
    ProducerTemplate template = camel1.createProducerTemplate();
    MockEndpoint mock = (MockEndpoint) camel1.getEndpoint("mock:result");
    mock.expectedMessageCount(1);
    template.sendBody("direct:start", "testmsg");
    mock.assertIsSatisfied(2000);
    List<Exchange> exchanges = mock.getReceivedExchanges();
    Assert.assertThat(exchanges.size(), CoreMatchers.is(1));
    ProjectModel result = exchanges.get(0).getIn().getBody(ProjectModel.class);
    Assert.assertThat(result.getId(), CoreMatchers.is(3));
    Assert.assertThat(result.getProject(), CoreMatchers.is("Linux"));
    Assert.assertThat(result.getLicense(), CoreMatchers.is("XXX"));
}
Also used : Exchange(org.apache.camel.Exchange) ProducerTemplate(org.apache.camel.ProducerTemplate) RouteBuilder(org.apache.camel.builder.RouteBuilder) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Test(org.junit.Test)

Aggregations

ProducerTemplate (org.apache.camel.ProducerTemplate)130 Test (org.junit.Test)58 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)53 CamelContext (org.apache.camel.CamelContext)48 Exchange (org.apache.camel.Exchange)36 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)27 Deployment (org.activiti.engine.test.Deployment)16 RouteBuilder (org.apache.camel.builder.RouteBuilder)16 Processor (org.apache.camel.Processor)8 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)8 HashMap (java.util.HashMap)7 Task (org.activiti.engine.task.Task)7 Endpoint (org.apache.camel.Endpoint)7 File (java.io.File)6 ArrayList (java.util.ArrayList)5 Message (org.apache.camel.Message)4 List (java.util.List)3 ExecutorService (java.util.concurrent.ExecutorService)3 HistoricVariableInstance (org.activiti.engine.history.HistoricVariableInstance)3 ConsumerTemplate (org.apache.camel.ConsumerTemplate)3