Skip to content

Commit 9d355f0

Browse files
committed
Merge branch '2.1.x'
Closes gh-17218
2 parents f36af7b + 6f4d598 commit 9d355f0

File tree

4 files changed

+55
-6
lines changed

4 files changed

+55
-6
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
* @author Eddú Meléndez
8181
* @author Dominic Gunn
8282
* @author Dan Zheng
83+
* @author András Deák
8384
* @since 1.1.0
8485
*/
8586
@SuppressWarnings("deprecation")
@@ -130,9 +131,9 @@ public Flyway flyway(FlywayProperties properties, DataSourceProperties dataSourc
130131
private DataSource configureDataSource(FluentConfiguration configuration, FlywayProperties properties,
131132
DataSourceProperties dataSourceProperties, DataSource flywayDataSource, DataSource dataSource) {
132133
if (properties.isCreateDataSource()) {
133-
String url = getProperty(properties::getUrl, dataSourceProperties::getUrl);
134-
String user = getProperty(properties::getUser, dataSourceProperties::getUsername);
135-
String password = getProperty(properties::getPassword, dataSourceProperties::getPassword);
134+
String url = getProperty(properties::getUrl, dataSourceProperties::determineUrl);
135+
String user = getProperty(properties::getUser, dataSourceProperties::determineUsername);
136+
String password = getProperty(properties::getPassword, dataSourceProperties::determinePassword);
136137
configuration.dataSource(url, user, password);
137138
if (!CollectionUtils.isEmpty(properties.getInitSqls())) {
138139
String initSql = StringUtils.collectionToDelimitedString(properties.getInitSqls(), "\n");

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfiguration.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
* @author Andy Wilkinson
6565
* @author Dominic Gunn
6666
* @author Dan Zheng
67+
* @author András Deák
6768
* @since 1.1.0
6869
*/
6970
@Configuration(proxyBeanMethods = false)
@@ -149,9 +150,9 @@ private DataSource getDataSource(DataSource liquibaseDataSource, DataSource data
149150
}
150151

151152
private DataSource createNewDataSource(DataSourceProperties dataSourceProperties) {
152-
String url = getProperty(this.properties::getUrl, dataSourceProperties::getUrl);
153-
String user = getProperty(this.properties::getUser, dataSourceProperties::getUsername);
154-
String password = getProperty(this.properties::getPassword, dataSourceProperties::getPassword);
153+
String url = getProperty(this.properties::getUrl, dataSourceProperties::determineUrl);
154+
String user = getProperty(this.properties::getUser, dataSourceProperties::determineUsername);
155+
String password = getProperty(this.properties::getPassword, dataSourceProperties::determinePassword);
155156
return DataSourceBuilder.create().url(url).username(user).password(password).build();
156157
}
157158

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfigurationTests.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
* @author Eddú Meléndez
7171
* @author Stephane Nicoll
7272
* @author Dominic Gunn
73+
* @author András Deák
7374
*/
7475
@SuppressWarnings("deprecation")
7576
class FlywayAutoConfigurationTests {
@@ -112,6 +113,29 @@ void createDataSourceWithUser() {
112113
});
113114
}
114115

116+
@Test
117+
void createDataSourceFallbackToEmbeddedProperties() {
118+
this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class)
119+
.withPropertyValues("spring.flyway.url:jdbc:hsqldb:mem:flywaytest").run((context) -> {
120+
assertThat(context).hasSingleBean(Flyway.class);
121+
DataSource dataSource = context.getBean(Flyway.class).getDataSource();
122+
assertThat(dataSource).isNotNull();
123+
assertThat(dataSource).hasFieldOrPropertyWithValue("user", "sa");
124+
assertThat(dataSource).hasFieldOrPropertyWithValue("password", "");
125+
});
126+
}
127+
128+
@Test
129+
void createDataSourceWithUserAndFallbackToEmbeddedProperties() {
130+
this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class)
131+
.withPropertyValues("spring.flyway.user:sa").run((context) -> {
132+
assertThat(context).hasSingleBean(Flyway.class);
133+
DataSource dataSource = context.getBean(Flyway.class).getDataSource();
134+
assertThat(dataSource).isNotNull();
135+
assertThat(dataSource).extracting("url").hasSize(1).first().asString().startsWith("jdbc:h2:mem:");
136+
});
137+
}
138+
115139
@Test
116140
void flywayDataSource() {
117141
this.contextRunner

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfigurationTests.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
* @author Andy Wilkinson
6565
* @author Stephane Nicoll
6666
* @author Dominic Gunn
67+
* @author András Deák
6768
*/
6869
@ExtendWith(OutputCaptureExtension.class)
6970
class LiquibaseAutoConfigurationTests {
@@ -209,6 +210,28 @@ void overrideUser() {
209210
}));
210211
}
211212

213+
@Test
214+
void overrideDataSourceAndFallbackToEmbeddedProperties() {
215+
this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class)
216+
.withPropertyValues("spring.liquibase.url:jdbc:hsqldb:mem:liquibase")
217+
.run(assertLiquibase((liquibase) -> {
218+
DataSource dataSource = liquibase.getDataSource();
219+
assertThat(((HikariDataSource) dataSource).isClosed()).isTrue();
220+
assertThat(((HikariDataSource) dataSource).getUsername()).isEqualTo("sa");
221+
assertThat(((HikariDataSource) dataSource).getPassword()).isEqualTo("");
222+
}));
223+
}
224+
225+
@Test
226+
void overrideUserAndFallbackToEmbeddedProperties() {
227+
this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class)
228+
.withPropertyValues("spring.liquibase.user:sa").run(assertLiquibase((liquibase) -> {
229+
DataSource dataSource = liquibase.getDataSource();
230+
assertThat(((HikariDataSource) dataSource).isClosed()).isTrue();
231+
assertThat(((HikariDataSource) dataSource).getJdbcUrl()).startsWith("jdbc:h2:mem:");
232+
}));
233+
}
234+
212235
@Test
213236
void overrideTestRollbackOnUpdate() {
214237
this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class)

0 commit comments

Comments
 (0)