From 5c7f97f1015cc67e6b8ee71177ae1b877482e832 Mon Sep 17 00:00:00 2001 From: Mark Fisher Date: Thu, 2 Sep 2010 14:19:57 +0000 Subject: [PATCH] INT-1401 EvaluationContext variable names are now fixed (#return, #method, #args, and #exception) --- .../aop/AbstractExpressionSource.java | 88 ------------------- .../integration/aop/ExpressionBinding.java | 67 -------------- .../integration/aop/ExpressionSource.java | 53 +++-------- .../aop/MessagePublishingInterceptor.java | 20 +++-- .../aop/MethodAnnotationExpressionSource.java | 65 +++----------- .../MethodNameMappingExpressionSource.java | 18 +--- .../aop/SimpleExpressionSource.java | 10 +-- .../MessagePublishingInterceptorTests.java | 26 +----- ...MethodAnnotationExpressionSourceTests.java | 61 ++++++------- 9 files changed, 69 insertions(+), 339 deletions(-) delete mode 100644 spring-integration-core/src/main/java/org/springframework/integration/aop/AbstractExpressionSource.java delete mode 100644 spring-integration-core/src/main/java/org/springframework/integration/aop/ExpressionBinding.java diff --git a/spring-integration-core/src/main/java/org/springframework/integration/aop/AbstractExpressionSource.java b/spring-integration-core/src/main/java/org/springframework/integration/aop/AbstractExpressionSource.java deleted file mode 100644 index d507de58c2..0000000000 --- a/spring-integration-core/src/main/java/org/springframework/integration/aop/AbstractExpressionSource.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright 2002-2010 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.integration.aop; - -import java.lang.reflect.Method; -import java.util.Map; - -import org.springframework.core.LocalVariableTableParameterNameDiscoverer; -import org.springframework.core.ParameterNameDiscoverer; - -/** - * Base class for {@link ExpressionSource} implementations. - * - * @author Mark Fisher - * @since 2.0 - */ -public abstract class AbstractExpressionSource implements ExpressionSource { - - private volatile String methodNameVariableName = ExpressionSource.DEFAULT_METHOD_NAME_VARIABLE_NAME; - - private volatile String argumentMapVariableName = ExpressionSource.DEFAULT_ARGUMENT_MAP_VARIABLE_NAME; - - private volatile String returnValueVariableName = ExpressionSource.DEFAULT_RETURN_VALUE_VARIABLE_NAME; - - private volatile String exceptionVariableName = ExpressionSource.DEFAULT_EXCEPTION_VARIABLE_NAME; - - private final ParameterNameDiscoverer parameterNameDiscoverer = new LocalVariableTableParameterNameDiscoverer(); - - - public void setMethodNameVariableName(String methodNameVariableName) { - this.methodNameVariableName = methodNameVariableName; - } - - public String getMethodNameVariableName(Method method) { - return this.methodNameVariableName; - } - - public void setArgumentMapVariableName(String argumentMapVariableName) { - this.argumentMapVariableName = argumentMapVariableName; - } - - public String getArgumentMapVariableName(Method method) { - return this.argumentMapVariableName; - } - - public void setExceptionVariableName(String exceptionVariableName) { - this.exceptionVariableName = exceptionVariableName; - } - - public String getExceptionVariableName(Method method) { - return this.exceptionVariableName; - } - - public void setReturnValueVariableName(String returnValueVariableName) { - this.returnValueVariableName = returnValueVariableName; - } - - public String getReturnValueVariableName(Method method) { - return this.returnValueVariableName; - } - - protected String[] discoverMethodParameterNames(Method method) { - return this.parameterNameDiscoverer.getParameterNames(method); - } - - public abstract String getPayloadExpression(Method method); - - public abstract String[] getArgumentVariableNames(Method method); - - public abstract Map getHeaderExpressions(Method method); - - public abstract String getChannelName(Method method); - -} diff --git a/spring-integration-core/src/main/java/org/springframework/integration/aop/ExpressionBinding.java b/spring-integration-core/src/main/java/org/springframework/integration/aop/ExpressionBinding.java deleted file mode 100644 index 1c240f7721..0000000000 --- a/spring-integration-core/src/main/java/org/springframework/integration/aop/ExpressionBinding.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.integration.aop; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Annotation that provides the variable names to use when constructing the - * evaluation context for a MessagePublishingInterceptor. - * - * @author Mark Fisher - * @since 2.0 - */ -@Target({ElementType.METHOD, ElementType.TYPE}) -@Retention(RetentionPolicy.RUNTIME) -public @interface ExpressionBinding { - - /** - * Name of the variable in the context that refers to the method name. - *

The default is "method". - */ - String methodNameVariableName() default ExpressionSource.DEFAULT_METHOD_NAME_VARIABLE_NAME; - - /** - * Names of the arguments as a comma-separated list. If not provided, the - * names will be discovered automatically if enabled by the compiler settings. - * These names will be used as the keys in the argument Map. - */ - String argumentVariableNames() default ""; - - /** - * Name of the variable in the context that refers to the Map of arguments. - *

The default is "args". - */ - String argumentMapVariableName() default ExpressionSource.DEFAULT_ARGUMENT_MAP_VARIABLE_NAME; - - /** - * Name of the variable in the context that refers to the return value, if any. - *

The default is "return". - */ - String returnValueVariableName() default ExpressionSource.DEFAULT_RETURN_VALUE_VARIABLE_NAME; - - /** - * Name of the variable in the context that refers to any exception thrown - * by the method invocation that is being intercepted. - *

The default is "exception". - */ - String exceptionVariableName() default ExpressionSource.DEFAULT_EXCEPTION_VARIABLE_NAME; - -} diff --git a/spring-integration-core/src/main/java/org/springframework/integration/aop/ExpressionSource.java b/spring-integration-core/src/main/java/org/springframework/integration/aop/ExpressionSource.java index 2a03882b9f..7dbad9b812 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/aop/ExpressionSource.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/aop/ExpressionSource.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2009 the original author or authors. + * Copyright 2002-2010 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. @@ -28,15 +28,21 @@ import java.util.Map; */ interface ExpressionSource { - static final String DEFAULT_METHOD_NAME_VARIABLE_NAME = "method"; + static final String METHOD_NAME_VARIABLE_NAME = "method"; - static final String DEFAULT_ARGUMENT_MAP_VARIABLE_NAME = "args"; + static final String ARGUMENT_MAP_VARIABLE_NAME = "args"; - static final String DEFAULT_RETURN_VALUE_VARIABLE_NAME = "return"; + static final String RETURN_VALUE_VARIABLE_NAME = "return"; - static final String DEFAULT_EXCEPTION_VARIABLE_NAME = "exception"; + static final String EXCEPTION_VARIABLE_NAME = "exception"; + /** + * Returns the channel name to which Messages should be published + * for this particular method invocation. + */ + String getChannelName(Method method); + /** * Returns the expression string to be evaluated for creating the Message * payload. @@ -50,41 +56,4 @@ interface ExpressionSource { */ Map getHeaderExpressions(Method method); - /** - * Returns the variable name to be associated with the intercepted - * method's name. - */ - String getMethodNameVariableName(Method method); - - /** - * Returns the variable names to be associated with the intercepted method - * invocation's argument array. - */ - String[] getArgumentVariableNames(Method method); - - /** - * Returns the variable name to use in the evaluation context for the Map - * of arguments. The keys in this map will be determined by the result of - * the {@link #getArgumentVariableNames(Method)} method. - */ - String getArgumentMapVariableName(Method method); - - /** - * Returns the variable name to use in the evaluation context for any - * return value resulting from the method invocation. - */ - String getReturnValueVariableName(Method method); - - /** - * Returns the variable name to use in the evaluation context for any - * exception thrown from the method invocation. - */ - String getExceptionVariableName(Method method); - - /** - * Returns the channel name to which Messages should be published - * for this particular method invocation. - */ - String getChannelName(Method method); - } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/aop/MessagePublishingInterceptor.java b/spring-integration-core/src/main/java/org/springframework/integration/aop/MessagePublishingInterceptor.java index 427c9dbc2e..f892b96110 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/aop/MessagePublishingInterceptor.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/aop/MessagePublishingInterceptor.java @@ -25,6 +25,8 @@ import org.aopalliance.intercept.MethodInvocation; import org.springframework.aop.support.AopUtils; import org.springframework.context.expression.MapAccessor; +import org.springframework.core.LocalVariableTableParameterNameDiscoverer; +import org.springframework.core.ParameterNameDiscoverer; import org.springframework.expression.EvaluationException; import org.springframework.expression.Expression; import org.springframework.expression.ExpressionParser; @@ -59,6 +61,8 @@ public class MessagePublishingInterceptor implements MethodInterceptor { private volatile ChannelResolver channelResolver; + private final ParameterNameDiscoverer parameterNameDiscoverer = new LocalVariableTableParameterNameDiscoverer(); + public MessagePublishingInterceptor(ExpressionSource expressionSource) { Assert.notNull(expressionSource, "expressionSource must not be null"); @@ -85,8 +89,8 @@ public class MessagePublishingInterceptor implements MethodInterceptor { context.addPropertyAccessor(new MapAccessor()); Class targetClass = AopUtils.getTargetClass(invocation.getThis()); Method method = AopUtils.getMostSpecificMethod(invocation.getMethod(), targetClass); - String[] argumentNames = this.expressionSource.getArgumentVariableNames(method); - context.setVariable(this.expressionSource.getMethodNameVariableName(method), method.getName()); + String[] argumentNames = this.resolveArgumentNames(method); + context.setVariable(ExpressionSource.METHOD_NAME_VARIABLE_NAME, method.getName()); if (invocation.getArguments().length > 0 && argumentNames != null) { Map argumentMap = new HashMap(); for (int i = 0; i < argumentNames.length; i++) { @@ -97,15 +101,15 @@ public class MessagePublishingInterceptor implements MethodInterceptor { argumentMap.put("" + i, argValue); argumentMap.put(argumentNames[i], argValue); } - context.setVariable(this.expressionSource.getArgumentMapVariableName(method), argumentMap); + context.setVariable(ExpressionSource.ARGUMENT_MAP_VARIABLE_NAME, argumentMap); } try { Object returnValue = invocation.proceed(); - context.setVariable(this.expressionSource.getReturnValueVariableName(method), returnValue); + context.setVariable(ExpressionSource.RETURN_VALUE_VARIABLE_NAME, returnValue); return returnValue; } catch (Throwable t) { - context.setVariable(this.expressionSource.getExceptionVariableName(method), t); + context.setVariable(ExpressionSource.EXCEPTION_VARIABLE_NAME, t); throw t; } finally { @@ -113,10 +117,14 @@ public class MessagePublishingInterceptor implements MethodInterceptor { } } + private String[] resolveArgumentNames(Method method) { + return this.parameterNameDiscoverer.getParameterNames(method); + } + private void publishMessage(Method method, StandardEvaluationContext context) throws Exception { String payloadExpressionString = this.expressionSource.getPayloadExpression(method); if (!StringUtils.hasText(payloadExpressionString)) { - payloadExpressionString = "#" + this.expressionSource.getReturnValueVariableName(method); + payloadExpressionString = "#" + ExpressionSource.RETURN_VALUE_VARIABLE_NAME; } Expression expression = this.parser.parseExpression(payloadExpressionString); Object result = expression.getValue(context); diff --git a/spring-integration-core/src/main/java/org/springframework/integration/aop/MethodAnnotationExpressionSource.java b/spring-integration-core/src/main/java/org/springframework/integration/aop/MethodAnnotationExpressionSource.java index 3c5957ecf5..bfaa026701 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/aop/MethodAnnotationExpressionSource.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/aop/MethodAnnotationExpressionSource.java @@ -62,6 +62,14 @@ public class MethodAnnotationExpressionSource implements ExpressionSource { this.channelAttributeName = channelAttributeName; } + public String getChannelName(Method method) { + String channelName = this.getAnnotationValue(method, this.channelAttributeName, String.class); + if (channelName == null) { + channelName = this.getAnnotationValue(method.getDeclaringClass(), this.channelAttributeName, String.class); + } + return (StringUtils.hasText(channelName) ? channelName : null); + } + public String getPayloadExpression(Method method) { String payloadExpression = null; method.getAnnotation(Payload.class); @@ -69,7 +77,7 @@ public class MethodAnnotationExpressionSource implements ExpressionSource { if (methodPayloadAnnotation != null) { payloadExpression = StringUtils.hasText(methodPayloadAnnotation.value()) ? methodPayloadAnnotation.value() - : "#" + this.getReturnValueVariableName(method); + : "#" + ExpressionSource.RETURN_VALUE_VARIABLE_NAME; } Annotation[][] annotationArray = method.getParameterAnnotations(); for (int i = 0; i < annotationArray.length; i++) { @@ -80,7 +88,7 @@ public class MethodAnnotationExpressionSource implements ExpressionSource { "@Payload can be used at most once on a @Publisher method, either at method-level or on a single parameter"); Assert.state("".equals(((Payload) currentAnnotation).value()), "@Payload on a parameter for a @Publisher method may not contain an expression"); - payloadExpression = "#" + this.getArgumentMapVariableName(method) + "[" + i + "]"; + payloadExpression = "#" + ExpressionSource.ARGUMENT_MAP_VARIABLE_NAME + "[" + i + "]"; } } } @@ -100,64 +108,13 @@ public class MethodAnnotationExpressionSource implements ExpressionSource { if (!StringUtils.hasText(name)) { name = parameterNames[i]; } - headerExpressions.put(name, "#" + this.getArgumentMapVariableName(method) + "['" + i + "']"); + headerExpressions.put(name, "#" + ExpressionSource.ARGUMENT_MAP_VARIABLE_NAME + "['" + i + "']"); } } } return headerExpressions; } - public String getMethodNameVariableName(Method method) { - ExpressionBinding annotation = AnnotationUtils.findAnnotation(method, ExpressionBinding.class); - if (annotation != null) { - return annotation.methodNameVariableName(); - } - return ExpressionSource.DEFAULT_METHOD_NAME_VARIABLE_NAME; - } - - public String[] getArgumentVariableNames(Method method) { - ExpressionBinding annotation = AnnotationUtils.findAnnotation(method, ExpressionBinding.class); - if (annotation != null) { - String argNameList = annotation.argumentVariableNames(); - if (StringUtils.hasText(argNameList)) { - return StringUtils.tokenizeToStringArray(argNameList, ","); - } - } - return this.parameterNameDiscoverer.getParameterNames(method); - } - - public String getArgumentMapVariableName(Method method) { - ExpressionBinding annotation = AnnotationUtils.findAnnotation(method, ExpressionBinding.class); - if (annotation != null) { - return annotation.argumentMapVariableName(); - } - return ExpressionSource.DEFAULT_ARGUMENT_MAP_VARIABLE_NAME; - } - - public String getReturnValueVariableName(Method method) { - ExpressionBinding annotation = AnnotationUtils.findAnnotation(method, ExpressionBinding.class); - if (annotation != null) { - return annotation.returnValueVariableName(); - } - return ExpressionSource.DEFAULT_RETURN_VALUE_VARIABLE_NAME; - } - - public String getExceptionVariableName(Method method) { - ExpressionBinding annotation = AnnotationUtils.findAnnotation(method, ExpressionBinding.class); - if (annotation != null) { - return annotation.exceptionVariableName(); - } - return ExpressionSource.DEFAULT_EXCEPTION_VARIABLE_NAME; - } - - public String getChannelName(Method method) { - String channelName = this.getAnnotationValue(method, this.channelAttributeName, String.class); - if (channelName == null) { - channelName = this.getAnnotationValue(method.getDeclaringClass(), this.channelAttributeName, String.class); - } - return (StringUtils.hasText(channelName) ? channelName : null); - } - private T getAnnotationValue(Method method, String attributeName, Class expectedType) { T value = null; for (Class annotationType : this.annotationTypes) { diff --git a/spring-integration-core/src/main/java/org/springframework/integration/aop/MethodNameMappingExpressionSource.java b/spring-integration-core/src/main/java/org/springframework/integration/aop/MethodNameMappingExpressionSource.java index b675b44dd2..5097d5a8c1 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/aop/MethodNameMappingExpressionSource.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/aop/MethodNameMappingExpressionSource.java @@ -27,7 +27,7 @@ import org.springframework.util.PatternMatchUtils; * @author Mark Fisher * @since 2.0 */ -public class MethodNameMappingExpressionSource extends AbstractExpressionSource { +public class MethodNameMappingExpressionSource implements ExpressionSource { private final Map payloadExpressionMap; @@ -35,17 +35,12 @@ public class MethodNameMappingExpressionSource extends AbstractExpressionSource private volatile Map channelMap = Collections.emptyMap(); - private volatile Map argumentVariableNameMap; - public MethodNameMappingExpressionSource(Map payloadExpressionMap) { Assert.notEmpty(payloadExpressionMap, "payloadExpressionMap must not be empty"); this.payloadExpressionMap = payloadExpressionMap; } - public void setArgumentVariableNameMap(Map argumentVariableNameMap) { - this.argumentVariableNameMap = argumentVariableNameMap; - } public void setHeaderExpressionMap(Map> headerExpressionMap) { this.headerExpressionMap = headerExpressionMap; @@ -55,17 +50,6 @@ public class MethodNameMappingExpressionSource extends AbstractExpressionSource this.channelMap = channelMap; } - public String[] getArgumentVariableNames(Method method) { - if (this.argumentVariableNameMap != null) { - for (Map.Entry entry : this.argumentVariableNameMap.entrySet()) { - if (PatternMatchUtils.simpleMatch(entry.getKey(), method.getName())) { - return entry.getValue(); - } - } - } - return this.discoverMethodParameterNames(method); - } - public String getPayloadExpression(Method method) { for (Map.Entry entry : this.payloadExpressionMap.entrySet()) { if (PatternMatchUtils.simpleMatch(entry.getKey(), method.getName())) { diff --git a/spring-integration-core/src/main/java/org/springframework/integration/aop/SimpleExpressionSource.java b/spring-integration-core/src/main/java/org/springframework/integration/aop/SimpleExpressionSource.java index 118171ca5e..748b1e1876 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/aop/SimpleExpressionSource.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/aop/SimpleExpressionSource.java @@ -27,7 +27,7 @@ import java.util.Map; * @author Mark Fisher * @since 2.0 */ -public class SimpleExpressionSource extends AbstractExpressionSource { +public class SimpleExpressionSource implements ExpressionSource { private volatile String channelName; @@ -40,7 +40,6 @@ public class SimpleExpressionSource extends AbstractExpressionSource { this.channelName = channelName; } - @Override public String getChannelName(Method method) { return this.channelName; } @@ -49,7 +48,6 @@ public class SimpleExpressionSource extends AbstractExpressionSource { this.payloadExpression = payloadExpression; } - @Override public String getPayloadExpression(Method method) { return this.payloadExpression; } @@ -58,14 +56,8 @@ public class SimpleExpressionSource extends AbstractExpressionSource { this.headerExpressions = headerExpressions; } - @Override public Map getHeaderExpressions(Method method) { return this.headerExpressions; } - @Override - public String[] getArgumentVariableNames(Method method) { - return this.discoverMethodParameterNames(method); - } - } diff --git a/spring-integration-core/src/test/java/org/springframework/integration/aop/MessagePublishingInterceptorTests.java b/spring-integration-core/src/test/java/org/springframework/integration/aop/MessagePublishingInterceptorTests.java index 90c23521c2..078819f346 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/aop/MessagePublishingInterceptorTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/aop/MessagePublishingInterceptorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2009 the original author or authors. + * Copyright 2002-2010 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. @@ -61,7 +61,7 @@ public class MessagePublishingInterceptorTests { proxy.test(); Message message = testChannel.receive(0); assertNotNull(message); - assertEquals("foo", message.getPayload()); + assertEquals("test-foo", message.getPayload()); } @Test public void demoMethodNameMappingExpressionSource() { @@ -111,28 +111,8 @@ public class MessagePublishingInterceptorTests { private static class TestExpressionSource implements ExpressionSource { - public String getMethodNameVariableName(Method method) { - return "m"; - } - - public String getArgumentMapVariableName(Method method) { - return "map"; - } - - public String[] getArgumentVariableNames(Method method) { - return new String[] { "a1", "a2"}; - } - - public String getReturnValueVariableName(Method method) { - return "r"; - } - - public String getExceptionVariableName(Method method) { - return "x"; - } - public String getPayloadExpression(Method method) { - return "#r"; + return "'test-' + #return"; } public Map getHeaderExpressions(Method method) { diff --git a/spring-integration-core/src/test/java/org/springframework/integration/aop/MethodAnnotationExpressionSourceTests.java b/spring-integration-core/src/test/java/org/springframework/integration/aop/MethodAnnotationExpressionSourceTests.java index cc0bac665f..6660384703 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/aop/MethodAnnotationExpressionSourceTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/aop/MethodAnnotationExpressionSourceTests.java @@ -24,6 +24,7 @@ import java.util.Map; import org.junit.Test; +import org.springframework.integration.annotation.Header; import org.springframework.integration.annotation.Payload; /** @@ -34,40 +35,36 @@ public class MethodAnnotationExpressionSourceTests { private final MethodAnnotationExpressionSource source = new MethodAnnotationExpressionSource(); - @Test - public void defaultBindings() { - Method method = getMethod("methodWithExpressionAnnotationOnly", String.class, int.class); - String expressionString = source.getPayloadExpression(method); - assertEquals("testExpression1", expressionString); - assertEquals(2, source.getArgumentVariableNames(method).length); - assertEquals("arg1", source.getArgumentVariableNames(method)[0]); - assertEquals("arg2", source.getArgumentVariableNames(method)[1]); - Map headerMap = source.getHeaderExpressions(method); - assertNotNull(headerMap); - assertEquals(0, headerMap.size()); - assertEquals(ExpressionSource.DEFAULT_ARGUMENT_MAP_VARIABLE_NAME, source.getArgumentMapVariableName(method)); - assertEquals(ExpressionSource.DEFAULT_EXCEPTION_VARIABLE_NAME, source.getExceptionVariableName(method)); - assertEquals(ExpressionSource.DEFAULT_RETURN_VALUE_VARIABLE_NAME, source.getReturnValueVariableName(method)); - } - - @Test - public void annotationBindings() { - Method method = getMethod("methodWithExpressionBinding", String.class, int.class); - String expressionString = source.getPayloadExpression(method); - assertEquals("testExpression2", expressionString); - assertEquals(2, source.getArgumentVariableNames(method).length); - assertEquals("s", source.getArgumentVariableNames(method)[0]); - assertEquals("i", source.getArgumentVariableNames(method)[1]); - assertEquals("argz", source.getArgumentMapVariableName(method)); - assertEquals("x", source.getExceptionVariableName(method)); - assertEquals("result", source.getReturnValueVariableName(method)); - } @Test public void channelName() { Method method = getMethod("methodWithChannelAndReturnAsPayload"); String channelName = source.getChannelName(method); + String payloadExpression = source.getPayloadExpression(method); assertEquals("foo", channelName); + assertEquals("#method", payloadExpression); + } + + @Test + public void payloadButNoHeaders() { + Method method = getMethod("methodWithPayloadAnnotation", String.class, int.class); + String expressionString = source.getPayloadExpression(method); + assertEquals("testExpression1", expressionString); + Map headerMap = source.getHeaderExpressions(method); + assertNotNull(headerMap); + assertEquals(0, headerMap.size()); + } + + @Test + public void payloadAndHeaders() { + Method method = getMethod("methodWithHeaderAnnotations", String.class, String.class, String.class); + String expressionString = source.getPayloadExpression(method); + assertEquals("testExpression2", expressionString); + Map headerMap = source.getHeaderExpressions(method); + assertNotNull(headerMap); + assertEquals(2, headerMap.size()); + assertEquals("#args['1']", headerMap.get("foo")); + assertEquals("#args['2']", headerMap.get("bar")); } @@ -83,19 +80,17 @@ public class MethodAnnotationExpressionSourceTests { @Publisher @Payload("testExpression1") - public void methodWithExpressionAnnotationOnly(String arg1, int arg2) { + public void methodWithPayloadAnnotation(String arg1, int arg2) { } @Publisher(channel="foo") - @Payload + @Payload("#method") public void methodWithChannelAndReturnAsPayload() { } @Publisher @Payload("testExpression2") - @ExpressionBinding(argumentVariableNames="s, i", argumentMapVariableName="argz", - exceptionVariableName="x", returnValueVariableName="result") - public void methodWithExpressionBinding(String arg1, int arg2) { + public void methodWithHeaderAnnotations(String arg1, @Header("foo") String h1, @Header("bar") String h2) { } }