INT-1343, INT-1355 @Publisher can now be used as a meta-annotation, and when the "channel" is not available at method-level, a class-level annotation will now be checked next, and only if neither are present will it fall back to the default channel of the advisor.

This commit is contained in:
Mark Fisher
2010-08-17 22:18:40 +00:00
parent 3eed02fbb3
commit 929e14a320
3 changed files with 222 additions and 21 deletions

View File

@@ -19,6 +19,11 @@ package org.springframework.integration.aop;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.junit.Before;
import org.junit.Test;
@@ -38,16 +43,17 @@ public class PublisherAnnotationAdvisorTests {
@Before
public void setup() {
context.registerSingleton("testChannel", QueueChannel.class);
context.registerSingleton("testChannel", QueueChannel.class);
context.registerSingleton("testMetaChannel", QueueChannel.class);
}
@Test
public void returnValue() {
public void annotationAtMethodLevel() {
PublisherAnnotationAdvisor advisor = new PublisherAnnotationAdvisor();
advisor.setBeanFactory(context);
QueueChannel testChannel = context.getBean("testChannel", QueueChannel.class);
advisor.setDefaultChannel(testChannel);
ProxyFactory pf = new ProxyFactory(new TestBeanImpl());
ProxyFactory pf = new ProxyFactory(new AnnotationAtMethodLevelTestBeanImpl());
pf.addAdvisor(advisor);
TestBean proxy = (TestBean) pf.getProxy();
proxy.test();
@@ -56,6 +62,48 @@ public class PublisherAnnotationAdvisorTests {
assertEquals("foo", message.getPayload());
}
@Test
public void annotationAtClassLevel() {
PublisherAnnotationAdvisor advisor = new PublisherAnnotationAdvisor();
advisor.setBeanFactory(context);
QueueChannel testChannel = context.getBean("testChannel", QueueChannel.class);
ProxyFactory pf = new ProxyFactory(new AnnotationAtClassLevelTestBeanImpl());
pf.addAdvisor(advisor);
TestBean proxy = (TestBean) pf.getProxy();
proxy.test();
Message<?> message = testChannel.receive(0);
assertNotNull(message);
assertEquals("foo", message.getPayload());
}
@Test
public void metaAnnotationAtMethodLevel() {
PublisherAnnotationAdvisor advisor = new PublisherAnnotationAdvisor();
advisor.setBeanFactory(context);
QueueChannel testMetaChannel = context.getBean("testMetaChannel", QueueChannel.class);
ProxyFactory pf = new ProxyFactory(new MetaAnnotationAtMethodLevelTestBeanImpl());
pf.addAdvisor(advisor);
TestBean proxy = (TestBean) pf.getProxy();
proxy.test();
Message<?> message = testMetaChannel.receive(0);
assertNotNull(message);
assertEquals("foo", message.getPayload());
}
@Test
public void metaAnnotationAtClassLevel() {
PublisherAnnotationAdvisor advisor = new PublisherAnnotationAdvisor();
advisor.setBeanFactory(context);
QueueChannel testMetaChannel = context.getBean("testMetaChannel", QueueChannel.class);
ProxyFactory pf = new ProxyFactory(new MetaAnnotationAtClassLevelTestBeanImpl());
pf.addAdvisor(advisor);
TestBean proxy = (TestBean) pf.getProxy();
proxy.test();
Message<?> message = testMetaChannel.receive(0);
assertNotNull(message);
assertEquals("foo", message.getPayload());
}
static interface TestBean {
@@ -64,13 +112,48 @@ public class PublisherAnnotationAdvisorTests {
}
static class TestBeanImpl implements TestBean {
static class AnnotationAtMethodLevelTestBeanImpl implements TestBean {
@Publisher
@Publisher(channel="testChannel")
public String test() {
return "foo";
}
}
@Publisher(channel="testChannel")
static class AnnotationAtClassLevelTestBeanImpl implements TestBean {
public String test() {
return "foo";
}
}
@Target({ElementType.METHOD, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Publisher(channel="testMetaChannel")
public @interface TestMetaPublisher {
}
static class MetaAnnotationAtMethodLevelTestBeanImpl implements TestBean {
@TestMetaPublisher
public String test() {
return "foo";
}
}
@TestMetaPublisher
static class MetaAnnotationAtClassLevelTestBeanImpl implements TestBean {
public String test() {
return "foo";
}
}
}