mirror of
https://github.com/spring-projects/spring-framework.git
synced 2026-10-05 22:49:02 +00:00
SPR-6688: Add tests and explicit detection of \ in sql script extractor
This commit is contained in:
+33
-2
@@ -23,7 +23,6 @@ import java.sql.Connection;
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.springframework.core.io.ClassRelativeResourceLoader;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
@@ -43,7 +42,11 @@ public class DatabasePopulatorTests {
|
||||
private final JdbcTemplate jdbcTemplate = new JdbcTemplate(db);
|
||||
|
||||
private void assertTestDatabaseCreated() {
|
||||
assertEquals("Keith", jdbcTemplate.queryForObject("select NAME from T_TEST", String.class));
|
||||
assertTestDatabaseCreated("Keith");
|
||||
}
|
||||
|
||||
private void assertTestDatabaseCreated(String name) {
|
||||
assertEquals(name, jdbcTemplate.queryForObject("select NAME from T_TEST", String.class));
|
||||
}
|
||||
|
||||
private void assertUsersDatabaseCreated(DataSource db) {
|
||||
@@ -71,6 +74,34 @@ public class DatabasePopulatorTests {
|
||||
assertTestDatabaseCreated();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBuildWithNormalEscapedLiteral() throws Exception {
|
||||
databasePopulator.addScript(resourceLoader.getResource("db-schema.sql"));
|
||||
databasePopulator.addScript(resourceLoader.getResource("db-test-data-escaped-literal.sql"));
|
||||
Connection connection = db.getConnection();
|
||||
try {
|
||||
databasePopulator.populate(connection);
|
||||
} finally {
|
||||
connection.close();
|
||||
}
|
||||
|
||||
assertTestDatabaseCreated("'Keith'");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBuildWithMySQLEscapedLiteral() throws Exception {
|
||||
databasePopulator.addScript(resourceLoader.getResource("db-schema.sql"));
|
||||
databasePopulator.addScript(resourceLoader.getResource("db-test-data-mysql-escaped-literal.sql"));
|
||||
Connection connection = db.getConnection();
|
||||
try {
|
||||
databasePopulator.populate(connection);
|
||||
} finally {
|
||||
connection.close();
|
||||
}
|
||||
|
||||
assertTestDatabaseCreated("\\$Keith\\$");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void scriptWithEolBetweenTokens() throws Exception {
|
||||
databasePopulator.addScript(resourceLoader.getResource("users-schema.sql"));
|
||||
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
drop table T_TEST if exists;
|
||||
|
||||
create table T_TEST (NAME varchar(50) not null);
|
||||
+1
@@ -0,0 +1 @@
|
||||
insert into T_TEST (NAME) values ('''Keith''');
|
||||
+1
@@ -0,0 +1 @@
|
||||
insert into T_TEST (NAME) values ('\$Keith\$');
|
||||
Reference in New Issue
Block a user