db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
Subject svn commit: r471089 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting: functionTests/tests/lang/ junit/
Date Sat, 04 Nov 2006 01:08:35 GMT
Author: djd
Date: Fri Nov  3 17:08:34 2006
New Revision: 471089

URL: http://svn.apache.org/viewvc?view=rev&rev=471089
Log:
DERBY-2043 (partial) Cleanup some of the connection methods in TestConfiguration to allow
easier
transition of the DataSource code into the junit package. Add a utility shutdownDatabase()
method
to TestConfiguration rather than using a getConnection with shutdown=true and duplicated code
for catching the exception and asserting its SQL state.

Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/DatabaseClassLoadingTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/SQLAuthorizationPropTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseJDBCTestCase.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/DatabasePropertyTestSetup.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/DropDatabaseSetup.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/TestConfiguration.java

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/DatabaseClassLoadingTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/DatabaseClassLoadingTest.java?view=diff&rev=471089&r1=471088&r2=471089
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/DatabaseClassLoadingTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/DatabaseClassLoadingTest.java
Fri Nov  3 17:08:34 2006
@@ -47,8 +47,12 @@
                 SecurityManagerSetup.noSecurityManager(
                         new DatabaseClassLoadingTest("testSetClasspath")));
         
-        suite.addTest(SecurityManagerSetup.noSecurityManager(
+        // Need DriverManager to execute the add contact procedure
+        // as it uses server side jdbc.
+        if (JDBC.vmSupportsJDBC3()) {
+           suite.addTest(SecurityManagerSetup.noSecurityManager(
                 new DatabaseClassLoadingTest("testAddContact")));
+        }
         
         suite.addTest(SecurityManagerSetup.noSecurityManager(
                 new DatabaseClassLoadingTest("testGetResource")));        
@@ -220,12 +224,6 @@
         // setting the change does see it!
         // 
         getConnection().close();
-        try {
-            TestConfiguration.getCurrent().getDefaultConnection(
-                    "shutdown=true");
-            fail("Database failed to shut down");
-        } catch (SQLException e) {
-            assertSQLState("Database shutdown", "08006", e);
-        }  
+        getTestConfiguration().shutdownDatabase(); 
     }
 }

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/SQLAuthorizationPropTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/SQLAuthorizationPropTest.java?view=diff&rev=471089&r1=471088&r2=471089
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/SQLAuthorizationPropTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/SQLAuthorizationPropTest.java
Fri Nov  3 17:08:34 2006
@@ -47,11 +47,12 @@
                 "SQLAuthorizationPropTest");
 		
 		// Use DatabasePropertyTestSetup decorator to set the property
-		// required by this test. 
+		// required by this test (and shutdown the database for the
+        // property to take effect.
 		Properties props = new Properties();
 	    props.setProperty("derby.database.sqlAuthorization", "true");
 	    Test test = new SQLAuthorizationPropTest("grantRevokeAfterSettingSQLAuthProperty");
-	    suite.addTest(new DatabasePropertyTestSetup (test, props));
+	    suite.addTest(new DatabasePropertyTestSetup (test, props, true));
 	    
 	    // This test has to be run after SQL authorization property has been 
 	    // set to true. 
@@ -116,14 +117,6 @@
 	 * @throws SQLException
 	 */
 	public void grantRevokeAfterSettingSQLAuthProperty() throws SQLException{
-		// Shutdown the database for derby.database.sqlAuthorization property 
-		// to take effect. This was set by DatabasePropertyTestSetup decorator.
-		try{ 
-			getDefaultConnection("shutdown=true");
-			fail("FAIL: Failed to shutdown database");
-		} catch (SQLException sqle) {
-			assertSQLState(SQLStateConstants.SHUTDOWN_DATABASE, sqle);
-		}
 		
 		Statement stmt = createStatement();
 		stmt.execute("grant select on GR_TAB to some_user");

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseJDBCTestCase.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseJDBCTestCase.java?view=diff&rev=471089&r1=471088&r2=471089
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseJDBCTestCase.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseJDBCTestCase.java Fri
Nov  3 17:08:34 2006
@@ -200,22 +200,6 @@
         initializeConnection(conn);
         return conn;        
     }
