From 478e6557588c75842b541bab2d5cd05c23006a99 Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Wed, 8 Jan 2014 18:03:37 +0000 Subject: [PATCH] Change algorithm for determining active profile from external config Instead of adding active prpfiles for every one we encounter, we need to build up a complete "default" Environment and then ask it what the active profiles are. Implemented in ConfigFileApplicationListener. Fixes gh-198 --- .../EndpointAutoConfigurationTests.java | 4 +- .../EndpointWebMvcAutoConfigurationTests.java | 4 +- .../JolokiaAutoConfigurationTests.java | 2 +- ...agementSecurityAutoConfigurationTests.java | 6 +-- .../endpoint/AbstractEndpointTests.java | 2 +- .../mvc/EnvironmentMvcEndpointTests.java | 2 +- .../endpoint/mvc/JolokiaEndpointTests.java | 2 +- ...ertyPlaceholderAutoConfigurationTests.java | 4 +- .../amqp/RabbitAutoconfigurationTests.java | 10 ++--- .../aop/AopAutoConfigurationTests.java | 6 +-- .../batch/BatchAutoConfigurationTests.java | 4 +- .../DataSourceAutoConfigurationTests.java | 4 +- .../TomcatDataSourceConfigurationTests.java | 2 +- .../JmsTemplateAutoConfigurationTests.java | 12 +++--- .../AbstractJpaAutoConfigurationTests.java | 4 +- .../HibernateJpaAutoConfigurationTests.java | 2 +- .../redis/RedisAutoConfigurationTests.java | 2 +- .../SecurityAutoConfigurationTests.java | 6 +-- ...erverPropertiesAutoConfigurationTests.java | 4 +- .../ConfigFileApplicationListener.java | 40 +++++++++++-------- ...tIdApplicationContextInitializerTests.java | 8 ++-- ...ateApplicationContextInitializerTests.java | 10 ++--- .../ConfigFileApplicationListenerTests.java | 15 ++++++- ...nmentDelegateApplicationListenerTests.java | 4 +- .../LoggingApplicationListenerTests.java | 14 +++---- .../VcapApplicationListenerTests.java | 8 ++-- .../EnableConfigurationPropertiesTests.java | 36 ++++++++--------- .../boot/test/SpringBootTestUtils.java | 2 +- 28 files changed, 119 insertions(+), 100 deletions(-) diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/EndpointAutoConfigurationTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/EndpointAutoConfigurationTests.java index 507082dcbc..85c9088ac4 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/EndpointAutoConfigurationTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/EndpointAutoConfigurationTests.java @@ -104,7 +104,7 @@ public class EndpointAutoConfigurationTests { @Test public void testInfoEndpointConfiguration() throws Exception { this.context = new AnnotationConfigApplicationContext(); - SpringBootTestUtils.addEnviroment(this.context, "info.foo:bar"); + SpringBootTestUtils.addEnvironment(this.context, "info.foo:bar"); this.context.register(EndpointAutoConfiguration.class); this.context.refresh(); InfoEndpoint endpoint = this.context.getBean(InfoEndpoint.class); @@ -116,7 +116,7 @@ public class EndpointAutoConfigurationTests { @Test public void testNoGitProperties() throws Exception { this.context = new AnnotationConfigApplicationContext(); - SpringBootTestUtils.addEnviroment(this.context, + SpringBootTestUtils.addEnvironment(this.context, "spring.git.properties:classpath:nonexistent"); this.context.register(EndpointAutoConfiguration.class); this.context.refresh(); diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/EndpointWebMvcAutoConfigurationTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/EndpointWebMvcAutoConfigurationTests.java index 53e8427c4a..fc43fb893a 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/EndpointWebMvcAutoConfigurationTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/EndpointWebMvcAutoConfigurationTests.java @@ -121,7 +121,7 @@ public class EndpointWebMvcAutoConfigurationTests { @Test public void specificPortsViaProperties() throws Exception { - SpringBootTestUtils.addEnviroment(this.applicationContext, "server.port:7070", + SpringBootTestUtils.addEnvironment(this.applicationContext, "server.port:7070", "management.port:7071"); this.applicationContext.register(RootConfig.class, PropertyPlaceholderAutoConfiguration.class, @@ -142,7 +142,7 @@ public class EndpointWebMvcAutoConfigurationTests { @Test public void contextPath() throws Exception { - SpringBootTestUtils.addEnviroment(this.applicationContext, "management.contextPath:/test"); + SpringBootTestUtils.addEnvironment(this.applicationContext, "management.contextPath:/test"); this.applicationContext.register(RootConfig.class, PropertyPlaceholderAutoConfiguration.class, ManagementServerPropertiesAutoConfiguration.class, diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/JolokiaAutoConfigurationTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/JolokiaAutoConfigurationTests.java index adaeef25aa..83dc6fed77 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/JolokiaAutoConfigurationTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/JolokiaAutoConfigurationTests.java @@ -65,7 +65,7 @@ public class JolokiaAutoConfigurationTests { @Test public void agentDisabled() throws Exception { this.context = new AnnotationConfigEmbeddedWebApplicationContext(); - SpringBootTestUtils.addEnviroment(this.context, "endpoints.jolokia.enabled:false"); + SpringBootTestUtils.addEnvironment(this.context, "endpoints.jolokia.enabled:false"); this.context.register(Config.class, WebMvcAutoConfiguration.class, ManagementServerPropertiesAutoConfiguration.class, HttpMessageConvertersAutoConfiguration.class, diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/ManagementSecurityAutoConfigurationTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/ManagementSecurityAutoConfigurationTests.java index 6e72929478..48c22f035e 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/ManagementSecurityAutoConfigurationTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/ManagementSecurityAutoConfigurationTests.java @@ -117,7 +117,7 @@ public class ManagementSecurityAutoConfigurationTests { EndpointAutoConfiguration.class, ManagementServerPropertiesAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class); - SpringBootTestUtils.addEnviroment(this.context, "security.ignored:none"); + SpringBootTestUtils.addEnvironment(this.context, "security.ignored:none"); this.context.refresh(); // Just the application and management endpoints now assertEquals(2, this.context.getBean(FilterChainProxy.class).getFilterChains() @@ -134,7 +134,7 @@ public class ManagementSecurityAutoConfigurationTests { EndpointAutoConfiguration.class, EndpointWebMvcAutoConfiguration.class, ManagementServerPropertiesAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class); - SpringBootTestUtils.addEnviroment(this.context, "security.basic.enabled:false"); + SpringBootTestUtils.addEnvironment(this.context, "security.basic.enabled:false"); this.context.refresh(); // Just the management endpoints (one filter) and ignores now assertEquals(7, this.context.getBean(FilterChainProxy.class).getFilterChains() @@ -171,7 +171,7 @@ public class ManagementSecurityAutoConfigurationTests { private static AnnotationConfigWebApplicationContext debugRefresh( AnnotationConfigWebApplicationContext context) { - SpringBootTestUtils.addEnviroment(context, "debug:true"); + SpringBootTestUtils.addEnvironment(context, "debug:true"); LoggingApplicationListener logging = new LoggingApplicationListener(); logging.onApplicationEvent(new SpringApplicationBeforeRefreshEvent( new SpringApplication(), context, new String[0])); diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/AbstractEndpointTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/AbstractEndpointTests.java index e2909e3480..046efb539c 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/AbstractEndpointTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/AbstractEndpointTests.java @@ -84,7 +84,7 @@ public abstract class AbstractEndpointTests> { @Test public void idOverride() throws Exception { this.context = new AnnotationConfigApplicationContext(); - SpringBootTestUtils.addEnviroment(this.context, this.property + ".id:myid"); + SpringBootTestUtils.addEnvironment(this.context, this.property + ".id:myid"); this.context.register(this.configClass); this.context.refresh(); assertThat(getEndpointBean().getId(), equalTo("myid")); diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/EnvironmentMvcEndpointTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/EnvironmentMvcEndpointTests.java index ea44eeead7..702bd0a5fc 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/EnvironmentMvcEndpointTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/EnvironmentMvcEndpointTests.java @@ -59,7 +59,7 @@ public class EnvironmentMvcEndpointTests { @Before public void setUp() { this.mvc = MockMvcBuilders.webAppContextSetup(this.context).build(); - SpringBootTestUtils.addEnviroment((ConfigurableApplicationContext) this.context, "foo:bar"); + SpringBootTestUtils.addEnvironment((ConfigurableApplicationContext) this.context, "foo:bar"); } @Test diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/JolokiaEndpointTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/JolokiaEndpointTests.java index 7511eaad40..ca5f0fbe16 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/JolokiaEndpointTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/JolokiaEndpointTests.java @@ -66,7 +66,7 @@ public class JolokiaEndpointTests { @Before public void setUp() { this.mvc = MockMvcBuilders.webAppContextSetup(this.context).build(); - SpringBootTestUtils.addEnviroment((ConfigurableApplicationContext) this.context, "foo:bar"); + SpringBootTestUtils.addEnvironment((ConfigurableApplicationContext) this.context, "foo:bar"); } @Test diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/PropertyPlaceholderAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/PropertyPlaceholderAutoConfigurationTests.java index 561e425218..5ece939347 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/PropertyPlaceholderAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/PropertyPlaceholderAutoConfigurationTests.java @@ -48,7 +48,7 @@ public class PropertyPlaceholderAutoConfigurationTests { public void propertyPlaceholderse() throws Exception { this.context.register(PropertyPlaceholderAutoConfiguration.class, PlaceholderConfig.class); - SpringBootTestUtils.addEnviroment(this.context, "foo:two"); + SpringBootTestUtils.addEnvironment(this.context, "foo:two"); this.context.refresh(); assertEquals("two", this.context.getBean(PlaceholderConfig.class).getFoo()); } @@ -57,7 +57,7 @@ public class PropertyPlaceholderAutoConfigurationTests { public void propertyPlaceholdersOverride() throws Exception { this.context.register(PropertyPlaceholderAutoConfiguration.class, PlaceholderConfig.class, PlaceholdersOverride.class); - SpringBootTestUtils.addEnviroment(this.context, "foo:two"); + SpringBootTestUtils.addEnvironment(this.context, "foo:two"); this.context.refresh(); assertEquals("spam", this.context.getBean(PlaceholderConfig.class).getFoo()); } diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/amqp/RabbitAutoconfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/amqp/RabbitAutoconfigurationTests.java index 182ac082c3..c64260c86b 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/amqp/RabbitAutoconfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/amqp/RabbitAutoconfigurationTests.java @@ -65,7 +65,7 @@ public class RabbitAutoconfigurationTests { public void testRabbitTemplateWithOverrides() { this.context = new AnnotationConfigApplicationContext(); this.context.register(TestConfiguration.class, RabbitAutoConfiguration.class); - SpringBootTestUtils.addEnviroment(this.context, "spring.rabbitmq.host:remote-server", + SpringBootTestUtils.addEnvironment(this.context, "spring.rabbitmq.host:remote-server", "spring.rabbitmq.port:9000", "spring.rabbitmq.username:alice", "spring.rabbitmq.password:secret", "spring.rabbitmq.virtual_host:/vhost"); this.context.refresh(); @@ -80,7 +80,7 @@ public class RabbitAutoconfigurationTests { public void testRabbitTemplateEmptyVirtualHost() { this.context = new AnnotationConfigApplicationContext(); this.context.register(TestConfiguration.class, RabbitAutoConfiguration.class); - SpringBootTestUtils.addEnviroment(this.context, "spring.rabbitmq.virtual_host:"); + SpringBootTestUtils.addEnvironment(this.context, "spring.rabbitmq.virtual_host:"); this.context.refresh(); CachingConnectionFactory connectionFactory = this.context .getBean(CachingConnectionFactory.class); @@ -91,7 +91,7 @@ public class RabbitAutoconfigurationTests { public void testRabbitTemplateVirtualHostMissingSlash() { this.context = new AnnotationConfigApplicationContext(); this.context.register(TestConfiguration.class, RabbitAutoConfiguration.class); - SpringBootTestUtils.addEnviroment(this.context, "spring.rabbitmq.virtual_host:foo"); + SpringBootTestUtils.addEnvironment(this.context, "spring.rabbitmq.virtual_host:foo"); this.context.refresh(); CachingConnectionFactory connectionFactory = this.context .getBean(CachingConnectionFactory.class); @@ -102,7 +102,7 @@ public class RabbitAutoconfigurationTests { public void testRabbitTemplateDefaultVirtualHost() { this.context = new AnnotationConfigApplicationContext(); this.context.register(TestConfiguration.class, RabbitAutoConfiguration.class); - SpringBootTestUtils.addEnviroment(this.context, "spring.rabbitmq.virtual_host:/"); + SpringBootTestUtils.addEnvironment(this.context, "spring.rabbitmq.virtual_host:/"); this.context.refresh(); CachingConnectionFactory connectionFactory = this.context .getBean(CachingConnectionFactory.class); @@ -126,7 +126,7 @@ public class RabbitAutoconfigurationTests { public void testStaticQueues() { this.context = new AnnotationConfigApplicationContext(); this.context.register(TestConfiguration.class, RabbitAutoConfiguration.class); - SpringBootTestUtils.addEnviroment(this.context, "spring.rabbitmq.dynamic:false"); + SpringBootTestUtils.addEnvironment(this.context, "spring.rabbitmq.dynamic:false"); this.context.refresh(); // There should NOT be an AmqpAdmin bean when dynamic is switch to false this.thrown.expect(NoSuchBeanDefinitionException.class); diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/aop/AopAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/aop/AopAutoConfigurationTests.java index 7e8077bd19..8d9c2a1b8a 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/aop/AopAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/aop/AopAutoConfigurationTests.java @@ -42,7 +42,7 @@ public class AopAutoConfigurationTests { this.context = new AnnotationConfigApplicationContext(); this.context.register(TestConfiguration.class, AopAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class); - SpringBootTestUtils.addEnviroment(this.context, "spring.aop.auto:false"); + SpringBootTestUtils.addEnvironment(this.context, "spring.aop.auto:false"); this.context.refresh(); TestAspect aspect = this.context.getBean(TestAspect.class); assertFalse(aspect.isCalled()); @@ -56,7 +56,7 @@ public class AopAutoConfigurationTests { this.context = new AnnotationConfigApplicationContext(); this.context.register(TestConfiguration.class, AopAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class); - SpringBootTestUtils.addEnviroment(this.context, "spring.aop.proxyTargetClass:true"); + SpringBootTestUtils.addEnvironment(this.context, "spring.aop.proxyTargetClass:true"); this.context.refresh(); TestAspect aspect = this.context.getBean(TestAspect.class); assertFalse(aspect.isCalled()); @@ -70,7 +70,7 @@ public class AopAutoConfigurationTests { this.context = new AnnotationConfigApplicationContext(); this.context.register(TestConfiguration.class, AopAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class); - SpringBootTestUtils.addEnviroment(this.context, "spring.aop.proxyTargetClass:false"); + SpringBootTestUtils.addEnvironment(this.context, "spring.aop.proxyTargetClass:false"); this.context.refresh(); TestAspect aspect = this.context.getBean(TestAspect.class); assertFalse(aspect.isCalled()); diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/batch/BatchAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/batch/BatchAutoConfigurationTests.java index 1cffb4e37f..07660c1225 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/batch/BatchAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/batch/BatchAutoConfigurationTests.java @@ -105,7 +105,7 @@ public class BatchAutoConfigurationTests { @Test public void testDisableLaunchesJob() throws Exception { this.context = new AnnotationConfigApplicationContext(); - SpringBootTestUtils.addEnviroment(this.context, "spring.batch.job.enabled:false"); + SpringBootTestUtils.addEnvironment(this.context, "spring.batch.job.enabled:false"); this.context.register(JobConfiguration.class, BatchAutoConfiguration.class, EmbeddedDataSourceConfiguration.class, PropertyPlaceholderAutoConfiguration.class); @@ -117,7 +117,7 @@ public class BatchAutoConfigurationTests { @Test public void testDisableSchemaLoader() throws Exception { this.context = new AnnotationConfigApplicationContext(); - SpringBootTestUtils.addEnviroment(this.context, "spring.datasource.name:batchtest", + SpringBootTestUtils.addEnvironment(this.context, "spring.datasource.name:batchtest", "spring.batch.initializer.enabled:false"); this.context.register(TestConfiguration.class, BatchAutoConfiguration.class, EmbeddedDataSourceConfiguration.class, diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfigurationTests.java index 2a50969300..9760a947d8 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfigurationTests.java @@ -66,7 +66,7 @@ public class DataSourceAutoConfigurationTests { @Test public void testEmbeddedTypeDefaultsUsername() throws Exception { - SpringBootTestUtils.addEnviroment(this.context, + SpringBootTestUtils.addEnvironment(this.context, "spring.datasource.driverClassName:org.hsqldb.jdbcDriver", "spring.datasource.url:jdbc:hsqldb:mem:testdb"); this.context.register(DataSourceAutoConfiguration.class, @@ -82,7 +82,7 @@ public class DataSourceAutoConfigurationTests { @Test public void testExplicitDriverClassClearsUserName() throws Exception { SpringBootTestUtils - .addEnviroment( + .addEnvironment( this.context, "spring.datasource.driverClassName:org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfigurationTests$DatabaseDriver", "spring.datasource.url:jdbc:foo://localhost", diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/TomcatDataSourceConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/TomcatDataSourceConfigurationTests.java index 1be4cf02be..854f94dc4c 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/TomcatDataSourceConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/TomcatDataSourceConfigurationTests.java @@ -56,7 +56,7 @@ public class TomcatDataSourceConfigurationTests { @Test public void testDataSourcePropertiesOverridden() throws Exception { this.context.register(TomcatDataSourceConfiguration.class); - SpringBootTestUtils.addEnviroment(this.context, "spring.datasource.url:jdbc:foo//bar/spam"); + SpringBootTestUtils.addEnvironment(this.context, "spring.datasource.url:jdbc:foo//bar/spam"); this.context.refresh(); assertEquals("jdbc:foo//bar/spam", this.context.getBean(org.apache.tomcat.jdbc.pool.DataSource.class) diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jms/JmsTemplateAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jms/JmsTemplateAutoConfigurationTests.java index 944e8de5cd..95b39514e4 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jms/JmsTemplateAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jms/JmsTemplateAutoConfigurationTests.java @@ -118,7 +118,7 @@ public class JmsTemplateAutoConfigurationTests { this.context = new AnnotationConfigApplicationContext(); this.context .register(TestConfiguration.class, JmsTemplateAutoConfiguration.class); - SpringBootTestUtils.addEnviroment(this.context, "spring.jms.pubSubDomain:false"); + SpringBootTestUtils.addEnvironment(this.context, "spring.jms.pubSubDomain:false"); this.context.refresh(); JmsTemplate jmsTemplate = this.context.getBean(JmsTemplate.class); ActiveMQConnectionFactory connectionFactory = this.context @@ -134,7 +134,7 @@ public class JmsTemplateAutoConfigurationTests { this.context = new AnnotationConfigApplicationContext(); this.context .register(TestConfiguration.class, JmsTemplateAutoConfiguration.class); - SpringBootTestUtils.addEnviroment(this.context, "spring.activemq.inMemory:false"); + SpringBootTestUtils.addEnvironment(this.context, "spring.activemq.inMemory:false"); this.context.refresh(); JmsTemplate jmsTemplate = this.context.getBean(JmsTemplate.class); ActiveMQConnectionFactory connectionFactory = this.context @@ -153,7 +153,7 @@ public class JmsTemplateAutoConfigurationTests { this.context = new AnnotationConfigApplicationContext(); this.context .register(TestConfiguration.class, JmsTemplateAutoConfiguration.class); - SpringBootTestUtils.addEnviroment(this.context, "spring.activemq.inMemory:false", + SpringBootTestUtils.addEnvironment(this.context, "spring.activemq.inMemory:false", "spring.activemq.brokerURL:tcp://remote-host:10000"); this.context.refresh(); JmsTemplate jmsTemplate = this.context.getBean(JmsTemplate.class); @@ -173,7 +173,7 @@ public class JmsTemplateAutoConfigurationTests { this.context = new AnnotationConfigApplicationContext(); this.context .register(TestConfiguration.class, JmsTemplateAutoConfiguration.class); - SpringBootTestUtils.addEnviroment(this.context, "spring.activemq.pooled:true"); + SpringBootTestUtils.addEnvironment(this.context, "spring.activemq.pooled:true"); this.context.refresh(); JmsTemplate jmsTemplate = this.context.getBean(JmsTemplate.class); PooledConnectionFactory pool = this.context @@ -191,7 +191,7 @@ public class JmsTemplateAutoConfigurationTests { this.context = new AnnotationConfigApplicationContext(); this.context .register(TestConfiguration.class, JmsTemplateAutoConfiguration.class); - SpringBootTestUtils.addEnviroment(this.context, "spring.activemq.pooled:true", + SpringBootTestUtils.addEnvironment(this.context, "spring.activemq.pooled:true", "spring.activemq.inMemory:false"); this.context.refresh(); JmsTemplate jmsTemplate = this.context.getBean(JmsTemplate.class); @@ -210,7 +210,7 @@ public class JmsTemplateAutoConfigurationTests { this.context = new AnnotationConfigApplicationContext(); this.context .register(TestConfiguration.class, JmsTemplateAutoConfiguration.class); - SpringBootTestUtils.addEnviroment(this.context, "spring.activemq.pooled:true", + SpringBootTestUtils.addEnvironment(this.context, "spring.activemq.pooled:true", "spring.activemq.inMemory:false", "spring.activemq.brokerURL:tcp://remote-host:10000"); this.context.refresh(); diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/orm/jpa/AbstractJpaAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/orm/jpa/AbstractJpaAutoConfigurationTests.java index 6b3a1edd76..a67fd13550 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/orm/jpa/AbstractJpaAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/orm/jpa/AbstractJpaAutoConfigurationTests.java @@ -112,7 +112,7 @@ public abstract class AbstractJpaAutoConfigurationTests { public void testOpenEntityManagerInViewInterceptorNotRegisteredWhenExplicitlyOff() throws Exception { AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext(); - SpringBootTestUtils.addEnviroment(context, "spring.jpa.open_in_view:false"); + SpringBootTestUtils.addEnvironment(context, "spring.jpa.open_in_view:false"); context.register(TestConfiguration.class, ComponentScanDetectorConfiguration.class, EmbeddedDataSourceConfiguration.class, @@ -124,7 +124,7 @@ public abstract class AbstractJpaAutoConfigurationTests { @Test public void customJpaProperties() throws Exception { - SpringBootTestUtils.addEnviroment(this.context, "spring.jpa.properties.a:b", + SpringBootTestUtils.addEnvironment(this.context, "spring.jpa.properties.a:b", "spring.jpa.properties.c:d"); setupTestConfiguration(); this.context.refresh(); diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfigurationTests.java index 882766b3d5..de73b74680 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfigurationTests.java @@ -38,7 +38,7 @@ public class HibernateJpaAutoConfigurationTests extends AbstractJpaAutoConfigura @Test public void testCustomNamingStrategy() throws Exception { - SpringBootTestUtils.addEnviroment(this.context, "spring.jpa.hibernate.namingstrategy:" + SpringBootTestUtils.addEnvironment(this.context, "spring.jpa.hibernate.namingstrategy:" + "org.hibernate.cfg.EJB3NamingStrategy"); setupTestConfiguration(); this.context.refresh(); diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/redis/RedisAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/redis/RedisAutoConfigurationTests.java index 877d638397..831b73571c 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/redis/RedisAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/redis/RedisAutoConfigurationTests.java @@ -47,7 +47,7 @@ public class RedisAutoConfigurationTests { @Test public void testOverrideRedisConfiguration() throws Exception { this.context = new AnnotationConfigApplicationContext(); - SpringBootTestUtils.addEnviroment(this.context, "spring.redis.host:foo"); + SpringBootTestUtils.addEnvironment(this.context, "spring.redis.host:foo"); this.context.register(RedisAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class); this.context.refresh(); diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/SecurityAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/SecurityAutoConfigurationTests.java index 1876c10368..9c76887b7c 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/SecurityAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/SecurityAutoConfigurationTests.java @@ -72,7 +72,7 @@ public class SecurityAutoConfigurationTests { this.context.setServletContext(new MockServletContext()); this.context.register(SecurityAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class); - SpringBootTestUtils.addEnviroment(this.context, "security.ignored:none"); + SpringBootTestUtils.addEnvironment(this.context, "security.ignored:none"); this.context.refresh(); // Just the application endpoints now assertEquals(1, this.context.getBean(FilterChainProxy.class).getFilterChains() @@ -85,7 +85,7 @@ public class SecurityAutoConfigurationTests { this.context.setServletContext(new MockServletContext()); this.context.register(SecurityAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class); - SpringBootTestUtils.addEnviroment(this.context, "security.basic.enabled:false"); + SpringBootTestUtils.addEnvironment(this.context, "security.basic.enabled:false"); this.context.refresh(); // No security at all not even ignores assertEquals(0, this.context.getBeanNamesForType(FilterChainProxy.class).length); @@ -118,7 +118,7 @@ public class SecurityAutoConfigurationTests { private static AnnotationConfigWebApplicationContext debugRefresh( AnnotationConfigWebApplicationContext context) { - SpringBootTestUtils.addEnviroment(context, "debug:true"); + SpringBootTestUtils.addEnvironment(context, "debug:true"); LoggingApplicationListener logging = new LoggingApplicationListener(); logging.onApplicationEvent(new SpringApplicationBeforeRefreshEvent( new SpringApplication(), context, new String[0])); diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ServerPropertiesAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ServerPropertiesAutoConfigurationTests.java index 8724cdba91..87f4031951 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ServerPropertiesAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ServerPropertiesAutoConfigurationTests.java @@ -72,7 +72,7 @@ public class ServerPropertiesAutoConfigurationTests { this.context = new AnnotationConfigEmbeddedWebApplicationContext(); this.context.register(Config.class, ServerPropertiesAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class); - SpringBootTestUtils.addEnviroment(this.context, "server.port:9000"); + SpringBootTestUtils.addEnvironment(this.context, "server.port:9000"); this.context.refresh(); ServerProperties server = this.context.getBean(ServerProperties.class); assertNotNull(server); @@ -86,7 +86,7 @@ public class ServerPropertiesAutoConfigurationTests { this.context = new AnnotationConfigEmbeddedWebApplicationContext(); this.context.register(Config.class, ServerPropertiesAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class); - SpringBootTestUtils.addEnviroment(this.context, "server.tomcat.basedir:target/foo", + SpringBootTestUtils.addEnvironment(this.context, "server.tomcat.basedir:target/foo", "server.port:9000"); this.context.refresh(); ServerProperties server = this.context.getBean(ServerProperties.class); diff --git a/spring-boot/src/main/java/org/springframework/boot/context/listener/ConfigFileApplicationListener.java b/spring-boot/src/main/java/org/springframework/boot/context/listener/ConfigFileApplicationListener.java index 816ec7d310..0c03a62782 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/listener/ConfigFileApplicationListener.java +++ b/spring-boot/src/main/java/org/springframework/boot/context/listener/ConfigFileApplicationListener.java @@ -187,31 +187,46 @@ public class ConfigFileApplicationListener implements PropertySource removed = environment.getPropertySources().remove( "defaultProperties"); - List> sources = new ArrayList>(); + String first = null; // Initial load allows profiles to be activated for (String candidate : candidates) { PropertySource source = load(environment, resourceLoader, candidate, null); if (source != null) { - sources.add(source); + if (first == null) { + first = source.getName(); + } + environment.getPropertySources().addLast(source); } } + if (environment.containsProperty("spring.profiles.active")) { + Set profiles = StringUtils.commaDelimitedListToSet(environment + .getProperty("spring.profiles.active").toString()); + for (String active : profiles) { + // allow document with no profile to set the active one + environment.addActiveProfile(active); + } + + } + // Second load for specific profiles for (String profile : environment.getActiveProfiles()) { for (String candidate : candidates) { PropertySource source = load(environment, resourceLoader, candidate, profile); if (source != null) { - environment.getPropertySources().addLast(source); + if (first != null) { + // Originals go at the end so they don't override the specific + // profiles + environment.getPropertySources().addBefore(first, source); + } + else { + environment.getPropertySources().addLast(source); + } } } } - // Originals go at the end so they don't override the specific profiles - for (PropertySource source : sources) { - environment.getPropertySources().addLast(source); - } - if (removed != null) { environment.getPropertySources().addLast(removed); } @@ -277,15 +292,6 @@ public class ConfigFileApplicationListener implements if (propertySource == null) { return null; } - if (propertySource.containsProperty("spring.profiles.active")) { - Set profiles = StringUtils.commaDelimitedListToSet(propertySource - .getProperty("spring.profiles.active").toString()); - for (String active : profiles) { - // allow document with no profile to set the active one - environment.addActiveProfile(active); - } - - } return propertySource; } diff --git a/spring-boot/src/test/java/org/springframework/boot/context/initializer/ContextIdApplicationContextInitializerTests.java b/spring-boot/src/test/java/org/springframework/boot/context/initializer/ContextIdApplicationContextInitializerTests.java index c08cabef70..3410248ce0 100644 --- a/spring-boot/src/test/java/org/springframework/boot/context/initializer/ContextIdApplicationContextInitializerTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/context/initializer/ContextIdApplicationContextInitializerTests.java @@ -42,7 +42,7 @@ public class ContextIdApplicationContextInitializerTests { @Test public void testNameAndPort() { ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(); - SpringBootTestUtils.addEnviroment(context, "spring.application.name:foo", "PORT:8080"); + SpringBootTestUtils.addEnvironment(context, "spring.application.name:foo", "PORT:8080"); this.initializer.initialize(context); assertEquals("foo:8080", context.getId()); } @@ -50,7 +50,7 @@ public class ContextIdApplicationContextInitializerTests { @Test public void testNameAndProfiles() { ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(); - SpringBootTestUtils.addEnviroment(context, "spring.application.name:foo", + SpringBootTestUtils.addEnvironment(context, "spring.application.name:foo", "spring.profiles.active: spam,bar", "spring.application.index:12"); this.initializer.initialize(context); assertEquals("foo:spam,bar:12", context.getId()); @@ -59,7 +59,7 @@ public class ContextIdApplicationContextInitializerTests { @Test public void testCloudFoundry() { ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(); - SpringBootTestUtils.addEnviroment(context, "spring.config.name:foo", "PORT:8080", + SpringBootTestUtils.addEnvironment(context, "spring.config.name:foo", "PORT:8080", "vcap.application.name:bar", "vcap.application.instance_index:2"); this.initializer.initialize(context); assertEquals("bar:2", context.getId()); @@ -68,7 +68,7 @@ public class ContextIdApplicationContextInitializerTests { @Test public void testExplicitName() { ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(); - SpringBootTestUtils.addEnviroment(context, "spring.application.name:spam", + SpringBootTestUtils.addEnvironment(context, "spring.application.name:spam", "spring.config.name:foo", "PORT:8080", "vcap.application.name:bar", "vcap.application.instance_index:2"); this.initializer.initialize(context); diff --git a/spring-boot/src/test/java/org/springframework/boot/context/initializer/EnvironmentDelegateApplicationContextInitializerTests.java b/spring-boot/src/test/java/org/springframework/boot/context/initializer/EnvironmentDelegateApplicationContextInitializerTests.java index 36b5b9cec4..84c3bbba90 100644 --- a/spring-boot/src/test/java/org/springframework/boot/context/initializer/EnvironmentDelegateApplicationContextInitializerTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/context/initializer/EnvironmentDelegateApplicationContextInitializerTests.java @@ -46,7 +46,7 @@ public class EnvironmentDelegateApplicationContextInitializerTests { @Test public void orderedInitialize() throws Exception { StaticApplicationContext context = new StaticApplicationContext(); - SpringBootTestUtils.addEnviroment(context, + SpringBootTestUtils.addEnvironment(context, "context.initializer.classes:" + MockInitB.class.getName() + "," + MockInitA.class.getName()); this.initializer.initialize(context); @@ -63,14 +63,14 @@ public class EnvironmentDelegateApplicationContextInitializerTests { @Test public void emptyInitializers() throws Exception { StaticApplicationContext context = new StaticApplicationContext(); - SpringBootTestUtils.addEnviroment(context, "context.initializer.classes:"); + SpringBootTestUtils.addEnvironment(context, "context.initializer.classes:"); this.initializer.initialize(context); } @Test public void noSuchInitializerClass() throws Exception { StaticApplicationContext context = new StaticApplicationContext(); - SpringBootTestUtils.addEnviroment(context, + SpringBootTestUtils.addEnvironment(context, "context.initializer.classes:missing.madeup.class"); this.thrown.expect(ApplicationContextException.class); this.initializer.initialize(context); @@ -79,7 +79,7 @@ public class EnvironmentDelegateApplicationContextInitializerTests { @Test public void notAnInitializerClass() throws Exception { StaticApplicationContext context = new StaticApplicationContext(); - SpringBootTestUtils.addEnviroment(context, + SpringBootTestUtils.addEnvironment(context, "context.initializer.classes:" + Object.class.getName()); this.thrown.expect(IllegalArgumentException.class); this.initializer.initialize(context); @@ -88,7 +88,7 @@ public class EnvironmentDelegateApplicationContextInitializerTests { @Test public void genericNotSuitable() throws Exception { StaticApplicationContext context = new StaticApplicationContext(); - SpringBootTestUtils.addEnviroment(context, "context.initializer.classes:" + SpringBootTestUtils.addEnvironment(context, "context.initializer.classes:" + NotSuitableInit.class.getName()); this.thrown.expect(IllegalArgumentException.class); this.thrown.expectMessage("generic parameter"); diff --git a/spring-boot/src/test/java/org/springframework/boot/context/listener/ConfigFileApplicationListenerTests.java b/spring-boot/src/test/java/org/springframework/boot/context/listener/ConfigFileApplicationListenerTests.java index 8ca2b86e7c..c14ae6e8e7 100644 --- a/spring-boot/src/test/java/org/springframework/boot/context/listener/ConfigFileApplicationListenerTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/context/listener/ConfigFileApplicationListenerTests.java @@ -16,6 +16,7 @@ package org.springframework.boot.context.listener; +import java.util.Arrays; import java.util.HashMap; import java.util.Map; @@ -23,7 +24,7 @@ import org.junit.After; import org.junit.Test; import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplicationEnvironmentAvailableEvent; -import org.springframework.boot.context.listener.ConfigFileApplicationListener; +import org.springframework.boot.test.SpringBootTestUtils; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Profile; @@ -32,6 +33,7 @@ import org.springframework.core.env.MapPropertySource; import org.springframework.core.env.SimpleCommandLinePropertySource; import org.springframework.core.env.StandardEnvironment; +import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.notNullValue; import static org.hamcrest.Matchers.nullValue; @@ -143,9 +145,20 @@ public class ConfigFileApplicationListenerTests { this.initializer.setNames("testsetprofiles"); this.initializer.onApplicationEvent(this.event); String property = this.environment.getProperty("my.property"); + assertThat(Arrays.asList(this.environment.getActiveProfiles()), contains("dev")); assertThat(property, equalTo("fromdevprofile")); } + @Test + public void yamlProfileCanBeChanged() throws Exception { + SpringBootTestUtils + .addEnviroment(this.environment, "spring.profiles.active:prod"); + this.initializer.setNames("testsetprofiles"); + this.initializer.onApplicationEvent(this.event); + assertThat(Arrays.asList(this.environment.getActiveProfiles()).toString(), + equalTo("[prod]")); + } + @Test public void specificNameAndProfileFromExistingSource() throws Exception { Map map = new HashMap(); diff --git a/spring-boot/src/test/java/org/springframework/boot/context/listener/EnvironmentDelegateApplicationListenerTests.java b/spring-boot/src/test/java/org/springframework/boot/context/listener/EnvironmentDelegateApplicationListenerTests.java index 8c3fc28f9c..abb79aa7ae 100644 --- a/spring-boot/src/test/java/org/springframework/boot/context/listener/EnvironmentDelegateApplicationListenerTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/context/listener/EnvironmentDelegateApplicationListenerTests.java @@ -51,7 +51,7 @@ public class EnvironmentDelegateApplicationListenerTests { @Test public void orderedInitialize() throws Exception { - SpringBootTestUtils.addEnviroment(this.context, "context.listener.classes:" + SpringBootTestUtils.addEnvironment(this.context, "context.listener.classes:" + MockInitB.class.getName() + "," + MockInitA.class.getName()); this.listener.onApplicationEvent(new SpringApplicationEnvironmentAvailableEvent( new SpringApplication(), this.context.getEnvironment(), new String[0])); @@ -69,7 +69,7 @@ public class EnvironmentDelegateApplicationListenerTests { @Test public void emptyInitializers() throws Exception { - SpringBootTestUtils.addEnviroment(this.context, "context.listener.classes:"); + SpringBootTestUtils.addEnvironment(this.context, "context.listener.classes:"); this.listener.onApplicationEvent(new SpringApplicationEnvironmentAvailableEvent( new SpringApplication(), this.context.getEnvironment(), new String[0])); } diff --git a/spring-boot/src/test/java/org/springframework/boot/context/listener/LoggingApplicationListenerTests.java b/spring-boot/src/test/java/org/springframework/boot/context/listener/LoggingApplicationListenerTests.java index 734cf7871a..c5e766d80e 100644 --- a/spring-boot/src/test/java/org/springframework/boot/context/listener/LoggingApplicationListenerTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/context/listener/LoggingApplicationListenerTests.java @@ -95,7 +95,7 @@ public class LoggingApplicationListenerTests { @Test public void testOverrideConfigLocation() { - SpringBootTestUtils.addEnviroment(this.context, + SpringBootTestUtils.addEnvironment(this.context, "logging.config: classpath:logback-nondefault.xml"); this.initializer.initialize(this.context.getEnvironment(), this.context.getClassLoader()); @@ -108,7 +108,7 @@ public class LoggingApplicationListenerTests { @Test public void testOverrideConfigDoesNotExist() throws Exception { - SpringBootTestUtils.addEnviroment(this.context, "logging.config: doesnotexist.xml"); + SpringBootTestUtils.addEnvironment(this.context, "logging.config: doesnotexist.xml"); this.initializer.initialize(this.context.getEnvironment(), this.context.getClassLoader()); // Should not throw @@ -116,7 +116,7 @@ public class LoggingApplicationListenerTests { @Test public void testAddLogFileProperty() { - SpringBootTestUtils.addEnviroment(this.context, + SpringBootTestUtils.addEnvironment(this.context, "logging.config: classpath:logback-nondefault.xml", "logging.file: foo.log"); this.initializer.initialize(this.context.getEnvironment(), @@ -129,7 +129,7 @@ public class LoggingApplicationListenerTests { @Test public void testAddLogPathProperty() { - SpringBootTestUtils.addEnviroment(this.context, + SpringBootTestUtils.addEnvironment(this.context, "logging.config: classpath:logback-nondefault.xml", "logging.path: foo/"); this.initializer.initialize(this.context.getEnvironment(), this.context.getClassLoader()); @@ -141,7 +141,7 @@ public class LoggingApplicationListenerTests { @Test public void parseDebugArg() throws Exception { - SpringBootTestUtils.addEnviroment(this.context, "debug"); + SpringBootTestUtils.addEnvironment(this.context, "debug"); this.initializer.initialize(this.context.getEnvironment(), this.context.getClassLoader()); this.logger.debug("testatdebug"); @@ -152,7 +152,7 @@ public class LoggingApplicationListenerTests { @Test public void parseTraceArg() throws Exception { - SpringBootTestUtils.addEnviroment(this.context, "trace"); + SpringBootTestUtils.addEnvironment(this.context, "trace"); this.initializer.initialize(this.context.getEnvironment(), this.context.getClassLoader()); this.logger.debug("testatdebug"); @@ -164,7 +164,7 @@ public class LoggingApplicationListenerTests { @Test public void parseArgsDisabled() throws Exception { this.initializer.setParseArgs(false); - SpringBootTestUtils.addEnviroment(this.context, "debug"); + SpringBootTestUtils.addEnvironment(this.context, "debug"); this.initializer.initialize(this.context.getEnvironment(), this.context.getClassLoader()); this.logger.debug("testatdebug"); diff --git a/spring-boot/src/test/java/org/springframework/boot/context/listener/VcapApplicationListenerTests.java b/spring-boot/src/test/java/org/springframework/boot/context/listener/VcapApplicationListenerTests.java index 729ec2d16b..ab3ab2daf0 100644 --- a/spring-boot/src/test/java/org/springframework/boot/context/listener/VcapApplicationListenerTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/context/listener/VcapApplicationListenerTests.java @@ -40,7 +40,7 @@ public class VcapApplicationListenerTests { @Test public void testApplicationProperties() { SpringBootTestUtils - .addEnviroment( + .addEnvironment( this.context, "VCAP_APPLICATION:{\"application_users\":[],\"instance_id\":\"bb7935245adf3e650dfb7c58a06e9ece\",\"instance_index\":0,\"version\":\"3464e092-1c13-462e-a47c-807c30318a50\",\"name\":\"foo\",\"uris\":[\"foo.cfapps.io\"],\"started_at\":\"2013-05-29 02:37:59 +0000\",\"started_at_timestamp\":1369795079,\"host\":\"0.0.0.0\",\"port\":61034,\"limits\":{\"mem\":128,\"disk\":1024,\"fds\":16384},\"version\":\"3464e092-1c13-462e-a47c-807c30318a50\",\"name\":\"dsyerenv\",\"uris\":[\"dsyerenv.cfapps.io\"],\"users\":[],\"start\":\"2013-05-29 02:37:59 +0000\",\"state_timestamp\":1369795079}"); this.initializer.onApplicationEvent(this.event); @@ -50,7 +50,7 @@ public class VcapApplicationListenerTests { @Test public void testUnparseableApplicationProperties() { - SpringBootTestUtils.addEnviroment(this.context, "VCAP_APPLICATION:"); + SpringBootTestUtils.addEnvironment(this.context, "VCAP_APPLICATION:"); this.initializer.onApplicationEvent(this.event); assertEquals(null, this.context.getEnvironment().getProperty("vcap")); } @@ -58,7 +58,7 @@ public class VcapApplicationListenerTests { @Test public void testNullApplicationProperties() { SpringBootTestUtils - .addEnviroment( + .addEnvironment( this.context, "VCAP_APPLICATION:{\"application_users\":null,\"instance_id\":\"bb7935245adf3e650dfb7c58a06e9ece\",\"instance_index\":0,\"version\":\"3464e092-1c13-462e-a47c-807c30318a50\",\"name\":\"foo\",\"uris\":[\"foo.cfapps.io\"],\"started_at\":\"2013-05-29 02:37:59 +0000\",\"started_at_timestamp\":1369795079,\"host\":\"0.0.0.0\",\"port\":61034,\"limits\":{\"mem\":128,\"disk\":1024,\"fds\":16384},\"version\":\"3464e092-1c13-462e-a47c-807c30318a50\",\"name\":\"dsyerenv\",\"uris\":[\"dsyerenv.cfapps.io\"],\"users\":[],\"start\":\"2013-05-29 02:37:59 +0000\",\"state_timestamp\":1369795079}"); this.initializer.onApplicationEvent(this.event); @@ -68,7 +68,7 @@ public class VcapApplicationListenerTests { @Test public void testServiceProperties() { SpringBootTestUtils - .addEnviroment( + .addEnvironment( this.context, "VCAP_SERVICES:{\"rds-mysql-n/a\":[{\"name\":\"mysql\",\"label\":\"rds-mysql-n/a\",\"plan\":\"10mb\",\"credentials\":{\"name\":\"d04fb13d27d964c62b267bbba1cffb9da\",\"hostname\":\"mysql-service-public.clqg2e2w3ecf.us-east-1.rds.amazonaws.com\",\"host\":\"mysql-service-public.clqg2e2w3ecf.us-east-1.rds.amazonaws.com\",\"port\":3306,\"user\":\"urpRuqTf8Cpe6\",\"username\":\"urpRuqTf8Cpe6\",\"password\":\"pxLsGVpsC9A5S\"}}]}"); this.initializer.onApplicationEvent(this.event); diff --git a/spring-boot/src/test/java/org/springframework/boot/context/properties/EnableConfigurationPropertiesTests.java b/spring-boot/src/test/java/org/springframework/boot/context/properties/EnableConfigurationPropertiesTests.java index 1e56f7b2c4..4c602bee38 100644 --- a/spring-boot/src/test/java/org/springframework/boot/context/properties/EnableConfigurationPropertiesTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/context/properties/EnableConfigurationPropertiesTests.java @@ -64,7 +64,7 @@ public class EnableConfigurationPropertiesTests { @Test public void testBasicPropertiesBinding() { this.context.register(TestConfiguration.class); - SpringBootTestUtils.addEnviroment(this.context, "name:foo"); + SpringBootTestUtils.addEnvironment(this.context, "name:foo"); this.context.refresh(); assertEquals(1, this.context.getBeanNamesForType(TestProperties.class).length); assertEquals("foo", this.context.getBean(TestProperties.class).name); @@ -105,7 +105,7 @@ public class EnableConfigurationPropertiesTests { public void testStrictPropertiesBinding() { removeSystemProperties(); this.context.register(StrictTestConfiguration.class); - SpringBootTestUtils.addEnviroment(this.context, "name:foo"); + SpringBootTestUtils.addEnvironment(this.context, "name:foo"); this.context.refresh(); assertEquals(1, this.context.getBeanNamesForType(StrictTestProperties.class).length); @@ -115,7 +115,7 @@ public class EnableConfigurationPropertiesTests { @Test public void testPropertiesEmbeddedBinding() { this.context.register(EmbeddedTestConfiguration.class); - SpringBootTestUtils.addEnviroment(this.context, "spring_foo_name:foo"); + SpringBootTestUtils.addEnvironment(this.context, "spring_foo_name:foo"); this.context.refresh(); assertEquals(1, this.context.getBeanNamesForType(EmbeddedTestProperties.class).length); @@ -126,7 +126,7 @@ public class EnableConfigurationPropertiesTests { public void testIgnoreNestedPropertiesBinding() { removeSystemProperties(); this.context.register(IgnoreNestedTestConfiguration.class); - SpringBootTestUtils.addEnviroment(this.context, "name:foo", "nested.name:bar"); + SpringBootTestUtils.addEnvironment(this.context, "name:foo", "nested.name:bar"); this.context.refresh(); assertEquals(1, this.context.getBeanNamesForType(IgnoreNestedTestProperties.class).length); @@ -136,7 +136,7 @@ public class EnableConfigurationPropertiesTests { @Test public void testExceptionOnValidation() { this.context.register(ExceptionIfInvalidTestConfiguration.class); - SpringBootTestUtils.addEnviroment(this.context, "name:foo"); + SpringBootTestUtils.addEnvironment(this.context, "name:foo"); this.expected.expectCause(Matchers. instanceOf(BindException.class)); this.context.refresh(); } @@ -144,7 +144,7 @@ public class EnableConfigurationPropertiesTests { @Test public void testNoExceptionOnValidation() { this.context.register(NoExceptionIfInvalidTestConfiguration.class); - SpringBootTestUtils.addEnviroment(this.context, "name:foo"); + SpringBootTestUtils.addEnvironment(this.context, "name:foo"); this.context.refresh(); assertEquals( 1, @@ -156,7 +156,7 @@ public class EnableConfigurationPropertiesTests { @Test public void testNestedPropertiesBinding() { this.context.register(NestedConfiguration.class); - SpringBootTestUtils.addEnviroment(this.context, "name:foo", "nested.name:bar"); + SpringBootTestUtils.addEnvironment(this.context, "name:foo", "nested.name:bar"); this.context.refresh(); assertEquals(1, this.context.getBeanNamesForType(NestedProperties.class).length); assertEquals("foo", this.context.getBean(NestedProperties.class).name); @@ -166,7 +166,7 @@ public class EnableConfigurationPropertiesTests { @Test public void testBasicPropertiesBindingWithAnnotationOnBaseClass() { this.context.register(DerivedConfiguration.class); - SpringBootTestUtils.addEnviroment(this.context, "name:foo"); + SpringBootTestUtils.addEnvironment(this.context, "name:foo"); this.context.refresh(); assertEquals(1, this.context.getBeanNamesForType(DerivedProperties.class).length); assertEquals("foo", this.context.getBean(BaseProperties.class).name); @@ -175,7 +175,7 @@ public class EnableConfigurationPropertiesTests { @Test public void testArrayPropertiesBinding() { this.context.register(TestConfiguration.class); - SpringBootTestUtils.addEnviroment(this.context, "name:foo", "array:1,2,3"); + SpringBootTestUtils.addEnvironment(this.context, "name:foo", "array:1,2,3"); this.context.refresh(); assertEquals(1, this.context.getBeanNamesForType(TestProperties.class).length); assertEquals(3, this.context.getBean(TestProperties.class).getArray().length); @@ -184,7 +184,7 @@ public class EnableConfigurationPropertiesTests { @Test public void testCollectionPropertiesBindingFromYamlArray() { this.context.register(TestConfiguration.class); - SpringBootTestUtils.addEnviroment(this.context, "name:foo", "list[0]:1", "list[1]:2"); + SpringBootTestUtils.addEnvironment(this.context, "name:foo", "list[0]:1", "list[1]:2"); this.context.refresh(); assertEquals(2, this.context.getBean(TestProperties.class).getList().size()); } @@ -192,7 +192,7 @@ public class EnableConfigurationPropertiesTests { @Test public void testPropertiesBindingWithoutAnnotation() { this.context.register(MoreConfiguration.class); - SpringBootTestUtils.addEnviroment(this.context, "name:foo"); + SpringBootTestUtils.addEnvironment(this.context, "name:foo"); this.context.refresh(); assertEquals(1, this.context.getBeanNamesForType(MoreProperties.class).length); assertEquals("foo", this.context.getBean(MoreProperties.class).name); @@ -227,7 +227,7 @@ public class EnableConfigurationPropertiesTests { @Test public void testBindingDirectlyToFileResolvedFromEnvironment() { - SpringBootTestUtils.addEnviroment(this.context, "binding.location:classpath:other.yml"); + SpringBootTestUtils.addEnvironment(this.context, "binding.location:classpath:other.yml"); this.context.register(ResourceBindingProperties.class, TestConfiguration.class); this.context.refresh(); assertEquals(1, @@ -268,7 +268,7 @@ public class EnableConfigurationPropertiesTests { AnnotationConfigApplicationContext parent = new AnnotationConfigApplicationContext(); parent.register(TestConfiguration.class); parent.refresh(); - SpringBootTestUtils.addEnviroment(this.context, "name:foo"); + SpringBootTestUtils.addEnvironment(this.context, "name:foo"); this.context.setParent(parent); this.context.register(TestConfiguration.class, TestConsumer.class); this.context.refresh(); @@ -280,7 +280,7 @@ public class EnableConfigurationPropertiesTests { @Test public void testBindingOnlyParentContext() { AnnotationConfigApplicationContext parent = new AnnotationConfigApplicationContext(); - SpringBootTestUtils.addEnviroment(parent, "name:foo"); + SpringBootTestUtils.addEnvironment(parent, "name:foo"); parent.register(TestConfiguration.class); parent.refresh(); this.context.setParent(parent); @@ -293,7 +293,7 @@ public class EnableConfigurationPropertiesTests { @Test public void testUnderscoresInPrefix() throws Exception { - SpringBootTestUtils.addEnviroment(this.context, "spring_test_external_val:baz"); + SpringBootTestUtils.addEnvironment(this.context, "spring_test_external_val:baz"); this.context.register(SystemExampleConfig.class); this.context.refresh(); assertEquals("baz", this.context.getBean(SystemEnvVar.class).getVal()); @@ -301,7 +301,7 @@ public class EnableConfigurationPropertiesTests { @Test public void testSimpleAutoConfig() throws Exception { - SpringBootTestUtils.addEnviroment(this.context, "external.name:foo"); + SpringBootTestUtils.addEnvironment(this.context, "external.name:foo"); this.context.register(ExampleConfig.class); this.context.refresh(); assertEquals("foo", this.context.getBean(External.class).getName()); @@ -309,7 +309,7 @@ public class EnableConfigurationPropertiesTests { @Test public void testExplicitType() throws Exception { - SpringBootTestUtils.addEnviroment(this.context, "external.name:foo"); + SpringBootTestUtils.addEnvironment(this.context, "external.name:foo"); this.context.register(AnotherExampleConfig.class); this.context.refresh(); assertEquals("foo", this.context.getBean(External.class).getName()); @@ -317,7 +317,7 @@ public class EnableConfigurationPropertiesTests { @Test public void testMultipleExplicitTypes() throws Exception { - SpringBootTestUtils.addEnviroment(this.context, "external.name:foo", "another.name:bar"); + SpringBootTestUtils.addEnvironment(this.context, "external.name:foo", "another.name:bar"); this.context.register(FurtherExampleConfig.class); this.context.refresh(); assertEquals("foo", this.context.getBean(External.class).getName()); diff --git a/spring-boot/src/test/java/org/springframework/boot/test/SpringBootTestUtils.java b/spring-boot/src/test/java/org/springframework/boot/test/SpringBootTestUtils.java index 163844ad95..51c6470ec0 100644 --- a/spring-boot/src/test/java/org/springframework/boot/test/SpringBootTestUtils.java +++ b/spring-boot/src/test/java/org/springframework/boot/test/SpringBootTestUtils.java @@ -30,7 +30,7 @@ import org.springframework.core.env.MapPropertySource; */ public abstract class SpringBootTestUtils { - public static void addEnviroment(ConfigurableApplicationContext context, + public static void addEnvironment(ConfigurableApplicationContext context, String... pairs) { addEnviroment(context.getEnvironment(), pairs); }