Search in sources :

Example 11 with Method

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());
}
Also used : Method(java.lang.reflect.Method)

Example 12 with Method

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]);
}
Also used : DefaultMessage(org.apache.camel.impl.DefaultMessage) DefaultExchange(org.apache.camel.impl.DefaultExchange) Exchange(org.apache.camel.Exchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) Message(org.apache.camel.Message) DefaultMessage(org.apache.camel.impl.DefaultMessage) Method(java.lang.reflect.Method)

Example 13 with Method

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();
}
Also used : EndpointInject(org.apache.camel.EndpointInject) Exchange(org.apache.camel.Exchange) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Method(java.lang.reflect.Method)

Example 14 with Method

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();
}
Also used : EndpointInject(org.apache.camel.EndpointInject) Exchange(org.apache.camel.Exchange) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Method(java.lang.reflect.Method)

Example 15 with Method

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);
}
Also used : Method(java.lang.reflect.Method) PropertyInject(org.apache.camel.PropertyInject)

Aggregations

Method (java.lang.reflect.Method)7234 Test (org.junit.Test)1402 InvocationTargetException (java.lang.reflect.InvocationTargetException)935 ArrayList (java.util.ArrayList)557 Field (java.lang.reflect.Field)498 IOException (java.io.IOException)463 HashMap (java.util.HashMap)279 Map (java.util.Map)232 PropertyDescriptor (java.beans.PropertyDescriptor)230 List (java.util.List)221 Annotation (java.lang.annotation.Annotation)174 Type (java.lang.reflect.Type)174 IndexedPropertyDescriptor (java.beans.IndexedPropertyDescriptor)168 BeanInfo (java.beans.BeanInfo)155 HashSet (java.util.HashSet)147 File (java.io.File)138 SimpleBeanInfo (java.beans.SimpleBeanInfo)128 FakeFox01BeanInfo (org.apache.harmony.beans.tests.support.mock.FakeFox01BeanInfo)128 URL (java.net.URL)114 ParameterizedType (java.lang.reflect.ParameterizedType)113