use of org.springframework.jdbc.core.JdbcTemplate in project spring-boot by spring-projects.
the class HibernateJpaAutoConfigurationTests method testDataScript.
// This can't succeed because the data SQL is executed immediately after the schema
// and Hibernate hasn't initialized yet at that point
@Test(expected = BeanCreationException.class)
public void testDataScript() throws Exception {
EnvironmentTestUtils.addEnvironment(this.context, "spring.datasource.data:classpath:/city.sql");
setupTestConfiguration();
this.context.refresh();
assertThat(new JdbcTemplate(this.context.getBean(DataSource.class)).queryForObject("SELECT COUNT(*) from CITY", Integer.class)).isEqualTo(1);
}
use of org.springframework.jdbc.core.JdbcTemplate in project spring-framework by spring-projects.
the class InitializeDatabaseIntegrationTests method testScriptNameWithPattern.
@Test
public void testScriptNameWithPattern() throws Exception {
context = new ClassPathXmlApplicationContext("org/springframework/jdbc/config/jdbc-initialize-pattern-config.xml");
DataSource dataSource = context.getBean("dataSource", DataSource.class);
assertCorrectSetup(dataSource);
JdbcTemplate t = new JdbcTemplate(dataSource);
assertEquals("Dave", t.queryForObject("select name from T_TEST", String.class));
}
use of org.springframework.jdbc.core.JdbcTemplate in project spring-framework by spring-projects.
the class InitializeDatabaseIntegrationTests method assertCorrectSetup.
private void assertCorrectSetup(DataSource dataSource) {
JdbcTemplate jt = new JdbcTemplate(dataSource);
assertEquals(1, jt.queryForObject("select count(*) from T_TEST", Integer.class).intValue());
}
use of org.springframework.jdbc.core.JdbcTemplate in project spring-framework by spring-projects.
the class JdbcNamespaceIntegrationTests method createAndDestroy.
@Test
public void createAndDestroy() throws Exception {
ClassPathXmlApplicationContext context = context("jdbc-destroy-config.xml");
try {
DataSource dataSource = context.getBean(DataSource.class);
JdbcTemplate template = new JdbcTemplate(dataSource);
assertNumRowsInTestTable(template, 1);
context.getBean(DataSourceInitializer.class).destroy();
// Table has been dropped
expected.expect(BadSqlGrammarException.class);
assertNumRowsInTestTable(template, 1);
} finally {
context.close();
}
}
use of org.springframework.jdbc.core.JdbcTemplate in project spring-framework by spring-projects.
the class JdbcNamespaceIntegrationTests method createAndDestroyNestedWithH2.
@Test
public void createAndDestroyNestedWithH2() throws Exception {
ClassPathXmlApplicationContext context = context("jdbc-destroy-nested-config-h2.xml");
try {
DataSource dataSource = context.getBean(DataSource.class);
JdbcTemplate template = new JdbcTemplate(dataSource);
assertNumRowsInTestTable(template, 1);
context.getBean(EmbeddedDatabaseFactoryBean.class).destroy();
// Table has been dropped
expected.expect(BadSqlGrammarException.class);
assertNumRowsInTestTable(template, 1);
} finally {
context.close();
}
}
Aggregations