Some updates prior to retrieving a fresh cvs copy:
authorPeter Mount
Wed, 7 Feb 2001 09:13:20 +0000 (09:13 +0000)
committerPeter Mount
Wed, 7 Feb 2001 09:13:20 +0000 (09:13 +0000)
Tue Feb 06 19:00:00 GMT 2001 [email protected]
        - Completed first two TestCase's for the test suite. JUnit is now
          recognised by ant.

src/interfaces/jdbc/CHANGELOG
src/interfaces/jdbc/build.xml
src/interfaces/jdbc/jdbc.jpx
src/interfaces/jdbc/org/postgresql/jdbc2/ResultSet.java
src/interfaces/jdbc/org/postgresql/test/JDBC2Tests.java [new file with mode: 0644]
src/interfaces/jdbc/org/postgresql/test/jdbc2/ANTTest.java [new file with mode: 0644]
src/interfaces/jdbc/org/postgresql/test/jdbc2/ConnectionTest.java [new file with mode: 0644]
src/interfaces/jdbc/org/postgresql/test/jdbc2/DriverTest.java [new file with mode: 0644]

index bbf3952f1a646ebb9333230ec89065086e2d0725..1da628411975fe4da7571f1e6cd744b5cb1965ea 100644 (file)
@@ -1,3 +1,7 @@
+Tue Feb 06 19:00:00 GMT 2001 [email protected]
+        - Completed first two TestCase's for the test suite. JUnit is now
+          recognised by ant.
+
 Wed Jan 31 08:46:00 GMT 2001 [email protected]
         - Some minor additions to Statement to make our own extensions more
           portable.
index 2a923495bae32c7bf5cddf4d11bc7a2cdd076865..e95c646f5d27c701fe8a9c863fb1368bd3fe6a46 100644 (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 $
 
 -->
 
   
   
 
+  
+  
+  
+  
+  
+
   
+    
+    
+
     
     
     
       
       
       
+      
     
     
       
 
   
   
-    org/**" />
+    ${package}/**" excludes="${package}/test/**"/>
     
   
 
     
   
 
-
\ No newline at end of file
+  
+  
+    
+      
+      
+    
+    
+      
+      
+      
+      
+      
+        
+        
+      
+    
+  
+
index 19fb6df5344dc69a92e33584777a26cd8e280230..2fff9537a6a41c0ed5aae2cd53ad5e179ba4ff26 100644 (file)
@@ -9,13 +9,13 @@
   \r
   \r
   \r
-  \r
+  .test.jdbc2" />\r
   \r
   \r
   \r
   \r
   \r
-  \r
+  JUnit" />\r
   \r
   \r
   \r
index 14fe603b69bfc6cddb96543f702883b6886ca0ba..d88d3190b16bb860c349a467c56c27d9e2023fa2 100644 (file)
@@ -353,6 +353,7 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu
 
     if (s != null)
       {
+
    try
      {
        val = new BigDecimal(s);
diff --git a/src/interfaces/jdbc/org/postgresql/test/JDBC2Tests.java b/src/interfaces/jdbc/org/postgresql/test/JDBC2Tests.java
new file mode 100644 (file)
index 0000000..c4ff4b2
--- /dev/null
@@ -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;
+  }
+}
\ No newline at end of file
diff --git a/src/interfaces/jdbc/org/postgresql/test/jdbc2/ANTTest.java b/src/interfaces/jdbc/org/postgresql/test/jdbc2/ANTTest.java
new file mode 100644 (file)
index 0000000..349c5bc
--- /dev/null
@@ -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(""));
+  }
+}
diff --git a/src/interfaces/jdbc/org/postgresql/test/jdbc2/ConnectionTest.java b/src/interfaces/jdbc/org/postgresql/test/jdbc2/ConnectionTest.java
new file mode 100644 (file)
index 0000000..6f268d3
--- /dev/null
@@ -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);
+    }
+  }
+
+}
\ No newline at end of file
diff --git a/src/interfaces/jdbc/org/postgresql/test/jdbc2/DriverTest.java b/src/interfaces/jdbc/org/postgresql/test/jdbc2/DriverTest.java
new file mode 100644 (file)
index 0000000..7337be4
--- /dev/null
@@ -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);
+    }
+  }
+}
\ No newline at end of file