use of java.lang.reflect.Method in project camel by apache.
the class BeanMethodBeanTest method testBeanMethod.
public void testBeanMethod() throws Exception {
Method method = MyFooBean.class.getMethod("hello", String.class);
MethodBean mb = new MethodBean();
mb.setName("hello");
mb.setType(MyFooBean.class);
mb.setParameterTypes(method.getParameterTypes());
assertEquals("hello", mb.getName());
assertEquals(method, mb.getMethod());
assertNotNull(mb.getParameterTypes());
assertEquals(MyFooBean.class, mb.getType());
}
use of java.lang.reflect.Method in project camel by apache.
the class BeanInfoAMoreComplexOverloadedTest method testRequestB.
public void testRequestB() throws Exception {
BeanInfo beanInfo = new BeanInfo(context, Bean.class);
Message message = new DefaultMessage();
message.setBody(new RequestB());
Exchange exchange = new DefaultExchange(context);
exchange.setIn(message);
MethodInvocation methodInvocation = beanInfo.createInvocation(new Bean(), exchange);
Method method = methodInvocation.getMethod();
assertEquals("doSomething", method.getName());
assertEquals(RequestB.class, method.getGenericParameterTypes()[0]);
}
use of java.lang.reflect.Method 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 java.lang.reflect.Method 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 java.lang.reflect.Method in project camel by apache.
the class CamelPostProcessorHelperTest method testPropertyMethodInject.
public void testPropertyMethodInject() throws Exception {
myProp.put("myTimeout", "2000");
myProp.put("myApp", "Camel");
CamelPostProcessorHelper helper = new CamelPostProcessorHelper(context);
MyPropertyMethodBean bean = new MyPropertyMethodBean();
Method method = bean.getClass().getMethod("setTimeout", int.class);
PropertyInject propertyInject = method.getAnnotation(PropertyInject.class);
Class<?> type = method.getParameterTypes()[0];
Object value = helper.getInjectionPropertyValue(type, propertyInject.value(), "", "timeout", bean, "foo");
assertEquals(Integer.valueOf("2000"), Integer.valueOf("" + value));
method = bean.getClass().getMethod("setGreeting", String.class);
propertyInject = method.getAnnotation(PropertyInject.class);
type = method.getParameterTypes()[0];
value = helper.getInjectionPropertyValue(type, propertyInject.value(), "", "greeting", bean, "foo");
assertEquals("Hello Camel", value);
}
Aggregations