summaryrefslogtreecommitdiff
path: root/src/interfaces/jdbc/org/postgresql/test/JDBC2Tests.java
blob: c4ff4b29f67d1e4a5c7cd3508d935013926ee668 (plain)
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
87
88
89
90
91
92
93
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;
  }
}