Added annotation-type method resolution to MessageMappingMethodInvoker.
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* Copyright 2002-2008 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.message;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class MessageMappingMethodInvokerAnnotationTests {
|
||||
|
||||
@Test
|
||||
public void singleAnnotationMatches() {
|
||||
SingleAnnotationTestBean testBean = new SingleAnnotationTestBean();
|
||||
MessageMappingMethodInvoker invoker =
|
||||
new MessageMappingMethodInvoker(testBean, TestAnnotation.class);
|
||||
invoker.afterPropertiesSet();
|
||||
String result = (String) invoker.invokeMethod("foo");
|
||||
assertEquals("FOO", result);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void multipleAnnotationMatches() {
|
||||
MultipleAnnotationTestBean testBean = new MultipleAnnotationTestBean();
|
||||
MessageMappingMethodInvoker invoker =
|
||||
new MessageMappingMethodInvoker(testBean, TestAnnotation.class);
|
||||
invoker.afterPropertiesSet();
|
||||
}
|
||||
|
||||
|
||||
@Target(ElementType.METHOD)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
private static @interface TestAnnotation {
|
||||
}
|
||||
|
||||
|
||||
private static class SingleAnnotationTestBean {
|
||||
|
||||
@TestAnnotation
|
||||
public String upperCase(String s) {
|
||||
return s.toUpperCase();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static class MultipleAnnotationTestBean {
|
||||
|
||||
@TestAnnotation
|
||||
public String upperCase(String s) {
|
||||
return s.toUpperCase();
|
||||
}
|
||||
|
||||
@TestAnnotation
|
||||
public String lowerCase(String s) {
|
||||
return s.toLowerCase();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -27,7 +27,6 @@ import java.util.concurrent.TimeUnit;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.context.support.GenericApplicationContext;
|
||||
import org.springframework.integration.ConfigurationException;
|
||||
import org.springframework.integration.bus.DefaultMessageBus;
|
||||
import org.springframework.integration.channel.QueueChannel;
|
||||
import org.springframework.integration.endpoint.ServiceActivatorEndpoint;
|
||||
@@ -38,20 +37,20 @@ import org.springframework.integration.endpoint.ServiceActivatorEndpoint;
|
||||
public class MethodInvokingConsumerTests {
|
||||
|
||||
@Test
|
||||
public void testValidMethod() {
|
||||
public void validMethod() {
|
||||
MethodInvokingConsumer consumer = new MethodInvokingConsumer(new TestSink(), "validMethod");
|
||||
consumer.afterPropertiesSet();
|
||||
consumer.onMessage(new GenericMessage<String>("test"));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testInvalidMethodWithNoArgs() {
|
||||
public void invalidMethodWithNoArgs() {
|
||||
MethodInvokingConsumer consumer = new MethodInvokingConsumer(new TestSink(), "invalidMethodWithNoArgs");
|
||||
consumer.afterPropertiesSet();
|
||||
}
|
||||
|
||||
@Test(expected = MessagingException.class)
|
||||
public void testMethodWithReturnValue() {
|
||||
public void methodWithReturnValue() {
|
||||
Message<?> message = new StringMessage("test");
|
||||
try {
|
||||
MethodInvokingConsumer consumer = new MethodInvokingConsumer(new TestSink(), "methodWithReturnValue");
|
||||
@@ -64,14 +63,14 @@ public class MethodInvokingConsumerTests {
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = ConfigurationException.class)
|
||||
public void testNoMatchingMethodName() {
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void noMatchingMethodName() {
|
||||
MethodInvokingConsumer consumer = new MethodInvokingConsumer(new TestSink(), "noSuchMethod");
|
||||
consumer.afterPropertiesSet();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSubscription() throws Exception {
|
||||
public void subscription() throws Exception {
|
||||
GenericApplicationContext context = new GenericApplicationContext();
|
||||
SynchronousQueue<String> queue = new SynchronousQueue<String>();
|
||||
TestBean testBean = new TestBean(queue);
|
||||
@@ -138,7 +137,6 @@ public class MethodInvokingConsumerTests {
|
||||
public String get() {
|
||||
return this.result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user