db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
Subject svn commit: r474552 - /db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/JDBCDataSource.java
Date Mon, 13 Nov 2006 22:57:50 GMT
Author: djd
Date: Mon Nov 13 14:57:49 2006
New Revision: 474552

URL: http://svn.apache.org/viewvc?view=rev&rev=474552
Log:
Add utility methods for JUnit tests to get a DataSource based upon the current configuration
but pointing to a different database and to shutdown a database from a data source.

Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/JDBCDataSource.java

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/JDBCDataSource.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/JDBCDataSource.java?view=diff&rev=474552&r1=474551&r2=474552
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/JDBCDataSource.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/JDBCDataSource.java Mon
Nov 13 14:57:49 2006
@@ -20,6 +20,7 @@
 package org.apache.derbyTesting.junit;
 
 import java.lang.reflect.Method;
+import java.sql.SQLException;
 import java.util.HashMap;
 import java.util.Iterator;
 
@@ -42,6 +43,21 @@
     }
     
     /**
+     * Return a DataSource corresponding to the current
+     * configuration except that the databse name is different.
+     */
+    public static javax.sql.DataSource getDataSource(String dbName)
+    {
+        // default DataSource
+        javax.sql.DataSource ds = getDataSource();
+        
+        // Override the database name
+        setBeanProperty(ds, "databaseName", dbName);
+        
+        return ds;
+    }
+    
+    /**
      * Create a new DataSource object setup from the passed in TestConfiguration.
      * The getConnection() method will return a connection identical to
      * TestConfiguration.openDefaultConnection().
@@ -137,5 +153,22 @@
     private static String getSetterName(String attribute) {
         return "set" + Character.toUpperCase(attribute.charAt(0))
                 + attribute.substring(1);
+    }
+    
+    /**
+     * Shutdown the database described by this data source.
+     * The shutdownDatabase property is cleared by this method.
+     */
+    public static void shutdownDatabase(javax.sql.DataSource ds)
+    {
+        setBeanProperty(ds, "shutdownDatabase", "shutdown");
+        try {
+            ds.getConnection();
+            Assert.fail("Database failed to shut down");
+        } catch (SQLException e) {
+             BaseJDBCTestCase.assertSQLState("Database shutdown", "08006", e);
+        } finally {
+            setBeanProperty(ds, "shutdownDatabase", "");
+        }
     }
 }



Mime
View raw message