h2 embedded db support; updated formatting conventions not to auto-format javadoc; added hsqldb and h2 to jdbc maven pom as optional deps
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
package org.springframework.jdbc.config;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
@@ -12,9 +12,14 @@ public class JdbcNamespaceIntegrationTest {
|
||||
|
||||
@Test
|
||||
public void testCreateEmbeddedDatabase() throws Exception {
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("org/springframework/jdbc/config/jdbc-config.xml");
|
||||
DataSource ds = context.getBean("dataSource", DataSource.class);
|
||||
JdbcTemplate t = new JdbcTemplate(ds);
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"org/springframework/jdbc/config/jdbc-config.xml");
|
||||
assertCorrectSetup(context.getBean("dataSource", DataSource.class));
|
||||
assertCorrectSetup(context.getBean("h2dataSource", DataSource.class));
|
||||
}
|
||||
|
||||
private void assertCorrectSetup(DataSource dataSource) {
|
||||
JdbcTemplate t = new JdbcTemplate(dataSource);
|
||||
assertEquals(1, t.queryForInt("select count(*) from T_TEST"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,28 +1,31 @@
|
||||
package org.springframework.jdbc.datasource.embedded;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
|
||||
public class EmbeddedDatabaseBuilderTests {
|
||||
|
||||
|
||||
@Test
|
||||
public void testBuildDefaults() {
|
||||
EmbeddedDatabase db = EmbeddedDatabaseBuilder.buildDefault();
|
||||
JdbcTemplate template = new JdbcTemplate(db);
|
||||
assertEquals("Keith", template.queryForObject("select NAME from T_TEST", String.class));
|
||||
db.shutdown();
|
||||
assertDatabaseCreatedAndShutdown(db);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testBuild() {
|
||||
EmbeddedDatabaseBuilder builder = EmbeddedDatabaseBuilder.relativeTo(getClass());
|
||||
EmbeddedDatabase db = builder.script("db-schema.sql").script("db-test-data.sql").build();
|
||||
JdbcTemplate template = new JdbcTemplate(db);
|
||||
assertEquals("Keith", template.queryForObject("select NAME from T_TEST", String.class));
|
||||
db.shutdown();
|
||||
assertDatabaseCreatedAndShutdown(db);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBuildH2() {
|
||||
EmbeddedDatabaseBuilder builder = EmbeddedDatabaseBuilder.relativeTo(getClass());
|
||||
EmbeddedDatabase db = builder.type(H2).script("db-schema.sql").script("db-test-data.sql").build();
|
||||
assertDatabaseCreatedAndShutdown(db);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -34,4 +37,11 @@ public class EmbeddedDatabaseBuilderTests {
|
||||
}
|
||||
}
|
||||
|
||||
private void assertDatabaseCreatedAndShutdown(EmbeddedDatabase db) {
|
||||
|
||||
JdbcTemplate template = new JdbcTemplate(db);
|
||||
assertEquals("Keith", template.queryForObject("select NAME from T_TEST", String.class));
|
||||
db.shutdown();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,4 +10,9 @@
|
||||
<jdbc:script location="classpath:org/springframework/jdbc/datasource/embedded/db-test-data.sql"/>
|
||||
</jdbc:embedded-database>
|
||||
|
||||
<jdbc:embedded-database id="h2dataSource" type="H2">
|
||||
<jdbc:script location="classpath:org/springframework/jdbc/datasource/embedded/db-schema.sql"/>
|
||||
<jdbc:script location="classpath:org/springframework/jdbc/datasource/embedded/db-test-data.sql"/>
|
||||
</jdbc:embedded-database>
|
||||
|
||||
</beans>
|
||||
Reference in New Issue
Block a user