Skip to content

Commit 05adf02

Browse files
committed
Include SQL init auto-config in JDBC-based test slices
Closes gh-25323
1 parent e2252c7 commit 05adf02

File tree

6 files changed

+20
-13
lines changed

6 files changed

+20
-13
lines changed

spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/jdbc/TestDatabaseAutoConfiguration.java

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 the original author or authors.
2+
* Copyright 2012-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,7 +16,8 @@
1616

1717
package org.springframework.boot.test.autoconfigure.jdbc;
1818

19-
import java.util.Collections;
19+
import java.util.HashMap;
20+
import java.util.Map;
2021

2122
import javax.sql.DataSource;
2223

@@ -173,8 +174,11 @@ private static class EmbeddedDataSourceFactory {
173174
EmbeddedDataSourceFactory(Environment environment) {
174175
this.environment = environment;
175176
if (environment instanceof ConfigurableEnvironment) {
176-
((ConfigurableEnvironment) environment).getPropertySources().addFirst(new MapPropertySource(
177-
"testDatabase", Collections.singletonMap("spring.datasource.schema-username", "")));
177+
Map<String, Object> source = new HashMap<>();
178+
source.put("spring.datasource.schema-username", "");
179+
source.put("spring.sql.init.username", "");
180+
((ConfigurableEnvironment) environment).getPropertySources()
181+
.addFirst(new MapPropertySource("testDatabase", source));
178182
}
179183
}
180184

spring-boot-project/spring-boot-test-autoconfigure/src/main/resources/META-INF/spring.factories

+4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration,\
1818
org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration,\
1919
org.springframework.boot.autoconfigure.jdbc.JdbcTemplateAutoConfiguration,\
2020
org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration,\
21+
org.springframework.boot.autoconfigure.sql.init.SqlInitializationAutoConfiguration,\
2122
org.springframework.boot.autoconfigure.transaction.TransactionAutoConfiguration
2223

2324
# AutoConfigureDataJpa auto-configuration imports
@@ -29,6 +30,7 @@ org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConf
2930
org.springframework.boot.autoconfigure.jdbc.JdbcTemplateAutoConfiguration,\
3031
org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration,\
3132
org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration,\
33+
org.springframework.boot.autoconfigure.sql.init.SqlInitializationAutoConfiguration,\
3234
org.springframework.boot.autoconfigure.transaction.TransactionAutoConfiguration
3335

3436
# AutoConfigureDataLdap auto-configuration imports
@@ -79,6 +81,7 @@ org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration,\
7981
org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration,\
8082
org.springframework.boot.autoconfigure.jdbc.JdbcTemplateAutoConfiguration,\
8183
org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration,\
84+
org.springframework.boot.autoconfigure.sql.init.SqlInitializationAutoConfiguration,\
8285
org.springframework.boot.autoconfigure.transaction.TransactionAutoConfiguration
8386

8487
# AutoConfigureTestDatabase auto-configuration imports
@@ -93,6 +96,7 @@ org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration,\
9396
org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration,\
9497
org.springframework.boot.autoconfigure.jooq.JooqAutoConfiguration,\
9598
org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration,\
99+
org.springframework.boot.autoconfigure.sql.init.SqlInitializationAutoConfiguration,\
96100
org.springframework.boot.autoconfigure.transaction.TransactionAutoConfiguration
97101

98102
# AutoConfigureJson auto-configuration imports

spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/jdbc/DataJdbcTestIntegrationTests.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -39,7 +39,7 @@
3939
*/
4040
@DataJdbcTest
4141
@TestPropertySource(
42-
properties = "spring.datasource.schema=classpath:org/springframework/boot/test/autoconfigure/data/jdbc/schema.sql")
42+
properties = "spring.sql.init.schemaLocations=classpath:org/springframework/boot/test/autoconfigure/data/jdbc/schema.sql")
4343
class DataJdbcTestIntegrationTests {
4444

4545
@Autowired

spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/jdbc/JdbcTestIntegrationTests.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -41,7 +41,7 @@
4141
*/
4242
@JdbcTest
4343
@TestPropertySource(
44-
properties = "spring.datasource.schema=classpath:org/springframework/boot/test/autoconfigure/jdbc/schema.sql")
44+
properties = "spring.sql.init.schemaLocations=classpath:org/springframework/boot/test/autoconfigure/jdbc/schema.sql")
4545
class JdbcTestIntegrationTests {
4646

4747
@Autowired

spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/jdbc/JdbcTestWithIncludeFilterIntegrationTests.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -32,7 +32,7 @@
3232
*/
3333
@JdbcTest(includeFilters = @Filter(Repository.class))
3434
@TestPropertySource(
35-
properties = "spring.datasource.schema=classpath:org/springframework/boot/test/autoconfigure/jdbc/schema.sql")
35+
properties = "spring.sql.init.schemaLocations=classpath:org/springframework/boot/test/autoconfigure/jdbc/schema.sql")
3636
class JdbcTestWithIncludeFilterIntegrationTests {
3737

3838
@Autowired

spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/orm/jpa/DataJpaTestSchemaCredentialsIntegrationTests.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 the original author or authors.
2+
* Copyright 2012-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -32,8 +32,7 @@
3232
* @author Andy Wilkinson
3333
*/
3434
@DataJpaTest
35-
@TestPropertySource(
36-
properties = { "spring.datasource.schema-username=alice", "spring.datasource.schema-password=secret" })
35+
@TestPropertySource(properties = { "spring.sql.init.username=alice", "spring.sql.init.password=secret" })
3736
class DataJpaTestSchemaCredentialsIntegrationTests {
3837

3938
@Autowired

0 commit comments

Comments
 (0)