From 9d0e1a2cb3726a240d8e5ec7b2635b0efd6fbec6 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Wed, 14 Apr 2021 16:37:33 +0100 Subject: [PATCH] Include SQL init auto-config in Data RDBC test slice Closes gh-24741 --- .../main/resources/META-INF/spring.factories | 1 + .../r2dbc/DataR2dbcTestIntegrationTests.java | 21 ++----------------- 2 files changed, 3 insertions(+), 19 deletions(-) diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/main/resources/META-INF/spring.factories b/spring-boot-project/spring-boot-test-autoconfigure/src/main/resources/META-INF/spring.factories index d858fbb79197..8b5e19bbb3aa 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/main/resources/META-INF/spring.factories +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/main/resources/META-INF/spring.factories @@ -67,6 +67,7 @@ org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration,\ org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration,\ org.springframework.boot.autoconfigure.r2dbc.R2dbcAutoConfiguration,\ org.springframework.boot.autoconfigure.r2dbc.R2dbcTransactionManagerAutoConfiguration,\ +org.springframework.boot.autoconfigure.sql.init.SqlInitializationAutoConfiguration,\ org.springframework.boot.autoconfigure.transaction.TransactionAutoConfiguration # AutoConfigureDataRedis auto-configuration imports diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/r2dbc/DataR2dbcTestIntegrationTests.java b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/r2dbc/DataR2dbcTestIntegrationTests.java index 39158181b273..6953a2bc96fb 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/r2dbc/DataR2dbcTestIntegrationTests.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/r2dbc/DataR2dbcTestIntegrationTests.java @@ -21,12 +21,7 @@ import reactor.test.StepVerifier; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.TestConfiguration; import org.springframework.context.ApplicationContext; -import org.springframework.core.io.DefaultResourceLoader; -import org.springframework.core.io.Resource; -import org.springframework.core.io.ResourceLoader; -import org.springframework.r2dbc.connection.init.ResourceDatabasePopulator; import org.springframework.r2dbc.core.DatabaseClient; import static org.assertj.core.api.Assertions.assertThat; @@ -36,7 +31,8 @@ * * @author Mark Paluch */ -@DataR2dbcTest +@DataR2dbcTest( + properties = "spring.sql.init.schemaLocations=classpath:org/springframework/boot/test/autoconfigure/data/r2dbc/schema.sql") class DataR2dbcTestIntegrationTests { @Autowired @@ -64,17 +60,4 @@ void registersExampleRepository() { assertThat(this.applicationContext.getBeanNamesForType(ExampleRepository.class)).isNotEmpty(); } - @TestConfiguration - static class DatabaseInitializationConfiguration { - - @Autowired - void initializeDatabase(ConnectionFactory connectionFactory) { - ResourceLoader resourceLoader = new DefaultResourceLoader(); - Resource[] scripts = new Resource[] { resourceLoader - .getResource("classpath:org/springframework/boot/test/autoconfigure/data/r2dbc/schema.sql") }; - new ResourceDatabasePopulator(scripts).populate(connectionFactory).block(); - } - - } - }