1 21 22 package org.dbunit; 23 24 import org.dbunit.database.IDatabaseConnection; 25 import org.dbunit.dataset.IDataSet; 26 import org.dbunit.dataset.ITable; 27 import org.dbunit.dataset.SortedTable; 28 import org.dbunit.operation.DatabaseOperation; 29 30 35 public abstract class AbstractDatabaseTest extends DatabaseTestCase 36 { 37 protected IDatabaseConnection _connection; 38 39 public AbstractDatabaseTest(String s) 40 { 41 super(s); 42 } 43 44 protected DatabaseEnvironment getEnvironment() throws Exception 45 { 46 return DatabaseEnvironment.getInstance(); 47 } 48 49 protected ITable createOrderedTable(String tableName, String orderByColumn) 50 throws Exception 51 { 52 return new SortedTable(_connection.createDataSet().getTable(tableName), 53 new String []{orderByColumn}); 54 } 57 58 61 protected void setUp() throws Exception 62 { 63 super.setUp(); 64 65 _connection = getEnvironment().getConnection(); 66 } 67 68 protected void tearDown() throws Exception 69 { 70 super.tearDown(); 71 72 DatabaseOperation.DELETE_ALL.execute(_connection, _connection.createDataSet()); 73 74 _connection = null; 75 } 76 77 80 protected IDatabaseConnection getConnection() throws Exception 81 { 82 IDatabaseConnection connection = getEnvironment().getConnection(); 83 return connection; 84 85 } 88 89 protected IDataSet getDataSet() throws Exception 90 { 91 return getEnvironment().getInitDataSet(); 92 } 93 94 protected void closeConnection(IDatabaseConnection connection) throws Exception 95 { 96 } 98 } 104 105 106 107 108 109 110 | Popular Tags |