Search in sources :

Example 1 with AbstractDriverBasedDataSource

use of org.springframework.jdbc.datasource.AbstractDriverBasedDataSource in project spring-framework by spring-projects.

the class JdbcNamespaceIntegrationTests method assertCorrectSetupAndCloseContext.

private void assertCorrectSetupAndCloseContext(String file, int count, String... dataSources) {
    ConfigurableApplicationContext context = context(file);
    try {
        for (String dataSourceName : dataSources) {
            DataSource dataSource = context.getBean(dataSourceName, DataSource.class);
            assertNumRowsInTestTable(new JdbcTemplate(dataSource), count);
            assertTrue(dataSource instanceof AbstractDriverBasedDataSource);
            AbstractDriverBasedDataSource adbDataSource = (AbstractDriverBasedDataSource) dataSource;
            assertThat(adbDataSource.getUrl(), containsString(dataSourceName));
        }
    } finally {
        context.close();
    }
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) AbstractDriverBasedDataSource(org.springframework.jdbc.datasource.AbstractDriverBasedDataSource) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) AbstractDriverBasedDataSource(org.springframework.jdbc.datasource.AbstractDriverBasedDataSource) DataSource(javax.sql.DataSource)

Example 2 with AbstractDriverBasedDataSource

use of org.springframework.jdbc.datasource.AbstractDriverBasedDataSource in project spring-framework by spring-projects.

the class JdbcNamespaceIntegrationTests method assertCorrectSetupForSingleDataSource.

private void assertCorrectSetupForSingleDataSource(String file, Predicate<String> urlPredicate) {
    ConfigurableApplicationContext context = context(file);
    try {
        DataSource dataSource = context.getBean(DataSource.class);
        assertNumRowsInTestTable(new JdbcTemplate(dataSource), 1);
        assertTrue(dataSource instanceof AbstractDriverBasedDataSource);
        AbstractDriverBasedDataSource adbDataSource = (AbstractDriverBasedDataSource) dataSource;
        assertTrue(urlPredicate.test(adbDataSource.getUrl()));
    } finally {
        context.close();
    }
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) AbstractDriverBasedDataSource(org.springframework.jdbc.datasource.AbstractDriverBasedDataSource) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) AbstractDriverBasedDataSource(org.springframework.jdbc.datasource.AbstractDriverBasedDataSource) DataSource(javax.sql.DataSource)

Aggregations

DataSource (javax.sql.DataSource)2 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)2 JdbcTemplate (org.springframework.jdbc.core.JdbcTemplate)2 AbstractDriverBasedDataSource (org.springframework.jdbc.datasource.AbstractDriverBasedDataSource)2