1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
|
/*-------------------------------------------------------------------------
*
* Copyright (c) 2004-2008, PostgreSQL Global Development Group
*
* IDENTIFICATION
* $PostgreSQL: pgjdbc/org/postgresql/test/jdbc2/GetXXXTest.java,v 1.6 2008/01/08 06:56:31 jurka Exp $
*
*-------------------------------------------------------------------------
*/
package org.postgresql.test.jdbc2;
import org.postgresql.test.TestUtil;
import java.util.Calendar;
import junit.framework.*;
import java.sql.*;
import java.util.HashMap;
/*
* Test for getObject
*/
public class GetXXXTest extends TestCase
{
Connection con = null;
public GetXXXTest(String name )
{
super(name);
}
protected void setUp() throws Exception
{
super.setUp();
con = TestUtil.openDB();
TestUtil.createTempTable(con, "test_interval",
"initial timestamp with time zone, final timestamp with time zone");
PreparedStatement pstmt = con.prepareStatement(
"insert into test_interval values (?,?)");
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DAY_OF_YEAR, -1);
pstmt.setTimestamp(1, new Timestamp(cal.getTime().getTime()));
pstmt.setTimestamp(2, new Timestamp(System.currentTimeMillis()));
assertTrue(pstmt.executeUpdate() == 1);
pstmt.close();
}
protected void tearDown() throws Exception
{
super.tearDown();
TestUtil.dropTable( con, "test_interval" );
con.close();
}
public void testGetObject() throws SQLException
{
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(
"select (final-initial) as diff from test_interval");
while (rs.next())
{
String str = (String) rs.getString(1);
assertNotNull(str);
Object obj = rs.getObject(1);
assertNotNull(obj);
}
}
public void testGetUDT() throws SQLException
{
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("select (final-initial) as diff from test_interval");
while (rs.next() )
{
// make this return a PGobject
Object obj = rs.getObject(1, new HashMap());
// it should not be an instance of PGInterval
assertTrue(obj instanceof org.postgresql.util.PGInterval);
}
}
}
|