Clover Coverage Report - Liquibase Core 2.0.3-SNAPSHOT
Coverage timestamp: Sat Aug 6 2011 11:33:15 EDT
46   169   17   4.18
10   113   0.37   5.5
11     1.55  
2    
 
  LiquibaseTest       Line # 29 25 0% 6 2 94.3% 0.94285715
  LiquibaseTest.TestLiquibase       Line # 102 21 0% 11 28 12.5% 0.125
 
  (1)
 
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    * Tests for {@link liquibase.Liquibase}
28    */
 
29    public class LiquibaseTest {
30   
31    private TestLiquibase testLiquibase;
32    private DatabaseConnection connectionForConstructor;
33   
 
34  1 toggle @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    // expect(connectionForConstructor.getMetaData()).andReturn(metaData);
48  1 replay(connectionForConstructor);
49   
50  1 testLiquibase = new TestLiquibase();
51    }
52   
53    //todo: reintroduce @Test
54    // public void isSaveToRunMigration() throws Exception {
55    // TestLiquibase liquibase = testLiquibase;
56    //
57    // // curiously setting the database of mock liquibase
58    // Database database = testLiquibase.getDatabase();
59    //
60    // liquibase.setUrl("jdbc:oracle:thin:@localhost:1521:latest");
61    // assertTrue(liquibase.isSafeToRunMigration());
62    //
63    // liquibase.setUrl("jdbc:oracle:thin:@liquibase:1521:latest");
64    // assertFalse(liquibase.isSafeToRunMigration());
65    //
66    // ExecutorService.getInstance().setWriteExecutor(database, new LoggingExecutor(new PrintWriter(System.out), database));
67    // assertTrue("Safe to run if outputing sql, even if non-localhost URL", liquibase.isSafeToRunMigration());
68    //
69    // }
70   
71    /*
72    @Test
73    public void testBlosDocumentation() throws Exception {
74    testLiquibase.generateDocumentation(".");
75    }
76    */
77   
 
78  1 toggle @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   
 
102    private class TestLiquibase extends Liquibase {
103    private String url;
104    // instead use super.database
105    //private Database database;
106    private InputStream inputStream;
107   
 
108  1 toggle 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   
 
114  0 toggle @Override
115    public Database getDatabase() {
116  0 if (database == null) {
117  0 database = new OracleDatabase() {
118   
119    };
120    }
121  0 return database;
122    }
123   
 
124  0 toggle public void setDatabase(Database database) {
125  0 this.database = database;
126    }
127   
128   
 
129  0 toggle @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   
 
148  0 toggle public void setUrl(String url) {
149  0 this.url = url;
150    }
151   
 
152  0 toggle @Override
153    public ResourceAccessor getFileOpener() {
154  0 return new ResourceAccessor() {
 
155  0 toggle public InputStream getResourceAsStream(String file) {
156  0 return inputStream;
157    }
158   
 
159  0 toggle public Enumeration<URL> getResources(String packageName) {
160  0 return null;
161    }
162   
 
163  0 toggle public ClassLoader toClassLoader() {
164  0 return null;
165    }
166    };
167    }
168    }
169    }