INT-1494 added test for header expressions

This commit is contained in:
Mark Fisher
2010-10-17 11:12:15 -04:00
parent 0b6c04c0ea
commit a6769f6fef

View File

@@ -19,8 +19,14 @@ package org.springframework.integration.message;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import java.util.HashMap;
import java.util.Map;
import org.junit.Test;
import org.springframework.expression.Expression;
import org.springframework.expression.common.LiteralExpression;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.integration.Message;
import org.springframework.integration.MessagingException;
import org.springframework.integration.endpoint.MethodInvokingMessageSource;
@@ -41,6 +47,23 @@ public class MethodInvokingMessageSourceTests {
assertEquals("valid", result.getPayload());
}
@Test
public void testHeaderExpressions() {
Map<String, Expression> headerExpressions = new HashMap<String, Expression>();
headerExpressions.put("foo", new LiteralExpression("abc"));
headerExpressions.put("bar", new SpelExpressionParser().parseExpression("new Integer(123)"));
MethodInvokingMessageSource source = new MethodInvokingMessageSource();
source.setObject(new TestBean());
source.setMethodName("validMethod");
source.setHeaderExpressions(headerExpressions);
Message<?> result = source.receive();
assertNotNull(result);
assertNotNull(result.getPayload());
assertEquals("valid", result.getPayload());
assertEquals("abc", result.getHeaders().get("foo"));
assertEquals(123, result.getHeaders().get("bar"));
}
@Test(expected=MessagingException.class)
public void testNoMatchingMethodName() {
MethodInvokingMessageSource source = new MethodInvokingMessageSource();