Publisher annotation interceptor now delegates to a ChannelResolver instance rather than a ChannelRegistry.
This commit is contained in:
@@ -21,15 +21,11 @@ import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.aop.framework.ProxyFactory;
|
||||
import org.springframework.integration.channel.ChannelRegistry;
|
||||
import org.springframework.integration.channel.MessageChannel;
|
||||
import org.springframework.integration.channel.QueueChannel;
|
||||
import org.springframework.integration.channel.TestChannelResolver;
|
||||
import org.springframework.integration.message.Message;
|
||||
|
||||
/**
|
||||
@@ -41,9 +37,9 @@ public class PublisherAnnotationAdvisorTests {
|
||||
public void testPublisherAnnotation() {
|
||||
final QueueChannel channel = new QueueChannel();
|
||||
channel.setBeanName("testChannel");
|
||||
TestChannelRegistry channelRegistry = new TestChannelRegistry();
|
||||
channelRegistry.registerChannel(channel);
|
||||
PublisherAnnotationAdvisor advisor = new PublisherAnnotationAdvisor(channelRegistry);
|
||||
TestChannelResolver channelResolver = new TestChannelResolver();
|
||||
channelResolver.addChannel(channel);
|
||||
PublisherAnnotationAdvisor advisor = new PublisherAnnotationAdvisor(channelResolver);
|
||||
TestService proxy = (TestService) this.createProxy(new TestServiceImpl("hello world"), advisor);
|
||||
proxy.publisherTest();
|
||||
Message<?> message = channel.receive(0);
|
||||
@@ -55,9 +51,9 @@ public class PublisherAnnotationAdvisorTests {
|
||||
public void testNoPublisherAnnotation() {
|
||||
final QueueChannel channel = new QueueChannel();
|
||||
channel.setBeanName("testChannel");
|
||||
TestChannelRegistry channelRegistry = new TestChannelRegistry();
|
||||
channelRegistry.registerChannel(channel);
|
||||
PublisherAnnotationAdvisor advisor = new PublisherAnnotationAdvisor(channelRegistry);
|
||||
TestChannelResolver channelResolver = new TestChannelResolver();
|
||||
channelResolver.addChannel(channel);
|
||||
PublisherAnnotationAdvisor advisor = new PublisherAnnotationAdvisor(channelResolver);
|
||||
TestService proxy = (TestService) this.createProxy(new TestServiceImpl("hello world"), advisor);
|
||||
proxy.noPublisherTest();
|
||||
Message<?> message = channel.receive(0);
|
||||
@@ -68,9 +64,9 @@ public class PublisherAnnotationAdvisorTests {
|
||||
public void testPublishArguments() {
|
||||
final QueueChannel channel = new QueueChannel();
|
||||
channel.setBeanName("testChannel");
|
||||
TestChannelRegistry channelRegistry = new TestChannelRegistry();
|
||||
channelRegistry.registerChannel(channel);
|
||||
PublisherAnnotationAdvisor advisor = new PublisherAnnotationAdvisor(channelRegistry);
|
||||
TestChannelResolver channelResolver = new TestChannelResolver();
|
||||
channelResolver.addChannel(channel);
|
||||
PublisherAnnotationAdvisor advisor = new PublisherAnnotationAdvisor(channelResolver);
|
||||
TestService proxy = (TestService) this.createProxy(new TestServiceImpl("hello world"), advisor);
|
||||
proxy.publishArguments("foo", 99);
|
||||
Message<?> message = channel.receive(0);
|
||||
@@ -86,9 +82,9 @@ public class PublisherAnnotationAdvisorTests {
|
||||
public void testPublishException() {
|
||||
final QueueChannel channel = new QueueChannel();
|
||||
channel.setBeanName("testChannel");
|
||||
TestChannelRegistry channelRegistry = new TestChannelRegistry();
|
||||
channelRegistry.registerChannel(channel);
|
||||
PublisherAnnotationAdvisor advisor = new PublisherAnnotationAdvisor(channelRegistry);
|
||||
TestChannelResolver channelResolver = new TestChannelResolver();
|
||||
channelResolver.addChannel(channel);
|
||||
PublisherAnnotationAdvisor advisor = new PublisherAnnotationAdvisor(channelResolver);
|
||||
TestService proxy = (TestService) this.createProxy(new TestServiceImpl("hello world"), advisor);
|
||||
RuntimeException caughtException = null;
|
||||
try {
|
||||
@@ -109,9 +105,9 @@ public class PublisherAnnotationAdvisorTests {
|
||||
public void testPublishReturnValue() {
|
||||
final QueueChannel channel = new QueueChannel();
|
||||
channel.setBeanName("testChannel");
|
||||
TestChannelRegistry channelRegistry = new TestChannelRegistry();
|
||||
channelRegistry.registerChannel(channel);
|
||||
PublisherAnnotationAdvisor advisor = new PublisherAnnotationAdvisor(channelRegistry);
|
||||
TestChannelResolver channelResolver = new TestChannelResolver();
|
||||
channelResolver.addChannel(channel);
|
||||
PublisherAnnotationAdvisor advisor = new PublisherAnnotationAdvisor(channelResolver);
|
||||
TestService proxy = (TestService) this.createProxy(new TestServiceImpl("hello world"), advisor);
|
||||
Integer actualReturnValue = proxy.publishReturnValue();
|
||||
Message<?> message = channel.receive(0);
|
||||
@@ -174,18 +170,4 @@ public class PublisherAnnotationAdvisorTests {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static class TestChannelRegistry implements ChannelRegistry {
|
||||
|
||||
private final Map<String, MessageChannel> channels = new HashMap<String, MessageChannel>();
|
||||
|
||||
public MessageChannel lookupChannel(String channelName) {
|
||||
return this.channels.get(channelName);
|
||||
}
|
||||
|
||||
public void registerChannel(MessageChannel channel) {
|
||||
this.channels.put(channel.getName(), channel);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,24 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
|
||||
|
||||
<bean id="messageBus" class="org.springframework.integration.bus.DefaultMessageBus">
|
||||
<property name="taskScheduler">
|
||||
<bean class="org.springframework.integration.util.TestUtils"
|
||||
factory-method="createTaskScheduler">
|
||||
<constructor-arg value="10"/>
|
||||
</bean>
|
||||
</property>
|
||||
</bean>
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
|
||||
|
||||
<bean id="testChannel" class="org.springframework.integration.channel.QueueChannel"/>
|
||||
|
||||
<bean id="testBean" class="org.springframework.integration.aop.PublisherAnnotationTestBean"/>
|
||||
|
||||
<bean class="org.springframework.integration.config.annotation.PublisherAnnotationPostProcessor">
|
||||
<property name="channelRegistry" ref="messageBus"/>
|
||||
</bean>
|
||||
<bean class="org.springframework.integration.config.annotation.PublisherAnnotationPostProcessor"/>
|
||||
|
||||
</beans>
|
||||
|
||||
@@ -19,6 +19,7 @@ package org.springframework.integration.channel;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
@@ -26,13 +27,18 @@ import org.springframework.util.Assert;
|
||||
*/
|
||||
public class TestChannelResolver implements ChannelResolver {
|
||||
|
||||
private final Map<String, MessageChannel> channels = new ConcurrentHashMap<String, MessageChannel>();
|
||||
private volatile Map<String, MessageChannel> channels = new ConcurrentHashMap<String, MessageChannel>();
|
||||
|
||||
|
||||
public MessageChannel resolveChannelName(String channelName) {
|
||||
return this.channels.get(channelName);
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setChannels(Map<String, MessageChannel> channels) {
|
||||
this.channels = channels;
|
||||
}
|
||||
|
||||
public void addChannel(MessageChannel channel) {
|
||||
Assert.notNull(channel, "'channel' must not be null");
|
||||
Assert.notNull(channel.getName(), "channel name must not be null");
|
||||
|
||||
Reference in New Issue
Block a user