db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
Subject svn commit: r495603 - /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/AutoloadTest.java
Date Fri, 12 Jan 2007 15:23:54 GMT
Author: djd
Date: Fri Jan 12 07:23:53 2007
New Revision: 495603

URL: http://svn.apache.org/viewvc?view=rev&rev=495603
Log:
DERBY-1952 (partial) Ensure fixtures in jdbcapi.AutoloadTest are ordered
and add a fixture to test that explicitly loading Derby's JDBC driver works
when auto-loading is enabled. 

Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/AutoloadTest.java

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/AutoloadTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/AutoloadTest.java?view=diff&rev=495603&r1=495602&r2=495603
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/AutoloadTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/AutoloadTest.java
Fri Jan 12 07:23:53 2007
@@ -54,36 +54,49 @@
         if (!JDBC.vmSupportsJDBC2())
             return new TestSuite("empty: no java.sql.DriverManager");
 
-        if (JDBC.vmSupportsJDBC4() && TestConfiguration.loadingFromJars()) {
+        boolean embeddedAutoLoad = false;
+        boolean clientAutoLoad = false;
+        
+        if (JDBC.vmSupportsJDBC4() && TestConfiguration.loadingFromJars())
+        {
             // test client & embedded
-            return TestConfiguration.defaultSuite(AutoloadTest.class);
+            embeddedAutoLoad = true;
+            clientAutoLoad = true;
         }
-        // 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.
-
-        try {
-            String jdbcDrivers = getSystemProperty("jdbc.drivers");
-            if (jdbcDrivers == null)
-                jdbcDrivers = "";
-
-            boolean embedded = jdbcDrivers
-                    .indexOf("org.apache.derby.jdbc.EmbeddedDriver") != -1;
-
-            boolean clientServer = jdbcDrivers
-                    .indexOf("org.apache.derby.jdbc.ClientDriver") != -1;
-
-            if (embedded && clientServer)
-                return TestConfiguration.defaultSuite(AutoloadTest.class);
-
-            if (embedded)
-                return TestConfiguration.embeddedSuite(AutoloadTest.class);
-
-            if (clientServer)
-                return TestConfiguration.clientServerSuite(AutoloadTest.class);
-        } catch (SecurityException se) {
-            // assume there is no autoloading if
-            // we can't read the value of jdbc.drivers.
+        else
+        {
+            // 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.
+
+            try {
+                String jdbcDrivers = getSystemProperty("jdbc.drivers");
+                if (jdbcDrivers == null)
+                    jdbcDrivers = "";
+
+                embeddedAutoLoad = jdbcDrivers
+                        .indexOf("org.apache.derby.jdbc.EmbeddedDriver") != -1;
+
+                clientAutoLoad = jdbcDrivers
+                        .indexOf("org.apache.derby.jdbc.ClientDriver") != -1;
+
+            } catch (SecurityException se) {
+                // assume there is no autoloading if
+                // we can't read the value of jdbc.drivers.
+            }
+        }
+        
+        if (embeddedAutoLoad || clientAutoLoad)
+        {
+            TestSuite suite = new TestSuite("AutoloadTest");
+            if (embeddedAutoLoad)
+                suite.addTest(baseAutoLoadSuite("embedded"));
+            if (clientAutoLoad)
+                suite.addTest(
+                  TestConfiguration.clientServerDecorator(
+                          baseAutoLoadSuite("client")));
+                
+            return suite;
         }
 
         // Run a single test that ensures that the driver is
@@ -96,6 +109,21 @@
         
         return suite;
     }
+    
+    /**
+     * Return the ordered set of tests when autoloading is enabled.
+     * @return
+     */
+    private static Test baseAutoLoadSuite(String which)
+    {
+        TestSuite suite = new TestSuite("AutoloadTest: " + which);
+        
+        suite.addTest(new AutoloadTest("testRegisteredDriver"));
+        suite.addTest(new AutoloadTest("testSuccessfulConnect"));
+        suite.addTest(new AutoloadTest("testUnsuccessfulConnect"));
+        suite.addTest(new AutoloadTest("testExplicitLoad"));
+        return suite;
+    }
 
 	// ///////////////////////////////////////////////////////////
 	//
@@ -111,9 +139,7 @@
     {
         String protocol =
             getTestConfiguration().getJDBCClient().getUrlBase();
-        
-        System.out.println("PROTOCOL " + protocol);
-            
+                    
         Driver driver = DriverManager.getDriver(protocol);
         assertNotNull("Expected registered driver", driver);
     }
@@ -152,6 +178,26 @@
             
             assertSQLState(expectedError, e);
         }
+    }
+    
+    /**
+     * Test an explict load of the driver works as well.
+     * @throws Exception 
+     *
+     */
+    public void testExplicitLoad() throws Exception
+    {
+        String driverClass =
+            getTestConfiguration().getJDBCClient().getJDBCDriverName();
+        
+        // With and without a new instance
+        Class.forName(driverClass);
+        testSuccessfulConnect();
+        testUnsuccessfulConnect();
+        
+        Class.forName(driverClass).newInstance();
+        testSuccessfulConnect();
+        testUnsuccessfulConnect();
     }
     
     /**



Mime
View raw message