Search in sources :

Example 6 with MessagingMethodInvokerHelper

use of org.springframework.integration.handler.support.MessagingMethodInvokerHelper in project spring-integration by spring-projects.

the class MethodInvokingMessageProcessorTests method testPrivateMethod.

@Test
public void testPrivateMethod() throws Exception {
    class Foo {

        @ServiceActivator
        private String service(String payload) {
            return payload.toUpperCase();
        }
    }
    MessagingMethodInvokerHelper helper = new MessagingMethodInvokerHelper(new Foo(), ServiceActivator.class, false);
    assertEquals("FOO", helper.process(new GenericMessage<>("foo")));
    assertEquals("BAR", helper.process(new GenericMessage<>("bar")));
}
Also used : MessagingMethodInvokerHelper(org.springframework.integration.handler.support.MessagingMethodInvokerHelper) GenericMessage(org.springframework.messaging.support.GenericMessage) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 7 with MessagingMethodInvokerHelper

use of org.springframework.integration.handler.support.MessagingMethodInvokerHelper in project spring-integration by spring-projects.

the class MethodInvokingMessageProcessorTests method testInt3199GenericTypeResolvingAndObjectMethod.

@Test
public void testInt3199GenericTypeResolvingAndObjectMethod() throws Exception {
    class Foo {

        @SuppressWarnings("unused")
        public String handleMessage(Message<Number> message) {
            return "" + (message.getPayload().intValue() * 2);
        }

        @SuppressWarnings("unused")
        public String objectMethod(Integer foo) {
            return foo.toString();
        }

        @SuppressWarnings("unused")
        public String voidMethod() {
            return "foo";
        }
    }
    MessagingMethodInvokerHelper helper = new MessagingMethodInvokerHelper(new Foo(), (String) null, false);
    assertEquals("4", helper.process(new GenericMessage<Object>(2L)));
    assertEquals("1", helper.process(new GenericMessage<Object>(1)));
    assertEquals("foo", helper.process(new GenericMessage<Object>(new Date())));
}
Also used : MessagingMethodInvokerHelper(org.springframework.integration.handler.support.MessagingMethodInvokerHelper) GenericMessage(org.springframework.messaging.support.GenericMessage) Message(org.springframework.messaging.Message) GenericMessage(org.springframework.messaging.support.GenericMessage) Date(java.util.Date) Test(org.junit.Test)

Example 8 with MessagingMethodInvokerHelper

use of org.springframework.integration.handler.support.MessagingMethodInvokerHelper in project spring-integration by spring-projects.

the class MethodInvokingMessageProcessorTests method gatewayTest.

@Test
public void gatewayTest() throws Exception {
    GatewayProxyFactoryBean gwFactoryBean = new GatewayProxyFactoryBean();
    gwFactoryBean.setBeanFactory(mock(BeanFactory.class));
    gwFactoryBean.afterPropertiesSet();
    Object target = gwFactoryBean.getObject();
    // just instantiate a helper with a simple target; we're going to invoke getTargetClass with reflection
    MessagingMethodInvokerHelper helper = new MessagingMethodInvokerHelper(new TestErrorService(), "error", true);
    Method method = MessagingMethodInvokerHelper.class.getDeclaredMethod("getTargetClass", Object.class);
    method.setAccessible(true);
    Object result = method.invoke(helper, target);
    assertSame(RequestReplyExchanger.class, result);
}
Also used : MessagingMethodInvokerHelper(org.springframework.integration.handler.support.MessagingMethodInvokerHelper) GatewayProxyFactoryBean(org.springframework.integration.gateway.GatewayProxyFactoryBean) ConfigurableListableBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory) BeanFactory(org.springframework.beans.factory.BeanFactory) Method(java.lang.reflect.Method) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)8 MessagingMethodInvokerHelper (org.springframework.integration.handler.support.MessagingMethodInvokerHelper)8 GenericMessage (org.springframework.messaging.support.GenericMessage)6 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)5 Message (org.springframework.messaging.Message)3 ConfigurableListableBeanFactory (org.springframework.beans.factory.config.ConfigurableListableBeanFactory)2 Method (java.lang.reflect.Method)1 Date (java.util.Date)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 Optional (java.util.Optional)1 BeanFactory (org.springframework.beans.factory.BeanFactory)1 ServiceActivator (org.springframework.integration.annotation.ServiceActivator)1 GatewayProxyFactoryBean (org.springframework.integration.gateway.GatewayProxyFactoryBean)1 Header (org.springframework.messaging.handler.annotation.Header)1