use of cn.taketoday.jdbc.core.JdbcTemplate in project today-framework by TAKETODAY.
the class InitializeDatabaseIntegrationTests method testScriptNameWithPattern.
@Test
public void testScriptNameWithPattern() throws Exception {
context = new ClassPathXmlApplicationContext("cn/taketoday/jdbc/config/jdbc-initialize-pattern-config.xml");
DataSource dataSource = context.getBean("dataSource", DataSource.class);
assertCorrectSetup(dataSource);
JdbcTemplate t = new JdbcTemplate(dataSource);
assertThat(t.queryForObject("select name from T_TEST", String.class)).isEqualTo("Dave");
}
use of cn.taketoday.jdbc.core.JdbcTemplate in project today-framework by TAKETODAY.
the class JdbcNamespaceIntegrationTests method createAndDestroyNestedWithH2.
@Test
void createAndDestroyNestedWithH2() throws Exception {
try (ClassPathXmlApplicationContext context = context("jdbc-destroy-nested-config-h2.xml")) {
DataSource dataSource = context.getBean(DataSource.class);
JdbcTemplate template = new JdbcTemplate(dataSource);
assertNumRowsInTestTable(template, 1);
context.getBean(EmbeddedDatabaseFactoryBean.class).destroy();
// Table has been dropped
assertThatExceptionOfType(BadSqlGrammarException.class).isThrownBy(() -> assertNumRowsInTestTable(template, 1));
}
}
use of cn.taketoday.jdbc.core.JdbcTemplate in project today-framework by TAKETODAY.
the class JdbcNamespaceIntegrationTests method createAndDestroyNestedWithHsql.
@Test
void createAndDestroyNestedWithHsql() throws Exception {
try (ClassPathXmlApplicationContext context = context("jdbc-destroy-nested-config.xml")) {
DataSource dataSource = context.getBean(DataSource.class);
JdbcTemplate template = new JdbcTemplate(dataSource);
assertNumRowsInTestTable(template, 1);
context.getBean(EmbeddedDatabaseFactoryBean.class).destroy();
// Table has been dropped
assertThatExceptionOfType(BadSqlGrammarException.class).isThrownBy(() -> assertNumRowsInTestTable(template, 1));
}
}
use of cn.taketoday.jdbc.core.JdbcTemplate in project today-framework by TAKETODAY.
the class JdbcDaoSupportTests method testJdbcDaoSupportWithJdbcTemplate.
@Test
public void testJdbcDaoSupportWithJdbcTemplate() throws Exception {
JdbcTemplate template = new JdbcTemplate();
final List<String> test = new ArrayList<>();
JdbcDataAccessObjectSupport dao = new JdbcDataAccessObjectSupport() {
@Override
protected void initDao() {
test.add("test");
}
};
dao.setJdbcTemplate(template);
dao.afterPropertiesSet();
assertThat(template).as("Correct JdbcTemplate").isEqualTo(dao.getJdbcTemplate());
assertThat(test.size()).as("initDao called").isEqualTo(1);
}
use of cn.taketoday.jdbc.core.JdbcTemplate in project today-framework by TAKETODAY.
the class EmbeddedDatabaseFactoryBeanTests method testFactoryBeanLifecycle.
@Test
public void testFactoryBeanLifecycle() throws Exception {
EmbeddedDatabaseFactoryBean bean = new EmbeddedDatabaseFactoryBean();
ResourceDatabasePopulator populator = new ResourceDatabasePopulator(resource("db-schema.sql"), resource("db-test-data.sql"));
bean.setDatabasePopulator(populator);
bean.afterPropertiesSet();
DataSource ds = bean.getObject();
JdbcTemplate template = new JdbcTemplate(ds);
assertThat(template.queryForObject("select NAME from T_TEST", String.class)).isEqualTo("Keith");
bean.destroy();
}
Aggregations