1
1
/**
2
- * Copyright 2010-2017 the original author or authors.
2
+ * Copyright 2010-2018 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -80,6 +80,8 @@ public void checkAssertion() {
80
80
81
81
testVersionCommand ();
82
82
testStatusContainsNoPendingMigrations ();
83
+ testSkippedScript ();
84
+ testMissingScript ();
83
85
testDownCommand ();
84
86
testStatusContainsPendingMigrations ();
85
87
testPendingCommand ();
@@ -153,11 +155,43 @@ private void testDoPendingScriptCommand() throws Exception {
153
155
154
156
private void testVersionCommand () throws Exception {
155
157
out .clearLog ();
156
- Migrator .main (TestUtil .args ("--path=" + dir .getAbsolutePath (), "version" , "20080827200216 " ));
158
+ Migrator .main (TestUtil .args ("--path=" + dir .getAbsolutePath (), "version" , "20080827200217 " ));
157
159
String output = out .getLog ();
158
160
assertFalse (output .toString ().contains ("FAILURE" ));
159
161
}
160
162
163
+ private void testSkippedScript () throws Exception {
164
+ out .clearLog ();
165
+ File skipped = new File (dir + File .separator + "scripts" , "20080827200215_skipped_migration.sql" );
166
+ assertTrue (skipped .createNewFile ());
167
+ try {
168
+ Migrator .main (TestUtil .args ("--path=" + dir .getAbsolutePath (), "up" ));
169
+ String output = out .getLog ();
170
+ assertFalse (output .toString ().contains ("FAILURE" ));
171
+ assertEquals (1 , TestUtil .countStr (output , "WARNING" ));
172
+ assertTrue (output .toString ().contains (
173
+ "WARNING: Migration script '20080827200215_skipped_migration.sql' was not applied to the database." ));
174
+ } finally {
175
+ skipped .delete ();
176
+ }
177
+ }
178
+
179
+ private void testMissingScript () throws Exception {
180
+ out .clearLog ();
181
+ File original = new File (dir + File .separator + "scripts" , "20080827200216_create_procs.sql" );
182
+ File renamed = new File (dir + File .separator + "scripts" , "20080827200216_create_procs._sql" );
183
+ assertTrue (original .renameTo (renamed ));
184
+ try {
185
+ Migrator .main (TestUtil .args ("--path=" + dir .getAbsolutePath (), "up" ));
186
+ String output = out .getLog ();
187
+ assertFalse (output .toString ().contains ("FAILURE" ));
188
+ assertTrue (output .toString ()
189
+ .contains ("WARNING: Missing migration script. id='20080827200216', description='create procs'." ));
190
+ } finally {
191
+ assertTrue (renamed .renameTo (original ));
192
+ }
193
+ }
194
+
161
195
private void testDownCommand () throws Exception {
162
196
out .clearLog ();
163
197
Migrator .main (TestUtil .args ("--path=" + dir .getAbsolutePath (), "down" ));
@@ -206,7 +240,7 @@ private void testDoScriptCommand() throws Exception {
206
240
assertFalse (output .toString ().contains ("20080827200212" ));
207
241
assertTrue (output .toString ().contains ("20080827200213" ));
208
242
assertTrue (output .toString ().contains ("20080827200214" ));
209
- assertFalse (output .toString ().contains ("20080827200215 " ));
243
+ assertFalse (output .toString ().contains ("20080827200216 " ));
210
244
assertFalse (output .toString ().contains ("-- @UNDO" ));
211
245
212
246
out .clearLog ();
@@ -218,21 +252,21 @@ private void testDoScriptCommand() throws Exception {
218
252
assertFalse (output .toString ().contains ("20080827200212" ));
219
253
assertFalse (output .toString ().contains ("20080827200213" ));
220
254
assertFalse (output .toString ().contains ("20080827200214" ));
221
- assertFalse (output .toString ().contains ("20080827200215 " ));
255
+ assertFalse (output .toString ().contains ("20080827200216 " ));
222
256
assertFalse (output .toString ().contains ("-- @UNDO" ));
223
257
}
224
258
225
259
private void testUndoScriptCommand () throws Exception {
226
260
out .clearLog ();
227
- Migrator .main (TestUtil .args ("--path=" + dir .getAbsolutePath (), "script" , "20080827200215 " , "20080827200213" ));
261
+ Migrator .main (TestUtil .args ("--path=" + dir .getAbsolutePath (), "script" , "20080827200216 " , "20080827200213" ));
228
262
String output = out .getLog ();
229
263
assertFalse (output .toString ().contains ("FAILURE" ));
230
264
assertFalse (output .toString ().contains ("20080827200210" ));
231
265
assertFalse (output .toString ().contains ("20080827200211" ));
232
266
assertFalse (output .toString ().contains ("20080827200212" ));
233
267
assertFalse (output .toString ().contains ("20080827200213" ));
234
268
assertTrue (output .toString ().contains ("20080827200214" ));
235
- assertTrue (output .toString ().contains ("20080827200215 " ));
269
+ assertTrue (output .toString ().contains ("20080827200216 " ));
236
270
assertTrue (output .toString ().contains ("-- @UNDO" ));
237
271
out .clearLog ();
238
272
@@ -244,7 +278,7 @@ private void testUndoScriptCommand() throws Exception {
244
278
assertFalse (output .toString ().contains ("20080827200212" ));
245
279
assertFalse (output .toString ().contains ("20080827200213" ));
246
280
assertFalse (output .toString ().contains ("20080827200214" ));
247
- assertFalse (output .toString ().contains ("20080827200215 " ));
281
+ assertFalse (output .toString ().contains ("20080827200216 " ));
248
282
assertTrue (output .toString ().contains ("-- @UNDO" ));
249
283
}
250
284
0 commit comments