Merge branch '2.1.x'

Closes gh-17218
This commit is contained in:
Andy Wilkinson
2019-06-17 13:19:45 +01:00
4 changed files with 55 additions and 6 deletions

View File

@@ -80,6 +80,7 @@ import org.springframework.util.StringUtils;
* @author Eddú Meléndez
* @author Dominic Gunn
* @author Dan Zheng
* @author András Deák
* @since 1.1.0
*/
@SuppressWarnings("deprecation")
@@ -130,9 +131,9 @@ public class FlywayAutoConfiguration {
private DataSource configureDataSource(FluentConfiguration configuration, FlywayProperties properties,
DataSourceProperties dataSourceProperties, DataSource flywayDataSource, DataSource dataSource) {
if (properties.isCreateDataSource()) {
String url = getProperty(properties::getUrl, dataSourceProperties::getUrl);
String user = getProperty(properties::getUser, dataSourceProperties::getUsername);
String password = getProperty(properties::getPassword, dataSourceProperties::getPassword);
String url = getProperty(properties::getUrl, dataSourceProperties::determineUrl);
String user = getProperty(properties::getUser, dataSourceProperties::determineUsername);
String password = getProperty(properties::getPassword, dataSourceProperties::determinePassword);
configuration.dataSource(url, user, password);
if (!CollectionUtils.isEmpty(properties.getInitSqls())) {
String initSql = StringUtils.collectionToDelimitedString(properties.getInitSqls(), "\n");

View File

@@ -64,6 +64,7 @@ import org.springframework.util.Assert;
* @author Andy Wilkinson
* @author Dominic Gunn
* @author Dan Zheng
* @author András Deák
* @since 1.1.0
*/
@Configuration(proxyBeanMethods = false)
@@ -149,9 +150,9 @@ public class LiquibaseAutoConfiguration {
}
private DataSource createNewDataSource(DataSourceProperties dataSourceProperties) {
String url = getProperty(this.properties::getUrl, dataSourceProperties::getUrl);
String user = getProperty(this.properties::getUser, dataSourceProperties::getUsername);
String password = getProperty(this.properties::getPassword, dataSourceProperties::getPassword);
String url = getProperty(this.properties::getUrl, dataSourceProperties::determineUrl);
String user = getProperty(this.properties::getUser, dataSourceProperties::determineUsername);
String password = getProperty(this.properties::getPassword, dataSourceProperties::determinePassword);
return DataSourceBuilder.create().url(url).username(user).password(password).build();
}

View File

@@ -70,6 +70,7 @@ import static org.mockito.Mockito.mock;
* @author Eddú Meléndez
* @author Stephane Nicoll
* @author Dominic Gunn
* @author András Deák
*/
@SuppressWarnings("deprecation")
class FlywayAutoConfigurationTests {
@@ -112,6 +113,29 @@ class FlywayAutoConfigurationTests {
});
}
@Test
void createDataSourceFallbackToEmbeddedProperties() {
this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class)
.withPropertyValues("spring.flyway.url:jdbc:hsqldb:mem:flywaytest").run((context) -> {
assertThat(context).hasSingleBean(Flyway.class);
DataSource dataSource = context.getBean(Flyway.class).getDataSource();
assertThat(dataSource).isNotNull();
assertThat(dataSource).hasFieldOrPropertyWithValue("user", "sa");
assertThat(dataSource).hasFieldOrPropertyWithValue("password", "");
});
}
@Test
void createDataSourceWithUserAndFallbackToEmbeddedProperties() {
this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class)
.withPropertyValues("spring.flyway.user:sa").run((context) -> {
assertThat(context).hasSingleBean(Flyway.class);
DataSource dataSource = context.getBean(Flyway.class).getDataSource();
assertThat(dataSource).isNotNull();
assertThat(dataSource).extracting("url").hasSize(1).first().asString().startsWith("jdbc:h2:mem:");
});
}
@Test
void flywayDataSource() {
this.contextRunner

View File

@@ -64,6 +64,7 @@ import static org.assertj.core.api.Assertions.contentOf;
* @author Andy Wilkinson
* @author Stephane Nicoll
* @author Dominic Gunn
* @author András Deák
*/
@ExtendWith(OutputCaptureExtension.class)
class LiquibaseAutoConfigurationTests {
@@ -209,6 +210,28 @@ class LiquibaseAutoConfigurationTests {
}));
}
@Test
void overrideDataSourceAndFallbackToEmbeddedProperties() {
this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class)
.withPropertyValues("spring.liquibase.url:jdbc:hsqldb:mem:liquibase")
.run(assertLiquibase((liquibase) -> {
DataSource dataSource = liquibase.getDataSource();
assertThat(((HikariDataSource) dataSource).isClosed()).isTrue();
assertThat(((HikariDataSource) dataSource).getUsername()).isEqualTo("sa");
assertThat(((HikariDataSource) dataSource).getPassword()).isEqualTo("");
}));
}
@Test
void overrideUserAndFallbackToEmbeddedProperties() {
this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class)
.withPropertyValues("spring.liquibase.user:sa").run(assertLiquibase((liquibase) -> {
DataSource dataSource = liquibase.getDataSource();
assertThat(((HikariDataSource) dataSource).isClosed()).isTrue();
assertThat(((HikariDataSource) dataSource).getJdbcUrl()).startsWith("jdbc:h2:mem:");
}));
}
@Test
void overrideTestRollbackOnUpdate() {
this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class)