INT-813 added tests for PollableJmsChannels

This commit is contained in:
Mark Fisher
2010-09-23 17:49:11 -04:00
parent 39e293d4ab
commit c05e5db50a
5 changed files with 47 additions and 9 deletions

View File

@@ -125,6 +125,10 @@ public class JmsChannelFactoryBean extends AbstractFactoryBean<AbstractJmsChanne
private volatile Integer transactionTimeout;
public JmsChannelFactoryBean() {
this(true);
}
public JmsChannelFactoryBean(boolean messageDriven) {
this.messageDriven = messageDriven;
}
@@ -309,6 +313,8 @@ public class JmsChannelFactoryBean extends AbstractFactoryBean<AbstractJmsChanne
this.channel = new SubscribableJmsChannel(this.container, this.jmsTemplate);
}
else {
Assert.isTrue(!Boolean.TRUE.equals(this.pubSubDomain),
"A JMS Topic-backed 'publish-subscribe-channel' must be message-driven.");
this.channel = new PollableJmsChannel(this.jmsTemplate);
}
if (!CollectionUtils.isEmpty(this.interceptors)) {

View File

@@ -47,7 +47,10 @@ public class JmsChannelParser extends AbstractChannelParser {
protected BeanDefinitionBuilder buildBeanDefinition(Element element, ParserContext parserContext) {
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(
"org.springframework.integration.jms.config.JmsChannelFactoryBean");
builder.addConstructorArgValue(element.getAttribute("message-driven"));
String messageDriven = element.getAttribute("message-driven");
if (StringUtils.hasText(messageDriven)) {
builder.addConstructorArgValue(messageDriven);
}
String connectionFactory = element.getAttribute("connection-factory");
if (!StringUtils.hasText(connectionFactory)) {
connectionFactory = "connectionFactory";

View File

@@ -36,6 +36,14 @@
</xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="message-driven" type="xsd:boolean" default="true">
<xsd:annotation>
<xsd:documentation>
Specifies whether this channel should be Message-Driven. The value is "true" by default.
Set to "false" if this channel should be pollable.
</xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="queue-name" type="xsd:string">
<xsd:annotation>
<xsd:documentation>
@@ -125,14 +133,6 @@
ID for this channel. Required.
</xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="message-driven" type="xsd:boolean" default="true">
<xsd:annotation>
<xsd:documentation>
Specifies whether this channel should be Message-Driven. The value is "true" by default.
Set to "false" if this channel should be pollable.
</xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="connection-factory" type="xsd:string">
<xsd:annotation>

View File

@@ -36,6 +36,10 @@
</jms:interceptors>
</jms:publish-subscribe-channel>
<jms:channel id="pollableQueueReferenceChannel" queue="testQueue" message-driven="false"/>
<jms:channel id="pollableQueueNameChannel" queue-name="foo" message-driven="false"/>
<bean id="testQueue" class="org.apache.activemq.command.ActiveMQQueue">
<property name="physicalName" value="test.queue"/>
</bean>

View File

@@ -36,6 +36,7 @@ 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.PollableJmsChannel;
import org.springframework.integration.jms.SubscribableJmsChannel;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.listener.AbstractMessageListenerContainer;
@@ -81,6 +82,12 @@ public class JmsChannelParserTests {
@Autowired
private MessageChannel topicChannelWithInterceptors;
@Autowired
private MessageChannel pollableQueueReferenceChannel;
@Autowired
private MessageChannel pollableQueueNameChannel;
@Autowired
private Topic topic;
@@ -194,6 +201,24 @@ public class JmsChannelParserTests {
assertEquals(TestInterceptor.class, interceptors.get(1).getClass());
}
@Test
public void queueReferencePollableChannel() {
assertEquals(PollableJmsChannel.class, pollableQueueReferenceChannel.getClass());
PollableJmsChannel channel = (PollableJmsChannel) pollableQueueReferenceChannel;
DirectFieldAccessor accessor = new DirectFieldAccessor(channel);
JmsTemplate jmsTemplate = (JmsTemplate) accessor.getPropertyValue("jmsTemplate");
assertEquals(queue, jmsTemplate.getDefaultDestination());
}
@Test
public void queueNamePollableChannel() {
assertEquals(PollableJmsChannel.class, pollableQueueNameChannel.getClass());
PollableJmsChannel channel = (PollableJmsChannel) pollableQueueNameChannel;
DirectFieldAccessor accessor = new DirectFieldAccessor(channel);
JmsTemplate jmsTemplate = (JmsTemplate) accessor.getPropertyValue("jmsTemplate");
assertEquals("foo", jmsTemplate.getDefaultDestinationName());
}
static class TestDestinationResolver implements DestinationResolver {