Add tests for default listener container configuration
This commit is contained in:
@@ -36,6 +36,7 @@ import org.springframework.beans.DirectFieldAccessor;
|
||||
import org.springframework.beans.factory.xml.XmlBeanFactory;
|
||||
import org.springframework.context.expression.StandardBeanExpressionResolver;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
@@ -73,12 +74,17 @@ public final class ListenerContainerParserTests {
|
||||
@Test
|
||||
public void testParseWithAdviceChain() throws Exception {
|
||||
SimpleMessageListenerContainer container = beanFactory.getBean("container3", SimpleMessageListenerContainer.class);
|
||||
DirectFieldAccessor accessor = new DirectFieldAccessor(container);
|
||||
Object adviceChain = accessor.getPropertyValue("adviceChain");
|
||||
Object adviceChain = ReflectionTestUtils.getField(container, "adviceChain");
|
||||
assertNotNull(adviceChain);
|
||||
assertEquals(3, ((Advice[]) adviceChain).length);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseWithDefaults() throws Exception {
|
||||
SimpleMessageListenerContainer container = beanFactory.getBean("container4", SimpleMessageListenerContainer.class);
|
||||
assertEquals(1, ReflectionTestUtils.getField(container, "concurrentConsumers"));
|
||||
}
|
||||
|
||||
static class TestBean {
|
||||
public void handle(String s) {
|
||||
}
|
||||
|
||||
@@ -12,12 +12,15 @@
|
||||
*/
|
||||
package org.springframework.amqp.rabbit.listener;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.springframework.amqp.core.AcknowledgeMode;
|
||||
import org.springframework.amqp.rabbit.connection.SingleConnectionFactory;
|
||||
import org.springframework.amqp.rabbit.listener.adapter.MessageListenerAdapter;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
import org.springframework.transaction.TransactionDefinition;
|
||||
import org.springframework.transaction.TransactionException;
|
||||
import org.springframework.transaction.support.AbstractPlatformTransactionManager;
|
||||
@@ -55,6 +58,16 @@ public class SimpleMessageListenerContainerTests {
|
||||
container.afterPropertiesSet();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaConsumerCount() throws Exception {
|
||||
SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(new SingleConnectionFactory());
|
||||
container.setMessageListener(new MessageListenerAdapter(this));
|
||||
container.setQueueNames("foo");
|
||||
container.setAutoStartup(false);
|
||||
container.afterPropertiesSet();
|
||||
assertEquals(1, ReflectionTestUtils.getField(container, "concurrentConsumers"));
|
||||
}
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
private class TestTransactionManager extends AbstractPlatformTransactionManager {
|
||||
|
||||
|
||||
@@ -24,6 +24,10 @@
|
||||
<rabbit:listener id="testListener" queues="foo" ref="testBean" method="handle"/>
|
||||
</rabbit:listener-container>
|
||||
|
||||
<rabbit:listener-container id="container4" connection-factory="connectionFactory">
|
||||
<rabbit:listener id="testListener" queues="foo" ref="testBean" method="handle"/>
|
||||
</rabbit:listener-container>
|
||||
|
||||
<util:list id="adviceChain">
|
||||
<bean class="org.springframework.amqp.rabbit.config.ListenerContainerParserTests$TestAdvice"/>
|
||||
<bean class="org.springframework.amqp.rabbit.config.ListenerContainerParserTests$TestAdvice"/>
|
||||
|
||||
Reference in New Issue
Block a user