1
package org.postgresql.test;
3
import junit.framework.TestSuite;
4
import junit.framework.TestCase;
6
import org.postgresql.test.jdbc2.*;
10
* Executes all known tests for JDBC2 and includes some utility methods.
12
public class JDBC2Tests extends TestSuite
15
* Returns the Test database JDBC URL
17
public static String getURL()
19
return System.getProperty("database");
23
* Returns the Postgresql username
25
public static String getUser()
27
return System.getProperty("username");
31
* Returns the user's password
33
public static String getPassword()
35
return System.getProperty("password");
39
* Helper - opens a connection.
41
public static java.sql.Connection openDB()
45
Class.forName("org.postgresql.Driver");
46
return java.sql.DriverManager.getConnection(JDBC2Tests.getURL(), JDBC2Tests.getUser(), JDBC2Tests.getPassword());
48
catch (ClassNotFoundException ex)
50
TestCase.fail(ex.getMessage());
52
catch (SQLException ex)
54
TestCase.fail(ex.getMessage());
60
* Helper - closes an open connection. This rewrites SQLException to a failed
61
* assertion. It's static so other classes can use it.
63
public static void closeDB(Connection con)
70
catch (SQLException ex)
72
TestCase.fail(ex.getMessage());
77
* Helper - creates a test table for use by a test
79
public static void createTable(Connection con,
85
Statement st = con.createStatement();
89
dropTable(con, table);
91
// Now create the table
92
st.executeUpdate("create table " + table + " (" + columns + ")");
99
catch (SQLException ex)
101
TestCase.fail(ex.getMessage());
106
* Helper - drops a table
108
public static void dropTable(Connection con, String table)
112
Statement stmt = con.createStatement();
115
stmt.executeUpdate("DROP TABLE " + table);
117
catch (SQLException ex)
122
catch (SQLException ex)
124
TestCase.fail(ex.getMessage());
129
* Helper - generates INSERT SQL - very simple
131
public static String insertSQL(String table, String values)
133
return insertSQL(table, null, values);
136
public static String insertSQL(String table, String columns, String values)
138
String s = "INSERT INTO " + table;
141
s = s + " (" + columns + ")";
143
return s + " VALUES (" + values + ")";
147
* Helper - generates SELECT SQL - very simple
149
public static String selectSQL(String table, String columns)
151
return selectSQL(table, columns, null, null);
154
public static String selectSQL(String table, String columns, String where)
156
return selectSQL(table, columns, where, null);
159
public static String selectSQL(String table, String columns, String where, String other)
161
String s = "SELECT " + columns + " FROM " + table;
164
s = s + " WHERE " + where;
172
* Helper to prefix a number with leading zeros - ugly but it works...
173
* @param v value to prefix
174
* @param l number of digits (0-10)
176
public static String fix(int v, int l)
178
String s = "0000000000".substring(0, l) + Integer.toString(v);
179
return s.substring(s.length() - l);
183
* The main entry point for JUnit
185
public static TestSuite suite()
187
TestSuite suite = new TestSuite();
190
// Add one line per class in our test cases. These should be in order of
193
// ANTTest should be first as it ensures that test parameters are
194
// being sent to the suite. It also initialises the database (if required)
195
// with some simple global tables (will make each testcase use its own later).
197
suite.addTestSuite(ANTTest.class);
199
// Basic Driver internals
200
suite.addTestSuite(DriverTest.class);
201
suite.addTestSuite(ConnectionTest.class);
202
suite.addTestSuite(DatabaseMetaDataTest.class);
203
suite.addTestSuite(EncodingTest.class);
205
// Connectivity/Protocols
208
suite.addTestSuite(ResultSetTest.class);
210
// Time, Date, Timestamp
211
suite.addTestSuite(DateTest.class);
212
suite.addTestSuite(TimeTest.class);
213
suite.addTestSuite(TimestampTest.class);
218
suite.addTestSuite(BatchExecuteTest.class);
222
// Other misc tests, based on previous problems users have had or specific
223
// features some applications require.
224
suite.addTestSuite(JBuilderTest.class);
225
suite.addTestSuite(MiscTest.class);
227
// Fastpath/LargeObject
228
suite.addTestSuite(BlobTest.class);