use of org.apache.camel.ProducerTemplate in project camel by apache.
the class ProducerTemplateAlreadyExistTest method testHasExistingTemplate.
@Test
public void testHasExistingTemplate() {
assertNotNull("Should have injected a producer template", template);
ProducerTemplate lookup = context.getRegistry().lookupByNameAndType("myTemplate", ProducerTemplate.class);
assertNotNull("Should lookup producer template", lookup);
ProducerTemplate lookup2 = context.getRegistry().lookupByNameAndType("template", ProducerTemplate.class);
assertNull("Should not be able to lookup producer template", lookup2);
}
use of org.apache.camel.ProducerTemplate in project camel by apache.
the class CustomProcessorWithNamespacesTest method testXMLRouteLoading.
public void testXMLRouteLoading() throws Exception {
applicationContext = createApplicationContext();
SpringCamelContext context = applicationContext.getBeansOfType(SpringCamelContext.class).values().iterator().next();
assertValidContext(context);
// now lets send a message
ProducerTemplate template = context.createProducerTemplate();
template.start();
template.send("direct:start", new Processor() {
public void process(Exchange exchange) {
Message in = exchange.getIn();
in.setHeader("name", "James");
in.setBody(body);
}
});
template.stop();
MyProcessor myProcessor = applicationContext.getBean("myProcessor", MyProcessor.class);
List<Exchange> list = myProcessor.getExchanges();
assertEquals("Should have received a single exchange: " + list, 1, list.size());
}
use of org.apache.camel.ProducerTemplate in project camel by apache.
the class UserProducerInOutTest method testPostStatusUpdateRequestResponse.
@Test
public void testPostStatusUpdateRequestResponse() throws Exception {
Date now = new Date();
String tweet = "UserProducerInOutTest: This is a tweet posted on " + now.toString();
LOG.info("Tweet: " + tweet);
ProducerTemplate producerTemplate = context.createProducerTemplate();
// send tweet to the twitter endpoint
producerTemplate.sendBodyAndHeader("direct:tweets", tweet, "customHeader", 12312);
resultEndpoint.expectedMessageCount(1);
resultEndpoint.expectedBodyReceived().body(Status.class);
// Message headers should be preserved
resultEndpoint.expectedHeaderReceived("customHeader", 12312);
resultEndpoint.assertIsSatisfied();
List<Exchange> tweets = resultEndpoint.getExchanges();
assertNotNull(tweets);
assertThat(tweets.size(), is(1));
Status receivedTweet = tweets.get(0).getIn().getBody(Status.class);
assertNotNull(receivedTweet);
// The identifier for the published tweet should be there
assertNotNull(receivedTweet.getId());
}
use of org.apache.camel.ProducerTemplate in project camel by apache.
the class CafeRouteBuilder method runCafeRouteDemo.
public void runCafeRouteDemo() throws Exception {
// create CamelContext
DefaultCamelContext camelContext = new DefaultCamelContext();
camelContext.setRegistry(createRegistry());
camelContext.addRoutes(this);
camelContext.start();
ProducerTemplate template = camelContext.createProducerTemplate();
Order order = new Order(2);
order.addItem(DrinkType.ESPRESSO, 2, true);
order.addItem(DrinkType.CAPPUCCINO, 4, false);
order.addItem(DrinkType.LATTE, 4, false);
order.addItem(DrinkType.MOCHA, 2, false);
template.sendBody("direct:cafe", order);
Thread.sleep(6000);
camelContext.stop();
}
use of org.apache.camel.ProducerTemplate in project camel by apache.
the class MainNoPidTest 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-pid-loadfile.xml");
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", "Good morning hello", result);
main.stop();
}
Aggregations