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:
Peter Mount 2001-02-07 09:13:20 +00:00
parent 90670ebdea
commit ca5d71cd07
8 changed files with 388 additions and 5 deletions

View File

@ -1,3 +1,7 @@
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.
Wed Jan 31 08:46:00 GMT 2001 peter@retep.org.uk
- Some minor additions to Statement to make our own extensions more
portable.

View File

@ -3,7 +3,7 @@
build file to allow ant (http://jakarta.apache.org/ant/) to be used
to build the PostgreSQL JDBC Driver.
$Id: build.xml,v 1.4 2001/01/18 17:37:11 peter Exp $
$Id: build.xml,v 1.5 2001/02/07 09:13:20 peter Exp $
-->
@ -17,6 +17,17 @@
<property name="major" value="7" />
<property name="minor" value="1" />
<!--
defaults for the tests - overide these if required
junit.ui is one of textui, awtui or swingui
password must be something. Doesnt matter if trust is used!
-->
<property name="database" value="jdbc:postgresql:test" />
<property name="username" value="test" />
<property name="password" value="password" />
<property name="junit.ui" value="textui" />
<!--
This is a simpler method than utils.CheckVersion
It defaults to jdbc1, but builds jdbc2 if the java.lang.Byte class is
@ -29,6 +40,7 @@
<available property="jdk1.2+" classname="java.lang.ThreadLocal" />
<available property="jdk1.3+" classname="java.lang.StrictMath" />
<available property="jdk1.2e+" classname="javax.sql.DataSource" />
<available property="junit" classname="junit.framework.Test" />
</target>
<!--
@ -47,6 +59,10 @@
<property name="connectclass" value="org.postgresql.jdbc1.Connection" />
<available property="connectclass" value="org.postgresql.jdbc2.Connection" classname="java.lang.ThreadLocal" />
<!-- comment out 1.3+ stuff -->
<property name="jdk13only" value="//" />
<available property="jdk13only" value="" classname="java.lang.StrictMath" />
<!-- Some defaults -->
<filter token="MAJORVERSION" value="${major}" />
<filter token="MINORVERSION" value="${minor}" />
@ -86,6 +102,7 @@
<exclude name="${package}/largeobject/PGblob.java" unless="jdk1.2+" />
<exclude name="${package}/PostgresqlDataSource.java" unless="jdk1.2e+" />
<exclude name="${package}/xa/**" unless="jdk1.2e+" />
<exclude name="${package}/test/**" unless="junit" />
</javac>
<copy todir="${dest}" overwrite="true" filtering="on">
<fileset dir="${src}">
@ -115,7 +132,7 @@
<!-- This builds the jar file containing the driver -->
<target name="jar" depends="compile,examples">
<jar jarfile="${jars}/postgresql.jar" basedir="${dest}" includes="org/**" />
<jar jarfile="${jars}/postgresql.jar" basedir="${dest}" includes="${package}/**" excludes="${package}/test/**"/>
<jar jarfile="${jars}/postgresql-examples.jar" basedir="${dest}" includes="example/**" />
</target>
@ -132,4 +149,23 @@
</copy>
</target>
</project>
<!--
This compiles and executes the JUnit tests
-->
<target name="test" depends="jar" if="junit">
<javac srcdir="${src}" destdir="${dest}">
<include name="${package}/test/jdbc2/**" if="jdk1.2+" />
<include name="${package}/test/java2ee/**" if="jdk1.2e+" />
</javac>
<java fork="yes" classname="junit.${junit.ui}.TestRunner" taskname="junit" failonerror="true">
<arg value="org.postgresql.test.JDBC2Tests" />
<sysproperty key="database" value="${database}" />
<sysproperty key="username" value="${username}" />
<sysproperty key="password" value="${password}" />
<classpath>
<pathelement location="${dest}" />
<pathelement path="${java.class.path}" />
</classpath>
</java>
</target>
</project>

View File

@ -9,13 +9,13 @@
<property category="sys" name="CheckStable" value="1" />
<property category="sys" name="Company" value="" />
<property category="sys" name="Copyright" value="Copyright (c) 2001" />
<property category="sys" name="DefaultPackage" value="org.postgresql" />
<property category="sys" name="DefaultPackage" value="org.postgresql.test.jdbc2" />
<property category="sys" name="Description" value="" />
<property category="sys" name="DocPath" value="doc" />
<property category="sys" name="ExcludeClassEnabled" value="0" />
<property category="sys" name="JDK" value="java 1.3.0-C" />
<property category="sys" name="LastTag" value="0" />
<property category="sys" name="Libraries" value="" />
<property category="sys" name="Libraries" value="JUnit" />
<property category="sys" name="MakeStable" value="0" />
<property category="sys" name="OutPath" value="build" />
<property category="sys" name="SourcePath" value="." />

View File

@ -353,6 +353,7 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu
if (s != null)
{
try
{
val = new BigDecimal(s);

View 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;
}
}

View 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(""));
}
}

View File

@ -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);
}
}
}

View File

@ -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);
}
}
}