File tree Expand file tree Collapse file tree 4 files changed +56
-6
lines changed
spring-boot-project/spring-boot-autoconfigure/src
main/java/org/springframework/boot/autoconfigure
test/java/org/springframework/boot/autoconfigure Expand file tree Collapse file tree 4 files changed +56
-6
lines changed Original file line number Diff line number Diff line change 79
79
* @author Eddú Meléndez
80
80
* @author Dominic Gunn
81
81
* @author Dan Zheng
82
+ * @author András Deák
82
83
* @since 1.1.0
83
84
*/
84
85
@ SuppressWarnings ("deprecation" )
@@ -156,9 +157,10 @@ public Flyway flyway() {
156
157
157
158
private DataSource configureDataSource (FluentConfiguration configuration ) {
158
159
if (this .properties .isCreateDataSource ()) {
159
- String url = getProperty (this .properties ::getUrl , this .dataSourceProperties ::getUrl );
160
- String user = getProperty (this .properties ::getUser , this .dataSourceProperties ::getUsername );
161
- String password = getProperty (this .properties ::getPassword , this .dataSourceProperties ::getPassword );
160
+ String url = getProperty (this .properties ::getUrl , this .dataSourceProperties ::determineUrl );
161
+ String user = getProperty (this .properties ::getUser , this .dataSourceProperties ::determineUsername );
162
+ String password = getProperty (this .properties ::getPassword ,
163
+ this .dataSourceProperties ::determinePassword );
162
164
configuration .dataSource (url , user , password );
163
165
if (!CollectionUtils .isEmpty (this .properties .getInitSqls ())) {
164
166
String initSql = StringUtils .collectionToDelimitedString (this .properties .getInitSqls (), "\n " );
Original file line number Diff line number Diff line change 61
61
* @author Andy Wilkinson
62
62
* @author Dominic Gunn
63
63
* @author Dan Zheng
64
+ * @author András Deák
64
65
* @since 1.1.0
65
66
*/
66
67
@ Configuration
@@ -153,9 +154,9 @@ private DataSource getDataSource() {
153
154
}
154
155
155
156
private DataSource createNewDataSource () {
156
- String url = getProperty (this .properties ::getUrl , this .dataSourceProperties ::getUrl );
157
- String user = getProperty (this .properties ::getUser , this .dataSourceProperties ::getUsername );
158
- String password = getProperty (this .properties ::getPassword , this .dataSourceProperties ::getPassword );
157
+ String url = getProperty (this .properties ::getUrl , this .dataSourceProperties ::determineUrl );
158
+ String user = getProperty (this .properties ::getUser , this .dataSourceProperties ::determineUsername );
159
+ String password = getProperty (this .properties ::getPassword , this .dataSourceProperties ::determinePassword );
159
160
return DataSourceBuilder .create ().url (url ).username (user ).password (password ).build ();
160
161
}
161
162
Original file line number Diff line number Diff line change 66
66
* @author Eddú Meléndez
67
67
* @author Stephane Nicoll
68
68
* @author Dominic Gunn
69
+ * @author András Deák
69
70
*/
70
71
@ SuppressWarnings ("deprecation" )
71
72
public class FlywayAutoConfigurationTests {
@@ -98,6 +99,29 @@ public void createDataSourceWithUser() {
98
99
});
99
100
}
100
101
102
+ @ Test
103
+ public void createDataSourceFallbackToEmbeddedProperties () {
104
+ this .contextRunner .withUserConfiguration (EmbeddedDataSourceConfiguration .class )
105
+ .withPropertyValues ("spring.flyway.url:jdbc:hsqldb:mem:flywaytest" ).run ((context ) -> {
106
+ assertThat (context ).hasSingleBean (Flyway .class );
107
+ DataSource dataSource = context .getBean (Flyway .class ).getDataSource ();
108
+ assertThat (dataSource ).isNotNull ();
109
+ assertThat (dataSource ).hasFieldOrPropertyWithValue ("user" , "sa" );
110
+ assertThat (dataSource ).hasFieldOrPropertyWithValue ("password" , "" );
111
+ });
112
+ }
113
+
114
+ @ Test
115
+ public void createDataSourceWithUserAndFallbackToEmbeddedProperties () {
116
+ this .contextRunner .withUserConfiguration (EmbeddedDataSourceConfiguration .class )
117
+ .withPropertyValues ("spring.flyway.user:sa" ).run ((context ) -> {
118
+ assertThat (context ).hasSingleBean (Flyway .class );
119
+ DataSource dataSource = context .getBean (Flyway .class ).getDataSource ();
120
+ assertThat (dataSource ).isNotNull ();
121
+ assertThat (dataSource ).extracting ("url" ).hasSize (1 ).first ().asString ().startsWith ("jdbc:h2:mem:" );
122
+ });
123
+ }
124
+
101
125
@ Test
102
126
public void flywayDataSource () {
103
127
this .contextRunner
Original file line number Diff line number Diff line change 60
60
* @author Andy Wilkinson
61
61
* @author Stephane Nicoll
62
62
* @author Dominic Gunn
63
+ * @author András Deák
63
64
*/
64
65
public class LiquibaseAutoConfigurationTests {
65
66
@@ -199,6 +200,28 @@ public void overrideUser() {
199
200
}));
200
201
}
201
202
203
+ @ Test
204
+ public void overrideDataSourceAndFallbackToEmbeddedProperties () {
205
+ this .contextRunner .withUserConfiguration (EmbeddedDataSourceConfiguration .class )
206
+ .withPropertyValues ("spring.liquibase.url:jdbc:hsqldb:mem:liquibase" )
207
+ .run (assertLiquibase ((liquibase ) -> {
208
+ DataSource dataSource = liquibase .getDataSource ();
209
+ assertThat (((HikariDataSource ) dataSource ).isClosed ()).isTrue ();
210
+ assertThat (((HikariDataSource ) dataSource ).getUsername ()).isEqualTo ("sa" );
211
+ assertThat (((HikariDataSource ) dataSource ).getPassword ()).isEqualTo ("" );
212
+ }));
213
+ }
214
+
215
+ @ Test
216
+ public void overrideUserAndFallbackToEmbeddedProperties () {
217
+ this .contextRunner .withUserConfiguration (EmbeddedDataSourceConfiguration .class )
218
+ .withPropertyValues ("spring.liquibase.user:sa" ).run (assertLiquibase ((liquibase ) -> {
219
+ DataSource dataSource = liquibase .getDataSource ();
220
+ assertThat (((HikariDataSource ) dataSource ).isClosed ()).isTrue ();
221
+ assertThat (((HikariDataSource ) dataSource ).getJdbcUrl ()).startsWith ("jdbc:h2:mem:" );
222
+ }));
223
+ }
224
+
202
225
@ Test
203
226
public void overrideTestRollbackOnUpdate () {
204
227
this .contextRunner .withUserConfiguration (EmbeddedDataSourceConfiguration .class )
You can’t perform that action at this time.
0 commit comments