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();
}
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);
}
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());
}
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();
}
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"));
}
Aggregations