db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kmars...@apache.org
Subject svn commit: r530868 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting: functionTests/master/ functionTests/master/j9_13/ functionTests/master/j9_22/ functionTests/tests/jdbc4/ functionTests/tests/lang/ functionTests/tests/tools/ junit/
Date Fri, 20 Apr 2007 18:06:54 GMT
Author: kmarsden
Date: Fri Apr 20 11:06:53 2007
New Revision: 530868

URL: http://svn.apache.org/viewvc?view=rev&rev=530868
Log:
DERBY-2567  convert lang/errorcode.sql to JUnit
Converted errorcode.sql. Changed individual bug queries to print fatal errors tojust print
the SQLExceptions with Errorcode >= 40000.
Added a method showResultSet(rs) to org.apache.derbyTesting.junit.Utilities
which will print out a resultSet in two dimensional array format.  This 
can be used to make converting tests easier.

Moved ij "DRIVER" testing to ij.sql


Removed:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/errorCode.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/j9_13/errorCode.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/j9_22/errorCode.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/errorCode.sql
Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/ij.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/PreparedStatementTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ProcedureInTriggerTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/_Suite.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/ij.sql
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/ij_app.properties
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseJDBCTestCase.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/Utilities.java

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/ij.out
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/ij.out?view=diff&rev=530868&r1=530867&r2=530868
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/ij.out (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/ij.out Fri
Apr 20 11:06:53 2007
@@ -19,10 +19,10 @@
 -- no driver loaded yet, detected off of the url
 -- this one is a bad url:
 connect 'cloudscape:wombat';
-ERROR 08001: No suitable driver
+ERROR 08001: No suitable driver (errorCode = 0)
 ij> -- this one will work.
 connect 'jdbc:derby:wombat';
-ERROR XJ004: Database 'wombat' not found.
+ERROR XJ004: Database 'wombat' not found. (errorCode = 40000)
 ij> -- no connection yet, this will fail
 create table t (i int);
 IJ ERROR: Unable to establish connection
@@ -50,6 +50,18 @@
 -- a foundation 2000 concept
 execute procedure sqlj.install_jar( 'file:c:/p4c/systest/out/DigIt.jar', 'SourceWUs', 1 );
 IJ ERROR: Unable to establish connection
+ij> -- moved from errorcode.sql
+-- specify an invalid driver
+driver 'java.lang.Integer';
+IJ ERROR: Could not locate class java.lang.Integer
+ij> -- now a valid driver
+driver 'org.apache.derby.jdbc.EmbeddedDriver';
+ij> -- specify an invalid database
+connect 'asdfasdf';
+ERROR 08001: No suitable driver (errorCode = 0)
+ij> -- now a valid database, but no create
+connect 'jdbc:derby:wombat';
+ERROR XJ004: Database 'wombat' not found. (errorCode = 40000)
 ij> -- and, the help output:
 help;
  Supported commands include:

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/PreparedStatementTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/PreparedStatementTest.java?view=diff&rev=530868&r1=530867&r2=530868
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/PreparedStatementTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/PreparedStatementTest.java
Fri Apr 20 11:06:53 2007
@@ -1134,20 +1134,6 @@
     }
 
     /**
-     * Return the last chained SQLException.
-     * If there are no exceptions chained, the original one is returned.
-     */
-    private SQLException getLastSQLException(SQLException sqle) {
-        SQLException last = sqle;
-        SQLException next = sqle;
-        while (next != null) {
-            last = next;
-            next = last.getNextException();
-        }
-        return last;
-    }
-
-    /**
      * This methods is not to be used, but sometimes you have to!
      *
      * @param preSQLState the expected outer SQL state

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ProcedureInTriggerTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ProcedureInTriggerTest.java?view=diff&rev=530868&r1=530867&r2=530868
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ProcedureInTriggerTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ProcedureInTriggerTest.java
Fri Apr 20 11:06:53 2007
@@ -309,26 +309,7 @@
       
     }
 
-    private void showResultSet(ResultSet rs) throws SQLException {
-        int row = 0;
-           while (rs.next()) {
-               row++;
-               ResultSetMetaData rsmd = rs.getMetaData();
-               int nocols = rsmd.getColumnCount();
-               System.out.print("{");
-              
-               for (int i = 0; i < nocols; i++)
-               {
-                   System.out.print("\"" + rs.getString(i+1) + "\"");
-                   if (i == (nocols -1))
-                       System.out.println("}");
-                   else
-                       System.out.print(",");
-                       
-               }
-           }
-    }
-
+  
     /**
      * Some misc negative tests for procedures in triggers.
      * 

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/_Suite.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/_Suite.java?view=diff&rev=530868&r1=530867&r2=530868
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/_Suite.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/_Suite.java
Fri Apr 20 11:06:53 2007
@@ -98,6 +98,7 @@
         suite.addTest(CollationTest.suite());
         suite.addTest(ScrollCursors1Test.suite());
         suite.addTest(SimpleTest.suite());
+        suite.addTest(ErrorCodeTest.suite());
 
         // Add the XML tests, which exist as a separate suite
         // so that users can "run all XML tests" easily.

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/ij.sql
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/ij.sql?view=diff&rev=530868&r1=530867&r2=530868
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/ij.sql
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/ij.sql
Fri Apr 20 11:06:53 2007
@@ -46,7 +46,19 @@
 -- a foundation 2000 concept
 execute procedure sqlj.install_jar( 'file:c:/p4c/systest/out/DigIt.jar', 'SourceWUs', 1 );
 
+-- moved from errorcode.sql
 
+-- specify an invalid driver
+driver 'java.lang.Integer';
+
+-- now a valid driver
+driver 'org.apache.derby.jdbc.EmbeddedDriver';
+
+-- specify an invalid database
+connect 'asdfasdf';
+
+-- now a valid database, but no create
+connect 'jdbc:derby:wombat';
 -- and, the help output:
 help;
 

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/ij_app.properties
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/ij_app.properties?view=diff&rev=530868&r1=530867&r2=530868
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/ij_app.properties
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/ij_app.properties
Fri Apr 20 11:06:53 2007
@@ -5,6 +5,7 @@
 
 ij.showNoConnectionsAtStart=true
 ij.showNoCountForSelect=true
+ij.showErrorCode=true
 
 #Exclude for J2ME/Foundation - test is specific to ij and tests bad/good urls
-runwithfoundation=false
\ No newline at end of file
+runwithfoundation=false

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseJDBCTestCase.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseJDBCTestCase.java?view=diff&rev=530868&r1=530867&r2=530868
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseJDBCTestCase.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseJDBCTestCase.java Fri
Apr 20 11:06:53 2007
@@ -584,7 +584,24 @@
     public static void assertSQLState(String expected, SQLException exception) {
         assertSQLState("Unexpected SQL state.", expected, exception);
     }
-
+    
+    public static void assertErrorCode(String message, int expected, SQLException exception)
{
+       while (exception != null)
+       {
+           try {
+               assertEquals(message, expected,exception.getErrorCode());
+           } catch (AssertionFailedError e) {
+               // check and see if our error code is in a chained exception
+               exception = exception.getNextException();               
+           }
+       }
+    }
+    
+    public static void assertErrorCode(int expected, SQLException exception)
+    {
+       assertErrorCode("Unexpected Error Code",expected, exception);
+    }
+    
     /**
      * Assert that the query does not compile and throws
      * a SQLException with the expected state.
@@ -689,7 +706,34 @@
             assertSQLState(sqlState, se);
         }
     }
-
+    /**
+     * Assert that the query fails (either in compilation,
+     * execution, or retrieval of results--doesn't matter)
+     * and throws a SQLException with the expected state
+     * and error code
+     *
+     * Assumption is that 'query' does *not* have parameters
+     * that need binding and thus can be executed using a
+     * simple Statement.execute() call.
+     * 
+     * @param sqlState expected sql state.
+     * @param errorCode expected error code.
+     * @param st Statement object on which to execute.
+     * @param query the query to compile and execute.
+     */
+    public static void assertStatementError(String sqlState, int errorCode, Statement st,
String query) {
+        try {
+            boolean haveRS = st.execute(query);
+            fetchAndDiscardAllResults(st, haveRS);
+            fail("Expected error '" + sqlState +
+                "' but no error was thrown.");
+        } catch (SQLException se) {
+            assertSQLState(sqlState, se);
+            assertEquals(errorCode,se.getErrorCode());
+        }
+        
+    }
+    
     /**
      * Assert that execution of the received PreparedStatement
      * object fails (either in execution or when retrieving
@@ -812,6 +856,21 @@
     {
         assertEquals("Update count does not match:",
             expectedRC, pSt.executeUpdate());
+    }
+
+    /**
+     * Get the last SQLException in chain.
+     * @param a <code>SQLException</code>
+     * @return the last exception in the chain.
+     */
+    public SQLException getLastSQLException(SQLException sqle) {
+        SQLException current = sqle;
+        SQLException next = sqle.getNextException();
+        while (next != null) {
+            current = next;
+            next = next.getNextException();
+        }
+        return current;
     }
 
     /**

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/Utilities.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/Utilities.java?view=diff&rev=530868&r1=530867&r2=530868
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/Utilities.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/Utilities.java Fri Apr
20 11:06:53 2007
@@ -20,6 +20,9 @@
 package org.apache.derbyTesting.junit;
 
 import java.io.UnsupportedEncodingException;
+import java.sql.ResultSet;
+import java.sql.ResultSetMetaData;
+import java.sql.SQLException;
 
 /**
  * General non-JDBC related utilities relocated from TestUtil
@@ -79,5 +82,40 @@
         }
 
 
+        /**
+         * Print out resultSet in two dimensional array format, for use by
+         * JDBC.assertFullResultSet(rs,expectedRows) expectedRows argument.
+         * Useful while converting tests to get output in correct format.
+         * 
+         * @param rs
+         * @throws SQLException
+         */
+        public static void showResultSet(ResultSet rs) throws SQLException {
+            System.out.print("{");
+            int row = 0;
+            boolean next = rs.next();
+            while (next) {
+                row++;
+                ResultSetMetaData rsmd = rs.getMetaData();
+                int nocols = rsmd.getColumnCount();
+                System.out.print("{");
+                
+                for (int i = 0; i < nocols; i++)
+                {
+                    System.out.print("\"" + rs.getString(i+1) + "\"");
+                    if (i == (nocols -1))
+                        System.out.print("}");
+                    else
+                        System.out.print(",");
+                           
+                }
+                next = rs.next();
+                   
+                if (next)
+                    System.out.println(",");
+                else
+                    System.out.println("};");
+            }
+        }       
 
 }



Mime
View raw message