1
0
mirror of https://github.com/postgres/postgres.git synced 2025-08-30 06:01:21 +03:00

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 many
methods in the same

 . all tests now use non-deprecated assertXYZ methods instead of the
deprecated assert method

 . failure in TimestampTest (testSetTimestamp) fixed. The failure is
because testSetTimestamp was inserting a timestamp with hour 7 but
checkTimeTest was expecting a timestamp with hour 8. AFAICS, there are
no issues wrt daylight savings time and timestamps being pushed in and
pulled out (but more explicit tests should be added in the future)

 . failure in TimeTest (testGetTime) fixed. Times to be inserted were
interpreted in the localtime zone but checking was done with the
assumption that the insertion was done in GMT.

 . formatting changes in a few of the source files (because I found
it convenient to have consistent formatting while working on them). The
formatting is consistent with the new format for java source files in
PostgreSQL.

Liam Stewart
This commit is contained in:
Bruce Momjian
2001-09-23 04:11:14 +00:00
parent c7bc0ddf76
commit b75814aee3
13 changed files with 669 additions and 717 deletions

View File

@@ -5,7 +5,7 @@ import junit.framework.TestCase;
import java.sql.*;
/**
* $Id: TimestampTest.java,v 1.2 2001/02/16 16:45:01 peter Exp $
* $Id: TimestampTest.java,v 1.3 2001/09/23 04:11:14 momjian Exp $
*
* This has been the most controversial pair of methods since 6.5 was released!
*
@@ -15,123 +15,118 @@ import java.sql.*;
*/
public class TimestampTest extends TestCase {
public TimestampTest(String name) {
super(name);
}
private Connection con;
/**
* Tests the time methods in ResultSet
*/
public void testGetTimestamp() {
try {
Connection con = JDBC2Tests.openDB();
public TimestampTest(String name) {
super(name);
}
Statement st=con.createStatement();
protected void setUp() throws Exception {
con = JDBC2Tests.openDB();
Statement stmt = con.createStatement();
JDBC2Tests.createTable(con, "testtimestamp", "ts timestamp");
}
JDBC2Tests.createTable(con,"ts timestamp");
protected void tearDown() throws Exception {
JDBC2Tests.dropTable(con, "testtimestamp");
JDBC2Tests.closeDB(con);
}
st.executeUpdate(JDBC2Tests.insert("'1950-02-07 15:00:00'"));
/**
* Tests the time methods in ResultSet
*/
public void testGetTimestamp() {
try {
Statement stmt = con.createStatement();
// Before you ask why 8:13:00 and not 7:13:00, this is a problem with the
// getTimestamp method in this TestCase. It's simple, brain-dead. It
// simply doesn't know about summer time. As this date is in June, it's
// summer (GMT wise).
//
// This case needs some work done on it.
//
st.executeUpdate(JDBC2Tests.insert("'"+getTimestamp(1970,6,2,8,13,0).toString()+"'"));
assertEquals(1, stmt.executeUpdate(JDBC2Tests.insertSQL("testtimestamp",
"'1950-02-07 15:00:00'")));
//st.executeUpdate(JDBC2Tests.insert("'1950-02-07'"));
assertEquals(1, stmt.executeUpdate(JDBC2Tests.insertSQL("testtimestamp", "'" +
getTimestamp(1970, 6, 2, 8, 13, 0, 0).toString() +
"'")));
// Fall through helper
checkTimeTest(con,st);
assertEquals(1, stmt.executeUpdate(JDBC2Tests.insertSQL("testtimestamp",
"'1970-06-02 08:13:00'")));
st.close();
// Fall through helper
timestampTest();
JDBC2Tests.closeDB(con);
} catch(Exception ex) {
assert(ex.getMessage(),false);
}
}
assertEquals(3, stmt.executeUpdate("DELETE FROM testtimestamp"));
/**
* Tests the time methods in PreparedStatement
*/
public void testSetTimestamp() {
try {
Connection con = JDBC2Tests.openDB();
stmt.close();
} catch(Exception ex) {
fail(ex.getMessage());
}
}
Statement st=con.createStatement();
/**
* Tests the time methods in PreparedStatement
*/
public void testSetTimestamp() {
try {
Statement stmt = con.createStatement();
PreparedStatement pstmt = con.prepareStatement(JDBC2Tests.insertSQL("testtimestamp", "?"));
JDBC2Tests.createTable(con,"ts timestamp");
pstmt.setTimestamp(1, getTimestamp(1950, 2, 7, 15, 0, 0, 0));
assertEquals(1, pstmt.executeUpdate());
PreparedStatement ps = con.prepareStatement(JDBC2Tests.insert("?"));
pstmt.setTimestamp(1, getTimestamp(1970, 6, 2, 8, 13, 0, 0));
assertEquals(1, pstmt.executeUpdate());
ps.setTimestamp(1,getTimestamp(1950,2,7,15,0,0));
assert(!ps.execute()); // false as its an update!
pstmt.setTimestamp(1, getTimestamp(1970, 6, 2, 8, 13, 0, 0));
assertEquals(1, pstmt.executeUpdate());
// Before you ask why 8:13:00 and not 7:13:00, this is a problem with the
// getTimestamp method in this TestCase. It's simple, brain-dead. It
// simply doesn't know about summer time. As this date is in June, it's
// summer (GMT wise).
//
// This case needs some work done on it.
//
ps.setTimestamp(1,getTimestamp(1970,6,2,7,13,0));
assert(!ps.execute()); // false as its an update!
// Fall through helper
timestampTest();
// Fall through helper
checkTimeTest(con,st);
assertEquals(3, stmt.executeUpdate("DELETE FROM testtimestamp"));
ps.close();
st.close();
pstmt.close();
stmt.close();
} catch(Exception ex) {
fail(ex.getMessage());
}
}
JDBC2Tests.closeDB(con);
} catch(Exception ex) {
assert(ex.getMessage(),false);
}
}
/**
* Helper for the TimeTests. It tests what should be in the db
*/
private void timestampTest() throws SQLException {
Statement stmt = con.createStatement();
ResultSet rs;
java.sql.Timestamp t;
/**
* Helper for the TimeTests. It tests what should be in the db
*/
private void checkTimeTest(Connection con,Statement st) throws SQLException {
ResultSet rs=null;
java.sql.Timestamp t=null;
rs = stmt.executeQuery(JDBC2Tests.selectSQL("testtimestamp", "ts"));
assertNotNull(rs);
rs=st.executeQuery(JDBC2Tests.select("ts"));
assert(rs!=null);
assertTrue(rs.next());
t = rs.getTimestamp(1);
assertNotNull(t);
assertTrue(t.equals(getTimestamp(1950, 2, 7, 15, 0, 0, 0)));
assert(rs.next());
t = rs.getTimestamp(1);
assert(t!=null);
assert(t.equals(getTimestamp(1950,2,7,15,0,0)));
assertTrue(rs.next());
t = rs.getTimestamp(1);
assertNotNull(t);
assertTrue(t.equals(getTimestamp(1970, 6, 2, 8, 13, 0, 0)));
assert(rs.next());
t = rs.getTimestamp(1);
assert(t!=null);
assertTrue(rs.next());
t = rs.getTimestamp(1);
assertNotNull(t);
assertTrue(t.equals(getTimestamp(1970, 6, 2, 8, 13, 0, 0)));
assertTrue(! rs.next()); // end of table. Fail if more entries exist.
// Seems Daylight saving is ignored?
assert(t.equals(getTimestamp(1970,6,2,8,13,0)));
assert(!rs.next()); // end of table. Fail if more entries exist.
rs.close();
}
/**
* These implement depreciated methods in java.sql.Time
*/
private static final long dayms = 24*3600*1000;
/**
* Yes this is ugly, but it gets the test done ;-)
*
* Actually its buggy. We need a better solution to this, then the hack of adding 1 hour to
* entries in June above don't need setting.
*/
private java.sql.Timestamp getTimestamp(int y,int m,int d,int h,int mn,int se) {
return java.sql.Timestamp.valueOf(JDBC2Tests.fix(y,4)+"-"+JDBC2Tests.fix(m,2)+"-"+JDBC2Tests.fix(d,2)+" "+JDBC2Tests.fix(h,2)+":"+JDBC2Tests.fix(mn,2)+":"+JDBC2Tests.fix(se,2)+"."+JDBC2Tests.fix(0,9));
}
rs.close();
stmt.close();
}
private java.sql.Timestamp getTimestamp(int y, int m, int d, int h, int mn, int se, int f) {
return java.sql.Timestamp.valueOf(JDBC2Tests.fix(y, 4) + "-" +
JDBC2Tests.fix(m, 2) + "-" +
JDBC2Tests.fix(d, 2) + " " +
JDBC2Tests.fix(h, 2) + ":" +
JDBC2Tests.fix(mn, 2) + ":" +
JDBC2Tests.fix(se, 2) + "." +
}