You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by dj...@apache.org on 2007/01/05 21:31:14 UTC

svn commit: r493180 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit: ChangeConfigurationSetup.java ChangeUserSetup.java ConnectorSetup.java DatabaseChangeSetup.java ServerSetup.java TestConfiguration.java

Author: djd
Date: Fri Jan  5 12:31:13 2007
New Revision: 493180

URL: http://svn.apache.org/viewvc?view=rev&rev=493180
Log:
DERBY-2215 Change ChangeConfigurationSetup to be an abstract class that allows
subclasses to generate the new TestConfiguration operation at setUp time.
Create three sub-classes to handle changing the database name, changing the
connection handling and switching to a client server configuration.
This ensures that nested changing of configurations works correctly
by creating new configurations based upon the current at the time of setUp.

Added:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/ConnectorSetup.java   (with props)
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/DatabaseChangeSetup.java   (with props)
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/ServerSetup.java   (with props)
Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/ChangeConfigurationSetup.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/ChangeUserSetup.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/TestConfiguration.java

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/ChangeConfigurationSetup.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/ChangeConfigurationSetup.java?view=diff&rev=493180&r1=493179&r2=493180
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/ChangeConfigurationSetup.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/ChangeConfigurationSetup.java Fri Jan  5 12:31:13 2007
@@ -22,25 +22,31 @@
 import junit.extensions.TestSetup;
 import junit.framework.Test;
 
