|
|
|
@ -21,6 +21,7 @@ import javax.sql.DataSource;
|
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
|
|
|
|
|
|
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
|
|
|
|
import org.springframework.boot.test.autoconfigure.jdbc.TestDatabaseAutoConfiguration.EmbeddedDataSourceFactoryBean;
|
|
|
|
|
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
|
|
|
|
import org.springframework.context.annotation.Bean;
|
|
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
|
@ -49,6 +50,7 @@ class TestDatabaseAutoConfigurationTests {
|
|
|
|
|
@Test
|
|
|
|
|
void replaceWithUniqueDatabase() {
|
|
|
|
|
this.contextRunner.withUserConfiguration(ExistingDataSourceConfiguration.class).run((context) -> {
|
|
|
|
|
assertThat(context).hasSingleBean(EmbeddedDataSourceFactoryBean.class);
|
|
|
|
|
DataSource datasource = context.getBean(DataSource.class);
|
|
|
|
|
JdbcTemplate jdbcTemplate = new JdbcTemplate(datasource);
|
|
|
|
|
jdbcTemplate.execute("create table example (id int, name varchar);");
|
|
|
|
@ -60,6 +62,13 @@ class TestDatabaseAutoConfigurationTests {
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void whenUsingAotGeneratedArtifactsEmbeddedDataSourceFactoryBeanIsNotDefined() {
|
|
|
|
|
this.contextRunner.withUserConfiguration(ExistingDataSourceConfiguration.class)
|
|
|
|
|
.withSystemProperties("spring.aot.enabled=true")
|
|
|
|
|
.run((context) -> assertThat(context).doesNotHaveBean(EmbeddedDataSourceFactoryBean.class));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Configuration(proxyBeanMethods = false)
|
|
|
|
|
static class ExistingDataSourceConfiguration {
|
|
|
|
|
|
|
|
|
|