Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
* @author Eddú Meléndez
* @author Dominic Gunn
* @author Dan Zheng
* @author András Deák
* @since 1.1.0
*/
@SuppressWarnings("deprecation")
Expand Down Expand Up @@ -163,11 +164,11 @@ public Flyway flyway() {
private DataSource configureDataSource(FluentConfiguration configuration) {
if (this.properties.isCreateDataSource()) {
String url = getProperty(this.properties::getUrl,
this.dataSourceProperties::getUrl);
this.dataSourceProperties::determineUrl);
String user = getProperty(this.properties::getUser,
this.dataSourceProperties::getUsername);
this.dataSourceProperties::determineUsername);
String password = getProperty(this.properties::getPassword,
this.dataSourceProperties::getPassword);
this.dataSourceProperties::determinePassword);
configuration.dataSource(url, user, password);
if (!CollectionUtils.isEmpty(this.properties.getInitSqls())) {
String initSql = StringUtils.collectionToDelimitedString(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
* @author Andy Wilkinson
* @author Dominic Gunn
* @author Dan Zheng
* @author András Deák
* @since 1.1.0
*/
@Configuration
Expand Down Expand Up @@ -163,11 +164,11 @@ private DataSource getDataSource() {

private DataSource createNewDataSource() {
String url = getProperty(this.properties::getUrl,
this.dataSourceProperties::getUrl);
this.dataSourceProperties::determineUrl);
String user = getProperty(this.properties::getUser,
this.dataSourceProperties::getUsername);
this.dataSourceProperties::determineUsername);
String password = getProperty(this.properties::getPassword,
this.dataSourceProperties::getPassword);
this.dataSourceProperties::determinePassword);
return DataSourceBuilder.create().url(url).username(user).password(password)
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.flywaydb.core.api.callback.Context;
import org.flywaydb.core.api.callback.Event;
import org.flywaydb.core.api.callback.FlywayCallback;
import org.flywaydb.core.internal.jdbc.DriverDataSource;
import org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform;
import org.junit.Test;
import org.mockito.InOrder;
Expand Down Expand Up @@ -66,6 +67,7 @@
* @author Eddú Meléndez
* @author Stephane Nicoll
* @author Dominic Gunn
* @author András Deák
*/
@SuppressWarnings("deprecation")
public class FlywayAutoConfigurationTests {
Expand Down Expand Up @@ -101,6 +103,31 @@ public void createDataSourceWithUser() {
});
}

@Test
public void createDataSourceFallbackToEmbeddedProperties() {
this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class)
.withPropertyValues("spring.flyway.url:jdbc:hsqldb:mem:flywaytest")
.run((context) -> {
assertThat(context).hasSingleBean(Flyway.class);
assertThat(context.getBean(Flyway.class).getDataSource()).isNotNull();
assertThat(((DriverDataSource) context.getBean(Flyway.class)
.getDataSource()).getUser()).isEqualTo("sa");
assertThat(((DriverDataSource) context.getBean(Flyway.class)
.getDataSource()).getPassword()).isEqualTo("");
});
}

@Test
public void createDataSourceWithUserAndFallbackToEmbeddedProperties() {
this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class)
.withPropertyValues("spring.flyway.user:sa").run((context) -> {
assertThat(context).hasSingleBean(Flyway.class);
assertThat(context.getBean(Flyway.class).getDataSource()).isNotNull();
assertThat(((DriverDataSource) context.getBean(Flyway.class)
.getDataSource()).getUrl()).startsWith("jdbc:h2:mem:");
});
}

@Test
public void flywayDataSource() {
this.contextRunner.withUserConfiguration(FlywayDataSourceConfiguration.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
* @author Andy Wilkinson
* @author Stephane Nicoll
* @author Dominic Gunn
* @author András Deák
*/
public class LiquibaseAutoConfigurationTests {

Expand Down Expand Up @@ -221,6 +222,32 @@ public void overrideUser() {
}));
}

@Test
public 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
public 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
public void overrideTestRollbackOnUpdate() {
this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class)
Expand Down
1 change: 1 addition & 0 deletions src/checkstyle/checkstyle-suppressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,5 @@
<suppress files="LogbackMetricsAutoConfiguration\.java" checks="IllegalImport" />
<suppress files="RemoteUrlPropertyExtractorTests\.java" checks="IllegalImport" />
<suppress files="SampleLogbackApplication\.java" checks="IllegalImport" />
<suppress files="FlywayAutoConfigurationTests\.java" checks="IllegalImport" />
</suppressions>