-final class ChangeConfigurationSetup extends TestSetup {
+abstract class ChangeConfigurationSetup extends TestSetup {
     
-    private final TestConfiguration config;
     private TestConfiguration old;
     
-    ChangeConfigurationSetup(TestConfiguration config, Test test)
+    ChangeConfigurationSetup(Test test)
     {
         super(test);
-        this.config = config;
     }
     
-    protected void setUp()
+    protected final void setUp()
     {
         old = TestConfiguration.getCurrent();
-        TestConfiguration.setCurrent(config);
+        TestConfiguration.setCurrent(getNewConfiguration(old));
     }
     
-    protected void tearDown()
+    protected final void tearDown()
     {
         TestConfiguration.setCurrent(old);
     }
+    
+    /**
+     * Return the new configuration to use at setUp time.
+     * Most likely based upon the old configuration passed in. 
+     * @param old The current configuration.
+     * @return new configuration
+     */
+    abstract TestConfiguration getNewConfiguration(TestConfiguration old);
 }

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/ChangeUserSetup.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/ChangeUserSetup.java?view=diff&rev=493180&r1=493179&r2=493180
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/ChangeUserSetup.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/ChangeUserSetup.java Fri Jan  5 12:31:13 2007
@@ -28,11 +28,10 @@
  * the previous configuration.
  * 
  */
-final class ChangeUserSetup extends TestSetup {
+final class ChangeUserSetup extends ChangeConfigurationSetup {
     
     private final String user;
     private final String password;
-    private TestConfiguration old;
     
     ChangeUserSetup(Test test, String user, String password)
     {
@@ -41,15 +40,8 @@
         this.password = password;
     }
     
-    protected void setUp()
+    TestConfiguration getNewConfiguration(TestConfiguration old)
     {
-        old = TestConfiguration.getCurrent();
-        TestConfiguration config = new TestConfiguration(old, user, password);
-        TestConfiguration.setCurrent(config);
-    }
-    
-    protected void tearDown()
-    {
-        TestConfiguration.setCurrent(old);
+        return new TestConfiguration(old, user, password);
     }
 }

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/ConnectorSetup.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/ConnectorSetup.java?view=auto&rev=493180
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/ConnectorSetup.java (added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/ConnectorSetup.java Fri Jan  5 12:31:13 2007
@@ -0,0 +1,54 @@
+/*
+ *
+ * Derby - Class org.apache.derbyTesting.junit.ConnectorSetup
+ *
+ * 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.framework.Assert;
+import junit.framework.Test;
+
+/**
+ * Change the Connector implementation at setup time and
+ * restore at tearDown time.
+ *
+ */
+final class ConnectorSetup extends ChangeConfigurationSetup {
+
+    private final String connectorClass;
+    public ConnectorSetup(Test test, String connectorClass) {
+        super(test);
+        this.connectorClass = connectorClass;
+    }
+
+    TestConfiguration getNewConfiguration(TestConfiguration old) {
+        // Copy the current configuration by creating one
+        // with the same database name
+        TestConfiguration newConfig = 
+            new TestConfiguration(old, old.getDatabaseName());
+        
+        try {
+            newConfig.connector = (Connector)
+             Class.forName(connectorClass).newInstance();
+        } catch (Exception e) {
+            Assert.fail(e.getMessage());
+        }
+        newConfig.connector.setConfiguration(newConfig);
+        return newConfig;
+    }
+
+}

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

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/DatabaseChangeSetup.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/DatabaseChangeSetup.java?view=auto&rev=493180
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/DatabaseChangeSetup.java (added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/DatabaseChangeSetup.java Fri Jan  5 12:31:13 2007
@@ -0,0 +1,41 @@
+/*
+ *
+ * Derby - Class org.apache.derbyTesting.junit.DatabaseChangeSetup
+ *
+ * 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.framework.Test;
+
+/**
+ * Change the current configuration's database name at setup.
+ * Previous configuration is restored on tearDown.
+ *
+ */
+final class DatabaseChangeSetup extends ChangeConfigurationSetup {
+
+    private final String dbName;
+    
+    public DatabaseChangeSetup(Test test, String dbName) {
+        super(test);
+        this.dbName = dbName;
+   }
+
+    TestConfiguration getNewConfiguration(TestConfiguration old) {
+        return new TestConfiguration(old, dbName);
+    }
+}

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

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/ServerSetup.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/ServerSetup.java?view=auto&rev=493180
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/ServerSetup.java (added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/ServerSetup.java Fri Jan  5 12:31:13 2007
@@ -0,0 +1,47 @@
+/*
+ *
+ * Derby - Class org.apache.derbyTesting.junit.ServerSetup
+ *
+ * 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.framework.Test;
+
+/**
+ * Change to a client server configuration based upon the
+ * current configuration at setup time. Previous configuration
+ * is restored at tearDown time. This only changes the
+ * configuration, it does not start any network server.
+ *
+ */
+final class ServerSetup extends ChangeConfigurationSetup {
+
+    private final String host;
+    private final int port;
+    
+    public ServerSetup(Test test, String host, int port) {
+        super(test);
+        this.host = host;
+        this.port = port;
+    }
+
+    TestConfiguration getNewConfiguration(TestConfiguration old) {
+               
+        return new TestConfiguration(old, JDBCClient.DERBYNETCLIENT,
+                    host, port);
+    }
+}

Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/ServerSetup.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=493180&r1=493179&r2=493180
==============================================================================
--- 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 Jan  5 12:31:13 2007
@@ -255,17 +255,10 @@
         if (!(Derby.hasClient() && Derby.hasServer())
                 || JDBC.vmSupportsJSR169())
             return new TestSuite("empty: no network server support");
-            
-        TestConfiguration config = TestConfiguration.getCurrent();
-        
-        TestConfiguration derbyClientConfig =
-            new TestConfiguration(config, JDBCClient.DERBYNETCLIENT,
-                    DEFAULT_HOSTNAME, DEFAULT_PORT);
                    
         Test test = new NetworkServerTestSetup(suite, false);
             
-        return new ChangeConfigurationSetup(derbyClientConfig, test);
-
+        return new ServerSetup(test, DEFAULT_HOSTNAME, DEFAULT_PORT);
     }
     
     /**
@@ -280,8 +273,6 @@
      */
     public static Test singleUseDatabaseDecorator(Test test)
     {
-        TestConfiguration config = TestConfiguration.getCurrent();
-
         // Forward slash is ok, Derby treats database names
         // as URLs and translates forward slash to the local
         // separator.
@@ -291,10 +282,8 @@
         synchronized (dbName) {
             dbName = dbName.concat(Integer.toHexString(uniqueDB++));
         }
-        TestConfiguration newDBconfig = 
-            new TestConfiguration(config, dbName);
-        return new ChangeConfigurationSetup(newDBconfig,
-                new DropDatabaseSetup(test));
+
+        return new DatabaseChangeSetup(new DropDatabaseSetup(test), dbName);
     }
     
     /**
@@ -332,11 +321,7 @@
      * @see DatabasePropertyTestSetup#builtinAuthentication(Test, String[], String)
      */
     public static Test sqlAuthorizationDecorator(Test test)
-    {
-        TestConfiguration config = TestConfiguration.getCurrent();
-        TestConfiguration newDBconfig = 
-            new TestConfiguration(config, DEFAULT_DBNAME_SQL);
-        
+    {       
         // Set the SQL authorization mode as a database property
         // with a modified DatabasePropertyTestSetup that does not
         // reset it.
@@ -348,7 +333,7 @@
             }
         };
 
-        return new ChangeConfigurationSetup(newDBconfig, setSQLAuthMode);
+        return new DatabaseChangeSetup(setSQLAuthMode, DEFAULT_DBNAME_SQL);
     }
     
     /**
@@ -364,22 +349,8 @@
      */
     public static Test connectionXADecorator(Test test)
     {
-        // Copy the current configuration by creating one
-        // with the same database name
-        TestConfiguration config = TestConfiguration.getCurrent();
-        TestConfiguration newConfig = 
-            new TestConfiguration(config, config.getDatabaseName());
-        
-        try {
-            newConfig.connector = (Connector) Class.forName(
-              "org.apache.derbyTesting.junit.XADataSourceConnector").newInstance();
-        } catch (Exception e) {
-            Assert.fail(e.getMessage());
-        }
-        
-        newConfig.connector.setConfiguration(newConfig);
-       
-        return new ChangeConfigurationSetup(newConfig, test);
+        return new ConnectorSetup(test,
+                "org.apache.derbyTesting.junit.XADataSourceConnector");
     }
     
     /**
@@ -399,7 +370,7 @@
  
     }
 
-    private TestConfiguration(TestConfiguration copy, JDBCClient client,
+    TestConfiguration(TestConfiguration copy, JDBCClient client,
             String hostName, int port)
     {
         this.dbName = copy.dbName;
@@ -787,7 +758,7 @@
      * Indirection for obtaining connections based upon
      * this configuration.
      */
-    private Connector connector;
+    Connector connector;
     
     /*
      * SecurityManager related configuration.