Clover Coverage Report - Liquibase Integration Tests 2.0.3-SNAPSHOT
Coverage timestamp: Wed Dec 31 1969 19:00:00 EST
../../img/srcFileCovDistChart0.png 0% of files have more coverage
44   87   16   14.67
16   77   0.36   3
3     5.33  
1    
 
  DatabaseTestTemplate       Line # 13 44 0% 16 63 0% 0.0
 
No Tests
 
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   
 
13    public class DatabaseTestTemplate {
 
14  0 toggle public void testOnAvailableDatabases(DatabaseTest test) throws Exception {
15  0 test(test, DatabaseTestContext.getInstance().getAvailableDatabases());
16    }
17   
 
18  0 toggle public void testOnAllDatabases(DatabaseTest test) throws Exception {
19  0 test(test, TestContext.getInstance().getAllDatabases());
20    }
21   
 
22  0 toggle 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; //todo: find how to get tests to run correctly on SQLite
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    }