1 |
|
package liquibase.test; |
2 |
|
|
3 |
|
import liquibase.database.Database; |
4 |
|
import liquibase.database.core.SQLiteDatabase; |
5 |
|
import liquibase.executor.ExecutorService; |
6 |
|
import liquibase.executor.jvm.JdbcExecutor; |
7 |
|
import liquibase.exception.MigrationFailedException; |
8 |
|
import liquibase.lockservice.LockService; |
9 |
|
import org.junit.ComparisonFailure; |
10 |
|
|
11 |
|
import java.util.Set; |
12 |
|
|
|
|
| 0% |
Uncovered Elements: 63 (63) |
Complexity: 16 |
Complexity Density: 0.36 |
|
13 |
|
public class DatabaseTestTemplate { |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
14 |
0
|
public void testOnAvailableDatabases(DatabaseTest test) throws Exception {... |
15 |
0
|
test(test, DatabaseTestContext.getInstance().getAvailableDatabases()); |
16 |
|
} |
17 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
18 |
0
|
public void testOnAllDatabases(DatabaseTest test) throws Exception {... |
19 |
0
|
test(test, TestContext.getInstance().getAllDatabases()); |
20 |
|
} |
21 |
|
|
|
|
| 0% |
Uncovered Elements: 58 (58) |
Complexity: 14 |
Complexity Density: 0.33 |
|
22 |
0
|
private void test(DatabaseTest test, Set<Database> databasesToTestOn) throws Exception {... |
23 |
0
|
for (Database database : databasesToTestOn) { |
24 |
0
|
if (database instanceof SQLiteDatabase) { |
25 |
0
|
continue; |
26 |
|
} |
27 |
0
|
JdbcExecutor writeExecutor = new JdbcExecutor(); |
28 |
0
|
writeExecutor.setDatabase(database); |
29 |
0
|
ExecutorService.getInstance().setExecutor(database, writeExecutor); |
30 |
0
|
LockService.getInstance(database).reset(); |
31 |
0
|
if (database.getConnection() != null) { |
32 |
0
|
LockService.getInstance(database).forceReleaseLock(); |
33 |
|
} |
34 |
|
|
35 |
0
|
try { |
36 |
0
|
test.performTest(database); |
37 |
|
} catch (ComparisonFailure e) { |
38 |
0
|
String newMessage = "Database Test Failure on " + database; |
39 |
0
|
if (e.getMessage() != null) { |
40 |
0
|
newMessage += ": " + e.getMessage(); |
41 |
|
} |
42 |
|
|
43 |
0
|
ComparisonFailure newError = new ComparisonFailure(newMessage, e.getExpected(), e.getActual()); |
44 |
0
|
newError.setStackTrace(e.getStackTrace()); |
45 |
0
|
throw newError; |
46 |
|
} catch (AssertionError e) { |
47 |
0
|
e.printStackTrace(); |
48 |
0
|
String newMessage = "Database Test Failure on " + database; |
49 |
0
|
if (e.getMessage() != null) { |
50 |
0
|
newMessage += ": " + e.getMessage(); |
51 |
|
} |
52 |
|
|
53 |
0
|
AssertionError newError = new AssertionError(newMessage); |
54 |
0
|
newError.setStackTrace(e.getStackTrace()); |
55 |
0
|
throw newError; |
56 |
|
} catch (MigrationFailedException e) { |
57 |
0
|
e.printStackTrace(); |
58 |
0
|
String newMessage = "Database Test Failure on " + database; |
59 |
0
|
if (e.getMessage() != null) { |
60 |
0
|
newMessage += ": " + e.getMessage(); |
61 |
|
} |
62 |
|
|
63 |
0
|
AssertionError newError = new AssertionError(newMessage); |
64 |
0
|
newError.setStackTrace(e.getStackTrace()); |
65 |
0
|
throw newError; |
66 |
|
} catch (Exception e) { |
67 |
0
|
e.printStackTrace(); |
68 |
0
|
String newMessage = "Database Test Exception on " + database; |
69 |
0
|
if (e.getMessage() != null) { |
70 |
0
|
newMessage += ": " + e.getMessage(); |
71 |
|
} |
72 |
|
|
73 |
0
|
Exception newError = e.getClass().getConstructor(String.class).newInstance(newMessage); |
74 |
0
|
if (e.getCause() == null) { |
75 |
0
|
newError.setStackTrace(e.getStackTrace()); |
76 |
|
} else { |
77 |
0
|
newError.setStackTrace(e.getCause().getStackTrace()); |
78 |
|
} |
79 |
0
|
throw newError; |
80 |
|
} finally { |
81 |
0
|
if (database.getConnection() != null && !database.getAutoCommitMode()) { |
82 |
0
|
database.rollback(); |
83 |
|
} |
84 |
|
} |
85 |
|
} |
86 |
|
} |
87 |
|
} |