Polish revisted JMS support

- Add createConnectionFactory method on ActiveMQProperties
- Change getBrokerUrl to return the broker URL and add new deduce method
- Move static methods to end of class
- Apply source formatting
This commit is contained in:
Phillip Webb
2014-05-15 16:27:52 +01:00
parent 875e77d420
commit 0b4e2b3667
6 changed files with 97 additions and 84 deletions

View File

@@ -16,15 +16,15 @@
package org.springframework.boot.autoconfigure.jms;
import static org.junit.Assert.*;
import org.junit.Test;
import org.springframework.boot.test.EnvironmentTestUtils;
import org.springframework.core.env.StandardEnvironment;
import static org.junit.Assert.assertEquals;
/**
*
* Tests for {@link ActiveMQProperties}.
*
* @author Stephane Nicoll
*/
public class ActiveMQPropertiesTests {
@@ -34,7 +34,7 @@ public class ActiveMQPropertiesTests {
@Test
public void determineBrokerUrlDefault() {
assertEquals(ActiveMQProperties.DEFAULT_EMBEDDED_BROKER_URL,
assertEquals(ActiveMQProperties.DEFAULT_EMBEDDED_BROKER_URL,
ActiveMQProperties.determineBrokerUrl(this.environment));
}
@@ -56,25 +56,27 @@ public class ActiveMQPropertiesTests {
@Test
public void getBrokerUrlIsInMemoryByDefault() {
assertEquals(ActiveMQProperties.DEFAULT_EMBEDDED_BROKER_URL, this.properties.getBrokerUrl());
assertEquals(ActiveMQProperties.DEFAULT_EMBEDDED_BROKER_URL,
this.properties.determineBrokerUrl());
}
@Test
public void getBrokerUrlUseExplicitBrokerUrl() {
this.properties.setBrokerUrl("vm://foo-bar");
assertEquals("vm://foo-bar", this.properties.getBrokerUrl());
assertEquals("vm://foo-bar", this.properties.determineBrokerUrl());
}
@Test
public void getBrokerUrlWithInMemorySetToFalse() {
this.properties.setInMemory(false);
assertEquals(ActiveMQProperties.DEFAULT_NETWORK_BROKER_URL, this.properties.getBrokerUrl());
assertEquals(ActiveMQProperties.DEFAULT_NETWORK_BROKER_URL,
this.properties.determineBrokerUrl());
}
@Test
public void getExplicitBrokerUrlAlwaysWins() {
this.properties.setBrokerUrl("vm://foo-bar");
this.properties.setInMemory(false);
assertEquals("vm://foo-bar", this.properties.getBrokerUrl());
assertEquals("vm://foo-bar", this.properties.determineBrokerUrl());
}
}

View File

@@ -36,7 +36,7 @@ import static org.junit.Assert.assertTrue;
/**
* Tests for {@link JmsTemplateAutoConfiguration}.
*
*
* @author Greg Turnquist
*/
public class JmsTemplateAutoConfigurationTests {
@@ -54,7 +54,8 @@ public class JmsTemplateAutoConfigurationTests {
assertNotNull(connectionFactory);
assertEquals(jmsTemplate.getConnectionFactory(), connectionFactory);
assertEquals(ActiveMQProperties.DEFAULT_EMBEDDED_BROKER_URL,
((ActiveMQConnectionFactory) jmsTemplate.getConnectionFactory()).getBrokerURL());
((ActiveMQConnectionFactory) jmsTemplate.getConnectionFactory())
.getBrokerURL());
}
@Test
@@ -127,7 +128,8 @@ public class JmsTemplateAutoConfigurationTests {
assertNotNull(connectionFactory);
assertEquals(jmsTemplate.getConnectionFactory(), connectionFactory);
assertEquals(ActiveMQProperties.DEFAULT_NETWORK_BROKER_URL,
((ActiveMQConnectionFactory) jmsTemplate.getConnectionFactory()).getBrokerURL());
((ActiveMQConnectionFactory) jmsTemplate.getConnectionFactory())
.getBrokerURL());
}
@Test
@@ -143,7 +145,8 @@ public class JmsTemplateAutoConfigurationTests {
assertNotNull(connectionFactory);
assertEquals(jmsTemplate.getConnectionFactory(), connectionFactory);
assertEquals("tcp://remote-host:10000",
((ActiveMQConnectionFactory) jmsTemplate.getConnectionFactory()).getBrokerURL());
((ActiveMQConnectionFactory) jmsTemplate.getConnectionFactory())
.getBrokerURL());
}
@Test
@@ -159,7 +162,8 @@ public class JmsTemplateAutoConfigurationTests {
assertEquals(jmsTemplate.getConnectionFactory(), pool);
ActiveMQConnectionFactory factory = (ActiveMQConnectionFactory) pool
.getConnectionFactory();
assertEquals(ActiveMQProperties.DEFAULT_EMBEDDED_BROKER_URL, factory.getBrokerURL());
assertEquals(ActiveMQProperties.DEFAULT_EMBEDDED_BROKER_URL,
factory.getBrokerURL());
}
@Test
@@ -176,7 +180,8 @@ public class JmsTemplateAutoConfigurationTests {
assertEquals(jmsTemplate.getConnectionFactory(), pool);
ActiveMQConnectionFactory factory = (ActiveMQConnectionFactory) pool
.getConnectionFactory();
assertEquals(ActiveMQProperties.DEFAULT_NETWORK_BROKER_URL, factory.getBrokerURL());
assertEquals(ActiveMQProperties.DEFAULT_NETWORK_BROKER_URL,
factory.getBrokerURL());
}
@Test
@@ -196,10 +201,12 @@ public class JmsTemplateAutoConfigurationTests {
assertEquals("tcp://remote-host:10000", factory.getBrokerURL());
}
private AnnotationConfigApplicationContext createContext(Class<?>... additionalClasses) {
private AnnotationConfigApplicationContext createContext(
Class<?>... additionalClasses) {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
context.register(additionalClasses);
context.register(ActiveMQAutoConfiguration.class, JmsTemplateAutoConfiguration.class);
context.register(ActiveMQAutoConfiguration.class,
JmsTemplateAutoConfiguration.class);
return context;
}