Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb75814a

Browse files
committed
The attached patch is my first run-through of the JDBC test suite. A
summary of changes: . removal of the tablename property from build.xml . addition of a dropTable method in JDBC2Tests and cleanups of manymethods in the same . all tests now use non-deprecated assertXYZ methods instead of thedeprecated assert method . failure in TimestampTest (testSetTimestamp) fixed. The failure isbecause testSetTimestamp was inserting a timestamp with hour 7 butcheckTimeTest was expecting a timestamp with hour 8. AFAICS, there areno issues wrt daylight savings time and timestamps being pushed in andpulled out (but more explicit tests should be added in the future) . failure in TimeTest (testGetTime) fixed. Times to be inserted wereinterpreted in the localtime zone but checking was done with theassumption that the insertion was done in GMT. . formatting changes in a few of the source files (because I foundit convenient to have consistent formatting while working on them). Theformatting is consistent with the new format for java source files inPostgreSQL.Liam Stewart
1 parentc7bc0dd commitb75814a

File tree

13 files changed

+759
-807
lines changed

13 files changed

+759
-807
lines changed

‎src/interfaces/jdbc/build.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
build file to allow ant (http://jakarta.apache.org/ant/) to be used
55
to build the PostgreSQL JDBC Driver
66
7-
$Header: /cvsroot/pgsql/src/interfaces/jdbc/Attic/build.xml,v 1.17 2001/07/06 23:07:20 petere Exp $
7+
$Header: /cvsroot/pgsql/src/interfaces/jdbc/Attic/build.xml,v 1.18 2001/09/23 04:11:14 momjian Exp $
88
99
-->
1010

@@ -182,7 +182,6 @@
182182
<propertyname="username"value="test" />
183183
<!-- Password must be something. Doesn't matter if trust is used!-->
184184
<propertyname="password"value="password" />
185-
<propertyname="tablename"value="jdbctest" />
186185
<!-- junit.ui is one of textui, awtui, or swingui-->
187186
<propertyname="junit.ui"value="textui" />
188187

‎src/interfaces/jdbc/org/postgresql/test/JDBC2Tests.java

Lines changed: 168 additions & 186 deletions
Original file line numberDiff line numberDiff line change
@@ -10,206 +10,188 @@
1010
* Executes all known tests for JDBC2 and includes some utility methods.
1111
*/
1212
publicclassJDBC2TestsextendsTestSuite {
13-
/**
14-
* Returns the Test database JDBC URL
15-
*/
16-
publicstaticStringgetURL() {
17-
returnSystem.getProperty("database");
18-
}
19-
20-
/**
21-
* Returns the Postgresql username
22-
*/
23-
publicstaticStringgetUser() {
24-
returnSystem.getProperty("username");
25-
}
26-
27-
/**
28-
* Returns the user's password
29-
*/
30-
publicstaticStringgetPassword() {
31-
returnSystem.getProperty("password");
32-
}
33-
34-
/**
35-
* helper - opens a connection. Static so other classes can call it.
36-
*/
37-
publicstaticjava.sql.ConnectionopenDB() {
38-
try {
39-
Class.forName("org.postgresql.Driver");
40-
returnjava.sql.DriverManager.getConnection(JDBC2Tests.getURL(),JDBC2Tests.getUser(),JDBC2Tests.getPassword());
41-
}catch(ClassNotFoundExceptionex) {
42-
TestCase.assert(ex.getMessage(),false);
43-
}catch(SQLExceptionex) {
44-
TestCase.assert(ex.getMessage(),false);
45-
}
46-
returnnull;
47-
}
48-
49-
/**
50-
* Helper - closes an open connection. This rewrites SQLException to a failed
51-
* assertion. It's static so other classes can use it.
52-
*/
53-
publicstaticvoidcloseDB(Connectionconn) {
54-
try {
55-
if(conn!=null)
56-
conn.close();
57-
}catch(SQLExceptionex) {
58-
TestCase.assert(ex.getMessage(),false);
59-
}
60-
}
13+
/**
14+
* Returns the Test database JDBC URL
15+
*/
16+
publicstaticStringgetURL() {
17+
returnSystem.getProperty("database");
18+
}
19+
20+
/**
21+
* Returns the Postgresql username
22+
*/
23+
publicstaticStringgetUser() {
24+
returnSystem.getProperty("username");
25+
}
26+
27+
/**
28+
* Returns the user's password
29+
*/
30+
publicstaticStringgetPassword() {
31+
returnSystem.getProperty("password");
32+
}
33+
34+
/**
35+
* Helper - opens a connection.
36+
*/
37+
publicstaticjava.sql.ConnectionopenDB() {
38+
try {
39+
Class.forName("org.postgresql.Driver");
40+
returnjava.sql.DriverManager.getConnection(JDBC2Tests.getURL(),JDBC2Tests.getUser(),JDBC2Tests.getPassword());
41+
}catch(ClassNotFoundExceptionex) {
42+
TestCase.fail(ex.getMessage());
43+
}catch(SQLExceptionex) {
44+
TestCase.fail(ex.getMessage());
45+
}
46+
returnnull;
47+
}
48+
49+
/**
50+
* Helper - closes an open connection. This rewrites SQLException to a failed
51+
* assertion. It's static so other classes can use it.
52+
*/
53+
publicstaticvoidcloseDB(Connectioncon) {
54+
try {
55+
if (con !=null)
56+
con.close();
57+
}catch(SQLExceptionex) {
58+
TestCase.fail(ex.getMessage());
59+
}
60+
}
6161

6262
/**
6363
* Helper - creates a test table for use by a test
64-
*/
65-
publicstaticvoidcreateTable(
66-
Connectionconn,Stringtable,Stringcolumns) {
64+
*/
65+
publicstaticvoidcreateTable(Connectioncon,
66+
Stringtable,
67+
Stringcolumns) {
6768
try {
68-
Statementst =conn.createStatement();
69+
Statementst =con.createStatement();
6970
try {
70-
try {
71-
st.executeUpdate("drop table " +table);
72-
}catch(SQLExceptionse) {
73-
// Intentionally ignore exception
74-
}
71+
// Drop the table
72+
dropTable(con,table);
7573

7674
// Now create the table
77-
st.executeUpdate("create table " +table +" (" +columns +
78-
")" );
75+
st.executeUpdate("create table " +table +" (" +columns +")");
7976
}finally {
8077
st.close();
8178
}
8279
}catch(SQLExceptionex) {
83-
TestCase.assert(ex.getMessage(),false);
80+
TestCase.fail(ex.getMessage());
81+
}
82+
}
83+
84+
/**
85+
* Helper - drops a table
86+
*/
87+
publicstaticvoiddropTable(Connectioncon,Stringtable) {
88+
try {
89+
Statementstmt =con.createStatement();
90+
try {
91+
stmt.executeUpdate("DROP TABLE " +table);
92+
}catch (SQLExceptionex) {
93+
// ignore
94+
}
95+
}catch (SQLExceptionex) {
96+
TestCase.fail(ex.getMessage());
8497
}
8598
}
8699

87-
// Create the test table whose name is passed via the properties
88-
// (see ../../../build.xml). It appears that the original author of
89-
// this test suite intended to specify all test table names via the
90-
// properties, but this was never fully implemented.
91-
publicstaticvoidcreateTable(Connectionconn,Stringcolumns) {
92-
createTable(conn,getTableName(),columns);
100+
/**
101+
* Helper - generates INSERT SQL - very simple
102+
*/
103+
publicstaticStringinsertSQL(Stringtable,Stringvalues) {
104+
returninsertSQL(table,null,values);
93105
}
106+
107+
publicstaticStringinsertSQL(Stringtable,Stringcolumns,Stringvalues) {
108+
Strings ="INSERT INTO " +table;
109+
110+
if (columns !=null)
111+
s =s +" (" +columns +")";
112+
113+
returns +" VALUES (" +values +")";
114+
}
115+
116+
/**
117+
* Helper - generates SELECT SQL - very simple
118+
*/
119+
publicstaticStringselectSQL(Stringtable,Stringcolumns) {
120+
returnselectSQL(table,columns,null,null);
121+
}
122+
123+
publicstaticStringselectSQL(Stringtable,Stringcolumns,Stringwhere) {
124+
returnselectSQL(table,columns,where,null);
125+
}
126+
127+
publicstaticStringselectSQL(Stringtable,Stringcolumns,Stringwhere,Stringother) {
128+
Strings ="SELECT " +columns +" FROM " +table;
129+
130+
if (where !=null)
131+
s =s +" WHERE " +where;
132+
if (other !=null)
133+
s =s +" " +other;
134+
135+
returns;
136+
}
137+
138+
/**
139+
* Helper to prefix a number with leading zeros - ugly but it works...
140+
* @param v value to prefix
141+
* @param l number of digits (0-10)
142+
*/
143+
publicstaticStringfix(intv,intl) {
144+
Strings ="0000000000".substring(0,l) +Integer.toString(v);
145+
returns.substring(s.length() -l);
146+
}
147+
148+
/**
149+
* The main entry point for JUnit
150+
*/
151+
publicstaticTestSuitesuite() {
152+
TestSuitesuite=newTestSuite();
94153

95-
/**
96-
* Helper - generates INSERT SQL - very simple
97-
*/
98-
publicstaticStringinsert(Stringvalues) {
99-
returninsert(null,values);
100-
}
101-
publicstaticStringinsert(Stringcolumns,Stringvalues) {
102-
Strings ="INSERT INTO "+getTableName();
103-
if(columns!=null)
104-
s=s+" ("+columns+")";
105-
returns+" VALUES ("+values+")";
106-
}
107-
108-
/**
109-
* Helper - generates SELECT SQL - very simple
110-
*/
111-
publicstaticStringselect(Stringcolumns) {
112-
returnselect(columns,null,null);
113-
}
114-
publicstaticStringselect(Stringcolumns,Stringwhere) {
115-
returnselect(columns,where,null);
116-
}
117-
publicstaticStringselect(Stringcolumns,Stringwhere,Stringother) {
118-
Strings ="SELECT "+columns+" FROM "+getTableName();
119-
if(where!=null)
120-
s=s+" WHERE "+where;
121-
if(other!=null)
122-
s=s+" "+other;
123-
returns;
124-
}
125-
126-
/**
127-
* Helper - returns the test table's name
128-
* This is defined by the tablename property. If not defined it defaults to
129-
* jdbctest
130-
*/
131-
publicstaticStringgetTableName() {
132-
if(tablename==null)
133-
tablename=System.getProperty("tablename","jdbctest");
134-
returntablename;
135-
}
136-
137-
/**
138-
* As getTableName() but the id is a suffix. Used when more than one table is
139-
* required in a test.
140-
*/
141-
publicstaticStringgetTableName(Stringid) {
142-
if(tablename==null)
143-
tablename=System.getProperty("tablename","jdbctest");
144-
returntablename+"_"+id;
145-
}
146-
147-
/**
148-
* Cache used by getTableName() [its used a lot!]
149-
*/
150-
privatestaticStringtablename;
151-
152-
/**
153-
* Helper to prefix a number with leading zeros - ugly but it works...
154-
* @param v value to prefix
155-
* @param l number of digits (0-10)
156-
*/
157-
publicstaticStringfix(intv,intl) {
158-
Strings ="0000000000".substring(0,l)+Integer.toString(v);
159-
returns.substring(s.length()-l);
160-
}
161-
162-
/**
163-
* Number of milliseconds in a day
164-
*/
165-
publicstaticfinallongDAYMILLIS =24*3600*1000;
166-
167-
/**
168-
* The main entry point for JUnit
169-
*/
170-
publicstaticTestSuitesuite() {
171-
TestSuitesuite=newTestSuite();
172-
173-
//
174-
// Add one line per class in our test cases. These should be in order of
175-
// complexity.
176-
177-
// ANTTest should be first as it ensures that test parameters are
178-
// being sent to the suite. It also initialises the database (if required)
179-
// with some simple global tables (will make each testcase use its own later).
180-
//
181-
suite.addTestSuite(ANTTest.class);
182-
183-
// Basic Driver internals
184-
suite.addTestSuite(DriverTest.class);
185-
suite.addTestSuite(ConnectionTest.class);
186-
suite.addTestSuite(DatabaseMetaDataTest.class);
187-
suite.addTestSuite(EncodingTest.class);
188-
189-
// Connectivity/Protocols
190-
191-
// ResultSet
192-
suite.addTestSuite(DateTest.class);
193-
suite.addTestSuite(TimeTest.class);
194-
suite.addTestSuite(TimestampTest.class);
195-
196-
// PreparedStatement
197-
suite.addTestSuite(BatchExecuteTest.class);
198-
199-
// BatchExecute
200-
201-
202-
// MetaData
203-
204-
// Other misc tests, based on previous problems users have had or specific
205-
// features some applications require.
206-
suite.addTestSuite(JBuilderTest.class);
207-
suite.addTestSuite(MiscTest.class);
208-
209-
// Fastpath/LargeObject
210-
suite.addTestSuite(BlobTest.class);
211-
212-
// That's all folks
213-
returnsuite;
214-
}
154+
//
155+
// Add one line per class in our test cases. These should be in order of
156+
// complexity.
157+
158+
// ANTTest should be first as it ensures that test parameters are
159+
// being sent to the suite. It also initialises the database (if required)
160+
// with some simple global tables (will make each testcase use its own later).
161+
//
162+
suite.addTestSuite(ANTTest.class);
163+
164+
// Basic Driver internals
165+
suite.addTestSuite(DriverTest.class);
166+
suite.addTestSuite(ConnectionTest.class);
167+
suite.addTestSuite(DatabaseMetaDataTest.class);
168+
suite.addTestSuite(EncodingTest.class);
169+
170+
// Connectivity/Protocols
171+
172+
// ResultSet
173+
174+
// Time, Date, Timestamp
175+
suite.addTestSuite(DateTest.class);
176+
suite.addTestSuite(TimeTest.class);
177+
suite.addTestSuite(TimestampTest.class);
178+
179+
// PreparedStatement
180+
181+
// BatchExecute
182+
suite.addTestSuite(BatchExecuteTest.class);
183+
184+
// MetaData
185+
186+
// Other misc tests, based on previous problems users have had or specific
187+
// features some applications require.
188+
suite.addTestSuite(JBuilderTest.class);
189+
suite.addTestSuite(MiscTest.class);
190+
191+
// Fastpath/LargeObject
192+
suite.addTestSuite(BlobTest.class);
193+
194+
// That's all folks
195+
returnsuite;
196+
}
215197
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp