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:
Keith Donald
2009-05-09 22:27:05 +00:00
parent 93cf346fb1
commit 96629c7dc5
18 changed files with 270 additions and 144 deletions

View File

@@ -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"));
}
}

View File

@@ -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();
}
}

View File

@@ -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>