Search in sources :

Example 1 with AbstractDriverBasedDataSource

use of cn.taketoday.jdbc.datasource.AbstractDriverBasedDataSource in project today-infrastructure by TAKETODAY.

the class JdbcNamespaceIntegrationTests method assertCorrectSetupAndCloseContext.

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

Example 2 with AbstractDriverBasedDataSource

use of cn.taketoday.jdbc.datasource.AbstractDriverBasedDataSource in project today-infrastructure by TAKETODAY.

the class JdbcNamespaceIntegrationTests method assertCorrectSetupForSingleDataSource.

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

Example 3 with AbstractDriverBasedDataSource

use of cn.taketoday.jdbc.datasource.AbstractDriverBasedDataSource in project today-framework by TAKETODAY.

the class JdbcNamespaceIntegrationTests method assertCorrectSetupAndCloseContext.

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

Example 4 with AbstractDriverBasedDataSource

use of cn.taketoday.jdbc.datasource.AbstractDriverBasedDataSource in project today-framework by TAKETODAY.

the class JdbcNamespaceIntegrationTests method assertCorrectSetupForSingleDataSource.

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

Aggregations

ConfigurableApplicationContext (cn.taketoday.context.ConfigurableApplicationContext)4 JdbcTemplate (cn.taketoday.jdbc.core.JdbcTemplate)4 AbstractDriverBasedDataSource (cn.taketoday.jdbc.datasource.AbstractDriverBasedDataSource)4 DataSource (javax.sql.DataSource)4