@ -32,9 +32,11 @@ import org.junit.Test;
import org.junit.rules.TemporaryFolder ;
import org.springframework.beans.factory.BeanCreationException ;
import org.springframework.beans.factory.config.BeanDefinition ;
import org.springframework.boot.SpringApplication ;
import org.springframework.boot.autoconfigure.AutoConfigurations ;
import org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration ;
import org.springframework.boot.autoconfigure.jdbc.JdbcTemplateAutoConfiguration ;
import org.springframework.boot.context.event.ApplicationStartingEvent ;
import org.springframework.boot.jdbc.DataSourceBuilder ;
import org.springframework.boot.liquibase.LiquibaseServiceLocatorApplicationListener ;
@ -61,6 +63,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Stephane Nicoll
* @author Dominic Gunn
* @author Andr á s De á k
* @author Andrii Hrytsiuk
* /
public class LiquibaseAutoConfigurationTests {
@ -300,6 +303,26 @@ public class LiquibaseAutoConfigurationTests {
} ) ;
}
@Test
public void userConfigurationBeans ( ) {
this . contextRunner
. withUserConfiguration ( LiquibaseUserConfiguration . class , EmbeddedDataSourceConfiguration . class )
. run ( ( context ) - > {
assertThat ( context ) . hasBean ( "springLiquibase" ) ;
assertThat ( context ) . doesNotHaveBean ( "liquibase" ) ;
} ) ;
}
@Test
public void userConfigurationJdbcTemplateDependency ( ) {
this . contextRunner . withConfiguration ( AutoConfigurations . of ( JdbcTemplateAutoConfiguration . class ) )
. withUserConfiguration ( LiquibaseUserConfiguration . class , EmbeddedDataSourceConfiguration . class )
. run ( ( context ) - > {
BeanDefinition beanDefinition = context . getBeanFactory ( ) . getBeanDefinition ( "jdbcTemplate" ) ;
assertThat ( beanDefinition . getDependsOn ( ) ) . containsExactly ( "springLiquibase" ) ;
} ) ;
}
private ContextConsumer < AssertableApplicationContext > assertLiquibase ( Consumer < SpringLiquibase > consumer ) {
return ( context ) - > {
assertThat ( context ) . hasSingleBean ( SpringLiquibase . class ) ;
@ -325,4 +348,18 @@ public class LiquibaseAutoConfigurationTests {
}
@Configuration
static class LiquibaseUserConfiguration {
@Bean
SpringLiquibase springLiquibase ( DataSource dataSource ) {
SpringLiquibase liquibase = new SpringLiquibase ( ) ;
liquibase . setChangeLog ( "classpath:/db/changelog/db.changelog-master.yaml" ) ;
liquibase . setShouldRun ( true ) ;
liquibase . setDataSource ( dataSource ) ;
return liquibase ;
}
}
}