| 1 |
|
package liquibase; |
| 2 |
|
|
| 3 |
|
import liquibase.database.Database; |
| 4 |
|
import liquibase.database.DatabaseConnection; |
| 5 |
|
import liquibase.database.DatabaseFactory; |
| 6 |
|
import liquibase.database.core.MSSQLDatabase; |
| 7 |
|
import liquibase.database.core.OracleDatabase; |
| 8 |
|
import liquibase.database.core.PostgresDatabase; |
| 9 |
|
import liquibase.exception.DatabaseException; |
| 10 |
|
import liquibase.exception.LiquibaseException; |
| 11 |
|
import liquibase.resource.ClassLoaderResourceAccessor; |
| 12 |
|
import liquibase.resource.ResourceAccessor; |
| 13 |
|
import static org.easymock.EasyMock.expect; |
| 14 |
|
import static org.easymock.EasyMock.expectLastCall; |
| 15 |
|
import static org.easymock.classextension.EasyMock.*; |
| 16 |
|
import static org.junit.Assert.*; |
| 17 |
|
import org.junit.Before; |
| 18 |
|
import org.junit.Test; |
| 19 |
|
|
| 20 |
|
import java.io.InputStream; |
| 21 |
|
import java.net.URL; |
| 22 |
|
import java.sql.DatabaseMetaData; |
| 23 |
|
import java.util.Enumeration; |
| 24 |
|
import java.util.List; |
| 25 |
|
|
| 26 |
|
|
| 27 |
|
@link |
| 28 |
|
|
|
|
|
| 94.3% |
Uncovered Elements: 2 (35) |
Complexity: 6 |
Complexity Density: 0.24 |
|
| 29 |
|
public class LiquibaseTest { |
| 30 |
|
|
| 31 |
|
private TestLiquibase testLiquibase; |
| 32 |
|
private DatabaseConnection connectionForConstructor; |
| 33 |
|
|
|
|
|
| 83.3% |
Uncovered Elements: 2 (12) |
Complexity: 2 |
Complexity Density: 0.2 |
|
| 34 |
1
|
@Before... |
| 35 |
|
public void setUp() throws Exception { |
| 36 |
1
|
if (connectionForConstructor != null) { |
| 37 |
0
|
reset(connectionForConstructor); |
| 38 |
|
} |
| 39 |
1
|
connectionForConstructor = createMock(DatabaseConnection.class); |
| 40 |
1
|
connectionForConstructor.setAutoCommit(false); |
| 41 |
1
|
expectLastCall().atLeastOnce(); |
| 42 |
|
|
| 43 |
1
|
DatabaseMetaData metaData = createMock(DatabaseMetaData.class); |
| 44 |
1
|
expect(metaData.getDatabaseProductName()).andReturn("Oracle"); |
| 45 |
1
|
replay(metaData); |
| 46 |
|
|
| 47 |
|
|
| 48 |
1
|
replay(connectionForConstructor); |
| 49 |
|
|
| 50 |
1
|
testLiquibase = new TestLiquibase(); |
| 51 |
|
} |
| 52 |
|
|
| 53 |
|
|
| 54 |
|
|
| 55 |
|
|
| 56 |
|
|
| 57 |
|
|
| 58 |
|
|
| 59 |
|
|
| 60 |
|
|
| 61 |
|
|
| 62 |
|
|
| 63 |
|
|
| 64 |
|
|
| 65 |
|
|
| 66 |
|
|
| 67 |
|
|
| 68 |
|
|
| 69 |
|
|
| 70 |
|
|
| 71 |
|
|
| 72 |
|
|
| 73 |
|
|
| 74 |
|
|
| 75 |
|
|
| 76 |
|
|
| 77 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (21) |
Complexity: 4 |
Complexity Density: 0.27 |
1
PASS
|
|
| 78 |
1
|
@Test... |
| 79 |
|
public void getImplementedDatabases() throws Exception { |
| 80 |
1
|
List<Database> databases = DatabaseFactory.getInstance().getImplementedDatabases(); |
| 81 |
1
|
assertTrue(databases.size() > 15); |
| 82 |
|
|
| 83 |
1
|
boolean foundOracle = false; |
| 84 |
1
|
boolean foundPostgres = false; |
| 85 |
1
|
boolean foundMSSQL = false; |
| 86 |
|
|
| 87 |
1
|
for (Database db : databases) { |
| 88 |
17
|
if (db instanceof OracleDatabase) { |
| 89 |
1
|
foundOracle = true; |
| 90 |
16
|
} else if (db instanceof PostgresDatabase) { |
| 91 |
1
|
foundPostgres = true; |
| 92 |
15
|
} else if (db instanceof MSSQLDatabase) { |
| 93 |
1
|
foundMSSQL = true; |
| 94 |
|
} |
| 95 |
|
} |
| 96 |
|
|
| 97 |
1
|
assertTrue("Oracle not in Implemented Databases", foundOracle); |
| 98 |
1
|
assertTrue("MSSQL not in Implemented Databases", foundMSSQL); |
| 99 |
1
|
assertTrue("Postgres not in Implemented Databases", foundPostgres); |
| 100 |
|
} |
| 101 |
|
|
|
|
|
| 12.5% |
Uncovered Elements: 28 (32) |
Complexity: 11 |
Complexity Density: 0.52 |
|
| 102 |
|
private class TestLiquibase extends Liquibase { |
| 103 |
|
private String url; |
| 104 |
|
|
| 105 |
|
|
| 106 |
|
private InputStream inputStream; |
| 107 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
| 108 |
1
|
public TestLiquibase() throws LiquibaseException {... |
| 109 |
1
|
super("liquibase/test.xml", new ClassLoaderResourceAccessor(), ((Database) null)); |
| 110 |
1
|
inputStream = createMock(InputStream.class); |
| 111 |
1
|
replay(inputStream); |
| 112 |
|
} |
| 113 |
|
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
| 114 |
0
|
@Override... |
| 115 |
|
public Database getDatabase() { |
| 116 |
0
|
if (database == null) { |
| 117 |
0
|
database = new OracleDatabase() { |
| 118 |
|
|
| 119 |
|
}; |
| 120 |
|
} |
| 121 |
0
|
return database; |
| 122 |
|
} |
| 123 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 124 |
0
|
public void setDatabase(Database database) {... |
| 125 |
0
|
this.database = database; |
| 126 |
|
} |
| 127 |
|
|
| 128 |
|
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 2 |
Complexity Density: 0.22 |
|
| 129 |
0
|
@SuppressWarnings("unused")... |
| 130 |
|
public Database[] getImplementedDatabases() { |
| 131 |
0
|
Database mockDatabase = createMock(Database.class); |
| 132 |
0
|
try { |
| 133 |
|
|
| 134 |
0
|
expect(mockDatabase.isCorrectDatabaseImplementation(null)).andReturn(true).atLeastOnce(); |
| 135 |
0
|
mockDatabase.setConnection((DatabaseConnection) null); |
| 136 |
0
|
expectLastCall(); |
| 137 |
0
|
expect(mockDatabase.getConnection()).andReturn(connectionForConstructor); |
| 138 |
0
|
replay(mockDatabase); |
| 139 |
|
|
| 140 |
0
|
return new Database[]{ |
| 141 |
|
mockDatabase, |
| 142 |
|
}; |
| 143 |
|
} catch (DatabaseException e) { |
| 144 |
0
|
throw new RuntimeException(e); |
| 145 |
|
} |
| 146 |
|
} |
| 147 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 148 |
0
|
public void setUrl(String url) {... |
| 149 |
0
|
this.url = url; |
| 150 |
|
} |
| 151 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 152 |
0
|
@Override... |
| 153 |
|
public ResourceAccessor getFileOpener() { |
| 154 |
0
|
return new ResourceAccessor() { |
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 155 |
0
|
public InputStream getResourceAsStream(String file) {... |
| 156 |
0
|
return inputStream; |
| 157 |
|
} |
| 158 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 159 |
0
|
public Enumeration<URL> getResources(String packageName) {... |
| 160 |
0
|
return null; |
| 161 |
|
} |
| 162 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 163 |
0
|
public ClassLoader toClassLoader() {... |
| 164 |
0
|
return null; |
| 165 |
|
} |
| 166 |
|
}; |
| 167 |
|
} |
| 168 |
|
} |
| 169 |
|
} |