use of org.apache.camel.ProducerTemplate in project camel by apache.
the class PropertyPlaceholderRouteTest method testCamelContext.
@Test
public void testCamelContext() throws Exception {
CamelContext context = getCamelContext();
assertNotNull(context);
assertEquals("MyCamel", context.getName());
ProducerTemplate template = context.createProducerTemplate();
MockEndpoint mock = context.getEndpoint("mock:result", MockEndpoint.class);
mock.expectedBodiesReceived("Hello World");
template.sendBody("direct:foo", "World");
mock.assertIsSatisfied();
template.stop();
}
use of org.apache.camel.ProducerTemplate in project camel by apache.
the class SnakeYAMLTestHelper method marshalAndUnmarshal.
public static void marshalAndUnmarshal(CamelContext context, Object body, String mockName, String directIn, String directBack, String expected) throws Exception {
MockEndpoint mock = context.getEndpoint(mockName, MockEndpoint.class);
assertNotNull(mock);
mock.expectedMessageCount(1);
mock.message(0).body().isInstanceOf(body.getClass());
mock.message(0).body().isEqualTo(body);
ProducerTemplate template = context.createProducerTemplate();
String result = template.requestBody(directIn, body, String.class);
assertNotNull(result);
assertEquals(expected, result.trim());
template.sendBody(directBack, result);
mock.assertIsSatisfied();
}
use of org.apache.camel.ProducerTemplate in project camel by apache.
the class SqlProducerOutputTypeSelectOneTest method testSelectOneWithoutClass.
@Test
public void testSelectOneWithoutClass() 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").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));
Map<String, Object> result = exchanges.get(0).getIn().getBody(Map.class);
Assert.assertThat((Integer) result.get("ID"), CoreMatchers.is(3));
Assert.assertThat((String) result.get("PROJECT"), CoreMatchers.is("Linux"));
Assert.assertThat((String) result.get("LICENSE"), CoreMatchers.is("XXX"));
}
use of org.apache.camel.ProducerTemplate in project camel by apache.
the class SqlProducerOutputTypeSelectOneTest method testSelectOneSingleColumnCount.
@Test
public void testSelectOneSingleColumnCount() throws Exception {
camel1.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:start").to("sql:select count(*) from projects?outputType=SelectOne").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));
Long result = exchanges.get(0).getIn().getBody(Long.class);
Assert.assertThat(result, CoreMatchers.is(3L));
}
use of org.apache.camel.ProducerTemplate in project camel by apache.
the class MainNoReloadTest method testMyMain.
@Test
public void testMyMain() throws Exception {
Main main = new Main();
main.setBundleName("MyMainBundle");
// as we run this test without packing ourselves as bundle, then include ourselves
main.setIncludeSelfAsBundle(true);
// setup the blueprint file here
main.setDescriptors("org/apache/camel/test/blueprint/main-no-reload-loadfile.xml");
// set the configAdmin persistent id
main.setConfigAdminPid("stuff");
// set the configAdmin persistent file name
main.setConfigAdminFileName("src/test/resources/etc/stuff.cfg");
main.start();
ProducerTemplate template = main.getCamelTemplate();
assertNotNull("We should get the template here", template);
String result = template.requestBody("direct:start", "hello", String.class);
assertEquals("Get a wrong response", "Bye hello", result);
main.stop();
}
Aggregations