Skip to content

Commit

Permalink
Include SQL init auto-config in Data RDBC test slice
Browse files Browse the repository at this point in the history
Closes gh-24741
  • Loading branch information
wilkinsona committed Apr 14, 2021
1 parent 05adf02 commit 9d0e1a2
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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();
}

}

}

0 comments on commit 9d0e1a2

Please sign in to comment.