mirror of
https://github.com/postgres/postgres.git
synced 2025-07-05 07:21:24 +03:00
Some updates prior to retrieving a fresh cvs copy:
Tue Feb 06 19:00:00 GMT 2001 peter@retep.org.uk - Completed first two TestCase's for the test suite. JUnit is now recognised by ant.
This commit is contained in:
@ -353,6 +353,7 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu
|
||||
|
||||
if (s != null)
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
val = new BigDecimal(s);
|
||||
|
94
src/interfaces/jdbc/org/postgresql/test/JDBC2Tests.java
Normal file
94
src/interfaces/jdbc/org/postgresql/test/JDBC2Tests.java
Normal file
@ -0,0 +1,94 @@
|
||||
package org.postgresql.test;
|
||||
|
||||
import junit.framework.TestSuite;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.postgresql.test.jdbc2.*;
|
||||
import java.sql.*;
|
||||
|
||||
/**
|
||||
* Executes all known tests for JDBC2
|
||||
*/
|
||||
public class JDBC2Tests extends TestSuite {
|
||||
/**
|
||||
* Returns the Test database JDBC URL
|
||||
*/
|
||||
public static String getURL() {
|
||||
return System.getProperty("database");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Postgresql username
|
||||
*/
|
||||
public static String getUser() {
|
||||
return System.getProperty("username");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the user's password
|
||||
*/
|
||||
public static String getPassword() {
|
||||
return System.getProperty("password");
|
||||
}
|
||||
|
||||
/**
|
||||
* helper - opens a connection. Static so other classes can call it.
|
||||
*/
|
||||
public static java.sql.Connection openDB() {
|
||||
try {
|
||||
Class.forName("org.postgresql.Driver");
|
||||
return java.sql.DriverManager.getConnection(JDBC2Tests.getURL(),JDBC2Tests.getUser(),JDBC2Tests.getPassword());
|
||||
} catch(ClassNotFoundException ex) {
|
||||
TestCase.assert(ex.getMessage(),false);
|
||||
} catch(SQLException ex) {
|
||||
TestCase.assert(ex.getMessage(),false);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper - closes an open connection. This rewrites SQLException to a failed
|
||||
* assertion. It's static so other classes can use it.
|
||||
*/
|
||||
public static void closeDB(Connection conn) {
|
||||
try {
|
||||
if(conn!=null)
|
||||
conn.close();
|
||||
} catch(SQLException ex) {
|
||||
TestCase.assert(ex.getMessage(),false);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The main entry point for JUnit
|
||||
*/
|
||||
public static TestSuite suite() {
|
||||
TestSuite suite= new TestSuite();
|
||||
|
||||
//
|
||||
// Add one line per class in our test cases. These should be in order of
|
||||
// complexity.
|
||||
//
|
||||
// ie: ANTTest should be first as it ensures that test parameters are
|
||||
// being sent to the suite.
|
||||
//
|
||||
|
||||
// Basic Driver internals
|
||||
suite.addTestSuite(ANTTest.class);
|
||||
suite.addTestSuite(DriverTest.class);
|
||||
suite.addTestSuite(ConnectionTest.class);
|
||||
|
||||
// Connectivity/Protocols
|
||||
|
||||
// ResultSet
|
||||
|
||||
// PreparedStatement
|
||||
|
||||
// MetaData
|
||||
|
||||
// Fastpath/LargeObject
|
||||
|
||||
// That's all folks
|
||||
return suite;
|
||||
}
|
||||
}
|
26
src/interfaces/jdbc/org/postgresql/test/jdbc2/ANTTest.java
Normal file
26
src/interfaces/jdbc/org/postgresql/test/jdbc2/ANTTest.java
Normal file
@ -0,0 +1,26 @@
|
||||
package org.postgresql.test.jdbc2;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class ANTTest extends TestCase {
|
||||
public ANTTest(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* This tests the acceptsURL() method with a couple of good and badly formed
|
||||
* jdbc urls
|
||||
*/
|
||||
public void testANT() {
|
||||
String url=System.getProperty("database");
|
||||
String usr=System.getProperty("username");
|
||||
String psw=System.getProperty("password");
|
||||
|
||||
assert(url!=null);
|
||||
assert(usr!=null);
|
||||
assert(psw!=null);
|
||||
|
||||
assert(!url.equals(""));
|
||||
assert(!usr.equals(""));
|
||||
}
|
||||
}
|
@ -0,0 +1,149 @@
|
||||
package org.postgresql.test.jdbc2;
|
||||
|
||||
import org.postgresql.test.JDBC2Tests;
|
||||
import junit.framework.TestCase;
|
||||
import java.sql.*;
|
||||
|
||||
/**
|
||||
* TestCase to test the internal functionality of org.postgresql.jdbc2.Connection
|
||||
* and it's superclass.
|
||||
*
|
||||
* PS: Do you know how difficult it is to type on a train? ;-)
|
||||
*
|
||||
* $Id: ConnectionTest.java,v 1.1 2001/02/07 09:13:20 peter Exp $
|
||||
*/
|
||||
|
||||
public class ConnectionTest extends TestCase {
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public ConnectionTest(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the two forms of createStatement()
|
||||
*/
|
||||
public void testCreateStatement() {
|
||||
try {
|
||||
java.sql.Connection conn = JDBC2Tests.openDB();
|
||||
|
||||
// A standard Statement
|
||||
java.sql.Statement stat = conn.createStatement();
|
||||
assert(stat!=null);
|
||||
stat.close();
|
||||
|
||||
// Ask for Updateable ResultSets
|
||||
stat = conn.createStatement(java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,java.sql.ResultSet.CONCUR_UPDATABLE);
|
||||
assert(stat!=null);
|
||||
stat.close();
|
||||
|
||||
} catch(SQLException ex) {
|
||||
assert(ex.getMessage(),false);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the two forms of prepareStatement()
|
||||
*/
|
||||
public void testPrepareStatement() {
|
||||
try {
|
||||
java.sql.Connection conn = JDBC2Tests.openDB();
|
||||
|
||||
String sql = "select source,cost,imageid from test_c";
|
||||
|
||||
// A standard Statement
|
||||
java.sql.PreparedStatement stat = conn.prepareStatement(sql);
|
||||
assert(stat!=null);
|
||||
stat.close();
|
||||
|
||||
// Ask for Updateable ResultSets
|
||||
stat = conn.prepareStatement(sql,java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,java.sql.ResultSet.CONCUR_UPDATABLE);
|
||||
assert(stat!=null);
|
||||
stat.close();
|
||||
|
||||
} catch(SQLException ex) {
|
||||
assert(ex.getMessage(),false);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Put the test for createPrepareCall here
|
||||
*/
|
||||
public void testPrepareCall() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Test nativeSQL
|
||||
*/
|
||||
public void testNativeSQL() {
|
||||
// For now do nothing as it returns itself
|
||||
}
|
||||
|
||||
/**
|
||||
* Test autoCommit (both get & set)
|
||||
*/
|
||||
public void testTransactions() {
|
||||
try {
|
||||
java.sql.Connection con = JDBC2Tests.openDB();
|
||||
java.sql.Statement st;
|
||||
java.sql.ResultSet rs;
|
||||
|
||||
// Turn it off
|
||||
con.setAutoCommit(false);
|
||||
assert(!con.getAutoCommit());
|
||||
|
||||
// Turn it back on
|
||||
con.setAutoCommit(true);
|
||||
assert(con.getAutoCommit());
|
||||
|
||||
// Now test commit
|
||||
st = con.createStatement();
|
||||
st.executeUpdate("insert into test_a (imagename,image,id) values ('comttest',1234,5678)");
|
||||
|
||||
con.setAutoCommit(false);
|
||||
|
||||
// Now update image to 9876 and commit
|
||||
st.executeUpdate("update test_a set image=9876 where id=5678");
|
||||
con.commit();
|
||||
rs = st.executeQuery("select image from test_a where id=5678");
|
||||
assert(rs.next());
|
||||
assert(rs.getInt(1)==9876);
|
||||
rs.close();
|
||||
|
||||
// Now try to change it but rollback
|
||||
st.executeUpdate("update test_a set image=1111 where id=5678");
|
||||
con.rollback();
|
||||
rs = st.executeQuery("select image from test_a where id=5678");
|
||||
assert(rs.next());
|
||||
assert(rs.getInt(1)==9876); // Should not change!
|
||||
rs.close();
|
||||
|
||||
JDBC2Tests.closeDB(con);
|
||||
} catch(SQLException ex) {
|
||||
assert(ex.getMessage(),false);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple test to see if isClosed works
|
||||
*/
|
||||
public void testIsClosed() {
|
||||
try {
|
||||
Connection con = JDBC2Tests.openDB();
|
||||
|
||||
// Should not say closed
|
||||
assert(!con.isClosed());
|
||||
|
||||
JDBC2Tests.closeDB(con);
|
||||
|
||||
// Should now say closed
|
||||
assert(con.isClosed());
|
||||
|
||||
} catch(SQLException ex) {
|
||||
assert(ex.getMessage(),false);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,73 @@
|
||||
package org.postgresql.test.jdbc2;
|
||||
|
||||
import org.postgresql.test.JDBC2Tests;
|
||||
import junit.framework.TestCase;
|
||||
import java.sql.*;
|
||||
|
||||
/**
|
||||
* $Id: DriverTest.java,v 1.1 2001/02/07 09:13:20 peter Exp $
|
||||
*
|
||||
* Tests the dynamically created class org.postgresql.Driver
|
||||
*
|
||||
*/
|
||||
public class DriverTest extends TestCase {
|
||||
|
||||
public DriverTest(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* This tests the acceptsURL() method with a couple of good and badly formed
|
||||
* jdbc urls
|
||||
*/
|
||||
public void testAcceptsURL() {
|
||||
try {
|
||||
|
||||
// Load the driver (note clients should never do it this way!)
|
||||
org.postgresql.Driver drv = new org.postgresql.Driver();
|
||||
assert(drv!=null);
|
||||
|
||||
// These are always correct
|
||||
assert(drv.acceptsURL("jdbc:postgresql:test"));
|
||||
assert(drv.acceptsURL("jdbc:postgresql://localhost/test"));
|
||||
assert(drv.acceptsURL("jdbc:postgresql://localhost:5432/test"));
|
||||
assert(drv.acceptsURL("jdbc:postgresql://127.0.0.1/anydbname"));
|
||||
assert(drv.acceptsURL("jdbc:postgresql://127.0.0.1:5433/hidden"));
|
||||
|
||||
// Badly formatted url's
|
||||
assert(!drv.acceptsURL("jdbc:postgres:test"));
|
||||
assert(!drv.acceptsURL("postgresql:test"));
|
||||
|
||||
} catch(SQLException ex) {
|
||||
assert(ex.getMessage(),false);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests parseURL (internal)
|
||||
*/
|
||||
/**
|
||||
* Tests the connect method by connecting to the test database
|
||||
*/
|
||||
public void testConnect() {
|
||||
Connection con=null;
|
||||
try {
|
||||
Class.forName("org.postgresql.Driver");
|
||||
|
||||
// Test with the url, username & password
|
||||
con = DriverManager.getConnection(JDBC2Tests.getURL(),JDBC2Tests.getUser(),JDBC2Tests.getPassword());
|
||||
assert(con!=null);
|
||||
con.close();
|
||||
|
||||
// Test with the username in the url
|
||||
con = DriverManager.getConnection(JDBC2Tests.getURL()+"?user="+JDBC2Tests.getUser()+"&password="+JDBC2Tests.getPassword());
|
||||
assert(con!=null);
|
||||
con.close();
|
||||
|
||||
} catch(ClassNotFoundException ex) {
|
||||
assert(ex.getMessage(),false);
|
||||
} catch(SQLException ex) {
|
||||
assert(ex.getMessage(),false);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user