Replace usages of EnvironmentTestUtils

This commit is contained in:
Madhura Bhave
2017-05-23 10:05:43 -07:00
parent 05254fe322
commit d745b69630
156 changed files with 863 additions and 883 deletions

View File

@@ -23,7 +23,7 @@ import net.minidev.json.JSONArray;
import org.junit.After;
import org.junit.Test;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.boot.web.context.ServerPortInfoApplicationContextInitializer;
import org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext;
@@ -123,7 +123,7 @@ public class BootCuriesHrefIntegrationTests {
}
});
EnvironmentTestUtils.addEnvironment(this.context, properties);
TestPropertyValues.of(properties).applyTo(this.context);
this.context.register(TestConfiguration.class);
new ServerPortInfoApplicationContextInitializer().initialize(this.context);
this.context.refresh();

View File

@@ -59,7 +59,7 @@ import org.springframework.boot.context.properties.bind.Bindable;
import org.springframework.boot.context.properties.bind.Binder;
import org.springframework.boot.context.properties.source.MapConfigurationPropertySource;
import org.springframework.boot.logging.LoggingSystem;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -172,7 +172,7 @@ public class EndpointAutoConfigurationTests {
@Test
public void testInfoEndpoint() throws Exception {
this.context = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(this.context, "info.foo:bar");
TestPropertyValues.of("info.foo:bar").applyTo(this.context);
this.context.register(ProjectInfoAutoConfiguration.class,
InfoContributorAutoConfiguration.class, EndpointAutoConfiguration.class);
this.context.refresh();
@@ -186,8 +186,7 @@ public class EndpointAutoConfigurationTests {
@Test
public void testInfoEndpointNoGitProperties() throws Exception {
this.context = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(this.context,
"spring.info.git.location:classpath:nonexistent");
TestPropertyValues.of("spring.info.git.location:classpath:nonexistent").applyTo(this.context);
this.context.register(InfoContributorAutoConfiguration.class,
EndpointAutoConfiguration.class);
this.context.refresh();
@@ -199,7 +198,7 @@ public class EndpointAutoConfigurationTests {
@Test
public void testInfoEndpointOrdering() throws Exception {
this.context = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(this.context, "info.name:foo");
TestPropertyValues.of("info.name:foo").applyTo(this.context);
this.context.register(CustomInfoContributorsConfig.class,
ProjectInfoAutoConfiguration.class,
InfoContributorAutoConfiguration.class, EndpointAutoConfiguration.class);

View File

@@ -64,7 +64,7 @@ import org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConf
import org.springframework.boot.context.event.ApplicationFailedEvent;
import org.springframework.boot.context.properties.source.ConfigurationPropertySources;
import org.springframework.boot.logging.LoggingSystem;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.boot.testutil.Matched;
import org.springframework.boot.web.context.ServerPortInfoApplicationContextInitializer;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
@@ -124,9 +124,9 @@ public class EndpointWebMvcAutoConfigurationTests {
public void setUp() {
Ports values = new Ports();
ports.set(values);
EnvironmentTestUtils.addEnvironment(this.applicationContext,
TestPropertyValues.of(
"management.context-path=", "management.security.enabled=false",
"server.servlet.context-path=", "server.port=" + ports.get().server);
"server.servlet.context-path=", "server.port=" + ports.get().server).applyTo(this.applicationContext);
}
@After
@@ -137,8 +137,8 @@ public class EndpointWebMvcAutoConfigurationTests {
@Test
public void onSamePort() throws Exception {
EnvironmentTestUtils.addEnvironment(this.applicationContext,
"management.security.enabled=false");
TestPropertyValues.of(
"management.security.enabled=false").applyTo(this.applicationContext);
this.applicationContext.register(RootConfig.class, EndpointConfig.class,
BaseConfiguration.class, EndpointWebMvcAutoConfiguration.class);
this.applicationContext.refresh();
@@ -154,8 +154,8 @@ public class EndpointWebMvcAutoConfigurationTests {
@Test
public void onSamePortWithHeader() throws Exception {
EnvironmentTestUtils.addEnvironment(this.applicationContext,
"management.add-application-context-header:true");
TestPropertyValues.of(
"management.add-application-context-header:true").applyTo(this.applicationContext);
this.applicationContext.register(RootConfig.class, EndpointConfig.class,
BaseConfiguration.class, EndpointWebMvcAutoConfiguration.class);
this.applicationContext.refresh();
@@ -167,8 +167,8 @@ public class EndpointWebMvcAutoConfigurationTests {
@Test
public void onDifferentPort() throws Exception {
EnvironmentTestUtils.addEnvironment(this.applicationContext,
"management.port=" + ports.get().management);
TestPropertyValues.of(
"management.port=" + ports.get().management).applyTo(this.applicationContext);
this.applicationContext.register(RootConfig.class, EndpointConfig.class,
DifferentPortConfig.class, BaseConfiguration.class,
EndpointWebMvcAutoConfiguration.class, ErrorMvcAutoConfiguration.class);
@@ -187,8 +187,8 @@ public class EndpointWebMvcAutoConfigurationTests {
@Test
public void onDifferentPortWithSpecificServer() throws Exception {
EnvironmentTestUtils.addEnvironment(this.applicationContext,
"management.port=" + ports.get().management);
TestPropertyValues.of(
"management.port=" + ports.get().management).applyTo(this.applicationContext);
this.applicationContext.register(SpecificWebServerConfig.class, RootConfig.class,
DifferentPortConfig.class, EndpointConfig.class, BaseConfiguration.class,
EndpointWebMvcAutoConfiguration.class, ErrorMvcAutoConfiguration.class);
@@ -214,9 +214,9 @@ public class EndpointWebMvcAutoConfigurationTests {
@Test
public void onDifferentPortAndContext() throws Exception {
EnvironmentTestUtils.addEnvironment(this.applicationContext,
TestPropertyValues.of(
"management.port=" + ports.get().management,
"management.context-path=/admin");
"management.context-path=/admin").applyTo(this.applicationContext);
this.applicationContext.register(RootConfig.class, EndpointConfig.class,
DifferentPortConfig.class, BaseConfiguration.class,
EndpointWebMvcAutoConfiguration.class, ErrorMvcAutoConfiguration.class);
@@ -228,10 +228,10 @@ public class EndpointWebMvcAutoConfigurationTests {
@Test
public void onDifferentPortAndMainContext() throws Exception {
EnvironmentTestUtils.addEnvironment(this.applicationContext,
TestPropertyValues.of(
"server.servlet.context-path=/spring",
"management.port=" + ports.get().management,
"management.context-path=/admin");
"management.context-path=/admin").applyTo(this.applicationContext);
this.applicationContext.register(RootConfig.class, EndpointConfig.class,
DifferentPortConfig.class, BaseConfiguration.class,
EndpointWebMvcAutoConfiguration.class, ErrorMvcAutoConfiguration.class);
@@ -243,8 +243,8 @@ public class EndpointWebMvcAutoConfigurationTests {
@Test
public void onDifferentPortWithoutErrorMvcAutoConfiguration() throws Exception {
EnvironmentTestUtils.addEnvironment(this.applicationContext,
"management.port=" + ports.get().management);
TestPropertyValues.of(
"management.port=" + ports.get().management).applyTo(this.applicationContext);
this.applicationContext.register(RootConfig.class, EndpointConfig.class,
DifferentPortConfig.class, BaseConfiguration.class,
EndpointWebMvcAutoConfiguration.class);
@@ -254,8 +254,8 @@ public class EndpointWebMvcAutoConfigurationTests {
@Test
public void onDifferentPortInWebServer() throws Exception {
EnvironmentTestUtils.addEnvironment(this.applicationContext,
"management.port=" + ports.get().management);
TestPropertyValues.of(
"management.port=" + ports.get().management).applyTo(this.applicationContext);
this.applicationContext.register(RootConfig.class, EndpointConfig.class,
DifferentPortConfig.class, BaseConfiguration.class,
EndpointWebMvcAutoConfiguration.class, ErrorMvcAutoConfiguration.class);
@@ -272,8 +272,8 @@ public class EndpointWebMvcAutoConfigurationTests {
@Test
public void onRandomPort() throws Exception {
EnvironmentTestUtils.addEnvironment(this.applicationContext, "management.port=0",
"management.security.enabled=false");
TestPropertyValues.of("management.port=0",
"management.security.enabled=false").applyTo(this.applicationContext);
this.applicationContext.register(RootConfig.class, EndpointConfig.class,
BaseConfiguration.class, EndpointWebMvcAutoConfiguration.class,
ErrorMvcAutoConfiguration.class);
@@ -291,8 +291,8 @@ public class EndpointWebMvcAutoConfigurationTests {
@Test
public void onDifferentPortWithPrimaryFailure() throws Exception {
EnvironmentTestUtils.addEnvironment(this.applicationContext,
"management.port=" + ports.get().management);
TestPropertyValues.of(
"management.port=" + ports.get().management).applyTo(this.applicationContext);
this.applicationContext.register(RootConfig.class, EndpointConfig.class,
DifferentPortConfig.class, BaseConfiguration.class,
EndpointWebMvcAutoConfiguration.class, ErrorMvcAutoConfiguration.class);
@@ -308,8 +308,7 @@ public class EndpointWebMvcAutoConfigurationTests {
@Test
public void disabled() throws Exception {
EnvironmentTestUtils.addEnvironment(this.applicationContext,
"management.port=-1");
TestPropertyValues.of("management.port=-1").applyTo(this.applicationContext);
this.applicationContext.register(RootConfig.class, EndpointConfig.class,
BaseConfiguration.class, EndpointWebMvcAutoConfiguration.class);
this.applicationContext.refresh();
@@ -321,10 +320,10 @@ public class EndpointWebMvcAutoConfigurationTests {
@Test
public void specificPortsViaProperties() throws Exception {
EnvironmentTestUtils.addEnvironment(this.applicationContext,
TestPropertyValues.of(
"server.port:" + ports.get().server,
"management.port:" + ports.get().management,
"management.security.enabled:false");
"management.security.enabled:false").applyTo(this.applicationContext);
this.applicationContext.register(RootConfig.class, EndpointConfig.class,
BaseConfiguration.class, EndpointWebMvcAutoConfiguration.class,
ErrorMvcAutoConfiguration.class);
@@ -340,9 +339,8 @@ public class EndpointWebMvcAutoConfigurationTests {
int managementPort = ports.get().management;
try (ServerSocket serverSocket = new ServerSocket()) {
serverSocket.bind(new InetSocketAddress(managementPort));
EnvironmentTestUtils.addEnvironment(this.applicationContext,
"server.port:" + ports.get().server,
"management.port:" + ports.get().management);
TestPropertyValues.of("server.port:" + ports.get().server,
"management.port:" + ports.get().management).applyTo(this.applicationContext);
this.applicationContext.register(RootConfig.class, EndpointConfig.class,
BaseConfiguration.class, EndpointWebMvcAutoConfiguration.class,
ErrorMvcAutoConfiguration.class);
@@ -353,8 +351,7 @@ public class EndpointWebMvcAutoConfigurationTests {
@Test
public void contextPath() throws Exception {
EnvironmentTestUtils.addEnvironment(this.applicationContext,
"management.context-path:/test", "management.security.enabled:false");
TestPropertyValues.of("management.context-path:/test", "management.security.enabled:false").applyTo(this.applicationContext);
this.applicationContext.register(RootConfig.class, EndpointConfig.class,
PropertyPlaceholderAutoConfiguration.class,
JacksonAutoConfiguration.class,
@@ -369,8 +366,8 @@ public class EndpointWebMvcAutoConfigurationTests {
@Test
public void overrideServerProperties() throws Exception {
EnvironmentTestUtils.addEnvironment(this.applicationContext,
"server.displayName:foo");
TestPropertyValues.of(
"server.displayName:foo").applyTo(this.applicationContext);
this.applicationContext.register(RootConfig.class, EndpointConfig.class,
PropertyPlaceholderAutoConfiguration.class,
JacksonAutoConfiguration.class,
@@ -403,8 +400,8 @@ public class EndpointWebMvcAutoConfigurationTests {
@Test
public void portPropertiesOnDifferentPort() throws Exception {
EnvironmentTestUtils.addEnvironment(this.applicationContext,
"management.port=" + ports.get().management);
TestPropertyValues.of(
"management.port=" + ports.get().management).applyTo(this.applicationContext);
new ServerPortInfoApplicationContextInitializer()
.initialize(this.applicationContext);
this.applicationContext.register(RootConfig.class, DifferentPortConfig.class,
@@ -444,8 +441,8 @@ public class EndpointWebMvcAutoConfigurationTests {
public void endpointsAllDisabled() throws Exception {
this.applicationContext.register(RootConfig.class, BaseConfiguration.class,
EndpointWebMvcAutoConfiguration.class);
EnvironmentTestUtils.addEnvironment(this.applicationContext,
"endpoints.enabled:false");
TestPropertyValues.of(
"endpoints.enabled:false").applyTo(this.applicationContext);
this.applicationContext.refresh();
assertThat(this.applicationContext.getBeansOfType(MvcEndpoint.class)).isEmpty();
}
@@ -494,8 +491,8 @@ public class EndpointWebMvcAutoConfigurationTests {
public void shutdownEndpointEnabled() {
this.applicationContext.register(RootConfig.class, BaseConfiguration.class,
EndpointWebMvcAutoConfiguration.class);
EnvironmentTestUtils.addEnvironment(this.applicationContext,
"endpoints.shutdown.enabled:true");
TestPropertyValues.of(
"endpoints.shutdown.enabled:true").applyTo(this.applicationContext);
this.applicationContext.refresh();
assertThat(this.applicationContext.getBeansOfType(ShutdownMvcEndpoint.class))
.hasSize(1);
@@ -505,8 +502,7 @@ public class EndpointWebMvcAutoConfigurationTests {
public void actuatorEndpointEnabledIndividually() {
this.applicationContext.register(RootConfig.class, BaseConfiguration.class,
EndpointWebMvcAutoConfiguration.class);
EnvironmentTestUtils.addEnvironment(this.applicationContext,
"endpoints.enabled:false", "endpoints.actuator.enabled:true");
TestPropertyValues.of("endpoints.enabled:false", "endpoints.actuator.enabled:true").applyTo(this.applicationContext);
this.applicationContext.refresh();
assertThat(this.applicationContext.getBeansOfType(HalJsonMvcEndpoint.class))
.hasSize(1);
@@ -514,11 +510,10 @@ public class EndpointWebMvcAutoConfigurationTests {
@Test
public void managementSpecificSslUsingDifferentPort() throws Exception {
EnvironmentTestUtils.addEnvironment(this.applicationContext,
"management.port=" + ports.get().management,
TestPropertyValues.of("management.port=" + ports.get().management,
"management.ssl.enabled=true",
"management.ssl.key-store=classpath:test.jks",
"management.ssl.key-password=password");
"management.ssl.key-password=password").applyTo(this.applicationContext);
this.applicationContext.register(RootConfig.class, EndpointConfig.class,
DifferentPortConfig.class, BaseConfiguration.class,
EndpointWebMvcAutoConfiguration.class, ErrorMvcAutoConfiguration.class);
@@ -541,10 +536,10 @@ public class EndpointWebMvcAutoConfigurationTests {
@Test
public void managementSpecificSslUsingSamePortFails() throws Exception {
EnvironmentTestUtils.addEnvironment(this.applicationContext,
TestPropertyValues.of(
"management.ssl.enabled=true",
"management.ssl.key-store=classpath:test.jks",
"management.ssl.key-password=password");
"management.ssl.key-password=password").applyTo(this.applicationContext);
this.applicationContext.register(RootConfig.class, EndpointConfig.class,
BaseConfiguration.class, EndpointWebMvcAutoConfiguration.class,
ErrorMvcAutoConfiguration.class);
@@ -556,10 +551,10 @@ public class EndpointWebMvcAutoConfigurationTests {
@Test
public void managementServerCanDisableSslWhenUsingADifferentPort() throws Exception {
EnvironmentTestUtils.addEnvironment(this.applicationContext,
TestPropertyValues.of(
"management.port=" + ports.get().management, "server.ssl.enabled=true",
"server.ssl.key-store=classpath:test.jks",
"server.ssl.key-password=password", "management.ssl.enabled=false");
"server.ssl.key-password=password", "management.ssl.enabled=false").applyTo(this.applicationContext);
this.applicationContext.register(RootConfig.class, EndpointConfig.class,
DifferentPortConfig.class, BaseConfiguration.class,
@@ -583,13 +578,13 @@ public class EndpointWebMvcAutoConfigurationTests {
@Test
public void tomcatManagementAccessLogUsesCustomPrefix() throws Exception {
EnvironmentTestUtils.addEnvironment(this.applicationContext,
"management.port=" + ports.get().management);
TestPropertyValues.of(
"management.port=" + ports.get().management).applyTo(this.applicationContext);
this.applicationContext.register(TomcatWebServerConfig.class, RootConfig.class,
EndpointConfig.class, DifferentPortConfig.class, BaseConfiguration.class,
EndpointWebMvcAutoConfiguration.class, ErrorMvcAutoConfiguration.class);
EnvironmentTestUtils.addEnvironment(this.applicationContext,
"server.tomcat.accesslog.enabled: true");
TestPropertyValues.of(
"server.tomcat.accesslog.enabled: true").applyTo(this.applicationContext);
this.applicationContext.refresh();
ApplicationContext managementContext = this.applicationContext
.getBean(ManagementContextResolver.class).getApplicationContext();
@@ -604,9 +599,9 @@ public class EndpointWebMvcAutoConfigurationTests {
@Test
public void undertowManagementAccessLogUsesCustomPrefix() throws Exception {
EnvironmentTestUtils.addEnvironment(this.applicationContext,
TestPropertyValues.of(
"management.port=" + ports.get().management,
"server.undertow.accesslog.enabled: true");
"server.undertow.accesslog.enabled: true").applyTo(this.applicationContext);
this.applicationContext.register(UndertowWebServerConfig.class, RootConfig.class,
EndpointConfig.class, DifferentPortConfig.class, BaseConfiguration.class,
EndpointWebMvcAutoConfiguration.class, ErrorMvcAutoConfiguration.class);
@@ -633,8 +628,7 @@ public class EndpointWebMvcAutoConfigurationTests {
private void endpointDisabled(String name, Class<? extends MvcEndpoint> type) {
this.applicationContext.register(RootConfig.class, BaseConfiguration.class,
EndpointWebMvcAutoConfiguration.class);
EnvironmentTestUtils.addEnvironment(this.applicationContext,
String.format("endpoints.%s.enabled:false", name));
TestPropertyValues.of(String.format("endpoints.%s.enabled:false", name)).applyTo(this.applicationContext);
this.applicationContext.refresh();
assertThat(this.applicationContext.getBeansOfType(type)).isEmpty();
}
@@ -644,9 +638,9 @@ public class EndpointWebMvcAutoConfigurationTests {
this.applicationContext.register(LoggingConfig.class, RootConfig.class,
BaseConfiguration.class, EndpointWebMvcAutoConfiguration.class);
ConfigurationPropertySources.attach(this.applicationContext.getEnvironment());
EnvironmentTestUtils.addEnvironment(this.applicationContext,
TestPropertyValues.of(
"endpoints.enabled:false",
String.format("endpoints.%s.enabled:true", name));
String.format("endpoints.%s.enabled:true", name)).applyTo(this.applicationContext);
this.applicationContext.refresh();
assertThat(this.applicationContext.getBeansOfType(type)).hasSize(1);
}

View File

@@ -29,7 +29,7 @@ import org.springframework.boot.actuate.endpoint.mvc.MvcEndpoints;
import org.springframework.boot.autoconfigure.http.HttpMessageConvertersAutoConfiguration;
import org.springframework.boot.autoconfigure.web.ServerProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.hateoas.Link;
@@ -126,7 +126,7 @@ public class EndpointWebMvcHypermediaManagementContextConfigurationTests {
}
});
EnvironmentTestUtils.addEnvironment(this.context, properties);
TestPropertyValues.of(properties).applyTo(this.context);
this.context.register(TestConfiguration.class,
HttpMessageConvertersAutoConfiguration.class,
EndpointWebMvcHypermediaManagementContextConfiguration.class);

View File

@@ -30,7 +30,7 @@ import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration;
import org.springframework.boot.autoconfigure.security.SecurityAutoConfiguration;
import org.springframework.boot.autoconfigure.web.client.RestTemplateAutoConfiguration;
import org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.mock.web.MockServletContext;
import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
@@ -68,9 +68,9 @@ public class EndpointWebMvcManagementContextConfigurationTests {
@Test
public void endpointHandlerMapping() throws Exception {
EnvironmentTestUtils.addEnvironment(this.context,
TestPropertyValues.of(
"management.security.enabled=false",
"management.security.roles=my-role,your-role");
"management.security.roles=my-role,your-role").applyTo(this.context);
this.context.refresh();
EndpointHandlerMapping mapping = this.context.getBean("endpointHandlerMapping",
EndpointHandlerMapping.class);

View File

@@ -57,7 +57,7 @@ import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration;
import org.springframework.boot.autoconfigure.solr.SolrAutoConfiguration;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -92,8 +92,8 @@ public class HealthIndicatorAutoConfigurationTests {
public void defaultHealthIndicator() {
this.context.register(HealthIndicatorAutoConfiguration.class,
ManagementServerProperties.class);
EnvironmentTestUtils.addEnvironment(this.context,
"management.health.diskspace.enabled:false");
TestPropertyValues.of(
"management.health.diskspace.enabled:false").applyTo(this.context);
this.context.refresh();
Map<String, HealthIndicator> beans = this.context
.getBeansOfType(HealthIndicator.class);
@@ -106,8 +106,8 @@ public class HealthIndicatorAutoConfigurationTests {
public void defaultHealthIndicatorsDisabled() {
this.context.register(HealthIndicatorAutoConfiguration.class,
ManagementServerProperties.class);
EnvironmentTestUtils.addEnvironment(this.context,
"management.health.defaults.enabled:false");
TestPropertyValues.of(
"management.health.defaults.enabled:false").applyTo(this.context);
this.context.refresh();
Map<String, HealthIndicator> beans = this.context
.getBeansOfType(HealthIndicator.class);
@@ -120,8 +120,8 @@ public class HealthIndicatorAutoConfigurationTests {
public void defaultHealthIndicatorsDisabledWithCustomOne() {
this.context.register(CustomHealthIndicator.class,
HealthIndicatorAutoConfiguration.class, ManagementServerProperties.class);
EnvironmentTestUtils.addEnvironment(this.context,
"management.health.defaults.enabled:false");
TestPropertyValues.of(
"management.health.defaults.enabled:false").applyTo(this.context);
this.context.refresh();
Map<String, HealthIndicator> beans = this.context
.getBeansOfType(HealthIndicator.class);
@@ -134,9 +134,9 @@ public class HealthIndicatorAutoConfigurationTests {
public void defaultHealthIndicatorsDisabledButOne() {
this.context.register(HealthIndicatorAutoConfiguration.class,
ManagementServerProperties.class);
EnvironmentTestUtils.addEnvironment(this.context,
TestPropertyValues.of(
"management.health.defaults.enabled:false",
"management.health.diskspace.enabled:true");
"management.health.diskspace.enabled:true").applyTo(this.context);
this.context.refresh();
Map<String, HealthIndicator> beans = this.context
.getBeansOfType(HealthIndicator.class);
@@ -149,8 +149,8 @@ public class HealthIndicatorAutoConfigurationTests {
public void redisHealthIndicator() {
this.context.register(RedisAutoConfiguration.class,
ManagementServerProperties.class, HealthIndicatorAutoConfiguration.class);
EnvironmentTestUtils.addEnvironment(this.context,
"management.health.diskspace.enabled:false");
TestPropertyValues.of(
"management.health.diskspace.enabled:false").applyTo(this.context);
this.context.refresh();
Map<String, HealthIndicator> beans = this.context
.getBeansOfType(HealthIndicator.class);
@@ -163,9 +163,9 @@ public class HealthIndicatorAutoConfigurationTests {
public void notRedisHealthIndicator() {
this.context.register(RedisAutoConfiguration.class,
ManagementServerProperties.class, HealthIndicatorAutoConfiguration.class);
EnvironmentTestUtils.addEnvironment(this.context,
TestPropertyValues.of(
"management.health.redis.enabled:false",
"management.health.diskspace.enabled:false");
"management.health.diskspace.enabled:false").applyTo(this.context);
this.context.refresh();
Map<String, HealthIndicator> beans = this.context
.getBeansOfType(HealthIndicator.class);
@@ -179,8 +179,8 @@ public class HealthIndicatorAutoConfigurationTests {
this.context.register(MongoAutoConfiguration.class,
ManagementServerProperties.class, MongoDataAutoConfiguration.class,
HealthIndicatorAutoConfiguration.class);
EnvironmentTestUtils.addEnvironment(this.context,
"management.health.diskspace.enabled:false");
TestPropertyValues.of(
"management.health.diskspace.enabled:false").applyTo(this.context);
this.context.refresh();
Map<String, HealthIndicator> beans = this.context
.getBeansOfType(HealthIndicator.class);
@@ -194,9 +194,9 @@ public class HealthIndicatorAutoConfigurationTests {
this.context.register(MongoAutoConfiguration.class,
ManagementServerProperties.class, MongoDataAutoConfiguration.class,
HealthIndicatorAutoConfiguration.class);
EnvironmentTestUtils.addEnvironment(this.context,
TestPropertyValues.of(
"management.health.mongo.enabled:false",
"management.health.diskspace.enabled:false");
"management.health.diskspace.enabled:false").applyTo(this.context);
this.context.refresh();
Map<String, HealthIndicator> beans = this.context
.getBeansOfType(HealthIndicator.class);
@@ -220,8 +220,8 @@ public class HealthIndicatorAutoConfigurationTests {
public void dataSourceHealthIndicator() {
this.context.register(EmbeddedDataSourceConfiguration.class,
ManagementServerProperties.class, HealthIndicatorAutoConfiguration.class);
EnvironmentTestUtils.addEnvironment(this.context,
"management.health.diskspace.enabled:false");
TestPropertyValues.of(
"management.health.diskspace.enabled:false").applyTo(this.context);
this.context.refresh();
Map<String, HealthIndicator> beans = this.context
.getBeansOfType(HealthIndicator.class);
@@ -235,8 +235,8 @@ public class HealthIndicatorAutoConfigurationTests {
this.context.register(EmbeddedDataSourceConfiguration.class,
DataSourceConfig.class, ManagementServerProperties.class,
HealthIndicatorAutoConfiguration.class);
EnvironmentTestUtils.addEnvironment(this.context,
"management.health.diskspace.enabled:false");
TestPropertyValues.of(
"management.health.diskspace.enabled:false").applyTo(this.context);
this.context.refresh();
Map<String, HealthIndicator> beans = this.context
.getBeansOfType(HealthIndicator.class);
@@ -252,8 +252,8 @@ public class HealthIndicatorAutoConfigurationTests {
this.context.register(EmbeddedDataSourceConfiguration.class,
RoutingDatasourceConfig.class, ManagementServerProperties.class,
HealthIndicatorAutoConfiguration.class);
EnvironmentTestUtils.addEnvironment(this.context,
"management.health.diskspace.enabled:false");
TestPropertyValues.of(
"management.health.diskspace.enabled:false").applyTo(this.context);
this.context.refresh();
Map<String, HealthIndicator> beans = this.context
.getBeansOfType(HealthIndicator.class);
@@ -269,9 +269,9 @@ public class HealthIndicatorAutoConfigurationTests {
DataSourceConfig.class,
DataSourcePoolMetadataProvidersConfiguration.class,
HealthIndicatorAutoConfiguration.class);
EnvironmentTestUtils.addEnvironment(this.context,
TestPropertyValues.of(
"spring.datasource.test.validation-query:SELECT from FOOBAR",
"management.health.diskspace.enabled:false");
"management.health.diskspace.enabled:false").applyTo(this.context);
this.context.refresh();
Map<String, HealthIndicator> beans = this.context
.getBeansOfType(HealthIndicator.class);
@@ -286,9 +286,9 @@ public class HealthIndicatorAutoConfigurationTests {
public void notDataSourceHealthIndicator() {
this.context.register(EmbeddedDataSourceConfiguration.class,
ManagementServerProperties.class, HealthIndicatorAutoConfiguration.class);
EnvironmentTestUtils.addEnvironment(this.context,
TestPropertyValues.of(
"management.health.db.enabled:false",
"management.health.diskspace.enabled:false");
"management.health.diskspace.enabled:false").applyTo(this.context);
this.context.refresh();
Map<String, HealthIndicator> beans = this.context
.getBeansOfType(HealthIndicator.class);
@@ -301,8 +301,8 @@ public class HealthIndicatorAutoConfigurationTests {
public void rabbitHealthIndicator() {
this.context.register(RabbitAutoConfiguration.class,
ManagementServerProperties.class, HealthIndicatorAutoConfiguration.class);
EnvironmentTestUtils.addEnvironment(this.context,
"management.health.diskspace.enabled:false");
TestPropertyValues.of(
"management.health.diskspace.enabled:false").applyTo(this.context);
this.context.refresh();
Map<String, HealthIndicator> beans = this.context
.getBeansOfType(HealthIndicator.class);
@@ -315,9 +315,9 @@ public class HealthIndicatorAutoConfigurationTests {
public void notRabbitHealthIndicator() {
this.context.register(RabbitAutoConfiguration.class,
ManagementServerProperties.class, HealthIndicatorAutoConfiguration.class);
EnvironmentTestUtils.addEnvironment(this.context,
TestPropertyValues.of(
"management.health.rabbit.enabled:false",
"management.health.diskspace.enabled:false");
"management.health.diskspace.enabled:false").applyTo(this.context);
this.context.refresh();
Map<String, HealthIndicator> beans = this.context
.getBeansOfType(HealthIndicator.class);
@@ -330,8 +330,8 @@ public class HealthIndicatorAutoConfigurationTests {
public void solrHealthIndicator() {
this.context.register(SolrAutoConfiguration.class,
ManagementServerProperties.class, HealthIndicatorAutoConfiguration.class);
EnvironmentTestUtils.addEnvironment(this.context,
"management.health.diskspace.enabled:false");
TestPropertyValues.of(
"management.health.diskspace.enabled:false").applyTo(this.context);
this.context.refresh();
Map<String, HealthIndicator> beans = this.context
.getBeansOfType(HealthIndicator.class);
@@ -344,9 +344,9 @@ public class HealthIndicatorAutoConfigurationTests {
public void notSolrHealthIndicator() {
this.context.register(SolrAutoConfiguration.class,
ManagementServerProperties.class, HealthIndicatorAutoConfiguration.class);
EnvironmentTestUtils.addEnvironment(this.context,
TestPropertyValues.of(
"management.health.solr.enabled:false",
"management.health.diskspace.enabled:false");
"management.health.diskspace.enabled:false").applyTo(this.context);
this.context.refresh();
Map<String, HealthIndicator> beans = this.context
.getBeansOfType(HealthIndicator.class);
@@ -368,9 +368,9 @@ public class HealthIndicatorAutoConfigurationTests {
@Test
public void mailHealthIndicator() {
EnvironmentTestUtils.addEnvironment(this.context,
TestPropertyValues.of(
"spring.mail.host:smtp.acme.org",
"management.health.diskspace.enabled:false");
"management.health.diskspace.enabled:false").applyTo(this.context);
this.context.register(MailSenderAutoConfiguration.class,
ManagementServerProperties.class, HealthIndicatorAutoConfiguration.class);
this.context.refresh();
@@ -384,9 +384,9 @@ public class HealthIndicatorAutoConfigurationTests {
@Test
public void notMailHealthIndicator() {
EnvironmentTestUtils.addEnvironment(this.context,
TestPropertyValues.of(
"spring.mail.host:smtp.acme.org", "management.health.mail.enabled:false",
"management.health.diskspace.enabled:false");
"management.health.diskspace.enabled:false").applyTo(this.context);
this.context.register(MailSenderAutoConfiguration.class,
ManagementServerProperties.class, HealthIndicatorAutoConfiguration.class);
this.context.refresh();
@@ -400,8 +400,8 @@ public class HealthIndicatorAutoConfigurationTests {
@Test
public void jmsHealthIndicator() {
EnvironmentTestUtils.addEnvironment(this.context,
"management.health.diskspace.enabled:false");
TestPropertyValues.of(
"management.health.diskspace.enabled:false").applyTo(this.context);
this.context.register(ActiveMQAutoConfiguration.class,
ManagementServerProperties.class, HealthIndicatorAutoConfiguration.class);
this.context.refresh();
@@ -415,9 +415,9 @@ public class HealthIndicatorAutoConfigurationTests {
@Test
public void notJmsHealthIndicator() {
EnvironmentTestUtils.addEnvironment(this.context,
TestPropertyValues.of(
"management.health.jms.enabled:false",
"management.health.diskspace.enabled:false");
"management.health.diskspace.enabled:false").applyTo(this.context);
this.context.register(ActiveMQAutoConfiguration.class,
ManagementServerProperties.class, HealthIndicatorAutoConfiguration.class);
this.context.refresh();
@@ -431,9 +431,9 @@ public class HealthIndicatorAutoConfigurationTests {
@Test
public void elasticsearchHealthIndicator() {
EnvironmentTestUtils.addEnvironment(this.context,
TestPropertyValues.of(
"spring.data.elasticsearch.properties.path.home:target",
"management.health.diskspace.enabled:false");
"management.health.diskspace.enabled:false").applyTo(this.context);
this.context.register(JestClientConfiguration.class, JestAutoConfiguration.class,
ElasticsearchAutoConfiguration.class, ManagementServerProperties.class,
HealthIndicatorAutoConfiguration.class);
@@ -448,8 +448,8 @@ public class HealthIndicatorAutoConfigurationTests {
@Test
public void elasticsearchJestHealthIndicator() {
EnvironmentTestUtils.addEnvironment(this.context,
"management.health.diskspace.enabled:false");
TestPropertyValues.of(
"management.health.diskspace.enabled:false").applyTo(this.context);
this.context.register(JestClientConfiguration.class, JestAutoConfiguration.class,
ManagementServerProperties.class, HealthIndicatorAutoConfiguration.class);
this.context.refresh();
@@ -463,10 +463,10 @@ public class HealthIndicatorAutoConfigurationTests {
@Test
public void notElasticsearchHealthIndicator() {
EnvironmentTestUtils.addEnvironment(this.context,
TestPropertyValues.of(
"management.health.elasticsearch.enabled:false",
"spring.data.elasticsearch.properties.path.home:target",
"management.health.diskspace.enabled:false");
"management.health.diskspace.enabled:false").applyTo(this.context);
this.context.register(JestClientConfiguration.class, JestAutoConfiguration.class,
ElasticsearchAutoConfiguration.class, ManagementServerProperties.class,
HealthIndicatorAutoConfiguration.class);
@@ -481,8 +481,8 @@ public class HealthIndicatorAutoConfigurationTests {
@Test
public void cassandraHealthIndicator() throws Exception {
EnvironmentTestUtils.addEnvironment(this.context,
"management.health.diskspace.enabled:false");
TestPropertyValues.of(
"management.health.diskspace.enabled:false").applyTo(this.context);
this.context.register(CassandraConfiguration.class,
ManagementServerProperties.class, HealthIndicatorAutoConfiguration.class);
this.context.refresh();
@@ -495,9 +495,9 @@ public class HealthIndicatorAutoConfigurationTests {
@Test
public void notCassandraHealthIndicator() throws Exception {
EnvironmentTestUtils.addEnvironment(this.context,
TestPropertyValues.of(
"management.health.diskspace.enabled:false",
"management.health.cassandra.enabled:false");
"management.health.cassandra.enabled:false").applyTo(this.context);
this.context.register(CassandraConfiguration.class,
ManagementServerProperties.class, HealthIndicatorAutoConfiguration.class);
this.context.refresh();
@@ -510,8 +510,8 @@ public class HealthIndicatorAutoConfigurationTests {
@Test
public void couchbaseHealthIndicator() throws Exception {
EnvironmentTestUtils.addEnvironment(this.context,
"management.health.diskspace.enabled:false");
TestPropertyValues.of(
"management.health.diskspace.enabled:false").applyTo(this.context);
this.context.register(CouchbaseConfiguration.class,
ManagementServerProperties.class, HealthIndicatorAutoConfiguration.class);
this.context.refresh();
@@ -524,9 +524,9 @@ public class HealthIndicatorAutoConfigurationTests {
@Test
public void notCouchbaseHealthIndicator() throws Exception {
EnvironmentTestUtils.addEnvironment(this.context,
TestPropertyValues.of(
"management.health.diskspace.enabled:false",
"management.health.couchbase.enabled:false");
"management.health.couchbase.enabled:false").applyTo(this.context);
this.context.register(CouchbaseConfiguration.class,
ManagementServerProperties.class, HealthIndicatorAutoConfiguration.class);
this.context.refresh();
@@ -539,8 +539,8 @@ public class HealthIndicatorAutoConfigurationTests {
@Test
public void ldapHealthIndicator() throws Exception {
EnvironmentTestUtils.addEnvironment(this.context,
"management.health.diskspace.enabled:false");
TestPropertyValues.of(
"management.health.diskspace.enabled:false").applyTo(this.context);
this.context.register(LdapConfiguration.class, ManagementServerProperties.class,
HealthIndicatorAutoConfiguration.class);
this.context.refresh();
@@ -553,9 +553,9 @@ public class HealthIndicatorAutoConfigurationTests {
@Test
public void notLdapHealthIndicator() throws Exception {
EnvironmentTestUtils.addEnvironment(this.context,
TestPropertyValues.of(
"management.health.diskspace.enabled:false",
"management.health.ldap.enabled:false");
"management.health.ldap.enabled:false").applyTo(this.context);
this.context.register(LdapConfiguration.class, ManagementServerProperties.class,
HealthIndicatorAutoConfiguration.class);
this.context.refresh();

View File

@@ -35,7 +35,7 @@ import org.springframework.boot.autoconfigure.http.HttpMessageConvertersAutoConf
import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration;
import org.springframework.boot.autoconfigure.security.SecurityAutoConfiguration;
import org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.mock.web.MockHttpServletRequest;
@@ -80,8 +80,8 @@ public class HealthMvcEndpointAutoConfigurationTests {
this.context = new AnnotationConfigWebApplicationContext();
this.context.setServletContext(new MockServletContext());
this.context.register(TestConfiguration.class);
EnvironmentTestUtils.addEnvironment(this.context,
"management.security.enabled=false");
TestPropertyValues.of(
"management.security.enabled=false").applyTo(this.context);
this.context.refresh();
Health health = (Health) this.context.getBean(HealthMvcEndpoint.class)
.invoke(null, null);
@@ -96,8 +96,8 @@ public class HealthMvcEndpointAutoConfigurationTests {
this.context = new AnnotationConfigWebApplicationContext();
this.context.setServletContext(new MockServletContext());
this.context.register(TestConfiguration.class);
EnvironmentTestUtils.addEnvironment(this.context,
"management.security.roles[0]=super");
TestPropertyValues.of(
"management.security.roles[0]=super").applyTo(this.context);
this.context.refresh();
HealthMvcEndpoint health = this.context.getBean(HealthMvcEndpoint.class);
assertThat(ReflectionTestUtils.getField(health, "roles"))

View File

@@ -28,7 +28,7 @@ import org.springframework.boot.actuate.info.Info;
import org.springframework.boot.actuate.info.InfoContributor;
import org.springframework.boot.info.BuildProperties;
import org.springframework.boot.info.GitProperties;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -152,7 +152,7 @@ public class InfoContributorAutoConfigurationTests {
context.register(config);
}
context.register(InfoContributorAutoConfiguration.class);
EnvironmentTestUtils.addEnvironment(context, environment);
TestPropertyValues.of(environment).applyTo(context);
context.refresh();
this.context = context;
}

View File

@@ -31,7 +31,7 @@ import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoCon
import org.springframework.boot.autoconfigure.http.HttpMessageConvertersAutoConfiguration;
import org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.boot.web.server.WebServerFactoryCustomizerBeanPostProcessor;
import org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext;
import org.springframework.boot.web.servlet.server.MockServletWebServerFactory;
@@ -68,8 +68,8 @@ public class JolokiaAutoConfigurationTests {
@Test
public void agentServletRegisteredWithAppContext() throws Exception {
this.context = new AnnotationConfigServletWebServerApplicationContext();
EnvironmentTestUtils.addEnvironment(this.context, "jolokia.config[key1]:value1",
"jolokia.config[key2]:value2");
TestPropertyValues.of("jolokia.config[key1]:value1",
"jolokia.config[key2]:value2").applyTo(this.context);
this.context.register(Config.class, WebMvcAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class,
HttpMessageConvertersAutoConfiguration.class,
@@ -81,8 +81,8 @@ public class JolokiaAutoConfigurationTests {
@Test
public void agentServletWithCustomPath() throws Exception {
this.context = new AnnotationConfigServletWebServerApplicationContext();
EnvironmentTestUtils.addEnvironment(this.context,
"endpoints.jolokia.path=/foo/bar");
TestPropertyValues.of(
"endpoints.jolokia.path=/foo/bar").applyTo(this.context);
this.context.register(EndpointsConfig.class, WebMvcAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class,
HttpMessageConvertersAutoConfiguration.class,
@@ -113,7 +113,7 @@ public class JolokiaAutoConfigurationTests {
private void assertEndpointDisabled(String... pairs) {
this.context = new AnnotationConfigServletWebServerApplicationContext();
EnvironmentTestUtils.addEnvironment(this.context, pairs);
TestPropertyValues.of(pairs).applyTo(this.context);
this.context.register(Config.class, WebMvcAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class,
HttpMessageConvertersAutoConfiguration.class,
@@ -124,7 +124,7 @@ public class JolokiaAutoConfigurationTests {
private void assertEndpointEnabled(String... pairs) {
this.context = new AnnotationConfigServletWebServerApplicationContext();
EnvironmentTestUtils.addEnvironment(this.context, pairs);
TestPropertyValues.of(pairs).applyTo(this.context);
this.context.register(Config.class, WebMvcAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class,
HttpMessageConvertersAutoConfiguration.class,

View File

@@ -23,7 +23,7 @@ import org.junit.runner.RunWith;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.junit.runner.classpath.ClassPathExclusions;
import org.springframework.boot.junit.runner.classpath.ModifiedClassPathRunner;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import static org.assertj.core.api.Assertions.assertThat;
@@ -54,7 +54,7 @@ public class ManagementServerPropertiesNoSecurityTests {
public ManagementServerProperties load(String... environment) {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(context, environment);
TestPropertyValues.of(environment).applyTo(context);
context.register(Config.class);
context.refresh();
this.context = context;

View File

@@ -20,7 +20,7 @@ import org.junit.After;
import org.junit.Test;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import static org.assertj.core.api.Assertions.assertThat;
@@ -88,7 +88,7 @@ public class ManagementServerPropertiesTests {
public ManagementServerProperties load(String... environment) {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(ctx, environment);
TestPropertyValues.of(environment).applyTo(ctx);
ctx.register(Config.class);
ctx.refresh();
this.context = ctx;

View File

@@ -32,7 +32,7 @@ import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration;
import org.springframework.boot.autoconfigure.security.FallbackWebSecurityAutoConfiguration;
import org.springframework.boot.autoconfigure.security.SecurityAutoConfiguration;
import org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.mock.web.MockServletContext;
@@ -91,7 +91,7 @@ public class ManagementWebSecurityAutoConfigurationTests {
HttpMessageConvertersAutoConfiguration.class,
EndpointAutoConfiguration.class, EndpointWebMvcAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class, AuditAutoConfiguration.class);
EnvironmentTestUtils.addEnvironment(this.context, "security.basic.enabled:false");
TestPropertyValues.of("security.basic.enabled:false").applyTo(this.context);
this.context.refresh();
assertThat(this.context.getBean(AuthenticationManagerBuilder.class)).isNotNull();
FilterChainProxy filterChainProxy = this.context.getBean(FilterChainProxy.class);
@@ -140,7 +140,7 @@ public class ManagementWebSecurityAutoConfigurationTests {
ManagementWebSecurityAutoConfiguration.class,
EndpointAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class);
EnvironmentTestUtils.addEnvironment(this.context, "security.ignored:none");
TestPropertyValues.of("security.ignored:none").applyTo(this.context);
this.context.refresh();
// Just the application and management endpoints now
assertThat(this.context.getBean(FilterChainProxy.class).getFilterChains())
@@ -152,7 +152,7 @@ public class ManagementWebSecurityAutoConfigurationTests {
this.context = new AnnotationConfigWebApplicationContext();
this.context.setServletContext(new MockServletContext());
this.context.register(WebConfiguration.class);
EnvironmentTestUtils.addEnvironment(this.context, "security.basic.enabled:false");
TestPropertyValues.of("security.basic.enabled:false").applyTo(this.context);
this.context.refresh();
// Just the management endpoints (one filter) and ignores now plus the backup
// filter on app endpoints
@@ -233,7 +233,7 @@ public class ManagementWebSecurityAutoConfigurationTests {
this.context = new AnnotationConfigWebApplicationContext();
this.context.setServletContext(new MockServletContext());
this.context.register(WebConfiguration.class);
EnvironmentTestUtils.addEnvironment(this.context, "endpoints.sensitive:true");
TestPropertyValues.of("endpoints.sensitive:true").applyTo(this.context);
this.context.refresh();
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(this.context) //

View File

@@ -34,7 +34,7 @@ import org.springframework.boot.actuate.metrics.statsd.StatsdMetricWriter;
import org.springframework.boot.actuate.metrics.writer.GaugeWriter;
import org.springframework.boot.actuate.metrics.writer.MetricWriter;
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -148,8 +148,8 @@ public class MetricExportAutoConfigurationTests {
@Test
public void statsdWithHost() throws Exception {
this.context = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(this.context,
"spring.metrics.export.statsd.host=localhost");
TestPropertyValues.of(
"spring.metrics.export.statsd.host=localhost").applyTo(this.context);
this.context.register(MetricEndpointConfiguration.class,
MetricExportAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class);

View File

@@ -31,7 +31,7 @@ import org.mockito.stubbing.Answer;
import org.springframework.boot.actuate.metrics.CounterService;
import org.springframework.boot.actuate.metrics.GaugeService;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -234,8 +234,8 @@ public class MetricFilterAutoConfigurationTests {
@Test
public void skipsFilterIfPropertyDisabled() throws Exception {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(context,
"endpoints.metrics.filter.enabled:false");
TestPropertyValues.of(
"endpoints.metrics.filter.enabled:false").applyTo(context);
context.register(Config.class, MetricFilterAutoConfiguration.class);
context.refresh();
assertThat(context.getBeansOfType(Filter.class).size()).isEqualTo(0);
@@ -355,9 +355,9 @@ public class MetricFilterAutoConfigurationTests {
throws Exception {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
context.register(Config.class, MetricFilterAutoConfiguration.class);
EnvironmentTestUtils.addEnvironment(context,
TestPropertyValues.of(
"endpoints.metrics.filter.gauge-submissions=merged,per-http-method",
"endpoints.metrics.filter.counter-submissions=merged,per-http-method");
"endpoints.metrics.filter.counter-submissions=merged,per-http-method").applyTo(context);
context.refresh();
Filter filter = context.getBean(Filter.class);
final MockHttpServletRequest request = new MockHttpServletRequest("PUT",
@@ -387,9 +387,9 @@ public class MetricFilterAutoConfigurationTests {
public void doesNotRecordRolledUpMetricsIfConfigured() throws Exception {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
context.register(Config.class, MetricFilterAutoConfiguration.class);
EnvironmentTestUtils.addEnvironment(context,
TestPropertyValues.of(
"endpoints.metrics.filter.gauge-submissions=",
"endpoints.metrics.filter.counter-submissions=");
"endpoints.metrics.filter.counter-submissions=").applyTo(context);
context.refresh();
Filter filter = context.getBean(Filter.class);
final MockHttpServletRequest request = new MockHttpServletRequest("PUT",

View File

@@ -52,7 +52,7 @@ import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionEvaluationReport;
import org.springframework.boot.autoconfigure.http.HttpMessageConvertersAutoConfiguration;
import org.springframework.boot.logging.LoggingSystem;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.mock.web.MockServletContext;
@@ -117,10 +117,10 @@ public class MvcEndpointPathConfigurationTests {
this.context = new AnnotationConfigWebApplicationContext();
this.context.register(TestConfiguration.class);
this.context.setServletContext(new MockServletContext());
EnvironmentTestUtils.addEnvironment(this.context,
TestPropertyValues.of(
"endpoints." + this.endpointName + ".path" + ":/custom/path",
"endpoints." + this.endpointName + ".enabled:true",
"logging.file:target/test.log");
"logging.file:target/test.log").applyTo(this.context);
this.context.refresh();
assertThat(getConfiguredPath()).isEqualTo("/custom/path");
}

View File

@@ -25,7 +25,7 @@ import org.springframework.boot.actuate.trace.TraceProperties;
import org.springframework.boot.actuate.trace.TraceRepository;
import org.springframework.boot.actuate.trace.WebRequestTraceFilter;
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -75,7 +75,7 @@ public class TraceWebFilterAutoConfigurationTests {
private void load(Class<?> config, String... environment) {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(context, environment);
TestPropertyValues.of(environment).applyTo(context);
if (config != null) {
context.register(config);
}

View File

@@ -35,7 +35,7 @@ import org.springframework.boot.autoconfigure.security.SecurityAutoConfiguration
import org.springframework.boot.autoconfigure.web.client.RestTemplateAutoConfiguration;
import org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration;
import org.springframework.boot.context.properties.source.ConfigurationPropertySources;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.http.HttpMethod;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockServletContext;
@@ -119,8 +119,8 @@ public class CloudFoundryActuatorAutoConfigurationTests {
@Test
public void skipSslValidation() throws Exception {
EnvironmentTestUtils.addEnvironment(this.context,
"management.cloudfoundry.skipSslValidation:true");
TestPropertyValues.of(
"management.cloudfoundry.skipSslValidation:true").applyTo(this.context);
ConfigurationPropertySources.attach(this.context.getEnvironment());
this.context.refresh();
CloudFoundryEndpointHandlerMapping handlerMapping = getHandlerMapping();
@@ -137,8 +137,8 @@ public class CloudFoundryActuatorAutoConfigurationTests {
@Test
public void cloudFoundryPlatformActiveAndCloudControllerUrlNotPresent()
throws Exception {
EnvironmentTestUtils.addEnvironment(this.context, "VCAP_APPLICATION:---",
"vcap.application.application_id:my-app-id");
TestPropertyValues.of("VCAP_APPLICATION:---",
"vcap.application.application_id:my-app-id").applyTo(this.context);
this.context.refresh();
CloudFoundryEndpointHandlerMapping handlerMapping = this.context.getBean(
"cloudFoundryEndpointHandlerMapping",
@@ -152,8 +152,8 @@ public class CloudFoundryActuatorAutoConfigurationTests {
@Test
public void cloudFoundryPathsIgnoredBySpringSecurity() throws Exception {
EnvironmentTestUtils.addEnvironment(this.context, "VCAP_APPLICATION:---",
"vcap.application.application_id:my-app-id");
TestPropertyValues.of("VCAP_APPLICATION:---",
"vcap.application.application_id:my-app-id").applyTo(this.context);
this.context.refresh();
IgnoredRequestCustomizer customizer = (IgnoredRequestCustomizer) this.context
.getBean("cloudFoundryIgnoredRequestCustomizer");
@@ -179,17 +179,17 @@ public class CloudFoundryActuatorAutoConfigurationTests {
@Test
public void cloudFoundryManagementEndpointsDisabled() throws Exception {
EnvironmentTestUtils.addEnvironment(this.context, "VCAP_APPLICATION=---",
"management.cloudfoundry.enabled:false");
TestPropertyValues.of("VCAP_APPLICATION=---",
"management.cloudfoundry.enabled:false").applyTo(this.context);
this.context.refresh();
assertThat(this.context.containsBean("cloudFoundryEndpointHandlerMapping"))
.isFalse();
}
private CloudFoundryEndpointHandlerMapping getHandlerMapping() {
EnvironmentTestUtils.addEnvironment(this.context, "VCAP_APPLICATION:---",
TestPropertyValues.of("VCAP_APPLICATION:---",
"vcap.application.application_id:my-app-id",
"vcap.application.cf_api:http://my-cloud-controller.com");
"vcap.application.cf_api:http://my-cloud-controller.com").applyTo(this.context);
this.context.refresh();
return this.context.getBean("cloudFoundryEndpointHandlerMapping",
CloudFoundryEndpointHandlerMapping.class);

View File

@@ -26,7 +26,7 @@ import org.junit.Before;
import org.junit.Test;
import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.core.env.MapPropertySource;
import org.springframework.core.env.PropertySource;
@@ -89,7 +89,7 @@ public abstract class AbstractEndpointTests<T extends Endpoint<?>> {
@Test
public void idOverride() throws Exception {
this.context = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(this.context, this.property + ".id:myid");
TestPropertyValues.of(this.property + ".id:myid").applyTo(this.context);
this.context.register(this.configClass);
this.context.refresh();
assertThat(getEndpointBean().getId()).isEqualTo("myid");

View File

@@ -24,7 +24,7 @@ import org.junit.Test;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -56,8 +56,8 @@ public class ConfigurationPropertiesReportEndpointMethodAnnotationsTests {
@SuppressWarnings("unchecked")
public void testNaming() throws Exception {
this.context.register(Config.class);
EnvironmentTestUtils.addEnvironment(this.context, "other.name:foo",
"first.name:bar");
TestPropertyValues.of("other.name:foo",
"first.name:bar").applyTo(this.context);
this.context.refresh();
ConfigurationPropertiesReportEndpoint report = this.context
.getBean(ConfigurationPropertiesReportEndpoint.class);
@@ -73,7 +73,7 @@ public class ConfigurationPropertiesReportEndpointMethodAnnotationsTests {
@SuppressWarnings("unchecked")
public void testOverride() throws Exception {
this.context.register(Other.class);
EnvironmentTestUtils.addEnvironment(this.context, "other.name:foo");
TestPropertyValues.of("other.name:foo").applyTo(this.context);
this.context.refresh();
ConfigurationPropertiesReportEndpoint report = this.context
.getBean(ConfigurationPropertiesReportEndpoint.class);

View File

@@ -28,7 +28,7 @@ import org.junit.Test;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -63,7 +63,7 @@ public class ConfigurationPropertiesReportEndpointSerializationTests {
@SuppressWarnings("unchecked")
public void testNaming() throws Exception {
this.context.register(FooConfig.class);
EnvironmentTestUtils.addEnvironment(this.context, "foo.name:foo");
TestPropertyValues.of("foo.name:foo").applyTo(this.context);
this.context.refresh();
ConfigurationPropertiesReportEndpoint report = this.context
.getBean(ConfigurationPropertiesReportEndpoint.class);
@@ -83,7 +83,7 @@ public class ConfigurationPropertiesReportEndpointSerializationTests {
@SuppressWarnings("unchecked")
public void testNestedNaming() throws Exception {
this.context.register(FooConfig.class);
EnvironmentTestUtils.addEnvironment(this.context, "foo.bar.name:foo");
TestPropertyValues.of("foo.bar.name:foo").applyTo(this.context);
this.context.refresh();
ConfigurationPropertiesReportEndpoint report = this.context
.getBean(ConfigurationPropertiesReportEndpoint.class);
@@ -102,7 +102,7 @@ public class ConfigurationPropertiesReportEndpointSerializationTests {
@SuppressWarnings("unchecked")
public void testCycle() throws Exception {
this.context.register(CycleConfig.class);
EnvironmentTestUtils.addEnvironment(this.context, "foo.name:foo");
TestPropertyValues.of("foo.name:foo").applyTo(this.context);
this.context.refresh();
ConfigurationPropertiesReportEndpoint report = this.context
.getBean(ConfigurationPropertiesReportEndpoint.class);
@@ -122,7 +122,7 @@ public class ConfigurationPropertiesReportEndpointSerializationTests {
@SuppressWarnings("unchecked")
public void testMap() throws Exception {
this.context.register(MapConfig.class);
EnvironmentTestUtils.addEnvironment(this.context, "foo.map.name:foo");
TestPropertyValues.of("foo.map.name:foo").applyTo(this.context);
this.context.refresh();
ConfigurationPropertiesReportEndpoint report = this.context
.getBean(ConfigurationPropertiesReportEndpoint.class);
@@ -162,7 +162,7 @@ public class ConfigurationPropertiesReportEndpointSerializationTests {
@SuppressWarnings("unchecked")
public void testList() throws Exception {
this.context.register(ListConfig.class);
EnvironmentTestUtils.addEnvironment(this.context, "foo.list[0]:foo");
TestPropertyValues.of("foo.list[0]:foo").applyTo(this.context);
this.context.refresh();
ConfigurationPropertiesReportEndpoint report = this.context
.getBean(ConfigurationPropertiesReportEndpoint.class);
@@ -182,7 +182,7 @@ public class ConfigurationPropertiesReportEndpointSerializationTests {
@SuppressWarnings("unchecked")
public void testInetAddress() throws Exception {
this.context.register(AddressedConfig.class);
EnvironmentTestUtils.addEnvironment(this.context, "foo.address:192.168.1.10");
TestPropertyValues.of("foo.address:192.168.1.10").applyTo(this.context);
this.context.refresh();
ConfigurationPropertiesReportEndpoint report = this.context
.getBean(ConfigurationPropertiesReportEndpoint.class);
@@ -203,8 +203,8 @@ public class ConfigurationPropertiesReportEndpointSerializationTests {
@SuppressWarnings("unchecked")
public void testInitializedMapAndList() throws Exception {
this.context.register(InitializedMapAndListPropertiesConfig.class);
EnvironmentTestUtils.addEnvironment(this.context, "foo.map.entryOne:true",
"foo.list[0]:abc");
TestPropertyValues.of("foo.map.entryOne:true",
"foo.list[0]:abc").applyTo(this.context);
this.context.refresh();
ConfigurationPropertiesReportEndpoint report = this.context
.getBean(ConfigurationPropertiesReportEndpoint.class);

View File

@@ -26,7 +26,7 @@ import org.junit.Test;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -130,8 +130,8 @@ public class ConfigurationPropertiesReportEndpointTests
@Test
public void testKeySanitizationWithCustomKeysByEnvironment() throws Exception {
this.context = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(this.context,
"endpoints.configprops.keys-to-sanitize:property");
TestPropertyValues.of(
"endpoints.configprops.keys-to-sanitize:property").applyTo(this.context);
this.context.register(Config.class);
this.context.refresh();
ConfigurationPropertiesReportEndpoint report = getEndpointBean();
@@ -147,8 +147,8 @@ public class ConfigurationPropertiesReportEndpointTests
@Test
public void testKeySanitizationWithCustomPatternByEnvironment() throws Exception {
this.context = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(this.context,
"endpoints.configprops.keys-to-sanitize: .*pass.*");
TestPropertyValues.of(
"endpoints.configprops.keys-to-sanitize: .*pass.*").applyTo(this.context);
this.context.register(Config.class);
this.context.refresh();
ConfigurationPropertiesReportEndpoint report = getEndpointBean();
@@ -165,8 +165,8 @@ public class ConfigurationPropertiesReportEndpointTests
public void testKeySanitizationWithCustomPatternAndKeyByEnvironment()
throws Exception {
this.context = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(this.context,
"endpoints.configprops.keys-to-sanitize: .*pass.*, property");
TestPropertyValues.of(
"endpoints.configprops.keys-to-sanitize: .*pass.*, property").applyTo(this.context);
this.context.register(Config.class);
this.context.refresh();
ConfigurationPropertiesReportEndpoint report = getEndpointBean();
@@ -184,8 +184,8 @@ public class ConfigurationPropertiesReportEndpointTests
throws Exception {
// gh-4415
this.context = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(this.context,
"endpoints.configprops.keys-to-sanitize: .*\\.secrets\\..*, .*\\.hidden\\..*");
TestPropertyValues.of(
"endpoints.configprops.keys-to-sanitize: .*\\.secrets\\..*, .*\\.hidden\\..*").applyTo(this.context);
this.context.register(Config.class);
this.context.refresh();
ConfigurationPropertiesReportEndpoint report = getEndpointBean();

View File

@@ -24,7 +24,7 @@ import org.junit.After;
import org.junit.Test;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -151,8 +151,8 @@ public class EnvironmentEndpointTests extends AbstractEndpointTests<EnvironmentE
@Test
public void testKeySanitizationWithCustomKeysByEnvironment() throws Exception {
this.context = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(this.context,
"endpoints.env.keys-to-sanitize: key");
TestPropertyValues.of(
"endpoints.env.keys-to-sanitize: key").applyTo(this.context);
this.context.register(Config.class);
this.context.refresh();
System.setProperty("dbPassword", "123456");
@@ -170,8 +170,8 @@ public class EnvironmentEndpointTests extends AbstractEndpointTests<EnvironmentE
@Test
public void testKeySanitizationWithCustomPatternByEnvironment() throws Exception {
this.context = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(this.context,
"endpoints.env.keys-to-sanitize: .*pass.*");
TestPropertyValues.of(
"endpoints.env.keys-to-sanitize: .*pass.*").applyTo(this.context);
this.context.register(Config.class);
this.context.refresh();
System.setProperty("dbPassword", "123456");
@@ -190,8 +190,8 @@ public class EnvironmentEndpointTests extends AbstractEndpointTests<EnvironmentE
public void testKeySanitizationWithCustomPatternAndKeyByEnvironment()
throws Exception {
this.context = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(this.context,
"endpoints.env.keys-to-sanitize: .*pass.*, key");
TestPropertyValues.of(
"endpoints.env.keys-to-sanitize: .*pass.*, key").applyTo(this.context);
this.context.register(Config.class);
this.context.refresh();
System.setProperty("dbPassword", "123456");
@@ -209,8 +209,8 @@ public class EnvironmentEndpointTests extends AbstractEndpointTests<EnvironmentE
@Test
public void propertyWithPlaceholderResolved() throws Exception {
this.context = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(this.context, "my.foo: ${bar.blah}",
"bar.blah: hello");
TestPropertyValues.of("my.foo: ${bar.blah}",
"bar.blah: hello").applyTo(this.context);
this.context.register(Config.class);
this.context.refresh();
EnvironmentEndpoint report = getEndpointBean();
@@ -223,7 +223,7 @@ public class EnvironmentEndpointTests extends AbstractEndpointTests<EnvironmentE
@Test
public void propertyWithPlaceholderNotResolved() throws Exception {
this.context = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(this.context, "my.foo: ${bar.blah}");
TestPropertyValues.of("my.foo: ${bar.blah}").applyTo(this.context);
this.context.register(Config.class);
this.context.refresh();
EnvironmentEndpoint report = getEndpointBean();
@@ -236,8 +236,8 @@ public class EnvironmentEndpointTests extends AbstractEndpointTests<EnvironmentE
@Test
public void propertyWithSensitivePlaceholderResolved() throws Exception {
this.context = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(this.context,
"my.foo: http://${bar.password}://hello", "bar.password: hello");
TestPropertyValues.of(
"my.foo: http://${bar.password}://hello", "bar.password: hello").applyTo(this.context);
this.context.register(Config.class);
this.context.refresh();
EnvironmentEndpoint report = getEndpointBean();
@@ -250,8 +250,8 @@ public class EnvironmentEndpointTests extends AbstractEndpointTests<EnvironmentE
@Test
public void propertyWithSensitivePlaceholderNotResolved() throws Exception {
this.context = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(this.context,
"my.foo: http://${bar.password}://hello");
TestPropertyValues.of(
"my.foo: http://${bar.password}://hello").applyTo(this.context);
this.context.register(Config.class);
this.context.refresh();
EnvironmentEndpoint report = getEndpointBean();

View File

@@ -32,7 +32,7 @@ import org.springframework.boot.autoconfigure.http.HttpMessageConvertersAutoConf
import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration;
import org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -76,8 +76,8 @@ public class EnvironmentMvcEndpointTests {
public void setUp() {
this.context.getBean(EnvironmentEndpoint.class).setEnabled(true);
this.mvc = MockMvcBuilders.webAppContextSetup(this.context).build();
EnvironmentTestUtils.addEnvironment((ConfigurableApplicationContext) this.context,
"foo:bar", "fool:baz");
TestPropertyValues.of(
"foo:bar", "fool:baz").applyTo((ConfigurableApplicationContext) this.context);
}
@Test

View File

@@ -30,7 +30,7 @@ import org.springframework.boot.autoconfigure.http.HttpMessageConvertersAutoConf
import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.ApplicationContextInitializer;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Configuration;
@@ -71,8 +71,7 @@ public class JolokiaMvcEndpointContextPathTests {
@Before
public void setUp() {
this.mvc = MockMvcBuilders.webAppContextSetup(this.context).build();
EnvironmentTestUtils.addEnvironment((ConfigurableApplicationContext) this.context,
"foo:bar");
TestPropertyValues.of("foo:bar").applyTo((ConfigurableApplicationContext) this.context);
}
@Test
@@ -97,7 +96,7 @@ public class JolokiaMvcEndpointContextPathTests {
@Override
public void initialize(ConfigurableApplicationContext context) {
EnvironmentTestUtils.addEnvironment(context, "management.contextPath:/admin");
TestPropertyValues.of("management.contextPath:/admin").applyTo(context);
}
}

View File

@@ -30,7 +30,7 @@ import org.springframework.boot.autoconfigure.http.HttpMessageConvertersAutoConf
import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
@@ -67,8 +67,7 @@ public class JolokiaMvcEndpointIntegrationTests {
@Before
public void setUp() {
this.mvc = MockMvcBuilders.webAppContextSetup(this.context).build();
EnvironmentTestUtils.addEnvironment((ConfigurableApplicationContext) this.context,
"foo:bar");
TestPropertyValues.of("foo:bar").applyTo((ConfigurableApplicationContext) this.context);
}
@Test

View File

@@ -27,7 +27,7 @@ import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoCon
import org.springframework.boot.autoconfigure.http.HttpMessageConvertersAutoConfiguration;
import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration;
import org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.http.HttpHeaders;
import org.springframework.mock.web.MockServletContext;
import org.springframework.test.web.servlet.MockMvc;
@@ -70,8 +70,8 @@ public class MvcEndpointCorsIntegrationTests {
@Test
public void settingAllowedOriginsEnablesCors() throws Exception {
EnvironmentTestUtils.addEnvironment(this.context,
"endpoints.cors.allowed-origins:foo.example.com");
TestPropertyValues.of(
"endpoints.cors.allowed-origins:foo.example.com").applyTo(this.context);
createMockMvc()
.perform(options("/application/beans").header("Origin", "bar.example.com")
.header(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "GET"))
@@ -81,25 +81,25 @@ public class MvcEndpointCorsIntegrationTests {
@Test
public void maxAgeDefaultsTo30Minutes() throws Exception {
EnvironmentTestUtils.addEnvironment(this.context,
"endpoints.cors.allowed-origins:foo.example.com");
TestPropertyValues.of(
"endpoints.cors.allowed-origins:foo.example.com").applyTo(this.context);
performAcceptedCorsRequest()
.andExpect(header().string(HttpHeaders.ACCESS_CONTROL_MAX_AGE, "1800"));
}
@Test
public void maxAgeCanBeConfigured() throws Exception {
EnvironmentTestUtils.addEnvironment(this.context,
TestPropertyValues.of(
"endpoints.cors.allowed-origins:foo.example.com",
"endpoints.cors.max-age: 2400");
"endpoints.cors.max-age: 2400").applyTo(this.context);
performAcceptedCorsRequest()
.andExpect(header().string(HttpHeaders.ACCESS_CONTROL_MAX_AGE, "2400"));
}
@Test
public void requestsWithDisallowedHeadersAreRejected() throws Exception {
EnvironmentTestUtils.addEnvironment(this.context,
"endpoints.cors.allowed-origins:foo.example.com");
TestPropertyValues.of(
"endpoints.cors.allowed-origins:foo.example.com").applyTo(this.context);
createMockMvc()
.perform(options("/application/beans").header("Origin", "foo.example.com")
.header(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "GET")
@@ -109,9 +109,9 @@ public class MvcEndpointCorsIntegrationTests {
@Test
public void allowedHeadersCanBeConfigured() throws Exception {
EnvironmentTestUtils.addEnvironment(this.context,
TestPropertyValues.of(
"endpoints.cors.allowed-origins:foo.example.com",
"endpoints.cors.allowed-headers:Alpha,Bravo");
"endpoints.cors.allowed-headers:Alpha,Bravo").applyTo(this.context);
createMockMvc()
.perform(options("/application/beans").header("Origin", "foo.example.com")
.header(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "GET")
@@ -122,8 +122,8 @@ public class MvcEndpointCorsIntegrationTests {
@Test
public void requestsWithDisallowedMethodsAreRejected() throws Exception {
EnvironmentTestUtils.addEnvironment(this.context,
"endpoints.cors.allowed-origins:foo.example.com");
TestPropertyValues.of(
"endpoints.cors.allowed-origins:foo.example.com").applyTo(this.context);
createMockMvc()
.perform(options("/application/health").header(HttpHeaders.ORIGIN, "foo.example.com")
.header(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "PATCH"))
@@ -132,9 +132,9 @@ public class MvcEndpointCorsIntegrationTests {
@Test
public void allowedMethodsCanBeConfigured() throws Exception {
EnvironmentTestUtils.addEnvironment(this.context,
TestPropertyValues.of(
"endpoints.cors.allowed-origins:foo.example.com",
"endpoints.cors.allowed-methods:GET,HEAD");
"endpoints.cors.allowed-methods:GET,HEAD").applyTo(this.context);
createMockMvc()
.perform(options("/application/health").header(HttpHeaders.ORIGIN, "foo.example.com")
.header(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "HEAD"))
@@ -144,26 +144,26 @@ public class MvcEndpointCorsIntegrationTests {
@Test
public void credentialsCanBeAllowed() throws Exception {
EnvironmentTestUtils.addEnvironment(this.context,
TestPropertyValues.of(
"endpoints.cors.allowed-origins:foo.example.com",
"endpoints.cors.allow-credentials:true");
"endpoints.cors.allow-credentials:true").applyTo(this.context);
performAcceptedCorsRequest().andExpect(
header().string(HttpHeaders.ACCESS_CONTROL_ALLOW_CREDENTIALS, "true"));
}
@Test
public void credentialsCanBeDisabled() throws Exception {
EnvironmentTestUtils.addEnvironment(this.context,
TestPropertyValues.of(
"endpoints.cors.allowed-origins:foo.example.com",
"endpoints.cors.allow-credentials:false");
"endpoints.cors.allow-credentials:false").applyTo(this.context);
performAcceptedCorsRequest().andExpect(
header().doesNotExist(HttpHeaders.ACCESS_CONTROL_ALLOW_CREDENTIALS));
}
@Test
public void jolokiaEndpointUsesGlobalCorsConfiguration() throws Exception {
EnvironmentTestUtils.addEnvironment(this.context,
"endpoints.cors.allowed-origins:foo.example.com");
TestPropertyValues.of(
"endpoints.cors.allowed-origins:foo.example.com").applyTo(this.context);
createMockMvc()
.perform(options("/application/jolokia").header("Origin", "bar.example.com")
.header(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "GET"))

View File

@@ -31,7 +31,7 @@ import org.springframework.boot.autoconfigure.http.HttpMessageConvertersAutoConf
import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration;
import org.springframework.boot.autoconfigure.security.SecurityAutoConfiguration;
import org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.annotation.Import;
import org.springframework.mock.web.MockServletContext;
import org.springframework.security.authentication.TestingAuthenticationToken;
@@ -124,8 +124,8 @@ public class MvcEndpointIntegrationTests {
throws Exception {
this.context = new AnnotationConfigWebApplicationContext();
this.context.register(SecureConfiguration.class);
EnvironmentTestUtils.addEnvironment(this.context,
"management.context-path:/management");
TestPropertyValues.of(
"management.context-path:/management").applyTo(this.context);
MockMvc mockMvc = createSecureMockMvc();
mockMvc.perform(get("/management/info")).andExpect(status().isOk());
mockMvc.perform(get("/management")).andExpect(status().isOk());
@@ -144,8 +144,8 @@ public class MvcEndpointIntegrationTests {
throws Exception {
this.context = new AnnotationConfigWebApplicationContext();
this.context.register(SecureConfiguration.class);
EnvironmentTestUtils.addEnvironment(this.context,
"management.context-path:/management");
TestPropertyValues.of(
"management.context-path:/management").applyTo(this.context);
MockMvc mockMvc = createSecureMockMvc();
mockMvc.perform(get("/management/beans")).andExpect(status().isUnauthorized());
}
@@ -157,8 +157,8 @@ public class MvcEndpointIntegrationTests {
new TestingAuthenticationToken("user", "N/A", "ROLE_USER"));
this.context = new AnnotationConfigWebApplicationContext();
this.context.register(SecureConfiguration.class);
EnvironmentTestUtils.addEnvironment(this.context,
"management.context-path:/management");
TestPropertyValues.of(
"management.context-path:/management").applyTo(this.context);
MockMvc mockMvc = createSecureMockMvc();
mockMvc.perform(get("/management/beans")).andExpect(status().isForbidden());
}
@@ -170,8 +170,8 @@ public class MvcEndpointIntegrationTests {
new TestingAuthenticationToken("user", "N/A", "ROLE_ACTUATOR"));
this.context = new AnnotationConfigWebApplicationContext();
this.context.register(SecureConfiguration.class);
EnvironmentTestUtils.addEnvironment(this.context,
"management.context-path:/management");
TestPropertyValues.of(
"management.context-path:/management").applyTo(this.context);
MockMvc mockMvc = createSecureMockMvc();
mockMvc.perform(get("/management/beans")).andExpect(status().isOk());
}
@@ -180,9 +180,9 @@ public class MvcEndpointIntegrationTests {
public void endpointSecurityCanBeDisabledWithCustomContextPath() throws Exception {
this.context = new AnnotationConfigWebApplicationContext();
this.context.register(SecureConfiguration.class);
EnvironmentTestUtils.addEnvironment(this.context,
TestPropertyValues.of(
"management.context-path:/management",
"management.security.enabled:false");
"management.security.enabled:false").applyTo(this.context);
MockMvc mockMvc = createSecureMockMvc();
mockMvc.perform(get("/management/beans")).andExpect(status().isOk());
}
@@ -191,8 +191,8 @@ public class MvcEndpointIntegrationTests {
public void endpointSecurityCanBeDisabled() throws Exception {
this.context = new AnnotationConfigWebApplicationContext();
this.context.register(SecureConfiguration.class);
EnvironmentTestUtils.addEnvironment(this.context,
"management.security.enabled:false");
TestPropertyValues.of(
"management.security.enabled:false").applyTo(this.context);
MockMvc mockMvc = createSecureMockMvc();
mockMvc.perform(get("/application/beans")).andExpect(status().isOk());
}
@@ -202,8 +202,8 @@ public class MvcEndpointIntegrationTests {
new TestingAuthenticationToken("user", "N/A", "ROLE_ACTUATOR"));
this.context = new AnnotationConfigWebApplicationContext();
this.context.register(configuration);
EnvironmentTestUtils.addEnvironment(this.context,
"spring.jackson.serialization.indent-output:true");
TestPropertyValues.of(
"spring.jackson.serialization.indent-output:true").applyTo(this.context);
MockMvc mockMvc = createSecureMockMvc();
mockMvc.perform(get("/application/mappings"))
.andExpect(content().string(startsWith("{" + LINE_SEPARATOR)));

View File

@@ -21,7 +21,7 @@ import org.junit.Test;
import org.springframework.boot.actuate.endpoint.AbstractEndpoint;
import org.springframework.boot.actuate.endpoint.Endpoint;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.support.StaticApplicationContext;
import static org.assertj.core.api.Assertions.assertThat;
@@ -68,8 +68,8 @@ public class MvcEndpointsTests {
@Test
public void changesPath() throws Exception {
EnvironmentTestUtils.addEnvironment(this.context,
"endpoints.test.path=/foo/bar/");
TestPropertyValues.of(
"endpoints.test.path=/foo/bar/").applyTo(this.context);
this.context.getDefaultListableBeanFactory().registerSingleton("endpoint",
new TestEndpoint());
this.endpoints.setApplicationContext(this.context);

View File

@@ -33,7 +33,7 @@ import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration;
import org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration;
import org.springframework.boot.junit.runner.classpath.ClassPathExclusions;
import org.springframework.boot.junit.runner.classpath.ModifiedClassPathRunner;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.mock.web.MockHttpServletRequest;
@@ -84,8 +84,8 @@ public class NoSpringSecurityHealthMvcEndpointIntegrationTests {
this.context = new AnnotationConfigWebApplicationContext();
this.context.setServletContext(new MockServletContext());
this.context.register(TestConfiguration.class);
EnvironmentTestUtils.addEnvironment(this.context,
"management.security.enabled:false");
TestPropertyValues.of(
"management.security.enabled:false").applyTo(this.context);
this.context.refresh();
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(this.context).build();
mockMvc.perform(get("/application/health")).andExpect(status().isOk())

View File

@@ -16,16 +16,14 @@
package org.springframework.boot.actuate.info;
import java.util.Collections;
import java.util.Map;
import org.junit.Test;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.boot.test.util.TestPropertyValues.Type;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.MutablePropertySources;
import org.springframework.core.env.StandardEnvironment;
import org.springframework.core.env.SystemEnvironmentPropertySource;
import static org.assertj.core.api.Assertions.assertThat;
@@ -40,8 +38,8 @@ public class EnvironmentInfoContributorTests {
@Test
public void extractOnlyInfoProperty() {
EnvironmentTestUtils.addEnvironment(this.environment, "info.app=my app",
"info.version=1.0.0", "foo=bar");
TestPropertyValues.of("info.app=my app",
"info.version=1.0.0", "foo=bar").applyTo(this.environment);
Info actual = contributeFrom(this.environment);
assertThat(actual.get("app", String.class)).isEqualTo("my app");
assertThat(actual.get("version", String.class)).isEqualTo("1.0.0");
@@ -50,7 +48,7 @@ public class EnvironmentInfoContributorTests {
@Test
public void extractNoEntry() {
EnvironmentTestUtils.addEnvironment(this.environment, "foo=bar");
TestPropertyValues.of("foo=bar").applyTo(this.environment);
Info actual = contributeFrom(this.environment);
assertThat(actual.getDetails().size()).isEqualTo(0);
}
@@ -58,9 +56,7 @@ public class EnvironmentInfoContributorTests {
@Test
@SuppressWarnings("unchecked")
public void propertiesFromEnvironmentShouldBindCorrectly() throws Exception {
MutablePropertySources propertySources = this.environment.getPropertySources();
propertySources.addFirst(new SystemEnvironmentPropertySource("system",
Collections.singletonMap("INFO_ENVIRONMENT_FOO", "green")));
TestPropertyValues.of("INFO_ENVIRONMENT_FOO=green").applyTo(this.environment, Type.SYSTEM);
Info actual = contributeFrom(this.environment);
assertThat(actual.get("environment", Map.class)).containsEntry("foo", "green");
}

View File

@@ -38,7 +38,7 @@ import org.springframework.boot.autoconfigure.jmx.JmxAutoConfiguration;
import org.springframework.boot.autoconfigure.web.servlet.DispatcherServletAutoConfiguration;
import org.springframework.boot.autoconfigure.web.servlet.ServletWebServerFactoryAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
@@ -175,7 +175,7 @@ public class SpringApplicationAdminJmxAutoConfigurationTests {
private void load(String... environment) {
AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(applicationContext, environment);
TestPropertyValues.of(environment).applyTo(applicationContext);
applicationContext.register(JmxAutoConfiguration.class,
SpringApplicationAdminJmxAutoConfiguration.class);
applicationContext.refresh();

View File

@@ -45,7 +45,7 @@ import org.springframework.amqp.rabbit.support.ValueExpression;
import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.beans.DirectFieldAccessor;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -497,7 +497,7 @@ public class RabbitAutoConfigurationTests {
AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();
applicationContext.register(configs);
applicationContext.register(RabbitAutoConfiguration.class);
EnvironmentTestUtils.addEnvironment(applicationContext, environment);
TestPropertyValues.of(environment).applyTo(applicationContext);
applicationContext.refresh();
this.context = applicationContext;
}

View File

@@ -21,7 +21,7 @@ import org.aspectj.lang.annotation.Before;
import org.junit.After;
import org.junit.Test;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -101,7 +101,7 @@ public class AopAutoConfigurationTests {
private void load(Class<?> config, String... environment) {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(config);
EnvironmentTestUtils.addEnvironment(ctx, environment);
TestPropertyValues.of(environment).applyTo(ctx);
ctx.register(AopAutoConfiguration.class);
ctx.refresh();
this.context = ctx;

View File

@@ -53,7 +53,7 @@ import org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfigurati
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
import org.springframework.boot.autoconfigure.orm.jpa.test.City;
import org.springframework.boot.autoconfigure.transaction.TransactionAutoConfiguration;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -263,7 +263,7 @@ public class BatchAutoConfigurationTests {
private void load(Class<?>[] configs, String... environment) {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(ctx, environment);
TestPropertyValues.of(environment).applyTo(ctx);
if (configs != null) {
ctx.register(configs);
}

View File

@@ -34,7 +34,7 @@ import org.springframework.boot.autoconfigure.orm.jpa.test.City;
import org.springframework.boot.autoconfigure.transaction.TransactionAutoConfiguration;
import org.springframework.boot.junit.runner.classpath.ClassPathExclusions;
import org.springframework.boot.junit.runner.classpath.ModifiedClassPathRunner;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.transaction.PlatformTransactionManager;
@@ -100,7 +100,7 @@ public class BatchAutoConfigurationWithoutJpaTests {
private void load(Class<?>[] configs, String... environment) {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(ctx, environment);
TestPropertyValues.of(environment).applyTo(ctx);
if (configs != null) {
ctx.register(configs);
}

View File

@@ -58,7 +58,7 @@ import org.springframework.boot.autoconfigure.cache.support.MockCachingProvider;
import org.springframework.boot.autoconfigure.hazelcast.HazelcastAutoConfiguration;
import org.springframework.boot.junit.runner.classpath.ClassPathExclusions;
import org.springframework.boot.junit.runner.classpath.ModifiedClassPathRunner;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.cache.Cache;
import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.CachingConfigurerSupport;
@@ -697,7 +697,7 @@ public class CacheAutoConfigurationTests {
private void load(Class<?>[] configs, String... environment) {
AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(applicationContext, environment);
TestPropertyValues.of(environment).applyTo(applicationContext);
applicationContext.register(configs);
applicationContext.register(CacheAutoConfiguration.class);
applicationContext.refresh();

View File

@@ -21,7 +21,7 @@ import org.junit.After;
import org.junit.Test;
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -91,7 +91,7 @@ public class CassandraAutoConfigurationTests {
}
ctx.register(PropertyPlaceholderAutoConfiguration.class,
CassandraAutoConfiguration.class);
EnvironmentTestUtils.addEnvironment(ctx, environment);
TestPropertyValues.of(environment).applyTo(ctx);
ctx.refresh();
this.context = ctx;
}

View File

@@ -18,7 +18,7 @@ package org.springframework.boot.autoconfigure.condition;
import org.junit.Test;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Condition;
@@ -64,7 +64,7 @@ public class AllNestedConditionsTests {
private AnnotationConfigApplicationContext load(Class<?> config, String... env) {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(context, env);
TestPropertyValues.of(env).applyTo(context);
context.register(config);
context.refresh();
return context;

View File

@@ -18,7 +18,7 @@ package org.springframework.boot.autoconfigure.condition;
import org.junit.Test;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Condition;
@@ -67,7 +67,7 @@ public class AnyNestedConditionTests {
private AnnotationConfigApplicationContext load(Class<?> config, String... env) {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(context, env);
TestPropertyValues.of(env).applyTo(context);
context.register(config);
context.refresh();
return context;

View File

@@ -32,7 +32,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionEvaluationRepor
import org.springframework.boot.autoconfigure.condition.ConditionEvaluationReport.ConditionAndOutcomes;
import org.springframework.boot.autoconfigure.web.servlet.MultipartAutoConfiguration;
import org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.boot.testutil.Matched;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
@@ -227,7 +227,7 @@ public class ConditionEvaluationReportTests {
@Test
public void negativeOuterPositiveInnerBean() throws Exception {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(context, "test.present=true");
TestPropertyValues.of("test.present=true").applyTo(context);
context.register(NegativeOuterConfig.class);
context.refresh();
ConditionEvaluationReport report = ConditionEvaluationReport

View File

@@ -28,7 +28,7 @@ import org.junit.Test;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -124,7 +124,7 @@ public class ConditionalOnBeanTests {
@Test
public void withPropertyPlaceholderClassName() throws Exception {
EnvironmentTestUtils.addEnvironment(this.context, "mybeanclass=java.lang.String");
TestPropertyValues.of("mybeanclass=java.lang.String").applyTo(this.context);
this.context.register(PropertySourcesPlaceholderConfigurer.class,
WithPropertyPlaceholderClassName.class, OnBeanClassConfiguration.class);
this.context.refresh();

View File

@@ -20,7 +20,7 @@ import org.junit.After;
import org.junit.Test;
import org.springframework.boot.cloud.CloudPlatform;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -62,7 +62,7 @@ public class ConditionalOnCloudPlatformTests {
}
private void load(Class<?> config, String... environment) {
EnvironmentTestUtils.addEnvironment(this.context, environment);
TestPropertyValues.of(environment).applyTo(this.context);
this.context.register(config);
this.context.refresh();
}

View File

@@ -27,7 +27,7 @@ import org.junit.Test;
import org.springframework.boot.autoconfigure.jndi.JndiPropertiesHidingClassLoader;
import org.springframework.boot.autoconfigure.jndi.TestableInitialContextFactory;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
@@ -133,7 +133,7 @@ public class ConditionalOnJndiTests {
private void load(Class<?> config, String... environment) {
AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(applicationContext, environment);
TestPropertyValues.of(environment).applyTo(applicationContext);
applicationContext.register(config);
applicationContext.register(JndiConditionConfiguration.class);
applicationContext.refresh();

View File

@@ -32,7 +32,7 @@ import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.boot.autoconfigure.condition.scan.ScannedFactoryBeanConfiguration;
import org.springframework.boot.autoconfigure.condition.scan.ScannedFactoryBeanWithBeanMethodArgumentsConfiguration;
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
@@ -176,7 +176,7 @@ public class ConditionalOnMissingBeanTests {
this.context.register(FactoryBeanWithBeanMethodArgumentsConfiguration.class,
ConditionalOnFactoryBean.class,
PropertyPlaceholderAutoConfiguration.class);
EnvironmentTestUtils.addEnvironment(this.context, "theValue:foo");
TestPropertyValues.of("theValue:foo").applyTo(this.context);
this.context.refresh();
assertThat(this.context.getBean(ExampleBean.class).toString())
.isEqualTo("fromFactory");

View File

@@ -28,7 +28,7 @@ import org.junit.rules.ExpectedException;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -258,7 +258,7 @@ public class ConditionalOnPropertyTests {
}
private void load(Class<?> config, String... environment) {
EnvironmentTestUtils.addEnvironment(this.environment, environment);
TestPropertyValues.of(environment).applyTo(this.environment);
this.context = new SpringApplicationBuilder(config).environment(this.environment)
.web(WebApplicationType.NONE).run();
}

View File

@@ -18,7 +18,7 @@ package org.springframework.boot.autoconfigure.condition;
import org.junit.Test;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -44,7 +44,7 @@ public class ConditionalOnResourceTests {
@Test
public void testResourceExistsWithPlaceholder() {
EnvironmentTestUtils.addEnvironment(this.context, "schema=schema.sql");
TestPropertyValues.of("schema=schema.sql").applyTo(this.context);
this.context.register(PlaceholderConfiguration.class);
this.context.refresh();
assertThat(this.context.containsBean("foo")).isTrue();

View File

@@ -18,7 +18,7 @@ package org.springframework.boot.autoconfigure.condition;
import org.junit.Test;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Condition;
@@ -64,7 +64,7 @@ public class NoneNestedConditionsTests {
private AnnotationConfigApplicationContext load(Class<?> config, String... env) {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(context, env);
TestPropertyValues.of(env).applyTo(context);
context.register(config);
context.refresh();
return context;

View File

@@ -19,7 +19,7 @@ package org.springframework.boot.autoconfigure.condition;
import org.junit.After;
import org.junit.Test;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
@@ -65,7 +65,7 @@ public class ResourceConditionTests {
private void load(Class<?> config, String... environment) {
AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(applicationContext, environment);
TestPropertyValues.of(environment).applyTo(applicationContext);
applicationContext.register(config);
applicationContext.refresh();
this.context = applicationContext;

View File

@@ -21,7 +21,7 @@ import org.junit.Test;
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
@@ -59,7 +59,7 @@ public class ConfigurationPropertiesAutoConfigurationTests {
private void load(Class<?>[] configs, String... environment) {
this.context = new AnnotationConfigApplicationContext();
this.context.register(configs);
EnvironmentTestUtils.addEnvironment(this.context, environment);
TestPropertyValues.of(environment).applyTo(this.context);
this.context.refresh();
}

View File

@@ -22,7 +22,7 @@ import org.junit.After;
import org.junit.Ignore;
import org.junit.Test;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.MessageSource;
import org.springframework.context.MessageSourceResolvable;
@@ -147,8 +147,8 @@ public class MessageSourceAutoConfigurationTests {
parent.refresh();
this.context = new AnnotationConfigApplicationContext();
this.context.setParent(parent);
EnvironmentTestUtils.addEnvironment(this.context,
"spring.messages.basename:test/messages");
TestPropertyValues.of(
"spring.messages.basename:test/messages").applyTo(this.context);
this.context.register(MessageSourceAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class);
this.context.refresh();
@@ -159,7 +159,7 @@ public class MessageSourceAutoConfigurationTests {
private void load(String... environment) {
this.context = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(this.context, environment);
TestPropertyValues.of(environment).applyTo(this.context);
this.context.register(MessageSourceAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class);
this.context.refresh();

View File

@@ -20,7 +20,7 @@ import org.junit.After;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -49,7 +49,7 @@ public class PropertyPlaceholderAutoConfigurationTests {
public void propertyPlaceholders() throws Exception {
this.context.register(PropertyPlaceholderAutoConfiguration.class,
PlaceholderConfig.class);
EnvironmentTestUtils.addEnvironment(this.context, "foo:two");
TestPropertyValues.of("foo:two").applyTo(this.context);
this.context.refresh();
assertThat(this.context.getBean(PlaceholderConfig.class).getFoo())
.isEqualTo("two");
@@ -59,7 +59,7 @@ public class PropertyPlaceholderAutoConfigurationTests {
public void propertyPlaceholdersOverride() throws Exception {
this.context.register(PropertyPlaceholderAutoConfiguration.class,
PlaceholderConfig.class, PlaceholdersOverride.class);
EnvironmentTestUtils.addEnvironment(this.context, "foo:two");
TestPropertyValues.of("foo:two").applyTo(this.context);
this.context.refresh();
assertThat(this.context.getBean(PlaceholderConfig.class).getFoo())
.isEqualTo("spam");

View File

@@ -19,7 +19,7 @@ package org.springframework.boot.autoconfigure.couchbase;
import org.junit.After;
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
/**
@@ -40,7 +40,7 @@ public abstract class AbstractCouchbaseAutoConfigurationTests {
protected void load(Class<?> config, String... environment) {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(context, environment);
TestPropertyValues.of(environment).applyTo(context);
if (config != null) {
context.register(config);
}

View File

@@ -19,7 +19,7 @@ package org.springframework.boot.autoconfigure.couchbase;
import org.junit.After;
import org.junit.Test;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;
@@ -75,7 +75,7 @@ public class OnBootstrapHostsConditionTests {
private void load(Class<?> config, String... environment) {
this.context = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(this.context, environment);
TestPropertyValues.of(environment).applyTo(this.context);
this.context.register(config);
this.context.refresh();
}

View File

@@ -26,7 +26,7 @@ import org.junit.Test;
import org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration;
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -66,8 +66,8 @@ public class PersistenceExceptionTranslationAutoConfigurationTests {
@Test
public void exceptionTranslationPostProcessorCanBeConfiguredToUseJdkProxy() {
this.context = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(this.context,
"spring.aop.proxy-target-class=false");
TestPropertyValues.of(
"spring.aop.proxy-target-class=false").applyTo(this.context);
this.context.register(PersistenceExceptionTranslationAutoConfiguration.class);
this.context.refresh();
Map<String, PersistenceExceptionTranslationPostProcessor> beans = this.context
@@ -79,8 +79,8 @@ public class PersistenceExceptionTranslationAutoConfigurationTests {
@Test
public void exceptionTranslationPostProcessorCanBeDisabled() {
this.context = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(this.context,
"spring.dao.exceptiontranslation.enabled=false");
TestPropertyValues.of(
"spring.dao.exceptiontranslation.enabled=false").applyTo(this.context);
this.context.register(PersistenceExceptionTranslationAutoConfiguration.class);
this.context.refresh();
Map<String, PersistenceExceptionTranslationPostProcessor> beans = this.context

View File

@@ -24,7 +24,7 @@ import org.junit.Test;
import org.springframework.boot.autoconfigure.AutoConfigurationPackages;
import org.springframework.boot.autoconfigure.cassandra.CassandraAutoConfiguration;
import org.springframework.boot.autoconfigure.data.cassandra.city.City;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.data.cassandra.config.CassandraSessionFactoryBean;
import org.springframework.data.cassandra.config.SchemaAction;
@@ -71,9 +71,9 @@ public class CassandraDataAutoConfigurationIntegrationTests {
this.context = new AnnotationConfigApplicationContext();
String cityPackage = City.class.getPackage().getName();
AutoConfigurationPackages.register(this.context, cityPackage);
EnvironmentTestUtils.addEnvironment(this.context,
TestPropertyValues.of(
"spring.data.cassandra.schemaAction=recreate_drop_unused",
"spring.data.cassandra.keyspaceName=boot_test");
"spring.data.cassandra.keyspaceName=boot_test").applyTo(this.context);
this.context.register(CassandraAutoConfiguration.class,
CassandraDataAutoConfiguration.class);
this.context.refresh();

View File

@@ -26,7 +26,7 @@ import org.springframework.boot.autoconfigure.cassandra.CassandraAutoConfigurati
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
import org.springframework.boot.autoconfigure.data.cassandra.city.City;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
@@ -60,8 +60,8 @@ public class CassandraDataAutoConfigurationTests {
@Test
public void templateExists() {
this.context = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(this.context,
"spring.data.cassandra.keyspaceName:boot_test");
TestPropertyValues.of(
"spring.data.cassandra.keyspaceName:boot_test").applyTo(this.context);
this.context.register(TestExcludeConfiguration.class, TestConfiguration.class,
PropertyPlaceholderAutoConfiguration.class,
CassandraAutoConfiguration.class, CassandraDataAutoConfiguration.class);
@@ -74,7 +74,7 @@ public class CassandraDataAutoConfigurationTests {
@SuppressWarnings("unchecked")
public void entityScanShouldSetInitialEntitySet() throws Exception {
this.context = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(this.context,
TestPropertyValues.of(
"spring.data.cassandra.keyspaceName:boot_test");
this.context.register(TestConfiguration.class, EntityScanConfig.class,
PropertyPlaceholderAutoConfiguration.class,
@@ -90,8 +90,8 @@ public class CassandraDataAutoConfigurationTests {
@Test
public void userTypeResolverShouldBeSet() throws Exception {
this.context = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(this.context,
"spring.data.cassandra.keyspaceName:boot_test");
TestPropertyValues.of(
"spring.data.cassandra.keyspaceName:boot_test").applyTo(this.context);
this.context.register(TestConfiguration.class,
PropertyPlaceholderAutoConfiguration.class,
CassandraAutoConfiguration.class, CassandraDataAutoConfiguration.class);

View File

@@ -25,7 +25,7 @@ import org.junit.Test;
import org.springframework.boot.autoconfigure.cassandra.CassandraAutoConfiguration;
import org.springframework.boot.autoconfigure.data.cassandra.city.City;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -88,7 +88,7 @@ public class CassandraReactiveDataAutoConfigurationTests {
private void load(Class<?> config, String... environment) {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(ctx, environment);
TestPropertyValues.of(environment).applyTo(ctx);
if (config != null) {
ctx.register(config);
}

View File

@@ -29,7 +29,7 @@ import org.springframework.boot.autoconfigure.couchbase.CouchbaseTestConfigurer;
import org.springframework.boot.autoconfigure.data.couchbase.city.City;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.boot.autoconfigure.validation.ValidationAutoConfiguration;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -135,7 +135,7 @@ public class CouchbaseDataAutoConfigurationTests {
private void load(Class<?> config, String... environment) {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(context, environment);
TestPropertyValues.of(environment).applyTo(context);
if (config != null) {
context.register(config);
}

View File

@@ -26,7 +26,7 @@ import org.springframework.boot.autoconfigure.couchbase.CouchbaseTestConfigurer;
import org.springframework.boot.autoconfigure.data.couchbase.city.City;
import org.springframework.boot.autoconfigure.data.couchbase.city.CityRepository;
import org.springframework.boot.autoconfigure.data.empty.EmptyDataPackage;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
@@ -77,7 +77,7 @@ public class CouchbaseRepositoriesAutoConfigurationTests {
private void load(Class<?> config, String... environment) {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(context, environment);
TestPropertyValues.of(environment).applyTo(context);
if (config != null) {
context.register(config);
}

View File

@@ -25,7 +25,7 @@ import org.junit.rules.ExpectedException;
import org.springframework.beans.factory.BeanCreationException;
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -55,9 +55,9 @@ public class ElasticsearchAutoConfigurationTests {
@Test
public void createNodeClientWithDefaults() {
this.context = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(this.context,
TestPropertyValues.of(
"spring.data.elasticsearch.properties.foo.bar:baz",
"spring.data.elasticsearch.properties.path.home:target");
"spring.data.elasticsearch.properties.path.home:target").applyTo(this.context);
this.context.register(PropertyPlaceholderAutoConfiguration.class,
ElasticsearchAutoConfiguration.class);
this.context.refresh();
@@ -71,12 +71,12 @@ public class ElasticsearchAutoConfigurationTests {
@Test
public void createNodeClientWithOverrides() {
this.context = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(this.context,
TestPropertyValues.of(
"spring.data.elasticsearch.properties.foo.bar:baz",
"spring.data.elasticsearch.properties.path.home:target",
"spring.data.elasticsearch.properties.node.local:false",
"spring.data.elasticsearch.properties.node.data:true",
"spring.data.elasticsearch.properties.http.enabled:true");
"spring.data.elasticsearch.properties.http.enabled:true").applyTo(this.context);
this.context.register(PropertyPlaceholderAutoConfiguration.class,
ElasticsearchAutoConfiguration.class);
this.context.refresh();
@@ -105,9 +105,9 @@ public class ElasticsearchAutoConfigurationTests {
// We don't have a local elasticsearch server so use an address that's missing
// a port and check the exception
this.context = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(this.context,
TestPropertyValues.of(
"spring.data.elasticsearch.cluster-nodes:localhost",
"spring.data.elasticsearch.properties.path.home:target");
"spring.data.elasticsearch.properties.path.home:target").applyTo(this.context);
this.context.register(PropertyPlaceholderAutoConfiguration.class,
ElasticsearchAutoConfiguration.class);
this.thrown.expect(BeanCreationException.class);

View File

@@ -20,7 +20,7 @@ import org.junit.After;
import org.junit.Test;
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
import org.springframework.data.elasticsearch.core.convert.ElasticsearchConverter;
@@ -48,9 +48,9 @@ public class ElasticsearchDataAutoConfigurationTests {
@Test
public void templateExists() {
this.context = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(this.context,
TestPropertyValues.of(
"spring.data.elasticsearch.properties.path.data:target/data",
"spring.data.elasticsearch.properties.path.logs:target/logs");
"spring.data.elasticsearch.properties.path.logs:target/logs").applyTo(this.context);
this.context.register(PropertyPlaceholderAutoConfiguration.class,
ElasticsearchAutoConfiguration.class,
ElasticsearchDataAutoConfiguration.class);
@@ -62,7 +62,7 @@ public class ElasticsearchDataAutoConfigurationTests {
@Test
public void mappingContextExists() {
this.context = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(this.context,
TestPropertyValues.of(
"spring.data.elasticsearch.properties.path.data:target/data",
"spring.data.elasticsearch.properties.path.logs:target/logs");
this.context.register(PropertyPlaceholderAutoConfiguration.class,
@@ -77,7 +77,7 @@ public class ElasticsearchDataAutoConfigurationTests {
@Test
public void converterExists() {
this.context = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(this.context,
TestPropertyValues.of(
"spring.data.elasticsearch.properties.path.data:target/data",
"spring.data.elasticsearch.properties.path.logs:target/logs");
this.context.register(PropertyPlaceholderAutoConfiguration.class,

View File

@@ -26,7 +26,7 @@ import org.springframework.boot.autoconfigure.data.alt.elasticsearch.CityElastic
import org.springframework.boot.autoconfigure.data.elasticsearch.city.City;
import org.springframework.boot.autoconfigure.data.elasticsearch.city.CityRepository;
import org.springframework.boot.autoconfigure.data.empty.EmptyDataPackage;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
@@ -88,8 +88,8 @@ public class ElasticsearchRepositoriesAutoConfigurationTests {
}
private void addElasticsearchProperties(AnnotationConfigApplicationContext context) {
EnvironmentTestUtils.addEnvironment(context,
"spring.data.elasticsearch.properties.path.home:target");
TestPropertyValues.of(
"spring.data.elasticsearch.properties.path.home:target").applyTo(context);
}
@Configuration

View File

@@ -21,7 +21,7 @@ import org.junit.Test;
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
import org.springframework.boot.autoconfigure.ldap.LdapAutoConfiguration;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.ldap.core.LdapTemplate;
@@ -46,8 +46,8 @@ public class LdapDataAutoConfigurationTests {
@Test
public void templateExists() {
this.context = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(this.context,
"spring.ldap.urls:ldap://localhost:389");
TestPropertyValues.of(
"spring.ldap.urls:ldap://localhost:389").applyTo(this.context);
this.context.register(PropertyPlaceholderAutoConfiguration.class,
LdapAutoConfiguration.class, LdapDataAutoConfiguration.class);
this.context.refresh();

View File

@@ -26,7 +26,7 @@ import org.springframework.boot.autoconfigure.data.empty.EmptyDataPackage;
import org.springframework.boot.autoconfigure.data.ldap.person.Person;
import org.springframework.boot.autoconfigure.data.ldap.person.PersonRepository;
import org.springframework.boot.autoconfigure.ldap.LdapAutoConfiguration;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.ldap.repository.config.EnableLdapRepositories;
@@ -69,8 +69,8 @@ public class LdapRepositoriesAutoConfigurationTests {
private void load(Class<?>... configurationClasses) {
this.context = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(this.context,
"spring.ldap.urls:ldap://localhost:389");
TestPropertyValues.of(
"spring.ldap.urls:ldap://localhost:389").applyTo(this.context);
this.context.register(configurationClasses);
this.context.register(LdapAutoConfiguration.class,
LdapDataAutoConfiguration.class, LdapRepositoriesAutoConfiguration.class,

View File

@@ -33,7 +33,7 @@ import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration;
import org.springframework.boot.autoconfigure.mongo.MongoAutoConfigurationTests;
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
@@ -62,8 +62,8 @@ public class MixedMongoRepositoriesAutoConfigurationTests {
@Test
public void testDefaultRepositoryConfiguration() throws Exception {
this.context = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(this.context,
"spring.datasource.initialize:false");
TestPropertyValues.of(
"spring.datasource.initialize:false").applyTo(this.context);
this.context.register(TestConfiguration.class, BaseConfiguration.class);
this.context.refresh();
assertThat(this.context.getBean(CountryRepository.class)).isNotNull();
@@ -72,8 +72,8 @@ public class MixedMongoRepositoriesAutoConfigurationTests {
@Test
public void testMixedRepositoryConfiguration() throws Exception {
this.context = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(this.context,
"spring.datasource.initialize:false");
TestPropertyValues.of(
"spring.datasource.initialize:false").applyTo(this.context);
this.context.register(MixedConfiguration.class, BaseConfiguration.class);
this.context.refresh();
assertThat(this.context.getBean(CountryRepository.class)).isNotNull();
@@ -83,8 +83,8 @@ public class MixedMongoRepositoriesAutoConfigurationTests {
@Test
public void testJpaRepositoryConfigurationWithMongoTemplate() throws Exception {
this.context = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(this.context,
"spring.datasource.initialize:false");
TestPropertyValues.of(
"spring.datasource.initialize:false").applyTo(this.context);
this.context.register(JpaConfiguration.class, BaseConfiguration.class);
this.context.refresh();
assertThat(this.context.getBean(CityRepository.class)).isNotNull();
@@ -93,8 +93,8 @@ public class MixedMongoRepositoriesAutoConfigurationTests {
@Test
public void testJpaRepositoryConfigurationWithMongoOverlap() throws Exception {
this.context = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(this.context,
"spring.datasource.initialize:false");
TestPropertyValues.of(
"spring.datasource.initialize:false").applyTo(this.context);
this.context.register(OverlapConfiguration.class, BaseConfiguration.class);
this.context.refresh();
assertThat(this.context.getBean(CityRepository.class)).isNotNull();
@@ -104,9 +104,9 @@ public class MixedMongoRepositoriesAutoConfigurationTests {
public void testJpaRepositoryConfigurationWithMongoOverlapDisabled()
throws Exception {
this.context = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(this.context,
TestPropertyValues.of(
"spring.datasource.initialize:false",
"spring.data.mongodb.repositories.enabled:false");
"spring.data.mongodb.repositories.enabled:false").applyTo(this.context);
this.context.register(OverlapConfiguration.class, BaseConfiguration.class);
this.context.refresh();
assertThat(this.context.getBean(CityRepository.class)).isNotNull();

View File

@@ -35,7 +35,7 @@ import org.springframework.boot.autoconfigure.data.mongo.city.City;
import org.springframework.boot.autoconfigure.data.mongo.country.Country;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -86,7 +86,7 @@ public class MongoDataAutoConfigurationTests {
@Test
public void gridFsTemplateExists() {
this.context = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(this.context,
TestPropertyValues.of(
"spring.data.mongodb.gridFsDatabase:grid");
this.context.register(PropertyPlaceholderAutoConfiguration.class,
MongoAutoConfiguration.class, MongoDataAutoConfiguration.class);
@@ -180,8 +180,8 @@ public class MongoDataAutoConfigurationTests {
Class<? extends FieldNamingStrategy> expectedType) {
this.context = new AnnotationConfigApplicationContext();
if (strategy != null) {
EnvironmentTestUtils.addEnvironment(this.context,
"spring.data.mongodb.field-naming-strategy:" + strategy);
TestPropertyValues.of(
"spring.data.mongodb.field-naming-strategy:" + strategy).applyTo(this.context);
}
this.context.register(PropertyPlaceholderAutoConfiguration.class,
MongoAutoConfiguration.class, MongoDataAutoConfiguration.class);

View File

@@ -28,7 +28,7 @@ import org.springframework.boot.autoconfigure.data.mongo.city.ReactiveCityReposi
import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration;
import org.springframework.boot.autoconfigure.mongo.MongoAutoConfigurationTests;
import org.springframework.boot.autoconfigure.mongo.MongoReactiveAutoConfiguration;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
@@ -58,8 +58,8 @@ public class MongoReactiveAndBlockingRepositoriesAutoConfigurationTests {
public void shouldCreateInstancesForReactiveAndBlockingRepositories()
throws Exception {
this.context = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(this.context,
"spring.datasource.initialize:false");
TestPropertyValues.of(
"spring.datasource.initialize:false").applyTo(this.context);
this.context.register(BlockingAndReactiveConfiguration.class,
BaseConfiguration.class);
this.context.refresh();

View File

@@ -33,7 +33,7 @@ import org.springframework.boot.autoconfigure.data.neo4j.empty.EmptyMarker;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
@@ -64,8 +64,8 @@ public class MixedNeo4jRepositoriesAutoConfigurationTests {
@Test
public void testDefaultRepositoryConfiguration() throws Exception {
EnvironmentTestUtils.addEnvironment(this.context,
"spring.datasource.initialize:false");
TestPropertyValues.of(
"spring.datasource.initialize:false").applyTo(this.context);
this.context.register(TestConfiguration.class, BaseConfiguration.class);
this.context.refresh();
assertThat(this.context.getBean(CountryRepository.class)).isNotNull();
@@ -73,7 +73,7 @@ public class MixedNeo4jRepositoriesAutoConfigurationTests {
@Test
public void testMixedRepositoryConfiguration() throws Exception {
EnvironmentTestUtils.addEnvironment(this.context,
TestPropertyValues.of(
"spring.datasource.initialize:false");
this.context.register(MixedConfiguration.class, BaseConfiguration.class);
this.context.refresh();
@@ -83,8 +83,8 @@ public class MixedNeo4jRepositoriesAutoConfigurationTests {
@Test
public void testJpaRepositoryConfigurationWithNeo4jTemplate() throws Exception {
EnvironmentTestUtils.addEnvironment(this.context,
"spring.datasource.initialize:false");
TestPropertyValues.of(
"spring.datasource.initialize:false").applyTo(this.context);
this.context.register(JpaConfiguration.class, BaseConfiguration.class);
this.context.refresh();
assertThat(this.context.getBean(CityRepository.class)).isNotNull();
@@ -93,8 +93,8 @@ public class MixedNeo4jRepositoriesAutoConfigurationTests {
@Test
@Ignore
public void testJpaRepositoryConfigurationWithNeo4jOverlap() throws Exception {
EnvironmentTestUtils.addEnvironment(this.context,
"spring.datasource.initialize:false");
TestPropertyValues.of(
"spring.datasource.initialize:false").applyTo(this.context);
this.context.register(OverlapConfiguration.class, BaseConfiguration.class);
this.context.refresh();
assertThat(this.context.getBean(CityRepository.class)).isNotNull();
@@ -103,9 +103,9 @@ public class MixedNeo4jRepositoriesAutoConfigurationTests {
@Test
public void testJpaRepositoryConfigurationWithNeo4jOverlapDisabled()
throws Exception {
EnvironmentTestUtils.addEnvironment(this.context,
TestPropertyValues.of(
"spring.datasource.initialize:false",
"spring.data.neo4j.repositories.enabled:false");
"spring.data.neo4j.repositories.enabled:false").applyTo(this.context);
this.context.register(OverlapConfiguration.class, BaseConfiguration.class);
this.context.refresh();
assertThat(this.context.getBean(CityRepository.class)).isNotNull();

View File

@@ -32,7 +32,7 @@ import org.springframework.boot.autoconfigure.data.neo4j.city.City;
import org.springframework.boot.autoconfigure.data.neo4j.country.Country;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.boot.autoconfigure.transaction.TransactionAutoConfiguration;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
@@ -141,7 +141,7 @@ public class Neo4jDataAutoConfigurationTests {
private void load(Class<?> config, String... environment) {
AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
EnvironmentTestUtils.addEnvironment(ctx, environment);
TestPropertyValues.of(environment).applyTo(ctx);
if (config != null) {
ctx.register(config);
}

View File

@@ -27,7 +27,7 @@ import org.neo4j.ogm.config.Configuration;
import org.neo4j.ogm.config.Credentials;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import static org.assertj.core.api.Assertions.assertThat;
@@ -182,7 +182,7 @@ public class Neo4jPropertiesTests {
}
});
EnvironmentTestUtils.addEnvironment(ctx, environment);
TestPropertyValues.of(environment).applyTo(ctx);
ctx.register(TestConfiguration.class);
ctx.refresh();
this.context = ctx;

View File

@@ -27,7 +27,7 @@ import org.springframework.boot.autoconfigure.data.alt.neo4j.CityNeo4jRepository
import org.springframework.boot.autoconfigure.data.empty.EmptyDataPackage;
import org.springframework.boot.autoconfigure.data.neo4j.city.City;
import org.springframework.boot.autoconfigure.data.neo4j.city.CityRepository;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.neo4j.mapping.Neo4jMappingContext;
@@ -82,8 +82,8 @@ public class Neo4jRepositoriesAutoConfigurationTests {
private void prepareApplicationContext(Class<?>... configurationClasses) {
this.context = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(this.context,
"spring.data.neo4j.uri=http://localhost:9797");
TestPropertyValues.of(
"spring.data.neo4j.uri=http://localhost:9797").applyTo(this.context);
this.context.register(configurationClasses);
this.context.register(Neo4jDataAutoConfiguration.class,
Neo4jRepositoriesAutoConfiguration.class,

View File

@@ -26,7 +26,7 @@ import redis.clients.jedis.Jedis;
import org.springframework.boot.junit.runner.classpath.ClassPathExclusions;
import org.springframework.boot.junit.runner.classpath.ModifiedClassPathRunner;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.util.StringUtils;
@@ -131,7 +131,7 @@ public class RedisAutoConfigurationJedisTests {
private void load(String... environment) {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(ctx, environment);
TestPropertyValues.of(environment).applyTo(ctx);
ctx.register(RedisAutoConfiguration.class);
ctx.refresh();
this.context = ctx;

View File

@@ -26,7 +26,7 @@ import io.lettuce.core.api.StatefulRedisConnection;
import org.junit.After;
import org.junit.Test;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.data.redis.connection.lettuce.DefaultLettucePool;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
@@ -191,7 +191,7 @@ public class RedisAutoConfigurationTests {
private void load(String... environment) {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(ctx, environment);
TestPropertyValues.of(environment).applyTo(ctx);
ctx.register(RedisAutoConfiguration.class);
ctx.refresh();
this.context = ctx;

View File

@@ -21,7 +21,7 @@ import java.util.Map;
import org.junit.After;
import org.junit.Test;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.data.redis.core.ReactiveRedisTemplate;
@@ -52,7 +52,7 @@ public class RedisReactiveAutoConfigurationTests {
private void load(String... environment) {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(ctx, environment);
TestPropertyValues.of(environment).applyTo(ctx);
ctx.register(RedisAutoConfiguration.class, RedisReactiveAutoConfiguration.class);
ctx.refresh();
this.context = ctx;

View File

@@ -33,7 +33,7 @@ import org.springframework.boot.autoconfigure.data.jpa.city.City;
import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration;
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
@@ -175,7 +175,7 @@ public class RepositoryRestMvcAutoConfigurationTests {
AnnotationConfigWebApplicationContext applicationContext = new AnnotationConfigWebApplicationContext();
applicationContext.setServletContext(new MockServletContext());
applicationContext.register(config, BaseConfiguration.class);
EnvironmentTestUtils.addEnvironment(applicationContext, environment);
TestPropertyValues.of(environment).applyTo(applicationContext);
applicationContext.refresh();
this.context = applicationContext;
}

View File

@@ -34,7 +34,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.diagnostics.FailureAnalysis;
import org.springframework.boot.diagnostics.LoggingFailureAnalysisReporter;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -237,7 +237,7 @@ public class NoSuchBeanDefinitionFailureAnalyzerTests {
private FatalBeanException createFailure(Class<?> config, String... environment) {
try (AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext()) {
this.analyzer.setBeanFactory(context.getBeanFactory());
EnvironmentTestUtils.addEnvironment(context, environment);
TestPropertyValues.of(environment).applyTo(context);
context.register(config);
context.refresh();
return null;

View File

@@ -36,7 +36,7 @@ import org.junit.rules.ExpectedException;
import org.springframework.beans.factory.BeanCreationException;
import org.springframework.boot.autoconfigure.data.elasticsearch.ElasticsearchAutoConfiguration;
import org.springframework.boot.autoconfigure.gson.GsonAutoConfiguration;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -129,7 +129,7 @@ public class JestAutoConfigurationTests {
private void load(Class<?> config, String... environment) {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(context, environment);
TestPropertyValues.of(environment).applyTo(context);
if (config != null) {
context.register(config);
}

View File

@@ -41,7 +41,7 @@ import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoCon
import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder;
import org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration;
import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -76,8 +76,8 @@ public class FlywayAutoConfigurationTests {
@Before
public void init() {
EnvironmentTestUtils.addEnvironment(this.context,
"spring.datasource.name:flywaytest");
TestPropertyValues.of(
"spring.datasource.name:flywaytest").applyTo(this.context);
}
@After
@@ -96,8 +96,8 @@ public class FlywayAutoConfigurationTests {
@Test
public void createDataSource() throws Exception {
EnvironmentTestUtils.addEnvironment(this.context,
"flyway.url:jdbc:hsqldb:mem:flywaytest", "flyway.user:sa");
TestPropertyValues.of(
"flyway.url:jdbc:hsqldb:mem:flywaytest", "flyway.user:sa").applyTo(this.context);
registerAndRefresh(EmbeddedDataSourceConfiguration.class,
FlywayAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class);
@@ -126,8 +126,8 @@ public class FlywayAutoConfigurationTests {
@Test
public void overrideLocations() throws Exception {
EnvironmentTestUtils.addEnvironment(this.context,
"flyway.locations:classpath:db/changelog,classpath:db/migration");
TestPropertyValues.of(
"flyway.locations:classpath:db/changelog,classpath:db/migration").applyTo(this.context);
registerAndRefresh(EmbeddedDataSourceConfiguration.class,
FlywayAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class);
@@ -138,9 +138,9 @@ public class FlywayAutoConfigurationTests {
@Test
public void overrideLocationsList() throws Exception {
EnvironmentTestUtils.addEnvironment(this.context,
TestPropertyValues.of(
"flyway.locations[0]:classpath:db/changelog",
"flyway.locations[1]:classpath:db/migration");
"flyway.locations[1]:classpath:db/migration").applyTo(this.context);
registerAndRefresh(EmbeddedDataSourceConfiguration.class,
FlywayAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class);
@@ -151,7 +151,7 @@ public class FlywayAutoConfigurationTests {
@Test
public void overrideSchemas() throws Exception {
EnvironmentTestUtils.addEnvironment(this.context, "flyway.schemas:public");
TestPropertyValues.of("flyway.schemas:public").applyTo(this.context);
registerAndRefresh(EmbeddedDataSourceConfiguration.class,
FlywayAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class);
@@ -161,8 +161,8 @@ public class FlywayAutoConfigurationTests {
@Test
public void changeLogDoesNotExist() throws Exception {
EnvironmentTestUtils.addEnvironment(this.context,
"flyway.locations:file:no-such-dir");
TestPropertyValues.of(
"flyway.locations:file:no-such-dir").applyTo(this.context);
this.thrown.expect(BeanCreationException.class);
registerAndRefresh(EmbeddedDataSourceConfiguration.class,
FlywayAutoConfiguration.class,
@@ -171,9 +171,9 @@ public class FlywayAutoConfigurationTests {
@Test
public void checkLocationsAllMissing() throws Exception {
EnvironmentTestUtils.addEnvironment(this.context,
TestPropertyValues.of(
"flyway.locations:classpath:db/missing1,classpath:db/migration2",
"flyway.check-location:true");
"flyway.check-location:true").applyTo(this.context);
this.thrown.expect(BeanCreationException.class);
this.thrown.expectMessage("Cannot find migrations location in");
registerAndRefresh(EmbeddedDataSourceConfiguration.class,
@@ -183,9 +183,9 @@ public class FlywayAutoConfigurationTests {
@Test
public void checkLocationsAllExist() throws Exception {
EnvironmentTestUtils.addEnvironment(this.context,
TestPropertyValues.of(
"flyway.locations:classpath:db/changelog,classpath:db/migration",
"flyway.check-location:true");
"flyway.check-location:true").applyTo(this.context);
registerAndRefresh(EmbeddedDataSourceConfiguration.class,
FlywayAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class);
@@ -220,7 +220,7 @@ public class FlywayAutoConfigurationTests {
@Test
public void overrideBaselineVersionString() throws Exception {
EnvironmentTestUtils.addEnvironment(this.context, "flyway.baseline-version=0");
TestPropertyValues.of("flyway.baseline-version=0").applyTo(this.context);
registerAndRefresh(EmbeddedDataSourceConfiguration.class,
FlywayAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class);
@@ -245,8 +245,8 @@ public class FlywayAutoConfigurationTests {
@Test
public void useVendorDirectory() throws Exception {
EnvironmentTestUtils.addEnvironment(this.context,
"flyway.locations=classpath:db/vendors/{vendor},classpath:db/changelog");
TestPropertyValues.of(
"flyway.locations=classpath:db/vendors/{vendor},classpath:db/changelog").applyTo(this.context);
registerAndRefresh(EmbeddedDataSourceConfiguration.class,
FlywayAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class);

View File

@@ -28,7 +28,7 @@ import org.junit.Rule;
import org.junit.Test;
import org.springframework.boot.test.rule.OutputCapture;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;
@@ -202,7 +202,7 @@ public class FreeMarkerAutoConfigurationTests {
}
private void registerAndRefreshContext(String... env) {
EnvironmentTestUtils.addEnvironment(this.context, env);
TestPropertyValues.of(env).applyTo(this.context);
this.context.register(FreeMarkerAutoConfiguration.class);
this.context.refresh();
}

View File

@@ -30,7 +30,7 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.core.io.ClassPathResource;
import org.springframework.mock.web.MockHttpServletRequest;
@@ -101,8 +101,8 @@ public class GroovyTemplateAutoConfigurationTests {
@Test
public void disableViewResolution() throws Exception {
EnvironmentTestUtils.addEnvironment(this.context,
"spring.groovy.template.enabled:false");
TestPropertyValues.of(
"spring.groovy.template.enabled:false").applyTo(this.context);
registerAndRefreshContext();
assertThat(this.context.getBeanNamesForType(ViewResolver.class)).isEmpty();
}
@@ -179,7 +179,7 @@ public class GroovyTemplateAutoConfigurationTests {
}
private void registerAndRefreshContext(String... env) {
EnvironmentTestUtils.addEnvironment(this.context, env);
TestPropertyValues.of(env).applyTo(this.context);
this.context.register(GroovyTemplateAutoConfiguration.class);
this.context.refresh();
}

View File

@@ -23,7 +23,7 @@ import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.springframework.beans.factory.BeanCreationException;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.mock.web.MockServletContext;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
@@ -66,8 +66,8 @@ public class H2ConsoleAutoConfigurationTests {
@Test
public void propertyCanEnableConsole() {
this.context.register(H2ConsoleAutoConfiguration.class);
EnvironmentTestUtils.addEnvironment(this.context,
"spring.h2.console.enabled:true");
TestPropertyValues.of(
"spring.h2.console.enabled:true").applyTo(this.context);
this.context.refresh();
assertThat(this.context.getBeansOfType(ServletRegistrationBean.class)).hasSize(1);
ServletRegistrationBean<?> registrationBean = this.context
@@ -83,16 +83,16 @@ public class H2ConsoleAutoConfigurationTests {
this.thrown.expect(BeanCreationException.class);
this.thrown.expectMessage("Failed to bind properties under 'spring.h2.console'");
this.context.register(H2ConsoleAutoConfiguration.class);
EnvironmentTestUtils.addEnvironment(this.context,
"spring.h2.console.enabled:true", "spring.h2.console.path:custom");
TestPropertyValues.of(
"spring.h2.console.enabled:true", "spring.h2.console.path:custom").applyTo(this.context);
this.context.refresh();
}
@Test
public void customPathWithTrailingSlash() {
this.context.register(H2ConsoleAutoConfiguration.class);
EnvironmentTestUtils.addEnvironment(this.context,
"spring.h2.console.enabled:true", "spring.h2.console.path:/custom/");
TestPropertyValues.of(
"spring.h2.console.enabled:true", "spring.h2.console.path:/custom/").applyTo(this.context);
this.context.refresh();
assertThat(this.context.getBeansOfType(ServletRegistrationBean.class)).hasSize(1);
ServletRegistrationBean<?> servletRegistrationBean = this.context
@@ -103,8 +103,8 @@ public class H2ConsoleAutoConfigurationTests {
@Test
public void customPath() {
this.context.register(H2ConsoleAutoConfiguration.class);
EnvironmentTestUtils.addEnvironment(this.context,
"spring.h2.console.enabled:true", "spring.h2.console.path:/custom");
TestPropertyValues.of(
"spring.h2.console.enabled:true", "spring.h2.console.path:/custom").applyTo(this.context);
this.context.refresh();
assertThat(this.context.getBeansOfType(ServletRegistrationBean.class)).hasSize(1);
ServletRegistrationBean<?> servletRegistrationBean = this.context
@@ -115,9 +115,9 @@ public class H2ConsoleAutoConfigurationTests {
@Test
public void customInitParameters() {
this.context.register(H2ConsoleAutoConfiguration.class);
EnvironmentTestUtils.addEnvironment(this.context,
TestPropertyValues.of(
"spring.h2.console.enabled:true", "spring.h2.console.settings.trace=true",
"spring.h2.console.settings.webAllowOthers=true");
"spring.h2.console.settings.webAllowOthers=true").applyTo(this.context);
this.context.refresh();
assertThat(this.context.getBeansOfType(ServletRegistrationBean.class)).hasSize(1);
ServletRegistrationBean<?> registrationBean = this.context

View File

@@ -25,7 +25,7 @@ import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
import org.springframework.boot.autoconfigure.http.HttpMessageConvertersAutoConfiguration;
import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration;
import org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.annotation.Configuration;
import org.springframework.hateoas.EntityLinks;
import org.springframework.hateoas.LinkDiscoverer;
@@ -88,8 +88,8 @@ public class HypermediaAutoConfigurationTests {
this.context = new AnnotationConfigWebApplicationContext();
this.context.setServletContext(new MockServletContext());
this.context.register(EnableHypermediaSupportConfig.class, BaseConfig.class);
EnvironmentTestUtils.addEnvironment(this.context,
"spring.jackson.serialization.INDENT_OUTPUT:true");
TestPropertyValues.of(
"spring.jackson.serialization.INDENT_OUTPUT:true").applyTo(this.context);
this.context.refresh();
ObjectMapper objectMapper = this.context.getBean("_halObjectMapper",
ObjectMapper.class);
@@ -102,8 +102,8 @@ public class HypermediaAutoConfigurationTests {
this.context = new AnnotationConfigWebApplicationContext();
this.context.setServletContext(new MockServletContext());
this.context.register(BaseConfig.class);
EnvironmentTestUtils.addEnvironment(this.context,
"spring.jackson.serialization.INDENT_OUTPUT:true");
TestPropertyValues.of(
"spring.jackson.serialization.INDENT_OUTPUT:true").applyTo(this.context);
this.context.refresh();
ObjectMapper objectMapper = this.context.getBean("_halObjectMapper",
ObjectMapper.class);
@@ -132,8 +132,8 @@ public class HypermediaAutoConfigurationTests {
this.context = new AnnotationConfigWebApplicationContext();
this.context.setServletContext(new MockServletContext());
this.context.register(BaseConfig.class);
EnvironmentTestUtils.addEnvironment(this.context,
"spring.hateoas.use-hal-as-default-json-media-type:false");
TestPropertyValues.of(
"spring.hateoas.use-hal-as-default-json-media-type:false").applyTo(this.context);
this.context.refresh();
RequestMappingHandlerAdapter handlerAdapter = this.context
.getBean(RequestMappingHandlerAdapter.class);

View File

@@ -31,7 +31,7 @@ import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.springframework.beans.factory.BeanCreationException;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -133,7 +133,7 @@ public class HazelcastAutoConfigurationClientTests {
private void load(Class<?> config, String... environment) {
AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(applicationContext, environment);
TestPropertyValues.of(environment).applyTo(applicationContext);
if (config != null) {
applicationContext.register(config);
}

View File

@@ -32,7 +32,7 @@ import org.junit.runner.RunWith;
import org.springframework.beans.factory.BeanCreationException;
import org.springframework.boot.junit.runner.classpath.ClassPathExclusions;
import org.springframework.boot.junit.runner.classpath.ModifiedClassPathRunner;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -150,7 +150,7 @@ public class HazelcastAutoConfigurationServerTests {
private void load(Class<?> config, String... environment) {
AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(applicationContext, environment);
TestPropertyValues.of(environment).applyTo(applicationContext);
if (config != null) {
applicationContext.register(config);
}

View File

@@ -22,7 +22,7 @@ import com.hazelcast.core.HazelcastInstance;
import org.junit.After;
import org.junit.Test;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.core.io.ClassPathResource;
@@ -55,7 +55,7 @@ public class HazelcastAutoConfigurationTests {
private void load(String... environment) {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(ctx, environment);
TestPropertyValues.of(environment).applyTo(ctx);
ctx.register(HazelcastAutoConfiguration.class);
ctx.refresh();
this.context = ctx;

View File

@@ -28,7 +28,7 @@ import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.boot.autoconfigure.gson.GsonAutoConfiguration;
import org.springframework.boot.autoconfigure.http.JacksonHttpMessageConvertersConfiguration.MappingJackson2HttpMessageConverterConfiguration;
import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -153,8 +153,8 @@ public class HttpMessageConvertersAutoConfigurationTests {
public void gsonCanBePreferredWhenBothGsonAndJacksonAreAvailable() {
this.context.register(GsonAutoConfiguration.class, JacksonAutoConfiguration.class,
HttpMessageConvertersAutoConfiguration.class);
EnvironmentTestUtils.addEnvironment(this.context,
"spring.http.converters.preferred-json-mapper:gson");
TestPropertyValues.of(
"spring.http.converters.preferred-json-mapper:gson").applyTo(this.context);
this.context.refresh();
assertConverterBeanExists(GsonHttpMessageConverter.class,
"gsonHttpMessageConverter");

View File

@@ -25,7 +25,7 @@ import org.junit.Test;
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
import org.springframework.boot.info.BuildProperties;
import org.springframework.boot.info.GitProperties;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -141,7 +141,7 @@ public class ProjectInfoAutoConfigurationTests {
}
context.register(PropertyPlaceholderAutoConfiguration.class,
ProjectInfoAutoConfiguration.class);
EnvironmentTestUtils.addEnvironment(context, environment);
TestPropertyValues.of(environment).applyTo(context);
context.refresh();
this.context = context;
}

View File

@@ -32,7 +32,7 @@ import org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfigurati
import org.springframework.boot.autoconfigure.jdbc.JdbcTemplateAutoConfiguration;
import org.springframework.boot.autoconfigure.jmx.JmxAutoConfiguration;
import org.springframework.boot.context.properties.source.ConfigurationPropertySources;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
@@ -207,7 +207,7 @@ public class IntegrationAutoConfigurationTests {
private void load(Class<?>[] configs, String... environment) {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(ctx, environment);
TestPropertyValues.of(environment).applyTo(ctx);
if (configs != null) {
ctx.register(configs);
}

View File

@@ -53,7 +53,7 @@ import org.junit.Test;
import org.springframework.boot.autoconfigure.http.HttpMessageConvertersAutoConfiguration;
import org.springframework.boot.jackson.JsonComponent;
import org.springframework.boot.jackson.JsonObjectSerializer;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -126,8 +126,8 @@ public class JacksonAutoConfigurationTests {
@Test
public void customDateFormat() throws Exception {
this.context.register(JacksonAutoConfiguration.class);
EnvironmentTestUtils.addEnvironment(this.context,
"spring.jackson.date-format:yyyyMMddHHmmss");
TestPropertyValues.of(
"spring.jackson.date-format:yyyyMMddHHmmss").applyTo(this.context);
this.context.refresh();
ObjectMapper mapper = this.context.getBean(ObjectMapper.class);
DateFormat dateFormat = mapper.getDateFormat();
@@ -139,9 +139,9 @@ public class JacksonAutoConfigurationTests {
@Test
public void customJodaDateTimeFormat() throws Exception {
this.context.register(JacksonAutoConfiguration.class);
EnvironmentTestUtils.addEnvironment(this.context,
TestPropertyValues.of(
"spring.jackson.date-format:yyyyMMddHHmmss",
"spring.jackson.joda-date-time-format:yyyy-MM-dd HH:mm:ss");
"spring.jackson.joda-date-time-format:yyyy-MM-dd HH:mm:ss").applyTo(this.context);
this.context.refresh();
ObjectMapper mapper = this.context.getBean(ObjectMapper.class);
DateTime dateTime = new DateTime(1988, 6, 25, 20, 30, DateTimeZone.UTC);
@@ -154,8 +154,8 @@ public class JacksonAutoConfigurationTests {
@Test
public void customDateFormatClass() throws Exception {
this.context.register(JacksonAutoConfiguration.class);
EnvironmentTestUtils.addEnvironment(this.context,
"spring.jackson.date-format:org.springframework.boot.autoconfigure.jackson.JacksonAutoConfigurationTests.MyDateFormat");
TestPropertyValues.of(
"spring.jackson.date-format:org.springframework.boot.autoconfigure.jackson.JacksonAutoConfigurationTests.MyDateFormat").applyTo(this.context);
this.context.refresh();
ObjectMapper mapper = this.context.getBean(ObjectMapper.class);
assertThat(mapper.getDateFormat()).isInstanceOf(MyDateFormat.class);
@@ -172,8 +172,8 @@ public class JacksonAutoConfigurationTests {
@Test
public void customPropertyNamingStrategyField() throws Exception {
this.context.register(JacksonAutoConfiguration.class);
EnvironmentTestUtils.addEnvironment(this.context,
"spring.jackson.property-naming-strategy:SNAKE_CASE");
TestPropertyValues.of(
"spring.jackson.property-naming-strategy:SNAKE_CASE").applyTo(this.context);
this.context.refresh();
ObjectMapper mapper = this.context.getBean(ObjectMapper.class);
assertThat(mapper.getPropertyNamingStrategy())
@@ -183,8 +183,8 @@ public class JacksonAutoConfigurationTests {
@Test
public void customPropertyNamingStrategyClass() throws Exception {
this.context.register(JacksonAutoConfiguration.class);
EnvironmentTestUtils.addEnvironment(this.context,
"spring.jackson.property-naming-strategy:com.fasterxml.jackson.databind.PropertyNamingStrategy.SnakeCaseStrategy");
TestPropertyValues.of(
"spring.jackson.property-naming-strategy:com.fasterxml.jackson.databind.PropertyNamingStrategy.SnakeCaseStrategy").applyTo(this.context);
this.context.refresh();
ObjectMapper mapper = this.context.getBean(ObjectMapper.class);
assertThat(mapper.getPropertyNamingStrategy())
@@ -194,8 +194,8 @@ public class JacksonAutoConfigurationTests {
@Test
public void enableSerializationFeature() throws Exception {
this.context.register(JacksonAutoConfiguration.class);
EnvironmentTestUtils.addEnvironment(this.context,
"spring.jackson.serialization.indent_output:true");
TestPropertyValues.of(
"spring.jackson.serialization.indent_output:true").applyTo(this.context);
this.context.refresh();
ObjectMapper mapper = this.context.getBean(ObjectMapper.class);
assertThat(SerializationFeature.INDENT_OUTPUT.enabledByDefault()).isFalse();
@@ -207,8 +207,8 @@ public class JacksonAutoConfigurationTests {
@Test
public void disableSerializationFeature() throws Exception {
this.context.register(JacksonAutoConfiguration.class);
EnvironmentTestUtils.addEnvironment(this.context,
"spring.jackson.serialization.write_dates_as_timestamps:false");
TestPropertyValues.of(
"spring.jackson.serialization.write_dates_as_timestamps:false").applyTo(this.context);
this.context.refresh();
ObjectMapper mapper = this.context.getBean(ObjectMapper.class);
assertThat(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS.enabledByDefault())
@@ -220,8 +220,8 @@ public class JacksonAutoConfigurationTests {
@Test
public void enableDeserializationFeature() throws Exception {
this.context.register(JacksonAutoConfiguration.class);
EnvironmentTestUtils.addEnvironment(this.context,
"spring.jackson.deserialization.use_big_decimal_for_floats:true");
TestPropertyValues.of(
"spring.jackson.deserialization.use_big_decimal_for_floats:true").applyTo(this.context);
this.context.refresh();
ObjectMapper mapper = this.context.getBean(ObjectMapper.class);
assertThat(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS.enabledByDefault())
@@ -233,8 +233,8 @@ public class JacksonAutoConfigurationTests {
@Test
public void disableDeserializationFeature() throws Exception {
this.context.register(JacksonAutoConfiguration.class);
EnvironmentTestUtils.addEnvironment(this.context,
"spring.jackson.deserialization.fail-on-unknown-properties:false");
TestPropertyValues.of(
"spring.jackson.deserialization.fail-on-unknown-properties:false").applyTo(this.context);
this.context.refresh();
ObjectMapper mapper = this.context.getBean(ObjectMapper.class);
assertThat(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES.enabledByDefault())
@@ -246,8 +246,8 @@ public class JacksonAutoConfigurationTests {
@Test
public void enableMapperFeature() throws Exception {
this.context.register(JacksonAutoConfiguration.class);
EnvironmentTestUtils.addEnvironment(this.context,
"spring.jackson.mapper.require_setters_for_getters:true");
TestPropertyValues.of(
"spring.jackson.mapper.require_setters_for_getters:true").applyTo(this.context);
this.context.refresh();
ObjectMapper mapper = this.context.getBean(ObjectMapper.class);
assertThat(MapperFeature.REQUIRE_SETTERS_FOR_GETTERS.enabledByDefault())
@@ -263,8 +263,8 @@ public class JacksonAutoConfigurationTests {
@Test
public void disableMapperFeature() throws Exception {
this.context.register(JacksonAutoConfiguration.class);
EnvironmentTestUtils.addEnvironment(this.context,
"spring.jackson.mapper.use_annotations:false");
TestPropertyValues.of(
"spring.jackson.mapper.use_annotations:false").applyTo(this.context);
this.context.refresh();
ObjectMapper mapper = this.context.getBean(ObjectMapper.class);
assertThat(MapperFeature.USE_ANNOTATIONS.enabledByDefault()).isTrue();
@@ -277,8 +277,8 @@ public class JacksonAutoConfigurationTests {
@Test
public void enableParserFeature() throws Exception {
this.context.register(JacksonAutoConfiguration.class);
EnvironmentTestUtils.addEnvironment(this.context,
"spring.jackson.parser.allow_single_quotes:true");
TestPropertyValues.of(
"spring.jackson.parser.allow_single_quotes:true").applyTo(this.context);
this.context.refresh();
ObjectMapper mapper = this.context.getBean(ObjectMapper.class);
assertThat(JsonParser.Feature.ALLOW_SINGLE_QUOTES.enabledByDefault()).isFalse();
@@ -289,8 +289,8 @@ public class JacksonAutoConfigurationTests {
@Test
public void disableParserFeature() throws Exception {
this.context.register(JacksonAutoConfiguration.class);
EnvironmentTestUtils.addEnvironment(this.context,
"spring.jackson.parser.auto_close_source:false");
TestPropertyValues.of(
"spring.jackson.parser.auto_close_source:false").applyTo(this.context);
this.context.refresh();
ObjectMapper mapper = this.context.getBean(ObjectMapper.class);
assertThat(JsonParser.Feature.AUTO_CLOSE_SOURCE.enabledByDefault()).isTrue();
@@ -301,8 +301,8 @@ public class JacksonAutoConfigurationTests {
@Test
public void enableGeneratorFeature() throws Exception {
this.context.register(JacksonAutoConfiguration.class);
EnvironmentTestUtils.addEnvironment(this.context,
"spring.jackson.generator.write_numbers_as_strings:true");
TestPropertyValues.of(
"spring.jackson.generator.write_numbers_as_strings:true").applyTo(this.context);
this.context.refresh();
ObjectMapper mapper = this.context.getBean(ObjectMapper.class);
assertThat(JsonGenerator.Feature.WRITE_NUMBERS_AS_STRINGS.enabledByDefault())
@@ -314,8 +314,8 @@ public class JacksonAutoConfigurationTests {
@Test
public void disableGeneratorFeature() throws Exception {
this.context.register(JacksonAutoConfiguration.class);
EnvironmentTestUtils.addEnvironment(this.context,
"spring.jackson.generator.auto_close_target:false");
TestPropertyValues.of(
"spring.jackson.generator.auto_close_target:false").applyTo(this.context);
this.context.refresh();
ObjectMapper mapper = this.context.getBean(ObjectMapper.class);
assertThat(JsonGenerator.Feature.AUTO_CLOSE_TARGET.enabledByDefault()).isTrue();
@@ -369,8 +369,8 @@ public class JacksonAutoConfigurationTests {
@Test
public void customSerializationInclusion() {
this.context.register(JacksonAutoConfiguration.class);
EnvironmentTestUtils.addEnvironment(this.context,
"spring.jackson.default-property-inclusion:non_null");
TestPropertyValues.of(
"spring.jackson.default-property-inclusion:non_null").applyTo(this.context);
this.context.refresh();
ObjectMapper objectMapper = this.context
.getBean(Jackson2ObjectMapperBuilder.class).build();
@@ -381,11 +381,11 @@ public class JacksonAutoConfigurationTests {
@Test
public void customTimeZoneFormattingADateTime() throws JsonProcessingException {
this.context.register(JacksonAutoConfiguration.class);
EnvironmentTestUtils.addEnvironment(this.context,
"spring.jackson.time-zone:America/Los_Angeles");
EnvironmentTestUtils.addEnvironment(this.context,
"spring.jackson.date-format:zzzz");
EnvironmentTestUtils.addEnvironment(this.context, "spring.jackson.locale:en");
TestPropertyValues.of(
"spring.jackson.time-zone:America/Los_Angeles").applyTo(this.context);
TestPropertyValues.of(
"spring.jackson.date-format:zzzz").applyTo(this.context);
TestPropertyValues.of("spring.jackson.locale:en").applyTo(this.context);
this.context.refresh();
ObjectMapper objectMapper = this.context
.getBean(Jackson2ObjectMapperBuilder.class).build();
@@ -397,9 +397,9 @@ public class JacksonAutoConfigurationTests {
@Test
public void customTimeZoneFormattingADate() throws JsonProcessingException {
this.context.register(JacksonAutoConfiguration.class);
EnvironmentTestUtils.addEnvironment(this.context,
"spring.jackson.time-zone:GMT+10");
EnvironmentTestUtils.addEnvironment(this.context, "spring.jackson.date-format:z");
TestPropertyValues.of(
"spring.jackson.time-zone:GMT+10").applyTo(this.context);
TestPropertyValues.of("spring.jackson.date-format:z").applyTo(this.context);
this.context.refresh();
ObjectMapper objectMapper = this.context
.getBean(Jackson2ObjectMapperBuilder.class).build();
@@ -410,9 +410,9 @@ public class JacksonAutoConfigurationTests {
@Test
public void customLocale() throws JsonProcessingException {
this.context.register(JacksonAutoConfiguration.class);
EnvironmentTestUtils.addEnvironment(this.context, "spring.jackson.locale:de");
EnvironmentTestUtils.addEnvironment(this.context,
"spring.jackson.date-format:zzzz");
TestPropertyValues.of("spring.jackson.locale:de").applyTo(this.context);
TestPropertyValues.of(
"spring.jackson.date-format:zzzz").applyTo(this.context);
this.context.refresh();
ObjectMapper objectMapper = this.context
.getBean(Jackson2ObjectMapperBuilder.class).build();

View File

@@ -36,7 +36,7 @@ import org.junit.Test;
import org.springframework.beans.factory.BeanCreationException;
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
import org.springframework.boot.jdbc.DatabaseDriver;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -58,9 +58,9 @@ public class DataSourceAutoConfigurationTests {
@Before
public void init() {
EmbeddedDatabaseConnection.override = null;
EnvironmentTestUtils.addEnvironment(this.context,
TestPropertyValues.of(
"spring.datasource.initialize:false",
"spring.datasource.url:jdbc:hsqldb:mem:testdb-" + new Random().nextInt());
"spring.datasource.url:jdbc:hsqldb:mem:testdb-" + new Random().nextInt()).applyTo(this.context);
}
@After
@@ -89,8 +89,8 @@ public class DataSourceAutoConfigurationTests {
@Test(expected = BeanCreationException.class)
public void testBadUrl() throws Exception {
EnvironmentTestUtils.addEnvironment(this.context,
"spring.datasource.url:jdbc:not-going-to-work");
TestPropertyValues.of(
"spring.datasource.url:jdbc:not-going-to-work").applyTo(this.context);
EmbeddedDatabaseConnection.override = EmbeddedDatabaseConnection.NONE;
this.context.register(DataSourceAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class);
@@ -100,9 +100,9 @@ public class DataSourceAutoConfigurationTests {
@Test(expected = BeanCreationException.class)
public void testBadDriverClass() throws Exception {
EnvironmentTestUtils.addEnvironment(this.context,
TestPropertyValues.of(
"spring.datasource.driverClassName:org.none.jdbcDriver",
"spring.datasource.url:jdbc:hsqldb:mem:testdb");
"spring.datasource.url:jdbc:hsqldb:mem:testdb").applyTo(this.context);
EmbeddedDatabaseConnection.override = EmbeddedDatabaseConnection.NONE;
this.context.register(DataSourceAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class);
@@ -152,9 +152,9 @@ public class DataSourceAutoConfigurationTests {
@Test
public void testEmbeddedTypeDefaultsUsername() throws Exception {
EnvironmentTestUtils.addEnvironment(this.context,
TestPropertyValues.of(
"spring.datasource.driverClassName:org.hsqldb.jdbcDriver",
"spring.datasource.url:jdbc:hsqldb:mem:testdb");
"spring.datasource.url:jdbc:hsqldb:mem:testdb").applyTo(this.context);
this.context.register(DataSourceAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class);
this.context.refresh();
@@ -172,10 +172,10 @@ public class DataSourceAutoConfigurationTests {
*/
@Test
public void explicitTypeNoSupportedDataSource() {
EnvironmentTestUtils.addEnvironment(this.context,
TestPropertyValues.of(
"spring.datasource.driverClassName:org.hsqldb.jdbcDriver",
"spring.datasource.url:jdbc:hsqldb:mem:testdb",
"spring.datasource.type:" + SimpleDriverDataSource.class.getName());
"spring.datasource.type:" + SimpleDriverDataSource.class.getName()).applyTo(this.context);
this.context.setClassLoader(
new HidePackagesClassLoader("org.apache.tomcat", "com.zaxxer.hikari",
"org.apache.commons.dbcp", "org.apache.commons.dbcp2"));
@@ -184,10 +184,10 @@ public class DataSourceAutoConfigurationTests {
@Test
public void explicitTypeSupportedDataSource() {
EnvironmentTestUtils.addEnvironment(this.context,
TestPropertyValues.of(
"spring.datasource.driverClassName:org.hsqldb.jdbcDriver",
"spring.datasource.url:jdbc:hsqldb:mem:testdb",
"spring.datasource.type:" + SimpleDriverDataSource.class.getName());
"spring.datasource.type:" + SimpleDriverDataSource.class.getName()).applyTo(this.context);
testExplicitType();
}
@@ -203,11 +203,11 @@ public class DataSourceAutoConfigurationTests {
@Test
public void testExplicitDriverClassClearsUsername() throws Exception {
EnvironmentTestUtils.addEnvironment(this.context,
TestPropertyValues.of(
"spring.datasource.driverClassName:"
+ "org.springframework.boot.autoconfigure.jdbc."
+ "DataSourceAutoConfigurationTests$DatabaseTestDriver",
"spring.datasource.url:jdbc:foo://localhost");
"spring.datasource.url:jdbc:foo://localhost").applyTo(this.context);
this.context.register(DataSourceAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class);
this.context.refresh();
@@ -232,9 +232,9 @@ public class DataSourceAutoConfigurationTests {
@SuppressWarnings("unchecked")
private <T extends DataSource> T autoConfigureDataSource(Class<T> expectedType,
final String... hiddenPackages) {
EnvironmentTestUtils.addEnvironment(this.context,
TestPropertyValues.of(
"spring.datasource.driverClassName:org.hsqldb.jdbcDriver",
"spring.datasource.url:jdbc:hsqldb:mem:testdb");
"spring.datasource.url:jdbc:hsqldb:mem:testdb").applyTo(this.context);
this.context.setClassLoader(new HidePackagesClassLoader(hiddenPackages));
this.context.register(DataSourceAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class);

View File

@@ -35,7 +35,7 @@ import org.springframework.beans.factory.BeanCreationException;
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -69,9 +69,9 @@ public class DataSourceInitializerTests {
@Before
public void init() {
EmbeddedDatabaseConnection.override = null;
EnvironmentTestUtils.addEnvironment(this.context,
TestPropertyValues.of(
"spring.datasource.initialize:false",
"spring.datasource.url:jdbc:hsqldb:mem:testdb-" + new Random().nextInt());
"spring.datasource.url:jdbc:hsqldb:mem:testdb-" + new Random().nextInt()).applyTo(this.context);
}
@After
@@ -93,9 +93,9 @@ public class DataSourceInitializerTests {
@Test
public void testTwoDataSources() throws Exception {
EnvironmentTestUtils.addEnvironment(this.context,
TestPropertyValues.of(
"datasource.one.url=jdbc:hsqldb:mem:/one",
"datasource.two.url=jdbc:hsqldb:mem:/two");
"datasource.two.url=jdbc:hsqldb:mem:/two").applyTo(this.context);
this.context.register(TwoDataSources.class, DataSourceInitializer.class,
PropertyPlaceholderAutoConfiguration.class, DataSourceProperties.class);
this.context.refresh();
@@ -105,8 +105,8 @@ public class DataSourceInitializerTests {
@Test
public void testDataSourceInitialized() throws Exception {
EnvironmentTestUtils.addEnvironment(this.context,
"spring.datasource.initialize:true");
TestPropertyValues.of(
"spring.datasource.initialize:true").applyTo(this.context);
this.context.register(DataSourceAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class);
this.context.refresh();
@@ -122,12 +122,12 @@ public class DataSourceInitializerTests {
public void testDataSourceInitializedWithExplicitScript() throws Exception {
this.context.register(DataSourceAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class);
EnvironmentTestUtils.addEnvironment(this.context,
TestPropertyValues.of(
"spring.datasource.initialize:true",
"spring.datasource.schema:" + ClassUtils
.addResourcePathToPackagePath(getClass(), "schema.sql"),
"spring.datasource.data:" + ClassUtils
.addResourcePathToPackagePath(getClass(), "data.sql"));
.addResourcePathToPackagePath(getClass(), "data.sql")).applyTo(this.context);
this.context.refresh();
DataSource dataSource = this.context.getBean(DataSource.class);
assertThat(dataSource).isInstanceOf(HikariDataSource.class);
@@ -139,7 +139,7 @@ public class DataSourceInitializerTests {
@Test
public void testDataSourceInitializedWithMultipleScripts() throws Exception {
EnvironmentTestUtils.addEnvironment(this.context,
TestPropertyValues.of(
"spring.datasource.initialize:true",
"spring.datasource.schema:"
+ ClassUtils.addResourcePathToPackagePath(getClass(),
@@ -148,7 +148,7 @@ public class DataSourceInitializerTests {
+ ClassUtils.addResourcePathToPackagePath(getClass(),
"another.sql"),
"spring.datasource.data:" + ClassUtils
.addResourcePathToPackagePath(getClass(), "data.sql"));
.addResourcePathToPackagePath(getClass(), "data.sql")).applyTo(this.context);
this.context.register(DataSourceAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class);
this.context.refresh();
@@ -167,13 +167,13 @@ public class DataSourceInitializerTests {
throws Exception {
this.context.register(DataSourceAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class);
EnvironmentTestUtils.addEnvironment(this.context,
TestPropertyValues.of(
"spring.datasource.initialize:true",
"spring.datasource.sqlScriptEncoding:UTF-8",
"spring.datasource.schema:" + ClassUtils
.addResourcePathToPackagePath(getClass(), "encoding-schema.sql"),
"spring.datasource.data:" + ClassUtils
.addResourcePathToPackagePath(getClass(), "encoding-data.sql"));
.addResourcePathToPackagePath(getClass(), "encoding-data.sql")).applyTo(this.context);
this.context.refresh();
DataSource dataSource = this.context.getBean(DataSource.class);
assertThat(dataSource).isInstanceOf(HikariDataSource.class);
@@ -214,7 +214,7 @@ public class DataSourceInitializerTests {
public void testDataSourceInitializedWithSchemaCredentials() {
this.context.register(DataSourceAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class);
EnvironmentTestUtils.addEnvironment(this.context,
TestPropertyValues.of(
"spring.datasource.initialize:true",
"spring.datasource.sqlScriptEncoding:UTF-8",
"spring.datasource.schema:" + ClassUtils
@@ -222,7 +222,7 @@ public class DataSourceInitializerTests {
"spring.datasource.data:" + ClassUtils
.addResourcePathToPackagePath(getClass(), "encoding-data.sql"),
"spring.datasource.schema-username:admin",
"spring.datasource.schema-password:admin");
"spring.datasource.schema-password:admin").applyTo(this.context);
try {
this.context.refresh();
fail("User does not exist");
@@ -236,7 +236,7 @@ public class DataSourceInitializerTests {
public void testDataSourceInitializedWithDataCredentials() {
this.context.register(DataSourceAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class);
EnvironmentTestUtils.addEnvironment(this.context,
TestPropertyValues.of(
"spring.datasource.initialize:true",
"spring.datasource.sqlScriptEncoding:UTF-8",
"spring.datasource.schema:" + ClassUtils
@@ -244,7 +244,7 @@ public class DataSourceInitializerTests {
"spring.datasource.data:" + ClassUtils
.addResourcePathToPackagePath(getClass(), "encoding-data.sql"),
"spring.datasource.data-username:admin",
"spring.datasource.data-password:admin");
"spring.datasource.data-password:admin").applyTo(this.context);
try {
this.context.refresh();
fail("User does not exist");
@@ -256,12 +256,12 @@ public class DataSourceInitializerTests {
@Test
public void multipleScriptsAppliedInLexicalOrder() throws Exception {
EnvironmentTestUtils.addEnvironment(this.context,
TestPropertyValues.of(
"spring.datasource.initialize:true",
"spring.datasource.schema:" + ClassUtils
.addResourcePathToPackagePath(getClass(), "lexical-schema-*.sql"),
"spring.datasource.data:" + ClassUtils
.addResourcePathToPackagePath(getClass(), "data.sql"));
.addResourcePathToPackagePath(getClass(), "data.sql")).applyTo(this.context);
this.context.register(DataSourceAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class);
ReverseOrderResourceLoader resourceLoader = new ReverseOrderResourceLoader(
@@ -280,9 +280,9 @@ public class DataSourceInitializerTests {
public void testDataSourceInitializedWithInvalidSchemaResource() {
this.context.register(DataSourceAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class);
EnvironmentTestUtils.addEnvironment(this.context,
TestPropertyValues.of(
"spring.datasource.initialize:true",
"spring.datasource.schema:classpath:does/not/exist.sql");
"spring.datasource.schema:classpath:does/not/exist.sql").applyTo(this.context);
this.thrown.expect(BeanCreationException.class);
this.thrown.expectMessage("does/not/exist.sql");
@@ -294,11 +294,11 @@ public class DataSourceInitializerTests {
public void testDataSourceInitializedWithInvalidDataResource() {
this.context.register(DataSourceAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class);
EnvironmentTestUtils.addEnvironment(this.context,
TestPropertyValues.of(
"spring.datasource.initialize:true",
"spring.datasource.schema:" + ClassUtils
.addResourcePathToPackagePath(getClass(), "schema.sql"),
"spring.datasource.data:classpath:does/not/exist.sql");
"spring.datasource.data:classpath:does/not/exist.sql").applyTo(this.context);
this.thrown.expect(BeanCreationException.class);
this.thrown.expectMessage("does/not/exist.sql");

View File

@@ -21,7 +21,7 @@ import javax.sql.DataSource;
import org.junit.Test;
import org.springframework.boot.autoconfigure.transaction.TransactionAutoConfiguration;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -110,9 +110,9 @@ public class DataSourceTransactionManagerAutoConfigurationTests {
@Test
public void testCustomizeDataSourceTransactionManagerUsingProperties()
throws Exception {
EnvironmentTestUtils.addEnvironment(this.context,
TestPropertyValues.of(
"spring.transaction.default-timeout:30",
"spring.transaction.rollback-on-commit-failure:true");
"spring.transaction.rollback-on-commit-failure:true").applyTo(this.context);
this.context.register(EmbeddedDataSourceConfiguration.class,
DataSourceTransactionManagerAutoConfiguration.class,
TransactionAutoConfiguration.class);

View File

@@ -25,7 +25,7 @@ import javax.sql.DataSource;
import org.junit.After;
import org.junit.Test;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import static org.assertj.core.api.Assertions.assertThat;
@@ -79,7 +79,7 @@ public class EmbeddedDataSourceConfigurationTests {
private AnnotationConfigApplicationContext load(String... environment) {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(ctx, environment);
TestPropertyValues.of(environment).applyTo(ctx);
ctx.register(EmbeddedDataSourceConfiguration.class);
ctx.refresh();
return ctx;

View File

@@ -26,7 +26,7 @@ import org.junit.Test;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -61,9 +61,9 @@ public class HikariDataSourceConfigurationTests {
@Test
public void testDataSourcePropertiesOverridden() throws Exception {
this.context.register(HikariDataSourceConfiguration.class);
EnvironmentTestUtils.addEnvironment(this.context,
PREFIX + "jdbcUrl:jdbc:foo//bar/spam");
EnvironmentTestUtils.addEnvironment(this.context, PREFIX + "maxLifetime:1234");
TestPropertyValues.of(
PREFIX + "jdbcUrl:jdbc:foo//bar/spam").applyTo(this.context);
TestPropertyValues.of(PREFIX + "maxLifetime:1234").applyTo(this.context);
this.context.refresh();
HikariDataSource ds = this.context.getBean(HikariDataSource.class);
assertThat(ds.getJdbcUrl()).isEqualTo("jdbc:foo//bar/spam");
@@ -74,8 +74,8 @@ public class HikariDataSourceConfigurationTests {
@Test
public void testDataSourceGenericPropertiesOverridden() throws Exception {
this.context.register(HikariDataSourceConfiguration.class);
EnvironmentTestUtils.addEnvironment(this.context, PREFIX
+ "dataSourceProperties.dataSourceClassName:org.h2.JDBCDataSource");
TestPropertyValues.of(PREFIX
+ "dataSourceProperties.dataSourceClassName:org.h2.JDBCDataSource").applyTo(this.context);
this.context.refresh();
HikariDataSource ds = this.context.getBean(HikariDataSource.class);
assertThat(ds.getDataSourceProperties().getProperty("dataSourceClassName"))

View File

@@ -22,7 +22,7 @@ import org.junit.Test;
import org.springframework.beans.factory.BeanCreationException;
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
import org.springframework.boot.diagnostics.FailureAnalysis;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Configuration;
@@ -61,9 +61,9 @@ public class HikariDriverConfigurationFailureAnalyzerTests {
private BeanCreationException createFailure(Class<?> configuration) {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(context,
TestPropertyValues.of(
"spring.datasource.type=" + HikariDataSource.class.getName(),
"spring.datasource.hikari.data-source-class-name=com.example.Foo");
"spring.datasource.hikari.data-source-class-name=com.example.Foo").applyTo(context);
context.register(configuration);
try {
context.refresh();

View File

@@ -26,7 +26,7 @@ import org.junit.Before;
import org.junit.Test;
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -52,9 +52,9 @@ public class JdbcTemplateAutoConfigurationTests {
@Before
public void init() {
EmbeddedDatabaseConnection.override = null;
EnvironmentTestUtils.addEnvironment(this.context,
TestPropertyValues.of(
"spring.datasource.initialize:false",
"spring.datasource.url:jdbc:hsqldb:mem:testdb-" + new Random().nextInt());
"spring.datasource.url:jdbc:hsqldb:mem:testdb-" + new Random().nextInt()).applyTo(this.context);
}
@After

View File

@@ -30,7 +30,7 @@ import org.junit.Test;
import org.springframework.beans.DirectFieldAccessor;
import org.springframework.boot.autoconfigure.jndi.JndiPropertiesHidingClassLoader;
import org.springframework.boot.autoconfigure.jndi.TestableInitialContextFactory;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.jmx.export.MBeanExporter;
@@ -88,8 +88,8 @@ public class JndiDataSourceAutoConfigurationTests {
configureJndi("foo", dataSource);
this.context = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(this.context,
"spring.datasource.jndi-name:foo");
TestPropertyValues.of(
"spring.datasource.jndi-name:foo").applyTo(this.context);
this.context.register(JndiDataSourceAutoConfiguration.class);
this.context.refresh();
@@ -104,8 +104,8 @@ public class JndiDataSourceAutoConfigurationTests {
configureJndi("foo", dataSource);
this.context = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(this.context,
"spring.datasource.jndi-name:foo");
TestPropertyValues.of(
"spring.datasource.jndi-name:foo").applyTo(this.context);
this.context.register(JndiDataSourceAutoConfiguration.class,
MBeanExporterConfiguration.class);
this.context.refresh();
@@ -125,8 +125,8 @@ public class JndiDataSourceAutoConfigurationTests {
configureJndi("foo", dataSource);
this.context = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(this.context,
"spring.datasource.jndi-name:foo");
TestPropertyValues.of(
"spring.datasource.jndi-name:foo").applyTo(this.context);
this.context.register(JndiDataSourceAutoConfiguration.class,
MBeanExporterConfiguration.class);
this.context.refresh();

View File

@@ -29,7 +29,7 @@ import org.junit.Test;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -53,7 +53,7 @@ public class TomcatDataSourceConfigurationTests {
@Before
public void init() {
EnvironmentTestUtils.addEnvironment(this.context, PREFIX + "initialize:false");
TestPropertyValues.of(PREFIX + "initialize:false");
}
@After
@@ -64,8 +64,8 @@ public class TomcatDataSourceConfigurationTests {
@Test
public void testDataSourceExists() throws Exception {
this.context.register(TomcatDataSourceConfiguration.class);
EnvironmentTestUtils.addEnvironment(this.context,
PREFIX + "url:jdbc:h2:mem:testdb");
TestPropertyValues.of(
PREFIX + "url:jdbc:h2:mem:testdb").applyTo(this.context);
this.context.refresh();
assertThat(this.context.getBean(DataSource.class)).isNotNull();
assertThat(this.context.getBean(org.apache.tomcat.jdbc.pool.DataSource.class))
@@ -75,20 +75,16 @@ public class TomcatDataSourceConfigurationTests {
@Test
public void testDataSourcePropertiesOverridden() throws Exception {
this.context.register(TomcatDataSourceConfiguration.class);
EnvironmentTestUtils.addEnvironment(this.context,
PREFIX + "url:jdbc:h2:mem:testdb");
EnvironmentTestUtils.addEnvironment(this.context, PREFIX + "testWhileIdle:true");
EnvironmentTestUtils.addEnvironment(this.context, PREFIX + "testOnBorrow:true");
EnvironmentTestUtils.addEnvironment(this.context, PREFIX + "testOnReturn:true");
EnvironmentTestUtils.addEnvironment(this.context,
PREFIX + "timeBetweenEvictionRunsMillis:10000");
EnvironmentTestUtils.addEnvironment(this.context,
PREFIX + "minEvictableIdleTimeMillis:12345");
EnvironmentTestUtils.addEnvironment(this.context, PREFIX + "maxWait:1234");
EnvironmentTestUtils.addEnvironment(this.context,
PREFIX + "jdbcInterceptors:SlowQueryReport");
EnvironmentTestUtils.addEnvironment(this.context,
PREFIX + "validationInterval:9999");
TestPropertyValues.of(
PREFIX + "url:jdbc:h2:mem:testdb",
PREFIX + "testWhileIdle:true",
PREFIX + "testOnBorrow:true",
PREFIX + "testOnReturn:true",
PREFIX + "timeBetweenEvictionRunsMillis:10000",
PREFIX + "minEvictableIdleTimeMillis:12345",
PREFIX + "maxWait:1234",
PREFIX + "jdbcInterceptors:SlowQueryReport",
PREFIX + "validationInterval:9999").applyTo(this.context);
this.context.refresh();
org.apache.tomcat.jdbc.pool.DataSource ds = this.context
.getBean(org.apache.tomcat.jdbc.pool.DataSource.class);
@@ -118,8 +114,8 @@ public class TomcatDataSourceConfigurationTests {
@Test
public void testDataSourceDefaultsPreserved() throws Exception {
this.context.register(TomcatDataSourceConfiguration.class);
EnvironmentTestUtils.addEnvironment(this.context,
PREFIX + "url:jdbc:h2:mem:testdb");
TestPropertyValues.of(
PREFIX + "url:jdbc:h2:mem:testdb").applyTo(this.context);
this.context.refresh();
org.apache.tomcat.jdbc.pool.DataSource ds = this.context
.getBean(org.apache.tomcat.jdbc.pool.DataSource.class);

View File

@@ -23,7 +23,7 @@ import org.hsqldb.jdbc.pool.JDBCXADataSource;
import org.junit.Test;
import org.springframework.boot.jta.XADataSourceWrapper;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
@@ -75,7 +75,7 @@ public class XADataSourceAutoConfigurationTests {
private ApplicationContext createContext(Class<?> configuration, String... env) {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(context, env);
TestPropertyValues.of(env).applyTo(context);
context.register(configuration, XADataSourceAutoConfiguration.class);
context.refresh();
return context;

View File

@@ -28,7 +28,7 @@ import org.springframework.beans.BeansException;
import org.springframework.beans.DirectFieldAccessor;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.boot.autoconfigure.jms.activemq.ActiveMQAutoConfiguration;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -405,7 +405,7 @@ public class JmsAutoConfigurationTests {
applicationContext.register(configs);
applicationContext.register(ActiveMQAutoConfiguration.class,
JmsAutoConfiguration.class);
EnvironmentTestUtils.addEnvironment(applicationContext, environment);
TestPropertyValues.of(environment).applyTo(applicationContext);
applicationContext.refresh();
return applicationContext;
}

Some files were not shown because too many files have changed in this diff Show More