MessageMappingMethodInvoker is now MethodInvokingMessageProcessor since it implements the MessageProcessor interface and is a parallel implementation to ExpressionEvaluatingMessageProcessor.

This commit is contained in:
Mark Fisher
2009-09-30 11:32:07 +00:00
parent 2b3971f68a
commit 93ba43f253
14 changed files with 100 additions and 97 deletions

View File

@@ -113,7 +113,7 @@ public class AggregatorAnnotationTests {
Assert.assertTrue(correlationStrategy instanceof CorrelationStrategyAdapter);
CorrelationStrategyAdapter completionStrategyAdapter = (CorrelationStrategyAdapter) correlationStrategy;
DirectFieldAccessor invokerAccessor = new DirectFieldAccessor(
new DirectFieldAccessor(completionStrategyAdapter).getPropertyValue("invoker"));
new DirectFieldAccessor(completionStrategyAdapter).getPropertyValue("processor"));
Object targetObject = invokerAccessor.getPropertyValue("object");
assertSame(context.getBean(endpointName), targetObject);
HandlerMethodResolver completionCheckerMethodResolver = (HandlerMethodResolver) invokerAccessor.getPropertyValue("methodResolver");

View File

@@ -81,7 +81,7 @@ public class PNamespaceTest {
DirectFieldAccessor saAccessor = new DirectFieldAccessor(serviceActivator);
Object handler = saAccessor.getPropertyValue("handler");
DirectFieldAccessor hAccessor = new DirectFieldAccessor(handler);
Object invoker = hAccessor.getPropertyValue("invoker");
Object invoker = hAccessor.getPropertyValue("processor");
DirectFieldAccessor iAccessor = new DirectFieldAccessor(invoker);
return (TestBean) iAccessor.getPropertyValue("object");
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2008 the original author or authors.
* Copyright 2002-2009 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -36,79 +36,79 @@ import org.springframework.integration.message.StringMessage;
* @author Mark Fisher
* @author Marius Bogoevici
*/
public class MessageMappingMethodInvokerTests {
public class MethodInvokingMessageProcessorTests {
@Test
public void payloadAsMethodParameterAndObjectAsReturnValue() {
MessageMappingMethodInvoker invoker = new MessageMappingMethodInvoker(
MethodInvokingMessageProcessor processor = new MethodInvokingMessageProcessor(
new TestBean(), "acceptPayloadAndReturnObject");
Object result = invoker.processMessage(new StringMessage("testing"));
Object result = processor.processMessage(new StringMessage("testing"));
assertEquals("testing-1", result);
}
@Test
public void payloadAsMethodParameterAndMessageAsReturnValue() {
MessageMappingMethodInvoker invoker = new MessageMappingMethodInvoker(
MethodInvokingMessageProcessor processor = new MethodInvokingMessageProcessor(
new TestBean(), "acceptPayloadAndReturnMessage");
Message<?> result = (Message<?>) invoker.processMessage(new StringMessage("testing"));
Message<?> result = (Message<?>) processor.processMessage(new StringMessage("testing"));
assertEquals("testing-2", result.getPayload());
}
@Test
public void messageAsMethodParameterAndObjectAsReturnValue() {
MessageMappingMethodInvoker invoker = new MessageMappingMethodInvoker(
MethodInvokingMessageProcessor processor = new MethodInvokingMessageProcessor(
new TestBean(), "acceptMessageAndReturnObject");
Object result = invoker.processMessage(new StringMessage("testing"));
Object result = processor.processMessage(new StringMessage("testing"));
assertEquals("testing-3", result);
}
@Test
public void messageAsMethodParameterAndMessageAsReturnValue() {
MessageMappingMethodInvoker invoker = new MessageMappingMethodInvoker(
MethodInvokingMessageProcessor processor = new MethodInvokingMessageProcessor(
new TestBean(), "acceptMessageAndReturnMessage");
Message<?> result = (Message<?>) invoker.processMessage(new StringMessage("testing"));
Message<?> result = (Message<?>) processor.processMessage(new StringMessage("testing"));
assertEquals("testing-4", result.getPayload());
}
@Test
public void messageSubclassAsMethodParameterAndMessageAsReturnValue() {
MessageMappingMethodInvoker invoker = new MessageMappingMethodInvoker(
MethodInvokingMessageProcessor processor = new MethodInvokingMessageProcessor(
new TestBean(), "acceptMessageSubclassAndReturnMessage");
Message<?> result = (Message<?>) invoker.processMessage(new StringMessage("testing"));
Message<?> result = (Message<?>) processor.processMessage(new StringMessage("testing"));
assertEquals("testing-5", result.getPayload());
}
@Test
public void messageSubclassAsMethodParameterAndMessageSubclassAsReturnValue() {
MessageMappingMethodInvoker invoker = new MessageMappingMethodInvoker(
MethodInvokingMessageProcessor processor = new MethodInvokingMessageProcessor(
new TestBean(), "acceptMessageSubclassAndReturnMessageSubclass");
Message<?> result = (Message<?>) invoker.processMessage(new StringMessage("testing"));
Message<?> result = (Message<?>) processor.processMessage(new StringMessage("testing"));
assertEquals("testing-6", result.getPayload());
}
@Test
public void payloadAndHeaderAnnotationMethodParametersAndObjectAsReturnValue() {
MessageMappingMethodInvoker invoker = new MessageMappingMethodInvoker(
MethodInvokingMessageProcessor processor = new MethodInvokingMessageProcessor(
new TestBean(), "acceptPayloadAndHeaderAndReturnObject");
Message<?> request = MessageBuilder.withPayload("testing")
.setHeader("number", new Integer(123)).build();
Object result = invoker.processMessage(request);
Object result = processor.processMessage(request);
assertEquals("testing-123", result);
}
@Test
public void testVoidMethodsIncludedbyDefault() {
MessageMappingMethodInvoker invoker = new MessageMappingMethodInvoker(new TestBean(), "testVoidReturningMethods");
assertNull(invoker.processMessage(MessageBuilder.withPayload("Something").build()));
assertEquals(12, invoker.processMessage(MessageBuilder.withPayload(12).build()));
MethodInvokingMessageProcessor processor = new MethodInvokingMessageProcessor(new TestBean(), "testVoidReturningMethods");
assertNull(processor.processMessage(MessageBuilder.withPayload("Something").build()));
assertEquals(12, processor.processMessage(MessageBuilder.withPayload(12).build()));
}
@Test
public void testVoidMethodsExcludedByFlag() {
MessageMappingMethodInvoker invoker = new MessageMappingMethodInvoker(new TestBean(), "testVoidReturningMethods", true);
assertEquals(12, invoker.processMessage(MessageBuilder.withPayload(12).build()));
MethodInvokingMessageProcessor processor = new MethodInvokingMessageProcessor(new TestBean(), "testVoidReturningMethods", true);
assertEquals(12, processor.processMessage(MessageBuilder.withPayload(12).build()));
try {
assertNull(invoker.processMessage(MessageBuilder.withPayload("Something").build()));
assertNull(processor.processMessage(MessageBuilder.withPayload("Something").build()));
fail();
} catch(IllegalArgumentException ex){
@@ -119,8 +119,8 @@ public class MessageMappingMethodInvokerTests {
public void messageOnlyWithAnnotatedMethod() throws Exception {
AnnotatedTestService service = new AnnotatedTestService();
Method method = service.getClass().getMethod("messageOnly", Message.class);
MessageMappingMethodInvoker invoker = new MessageMappingMethodInvoker(service, method);
Object result = invoker.processMessage(new StringMessage("foo"));
MethodInvokingMessageProcessor processor = new MethodInvokingMessageProcessor(service, method);
Object result = processor.processMessage(new StringMessage("foo"));
assertEquals("foo", result);
}
@@ -128,8 +128,8 @@ public class MessageMappingMethodInvokerTests {
public void payloadWithAnnotatedMethod() throws Exception {
AnnotatedTestService service = new AnnotatedTestService();
Method method = service.getClass().getMethod("integerMethod", Integer.class);
MessageMappingMethodInvoker invoker = new MessageMappingMethodInvoker(service, method);
Object result = invoker.processMessage(new GenericMessage<Integer>(new Integer(123)));
MethodInvokingMessageProcessor processor = new MethodInvokingMessageProcessor(service, method);
Object result = processor.processMessage(new GenericMessage<Integer>(new Integer(123)));
assertEquals(new Integer(123), result);
}
@@ -137,8 +137,8 @@ public class MessageMappingMethodInvokerTests {
public void convertedPayloadWithAnnotatedMethod() throws Exception {
AnnotatedTestService service = new AnnotatedTestService();
Method method = service.getClass().getMethod("integerMethod", Integer.class);
MessageMappingMethodInvoker invoker = new MessageMappingMethodInvoker(service, method);
Object result = invoker.processMessage(new StringMessage("456"));
MethodInvokingMessageProcessor processor = new MethodInvokingMessageProcessor(service, method);
Object result = processor.processMessage(new StringMessage("456"));
assertEquals(new Integer(456), result);
}
@@ -146,8 +146,8 @@ public class MessageMappingMethodInvokerTests {
public void conversionFailureWithAnnotatedMethod() throws Exception {
AnnotatedTestService service = new AnnotatedTestService();
Method method = service.getClass().getMethod("integerMethod", Integer.class);
MessageMappingMethodInvoker invoker = new MessageMappingMethodInvoker(service, method);
Object result = invoker.processMessage(new StringMessage("foo"));
MethodInvokingMessageProcessor processor = new MethodInvokingMessageProcessor(service, method);
Object result = processor.processMessage(new StringMessage("foo"));
assertEquals(new Integer(123), result);
}
@@ -155,10 +155,10 @@ public class MessageMappingMethodInvokerTests {
public void messageAndHeaderWithAnnotatedMethod() throws Exception {
AnnotatedTestService service = new AnnotatedTestService();
Method method = service.getClass().getMethod("messageAndHeader", Message.class, Integer.class);
MessageMappingMethodInvoker invoker = new MessageMappingMethodInvoker(service, method);
MethodInvokingMessageProcessor processor = new MethodInvokingMessageProcessor(service, method);
Message<String> message = MessageBuilder.withPayload("foo")
.setHeader("number", 42).build();
Object result = invoker.processMessage(message);
Object result = processor.processMessage(message);
assertEquals("foo-42", result);
}
@@ -166,15 +166,16 @@ public class MessageMappingMethodInvokerTests {
public void multipleHeadersWithAnnotatedMethod() throws Exception {
AnnotatedTestService service = new AnnotatedTestService();
Method method = service.getClass().getMethod("twoHeaders", String.class, Integer.class);
MessageMappingMethodInvoker invoker = new MessageMappingMethodInvoker(service, method);
MethodInvokingMessageProcessor processor = new MethodInvokingMessageProcessor(service, method);
Message<String> message = MessageBuilder.withPayload("foo")
.setHeader("prop", "bar")
.setHeader("number", 42).build();
Object result = invoker.processMessage(message);
Object result = processor.processMessage(message);
assertEquals("bar-42", result);
}
@SuppressWarnings("unused")
private static class TestBean {
public String acceptPayloadAndReturnObject(String s) {
@@ -215,6 +216,8 @@ public class MessageMappingMethodInvokerTests {
}
@SuppressWarnings("unused")
private static class AnnotatedTestService {
public String messageOnly(Message<?> message) {

View File

@@ -28,7 +28,7 @@ import org.junit.Test;
import org.springframework.integration.annotation.Header;
import org.springframework.integration.annotation.Transformer;
import org.springframework.integration.core.Message;
import org.springframework.integration.handler.MessageMappingMethodInvoker;
import org.springframework.integration.handler.MethodInvokingMessageProcessor;
import org.springframework.integration.handler.MessageProcessor;
import org.springframework.integration.message.GenericMessage;
import org.springframework.integration.message.MessageBuilder;
@@ -44,7 +44,7 @@ public class MethodInvokingTransformerTests {
public void simplePayloadConfiguredWithMethodReference() throws Exception {
TestBean testBean = new TestBean();
Method testMethod = testBean.getClass().getMethod("exclaim", String.class);
MessageProcessor messageProcessor = new MessageMappingMethodInvoker(testBean, testMethod);
MessageProcessor messageProcessor = new MethodInvokingMessageProcessor(testBean, testMethod);
MessageProcessingTransformer transformer = new MessageProcessingTransformer(messageProcessor);
Message<?> message = new StringMessage("foo");
Message<?> result = transformer.transform(message);
@@ -54,7 +54,7 @@ public class MethodInvokingTransformerTests {
@Test
public void simplePayloadConfiguredWithMethodName() throws Exception {
TestBean testBean = new TestBean();
MessageProcessor messageProcessor = new MessageMappingMethodInvoker(testBean, "exclaim");
MessageProcessor messageProcessor = new MethodInvokingMessageProcessor(testBean, "exclaim");
MessageProcessingTransformer transformer = new MessageProcessingTransformer(messageProcessor);
Message<?> message = new StringMessage("foo");
Message<?> result = transformer.transform(message);
@@ -65,7 +65,7 @@ public class MethodInvokingTransformerTests {
public void typeConversionConfiguredWithMethodReference() throws Exception {
TestBean testBean = new TestBean();
Method testMethod = testBean.getClass().getMethod("exclaim", String.class);
MessageProcessor messageProcessor = new MessageMappingMethodInvoker(testBean, testMethod);
MessageProcessor messageProcessor = new MethodInvokingMessageProcessor(testBean, testMethod);
MessageProcessingTransformer transformer = new MessageProcessingTransformer(messageProcessor);
Message<?> message = new GenericMessage<Integer>(123);
Message<?> result = transformer.transform(message);
@@ -75,7 +75,7 @@ public class MethodInvokingTransformerTests {
@Test
public void typeConversionConfiguredWithMethodName() throws Exception {
TestBean testBean = new TestBean();
MessageProcessor messageProcessor = new MessageMappingMethodInvoker(testBean, "exclaim");
MessageProcessor messageProcessor = new MethodInvokingMessageProcessor(testBean, "exclaim");
MessageProcessingTransformer transformer = new MessageProcessingTransformer(messageProcessor);
Message<?> message = new GenericMessage<Integer>(123);
Message<?> result = transformer.transform(message);
@@ -86,7 +86,7 @@ public class MethodInvokingTransformerTests {
public void typeConversionFailureConfiguredWithMethodReference() throws Exception {
TestBean testBean = new TestBean();
Method testMethod = testBean.getClass().getMethod("exclaim", String.class);
MessageProcessor messageProcessor = new MessageMappingMethodInvoker(testBean, testMethod);
MessageProcessor messageProcessor = new MethodInvokingMessageProcessor(testBean, testMethod);
MessageProcessingTransformer transformer = new MessageProcessingTransformer(messageProcessor);
Message<?> message = new GenericMessage<Date>(new Date());
transformer.transform(message);
@@ -95,7 +95,7 @@ public class MethodInvokingTransformerTests {
@Test(expected = IllegalArgumentException.class)
public void typeConversionFailureConfiguredWithMethodName() throws Exception {
TestBean testBean = new TestBean();
MessageProcessor messageProcessor = new MessageMappingMethodInvoker(testBean, "exclaim");
MessageProcessor messageProcessor = new MethodInvokingMessageProcessor(testBean, "exclaim");
MessageProcessingTransformer transformer = new MessageProcessingTransformer(messageProcessor);
Message<?> message = new GenericMessage<Date>(new Date());
transformer.transform(message);
@@ -105,7 +105,7 @@ public class MethodInvokingTransformerTests {
public void headerAnnotationConfiguredWithMethodReference() throws Exception {
TestBean testBean = new TestBean();
Method testMethod = testBean.getClass().getMethod("headerTest", String.class, Integer.class);
MessageProcessor messageProcessor = new MessageMappingMethodInvoker(testBean, testMethod);
MessageProcessor messageProcessor = new MethodInvokingMessageProcessor(testBean, testMethod);
MessageProcessingTransformer transformer = new MessageProcessingTransformer(messageProcessor);
Message<String> message = MessageBuilder.withPayload("foo")
.setHeader("number", 123).build();
@@ -116,7 +116,7 @@ public class MethodInvokingTransformerTests {
@Test
public void headerAnnotationConfiguredWithMethodName() throws Exception {
TestBean testBean = new TestBean();
MessageProcessor messageProcessor = new MessageMappingMethodInvoker(testBean, "headerTest");
MessageProcessor messageProcessor = new MethodInvokingMessageProcessor(testBean, "headerTest");
MessageProcessingTransformer transformer = new MessageProcessingTransformer(messageProcessor);
Message<String> message = MessageBuilder.withPayload("foo")
.setHeader("number", 123).build();
@@ -128,7 +128,7 @@ public class MethodInvokingTransformerTests {
public void headerValueNotProvided() throws Exception {
TestBean testBean = new TestBean();
Method testMethod = testBean.getClass().getMethod("headerTest", String.class, Integer.class);
MessageProcessor messageProcessor = new MessageMappingMethodInvoker(testBean, testMethod);
MessageProcessor messageProcessor = new MethodInvokingMessageProcessor(testBean, testMethod);
MessageProcessingTransformer transformer = new MessageProcessingTransformer(messageProcessor);
Message<String> message = MessageBuilder.withPayload("foo")
.setHeader("wrong", 123).build();
@@ -139,7 +139,7 @@ public class MethodInvokingTransformerTests {
public void optionalHeaderAnnotation() throws Exception {
TestBean testBean = new TestBean();
Method testMethod = testBean.getClass().getMethod("optionalHeaderTest", String.class, Integer.class);
MessageProcessor messageProcessor = new MessageMappingMethodInvoker(testBean, testMethod);
MessageProcessor messageProcessor = new MethodInvokingMessageProcessor(testBean, testMethod);
MessageProcessingTransformer transformer = new MessageProcessingTransformer(messageProcessor);
Message<String> message = MessageBuilder.withPayload("foo").setHeader("number", 99).build();
Message<?> result = transformer.transform(message);
@@ -150,7 +150,7 @@ public class MethodInvokingTransformerTests {
public void optionalHeaderValueNotProvided() throws Exception {
TestBean testBean = new TestBean();
Method testMethod = testBean.getClass().getMethod("optionalHeaderTest", String.class, Integer.class);
MessageProcessor messageProcessor = new MessageMappingMethodInvoker(testBean, testMethod);
MessageProcessor messageProcessor = new MethodInvokingMessageProcessor(testBean, testMethod);
MessageProcessingTransformer transformer = new MessageProcessingTransformer(messageProcessor);
Message<String> message = MessageBuilder.withPayload("foo").build();
Message<?> result = transformer.transform(message);
@@ -161,7 +161,7 @@ public class MethodInvokingTransformerTests {
public void headerEnricherConfiguredWithMethodReference() throws Exception {
TestBean testBean = new TestBean();
Method testMethod = testBean.getClass().getMethod("propertyEnricherTest", String.class);
MessageProcessor messageProcessor = new MessageMappingMethodInvoker(testBean, testMethod);
MessageProcessor messageProcessor = new MethodInvokingMessageProcessor(testBean, testMethod);
MessageProcessingTransformer transformer = new MessageProcessingTransformer(messageProcessor);
Message<String> message = MessageBuilder.withPayload("test")
.setHeader("prop1", "bad")
@@ -176,7 +176,7 @@ public class MethodInvokingTransformerTests {
@Test
public void headerEnricherConfiguredWithMethodName() throws Exception {
TestBean testBean = new TestBean();
MessageProcessor messageProcessor = new MessageMappingMethodInvoker(testBean, "propertyEnricherTest");
MessageProcessor messageProcessor = new MethodInvokingMessageProcessor(testBean, "propertyEnricherTest");
MessageProcessingTransformer transformer = new MessageProcessingTransformer(messageProcessor);
Message<String> message = MessageBuilder.withPayload("test")
.setHeader("prop1", "bad")
@@ -192,7 +192,7 @@ public class MethodInvokingTransformerTests {
public void messageReturnValueConfiguredWithMethodReference() throws Exception {
TestBean testBean = new TestBean();
Method testMethod = testBean.getClass().getMethod("messageReturnValueTest", Message.class);
MessageProcessor messageProcessor = new MessageMappingMethodInvoker(testBean, testMethod);
MessageProcessor messageProcessor = new MethodInvokingMessageProcessor(testBean, testMethod);
MessageProcessingTransformer transformer = new MessageProcessingTransformer(messageProcessor);
Message<String> message = MessageBuilder.withPayload("test").build();
Message<?> result = transformer.transform(message);
@@ -202,7 +202,7 @@ public class MethodInvokingTransformerTests {
@Test
public void messageReturnValueConfiguredWithMethodName() throws Exception {
TestBean testBean = new TestBean();
MessageProcessor messageProcessor = new MessageMappingMethodInvoker(testBean, "messageReturnValueTest");
MessageProcessor messageProcessor = new MethodInvokingMessageProcessor(testBean, "messageReturnValueTest");
MessageProcessingTransformer transformer = new MessageProcessingTransformer(messageProcessor);
Message<String> message = MessageBuilder.withPayload("test").build();
Message<?> result = transformer.transform(message);
@@ -214,7 +214,7 @@ public class MethodInvokingTransformerTests {
public void propertiesPayloadConfiguredWithMethodReference() throws Exception {
TestBean testBean = new TestBean();
Method testMethod = testBean.getClass().getMethod("propertyPayloadTest", Properties.class);
MessageProcessor messageProcessor = new MessageMappingMethodInvoker(testBean, testMethod);
MessageProcessor messageProcessor = new MethodInvokingMessageProcessor(testBean, testMethod);
MessageProcessingTransformer transformer = new MessageProcessingTransformer(messageProcessor);
Properties props = new Properties();
props.setProperty("prop1", "bad");
@@ -235,7 +235,7 @@ public class MethodInvokingTransformerTests {
@SuppressWarnings("unchecked")
public void propertiesPayloadConfiguredWithMethodName() throws Exception {
TestBean testBean = new TestBean();
MessageProcessor messageProcessor = new MessageMappingMethodInvoker(testBean, "propertyPayloadTest");
MessageProcessor messageProcessor = new MethodInvokingMessageProcessor(testBean, "propertyPayloadTest");
MessageProcessingTransformer transformer = new MessageProcessingTransformer(messageProcessor);
Properties props = new Properties();
props.setProperty("prop1", "bad");
@@ -255,7 +255,7 @@ public class MethodInvokingTransformerTests {
@Test
public void nullReturningMethod() {
TestBean testBean = new TestBean();
MessageProcessor messageProcessor = new MessageMappingMethodInvoker(testBean, "nullReturnValueTest");
MessageProcessor messageProcessor = new MethodInvokingMessageProcessor(testBean, "nullReturnValueTest");
MessageProcessingTransformer transformer = new MessageProcessingTransformer(messageProcessor);
StringMessage message = new StringMessage("test");
Message<?> result = transformer.transform(message);