mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-09-03 03:43:21 +08:00
Auto-configure Flyway and Liquibase when using DataJpaTest
Closes gh-5716
This commit is contained in:
parent
0a765e36f1
commit
c1a2a77cbe
@ -24,8 +24,10 @@ import java.lang.annotation.Target;
|
||||
|
||||
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.data.jpa.JpaRepositoriesAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.transaction.TransactionAutoConfiguration;
|
||||
|
||||
@ -35,6 +37,7 @@ import org.springframework.boot.autoconfigure.transaction.TransactionAutoConfigu
|
||||
* this annotation directly.
|
||||
*
|
||||
* @author Phillip Webb
|
||||
* @author Andy Wilkinson
|
||||
* @since 1.4.0
|
||||
* @see DataJpaTest
|
||||
*/
|
||||
@ -44,7 +47,8 @@ import org.springframework.boot.autoconfigure.transaction.TransactionAutoConfigu
|
||||
@ImportAutoConfiguration({ HibernateJpaAutoConfiguration.class,
|
||||
JpaRepositoriesAutoConfiguration.class, TransactionAutoConfiguration.class,
|
||||
DataSourceTransactionManagerAutoConfiguration.class,
|
||||
DataSourceAutoConfiguration.class })
|
||||
DataSourceAutoConfiguration.class, FlywayAutoConfiguration.class,
|
||||
LiquibaseAutoConfiguration.class })
|
||||
public @interface AutoConfigureDataJpa {
|
||||
|
||||
}
|
||||
|
@ -25,6 +25,10 @@ import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionEvaluationReport;
|
||||
import org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
@ -34,6 +38,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* Integration tests for {@link DataJpaTest}.
|
||||
*
|
||||
* @author Phillip Webb
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@DataJpaTest
|
||||
@ -92,4 +97,22 @@ public class DataJpaTestIntegrationTests {
|
||||
this.applicationContext.getBean(ExampleComponent.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void flywayAutoConfigurationWasImported() {
|
||||
ConditionEvaluationReport report = ConditionEvaluationReport
|
||||
.get((ConfigurableListableBeanFactory) this.applicationContext
|
||||
.getAutowireCapableBeanFactory());
|
||||
assertThat(report.getConditionAndOutcomesBySource().keySet())
|
||||
.contains(FlywayAutoConfiguration.class.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void liquibaseAutoConfigurationWasImported() {
|
||||
ConditionEvaluationReport report = ConditionEvaluationReport
|
||||
.get((ConfigurableListableBeanFactory) this.applicationContext
|
||||
.getAutowireCapableBeanFactory());
|
||||
assertThat(report.getConditionAndOutcomesBySource().keySet())
|
||||
.contains(LiquibaseAutoConfiguration.class.getName());
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user