Merge pull request #190 from olegz/INT-2249

This commit is contained in:
Mark Fisher
2011-11-21 17:12:23 -05:00
2 changed files with 17 additions and 55 deletions

View File

@@ -48,8 +48,8 @@ public class MethodInvokingMessageProcessor<T> extends AbstractMessageProcessor<
delegate = new MessagingMethodInvokerHelper<T>(targetObject, methodName, false);
}
public MethodInvokingMessageProcessor(Object targetObject, String methodName, boolean requiresReply) {
delegate = new MessagingMethodInvokerHelper<T>(targetObject, methodName, Object.class, false);
public MethodInvokingMessageProcessor(Object targetObject, String methodName, boolean canProcessMessageList) {
delegate = new MessagingMethodInvokerHelper<T>(targetObject, methodName, canProcessMessageList);
}
public MethodInvokingMessageProcessor(Object targetObject, Class<? extends Annotation> annotationType) {

View File

@@ -16,11 +16,6 @@
package org.springframework.integration.handler;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.fail;
import java.lang.reflect.Method;
import java.util.Map;
import java.util.Properties;
@@ -40,6 +35,10 @@ import org.springframework.integration.annotation.ServiceActivator;
import org.springframework.integration.message.GenericMessage;
import org.springframework.integration.support.MessageBuilder;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
/**
* @author Mark Fisher
* @author Marius Bogoevici
@@ -219,32 +218,6 @@ public class MethodInvokingMessageProcessorTests {
assertEquals(12, processor.processMessage(MessageBuilder.withPayload(12).build()));
}
@Test
public void testVoidMethodsExcludedByFlag() {
@SuppressWarnings("unused")
class VoidMethodsBean {
public void testVoidReturningMethods(String s) {
// do nothing
}
public int testVoidReturningMethods(int i) {
return i;
}
}
Exception exception = null;
MethodInvokingMessageProcessor processor = new MethodInvokingMessageProcessor(new VoidMethodsBean(),
"testVoidReturningMethods", true);
assertEquals(12, processor.processMessage(MessageBuilder.withPayload(12).build()));
try {
processor.processMessage(MessageBuilder.withPayload("not_a_number").build());
fail();
}
catch (MessageHandlingException ex) {
// the only void method expects a number
exception = ex;
}
assertNotNull(exception);
}
@Test
public void messageOnlyWithAnnotatedMethod() throws Exception {
AnnotatedTestService service = new AnnotatedTestService();
@@ -280,6 +253,16 @@ public class MethodInvokingMessageProcessorTests {
processor.processMessage(new GenericMessage<String>("foo"));
}
@Test
public void filterSelectsAnnotationMethodsOnly() {
OverloadedMethodBean bean = new OverloadedMethodBean();
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 testProcessMessageBadExpression() throws Exception {
// TODO: should this be MessageHandlingException or NumberFormatException?
@@ -329,30 +312,10 @@ public class MethodInvokingMessageProcessorTests {
assertEquals("bar-42", result);
}
@Test
public void filterSelectsAnnotationMethodsOnly() {
OverloadedMethodBean bean = new OverloadedMethodBean();
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() {
OverloadedMethodBean bean = new OverloadedMethodBean();
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);
}
@Test
public void testOverloadedNonVoidReturningMethodsWithExactMatchForType() {
AmbiguousMethodBean bean = new AmbiguousMethodBean();
MethodInvokingMessageProcessor processor = new MethodInvokingMessageProcessor(bean, "foo", true);
MethodInvokingMessageProcessor processor = new MethodInvokingMessageProcessor(bean, "foo");
processor.processMessage(MessageBuilder.withPayload("true").build());
assertNotNull(bean.lastArg);
assertEquals(String.class, bean.lastArg.getClass());
@@ -525,6 +488,5 @@ public class MethodInvokingMessageProcessorTests {
this.lastArg = s;
return s;
}
}
}