User: mulder  
  Date: 00/06/04 20:18:44

  Added:       src/main/test/jboss/testdb TestConnection.java
                        TestDBDriver.java
  Log:
  Update test suite to dynamically read list of tests from test classes,
  assuming they use method names like testSomething.
  
  Add phony database driver for testing.
  
  Add starter tests for JDBCConnectionFactory (not yet complete).
  
  Revision  Changes    Path
  1.1                  jboss/src/main/test/jboss/testdb/TestConnection.java
  
  Index: TestConnection.java
  ===================================================================
  /*
   * jBoss, the OpenSource EJB server
   *
   * Distributable under GPL license.
   * See terms of license at gnu.org.
   */
  package test.jboss.testdb;
  
  import java.sql.*;
  import java.util.Map;
  
  /**
   * Database connection for unit tests.  Currently nothing is implemented except
   * close, isClosed, isAutoCommit, setAutoCommit(true), and rollback.  Everything
   * else throws a SQLException.
   * @version $Revision: 1.1 $
   * @author Aaron Mulder ([EMAIL PROTECTED])
   */
  public class TestConnection implements Connection {
      private final static String TEST_DB = "Not implemented in test database.";
      private boolean closed = false;
  
      public TestConnection() {
      }
  
      public void clearWarnings() throws java.sql.SQLException {
          throw new SQLException(TEST_DB);
      }
  
      public void close() throws java.sql.SQLException {
          closed = true;
      }
  
      public void commit() throws java.sql.SQLException {
          throw new SQLException(TEST_DB);
      }
  
      public Statement createStatement() throws java.sql.SQLException {
          throw new SQLException(TEST_DB);
      }
  
      public Statement createStatement(int parm1, int parm2) throws 
java.sql.SQLException {
          throw new SQLException(TEST_DB);
      }
  
      public boolean getAutoCommit() throws java.sql.SQLException {
          return true;
      }
  
      public String getCatalog() throws java.sql.SQLException {
          throw new SQLException(TEST_DB);
      }
  
      public DatabaseMetaData getMetaData() throws java.sql.SQLException {
          throw new SQLException(TEST_DB);
      }
  
      public int getTransactionIsolation() throws java.sql.SQLException {
          throw new SQLException(TEST_DB);
      }
  
      public Map getTypeMap() throws java.sql.SQLException {
          throw new SQLException(TEST_DB);
      }
  
      public SQLWarning getWarnings() throws java.sql.SQLException {
          throw new SQLException(TEST_DB);
      }
  
      public boolean isClosed() throws java.sql.SQLException {
          return closed;
      }
  
      public boolean isReadOnly() throws java.sql.SQLException {
          throw new SQLException(TEST_DB);
      }
  
      public String nativeSQL(String parm1) throws java.sql.SQLException {
          throw new SQLException(TEST_DB);
      }
  
      public CallableStatement prepareCall(String parm1) throws java.sql.SQLException {
          throw new SQLException(TEST_DB);
      }
  
      public CallableStatement prepareCall(String parm1, int parm2, int parm3) throws 
java.sql.SQLException {
          throw new SQLException(TEST_DB);
      }
  
      public PreparedStatement prepareStatement(String parm1) throws 
java.sql.SQLException {
          throw new SQLException(TEST_DB);
      }
  
      public PreparedStatement prepareStatement(String parm1, int parm2, int parm3) 
throws java.sql.SQLException {
          throw new SQLException(TEST_DB);
      }
  
      public void rollback() throws java.sql.SQLException {
      }
  
      public void setAutoCommit(boolean ac) throws java.sql.SQLException {
          if(!ac)
              throw new SQLException(TEST_DB);
      }
  
      public void setCatalog(String parm1) throws java.sql.SQLException {
          throw new SQLException(TEST_DB);
      }
  
      public void setReadOnly(boolean parm1) throws java.sql.SQLException {
          throw new SQLException(TEST_DB);
      }
  
      public void setTransactionIsolation(int parm1) throws java.sql.SQLException {
          throw new SQLException(TEST_DB);
      }
  
      public void setTypeMap(Map parm1) throws java.sql.SQLException {
          throw new SQLException(TEST_DB);
      }
  }
  
  
  1.1                  jboss/src/main/test/jboss/testdb/TestDBDriver.java
  
  Index: TestDBDriver.java
  ===================================================================
  /*
   * jBoss, the OpenSource EJB server
   *
   * Distributable under GPL license.
   * See terms of license at gnu.org.
   */
  package test.jboss.testdb;
  
  import java.sql.*;
  import java.util.Properties;
  
  /**
   * Database driver for unit tests.  Creates connections that implement virtually
   * nothing - enough to test with, in other words.
   * @version $Revision: 1.1 $
   * @author Aaron Mulder ([EMAIL PROTECTED])
   */
  public class TestDBDriver implements Driver {
      private final static String URL_START = "jdbc:testdb:";
      private final static TestDBDriver instance;
      static {
          instance = new TestDBDriver();
          try {
              DriverManager.registerDriver(TestDBDriver.instance());
          } catch(SQLException e) {
              System.out.println("Unable to register Test DB pool driver!");
              e.printStackTrace();
          }
      }
      public static TestDBDriver instance() {
          return instance;
      }
  
      public TestDBDriver() {
      }
  
      public boolean acceptsURL(String url) throws java.sql.SQLException {
          return url.startsWith(URL_START);
      }
  
      public Connection connect(String url, Properties props) throws 
java.sql.SQLException {
          if(!url.startsWith(URL_START)) throw new SQLException("Wrong URL!");
          return new TestConnection();
      }
  
      public int getMajorVersion() {
          return 1;
      }
  
      public int getMinorVersion() {
          return 0;
      }
  
      public DriverPropertyInfo[] getPropertyInfo(String parm1, Properties parm2) 
throws java.sql.SQLException {
          return new DriverPropertyInfo[0];
      }
  
      public boolean jdbcCompliant() {
          return false;
      }
  }
  
  

Reply via email to