Skip to content

Commit b3a693e

Browse files
committed
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
1 parent bc9e4ab commit b3a693e

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

spring-test/src/test/java/org/springframework/test/jdbc/JdbcTestUtilsTests.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public class JdbcTestUtilsTests {
4848
@Mock
4949
private JdbcTemplate jdbcTemplate;
5050

51+
5152
@Test
5253
public void containsDelimiters() {
5354
assertTrue("test with ';' is wrong", !JdbcTestUtils.containsSqlScriptDelimiters("select 1\n select ';'", ';'));
@@ -117,6 +118,33 @@ public void readAndSplitScriptContainingComments() throws Exception {
117118
assertEquals("statement 4 not split correctly", statement4, statements.get(3));
118119
}
119120

121+
/**
122+
* See <a href="https://jira.springsource.org/browse/SPR-10330">SPR-10330</a>
123+
* @since 4.0
124+
*/
125+
@Test
126+
public void readAndSplitScriptContainingCommentsWithLeadingTabs() throws Exception {
127+
128+
EncodedResource resource = new EncodedResource(new ClassPathResource(
129+
"test-data-with-comments-and-leading-tabs.sql", getClass()));
130+
LineNumberReader lineNumberReader = new LineNumberReader(resource.getReader());
131+
132+
String script = JdbcTestUtils.readScript(lineNumberReader);
133+
134+
char delim = ';';
135+
List<String> statements = new ArrayList<String>();
136+
JdbcTestUtils.splitSqlScript(script, delim, statements);
137+
138+
String statement1 = "insert into customer (id, name) values (1, 'Sam Brannen')";
139+
String statement2 = "insert into orders(id, order_date, customer_id) values (1, '2013-06-08', 1)";
140+
String statement3 = "insert into orders(id, order_date, customer_id) values (2, '2013-06-08', 1)";
141+
142+
assertEquals("wrong number of statements", 3, statements.size());
143+
assertEquals("statement 1 not split correctly", statement1, statements.get(0));
144+
assertEquals("statement 2 not split correctly", statement2, statements.get(1));
145+
assertEquals("statement 3 not split correctly", statement3, statements.get(2));
146+
}
147+
120148
@Test
121149
public void deleteWithoutWhereClause() throws Exception {
122150
given(jdbcTemplate.update("DELETE FROM person")).willReturn(10);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
-- The next comment line starts with a tab.
2+
-- x, y, z...
3+
4+
insert into customer (id, name)
5+
values (1, 'Sam Brannen');
6+
-- This is also a comment with a leading tab.
7+
insert into orders(id, order_date, customer_id) values (1, '2013-06-08', 1);
8+
-- This is also a comment with a leading tab, a space, and a tab.
9+
insert into orders(id, order_date, customer_id) values (2, '2013-06-08', 1);

0 commit comments

Comments
 (0)