Add test to assess claim in SPR-10330
This commit verifies that JdbcTestUtils.readScript() properly handles SQL comments prefixed by tab characters. Issue: SPR-10330
This commit is contained in:
parent
bc9e4ab106
commit
b3a693e356
|
@ -48,6 +48,7 @@ public class JdbcTestUtilsTests {
|
|||
@Mock
|
||||
private JdbcTemplate jdbcTemplate;
|
||||
|
||||
|
||||
@Test
|
||||
public void containsDelimiters() {
|
||||
assertTrue("test with ';' is wrong", !JdbcTestUtils.containsSqlScriptDelimiters("select 1\n select ';'", ';'));
|
||||
|
@ -117,6 +118,33 @@ public class JdbcTestUtilsTests {
|
|||
assertEquals("statement 4 not split correctly", statement4, statements.get(3));
|
||||
}
|
||||
|
||||
/**
|
||||
* See <a href="https://jira.springsource.org/browse/SPR-10330">SPR-10330</a>
|
||||
* @since 4.0
|
||||
*/
|
||||
@Test
|
||||
public void readAndSplitScriptContainingCommentsWithLeadingTabs() throws Exception {
|
||||
|
||||
EncodedResource resource = new EncodedResource(new ClassPathResource(
|
||||
"test-data-with-comments-and-leading-tabs.sql", getClass()));
|
||||
LineNumberReader lineNumberReader = new LineNumberReader(resource.getReader());
|
||||
|
||||
String script = JdbcTestUtils.readScript(lineNumberReader);
|
||||
|
||||
char delim = ';';
|
||||
List<String> statements = new ArrayList<String>();
|
||||
JdbcTestUtils.splitSqlScript(script, delim, statements);
|
||||
|
||||
String statement1 = "insert into customer (id, name) values (1, 'Sam Brannen')";
|
||||
String statement2 = "insert into orders(id, order_date, customer_id) values (1, '2013-06-08', 1)";
|
||||
String statement3 = "insert into orders(id, order_date, customer_id) values (2, '2013-06-08', 1)";
|
||||
|
||||
assertEquals("wrong number of statements", 3, statements.size());
|
||||
assertEquals("statement 1 not split correctly", statement1, statements.get(0));
|
||||
assertEquals("statement 2 not split correctly", statement2, statements.get(1));
|
||||
assertEquals("statement 3 not split correctly", statement3, statements.get(2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void deleteWithoutWhereClause() throws Exception {
|
||||
given(jdbcTemplate.update("DELETE FROM person")).willReturn(10);
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
-- The next comment line starts with a tab.
|
||||
-- x, y, z...
|
||||
|
||||
insert into customer (id, name)
|
||||
values (1, 'Sam Brannen');
|
||||
-- This is also a comment with a leading tab.
|
||||
insert into orders(id, order_date, customer_id) values (1, '2013-06-08', 1);
|
||||
-- This is also a comment with a leading tab, a space, and a tab.
|
||||
insert into orders(id, order_date, customer_id) values (2, '2013-06-08', 1);
|
Loading…
Reference in New Issue