DefaultMethodResolver and AnnotationMethodResolver now use the target class of an AOP proxy. Added tests to DefaultMethodResolverTests: 'jdkProxy' and 'cglibProxy' (INT-425).

This commit is contained in:
Mark Fisher
2008-10-14 14:16:49 +00:00
parent b7f4c1c1e9
commit 79d9d8dc07
9 changed files with 122 additions and 7 deletions

View File

@@ -16,6 +16,7 @@
package org.springframework.integration.util;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
@@ -27,6 +28,14 @@ import java.lang.reflect.Method;
import org.junit.Test;
import org.springframework.aop.framework.ProxyFactory;
import org.springframework.integration.annotation.ServiceActivator;
import org.springframework.integration.channel.DirectChannel;
import org.springframework.integration.channel.QueueChannel;
import org.springframework.integration.endpoint.ServiceActivatorEndpoint;
import org.springframework.integration.endpoint.SubscribingConsumerEndpoint;
import org.springframework.integration.message.StringMessage;
/**
* @author Mark Fisher
*/
@@ -65,6 +74,38 @@ public class DefaultMethodResolverTests {
assertNull(method);
}
@Test
public void jdkProxy() {
DirectChannel input = new DirectChannel();
QueueChannel output = new QueueChannel();
GreetingService testBean = new GreetingBean();
ProxyFactory proxyFactory = new ProxyFactory(testBean);
proxyFactory.setProxyTargetClass(false);
testBean = (GreetingService) proxyFactory.getProxy();
ServiceActivatorEndpoint consumer = new ServiceActivatorEndpoint(testBean);
consumer.setOutputChannel(output);
SubscribingConsumerEndpoint endpoint = new SubscribingConsumerEndpoint(consumer, input);
endpoint.start();
input.send(new StringMessage("proxy"));
assertEquals("hello proxy", output.receive(0).getPayload());;
}
@Test
public void cglibProxy() {
DirectChannel input = new DirectChannel();
QueueChannel output = new QueueChannel();
GreetingService testBean = new GreetingBean();
ProxyFactory proxyFactory = new ProxyFactory(testBean);
proxyFactory.setProxyTargetClass(true);
testBean = (GreetingService) proxyFactory.getProxy();
ServiceActivatorEndpoint consumer = new ServiceActivatorEndpoint(testBean);
consumer.setOutputChannel(output);
SubscribingConsumerEndpoint endpoint = new SubscribingConsumerEndpoint(consumer, input);
endpoint.start();
input.send(new StringMessage("proxy"));
assertEquals("hello proxy", output.receive(0).getPayload());;
}
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@@ -130,4 +171,27 @@ public class DefaultMethodResolverTests {
}
}
public interface GreetingService {
String sayHello(String s);
}
public static class GreetingBean implements GreetingService {
private String greeting = "hello";
public void setGreeting(String greeting) {
this.greeting = greeting;
}
@ServiceActivator
public String sayHello(String name) {
return greeting + " " + name;
}
}
}