INT-828, INT-936 Created a FilteringReflectiveMethodResolver for use in the SpEL expression evaluation.

This commit is contained in:
Mark Fisher
2009-12-23 02:09:50 +00:00
parent f84f71f261
commit 886e1dccb2
6 changed files with 377 additions and 7 deletions

View File

@@ -28,6 +28,7 @@ import java.util.Properties;
import org.junit.Test;
import org.springframework.integration.annotation.Header;
import org.springframework.integration.annotation.ServiceActivator;
import org.springframework.integration.core.Message;
import org.springframework.integration.message.GenericMessage;
import org.springframework.integration.message.MessageBuilder;
@@ -114,7 +115,7 @@ public class MethodInvokingMessageProcessorTests {
processor.processMessage(MessageBuilder.withPayload("Something").build());
fail();
}
catch(IllegalArgumentException ex) {
catch(MessageHandlingException ex) {
exception = ex;
}
assertNotNull(exception);
@@ -178,6 +179,26 @@ public class MethodInvokingMessageProcessorTests {
assertEquals("bar-42", result);
}
@Test
public void filterSelectsAnnotationMethodsOnly() {
AmbiguousMethodBean bean = new AmbiguousMethodBean();
MethodInvokingMessageProcessor processor = new MethodInvokingMessageProcessor(bean, ServiceActivator.class);
processor.processMessage(MessageBuilder.withPayload(123).build());
assertNotNull(bean.lastArg);
assertEquals(String.class, bean.lastArg.getClass());
assertEquals("123", bean.lastArg);
}
@Test
public void filterSelectsNonVoidReturningMethodsOnly() {
AmbiguousMethodBean bean = new AmbiguousMethodBean();
MethodInvokingMessageProcessor processor = new MethodInvokingMessageProcessor(bean, "foo", true);
processor.processMessage(MessageBuilder.withPayload(true).build());
assertNotNull(bean.lastArg);
assertEquals(String.class, bean.lastArg.getClass());
assertEquals("true", bean.lastArg);
}
@SuppressWarnings("unused")
private static class TestBean {
@@ -263,4 +284,31 @@ public class MethodInvokingMessageProcessorTests {
}
/**
* Method names create ambiguities, but the MethodResolver implementation
* should filter out based on the annotation or the 'requiresReply' flag.
*/
@SuppressWarnings("unused")
private static class AmbiguousMethodBean {
private volatile Object lastArg = null;
public void foo(boolean b) {
this.lastArg = b;
}
@ServiceActivator
public String foo(String s) {
this.lastArg = s;
return s;
}
public String foo(int i) {
this.lastArg = i;
return Integer.valueOf(i).toString();
}
}
}