1
package org.postgresql.test.jdbc2;
3
import org.postgresql.test.JDBC2Tests;
4
import junit.framework.TestCase;
8
* $Id: TimeTest.java,v 1.4 2001/11/19 22:33:39 momjian Exp $
10
* Some simple tests based on problems reported by users. Hopefully these will
11
* help prevent previous problems from re-occuring ;-)
14
public class TimeTest extends TestCase
17
private Connection con;
19
public TimeTest(String name)
24
protected void setUp() throws Exception
26
con = JDBC2Tests.openDB();
27
JDBC2Tests.createTable(con, "testtime", "tm time");
30
protected void tearDown() throws Exception
32
JDBC2Tests.dropTable(con, "testtime");
33
JDBC2Tests.closeDB(con);
37
* Tests the time methods in ResultSet
39
public void testGetTime()
43
Statement stmt = con.createStatement();
45
assertEquals(1, stmt.executeUpdate(JDBC2Tests.insertSQL("testtime", "'01:02:03'")));
46
assertEquals(1, stmt.executeUpdate(JDBC2Tests.insertSQL("testtime", "'23:59:59'")));
48
// Fall through helper
51
assertEquals(2, stmt.executeUpdate("DELETE FROM testtime"));
56
fail(ex.getMessage());
61
* Tests the time methods in PreparedStatement
63
public void testSetTime()
67
PreparedStatement ps = con.prepareStatement(JDBC2Tests.insertSQL("testtime", "?"));
68
Statement stmt = con.createStatement();
70
ps.setTime(1, makeTime(1, 2, 3));
71
assertEquals(1, ps.executeUpdate());
73
ps.setTime(1, makeTime(23, 59, 59));
74
assertEquals(1, ps.executeUpdate());
76
// Fall through helper
79
assertEquals(2, stmt.executeUpdate("DELETE FROM testtime"));
85
fail(ex.getMessage());
90
* Helper for the TimeTests. It tests what should be in the db
92
private void timeTest() throws SQLException
94
Statement st = con.createStatement();
98
rs = st.executeQuery(JDBC2Tests.selectSQL("testtime", "tm"));
101
assertTrue(rs.next());
104
assertEquals(makeTime(1, 2, 3), t);
106
assertTrue(rs.next());
109
assertEquals(makeTime(23, 59, 59), t);
111
assertTrue(! rs.next());
116
private java.sql.Time makeTime(int h, int m, int s)
118
return java.sql.Time.valueOf(JDBC2Tests.fix(h, 2) + ":" +
119
JDBC2Tests.fix(m, 2) + ":" +
120
JDBC2Tests.fix(s, 2));