@ -24,7 +24,6 @@ import javax.sql.DataSource;
@@ -24,7 +24,6 @@ import javax.sql.DataSource;
import org.apache.commons.dbcp.BasicDataSource ;
import org.junit.Test ;
import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration ;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration ;
import org.springframework.context.annotation.AnnotationConfigApplicationContext ;
import org.springframework.context.annotation.Bean ;
import org.springframework.context.annotation.Configuration ;
@ -86,6 +85,19 @@ public class DataSourceAutoConfigurationTests {
@@ -86,6 +85,19 @@ public class DataSourceAutoConfigurationTests {
@Test
public void testDataSourceInitialized ( ) throws Exception {
this . context . register ( DataSourceAutoConfiguration . class ,
PropertyPlaceholderAutoConfiguration . class ) ;
this . context . refresh ( ) ;
DataSource dataSource = this . context . getBean ( DataSource . class ) ;
assertTrue ( dataSource instanceof org . apache . tomcat . jdbc . pool . DataSource ) ;
assertNotNull ( dataSource ) ;
JdbcOperations template = new JdbcTemplate ( dataSource ) ;
assertEquals ( new Integer ( 0 ) ,
template . queryForObject ( "SELECT COUNT(*) from BAR" , Integer . class ) ) ;
}
@Test
public void testDataSourceInitializedWithExplicitScript ( ) throws Exception {
this . context . register ( DataSourceAutoConfiguration . class ,
PropertyPlaceholderAutoConfiguration . class ) ;
Map < String , Object > map = new HashMap < String , Object > ( ) ;
@ -102,6 +114,29 @@ public class DataSourceAutoConfigurationTests {
@@ -102,6 +114,29 @@ public class DataSourceAutoConfigurationTests {
template . queryForObject ( "SELECT COUNT(*) from FOO" , Integer . class ) ) ;
}
@Test
public void testDataSourceInitializedWithMultipleScripts ( ) throws Exception {
this . context . register ( DataSourceAutoConfiguration . class ,
PropertyPlaceholderAutoConfiguration . class ) ;
Map < String , Object > map = new HashMap < String , Object > ( ) ;
map . put ( "spring.database.schema" ,
ClassUtils . addResourcePathToPackagePath ( getClass ( ) , "schema.sql" )
+ ","
+ ClassUtils . addResourcePathToPackagePath ( getClass ( ) ,
"another.sql" ) ) ;
this . context . getEnvironment ( ) . getPropertySources ( )
. addFirst ( new MapPropertySource ( "test" , map ) ) ;
this . context . refresh ( ) ;
DataSource dataSource = this . context . getBean ( DataSource . class ) ;
assertTrue ( dataSource instanceof org . apache . tomcat . jdbc . pool . DataSource ) ;
assertNotNull ( dataSource ) ;
JdbcOperations template = new JdbcTemplate ( dataSource ) ;
assertEquals ( new Integer ( 0 ) ,
template . queryForObject ( "SELECT COUNT(*) from FOO" , Integer . class ) ) ;
assertEquals ( new Integer ( 0 ) ,
template . queryForObject ( "SELECT COUNT(*) from SPAM" , Integer . class ) ) ;
}
@Configuration
static class TestDataSourceConfiguration {