-    
-    /**
-     * Get a connection to the default database using the  specified connection
-     * attributes.
-     *  
-     * @param connAttrs connection attributes
-     * @return connection to default database.
-     * @throws SQLException
-     */
-    public Connection getDefaultConnection(String connAttrs)
-    	throws SQLException {
-    	Connection conn =  getTestConfiguration().
-								getDefaultConnection(connAttrs);
-    	initializeConnection(conn);
-    	return conn;
-    }
 
     /**
      * Get a connection to a database using the specified connection 

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/DatabasePropertyTestSetup.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/DatabasePropertyTestSetup.java?view=diff&rev=471089&r1=471088&r2=471089
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/DatabasePropertyTestSetup.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/DatabasePropertyTestSetup.java
Fri Nov  3 17:08:34 2006
@@ -164,13 +164,7 @@
     {
     	setProperties(newValues);
         if (staticProperties) {
-            try {
-                TestConfiguration.getCurrent().getDefaultConnection(
-                        "shutdown=true");
-                fail("Database failed to shut down");
-            } catch (SQLException e) {
-                 BaseJDBCTestCase.assertSQLState("Database shutdown", "08006", e);
-            }
+            TestConfiguration.getCurrent().shutdownDatabase();
         }
     }
 
@@ -207,13 +201,7 @@
         newValues = null;
         oldValues = null;
         if (staticProperties) {
-            try {
-                TestConfiguration.getCurrent().getDefaultConnection(
-                        "shutdown=true");
-                fail("Database failed to shut down");
-            } catch (SQLException e) {
-                BaseJDBCTestCase.assertSQLState("Database shutdown", "08006", e);
-            }
+            TestConfiguration.getCurrent().shutdownDatabase();
         }
     }
     

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/DropDatabaseSetup.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/DropDatabaseSetup.java?view=diff&rev=471089&r1=471088&r2=471089
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/DropDatabaseSetup.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/DropDatabaseSetup.java
Fri Nov  3 17:08:34 2006
@@ -42,13 +42,7 @@
     protected void tearDown() throws Exception {  
         super.tearDown();
         
-        try {
-            TestConfiguration.getCurrent().getDefaultConnection(
-                    "shutdown=true");
-            fail("Database failed to shut down");
-        } catch (SQLException e) {
-            BaseJDBCTestCase.assertSQLState("Database shutdown", "08006", e);
-        }
+        TestConfiguration.getCurrent().shutdownDatabase();
 
         String dbName = TestConfiguration.getCurrent().getDatabaseName();
         dbName = dbName.replace('/', File.separatorChar);

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/TestConfiguration.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/TestConfiguration.java?view=diff&rev=471089&r1=471088&r2=471089
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/TestConfiguration.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/TestConfiguration.java
Fri Nov  3 17:08:34 2006
@@ -27,6 +27,7 @@
 import java.sql.SQLException;
 import java.util.Properties;
 
+import junit.framework.Assert;
 import junit.framework.Test;
 import junit.framework.TestCase;
 import junit.framework.TestSuite;
@@ -561,7 +562,7 @@
      *
      * @return connection to default database.
      */
-    public Connection openDefaultConnection()
+    Connection openDefaultConnection()
         throws SQLException {
         return getDefaultConnection("create=true");
     }
@@ -575,7 +576,7 @@
      *
      * @return connection to database.
      */
-    public Connection openConnection (String databaseName) throws SQLException {
+    Connection openConnection (String databaseName) throws SQLException {
         return getConnection(databaseName, "create=true");
     }
     
@@ -626,6 +627,21 @@
             con = TestDataSourceFactory.getDataSource(attrs).getConnection();
         }
         return con;
+    }
+    
+    /**
+     * Shutdown the database for this configuration
+     * assuming it is booted.
+     *
+     */
+    public void shutdownDatabase()
+    {
+        try {
+            getDefaultConnection("shutdown=true");
+            Assert.fail("Database failed to shut down");
+        } catch (SQLException e) {
+             BaseJDBCTestCase.assertSQLState("Database shutdown", "08006", e);
+        }
     }
     
     /**



Mime
View raw message