Merge branch '2.0.x' into 2.1.x
Closes gh-17078
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -60,12 +60,11 @@ public class UserServiceAutoConfigurationTests {
|
||||
// tag::test-user-config[]
|
||||
@Test
|
||||
public void defaultServiceBacksOff() {
|
||||
this.contextRunner.withUserConfiguration(UserConfiguration.class)
|
||||
.run((context) -> {
|
||||
assertThat(context).hasSingleBean(UserService.class);
|
||||
assertThat(context.getBean(UserService.class)).isSameAs(
|
||||
context.getBean(UserConfiguration.class).myUserService());
|
||||
});
|
||||
this.contextRunner.withUserConfiguration(UserConfiguration.class).run((context) -> {
|
||||
assertThat(context).hasSingleBean(UserService.class);
|
||||
assertThat(context.getBean(UserService.class))
|
||||
.isSameAs(context.getBean(UserConfiguration.class).myUserService());
|
||||
});
|
||||
}
|
||||
|
||||
@Configuration
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -35,8 +35,7 @@ public class EnvironmentPostProcessorExampleTests {
|
||||
@Test
|
||||
public void applyEnvironmentPostProcessor() {
|
||||
assertThat(this.environment.containsProperty("test.foo.bar")).isFalse();
|
||||
new EnvironmentPostProcessorExample().postProcessEnvironment(this.environment,
|
||||
new SpringApplication());
|
||||
new EnvironmentPostProcessorExample().postProcessEnvironment(this.environment, new SpringApplication());
|
||||
assertThat(this.environment.containsProperty("test.foo.bar")).isTrue();
|
||||
assertThat(this.environment.getProperty("test.foo.bar")).isEqualTo("value");
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -42,10 +42,9 @@ public class TomcatLegacyCookieProcessorExampleTests {
|
||||
public void cookieProcessorIsCustomized() {
|
||||
ServletWebServerApplicationContext applicationContext = (ServletWebServerApplicationContext) new SpringApplication(
|
||||
TestConfiguration.class, LegacyCookieProcessorConfiguration.class).run();
|
||||
Context context = (Context) ((TomcatWebServer) applicationContext.getWebServer())
|
||||
.getTomcat().getHost().findChildren()[0];
|
||||
assertThat(context.getCookieProcessor())
|
||||
.isInstanceOf(LegacyCookieProcessor.class);
|
||||
Context context = (Context) ((TomcatWebServer) applicationContext.getWebServer()).getTomcat().getHost()
|
||||
.findChildren()[0];
|
||||
assertThat(context.getCookieProcessor()).isInstanceOf(LegacyCookieProcessor.class);
|
||||
}
|
||||
|
||||
@Configuration
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -41,43 +41,32 @@ public class AppSystemPropertiesTests {
|
||||
|
||||
@Test
|
||||
public void bindWithDefaultUnit() {
|
||||
this.contextRunner
|
||||
.withPropertyValues("app.system.session-timeout=40",
|
||||
"app.system.read-timeout=5000")
|
||||
this.contextRunner.withPropertyValues("app.system.session-timeout=40", "app.system.read-timeout=5000")
|
||||
.run(assertBinding((properties) -> {
|
||||
assertThat(properties.getSessionTimeout())
|
||||
.isEqualTo(Duration.ofSeconds(40));
|
||||
assertThat(properties.getReadTimeout())
|
||||
.isEqualTo(Duration.ofMillis(5000));
|
||||
assertThat(properties.getSessionTimeout()).isEqualTo(Duration.ofSeconds(40));
|
||||
assertThat(properties.getReadTimeout()).isEqualTo(Duration.ofMillis(5000));
|
||||
}));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bindWithExplicitUnit() {
|
||||
this.contextRunner.withPropertyValues("app.system.session-timeout=1h",
|
||||
"app.system.read-timeout=5s").run(assertBinding((properties) -> {
|
||||
assertThat(properties.getSessionTimeout())
|
||||
.isEqualTo(Duration.ofMinutes(60));
|
||||
assertThat(properties.getReadTimeout())
|
||||
.isEqualTo(Duration.ofMillis(5000));
|
||||
this.contextRunner.withPropertyValues("app.system.session-timeout=1h", "app.system.read-timeout=5s")
|
||||
.run(assertBinding((properties) -> {
|
||||
assertThat(properties.getSessionTimeout()).isEqualTo(Duration.ofMinutes(60));
|
||||
assertThat(properties.getReadTimeout()).isEqualTo(Duration.ofMillis(5000));
|
||||
}));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bindWithIso8601Format() {
|
||||
this.contextRunner
|
||||
.withPropertyValues("app.system.session-timeout=PT15S",
|
||||
"app.system.read-timeout=PT0.5S")
|
||||
this.contextRunner.withPropertyValues("app.system.session-timeout=PT15S", "app.system.read-timeout=PT0.5S")
|
||||
.run(assertBinding((properties) -> {
|
||||
assertThat(properties.getSessionTimeout())
|
||||
.isEqualTo(Duration.ofSeconds(15));
|
||||
assertThat(properties.getReadTimeout())
|
||||
.isEqualTo(Duration.ofMillis(500));
|
||||
assertThat(properties.getSessionTimeout()).isEqualTo(Duration.ofSeconds(15));
|
||||
assertThat(properties.getReadTimeout()).isEqualTo(Duration.ofMillis(500));
|
||||
}));
|
||||
}
|
||||
|
||||
private ContextConsumer<AssertableApplicationContext> assertBinding(
|
||||
Consumer<AppSystemProperties> properties) {
|
||||
private ContextConsumer<AssertableApplicationContext> assertBinding(Consumer<AppSystemProperties> properties) {
|
||||
return (context) -> {
|
||||
assertThat(context).hasSingleBean(AppSystemProperties.class);
|
||||
properties.accept(context.getBean(AppSystemProperties.class));
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -48,8 +48,7 @@ public class BasicDataSourceExampleTests {
|
||||
public void validateConfiguration() throws SQLException {
|
||||
assertThat(this.context.getBeansOfType(DataSource.class)).hasSize(1);
|
||||
DataSource dataSource = this.context.getBean(DataSource.class);
|
||||
assertThat(dataSource.getConnection().getMetaData().getURL())
|
||||
.isEqualTo("jdbc:h2:mem:basic");
|
||||
assertThat(dataSource.getConnection().getMetaData().getURL()).isEqualTo("jdbc:h2:mem:basic");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -49,12 +49,9 @@ public class CompleteTwoDataSourcesExampleTests {
|
||||
assertThat(this.context.getBeansOfType(DataSource.class)).hasSize(2);
|
||||
DataSource dataSource = this.context.getBean(DataSource.class);
|
||||
assertThat(this.context.getBean("firstDataSource")).isSameAs(dataSource);
|
||||
assertThat(dataSource.getConnection().getMetaData().getURL())
|
||||
.startsWith("jdbc:h2:mem:");
|
||||
DataSource secondDataSource = this.context.getBean("secondDataSource",
|
||||
DataSource.class);
|
||||
assertThat(secondDataSource.getConnection().getMetaData().getURL())
|
||||
.startsWith("jdbc:h2:mem:");
|
||||
assertThat(dataSource.getConnection().getMetaData().getURL()).startsWith("jdbc:h2:mem:");
|
||||
DataSource secondDataSource = this.context.getBean("secondDataSource", DataSource.class);
|
||||
assertThat(secondDataSource.getConnection().getMetaData().getURL()).startsWith("jdbc:h2:mem:");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -38,9 +38,8 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(
|
||||
properties = { "app.datasource.url=jdbc:h2:mem:configurable;DB_CLOSE_DELAY=-1",
|
||||
"app.datasource.configuration.maximum-pool-size=42" })
|
||||
@SpringBootTest(properties = { "app.datasource.url=jdbc:h2:mem:configurable;DB_CLOSE_DELAY=-1",
|
||||
"app.datasource.configuration.maximum-pool-size=42" })
|
||||
@Import(ConfigurableDataSourceExample.ConfigurableDataSourceConfiguration.class)
|
||||
public class ConfigurableDataSourceExampleTests {
|
||||
|
||||
@@ -51,8 +50,7 @@ public class ConfigurableDataSourceExampleTests {
|
||||
public void validateConfiguration() throws SQLException {
|
||||
assertThat(this.context.getBeansOfType(DataSource.class)).hasSize(1);
|
||||
HikariDataSource dataSource = this.context.getBean(HikariDataSource.class);
|
||||
assertThat(dataSource.getConnection().getMetaData().getURL())
|
||||
.isEqualTo("jdbc:h2:mem:configurable");
|
||||
assertThat(dataSource.getConnection().getMetaData().getURL()).isEqualTo("jdbc:h2:mem:configurable");
|
||||
assertThat(dataSource.getMaximumPoolSize()).isEqualTo(42);
|
||||
}
|
||||
|
||||
|
||||
@@ -38,9 +38,8 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(
|
||||
properties = { "app.datasource.jdbc-url=jdbc:h2:mem:simple;DB_CLOSE_DELAY=-1",
|
||||
"app.datasource.maximum-pool-size=42" })
|
||||
@SpringBootTest(properties = { "app.datasource.jdbc-url=jdbc:h2:mem:simple;DB_CLOSE_DELAY=-1",
|
||||
"app.datasource.maximum-pool-size=42" })
|
||||
@Import(SimpleDataSourceExample.SimpleDataSourceConfiguration.class)
|
||||
public class SimpleDataSourceExampleTests {
|
||||
|
||||
@@ -51,8 +50,7 @@ public class SimpleDataSourceExampleTests {
|
||||
public void validateConfiguration() throws SQLException {
|
||||
assertThat(this.context.getBeansOfType(DataSource.class)).hasSize(1);
|
||||
HikariDataSource dataSource = this.context.getBean(HikariDataSource.class);
|
||||
assertThat(dataSource.getConnection().getMetaData().getURL())
|
||||
.isEqualTo("jdbc:h2:mem:simple");
|
||||
assertThat(dataSource.getConnection().getMetaData().getURL()).isEqualTo("jdbc:h2:mem:simple");
|
||||
assertThat(dataSource.getMaximumPoolSize()).isEqualTo(42);
|
||||
}
|
||||
|
||||
|
||||
@@ -38,9 +38,8 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(
|
||||
properties = { "app.datasource.second.url=jdbc:h2:mem:bar;DB_CLOSE_DELAY=-1",
|
||||
"app.datasource.second.max-total=42" })
|
||||
@SpringBootTest(properties = { "app.datasource.second.url=jdbc:h2:mem:bar;DB_CLOSE_DELAY=-1",
|
||||
"app.datasource.second.max-total=42" })
|
||||
@Import(SimpleTwoDataSourcesExample.SimpleDataSourcesConfiguration.class)
|
||||
public class SimpleTwoDataSourcesExampleTests {
|
||||
|
||||
@@ -52,12 +51,9 @@ public class SimpleTwoDataSourcesExampleTests {
|
||||
assertThat(this.context.getBeansOfType(DataSource.class)).hasSize(2);
|
||||
DataSource dataSource = this.context.getBean(DataSource.class);
|
||||
assertThat(this.context.getBean("firstDataSource")).isSameAs(dataSource);
|
||||
assertThat(dataSource.getConnection().getMetaData().getURL())
|
||||
.startsWith("jdbc:h2:mem:");
|
||||
BasicDataSource secondDataSource = this.context.getBean("secondDataSource",
|
||||
BasicDataSource.class);
|
||||
assertThat(secondDataSource.getUrl())
|
||||
.isEqualTo("jdbc:h2:mem:bar;DB_CLOSE_DELAY=-1");
|
||||
assertThat(dataSource.getConnection().getMetaData().getURL()).startsWith("jdbc:h2:mem:");
|
||||
BasicDataSource secondDataSource = this.context.getBean("secondDataSource", BasicDataSource.class);
|
||||
assertThat(secondDataSource.getUrl()).isEqualTo("jdbc:h2:mem:bar;DB_CLOSE_DELAY=-1");
|
||||
assertThat(secondDataSource.getMaxTotal()).isEqualTo(42);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -34,9 +34,8 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
@SpringBootConfiguration
|
||||
@ImportAutoConfiguration({ ServletWebServerFactoryAutoConfiguration.class,
|
||||
DispatcherServletAutoConfiguration.class, JacksonAutoConfiguration.class,
|
||||
HttpMessageConvertersAutoConfiguration.class })
|
||||
@ImportAutoConfiguration({ ServletWebServerFactoryAutoConfiguration.class, DispatcherServletAutoConfiguration.class,
|
||||
JacksonAutoConfiguration.class, HttpMessageConvertersAutoConfiguration.class })
|
||||
class SampleWebClientConfiguration {
|
||||
|
||||
@RestController
|
||||
@@ -44,9 +43,7 @@ class SampleWebClientConfiguration {
|
||||
|
||||
@RequestMapping("/example")
|
||||
public ResponseEntity<String> example() {
|
||||
return ResponseEntity.ok()
|
||||
.location(URI.create("https://other.example.com/example"))
|
||||
.body("test");
|
||||
return ResponseEntity.ok().location(URI.create("https://other.example.com/example")).body("test");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -48,8 +48,7 @@ public class SampleWebClientTests {
|
||||
|
||||
@Test
|
||||
public void testRequest() {
|
||||
HttpHeaders headers = this.template.getForEntity("/example", String.class)
|
||||
.getHeaders();
|
||||
HttpHeaders headers = this.template.getForEntity("/example", String.class).getHeaders();
|
||||
assertThat(headers.getLocation()).hasHost("other.example.com");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user