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
This commit is contained in:
parent
7d846c835a
commit
478e655758
|
@ -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();
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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]));
|
||||
|
|
|
@ -84,7 +84,7 @@ public abstract class AbstractEndpointTests<T extends Endpoint<?>> {
|
|||
@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"));
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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]));
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -187,31 +187,46 @@ public class ConfigFileApplicationListener implements
|
|||
PropertySource<?> removed = environment.getPropertySources().remove(
|
||||
"defaultProperties");
|
||||
|
||||
List<PropertySource<?>> sources = new ArrayList<PropertySource<?>>();
|
||||
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<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
|
||||
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<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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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<String, Object> map = new HashMap<String, Object>();
|
||||
|
|
|
@ -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]));
|
||||
}
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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.<Throwable> 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());
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue