KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > dbunit > AbstractDatabaseTest


1 /*
2  *
3  * The DbUnit Database Testing Framework
4  * Copyright (C)2002-2004, DbUnit.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  *
20  */

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 /**
31  * @author Manuel Laflamme
32  * @version $Revision: 1.16 $
33  * @since Feb 18, 2002
34  */

35 public abstract class AbstractDatabaseTest extends DatabaseTestCase
36 {
37     protected IDatabaseConnection _connection;
38
39     public AbstractDatabaseTest(String JavaDoc s)
40     {
41         super(s);
42     }
43
44     protected DatabaseEnvironment getEnvironment() throws Exception JavaDoc
45     {
46         return DatabaseEnvironment.getInstance();
47     }
48
49     protected ITable createOrderedTable(String JavaDoc tableName, String JavaDoc orderByColumn)
50             throws Exception JavaDoc
51     {
52         return new SortedTable(_connection.createDataSet().getTable(tableName),
53                 new String JavaDoc[]{orderByColumn});
54 // String sql = "select * from " + tableName + " order by " + orderByColumn;
55
// return _connection.createQueryTable(tableName, sql);
56
}
57
58     ////////////////////////////////////////////////////////////////////////////
59
// TestCase class
60

61     protected void setUp() throws Exception JavaDoc
62     {
63         super.setUp();
64
65         _connection = getEnvironment().getConnection();
66     }
67
68     protected void tearDown() throws Exception JavaDoc
69     {
70         super.tearDown();
71
72         DatabaseOperation.DELETE_ALL.execute(_connection, _connection.createDataSet());
73
74         _connection = null;
75     }
76
77     ////////////////////////////////////////////////////////////////////////////
78
// DatabaseTestCase class
79

80     protected IDatabaseConnection getConnection() throws Exception JavaDoc
81     {
82         IDatabaseConnection connection = getEnvironment().getConnection();
83         return connection;
84
85 // return new DatabaseEnvironment(getEnvironment().getProfile()).getConnection();
86
// return new DatabaseConnection(connection.getConnection(), connection.getSchema());
87
}
88
89     protected IDataSet getDataSet() throws Exception JavaDoc
90     {
91         return getEnvironment().getInitDataSet();
92     }
93
94     protected void closeConnection(IDatabaseConnection connection) throws Exception JavaDoc
95     {
96 // getEnvironment().closeConnection();
97
}
98 //
99
// protected DatabaseOperation getTearDownOperation() throws Exception
100
// {
101
// return DatabaseOperation.DELETE_ALL;
102
// }
103
}
104
105
106
107
108
109
110
Popular Tags