Search in sources :

Example 1 with MethodInvokingMessageSource

use of org.springframework.integration.endpoint.MethodInvokingMessageSource in project spring-integration by spring-projects.

the class IntegrationFlows method from.

/**
 * Populate the provided {@link MethodInvokingMessageSource} for the method of the provided service.
 * The {@link org.springframework.integration.dsl.IntegrationFlow} {@code startMessageSource}.
 * @param service the service to use.
 * @param methodName the method to invoke.
 * @param endpointConfigurer the {@link Consumer} to provide more options for the
 * {@link org.springframework.integration.config.SourcePollingChannelAdapterFactoryBean}.
 * @return new {@link IntegrationFlowBuilder}.
 * @since 1.1
 * @see MethodInvokingMessageSource
 */
public static IntegrationFlowBuilder from(Object service, String methodName, Consumer<SourcePollingChannelAdapterSpec> endpointConfigurer) {
    Assert.notNull(service, "'service' must not be null");
    Assert.hasText(methodName, "'methodName' must not be empty");
    MethodInvokingMessageSource messageSource = new MethodInvokingMessageSource();
    messageSource.setObject(service);
    messageSource.setMethodName(methodName);
    return from(messageSource, endpointConfigurer);
}
Also used : MethodInvokingMessageSource(org.springframework.integration.endpoint.MethodInvokingMessageSource)

Example 2 with MethodInvokingMessageSource

use of org.springframework.integration.endpoint.MethodInvokingMessageSource in project spring-integration by spring-projects.

the class MethodInvokingMessageSourceTests method testNoMatchingMethodName.

@Test(expected = MessagingException.class)
public void testNoMatchingMethodName() {
    MethodInvokingMessageSource source = new MethodInvokingMessageSource();
    source.setBeanFactory(mock(BeanFactory.class));
    source.setObject(new TestBean());
    source.setMethodName("noMatchingMethod");
    source.receive();
}
Also used : MethodInvokingMessageSource(org.springframework.integration.endpoint.MethodInvokingMessageSource) BeanFactory(org.springframework.beans.factory.BeanFactory) Test(org.junit.Test)

Example 3 with MethodInvokingMessageSource

use of org.springframework.integration.endpoint.MethodInvokingMessageSource in project spring-integration by spring-projects.

the class MethodInvokingMessageSourceTests method testInvalidMethodWithNoReturnValue.

@Test(expected = MessagingException.class)
public void testInvalidMethodWithNoReturnValue() {
    MethodInvokingMessageSource source = new MethodInvokingMessageSource();
    source.setBeanFactory(mock(BeanFactory.class));
    source.setObject(new TestBean());
    source.setMethodName("invalidMethodWithNoReturnValue");
    source.receive();
}
Also used : MethodInvokingMessageSource(org.springframework.integration.endpoint.MethodInvokingMessageSource) BeanFactory(org.springframework.beans.factory.BeanFactory) Test(org.junit.Test)

Example 4 with MethodInvokingMessageSource

use of org.springframework.integration.endpoint.MethodInvokingMessageSource in project spring-integration by spring-projects.

the class MethodInvokingMessageSourceTests method testInvalidMethodWithArg.

@Test(expected = MessagingException.class)
public void testInvalidMethodWithArg() {
    MethodInvokingMessageSource source = new MethodInvokingMessageSource();
    source.setBeanFactory(mock(BeanFactory.class));
    source.setObject(new TestBean());
    source.setMethodName("invalidMethodWithArg");
    source.receive();
}
Also used : MethodInvokingMessageSource(org.springframework.integration.endpoint.MethodInvokingMessageSource) BeanFactory(org.springframework.beans.factory.BeanFactory) Test(org.junit.Test)

Example 5 with MethodInvokingMessageSource

use of org.springframework.integration.endpoint.MethodInvokingMessageSource in project spring-integration by spring-projects.

the class MethodInvokingMessageSourceTests method testNullReturningMethodReturnsNullMessage.

@Test
public void testNullReturningMethodReturnsNullMessage() {
    MethodInvokingMessageSource source = new MethodInvokingMessageSource();
    source.setBeanFactory(mock(BeanFactory.class));
    source.setObject(new TestBean());
    source.setMethodName("nullReturningMethod");
    Message<?> message = source.receive();
    assertNull(message);
}
Also used : MethodInvokingMessageSource(org.springframework.integration.endpoint.MethodInvokingMessageSource) BeanFactory(org.springframework.beans.factory.BeanFactory) Test(org.junit.Test)

Aggregations

MethodInvokingMessageSource (org.springframework.integration.endpoint.MethodInvokingMessageSource)8 Test (org.junit.Test)6 BeanFactory (org.springframework.beans.factory.BeanFactory)6 HashMap (java.util.HashMap)1 Supplier (java.util.function.Supplier)1 Bean (org.springframework.context.annotation.Bean)1 Expression (org.springframework.expression.Expression)1 LiteralExpression (org.springframework.expression.common.LiteralExpression)1 SpelExpressionParser (org.springframework.expression.spel.standard.SpelExpressionParser)1 MessageSource (org.springframework.integration.core.MessageSource)1