use of org.apache.camel.ProducerTemplate in project camel by apache.
the class RoutingUsingCamelContextFactoryTest method testXMLRouteLoading.
public void testXMLRouteLoading() throws Exception {
applicationContext = createApplicationContext();
SpringCamelContext context = applicationContext.getBean("camel-A", SpringCamelContext.class);
assertValidContext(context);
MockEndpoint resultEndpoint = (MockEndpoint) resolveMandatoryEndpoint(context, "mock:result");
resultEndpoint.expectedBodiesReceived(body);
// now lets send a message
ProducerTemplate template = context.createProducerTemplate();
template.start();
template.send("seda:start", new Processor() {
public void process(Exchange exchange) {
Message in = exchange.getIn();
in.setHeader("name", "James");
in.setBody(body);
}
});
template.stop();
resultEndpoint.assertIsSatisfied();
}
use of org.apache.camel.ProducerTemplate in project camel by apache.
the class PojoDualCamelContextConsumerTest method testCamel1.
public void testCamel1() throws Exception {
String body = "<hello>world!</hello>";
MockEndpoint result = camel1.getEndpoint("mock:result", MockEndpoint.class);
result.expectedBodiesReceived(body);
ProducerTemplate template = camel1.createProducerTemplate();
template.start();
template.sendBody("direct:start", body);
template.stop();
result.assertIsSatisfied();
}
use of org.apache.camel.ProducerTemplate in project camel by apache.
the class DependencyInjectCamelTemplateTest method testBeanHasCamelTemplateInjected.
@Test
public void testBeanHasCamelTemplateInjected() throws Exception {
assertNotNull("Bean should be injected", bean);
ProducerTemplate template = bean.getTemplate();
assertNotNull("Bean should have a CamelTemplate", template);
endpoint.expectedBodiesReceived(body);
template.sendBody(body);
endpoint.assertIsSatisfied();
}
use of org.apache.camel.ProducerTemplate in project camel by apache.
the class DualCamelContextEndpointOutsideTest method testDualCamelContextEndpoint.
public void testDualCamelContextEndpoint() throws Exception {
CamelContext camelA = applicationContext.getBean("camel-A", CamelContext.class);
assertNotNull(camelA);
CamelContext camelB = applicationContext.getBean("camel-B", CamelContext.class);
assertNotNull(camelB);
MockEndpoint mockA = camelA.getEndpoint("mock:mock1", MockEndpoint.class);
mockA.expectedBodiesReceived("Hello A");
MockEndpoint mockB = camelB.getEndpoint("mock:mock2", MockEndpoint.class);
mockB.expectedBodiesReceived("Hello B");
ProducerTemplate producer1 = camelA.createProducerTemplate();
producer1.sendBody("direct:start1", "Hello A");
ProducerTemplate producer2 = camelB.createProducerTemplate();
producer2.sendBody("direct:start2", "Hello B");
// make sure we properly stop the services we created
ServiceHelper.stopServices(producer1, producer2);
mockA.assertIsSatisfied();
mockB.assertIsSatisfied();
}
use of org.apache.camel.ProducerTemplate in project camel by apache.
the class UserProducerInOnlyTest method testPostStatusUpdateRequestResponse.
@Test
public void testPostStatusUpdateRequestResponse() throws Exception {
Date now = new Date();
String tweet = "UserProducerInOnlyTest: 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(String.class);
// Message headers should be preserved
resultEndpoint.expectedHeaderReceived("customHeader", 12312);
resultEndpoint.assertIsSatisfied();
List<Exchange> tweets = resultEndpoint.getExchanges();
assertNotNull(tweets);
assertThat(tweets.size(), is(1));
String receivedTweet = tweets.get(0).getIn().getBody(String.class);
assertThat(receivedTweet, is(tweet));
}
Aggregations