1 21 22 package org.dbunit.database; 23 24 import com.mockobjects.ExpectationCounter; 25 import com.mockobjects.Verifiable; 26 import org.dbunit.database.statement.IStatementFactory; 27 import org.dbunit.dataset.*; 28 29 import java.sql.Connection ; 30 import java.sql.SQLException ; 31 32 37 public class MockDatabaseConnection implements IDatabaseConnection, Verifiable 38 { 39 private ExpectationCounter _closeCalls = 40 new ExpectationCounter("MockDatabaseConnection.close");; 41 42 private Connection _connection; 43 private String _schema; 44 private IDataSet _dataSet; 45 private DatabaseConfig _databaseConfig = new DatabaseConfig(); 47 48 public void setupSchema(String schema) 49 { 50 _schema = schema; 51 } 52 53 public void setupConnection(Connection connection) 54 { 55 _connection = connection; 56 } 57 58 public void setupDataSet(IDataSet dataSet) 59 { 60 _dataSet = dataSet; 61 } 62 63 public void setupDataSet(ITable table) 64 { 65 _dataSet = new DefaultDataSet(table); 66 } 67 68 public void setupDataSet(ITable[] tables) 69 { 70 _dataSet = new DefaultDataSet(tables); 71 } 72 73 public void setupStatementFactory(IStatementFactory statementFactory) 74 { 75 _databaseConfig.setProperty(DatabaseConfig.PROPERTY_STATEMENT_FACTORY, statementFactory); 76 } 77 78 public void setExpectedCloseCalls(int callsCount) 84 { 85 _closeCalls.setExpected(callsCount); 86 } 87 88 91 public void verify() 92 { 93 _closeCalls.verify(); 94 } 95 96 99 public Connection getConnection() throws SQLException 100 { 101 return _connection; 102 } 103 104 public String getSchema() 105 { 106 return _schema; 107 } 108 109 public void close() throws SQLException 110 { 111 _closeCalls.inc(); 112 } 113 114 public IDataSet createDataSet() throws SQLException 115 { 116 return _dataSet; 117 } 118 119 public IDataSet createDataSet(String [] tableNames) throws SQLException 120 { 121 return new FilteredDataSet(tableNames, createDataSet()); 122 } 123 124 public ITable createQueryTable(String resultName, String sql) 125 throws DataSetException, SQLException 126 { 127 throw new UnsupportedOperationException (); 128 } 129 130 public int getRowCount(String tableName) throws SQLException 131 { 132 throw new UnsupportedOperationException (); 133 } 134 135 public int getRowCount(String tableName, String whereClause) throws SQLException 136 { 137 throw new UnsupportedOperationException (); 138 } 139 140 public IStatementFactory getStatementFactory() 141 { 142 return (IStatementFactory)_databaseConfig.getProperty( 143 DatabaseConfig.PROPERTY_STATEMENT_FACTORY); 144 } 145 146 public DatabaseConfig getConfig() 147 { 148 return _databaseConfig; 149 } 150 } 151 152 153 154 155 156 | Popular Tags |