polishing

pull/1361/head
Stephane Nicoll 10 years ago
parent 063f67da5f
commit 6217c1b095

@ -47,8 +47,7 @@ public class JmsAutoConfigurationTests {
@Test @Test
public void testDefaultJmsTemplate() { public void testDefaultJmsTemplate() {
this.context = createContext(TestConfiguration.class); load(TestConfiguration.class);
this.context.refresh();
JmsTemplate jmsTemplate = this.context.getBean(JmsTemplate.class); JmsTemplate jmsTemplate = this.context.getBean(JmsTemplate.class);
ActiveMQConnectionFactory connectionFactory = this.context ActiveMQConnectionFactory connectionFactory = this.context
.getBean(ActiveMQConnectionFactory.class); .getBean(ActiveMQConnectionFactory.class);
@ -62,16 +61,14 @@ public class JmsAutoConfigurationTests {
@Test @Test
public void testConnectionFactoryBackoff() { public void testConnectionFactoryBackoff() {
this.context = createContext(TestConfiguration2.class); load(TestConfiguration2.class);
this.context.refresh();
assertEquals("foobar", this.context.getBean(ActiveMQConnectionFactory.class) assertEquals("foobar", this.context.getBean(ActiveMQConnectionFactory.class)
.getBrokerURL()); .getBrokerURL());
} }
@Test @Test
public void testJmsTemplateBackoff() { public void testJmsTemplateBackoff() {
this.context = createContext(TestConfiguration3.class); load(TestConfiguration3.class);
this.context.refresh();
JmsTemplate jmsTemplate = this.context.getBean(JmsTemplate.class); JmsTemplate jmsTemplate = this.context.getBean(JmsTemplate.class);
assertEquals(999, jmsTemplate.getPriority()); assertEquals(999, jmsTemplate.getPriority());
} }
@ -79,7 +76,6 @@ public class JmsAutoConfigurationTests {
@Test @Test
public void testJmsTemplateBackoffEverything() { public void testJmsTemplateBackoffEverything() {
this.context = createContext(TestConfiguration2.class, TestConfiguration3.class); this.context = createContext(TestConfiguration2.class, TestConfiguration3.class);
this.context.refresh();
JmsTemplate jmsTemplate = this.context.getBean(JmsTemplate.class); JmsTemplate jmsTemplate = this.context.getBean(JmsTemplate.class);
assertEquals(999, jmsTemplate.getPriority()); assertEquals(999, jmsTemplate.getPriority());
assertEquals("foobar", this.context.getBean(ActiveMQConnectionFactory.class) assertEquals("foobar", this.context.getBean(ActiveMQConnectionFactory.class)
@ -88,26 +84,21 @@ public class JmsAutoConfigurationTests {
@Test @Test
public void testPubSubDisabledByDefault() { public void testPubSubDisabledByDefault() {
this.context = createContext(TestConfiguration.class); load(TestConfiguration.class);
this.context.refresh();
JmsTemplate jmsTemplate = this.context.getBean(JmsTemplate.class); JmsTemplate jmsTemplate = this.context.getBean(JmsTemplate.class);
assertFalse(jmsTemplate.isPubSubDomain()); assertFalse(jmsTemplate.isPubSubDomain());
} }
@Test @Test
public void testJmsTemplatePostProcessedSoThatPubSubIsTrue() { public void testJmsTemplatePostProcessedSoThatPubSubIsTrue() {
this.context = createContext(TestConfiguration4.class); load(TestConfiguration4.class);
this.context.refresh();
JmsTemplate jmsTemplate = this.context.getBean(JmsTemplate.class); JmsTemplate jmsTemplate = this.context.getBean(JmsTemplate.class);
assertTrue(jmsTemplate.isPubSubDomain()); assertTrue(jmsTemplate.isPubSubDomain());
} }
@Test @Test
public void testJmsTemplateOverridden() { public void testJmsTemplateOverridden() {
this.context = createContext(TestConfiguration.class); load(TestConfiguration.class, "spring.jms.pubSubDomain:false");
EnvironmentTestUtils
.addEnvironment(this.context, "spring.jms.pubSubDomain:false");
this.context.refresh();
JmsTemplate jmsTemplate = this.context.getBean(JmsTemplate.class); JmsTemplate jmsTemplate = this.context.getBean(JmsTemplate.class);
ActiveMQConnectionFactory connectionFactory = this.context ActiveMQConnectionFactory connectionFactory = this.context
.getBean(ActiveMQConnectionFactory.class); .getBean(ActiveMQConnectionFactory.class);
@ -119,10 +110,7 @@ public class JmsAutoConfigurationTests {
@Test @Test
public void testActiveMQOverriddenStandalone() { public void testActiveMQOverriddenStandalone() {
this.context = createContext(TestConfiguration.class); load(TestConfiguration.class, "spring.activemq.inMemory:false");
EnvironmentTestUtils.addEnvironment(this.context,
"spring.activemq.inMemory:false");
this.context.refresh();
JmsTemplate jmsTemplate = this.context.getBean(JmsTemplate.class); JmsTemplate jmsTemplate = this.context.getBean(JmsTemplate.class);
ActiveMQConnectionFactory connectionFactory = this.context ActiveMQConnectionFactory connectionFactory = this.context
.getBean(ActiveMQConnectionFactory.class); .getBean(ActiveMQConnectionFactory.class);
@ -136,10 +124,7 @@ public class JmsAutoConfigurationTests {
@Test @Test
public void testActiveMQOverriddenRemoteHost() { public void testActiveMQOverriddenRemoteHost() {
this.context = createContext(TestConfiguration.class); load(TestConfiguration.class, "spring.activemq.brokerUrl:tcp://remote-host:10000");
EnvironmentTestUtils.addEnvironment(this.context,
"spring.activemq.brokerUrl:tcp://remote-host:10000");
this.context.refresh();
JmsTemplate jmsTemplate = this.context.getBean(JmsTemplate.class); JmsTemplate jmsTemplate = this.context.getBean(JmsTemplate.class);
ActiveMQConnectionFactory connectionFactory = this.context ActiveMQConnectionFactory connectionFactory = this.context
.getBean(ActiveMQConnectionFactory.class); .getBean(ActiveMQConnectionFactory.class);
@ -153,9 +138,7 @@ public class JmsAutoConfigurationTests {
@Test @Test
public void testActiveMQOverriddenPool() { public void testActiveMQOverriddenPool() {
this.context = createContext(TestConfiguration.class); load(TestConfiguration.class, "spring.activemq.pooled:true");
EnvironmentTestUtils.addEnvironment(this.context, "spring.activemq.pooled:true");
this.context.refresh();
JmsTemplate jmsTemplate = this.context.getBean(JmsTemplate.class); JmsTemplate jmsTemplate = this.context.getBean(JmsTemplate.class);
PooledConnectionFactory pool = this.context PooledConnectionFactory pool = this.context
.getBean(PooledConnectionFactory.class); .getBean(PooledConnectionFactory.class);
@ -170,10 +153,8 @@ public class JmsAutoConfigurationTests {
@Test @Test
public void testActiveMQOverriddenPoolAndStandalone() { public void testActiveMQOverriddenPoolAndStandalone() {
this.context = createContext(TestConfiguration.class); load(TestConfiguration.class, "spring.activemq.pooled:true",
EnvironmentTestUtils.addEnvironment(this.context, "spring.activemq.pooled:true",
"spring.activemq.inMemory:false"); "spring.activemq.inMemory:false");
this.context.refresh();
JmsTemplate jmsTemplate = this.context.getBean(JmsTemplate.class); JmsTemplate jmsTemplate = this.context.getBean(JmsTemplate.class);
PooledConnectionFactory pool = this.context PooledConnectionFactory pool = this.context
.getBean(PooledConnectionFactory.class); .getBean(PooledConnectionFactory.class);
@ -188,10 +169,8 @@ public class JmsAutoConfigurationTests {
@Test @Test
public void testActiveMQOverriddenPoolAndRemoteServer() { public void testActiveMQOverriddenPoolAndRemoteServer() {
this.context = createContext(TestConfiguration.class); load(TestConfiguration.class, "spring.activemq.pooled:true",
EnvironmentTestUtils.addEnvironment(this.context, "spring.activemq.pooled:true",
"spring.activemq.brokerUrl:tcp://remote-host:10000"); "spring.activemq.brokerUrl:tcp://remote-host:10000");
this.context.refresh();
JmsTemplate jmsTemplate = this.context.getBean(JmsTemplate.class); JmsTemplate jmsTemplate = this.context.getBean(JmsTemplate.class);
PooledConnectionFactory pool = this.context PooledConnectionFactory pool = this.context
.getBean(PooledConnectionFactory.class); .getBean(PooledConnectionFactory.class);
@ -205,10 +184,20 @@ public class JmsAutoConfigurationTests {
private AnnotationConfigApplicationContext createContext( private AnnotationConfigApplicationContext createContext(
Class<?>... additionalClasses) { Class<?>... additionalClasses) {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); return doLoad(additionalClasses);
context.register(additionalClasses); }
context.register(ActiveMQAutoConfiguration.class, JmsAutoConfiguration.class);
return context; private void load(Class<?> config, String... environment) {
this.context = doLoad(new Class<?>[] {config}, environment);
}
private AnnotationConfigApplicationContext doLoad(Class<?>[] configs, String... environment) {
AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();
applicationContext.register(configs);
applicationContext.register(ActiveMQAutoConfiguration.class, JmsAutoConfiguration.class);
EnvironmentTestUtils.addEnvironment(applicationContext, environment);
applicationContext.refresh();
return applicationContext;
} }
@Configuration @Configuration

Loading…
Cancel
Save