use of org.apache.camel.FluentProducerTemplate in project camel by apache.
the class FluentProducerTemplateAutoRegisterTest method testHasFluentTemplate.
@Test
public void testHasFluentTemplate() {
assertNotNull("Should have injected a fluent producer template", template);
FluentProducerTemplate lookup = context.getRegistry().lookupByNameAndType("fluentTemplate", FluentProducerTemplate.class);
assertNotNull("Should lookup fluent producer template", lookup);
}
use of org.apache.camel.FluentProducerTemplate in project camel by apache.
the class FluentProducerTemplateTest method testFromCamelContext.
public void testFromCamelContext() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedBodiesReceived("Bye World");
FluentProducerTemplate fluent = context.createFluentProducerTemplate();
Object result = fluent.withBody("Hello World").to("direct:in").request();
assertMockEndpointsSatisfied();
assertEquals("Bye World", result);
assertSame(context, fluent.getCamelContext());
}
use of org.apache.camel.FluentProducerTemplate in project camel by apache.
the class FluentProducerTemplateTest method testNoEndpoint.
public void testNoEndpoint() throws Exception {
FluentProducerTemplate fluent = context.createFluentProducerTemplate();
try {
fluent.withBody("Hello World").send();
fail("Should have thrown exception");
} catch (IllegalArgumentException e) {
// expected
}
try {
fluent.withBody("Hello World").request();
fail("Should have thrown exception");
} catch (IllegalArgumentException e) {
// expected
}
}
use of org.apache.camel.FluentProducerTemplate in project camel by apache.
the class CamelPostProcessorHelper method createInjectionFluentProducerTemplate.
/**
* Factory method to create a
* {@link org.apache.camel.FluentProducerTemplate} to be injected into a
* POJO
*/
protected FluentProducerTemplate createInjectionFluentProducerTemplate(String endpointUri, String endpointRef, String endpointProperty, String injectionPointName, Object bean) {
// endpoint is optional for this injection point
Endpoint endpoint = getEndpointInjection(bean, endpointUri, endpointRef, endpointProperty, injectionPointName, false);
CamelContext context = endpoint != null ? endpoint.getCamelContext() : getCamelContext();
FluentProducerTemplate answer = new DefaultFluentProducerTemplate(context);
answer.setDefaultEndpoint(endpoint);
// start the template so its ready to use
try {
// no need to defer the template as it can adjust to the endpoint at runtime
startService(answer, context, bean, null);
} catch (Exception e) {
throw ObjectHelper.wrapRuntimeCamelException(e);
}
return answer;
}
Aggregations