RESOLVED - issue SPR-6345: ResourceDatabasePopulator does not handle comments properly when ignoring failures
http://jira.springframework.org/browse/SPR-6345
This commit is contained in:
@@ -26,6 +26,20 @@ public class EmbeddedDatabaseBuilderTests {
|
||||
assertDatabaseCreatedAndShutdown(db);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBuildWithComments() {
|
||||
EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder(new ClassRelativeResourceLoader(getClass()));
|
||||
EmbeddedDatabase db = builder.addScript("db-schema-comments.sql").addScript("db-test-data.sql").build();
|
||||
assertDatabaseCreatedAndShutdown(db);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBuildWithCommentsAndFailedDrop() {
|
||||
EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder(new ClassRelativeResourceLoader(getClass()));
|
||||
EmbeddedDatabase db = builder.ignoreFailedDrops(true).addScript("db-schema-failed-drop-comments.sql").addScript("db-test-data.sql").build();
|
||||
assertDatabaseCreatedAndShutdown(db);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBuildH2() {
|
||||
EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder(new ClassRelativeResourceLoader(getClass()));
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
package org.springframework.jdbc.datasource.init;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.core.io.ClassRelativeResourceLoader;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabase;
|
||||
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
|
||||
|
||||
public class DatabasePopulatorTests {
|
||||
|
||||
@Test
|
||||
public void testBuildWithCommentsAndFailedDrop() throws Exception {
|
||||
EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder();
|
||||
EmbeddedDatabase db = builder.build();
|
||||
ResourceDatabasePopulator databasePopulator = new ResourceDatabasePopulator();
|
||||
ClassRelativeResourceLoader resourceLoader = new ClassRelativeResourceLoader(getClass());
|
||||
databasePopulator.addScript(resourceLoader.getResource("db-schema-failed-drop-comments.sql"));
|
||||
databasePopulator.addScript(resourceLoader.getResource("db-test-data.sql"));
|
||||
databasePopulator.setIgnoreFailedDrops(true);
|
||||
databasePopulator.populate(db.getConnection());
|
||||
assertDatabaseCreated(db);
|
||||
db.shutdown();
|
||||
}
|
||||
|
||||
private void assertDatabaseCreated(DataSource db) {
|
||||
JdbcTemplate template = new JdbcTemplate(db);
|
||||
assertEquals("Keith", template.queryForObject("select NAME from T_TEST", String.class));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
-- Failed DROP can be ignored if necessary
|
||||
drop table T_TEST if exists;
|
||||
|
||||
-- Create the test table
|
||||
create table T_TEST (NAME varchar(50) not null);
|
||||
@@ -0,0 +1,5 @@
|
||||
-- Failed DROP can be ignored if necessary
|
||||
drop table T_TEST;
|
||||
|
||||
-- Create the test table
|
||||
create table T_TEST (NAME varchar(50) not null);
|
||||
@@ -0,0 +1,5 @@
|
||||
-- Failed DROP can be ignored if necessary
|
||||
drop table T_TEST;
|
||||
|
||||
-- Create the test table
|
||||
create table T_TEST (NAME varchar(50) not null);
|
||||
@@ -0,0 +1 @@
|
||||
insert into T_TEST (NAME) values ('Keith');
|
||||
Reference in New Issue
Block a user