db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
Subject svn commit: r469594 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting: functionTests/tests/lang/SQLAuthorizationPropTest.java junit/DropDatabaseSetup.java junit/TestConfiguration.java
Date Tue, 31 Oct 2006 18:21:43 GMT
Author: djd
Date: Tue Oct 31 10:21:42 2006
New Revision: 469594

URL: http://svn.apache.org/viewvc?view=rev&rev=469594
Log:
DERBY-1975 (partial) Add some incremental work to support a single use database for a test.

Added:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/DropDatabaseSetup.java
  (with props)
Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/SQLAuthorizationPropTest.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/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=469594&r1=469593&r2=469594
==============================================================================
--- 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
Tue Oct 31 10:21:42 2006
@@ -33,6 +33,7 @@
 
 import org.apache.derbyTesting.junit.BaseJDBCTestCase;
 import org.apache.derbyTesting.junit.DatabasePropertyTestSetup;
+import org.apache.derbyTesting.junit.TestConfiguration;
 import org.apache.derbyTesting.functionTests.util.SQLStateConstants;
 
 public class SQLAuthorizationPropTest extends BaseJDBCTestCase {
@@ -42,8 +43,8 @@
 	}
 
 	public static Test suite() {
-		TestSuite suite = new TestSuite();
-		suite.addTestSuite(SQLAuthorizationPropTest.class);
+		TestSuite suite = new TestSuite(SQLAuthorizationPropTest.class,
+                "SQLAuthorizationPropTest");
 		
 		// Use DatabasePropertyTestSetup decorator to set the property
 		// required by this test. 
@@ -56,7 +57,10 @@
 	    // set to true. 
 	    suite.addTest(new SQLAuthorizationPropTest("resetSQLAuthProperty"));
 	    
-	    return suite;
+        // This test needs to run in a new single use database as upon entry
+        // the test expects SQL authorization to be off and then sets it
+        // which cannot be undone.
+	    return TestConfiguration.singleUseDatabaseDecorator(suite);
 	}
 	
     /**
@@ -148,6 +152,8 @@
         testPropertyReset(setDBP, "some_value");
         // This should work
         testPropertyReset(setDBP, "true");
+        
+        setDBP.close();
 	}
 	
 	/**
@@ -159,7 +165,7 @@
 	 * @param value value of database property
 	 * @throws SQLException
 	 */
-	public void testPropertyReset(CallableStatement cs, String value) throws SQLException {
+	private void testPropertyReset(CallableStatement cs, String value) throws SQLException {
 
 		cs.setString(2, value);
         

Added: 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=auto&rev=469594
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/DropDatabaseSetup.java
(added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/DropDatabaseSetup.java
Tue Oct 31 10:21:42 2006
@@ -0,0 +1,54 @@
+/*
+ *
+ * Derby - Class org.apache.derbyTesting.unit.DropDatabaseSetup
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, 
+ * software distributed under the License is distributed on an 
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 
+ * either express or implied. See the License for the specific 
+ * language governing permissions and limitations under the License.
+ */
+package org.apache.derbyTesting.junit;
+
+import java.io.File;
+import java.security.AccessController;
+import java.sql.SQLException;
+
+import junit.extensions.TestSetup;
+import junit.framework.Test;
+
+/**
+ * Shutdown and drop the current database at tearDown time.
+ * Work in progress - currently just shuts the database down.
+ *
+ */
+class DropDatabaseSetup extends TestSetup {
+
+    DropDatabaseSetup(Test test) {
+        super(test);
+     }
+    
+    /**
+     * Drop the current database.
+     */
+    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);
+        }
+    } 
+}

Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/DropDatabaseSetup.java
------------------------------------------------------------------------------
    svn:eol-style = native

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=469594&r1=469593&r2=469594
==============================================================================
--- 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
Tue Oct 31 10:21:42 2006
@@ -245,6 +245,26 @@
 
     }
     
+    /**
+     * Decorate a test to use a new database that is created upon the
+     * first connection request to the database and shutdown & deleted at
+     * tearDown. The configuration differs only from the current configuration
+     * by the database name.
+     * @param test Test to be decorated
+     * @return decorated test.
+     */
+    public static Test singleUseDatabaseDecorator(Test test)
+    {
+        TestConfiguration config = TestConfiguration.getCurrent();
+
+        // WORK IN PROGRESS - need to have unique name.
+        String dbName = "singleUse/wombat2";        
+        TestConfiguration newDBconfig = 
+            new TestConfiguration(config, dbName);
+        return new ChangeConfigurationSetup(newDBconfig,
+                new DropDatabaseSetup(test));
+    }
+    
     public static Test changeUserDecorator(Test test, String user, String password)
     {
         return new ChangeUserSetup(test, user, password);
@@ -306,7 +326,28 @@
         
         this.url = copy.url;
     }
+    /**
+     * Obtain a new configuration identical to the passed in
+     * one except for the database name.
+     * @param copy Configuration to copy.
+     * @param dbName New database name
+      */
+    TestConfiguration(TestConfiguration copy, String dbName)
+    {
+        this.dbName = dbName;
+        this.userName = copy.userName;
+        this.userPassword = copy.userPassword;
 
+        this.isVerbose = copy.isVerbose;
+        this.singleLegXA = copy.singleLegXA;
+        this.port = copy.port;
+        
+        this.jdbcClient = copy.jdbcClient;
+        this.hostName = copy.hostName;
+        
+        this.url = createJDBCUrlWithDatabaseName(dbName);
+    }
+    
     /**
      * This constructor creates a TestConfiguration from a Properties object.
      *



Mime
View raw message