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 2006/08/25 03:27:00 UTC

svn commit: r434586 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting: functionTests/tests/jdbc4/AutoloadBooting.java functionTests/tests/jdbc4/AutoloadTest.java junit/TestConfiguration.java

Author: djd
Date: Thu Aug 24 18:26:59 2006
New Revision: 434586

URL: http://svn.apache.org/viewvc?rev=434586&view=rev
Log:
Cleanup the autoloading tests to move the setup checks out of TestConfiguration into the tests
themselves as they are very specific to the autoloading tests.

Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/AutoloadBooting.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/AutoloadTest.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/jdbc4/AutoloadBooting.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/AutoloadBooting.java?rev=434586&r1=434585&r2=434586&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/AutoloadBooting.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/AutoloadBooting.java Thu Aug 24 18:26:59 2006
@@ -61,6 +61,7 @@
 	//	STATE
 	//
 	/////////////////////////////////////////////////////////////
+    
 
 	/////////////////////////////////////////////////////////////
 	//
@@ -82,6 +83,18 @@
 	//
 	/////////////////////////////////////////////////////////////
 
+    /**
+     * Only run embedded.
+     */
+    public static Test suite() {
+        TestSuite suite = new TestSuite();
+        
+        if (usingEmbedded())
+            suite.addTestSuite(AutoloadBooting.class);
+        
+        return suite;
+    }
+    
 	/////////////////////////////////////////////////////////////
 	//
 	//	TEST ENTRY POINTS
@@ -103,15 +116,6 @@
 		//
 		//CONFIG.setVerbosity( true );
 
-		//
-		// Only run embedded.
-		//
-		if ( !usingEmbedded() )
-		{
-			println( "Not running in the embedded framework. Exitting..." );
-			return;
-		}
-
 		vetInitialization();
 		scenario1_3();
 		scenario2();
