Skip to content

Commit

Permalink
Add test to assess claim in SPR-10330
Browse files Browse the repository at this point in the history
This commit verifies that JdbcTestUtils.readScript() properly handles
SQL comments prefixed by tab characters.

Issue: SPR-10330
  • Loading branch information
sbrannen committed Jun 8, 2013
1 parent bc9e4ab commit b3a693e
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 ';'", ';'));
Expand Down Expand Up @@ -117,6 +118,33 @@ public void readAndSplitScriptContainingComments() throws Exception {
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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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);

0 comments on commit b3a693e

Please sign in to comment.