INT-965 added support for 'interceptors' as a sub-element of JMS channel and publish-subcribe-channel elements

This commit is contained in:
Mark Fisher
2010-09-23 17:05:15 -04:00
parent 6cde5c6d83
commit 39e293d4ab
3 changed files with 72 additions and 1 deletions

View File

@@ -106,10 +106,19 @@
]]></xsd:documentation>
<xsd:appinfo>
<tool:annotation>
<tool:exports type="org.springframework.integration.jms.JmsDestinationBackedMessageChannel"/>
<tool:exports type="org.springframework.integration.jms.AbstractJmsChannel"/>
</tool:annotation>
</xsd:appinfo>
</xsd:annotation>
<xsd:sequence>
<xsd:element name="interceptors" type="integration:channelInterceptorsType" minOccurs="0" maxOccurs="1">
<xsd:annotation>
<xsd:documentation><![CDATA[
A list of ChannelInterceptor instances to be applied to this channel.
]]></xsd:documentation>
</xsd:annotation>
</xsd:element>
</xsd:sequence>
<xsd:attribute name="id" type="xsd:ID" use="required">
<xsd:annotation>
<xsd:documentation>

View File

@@ -23,6 +23,19 @@
<jms:channel id="channelWithConcurrencySettings" queue-name="foo" concurrency="11-55"/>
<jms:channel id="queueChannelWithInterceptors" queue-name="foo">
<jms:interceptors>
<bean class="org.springframework.integration.jms.config.JmsChannelParserTests$TestInterceptor"/>
</jms:interceptors>
</jms:channel>
<jms:publish-subscribe-channel id="topicChannelWithInterceptors" topic-name="test.topic">
<jms:interceptors>
<bean class="org.springframework.integration.jms.config.JmsChannelParserTests$TestInterceptor"/>
<bean class="org.springframework.integration.jms.config.JmsChannelParserTests$TestInterceptor"/>
</jms:interceptors>
</jms:publish-subscribe-channel>
<bean id="testQueue" class="org.apache.activemq.command.ActiveMQQueue">
<property name="physicalName" value="test.queue"/>
</bean>

View File

@@ -18,18 +18,24 @@ package org.springframework.integration.jms.config;
import static org.junit.Assert.assertEquals;
import java.util.List;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.Queue;
import javax.jms.Session;
import javax.jms.Topic;
import org.junit.After;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.DirectFieldAccessor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.integration.MessageChannel;
import org.springframework.integration.channel.ChannelInterceptor;
import org.springframework.integration.channel.interceptor.ChannelInterceptorAdapter;
import org.springframework.integration.jms.SubscribableJmsChannel;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.listener.AbstractMessageListenerContainer;
@@ -69,9 +75,23 @@ public class JmsChannelParserTests {
@Autowired
private MessageChannel channelWithConcurrencySettings;
@Autowired
private MessageChannel queueChannelWithInterceptors;
@Autowired
private MessageChannel topicChannelWithInterceptors;
@Autowired
private Topic topic;
@Autowired
private AbstractApplicationContext context;
@After
public void closeContext() {
this.context.close();
}
@Test
public void queueReferenceChannel() {
@@ -149,6 +169,31 @@ public class JmsChannelParserTests {
assertEquals(55, container.getMaxConcurrentConsumers());
}
@Test
@SuppressWarnings("unchecked")
public void queueChannelWithInterceptors() {
assertEquals(SubscribableJmsChannel.class, queueChannelWithInterceptors.getClass());
SubscribableJmsChannel channel = (SubscribableJmsChannel) queueChannelWithInterceptors;
DirectFieldAccessor accessor = new DirectFieldAccessor(channel);
List<ChannelInterceptor> interceptors = (List<ChannelInterceptor>) new DirectFieldAccessor(
accessor.getPropertyValue("interceptors")).getPropertyValue("interceptors");
assertEquals(1, interceptors.size());
assertEquals(TestInterceptor.class, interceptors.get(0).getClass());
}
@Test
@SuppressWarnings("unchecked")
public void topicChannelWithInterceptors() {
assertEquals(SubscribableJmsChannel.class, topicChannelWithInterceptors.getClass());
SubscribableJmsChannel channel = (SubscribableJmsChannel) topicChannelWithInterceptors;
DirectFieldAccessor accessor = new DirectFieldAccessor(channel);
List<ChannelInterceptor> interceptors = (List<ChannelInterceptor>) new DirectFieldAccessor(
accessor.getPropertyValue("interceptors")).getPropertyValue("interceptors");
assertEquals(2, interceptors.size());
assertEquals(TestInterceptor.class, interceptors.get(0).getClass());
assertEquals(TestInterceptor.class, interceptors.get(1).getClass());
}
static class TestDestinationResolver implements DestinationResolver {
@@ -167,4 +212,8 @@ public class JmsChannelParserTests {
}
}
static class TestInterceptor extends ChannelInterceptorAdapter {
}
}