use of org.apache.camel.EndpointInject in project camel by apache.
the class CamelPostProcessorHelperTest method testEndpointInjectPollingConsumer.
public void testEndpointInjectPollingConsumer() throws Exception {
CamelPostProcessorHelper helper = new CamelPostProcessorHelper(context);
MyEndpointBeanPollingConsumer bean = new MyEndpointBeanPollingConsumer();
Method method = bean.getClass().getMethod("setConsumer", PollingConsumer.class);
EndpointInject endpointInject = method.getAnnotation(EndpointInject.class);
Class<?>[] parameterTypes = method.getParameterTypes();
for (Class<?> type : parameterTypes) {
String propertyName = ObjectHelper.getPropertyName(method);
Object value = helper.getInjectionValue(type, endpointInject.uri(), endpointInject.ref(), endpointInject.property(), propertyName, bean, "foo");
ObjectHelper.invokeMethod(method, bean, value);
}
template.sendBody("seda:foo", "Hello World");
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedBodiesReceived("Hello World");
assertNotNull(bean.getConsumer());
Exchange exchange = bean.consume();
template.send("mock:result", exchange);
assertMockEndpointsSatisfied();
}
use of org.apache.camel.EndpointInject in project camel by apache.
the class CamelPostProcessorHelperTest method testEndpointInjectProducer.
public void testEndpointInjectProducer() throws Exception {
CamelPostProcessorHelper helper = new CamelPostProcessorHelper(context);
MyEndpointBeanProducer bean = new MyEndpointBeanProducer();
Method method = bean.getClass().getMethod("setProducer", Producer.class);
EndpointInject endpointInject = method.getAnnotation(EndpointInject.class);
Class<?>[] parameterTypes = method.getParameterTypes();
for (Class<?> type : parameterTypes) {
String propertyName = ObjectHelper.getPropertyName(method);
Object value = helper.getInjectionValue(type, endpointInject.uri(), endpointInject.ref(), endpointInject.property(), propertyName, bean, "foo");
ObjectHelper.invokeMethod(method, bean, value);
}
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedBodiesReceived("Hello World");
assertNotNull(bean.getProducer());
Exchange exchange = new DefaultExchange(context);
exchange.getIn().setBody("Hello World");
bean.send(exchange);
assertMockEndpointsSatisfied();
}
use of org.apache.camel.EndpointInject in project camel by apache.
the class CamelPostProcessorHelperTest method testEndpointInjectProducerTemplateField.
public void testEndpointInjectProducerTemplateField() throws Exception {
CamelPostProcessorHelper helper = new CamelPostProcessorHelper(context);
MyEndpointInjectProducerTemplate bean = new MyEndpointInjectProducerTemplate();
Field field = bean.getClass().getField("producer");
EndpointInject endpointInject = field.getAnnotation(EndpointInject.class);
Class<?> type = field.getType();
String propertyName = "producer";
Object value = helper.getInjectionValue(type, endpointInject.uri(), endpointInject.ref(), endpointInject.property(), propertyName, bean, "foo");
field.set(bean, value);
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedBodiesReceived("Hello World");
Exchange exchange = new DefaultExchange(context);
exchange.getIn().setBody("Hello World");
bean.send(exchange);
assertMockEndpointsSatisfied();
}
use of org.apache.camel.EndpointInject in project camel by apache.
the class CamelPostProcessorHelperTest method testEndpointInjectProducerTemplateFieldUrlUnknown.
public void testEndpointInjectProducerTemplateFieldUrlUnknown() throws Exception {
CamelPostProcessorHelper helper = new CamelPostProcessorHelper(context);
MyEndpointInjectProducerTemplateUrlUnknown bean = new MyEndpointInjectProducerTemplateUrlUnknown();
Field field = bean.getClass().getField("producer");
EndpointInject endpointInject = field.getAnnotation(EndpointInject.class);
Class<?> type = field.getType();
String propertyName = "producer";
try {
helper.getInjectionValue(type, endpointInject.uri(), endpointInject.ref(), endpointInject.property(), propertyName, bean, "foo");
fail("Should throw exception");
} catch (ResolveEndpointFailedException e) {
assertEquals("Failed to resolve endpoint: xxx://foo due to: No component found with scheme: xxx", e.getMessage());
}
}
use of org.apache.camel.EndpointInject in project camel by apache.
the class CamelPostProcessorHelperTest method testEndpointInjectBothUriAndRef.
public void testEndpointInjectBothUriAndRef() throws Exception {
CamelPostProcessorHelper helper = new CamelPostProcessorHelper(context);
MyEndpointBothUriAndRef bean = new MyEndpointBothUriAndRef();
Field field = bean.getClass().getField("producer");
EndpointInject endpointInject = field.getAnnotation(EndpointInject.class);
Class<?> type = field.getType();
String propertyName = "producer";
try {
helper.getInjectionValue(type, endpointInject.uri(), endpointInject.ref(), endpointInject.property(), propertyName, bean, "foo");
fail("Should throw exception");
} catch (IllegalArgumentException e) {
assertEquals("Both uri and name is provided, only either one is allowed: uri=seda:foo, ref=myEndpoint", e.getMessage());
}
}
Aggregations