diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/hornetq/HornetQAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/hornetq/HornetQAutoConfiguration.java index d56ac558cbe..b6ff2e14f84 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/hornetq/HornetQAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/hornetq/HornetQAutoConfiguration.java @@ -105,7 +105,8 @@ public class HornetQAutoConfiguration { private ConnectionFactory createEmbeddedConnectionFactory() { try { TransportConfiguration transportConfiguration = new TransportConfiguration( - InVMConnectorFactory.class.getName(), properties.getEmbedded().generateTransportParameters()); + InVMConnectorFactory.class.getName(), this.properties.getEmbedded() + .generateTransportParameters()); ServerLocator serviceLocator = HornetQClient .createServerLocatorWithoutHA(transportConfiguration); return new HornetQConnectionFactory(serviceLocator); diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/hornetq/HornetQEmbeddedConfigurationFactory.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/hornetq/HornetQEmbeddedConfigurationFactory.java index a92b0b0ea82..5c147f7ceb9 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/hornetq/HornetQEmbeddedConfigurationFactory.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/hornetq/HornetQEmbeddedConfigurationFactory.java @@ -62,7 +62,8 @@ class HornetQEmbeddedConfigurationFactory { } TransportConfiguration transportConfiguration = new TransportConfiguration( - InVMAcceptorFactory.class.getName(), properties.generateTransportParameters()); + InVMAcceptorFactory.class.getName(), + this.properties.generateTransportParameters()); configuration.getAcceptorConfigurations().add(transportConfiguration); // HORNETQ-1143 diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/hornetq/HornetQProperties.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/hornetq/HornetQProperties.java index 35927b70f60..f2c3d594dee 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/hornetq/HornetQProperties.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/hornetq/HornetQProperties.java @@ -22,7 +22,6 @@ import java.util.UUID; import java.util.concurrent.atomic.AtomicInteger; import org.hornetq.core.remoting.impl.invm.TransportConstants; - import org.springframework.boot.context.properties.ConfigurationProperties; /** @@ -94,7 +93,7 @@ public class HornetQProperties { private boolean defaultClusterPassword = true; public int getServerId() { - return serverId; + return this.serverId; } public void setServerId(int serverId) { @@ -155,12 +154,11 @@ public class HornetQProperties { } /** - * Creates the minimal transport parameters for an embedded transport configuration. - *

Specifies the identifier of the server. - * + * Creates the minimal transport parameters for an embedded transport + * configuration. * @see TransportConstants#SERVER_ID_PROP_NAME */ - public Map generateTransportParameters() { + public Map generateTransportParameters() { Map parameters = new HashMap(); parameters.put(TransportConstants.SERVER_ID_PROP_NAME, getServerId()); return parameters; diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jms/hornetq/HornetQAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jms/hornetq/HornetQAutoConfigurationTests.java index dbdf6a51af7..c24a16ae7e6 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jms/hornetq/HornetQAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jms/hornetq/HornetQAutoConfigurationTests.java @@ -16,8 +16,6 @@ package org.springframework.boot.autoconfigure.jms.hornetq; -import static org.junit.Assert.*; - import java.io.File; import java.io.IOException; import java.util.UUID; @@ -56,6 +54,11 @@ import org.springframework.jms.core.SessionCallback; import org.springframework.jms.support.destination.DestinationResolver; import org.springframework.jms.support.destination.DynamicDestinationResolver; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + /** * Tests for {@link HornetQAutoConfiguration}. * @@ -88,8 +91,7 @@ public class HornetQAutoConfigurationTests { @Test public void nativeConnectionFactoryCustomHost() { load(EmptyConfiguration.class, "spring.hornetq.mode:native", - "spring.hornetq.host:192.168.1.144", - "spring.hornetq.port:9876"); + "spring.hornetq.host:192.168.1.144", "spring.hornetq.port:9876"); HornetQConnectionFactory connectionFactory = this.context .getBean(HornetQConnectionFactory.class); assertNettyConnectionFactory(connectionFactory, "192.168.1.144", 9876); @@ -146,8 +148,7 @@ public class HornetQAutoConfigurationTests { @Test public void embeddedConnectionFactorEvenIfEmbeddedServiceDisabled() { // No mode is specified - load(EmptyConfiguration.class, - "spring.hornetq.mode:embedded", + load(EmptyConfiguration.class, "spring.hornetq.mode:embedded", "spring.hornetq.embedded.enabled:false"); assertEquals(0, this.context.getBeansOfType(EmbeddedJMS.class).size()); @@ -157,11 +158,9 @@ public class HornetQAutoConfigurationTests { assertInVmConnectionFactory(connectionFactory); } - @Test public void embeddedServerWithDestinations() { - load(EmptyConfiguration.class, - "spring.hornetq.embedded.queues=Queue1,Queue2", + load(EmptyConfiguration.class, "spring.hornetq.embedded.queues=Queue1,Queue2", "spring.hornetq.embedded.topics=Topic1"); DestinationChecker checker = new DestinationChecker(this.context); @@ -184,9 +183,10 @@ public class HornetQAutoConfigurationTests { @Test public void embeddedServiceWithCustomJmsConfiguration() { - load(CustomJmsConfiguration.class, - "spring.hornetq.embedded.queues=Queue1,Queue2"); // Ignored with custom - // config + load(CustomJmsConfiguration.class, "spring.hornetq.embedded.queues=Queue1,Queue2"); // Ignored + // with + // custom + // config DestinationChecker checker = new DestinationChecker(this.context); checker.checkQueue("custom", true); // See CustomJmsConfiguration @@ -207,8 +207,7 @@ public class HornetQAutoConfigurationTests { File dataFolder = this.folder.newFolder(); // Start the server and post a message to some queue - load(EmptyConfiguration.class, - "spring.hornetq.embedded.queues=TestQueue", + load(EmptyConfiguration.class, "spring.hornetq.embedded.queues=TestQueue", "spring.hornetq.embedded.persistent:true", "spring.hornetq.embedded.dataDirectory:" + dataFolder.getAbsolutePath()); @@ -223,8 +222,7 @@ public class HornetQAutoConfigurationTests { this.context.close(); // Shutdown the broker // Start the server again and check if our message is still here - load(EmptyConfiguration.class, - "spring.hornetq.embedded.queues=TestQueue", + load(EmptyConfiguration.class, "spring.hornetq.embedded.queues=TestQueue", "spring.hornetq.embedded.persistent:true", "spring.hornetq.embedded.dataDirectory:" + dataFolder.getAbsolutePath()); @@ -238,17 +236,17 @@ public class HornetQAutoConfigurationTests { @Test public void severalEmbeddedBrokers() { - load(EmptyConfiguration.class, - "spring.hornetq.embedded.queues=Queue1"); + load(EmptyConfiguration.class, "spring.hornetq.embedded.queues=Queue1"); - AnnotationConfigApplicationContext anotherContext = doLoad(EmptyConfiguration.class, - "spring.hornetq.embedded.queues=Queue2"); + AnnotationConfigApplicationContext anotherContext = doLoad( + EmptyConfiguration.class, "spring.hornetq.embedded.queues=Queue2"); try { HornetQProperties properties = this.context.getBean(HornetQProperties.class); - HornetQProperties anotherProperties = anotherContext.getBean(HornetQProperties.class); - assertTrue("ServerId should not match", - properties.getEmbedded().getServerId() < anotherProperties.getEmbedded().getServerId()); + HornetQProperties anotherProperties = anotherContext + .getBean(HornetQProperties.class); + assertTrue("ServerId should not match", properties.getEmbedded() + .getServerId() < anotherProperties.getEmbedded().getServerId()); DestinationChecker checker = new DestinationChecker(this.context); checker.checkQueue("Queue1", true); @@ -259,19 +257,18 @@ public class HornetQAutoConfigurationTests { anotherChecker.checkQueue("Queue1", false); } finally { - anotherContext.close(); + anotherContext.close(); } } @Test public void connectToASpecificEmbeddedBroker() { - load(EmptyConfiguration.class, - "spring.hornetq.embedded.serverId=93", + load(EmptyConfiguration.class, "spring.hornetq.embedded.serverId=93", "spring.hornetq.embedded.queues=Queue1"); - AnnotationConfigApplicationContext anotherContext = doLoad(EmptyConfiguration.class, - "spring.hornetq.mode=embedded", - "spring.hornetq.embedded.serverId=93", // Connect to the "main" broker + AnnotationConfigApplicationContext anotherContext = doLoad( + EmptyConfiguration.class, "spring.hornetq.mode=embedded", + "spring.hornetq.embedded.serverId=93", // Connect to the "main" broker "spring.hornetq.embedded.enabled=false"); // do not start a specific one try { @@ -316,10 +313,12 @@ public class HornetQAutoConfigurationTests { this.context = doLoad(config, environment); } - private AnnotationConfigApplicationContext doLoad(Class config, String... environment) { + private AnnotationConfigApplicationContext doLoad(Class config, + String... environment) { AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(); applicationContext.register(config); - applicationContext.register(HornetQAutoConfiguration.class, JmsAutoConfiguration.class); + applicationContext.register(HornetQAutoConfiguration.class, + JmsAutoConfiguration.class); EnvironmentTestUtils.addEnvironment(applicationContext, environment); applicationContext.refresh(); return applicationContext; diff --git a/spring-boot/src/main/java/org/springframework/boot/test/SpringApplicationContextLoader.java b/spring-boot/src/main/java/org/springframework/boot/test/SpringApplicationContextLoader.java index d671fc90e9f..c91d3ec03eb 100644 --- a/spring-boot/src/main/java/org/springframework/boot/test/SpringApplicationContextLoader.java +++ b/spring-boot/src/main/java/org/springframework/boot/test/SpringApplicationContextLoader.java @@ -153,7 +153,8 @@ public class SpringApplicationContextLoader extends AbstractContextLoader { .detectDefaultConfigurationClasses(declaringClass); } - protected Map getEnvironmentProperties(MergedContextConfiguration config) { + protected Map getEnvironmentProperties( + MergedContextConfiguration config) { Map properties = new LinkedHashMap(); // JMX bean names will clash if the same bean is used in multiple contexts disableJmx(properties); @@ -180,7 +181,7 @@ public class SpringApplicationContextLoader extends AbstractContextLoader { // Instead of parsing the keys ourselves, we rely on standard handling private Map extractEnvironmentProperties(String[] values) { - StringBuilder sb = new StringBuilder(); + StringBuilder sb = new StringBuilder(); for (String value : values) { sb.append(value).append(LINE_SEPARATOR); } @@ -190,11 +191,12 @@ public class SpringApplicationContextLoader extends AbstractContextLoader { props.load(new StringReader(content)); } catch (IOException e) { - throw new IllegalStateException("Unexpected could not load properties from '"+content+"'", e); + throw new IllegalStateException("Unexpected could not load properties from '" + + content + "'", e); } Map properties = new HashMap(); - for (String name: props.stringPropertyNames()) { + for (String name : props.stringPropertyNames()) { properties.put(name, props.getProperty(name)); } return properties; diff --git a/spring-boot/src/test/java/org/springframework/boot/test/SpringApplicationContextLoaderTests.java b/spring-boot/src/test/java/org/springframework/boot/test/SpringApplicationContextLoaderTests.java index c739af82509..57b0e9beb5b 100644 --- a/spring-boot/src/test/java/org/springframework/boot/test/SpringApplicationContextLoaderTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/test/SpringApplicationContextLoaderTests.java @@ -16,18 +16,19 @@ package org.springframework.boot.test; -import static org.junit.Assert.*; -import static org.mockito.Mockito.*; - import java.util.Map; import org.junit.Test; - import org.springframework.test.context.MergedContextConfiguration; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.mock; + /** * Tests for {@link SpringApplicationContextLoader} - * + * * @author Stephane Nicoll */ public class SpringApplicationContextLoaderTests { @@ -55,12 +56,10 @@ public class SpringApplicationContextLoaderTests { assertKey(config, "anotherKey", "another=Value"); } - private Map getEnvironmentProperties(Class testClass) { MergedContextConfiguration configuration = mock(MergedContextConfiguration.class); doReturn(testClass).when(configuration).getTestClass(); - - return loader.getEnvironmentProperties(configuration); + return this.loader.getEnvironmentProperties(configuration); } private void assertKey(Map actual, String key, Object value) { @@ -68,16 +67,15 @@ public class SpringApplicationContextLoaderTests { assertEquals(value, actual.get(key)); } - - @IntegrationTest({"key=myValue", "anotherKey:anotherValue"}) + @IntegrationTest({ "key=myValue", "anotherKey:anotherValue" }) static class SimpleConfig { } - @IntegrationTest({"key=my=Value", "anotherKey:another:Value"}) + @IntegrationTest({ "key=my=Value", "anotherKey:another:Value" }) static class SameSeparatorInValue { } - @IntegrationTest({"key=my:Value", "anotherKey:another=Value"}) + @IntegrationTest({ "key=my:Value", "anotherKey:another=Value" }) static class AnotherSeparatorInValue { }