db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
Subject svn commit: r541044 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting: functionTests/tests/derbynet/ functionTests/tests/upgradeTests/ junit/
Date Wed, 23 May 2007 19:42:20 GMT
Author: djd
Date: Wed May 23 12:42:19 2007
New Revision: 541044

URL: http://svn.apache.org/viewvc?view=rev&rev=541044
Log:
DERBY-2000 Add a BaseTestSetup class that installs the security manager so
that it is in place during the decorator's methods. Changed the various
Derby decorators to extend this new class.

Added:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseTestSetup.java   (with
props)
Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/SecureServerTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/PhaseChanger.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseJDBCTestSetup.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/Decorator.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/DropDatabaseSetup.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/NetworkServerTestSetup.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/SecurityManagerSetup.java

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/SecureServerTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/SecureServerTest.java?view=diff&rev=541044&r1=541043&r2=541044
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/SecureServerTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/SecureServerTest.java
Wed May 23 12:42:19 2007
@@ -214,7 +214,8 @@
         String[]        startupProperties = getStartupProperties( authenticationRequired,
useCustomDerbyProperties );
         String[]        startupArgs = getStartupArgs( unsecureSet );
 
-        TestSetup   testSetup = new NetworkServerTestSetup
+        Test  testSetup = SecurityManagerSetup.noSecurityManager(
+                new NetworkServerTestSetup
             (
              secureServerTest,
              startupProperties,
@@ -222,7 +223,7 @@
              true,
              secureServerTest._outcome.serverShouldComeUp(),
              secureServerTest._inputStreamHolder
-             );
+             ));
 
         // if using the custom derby.properties, copy the custom properties to a visible
place
         if ( useCustomDerbyProperties )
@@ -238,8 +239,6 @@
         }
 
         Test        test = TestConfiguration.defaultServerDecorator( testSetup );
-
-        test = SecurityManagerSetup.noSecurityManager( test );
 
         return test;
     }

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/PhaseChanger.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/PhaseChanger.java?view=diff&rev=541044&r1=541043&r2=541044
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/PhaseChanger.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/PhaseChanger.java
Wed May 23 12:42:19 2007
@@ -28,6 +28,7 @@
 import junit.extensions.TestSetup;
 import junit.framework.Test;
 
+import org.apache.derbyTesting.junit.BaseTestSetup;
 import org.apache.derbyTesting.junit.JDBCDataSource;
 import org.apache.derbyTesting.junit.TestConfiguration;
 
@@ -35,7 +36,7 @@
  * Decorator that sets the phase of the upgrade process
  * for a suite of upgrade tests.
  */
