[SPR-7449] @Ignore'd failing test for regression in ResourceDatabasePopulator.
This commit is contained in:
parent
9008cf907a
commit
e3400f77c9
|
@ -16,12 +16,15 @@
|
|||
|
||||
package org.springframework.jdbc.datasource.init;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.sql.Connection;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.After;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.core.io.ClassRelativeResourceLoader;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabase;
|
||||
|
@ -29,32 +32,58 @@ import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
|
|||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
* @author Sam Brannen
|
||||
*/
|
||||
public class DatabasePopulatorTests {
|
||||
|
||||
private final EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder();
|
||||
private final EmbeddedDatabase db = builder.build();
|
||||
private final ResourceDatabasePopulator databasePopulator = new ResourceDatabasePopulator();
|
||||
private final ClassRelativeResourceLoader resourceLoader = new ClassRelativeResourceLoader(getClass());
|
||||
private final JdbcTemplate jdbcTemplate = new JdbcTemplate(db);
|
||||
|
||||
private void assertTestDatabaseCreated() {
|
||||
assertEquals("Keith", jdbcTemplate.queryForObject("select NAME from T_TEST", String.class));
|
||||
}
|
||||
|
||||
private void assertUsersDatabaseCreated(DataSource db) {
|
||||
assertEquals("Sam", jdbcTemplate.queryForObject("select first_name from users where last_name = 'Brannen'",
|
||||
String.class));
|
||||
}
|
||||
|
||||
@After
|
||||
public void shutDown() {
|
||||
db.shutdown();
|
||||
}
|
||||
|
||||
@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);
|
||||
Connection connection = db.getConnection();
|
||||
try {
|
||||
databasePopulator.populate(connection);
|
||||
}
|
||||
finally {
|
||||
} finally {
|
||||
connection.close();
|
||||
}
|
||||
assertDatabaseCreated(db);
|
||||
db.shutdown();
|
||||
|
||||
assertTestDatabaseCreated();
|
||||
}
|
||||
|
||||
private void assertDatabaseCreated(DataSource db) {
|
||||
JdbcTemplate template = new JdbcTemplate(db);
|
||||
assertEquals("Keith", template.queryForObject("select NAME from T_TEST", String.class));
|
||||
@Ignore("Disabled until SPR-7449 is resolved")
|
||||
@Test
|
||||
public void scriptWithEolBetweenTokens() throws Exception {
|
||||
databasePopulator.addScript(resourceLoader.getResource("users-schema.sql"));
|
||||
databasePopulator.addScript(resourceLoader.getResource("users-data.sql"));
|
||||
Connection connection = db.getConnection();
|
||||
try {
|
||||
databasePopulator.populate(connection);
|
||||
} finally {
|
||||
connection.close();
|
||||
}
|
||||
|
||||
assertUsersDatabaseCreated(db);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
INSERT INTO
|
||||
users(first_name, last_name)
|
||||
values('Sam', 'Brannen');
|
|
@ -0,0 +1,7 @@
|
|||
DROP TABLE users IF EXISTS;
|
||||
|
||||
CREATE TABLE users (
|
||||
id INTEGER NOT NULL IDENTITY PRIMARY KEY,
|
||||
first_name VARCHAR(50) NOT NULL,
|
||||
last_name VARCHAR(50) NOT NULL
|
||||
);
|
Loading…
Reference in New Issue