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
pull/208/head
Dave Syer 11 years ago
parent 7d846c835a
commit 478e655758

@ -104,7 +104,7 @@ public class EndpointAutoConfigurationTests {
@Test @Test
public void testInfoEndpointConfiguration() throws Exception { public void testInfoEndpointConfiguration() throws Exception {
this.context = new AnnotationConfigApplicationContext(); 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.register(EndpointAutoConfiguration.class);
this.context.refresh(); this.context.refresh();
InfoEndpoint endpoint = this.context.getBean(InfoEndpoint.class); InfoEndpoint endpoint = this.context.getBean(InfoEndpoint.class);
@ -116,7 +116,7 @@ public class EndpointAutoConfigurationTests {
@Test @Test
public void testNoGitProperties() throws Exception { public void testNoGitProperties() throws Exception {
this.context = new AnnotationConfigApplicationContext(); this.context = new AnnotationConfigApplicationContext();
SpringBootTestUtils.addEnviroment(this.context, SpringBootTestUtils.addEnvironment(this.context,
"spring.git.properties:classpath:nonexistent"); "spring.git.properties:classpath:nonexistent");
this.context.register(EndpointAutoConfiguration.class); this.context.register(EndpointAutoConfiguration.class);
this.context.refresh(); this.context.refresh();

@ -121,7 +121,7 @@ public class EndpointWebMvcAutoConfigurationTests {
@Test @Test
public void specificPortsViaProperties() throws Exception { public void specificPortsViaProperties() throws Exception {
SpringBootTestUtils.addEnviroment(this.applicationContext, "server.port:7070", SpringBootTestUtils.addEnvironment(this.applicationContext, "server.port:7070",
"management.port:7071"); "management.port:7071");
this.applicationContext.register(RootConfig.class, this.applicationContext.register(RootConfig.class,
PropertyPlaceholderAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class,
@ -142,7 +142,7 @@ public class EndpointWebMvcAutoConfigurationTests {
@Test @Test
public void contextPath() throws Exception { public void contextPath() throws Exception {
SpringBootTestUtils.addEnviroment(this.applicationContext, "management.contextPath:/test"); SpringBootTestUtils.addEnvironment(this.applicationContext, "management.contextPath:/test");
this.applicationContext.register(RootConfig.class, this.applicationContext.register(RootConfig.class,
PropertyPlaceholderAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class,
ManagementServerPropertiesAutoConfiguration.class, ManagementServerPropertiesAutoConfiguration.class,

@ -65,7 +65,7 @@ public class JolokiaAutoConfigurationTests {
@Test @Test
public void agentDisabled() throws Exception { public void agentDisabled() throws Exception {
this.context = new AnnotationConfigEmbeddedWebApplicationContext(); 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, this.context.register(Config.class, WebMvcAutoConfiguration.class,
ManagementServerPropertiesAutoConfiguration.class, ManagementServerPropertiesAutoConfiguration.class,
HttpMessageConvertersAutoConfiguration.class, HttpMessageConvertersAutoConfiguration.class,

@ -117,7 +117,7 @@ public class ManagementSecurityAutoConfigurationTests {
EndpointAutoConfiguration.class, EndpointAutoConfiguration.class,
ManagementServerPropertiesAutoConfiguration.class, ManagementServerPropertiesAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class); PropertyPlaceholderAutoConfiguration.class);
SpringBootTestUtils.addEnviroment(this.context, "security.ignored:none"); SpringBootTestUtils.addEnvironment(this.context, "security.ignored:none");
this.context.refresh(); this.context.refresh();
// Just the application and management endpoints now // Just the application and management endpoints now
assertEquals(2, this.context.getBean(FilterChainProxy.class).getFilterChains() assertEquals(2, this.context.getBean(FilterChainProxy.class).getFilterChains()
@ -134,7 +134,7 @@ public class ManagementSecurityAutoConfigurationTests {
EndpointAutoConfiguration.class, EndpointWebMvcAutoConfiguration.class, EndpointAutoConfiguration.class, EndpointWebMvcAutoConfiguration.class,
ManagementServerPropertiesAutoConfiguration.class, ManagementServerPropertiesAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class); PropertyPlaceholderAutoConfiguration.class);
SpringBootTestUtils.addEnviroment(this.context, "security.basic.enabled:false"); SpringBootTestUtils.addEnvironment(this.context, "security.basic.enabled:false");
this.context.refresh(); this.context.refresh();
// Just the management endpoints (one filter) and ignores now // Just the management endpoints (one filter) and ignores now
assertEquals(7, this.context.getBean(FilterChainProxy.class).getFilterChains() assertEquals(7, this.context.getBean(FilterChainProxy.class).getFilterChains()
@ -171,7 +171,7 @@ public class ManagementSecurityAutoConfigurationTests {
private static AnnotationConfigWebApplicationContext debugRefresh( private static AnnotationConfigWebApplicationContext debugRefresh(
AnnotationConfigWebApplicationContext context) { AnnotationConfigWebApplicationContext context) {
SpringBootTestUtils.addEnviroment(context, "debug:true"); SpringBootTestUtils.addEnvironment(context, "debug:true");
LoggingApplicationListener logging = new LoggingApplicationListener(); LoggingApplicationListener logging = new LoggingApplicationListener();
logging.onApplicationEvent(new SpringApplicationBeforeRefreshEvent( logging.onApplicationEvent(new SpringApplicationBeforeRefreshEvent(
new SpringApplication(), context, new String[0])); new SpringApplication(), context, new String[0]));

@ -84,7 +84,7 @@ public abstract class AbstractEndpointTests<T extends Endpoint<?>> {
@Test @Test
public void idOverride() throws Exception { public void idOverride() throws Exception {
this.context = new AnnotationConfigApplicationContext(); 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.register(this.configClass);
this.context.refresh(); this.context.refresh();
assertThat(getEndpointBean().getId(), equalTo("myid")); assertThat(getEndpointBean().getId(), equalTo("myid"));

@ -59,7 +59,7 @@ public class EnvironmentMvcEndpointTests {
@Before @Before
public void setUp() { public void setUp() {
this.mvc = MockMvcBuilders.webAppContextSetup(this.context).build(); this.mvc = MockMvcBuilders.webAppContextSetup(this.context).build();
SpringBootTestUtils.addEnviroment((ConfigurableApplicationContext) this.context, "foo:bar"); SpringBootTestUtils.addEnvironment((ConfigurableApplicationContext) this.context, "foo:bar");
} }
@Test @Test

@ -66,7 +66,7 @@ public class JolokiaEndpointTests {
@Before @Before
public void setUp() { public void setUp() {
this.mvc = MockMvcBuilders.webAppContextSetup(this.context).build(); this.mvc = MockMvcBuilders.webAppContextSetup(this.context).build();
SpringBootTestUtils.addEnviroment((ConfigurableApplicationContext) this.context, "foo:bar"); SpringBootTestUtils.addEnvironment((ConfigurableApplicationContext) this.context, "foo:bar");
} }
@Test @Test

@ -48,7 +48,7 @@ public class PropertyPlaceholderAutoConfigurationTests {
public void propertyPlaceholderse() throws Exception { public void propertyPlaceholderse() throws Exception {
this.context.register(PropertyPlaceholderAutoConfiguration.class, this.context.register(PropertyPlaceholderAutoConfiguration.class,
PlaceholderConfig.class); PlaceholderConfig.class);
SpringBootTestUtils.addEnviroment(this.context, "foo:two"); SpringBootTestUtils.addEnvironment(this.context, "foo:two");
this.context.refresh(); this.context.refresh();
assertEquals("two", this.context.getBean(PlaceholderConfig.class).getFoo()); assertEquals("two", this.context.getBean(PlaceholderConfig.class).getFoo());
} }
@ -57,7 +57,7 @@ public class PropertyPlaceholderAutoConfigurationTests {
public void propertyPlaceholdersOverride() throws Exception { public void propertyPlaceholdersOverride() throws Exception {
this.context.register(PropertyPlaceholderAutoConfiguration.class, this.context.register(PropertyPlaceholderAutoConfiguration.class,
PlaceholderConfig.class, PlaceholdersOverride.class); PlaceholderConfig.class, PlaceholdersOverride.class);
SpringBootTestUtils.addEnviroment(this.context, "foo:two"); SpringBootTestUtils.addEnvironment(this.context, "foo:two");
this.context.refresh(); this.context.refresh();
assertEquals("spam", this.context.getBean(PlaceholderConfig.class).getFoo()); assertEquals("spam", this.context.getBean(PlaceholderConfig.class).getFoo());
} }

@ -65,7 +65,7 @@ public class RabbitAutoconfigurationTests {
public void testRabbitTemplateWithOverrides() { public void testRabbitTemplateWithOverrides() {
this.context = new AnnotationConfigApplicationContext(); this.context = new AnnotationConfigApplicationContext();
this.context.register(TestConfiguration.class, RabbitAutoConfiguration.class); 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.port:9000", "spring.rabbitmq.username:alice",
"spring.rabbitmq.password:secret", "spring.rabbitmq.virtual_host:/vhost"); "spring.rabbitmq.password:secret", "spring.rabbitmq.virtual_host:/vhost");
this.context.refresh(); this.context.refresh();
@ -80,7 +80,7 @@ public class RabbitAutoconfigurationTests {
public void testRabbitTemplateEmptyVirtualHost() { public void testRabbitTemplateEmptyVirtualHost() {
this.context = new AnnotationConfigApplicationContext(); this.context = new AnnotationConfigApplicationContext();
this.context.register(TestConfiguration.class, RabbitAutoConfiguration.class); 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(); this.context.refresh();
CachingConnectionFactory connectionFactory = this.context CachingConnectionFactory connectionFactory = this.context
.getBean(CachingConnectionFactory.class); .getBean(CachingConnectionFactory.class);
@ -91,7 +91,7 @@ public class RabbitAutoconfigurationTests {
public void testRabbitTemplateVirtualHostMissingSlash() { public void testRabbitTemplateVirtualHostMissingSlash() {
this.context = new AnnotationConfigApplicationContext(); this.context = new AnnotationConfigApplicationContext();
this.context.register(TestConfiguration.class, RabbitAutoConfiguration.class); 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(); this.context.refresh();
CachingConnectionFactory connectionFactory = this.context CachingConnectionFactory connectionFactory = this.context
.getBean(CachingConnectionFactory.class); .getBean(CachingConnectionFactory.class);
@ -102,7 +102,7 @@ public class RabbitAutoconfigurationTests {
public void testRabbitTemplateDefaultVirtualHost() { public void testRabbitTemplateDefaultVirtualHost() {
this.context = new AnnotationConfigApplicationContext(); this.context = new AnnotationConfigApplicationContext();
this.context.register(TestConfiguration.class, RabbitAutoConfiguration.class); 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(); this.context.refresh();
CachingConnectionFactory connectionFactory = this.context CachingConnectionFactory connectionFactory = this.context
.getBean(CachingConnectionFactory.class); .getBean(CachingConnectionFactory.class);
@ -126,7 +126,7 @@ public class RabbitAutoconfigurationTests {
public void testStaticQueues() { public void testStaticQueues() {
this.context = new AnnotationConfigApplicationContext(); this.context = new AnnotationConfigApplicationContext();
this.context.register(TestConfiguration.class, RabbitAutoConfiguration.class); 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(); this.context.refresh();
// There should NOT be an AmqpAdmin bean when dynamic is switch to false // There should NOT be an AmqpAdmin bean when dynamic is switch to false
this.thrown.expect(NoSuchBeanDefinitionException.class); this.thrown.expect(NoSuchBeanDefinitionException.class);

@ -42,7 +42,7 @@ public class AopAutoConfigurationTests {
this.context = new AnnotationConfigApplicationContext(); this.context = new AnnotationConfigApplicationContext();
this.context.register(TestConfiguration.class, AopAutoConfiguration.class, this.context.register(TestConfiguration.class, AopAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class); PropertyPlaceholderAutoConfiguration.class);
SpringBootTestUtils.addEnviroment(this.context, "spring.aop.auto:false"); SpringBootTestUtils.addEnvironment(this.context, "spring.aop.auto:false");
this.context.refresh(); this.context.refresh();
TestAspect aspect = this.context.getBean(TestAspect.class); TestAspect aspect = this.context.getBean(TestAspect.class);
assertFalse(aspect.isCalled()); assertFalse(aspect.isCalled());
@ -56,7 +56,7 @@ public class AopAutoConfigurationTests {
this.context = new AnnotationConfigApplicationContext(); this.context = new AnnotationConfigApplicationContext();
this.context.register(TestConfiguration.class, AopAutoConfiguration.class, this.context.register(TestConfiguration.class, AopAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class); PropertyPlaceholderAutoConfiguration.class);
SpringBootTestUtils.addEnviroment(this.context, "spring.aop.proxyTargetClass:true"); SpringBootTestUtils.addEnvironment(this.context, "spring.aop.proxyTargetClass:true");
this.context.refresh(); this.context.refresh();
TestAspect aspect = this.context.getBean(TestAspect.class); TestAspect aspect = this.context.getBean(TestAspect.class);
assertFalse(aspect.isCalled()); assertFalse(aspect.isCalled());
@ -70,7 +70,7 @@ public class AopAutoConfigurationTests {
this.context = new AnnotationConfigApplicationContext(); this.context = new AnnotationConfigApplicationContext();
this.context.register(TestConfiguration.class, AopAutoConfiguration.class, this.context.register(TestConfiguration.class, AopAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class); PropertyPlaceholderAutoConfiguration.class);
SpringBootTestUtils.addEnviroment(this.context, "spring.aop.proxyTargetClass:false"); SpringBootTestUtils.addEnvironment(this.context, "spring.aop.proxyTargetClass:false");
this.context.refresh(); this.context.refresh();
TestAspect aspect = this.context.getBean(TestAspect.class); TestAspect aspect = this.context.getBean(TestAspect.class);
assertFalse(aspect.isCalled()); assertFalse(aspect.isCalled());

@ -105,7 +105,7 @@ public class BatchAutoConfigurationTests {
@Test @Test
public void testDisableLaunchesJob() throws Exception { public void testDisableLaunchesJob() throws Exception {
this.context = new AnnotationConfigApplicationContext(); 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, this.context.register(JobConfiguration.class, BatchAutoConfiguration.class,
EmbeddedDataSourceConfiguration.class, EmbeddedDataSourceConfiguration.class,
PropertyPlaceholderAutoConfiguration.class); PropertyPlaceholderAutoConfiguration.class);
@ -117,7 +117,7 @@ public class BatchAutoConfigurationTests {
@Test @Test
public void testDisableSchemaLoader() throws Exception { public void testDisableSchemaLoader() throws Exception {
this.context = new AnnotationConfigApplicationContext(); 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"); "spring.batch.initializer.enabled:false");
this.context.register(TestConfiguration.class, BatchAutoConfiguration.class, this.context.register(TestConfiguration.class, BatchAutoConfiguration.class,
EmbeddedDataSourceConfiguration.class, EmbeddedDataSourceConfiguration.class,

@ -66,7 +66,7 @@ public class DataSourceAutoConfigurationTests {
@Test @Test
public void testEmbeddedTypeDefaultsUsername() throws Exception { public void testEmbeddedTypeDefaultsUsername() throws Exception {
SpringBootTestUtils.addEnviroment(this.context, SpringBootTestUtils.addEnvironment(this.context,
"spring.datasource.driverClassName:org.hsqldb.jdbcDriver", "spring.datasource.driverClassName:org.hsqldb.jdbcDriver",
"spring.datasource.url:jdbc:hsqldb:mem:testdb"); "spring.datasource.url:jdbc:hsqldb:mem:testdb");
this.context.register(DataSourceAutoConfiguration.class, this.context.register(DataSourceAutoConfiguration.class,
@ -82,7 +82,7 @@ public class DataSourceAutoConfigurationTests {
@Test @Test
public void testExplicitDriverClassClearsUserName() throws Exception { public void testExplicitDriverClassClearsUserName() throws Exception {
SpringBootTestUtils SpringBootTestUtils
.addEnviroment( .addEnvironment(
this.context, this.context,
"spring.datasource.driverClassName:org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfigurationTests$DatabaseDriver", "spring.datasource.driverClassName:org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfigurationTests$DatabaseDriver",
"spring.datasource.url:jdbc:foo://localhost", "spring.datasource.url:jdbc:foo://localhost",

@ -56,7 +56,7 @@ public class TomcatDataSourceConfigurationTests {
@Test @Test
public void testDataSourcePropertiesOverridden() throws Exception { public void testDataSourcePropertiesOverridden() throws Exception {
this.context.register(TomcatDataSourceConfiguration.class); 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(); this.context.refresh();
assertEquals("jdbc:foo//bar/spam", assertEquals("jdbc:foo//bar/spam",
this.context.getBean(org.apache.tomcat.jdbc.pool.DataSource.class) this.context.getBean(org.apache.tomcat.jdbc.pool.DataSource.class)

@ -118,7 +118,7 @@ public class JmsTemplateAutoConfigurationTests {
this.context = new AnnotationConfigApplicationContext(); this.context = new AnnotationConfigApplicationContext();
this.context this.context
.register(TestConfiguration.class, JmsTemplateAutoConfiguration.class); .register(TestConfiguration.class, JmsTemplateAutoConfiguration.class);
SpringBootTestUtils.addEnviroment(this.context, "spring.jms.pubSubDomain:false"); SpringBootTestUtils.addEnvironment(this.context, "spring.jms.pubSubDomain:false");
this.context.refresh(); 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
@ -134,7 +134,7 @@ public class JmsTemplateAutoConfigurationTests {
this.context = new AnnotationConfigApplicationContext(); this.context = new AnnotationConfigApplicationContext();
this.context this.context
.register(TestConfiguration.class, JmsTemplateAutoConfiguration.class); .register(TestConfiguration.class, JmsTemplateAutoConfiguration.class);
SpringBootTestUtils.addEnviroment(this.context, "spring.activemq.inMemory:false"); SpringBootTestUtils.addEnvironment(this.context, "spring.activemq.inMemory:false");
this.context.refresh(); 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
@ -153,7 +153,7 @@ public class JmsTemplateAutoConfigurationTests {
this.context = new AnnotationConfigApplicationContext(); this.context = new AnnotationConfigApplicationContext();
this.context this.context
.register(TestConfiguration.class, JmsTemplateAutoConfiguration.class); .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"); "spring.activemq.brokerURL:tcp://remote-host:10000");
this.context.refresh(); this.context.refresh();
JmsTemplate jmsTemplate = this.context.getBean(JmsTemplate.class); JmsTemplate jmsTemplate = this.context.getBean(JmsTemplate.class);
@ -173,7 +173,7 @@ public class JmsTemplateAutoConfigurationTests {
this.context = new AnnotationConfigApplicationContext(); this.context = new AnnotationConfigApplicationContext();
this.context this.context
.register(TestConfiguration.class, JmsTemplateAutoConfiguration.class); .register(TestConfiguration.class, JmsTemplateAutoConfiguration.class);
SpringBootTestUtils.addEnviroment(this.context, "spring.activemq.pooled:true"); SpringBootTestUtils.addEnvironment(this.context, "spring.activemq.pooled:true");
this.context.refresh(); 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
@ -191,7 +191,7 @@ public class JmsTemplateAutoConfigurationTests {
this.context = new AnnotationConfigApplicationContext(); this.context = new AnnotationConfigApplicationContext();
this.context this.context
.register(TestConfiguration.class, JmsTemplateAutoConfiguration.class); .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.inMemory:false");
this.context.refresh(); this.context.refresh();
JmsTemplate jmsTemplate = this.context.getBean(JmsTemplate.class); JmsTemplate jmsTemplate = this.context.getBean(JmsTemplate.class);
@ -210,7 +210,7 @@ public class JmsTemplateAutoConfigurationTests {
this.context = new AnnotationConfigApplicationContext(); this.context = new AnnotationConfigApplicationContext();
this.context this.context
.register(TestConfiguration.class, JmsTemplateAutoConfiguration.class); .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.inMemory:false",
"spring.activemq.brokerURL:tcp://remote-host:10000"); "spring.activemq.brokerURL:tcp://remote-host:10000");
this.context.refresh(); this.context.refresh();

@ -112,7 +112,7 @@ public abstract class AbstractJpaAutoConfigurationTests {
public void testOpenEntityManagerInViewInterceptorNotRegisteredWhenExplicitlyOff() public void testOpenEntityManagerInViewInterceptorNotRegisteredWhenExplicitlyOff()
throws Exception { throws Exception {
AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext(); 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, context.register(TestConfiguration.class,
ComponentScanDetectorConfiguration.class, ComponentScanDetectorConfiguration.class,
EmbeddedDataSourceConfiguration.class, EmbeddedDataSourceConfiguration.class,
@ -124,7 +124,7 @@ public abstract class AbstractJpaAutoConfigurationTests {
@Test @Test
public void customJpaProperties() throws Exception { 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"); "spring.jpa.properties.c:d");
setupTestConfiguration(); setupTestConfiguration();
this.context.refresh(); this.context.refresh();

@ -38,7 +38,7 @@ public class HibernateJpaAutoConfigurationTests extends AbstractJpaAutoConfigura
@Test @Test
public void testCustomNamingStrategy() throws Exception { 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"); + "org.hibernate.cfg.EJB3NamingStrategy");
setupTestConfiguration(); setupTestConfiguration();
this.context.refresh(); this.context.refresh();

@ -47,7 +47,7 @@ public class RedisAutoConfigurationTests {
@Test @Test
public void testOverrideRedisConfiguration() throws Exception { public void testOverrideRedisConfiguration() throws Exception {
this.context = new AnnotationConfigApplicationContext(); 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, this.context.register(RedisAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class); PropertyPlaceholderAutoConfiguration.class);
this.context.refresh(); this.context.refresh();

@ -72,7 +72,7 @@ public class SecurityAutoConfigurationTests {
this.context.setServletContext(new MockServletContext()); this.context.setServletContext(new MockServletContext());
this.context.register(SecurityAutoConfiguration.class, this.context.register(SecurityAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class); PropertyPlaceholderAutoConfiguration.class);
SpringBootTestUtils.addEnviroment(this.context, "security.ignored:none"); SpringBootTestUtils.addEnvironment(this.context, "security.ignored:none");
this.context.refresh(); this.context.refresh();
// Just the application endpoints now // Just the application endpoints now
assertEquals(1, this.context.getBean(FilterChainProxy.class).getFilterChains() assertEquals(1, this.context.getBean(FilterChainProxy.class).getFilterChains()
@ -85,7 +85,7 @@ public class SecurityAutoConfigurationTests {
this.context.setServletContext(new MockServletContext()); this.context.setServletContext(new MockServletContext());
this.context.register(SecurityAutoConfiguration.class, this.context.register(SecurityAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class); PropertyPlaceholderAutoConfiguration.class);
SpringBootTestUtils.addEnviroment(this.context, "security.basic.enabled:false"); SpringBootTestUtils.addEnvironment(this.context, "security.basic.enabled:false");
this.context.refresh(); this.context.refresh();
// No security at all not even ignores // No security at all not even ignores
assertEquals(0, this.context.getBeanNamesForType(FilterChainProxy.class).length); assertEquals(0, this.context.getBeanNamesForType(FilterChainProxy.class).length);
@ -118,7 +118,7 @@ public class SecurityAutoConfigurationTests {
private static AnnotationConfigWebApplicationContext debugRefresh( private static AnnotationConfigWebApplicationContext debugRefresh(
AnnotationConfigWebApplicationContext context) { AnnotationConfigWebApplicationContext context) {
SpringBootTestUtils.addEnviroment(context, "debug:true"); SpringBootTestUtils.addEnvironment(context, "debug:true");
LoggingApplicationListener logging = new LoggingApplicationListener(); LoggingApplicationListener logging = new LoggingApplicationListener();
logging.onApplicationEvent(new SpringApplicationBeforeRefreshEvent( logging.onApplicationEvent(new SpringApplicationBeforeRefreshEvent(
new SpringApplication(), context, new String[0])); new SpringApplication(), context, new String[0]));

@ -72,7 +72,7 @@ public class ServerPropertiesAutoConfigurationTests {
this.context = new AnnotationConfigEmbeddedWebApplicationContext(); this.context = new AnnotationConfigEmbeddedWebApplicationContext();
this.context.register(Config.class, ServerPropertiesAutoConfiguration.class, this.context.register(Config.class, ServerPropertiesAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class); PropertyPlaceholderAutoConfiguration.class);
SpringBootTestUtils.addEnviroment(this.context, "server.port:9000"); SpringBootTestUtils.addEnvironment(this.context, "server.port:9000");
this.context.refresh(); this.context.refresh();
ServerProperties server = this.context.getBean(ServerProperties.class); ServerProperties server = this.context.getBean(ServerProperties.class);
assertNotNull(server); assertNotNull(server);
@ -86,7 +86,7 @@ public class ServerPropertiesAutoConfigurationTests {
this.context = new AnnotationConfigEmbeddedWebApplicationContext(); this.context = new AnnotationConfigEmbeddedWebApplicationContext();
this.context.register(Config.class, ServerPropertiesAutoConfiguration.class, this.context.register(Config.class, ServerPropertiesAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class); PropertyPlaceholderAutoConfiguration.class);
SpringBootTestUtils.addEnviroment(this.context, "server.tomcat.basedir:target/foo", SpringBootTestUtils.addEnvironment(this.context, "server.tomcat.basedir:target/foo",
"server.port:9000"); "server.port:9000");
this.context.refresh(); this.context.refresh();
ServerProperties server = this.context.getBean(ServerProperties.class); ServerProperties server = this.context.getBean(ServerProperties.class);

@ -187,13 +187,26 @@ public class ConfigFileApplicationListener implements
PropertySource<?> removed = environment.getPropertySources().remove( PropertySource<?> removed = environment.getPropertySources().remove(
"defaultProperties"); "defaultProperties");
List<PropertySource<?>> sources = new ArrayList<PropertySource<?>>(); String first = null;
// Initial load allows profiles to be activated // Initial load allows profiles to be activated
for (String candidate : candidates) { for (String candidate : candidates) {
PropertySource<?> source = load(environment, resourceLoader, candidate, null); PropertySource<?> source = load(environment, resourceLoader, candidate, null);
if (source != null) { if (source != null) {
sources.add(source); if (first == null) {
first = source.getName();
} }
environment.getPropertySources().addLast(source);
}
}
if (environment.containsProperty("spring.profiles.active")) {
Set<String> 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 // Second load for specific profiles
@ -202,14 +215,16 @@ public class ConfigFileApplicationListener implements
PropertySource<?> source = load(environment, resourceLoader, candidate, PropertySource<?> source = load(environment, resourceLoader, candidate,
profile); profile);
if (source != null) { if (source != null) {
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); 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) { if (removed != null) {
@ -277,15 +292,6 @@ public class ConfigFileApplicationListener implements
if (propertySource == null) { if (propertySource == null) {
return null; return null;
} }
if (propertySource.containsProperty("spring.profiles.active")) {
Set<String> 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; return propertySource;
} }

@ -42,7 +42,7 @@ public class ContextIdApplicationContextInitializerTests {
@Test @Test
public void testNameAndPort() { public void testNameAndPort() {
ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(); 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); this.initializer.initialize(context);
assertEquals("foo:8080", context.getId()); assertEquals("foo:8080", context.getId());
} }
@ -50,7 +50,7 @@ public class ContextIdApplicationContextInitializerTests {
@Test @Test
public void testNameAndProfiles() { public void testNameAndProfiles() {
ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(); 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"); "spring.profiles.active: spam,bar", "spring.application.index:12");
this.initializer.initialize(context); this.initializer.initialize(context);
assertEquals("foo:spam,bar:12", context.getId()); assertEquals("foo:spam,bar:12", context.getId());
@ -59,7 +59,7 @@ public class ContextIdApplicationContextInitializerTests {
@Test @Test
public void testCloudFoundry() { public void testCloudFoundry() {
ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(); 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"); "vcap.application.name:bar", "vcap.application.instance_index:2");
this.initializer.initialize(context); this.initializer.initialize(context);
assertEquals("bar:2", context.getId()); assertEquals("bar:2", context.getId());
@ -68,7 +68,7 @@ public class ContextIdApplicationContextInitializerTests {
@Test @Test
public void testExplicitName() { public void testExplicitName() {
ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(); 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", "spring.config.name:foo", "PORT:8080", "vcap.application.name:bar",
"vcap.application.instance_index:2"); "vcap.application.instance_index:2");
this.initializer.initialize(context); this.initializer.initialize(context);

@ -46,7 +46,7 @@ public class EnvironmentDelegateApplicationContextInitializerTests {
@Test @Test
public void orderedInitialize() throws Exception { public void orderedInitialize() throws Exception {
StaticApplicationContext context = new StaticApplicationContext(); StaticApplicationContext context = new StaticApplicationContext();
SpringBootTestUtils.addEnviroment(context, SpringBootTestUtils.addEnvironment(context,
"context.initializer.classes:" + MockInitB.class.getName() + "," "context.initializer.classes:" + MockInitB.class.getName() + ","
+ MockInitA.class.getName()); + MockInitA.class.getName());
this.initializer.initialize(context); this.initializer.initialize(context);
@ -63,14 +63,14 @@ public class EnvironmentDelegateApplicationContextInitializerTests {
@Test @Test
public void emptyInitializers() throws Exception { public void emptyInitializers() throws Exception {
StaticApplicationContext context = new StaticApplicationContext(); StaticApplicationContext context = new StaticApplicationContext();
SpringBootTestUtils.addEnviroment(context, "context.initializer.classes:"); SpringBootTestUtils.addEnvironment(context, "context.initializer.classes:");
this.initializer.initialize(context); this.initializer.initialize(context);
} }
@Test @Test
public void noSuchInitializerClass() throws Exception { public void noSuchInitializerClass() throws Exception {
StaticApplicationContext context = new StaticApplicationContext(); StaticApplicationContext context = new StaticApplicationContext();
SpringBootTestUtils.addEnviroment(context, SpringBootTestUtils.addEnvironment(context,
"context.initializer.classes:missing.madeup.class"); "context.initializer.classes:missing.madeup.class");
this.thrown.expect(ApplicationContextException.class); this.thrown.expect(ApplicationContextException.class);
this.initializer.initialize(context); this.initializer.initialize(context);
@ -79,7 +79,7 @@ public class EnvironmentDelegateApplicationContextInitializerTests {
@Test @Test
public void notAnInitializerClass() throws Exception { public void notAnInitializerClass() throws Exception {
StaticApplicationContext context = new StaticApplicationContext(); StaticApplicationContext context = new StaticApplicationContext();
SpringBootTestUtils.addEnviroment(context, SpringBootTestUtils.addEnvironment(context,
"context.initializer.classes:" + Object.class.getName()); "context.initializer.classes:" + Object.class.getName());
this.thrown.expect(IllegalArgumentException.class); this.thrown.expect(IllegalArgumentException.class);
this.initializer.initialize(context); this.initializer.initialize(context);
@ -88,7 +88,7 @@ public class EnvironmentDelegateApplicationContextInitializerTests {
@Test @Test
public void genericNotSuitable() throws Exception { public void genericNotSuitable() throws Exception {
StaticApplicationContext context = new StaticApplicationContext(); StaticApplicationContext context = new StaticApplicationContext();
SpringBootTestUtils.addEnviroment(context, "context.initializer.classes:" SpringBootTestUtils.addEnvironment(context, "context.initializer.classes:"
+ NotSuitableInit.class.getName()); + NotSuitableInit.class.getName());
this.thrown.expect(IllegalArgumentException.class); this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage("generic parameter"); this.thrown.expectMessage("generic parameter");

@ -16,6 +16,7 @@
package org.springframework.boot.context.listener; package org.springframework.boot.context.listener;
import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -23,7 +24,7 @@ import org.junit.After;
import org.junit.Test; import org.junit.Test;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.SpringApplicationEnvironmentAvailableEvent; 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.ConfigurableApplicationContext;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile; 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.SimpleCommandLinePropertySource;
import org.springframework.core.env.StandardEnvironment; import org.springframework.core.env.StandardEnvironment;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.notNullValue; import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue; import static org.hamcrest.Matchers.nullValue;
@ -143,9 +145,20 @@ public class ConfigFileApplicationListenerTests {
this.initializer.setNames("testsetprofiles"); this.initializer.setNames("testsetprofiles");
this.initializer.onApplicationEvent(this.event); this.initializer.onApplicationEvent(this.event);
String property = this.environment.getProperty("my.property"); String property = this.environment.getProperty("my.property");
assertThat(Arrays.asList(this.environment.getActiveProfiles()), contains("dev"));
assertThat(property, equalTo("fromdevprofile")); 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 @Test
public void specificNameAndProfileFromExistingSource() throws Exception { public void specificNameAndProfileFromExistingSource() throws Exception {
Map<String, Object> map = new HashMap<String, Object>(); Map<String, Object> map = new HashMap<String, Object>();

@ -51,7 +51,7 @@ public class EnvironmentDelegateApplicationListenerTests {
@Test @Test
public void orderedInitialize() throws Exception { 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()); + MockInitB.class.getName() + "," + MockInitA.class.getName());
this.listener.onApplicationEvent(new SpringApplicationEnvironmentAvailableEvent( this.listener.onApplicationEvent(new SpringApplicationEnvironmentAvailableEvent(
new SpringApplication(), this.context.getEnvironment(), new String[0])); new SpringApplication(), this.context.getEnvironment(), new String[0]));
@ -69,7 +69,7 @@ public class EnvironmentDelegateApplicationListenerTests {
@Test @Test
public void emptyInitializers() throws Exception { public void emptyInitializers() throws Exception {
SpringBootTestUtils.addEnviroment(this.context, "context.listener.classes:"); SpringBootTestUtils.addEnvironment(this.context, "context.listener.classes:");
this.listener.onApplicationEvent(new SpringApplicationEnvironmentAvailableEvent( this.listener.onApplicationEvent(new SpringApplicationEnvironmentAvailableEvent(
new SpringApplication(), this.context.getEnvironment(), new String[0])); new SpringApplication(), this.context.getEnvironment(), new String[0]));
} }

@ -95,7 +95,7 @@ public class LoggingApplicationListenerTests {
@Test @Test
public void testOverrideConfigLocation() { public void testOverrideConfigLocation() {
SpringBootTestUtils.addEnviroment(this.context, SpringBootTestUtils.addEnvironment(this.context,
"logging.config: classpath:logback-nondefault.xml"); "logging.config: classpath:logback-nondefault.xml");
this.initializer.initialize(this.context.getEnvironment(), this.initializer.initialize(this.context.getEnvironment(),
this.context.getClassLoader()); this.context.getClassLoader());
@ -108,7 +108,7 @@ public class LoggingApplicationListenerTests {
@Test @Test
public void testOverrideConfigDoesNotExist() throws Exception { 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.initializer.initialize(this.context.getEnvironment(),
this.context.getClassLoader()); this.context.getClassLoader());
// Should not throw // Should not throw
@ -116,7 +116,7 @@ public class LoggingApplicationListenerTests {
@Test @Test
public void testAddLogFileProperty() { public void testAddLogFileProperty() {
SpringBootTestUtils.addEnviroment(this.context, SpringBootTestUtils.addEnvironment(this.context,
"logging.config: classpath:logback-nondefault.xml", "logging.config: classpath:logback-nondefault.xml",
"logging.file: foo.log"); "logging.file: foo.log");
this.initializer.initialize(this.context.getEnvironment(), this.initializer.initialize(this.context.getEnvironment(),
@ -129,7 +129,7 @@ public class LoggingApplicationListenerTests {
@Test @Test
public void testAddLogPathProperty() { public void testAddLogPathProperty() {
SpringBootTestUtils.addEnviroment(this.context, SpringBootTestUtils.addEnvironment(this.context,
"logging.config: classpath:logback-nondefault.xml", "logging.path: foo/"); "logging.config: classpath:logback-nondefault.xml", "logging.path: foo/");
this.initializer.initialize(this.context.getEnvironment(), this.initializer.initialize(this.context.getEnvironment(),
this.context.getClassLoader()); this.context.getClassLoader());
@ -141,7 +141,7 @@ public class LoggingApplicationListenerTests {
@Test @Test
public void parseDebugArg() throws Exception { public void parseDebugArg() throws Exception {
SpringBootTestUtils.addEnviroment(this.context, "debug"); SpringBootTestUtils.addEnvironment(this.context, "debug");
this.initializer.initialize(this.context.getEnvironment(), this.initializer.initialize(this.context.getEnvironment(),
this.context.getClassLoader()); this.context.getClassLoader());
this.logger.debug("testatdebug"); this.logger.debug("testatdebug");
@ -152,7 +152,7 @@ public class LoggingApplicationListenerTests {
@Test @Test
public void parseTraceArg() throws Exception { public void parseTraceArg() throws Exception {
SpringBootTestUtils.addEnviroment(this.context, "trace"); SpringBootTestUtils.addEnvironment(this.context, "trace");
this.initializer.initialize(this.context.getEnvironment(), this.initializer.initialize(this.context.getEnvironment(),
this.context.getClassLoader()); this.context.getClassLoader());
this.logger.debug("testatdebug"); this.logger.debug("testatdebug");
@ -164,7 +164,7 @@ public class LoggingApplicationListenerTests {
@Test @Test
public void parseArgsDisabled() throws Exception { public void parseArgsDisabled() throws Exception {
this.initializer.setParseArgs(false); this.initializer.setParseArgs(false);
SpringBootTestUtils.addEnviroment(this.context, "debug"); SpringBootTestUtils.addEnvironment(this.context, "debug");
this.initializer.initialize(this.context.getEnvironment(), this.initializer.initialize(this.context.getEnvironment(),
this.context.getClassLoader()); this.context.getClassLoader());
this.logger.debug("testatdebug"); this.logger.debug("testatdebug");

@ -40,7 +40,7 @@ public class VcapApplicationListenerTests {
@Test @Test
public void testApplicationProperties() { public void testApplicationProperties() {
SpringBootTestUtils SpringBootTestUtils
.addEnviroment( .addEnvironment(
this.context, 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}"); "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); this.initializer.onApplicationEvent(this.event);
@ -50,7 +50,7 @@ public class VcapApplicationListenerTests {
@Test @Test
public void testUnparseableApplicationProperties() { public void testUnparseableApplicationProperties() {
SpringBootTestUtils.addEnviroment(this.context, "VCAP_APPLICATION:"); SpringBootTestUtils.addEnvironment(this.context, "VCAP_APPLICATION:");
this.initializer.onApplicationEvent(this.event); this.initializer.onApplicationEvent(this.event);
assertEquals(null, this.context.getEnvironment().getProperty("vcap")); assertEquals(null, this.context.getEnvironment().getProperty("vcap"));
} }
@ -58,7 +58,7 @@ public class VcapApplicationListenerTests {
@Test @Test
public void testNullApplicationProperties() { public void testNullApplicationProperties() {
SpringBootTestUtils SpringBootTestUtils
.addEnviroment( .addEnvironment(
this.context, 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}"); "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); this.initializer.onApplicationEvent(this.event);
@ -68,7 +68,7 @@ public class VcapApplicationListenerTests {
@Test @Test
public void testServiceProperties() { public void testServiceProperties() {
SpringBootTestUtils SpringBootTestUtils
.addEnviroment( .addEnvironment(
this.context, 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\"}}]}"); "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); this.initializer.onApplicationEvent(this.event);

@ -64,7 +64,7 @@ public class EnableConfigurationPropertiesTests {
@Test @Test
public void testBasicPropertiesBinding() { public void testBasicPropertiesBinding() {
this.context.register(TestConfiguration.class); this.context.register(TestConfiguration.class);
SpringBootTestUtils.addEnviroment(this.context, "name:foo"); SpringBootTestUtils.addEnvironment(this.context, "name:foo");
this.context.refresh(); this.context.refresh();
assertEquals(1, this.context.getBeanNamesForType(TestProperties.class).length); assertEquals(1, this.context.getBeanNamesForType(TestProperties.class).length);
assertEquals("foo", this.context.getBean(TestProperties.class).name); assertEquals("foo", this.context.getBean(TestProperties.class).name);
@ -105,7 +105,7 @@ public class EnableConfigurationPropertiesTests {
public void testStrictPropertiesBinding() { public void testStrictPropertiesBinding() {
removeSystemProperties(); removeSystemProperties();
this.context.register(StrictTestConfiguration.class); this.context.register(StrictTestConfiguration.class);
SpringBootTestUtils.addEnviroment(this.context, "name:foo"); SpringBootTestUtils.addEnvironment(this.context, "name:foo");
this.context.refresh(); this.context.refresh();
assertEquals(1, assertEquals(1,
this.context.getBeanNamesForType(StrictTestProperties.class).length); this.context.getBeanNamesForType(StrictTestProperties.class).length);
@ -115,7 +115,7 @@ public class EnableConfigurationPropertiesTests {
@Test @Test
public void testPropertiesEmbeddedBinding() { public void testPropertiesEmbeddedBinding() {
this.context.register(EmbeddedTestConfiguration.class); this.context.register(EmbeddedTestConfiguration.class);
SpringBootTestUtils.addEnviroment(this.context, "spring_foo_name:foo"); SpringBootTestUtils.addEnvironment(this.context, "spring_foo_name:foo");
this.context.refresh(); this.context.refresh();
assertEquals(1, assertEquals(1,
this.context.getBeanNamesForType(EmbeddedTestProperties.class).length); this.context.getBeanNamesForType(EmbeddedTestProperties.class).length);
@ -126,7 +126,7 @@ public class EnableConfigurationPropertiesTests {
public void testIgnoreNestedPropertiesBinding() { public void testIgnoreNestedPropertiesBinding() {
removeSystemProperties(); removeSystemProperties();
this.context.register(IgnoreNestedTestConfiguration.class); 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(); this.context.refresh();
assertEquals(1, assertEquals(1,
this.context.getBeanNamesForType(IgnoreNestedTestProperties.class).length); this.context.getBeanNamesForType(IgnoreNestedTestProperties.class).length);
@ -136,7 +136,7 @@ public class EnableConfigurationPropertiesTests {
@Test @Test
public void testExceptionOnValidation() { public void testExceptionOnValidation() {
this.context.register(ExceptionIfInvalidTestConfiguration.class); this.context.register(ExceptionIfInvalidTestConfiguration.class);
SpringBootTestUtils.addEnviroment(this.context, "name:foo"); SpringBootTestUtils.addEnvironment(this.context, "name:foo");
this.expected.expectCause(Matchers.<Throwable> instanceOf(BindException.class)); this.expected.expectCause(Matchers.<Throwable> instanceOf(BindException.class));
this.context.refresh(); this.context.refresh();
} }
@ -144,7 +144,7 @@ public class EnableConfigurationPropertiesTests {
@Test @Test
public void testNoExceptionOnValidation() { public void testNoExceptionOnValidation() {
this.context.register(NoExceptionIfInvalidTestConfiguration.class); this.context.register(NoExceptionIfInvalidTestConfiguration.class);
SpringBootTestUtils.addEnviroment(this.context, "name:foo"); SpringBootTestUtils.addEnvironment(this.context, "name:foo");
this.context.refresh(); this.context.refresh();
assertEquals( assertEquals(
1, 1,
@ -156,7 +156,7 @@ public class EnableConfigurationPropertiesTests {
@Test @Test
public void testNestedPropertiesBinding() { public void testNestedPropertiesBinding() {
this.context.register(NestedConfiguration.class); 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(); this.context.refresh();
assertEquals(1, this.context.getBeanNamesForType(NestedProperties.class).length); assertEquals(1, this.context.getBeanNamesForType(NestedProperties.class).length);
assertEquals("foo", this.context.getBean(NestedProperties.class).name); assertEquals("foo", this.context.getBean(NestedProperties.class).name);
@ -166,7 +166,7 @@ public class EnableConfigurationPropertiesTests {
@Test @Test
public void testBasicPropertiesBindingWithAnnotationOnBaseClass() { public void testBasicPropertiesBindingWithAnnotationOnBaseClass() {
this.context.register(DerivedConfiguration.class); this.context.register(DerivedConfiguration.class);
SpringBootTestUtils.addEnviroment(this.context, "name:foo"); SpringBootTestUtils.addEnvironment(this.context, "name:foo");
this.context.refresh(); this.context.refresh();
assertEquals(1, this.context.getBeanNamesForType(DerivedProperties.class).length); assertEquals(1, this.context.getBeanNamesForType(DerivedProperties.class).length);
assertEquals("foo", this.context.getBean(BaseProperties.class).name); assertEquals("foo", this.context.getBean(BaseProperties.class).name);
@ -175,7 +175,7 @@ public class EnableConfigurationPropertiesTests {
@Test @Test
public void testArrayPropertiesBinding() { public void testArrayPropertiesBinding() {
this.context.register(TestConfiguration.class); 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(); this.context.refresh();
assertEquals(1, this.context.getBeanNamesForType(TestProperties.class).length); assertEquals(1, this.context.getBeanNamesForType(TestProperties.class).length);
assertEquals(3, this.context.getBean(TestProperties.class).getArray().length); assertEquals(3, this.context.getBean(TestProperties.class).getArray().length);
@ -184,7 +184,7 @@ public class EnableConfigurationPropertiesTests {
@Test @Test
public void testCollectionPropertiesBindingFromYamlArray() { public void testCollectionPropertiesBindingFromYamlArray() {
this.context.register(TestConfiguration.class); 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(); this.context.refresh();
assertEquals(2, this.context.getBean(TestProperties.class).getList().size()); assertEquals(2, this.context.getBean(TestProperties.class).getList().size());
} }
@ -192,7 +192,7 @@ public class EnableConfigurationPropertiesTests {
@Test @Test
public void testPropertiesBindingWithoutAnnotation() { public void testPropertiesBindingWithoutAnnotation() {
this.context.register(MoreConfiguration.class); this.context.register(MoreConfiguration.class);
SpringBootTestUtils.addEnviroment(this.context, "name:foo"); SpringBootTestUtils.addEnvironment(this.context, "name:foo");
this.context.refresh(); this.context.refresh();
assertEquals(1, this.context.getBeanNamesForType(MoreProperties.class).length); assertEquals(1, this.context.getBeanNamesForType(MoreProperties.class).length);
assertEquals("foo", this.context.getBean(MoreProperties.class).name); assertEquals("foo", this.context.getBean(MoreProperties.class).name);
@ -227,7 +227,7 @@ public class EnableConfigurationPropertiesTests {
@Test @Test
public void testBindingDirectlyToFileResolvedFromEnvironment() { 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.register(ResourceBindingProperties.class, TestConfiguration.class);
this.context.refresh(); this.context.refresh();
assertEquals(1, assertEquals(1,
@ -268,7 +268,7 @@ public class EnableConfigurationPropertiesTests {
AnnotationConfigApplicationContext parent = new AnnotationConfigApplicationContext(); AnnotationConfigApplicationContext parent = new AnnotationConfigApplicationContext();
parent.register(TestConfiguration.class); parent.register(TestConfiguration.class);
parent.refresh(); parent.refresh();
SpringBootTestUtils.addEnviroment(this.context, "name:foo"); SpringBootTestUtils.addEnvironment(this.context, "name:foo");
this.context.setParent(parent); this.context.setParent(parent);
this.context.register(TestConfiguration.class, TestConsumer.class); this.context.register(TestConfiguration.class, TestConsumer.class);
this.context.refresh(); this.context.refresh();
@ -280,7 +280,7 @@ public class EnableConfigurationPropertiesTests {
@Test @Test
public void testBindingOnlyParentContext() { public void testBindingOnlyParentContext() {
AnnotationConfigApplicationContext parent = new AnnotationConfigApplicationContext(); AnnotationConfigApplicationContext parent = new AnnotationConfigApplicationContext();
SpringBootTestUtils.addEnviroment(parent, "name:foo"); SpringBootTestUtils.addEnvironment(parent, "name:foo");
parent.register(TestConfiguration.class); parent.register(TestConfiguration.class);
parent.refresh(); parent.refresh();
this.context.setParent(parent); this.context.setParent(parent);
@ -293,7 +293,7 @@ public class EnableConfigurationPropertiesTests {
@Test @Test
public void testUnderscoresInPrefix() throws Exception { 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.register(SystemExampleConfig.class);
this.context.refresh(); this.context.refresh();
assertEquals("baz", this.context.getBean(SystemEnvVar.class).getVal()); assertEquals("baz", this.context.getBean(SystemEnvVar.class).getVal());
@ -301,7 +301,7 @@ public class EnableConfigurationPropertiesTests {
@Test @Test
public void testSimpleAutoConfig() throws Exception { 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.register(ExampleConfig.class);
this.context.refresh(); this.context.refresh();
assertEquals("foo", this.context.getBean(External.class).getName()); assertEquals("foo", this.context.getBean(External.class).getName());
@ -309,7 +309,7 @@ public class EnableConfigurationPropertiesTests {
@Test @Test
public void testExplicitType() throws Exception { 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.register(AnotherExampleConfig.class);
this.context.refresh(); this.context.refresh();
assertEquals("foo", this.context.getBean(External.class).getName()); assertEquals("foo", this.context.getBean(External.class).getName());
@ -317,7 +317,7 @@ public class EnableConfigurationPropertiesTests {
@Test @Test
public void testMultipleExplicitTypes() throws Exception { 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.register(FurtherExampleConfig.class);
this.context.refresh(); this.context.refresh();
assertEquals("foo", this.context.getBean(External.class).getName()); assertEquals("foo", this.context.getBean(External.class).getName());

@ -30,7 +30,7 @@ import org.springframework.core.env.MapPropertySource;
*/ */
public abstract class SpringBootTestUtils { public abstract class SpringBootTestUtils {
public static void addEnviroment(ConfigurableApplicationContext context, public static void addEnvironment(ConfigurableApplicationContext context,
String... pairs) { String... pairs) {
addEnviroment(context.getEnvironment(), pairs); addEnviroment(context.getEnvironment(), pairs);
} }

Loading…
Cancel
Save