@@ -57,10 +57,7 @@ public void splitSqlScriptDelimitedWithSemicolon() {
57
57
String script = rawStatement1 + delim + rawStatement2 + delim + rawStatement3 + delim ;
58
58
List <String > statements = new ArrayList <>();
59
59
splitSqlScript (script , delim , statements );
60
- assertThat (statements .size ()).as ("wrong number of statements" ).isEqualTo (3 );
61
- assertThat (statements .get (0 )).as ("statement 1 not split correctly" ).isEqualTo (cleanedStatement1 );
62
- assertThat (statements .get (1 )).as ("statement 2 not split correctly" ).isEqualTo (cleanedStatement2 );
63
- assertThat (statements .get (2 )).as ("statement 3 not split correctly" ).isEqualTo (cleanedStatement3 );
60
+ assertThat (statements ).containsExactly (cleanedStatement1 , cleanedStatement2 , cleanedStatement3 );
64
61
}
65
62
66
63
@ Test
@@ -72,10 +69,7 @@ public void splitSqlScriptDelimitedWithNewLine() {
72
69
String script = statement1 + delim + statement2 + delim + statement3 + delim ;
73
70
List <String > statements = new ArrayList <>();
74
71
splitSqlScript (script , delim , statements );
75
- assertThat (statements .size ()).as ("wrong number of statements" ).isEqualTo (3 );
76
- assertThat (statements .get (0 )).as ("statement 1 not split correctly" ).isEqualTo (statement1 );
77
- assertThat (statements .get (1 )).as ("statement 2 not split correctly" ).isEqualTo (statement2 );
78
- assertThat (statements .get (2 )).as ("statement 3 not split correctly" ).isEqualTo (statement3 );
72
+ assertThat (statements ).containsExactly (statement1 , statement2 , statement3 );
79
73
}
80
74
81
75
@ Test
@@ -86,8 +80,7 @@ public void splitSqlScriptDelimitedWithNewLineButDefaultDelimiterSpecified() {
86
80
String script = statement1 + delim + statement2 + delim ;
87
81
List <String > statements = new ArrayList <>();
88
82
splitSqlScript (script , DEFAULT_STATEMENT_SEPARATOR , statements );
89
- assertThat (statements .size ()).as ("wrong number of statements" ).isEqualTo (1 );
90
- assertThat (statements .get (0 )).as ("script should have been 'stripped' but not actually 'split'" ).isEqualTo (script .replace ('\n' , ' ' ));
83
+ assertThat (statements ).as ("stripped but not split statements" ).containsExactly (script .replace ('\n' , ' ' ));
91
84
}
92
85
93
86
@ Test // SPR-13218
@@ -98,23 +91,17 @@ public void splitScriptWithSingleQuotesNestedInsideDoubleQuotes() throws Excepti
98
91
String script = statement1 + delim + statement2 + delim ;
99
92
List <String > statements = new ArrayList <>();
100
93
splitSqlScript (script , ';' , statements );
101
- assertThat (statements .size ()).as ("wrong number of statements" ).isEqualTo (2 );
102
- assertThat (statements .get (0 )).as ("statement 1 not split correctly" ).isEqualTo (statement1 );
103
- assertThat (statements .get (1 )).as ("statement 2 not split correctly" ).isEqualTo (statement2 );
94
+ assertThat (statements ).containsExactly (statement1 , statement2 );
104
95
}
105
96
106
97
@ Test // SPR-11560
107
98
public void readAndSplitScriptWithMultipleNewlinesAsSeparator () throws Exception {
108
99
String script = readScript ("db-test-data-multi-newline.sql" );
109
100
List <String > statements = new ArrayList <>();
110
101
splitSqlScript (script , "\n \n " , statements );
111
-
112
102
String statement1 = "insert into T_TEST (NAME) values ('Keith')" ;
113
103
String statement2 = "insert into T_TEST (NAME) values ('Dave')" ;
114
-
115
- assertThat (statements .size ()).as ("wrong number of statements" ).isEqualTo (2 );
116
- assertThat (statements .get (0 )).as ("statement 1 not split correctly" ).isEqualTo (statement1 );
117
- assertThat (statements .get (1 )).as ("statement 2 not split correctly" ).isEqualTo (statement2 );
104
+ assertThat (statements ).containsExactly (statement1 , statement2 );
118
105
}
119
106
120
107
@ Test
@@ -139,75 +126,53 @@ private void splitScriptContainingComments(String script, String... commentPrefi
139
126
List <String > statements = new ArrayList <>();
140
127
splitSqlScript (null , script , ";" , commentPrefixes , DEFAULT_BLOCK_COMMENT_START_DELIMITER ,
141
128
DEFAULT_BLOCK_COMMENT_END_DELIMITER , statements );
142
-
143
129
String statement1 = "insert into customer (id, name) values (1, 'Rod; Johnson'), (2, 'Adrian Collier')" ;
144
130
String statement2 = "insert into orders(id, order_date, customer_id) values (1, '2008-01-02', 2)" ;
145
131
String statement3 = "insert into orders(id, order_date, customer_id) values (1, '2008-01-02', 2)" ;
146
132
// Statement 4 addresses the error described in SPR-9982.
147
133
String statement4 = "INSERT INTO persons( person_id , name) VALUES( 1 , 'Name' )" ;
148
-
149
- assertThat (statements .size ()).as ("wrong number of statements" ).isEqualTo (4 );
150
- assertThat (statements .get (0 )).as ("statement 1 not split correctly" ).isEqualTo (statement1 );
151
- assertThat (statements .get (1 )).as ("statement 2 not split correctly" ).isEqualTo (statement2 );
152
- assertThat (statements .get (2 )).as ("statement 3 not split correctly" ).isEqualTo (statement3 );
153
- assertThat (statements .get (3 )).as ("statement 4 not split correctly" ).isEqualTo (statement4 );
134
+ assertThat (statements ).containsExactly (statement1 , statement2 , statement3 , statement4 );
154
135
}
155
136
156
137
@ Test // SPR-10330
157
138
public void readAndSplitScriptContainingCommentsWithLeadingTabs () throws Exception {
158
139
String script = readScript ("test-data-with-comments-and-leading-tabs.sql" );
159
140
List <String > statements = new ArrayList <>();
160
141
splitSqlScript (script , ';' , statements );
161
-
162
142
String statement1 = "insert into customer (id, name) values (1, 'Sam Brannen')" ;
163
143
String statement2 = "insert into orders(id, order_date, customer_id) values (1, '2013-06-08', 1)" ;
164
144
String statement3 = "insert into orders(id, order_date, customer_id) values (2, '2013-06-08', 1)" ;
165
-
166
- assertThat (statements .size ()).as ("wrong number of statements" ).isEqualTo (3 );
167
- assertThat (statements .get (0 )).as ("statement 1 not split correctly" ).isEqualTo (statement1 );
168
- assertThat (statements .get (1 )).as ("statement 2 not split correctly" ).isEqualTo (statement2 );
169
- assertThat (statements .get (2 )).as ("statement 3 not split correctly" ).isEqualTo (statement3 );
145
+ assertThat (statements ).containsExactly (statement1 , statement2 , statement3 );
170
146
}
171
147
172
148
@ Test // SPR-9531
173
149
public void readAndSplitScriptContainingMultiLineComments () throws Exception {
174
150
String script = readScript ("test-data-with-multi-line-comments.sql" );
175
151
List <String > statements = new ArrayList <>();
176
152
splitSqlScript (script , ';' , statements );
177
-
178
153
String statement1 = "INSERT INTO users(first_name, last_name) VALUES('Juergen', 'Hoeller')" ;
179
154
String statement2 = "INSERT INTO users(first_name, last_name) VALUES( 'Sam' , 'Brannen' )" ;
180
-
181
- assertThat (statements .size ()).as ("wrong number of statements" ).isEqualTo (2 );
182
- assertThat (statements .get (0 )).as ("statement 1 not split correctly" ).isEqualTo (statement1 );
183
- assertThat (statements .get (1 )).as ("statement 2 not split correctly" ).isEqualTo (statement2 );
155
+ assertThat (statements ).containsExactly (statement1 , statement2 );
184
156
}
185
157
186
158
@ Test
187
159
public void readAndSplitScriptContainingMultiLineNestedComments () throws Exception {
188
160
String script = readScript ("test-data-with-multi-line-nested-comments.sql" );
189
161
List <String > statements = new ArrayList <>();
190
162
splitSqlScript (script , ';' , statements );
191
-
192
163
String statement1 = "INSERT INTO users(first_name, last_name) VALUES('Juergen', 'Hoeller')" ;
193
164
String statement2 = "INSERT INTO users(first_name, last_name) VALUES( 'Sam' , 'Brannen' )" ;
194
-
195
- assertThat (statements .size ()).as ("wrong number of statements" ).isEqualTo (2 );
196
- assertThat (statements .get (0 )).as ("statement 1 not split correctly" ).isEqualTo (statement1 );
197
- assertThat (statements .get (1 )).as ("statement 2 not split correctly" ).isEqualTo (statement2 );
165
+ assertThat (statements ).containsExactly (statement1 , statement2 );
198
166
}
199
167
200
168
@ Test
201
169
public void containsDelimiters () {
202
170
assertThat (containsSqlScriptDelimiters ("select 1\n select ';'" , ";" )).isFalse ();
203
171
assertThat (containsSqlScriptDelimiters ("select 1; select 2" , ";" )).isTrue ();
204
-
205
172
assertThat (containsSqlScriptDelimiters ("select 1; select '\\ n\n ';" , "\n " )).isFalse ();
206
173
assertThat (containsSqlScriptDelimiters ("select 1\n select 2" , "\n " )).isTrue ();
207
-
208
174
assertThat (containsSqlScriptDelimiters ("select 1\n select 2" , "\n \n " )).isFalse ();
209
175
assertThat (containsSqlScriptDelimiters ("select 1\n \n select 2" , "\n \n " )).isTrue ();
210
-
211
176
// MySQL style escapes '\\'
212
177
assertThat (containsSqlScriptDelimiters ("insert into users(first_name, last_name)\n values('a\\ \\ ', 'b;')" , ";" )).isFalse ();
213
178
assertThat (containsSqlScriptDelimiters ("insert into users(first_name, last_name)\n values('Charles', 'd\\ 'Artagnan'); select 1;" , ";" )).isTrue ();
0 commit comments