-final class PhaseChanger extends TestSetup {
+final class PhaseChanger extends BaseTestSetup {
 
     private final int phase;
     private final int[] version;

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseJDBCTestSetup.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseJDBCTestSetup.java?view=diff&rev=541044&r1=541043&r2=541044
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseJDBCTestSetup.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseJDBCTestSetup.java
Wed May 23 12:42:19 2007
@@ -29,7 +29,7 @@
  * Base class for JDBC JUnit test decorators.
  */
 public abstract class BaseJDBCTestSetup
-    extends TestSetup {
+    extends BaseTestSetup {
 	
 	public BaseJDBCTestSetup(Test test) {
 		super(test);

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseTestSetup.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseTestSetup.java?view=auto&rev=541044
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseTestSetup.java (added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseTestSetup.java Wed
May 23 12:42:19 2007
@@ -0,0 +1,61 @@
+/*
+ *
+ * Derby - Class BaseTestSetup
+ *
+ * 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 junit.extensions.TestSetup;
+import junit.framework.Test;
+import junit.framework.TestResult;
+
+/**
+ * TestSetup/Decorator base class for Derby's JUnit
+ * tests. Installs the security manager according
+ * to the configuration before executing any setup
+ * or tests. Matches the security manager setup
+ * provided by BaseTestCase.
+ *
+ */
+public abstract class BaseTestSetup extends TestSetup {
+    
+    protected BaseTestSetup(Test test) {
+        super(test);
+    }
+
+    /**
+     * Setup the security manager for this Derby decorator/TestSetup
+     * and then call the part's run method to run the decorator and
+     * the test it wraps.
+     */
+    public final void run(TestResult result)
+    {
+        // install a default security manager if one has not already been
+        // installed
+        if ( System.getSecurityManager() == null )
+        {
+            if (TestConfiguration.getCurrent().defaultSecurityManagerSetup())
+            {
+                BaseTestCase.assertSecurityManager();
+            }
+        }
+        
+        super.run(result);
+    }
+
+
+}

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

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/Decorator.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/Decorator.java?view=diff&rev=541044&r1=541043&r2=541044
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/Decorator.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/Decorator.java Wed May
23 12:42:19 2007
@@ -61,7 +61,7 @@
      */
     public static Test encryptedDatabase(Test test)
     {
-        test = new TestSetup(test) {
+        test = new BaseTestSetup(test) {
             
             /**
              * Create an encrypted database using a
@@ -69,8 +69,6 @@
              */
             protected void setUp() throws SQLException
             {
-                String bootPhrase = getBootPhrase(16);
-
                 DataSource ds = JDBCDataSource.getDataSource();
                                
                 JDBCDataSource.setBeanProperty(ds,
@@ -108,7 +106,7 @@
      */
     public static Test encryptedDatabase(Test test, final String algorithm)
     {
-        test = new TestSetup(test) {
+        test = new BaseTestSetup(test) {
             
             /**
              * Create an encrypted database using a

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=541044&r1=541043&r2=541044
==============================================================================
--- 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
Wed May 23 12:42:19 2007
@@ -35,7 +35,7 @@
  * name passed in when creating this decorator.
  *
  */
-class DropDatabaseSetup extends TestSetup {
+class DropDatabaseSetup extends BaseTestSetup {
 
     final String logicalDBName;
     DropDatabaseSetup(Test test, String logicalDBName) {

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/NetworkServerTestSetup.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/NetworkServerTestSetup.java?view=diff&rev=541044&r1=541043&r2=541044
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/NetworkServerTestSetup.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/NetworkServerTestSetup.java
Wed May 23 12:42:19 2007
@@ -41,7 +41,7 @@
  * and it does not support starting it from a remote 
  * machine.
  */
-final public class NetworkServerTestSetup extends TestSetup {
+final public class NetworkServerTestSetup extends BaseTestSetup {
 
     /** Setting maximum wait time to 300 seconds.   For some systems it looks
      *  like restarting a server to listen on the same port is blocked waiting

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/SecurityManagerSetup.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/SecurityManagerSetup.java?view=diff&rev=541044&r1=541043&r2=541044
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/SecurityManagerSetup.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/SecurityManagerSetup.java
Wed May 23 12:42:19 2007
@@ -22,6 +22,7 @@
 import java.io.File;
 import java.net.URL;
 import java.security.AccessController;
+import java.security.Policy;
 import java.security.PrivilegedActionException;
 import java.util.Enumeration;
 import java.util.Properties;
@@ -75,6 +76,10 @@
 	 * mode of no security manager as it may not have enough information
 	 * to re-install the security manager. So the passed in test
 	 * will be skipped.
+     * 
+     * @param test Test to run without a security manager. Note that
+     * this must be an instance of BaseTestCase as this call depends
+     * on setup code in that class. Arbitrary Test instances cannot be passed in.
 	 */
 	public static Test noSecurityManager(Test test)
 	{
@@ -83,18 +88,6 @@
                     + test.toString());
 		return new SecurityManagerSetup(test, "<NONE>");
 	}
-	
-    /**
-     * Same as noSecurityManager() above but takes a TestSetup
-     * instead of a BaseTestCase.
-     */
-    public static Test noSecurityManager(TestSetup tSetup)
-    {
-		if (externalSecurityManagerInstalled)
-			return new TestSuite("skipped due to external security manager "
-                    + tSetup.toString());
-		return new SecurityManagerSetup(tSetup, "<NONE>");
-    }
 
 	/**
 	 * "Install" no security manager.
@@ -183,8 +176,9 @@
 
 
                 public Object run() {
-				System.setSecurityManager(new SecurityManager());
-				return null;
+                    SecurityManager sm = new SecurityManager();
+				System.setSecurityManager(sm);
+ 				return null;
 			}
 		});
 
@@ -206,9 +200,10 @@
 			catch (Exception e) { System.out.println( "Unreadable url: " + policyResource ); }
 		}
 
-		if (policyURL != null)
+		if (policyURL != null) {
 			set.setProperty("java.security.policy",
 					policyURL.toExternalForm());
+        }
 	}
 
 	
@@ -376,7 +371,7 @@
              new java.security.PrivilegedAction()
              {
                  public Object run() {
-                     System.setSecurityManager(null);
+                      System.setSecurityManager(null);
                      return null;
                  }
              }



Mime
View raw message