@@ -348,16 +352,19 @@
 	private	void	loadNetworkClientDriver()
 		throws Exception
 	{
-		boolean		isAutoloading = !getTestConfiguration().autoloading();
+        // This test is only run in JDBC 4 or higher which means the
+        // drivers will always be auto-loading when the classes are
+        // being loaded from the jars.
+		boolean		isAutoloading = getTestConfiguration().loadingFromJars();
 		
 		//
 		// Forcibly load the network client if we are not autoloading it.
 		//
-		if ( isAutoloading )
+		if ( !isAutoloading )
 		{
 			println( "Not autoloading, so forcibly faulting in the client driver." );
 
-			Class.forName( CLIENT_DRIVER_NAME );
+			Class.forName( CLIENT_DRIVER_NAME ).newInstance();
 		}
 
 		//

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/AutoloadTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/AutoloadTest.java?rev=434586&r1=434585&r2=434586&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/AutoloadTest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/AutoloadTest.java Thu Aug 24 18:26:59 2006
@@ -30,12 +30,15 @@
 
 package org.apache.derbyTesting.functionTests.tests.jdbc4;
 
+import java.security.PrivilegedActionException;
 import java.sql.*;
 import java.util.*;
 import junit.framework.*;
 
 import org.apache.derbyTesting.functionTests.util.SQLStateConstants;
 import org.apache.derbyTesting.junit.BaseJDBCTestCase;
+import org.apache.derbyTesting.junit.JDBC;
+import org.apache.derbyTesting.junit.TestConfiguration;
 
 public	class	AutoloadTest	extends	BaseJDBCTestCase
 {
@@ -72,6 +75,57 @@
 	//	JUnit BEHAVIOR
 	//
 	/////////////////////////////////////////////////////////////
+    
+    /**
+     * Only run a test if the driver will be auto-loaded.
+     */
+    public static Test suite()
+    {
+        TestSuite suite = new TestSuite();
+        
+        // need DriverManager at least and Derby drivers
+        // no interest in testing DB2's client.
+        if (JDBC.vmSupportsJDBC2() &&
+                (usingEmbedded() || usingDerbyNetClient()))
+        {
+
+            boolean autoloadingCurrentDriver = false;
+            
+            // Autoloading if the current driver is defined in the
+            // system property jdbc.drivers, see java.sql.DriverManager.
+            try {
+                String jdbcDrivers = getSystemProperty("jdbc.drivers");
+                if (jdbcDrivers != null)
+                {
+                    // Simple test to see if the driver class is
+                    // in the value. Could get fancy and see if it is
+                    // correctly formatted but not worth it.
+                    String driver =
+                        TestConfiguration.getCurrent().getJDBCClient().getJDBCDriverName();
+                    
+                    if (jdbcDrivers.indexOf(driver) != -1)
+                        autoloadingCurrentDriver = true;
+                }
+                
+            } catch (PrivilegedActionException e) {
+                // can't read property, assume not autoloading.
+            }
+            
+            // Also auto loading if this is JDBC 4 and loading from the
+            // jar files, due to the required manifest entry.
+            if (JDBC.vmSupportsJDBC4() &&
+                    TestConfiguration.getCurrent().loadingFromJars())
+                autoloadingCurrentDriver = true;
+          
+            if (autoloadingCurrentDriver)
+                suite.addTestSuite(AutoloadTest.class);
+
+        }
+        
+        System.out.println("TEST COUNT" + suite.countTestCases());
+        
+        return suite;
+    }
 
 	/////////////////////////////////////////////////////////////
 	//
@@ -101,30 +155,28 @@
 		// We expect that the connection to the database will fail for
 		// one reason or another.
 		//
-		if ( getTestConfiguration().autoloading() )
-		{
-			println( "We ARE autoloading..." );
-
-			//
-			// The DriverManager should have autoloaded the client driver.
-			// This means that the connection request is passed on to the
-			// server. The server then determines that the database does
-			// not exist. This raises a different error depending on whether
-			// we're running embedded or with the Derby client.
-			//
-			if ( usingEmbedded() ) { failToConnect( "XJ004" ); }
-			else { failToConnect( "08004" ); }
-		}
-		else
-		{
-			println( "We are NOT autoloading..." );
-
-			//
-			// We aren't autoloading the driver. The
-			// DriverManager returns the following SQLState.
-			//
-			failToConnect( "08001" );
-		}
+
+		println( "We ARE autoloading..." );
+
+		//
+		// The DriverManager should have autoloaded the client driver.
+		// This means that the connection request is passed on to the
+		// server. The server then determines that the database does
+		// not exist. This raises a different error depending on whether
+		// we're running embedded or with the Derby client.
+		//
+        String expectedError =
+            usingEmbedded() ? "XJ004" : "08004";
+        
+        failToConnect(expectedError);
+       
+        // Test we can connect successfully to a database!
+        String url = getTestConfiguration().getJDBCUrl();
+        url = url.concat(";create=true");
+        String user = getTestConfiguration().getUserName();
+        String password = getTestConfiguration().getUserPassword();
+        DriverManager.getConnection(url, user, password).close();
+
 	}
 
 	/**
@@ -147,6 +199,8 @@
 			println( "Attempting to connect with this URL: '" + connectionURL + "'" );
 			
 			DriverManager.getConnection( connectionURL, properties );
+            
+            fail("Connection succeed, expected to fail.");
 		}
 		catch ( SQLException e ) { se = e; }
 

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?rev=434586&r1=434585&r2=434586&view=diff
==============================================================================
--- 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 Thu Aug 24 18:26:59 2006
@@ -311,56 +311,6 @@
     public boolean isVerbose() {
         return isVerbose;
     }
-    
-	/**
-	 * <p>
-	 * Return true if we expect that the DriverManager will autoload the client driver.
-	 * </p>
-	 */
-	public	boolean	autoloading()
-		throws Exception
-	{
-		//
-		// DriverManager autoloads the client only as of JDBC4.
-		//
-		if ( !JDBC.vmSupportsJDBC4() )
-		{
-			return false;
-		}
-
-		//
-		// The DriverManager will autoload drivers specified by the jdbc.drivers
-		// property. 
-		//
-		if ( getSystemStartupProperty( DRIVER_LIST ) != null )
-		{
-			return true;
-		}
-
-		//
-		// The DriverManager will also look inside our jar files for
-		// the generated file META-INF/services/java.sql.Driver. This file
-		// will contain the name of the driver to load. So if we are running
-		// this test against Derby jar files, we expect that the driver will
-		// be autoloaded.
-		//
-		// Note that if we run with a security manager, we get permissions
-		// exception at startup when the driver is autoloaded. This exception
-		// is silently swallowed and the result is that the driver is not
-		// loaded even though we expect it to be.
-		//
-		if ( loadingFromJars() )
-		{
-			return true;
-		}
-
-		//
-		// OK, we've run out of options. We do not expect that the driver
-		// will be autoloaded.
-		//
-
-		return false;
-	}
 
 	/**
 	 * <p>
@@ -478,7 +428,6 @@
     private final static String KEY_PORT = "port";
     private final static String KEY_VERBOSE = "derby.tests.debug";    
     private final static String KEY_SINGLE_LEG_XA = "derbyTesting.xa.single";
-	private final static String DRIVER_LIST = "jdbc.drivers";
 
     /**
      * Possible values of system properties.