9 changed files with 97 additions and 8 deletions
@ -0,0 +1,34 @@
@@ -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 @@
@@ -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 @@
@@ -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); |
||||
Loading…
Reference in new issue