db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
Subject svn commit: r627203 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting: functionTests/tests/jdbcapi/ functionTests/tests/lang/ junit/
Date Wed, 13 Feb 2008 00:40:39 GMT
Author: djd
Date: Tue Feb 12 16:40:38 2008
New Revision: 627203

URL: http://svn.apache.org/viewvc?rev=627203&view=rev
Log:
Add a utility JDBC assert to test that a SQLWarning (typically returned from a method like
Connection.getWarnings) is null, ie. no warnings. If the assert fails then the message will
contain the text of the warning. Replace the previous use of assertNull() which leaves no
traces as to what the warning was.

Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/URCoveringIndexTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/LangProcedureTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ScrollCursors2Test.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/UpdatableResultSetTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/JDBC.java

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/URCoveringIndexTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/URCoveringIndexTest.java?rev=627203&r1=627202&r2=627203&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/URCoveringIndexTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/URCoveringIndexTest.java
Tue Feb 12 16:40:38 2008
@@ -100,7 +100,7 @@
             rs.updateRow();
             w = rs.getWarnings();
         }
-        assertTrue("Update should not produce any warnings ", w == null);
+        JDBC.assertNoWarnings(w);
         rs.close();
         
         rs = roStmt.executeQuery("SELECT c1 FROM tableWithPK");

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/LangProcedureTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/LangProcedureTest.java?rev=627203&r1=627202&r2=627203&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/LangProcedureTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/LangProcedureTest.java
Tue Feb 12 16:40:38 2008
@@ -771,7 +771,7 @@
         toomany.execute();
         rs = toomany.getResultSet();
         // Single result set returned, therefore no warnings.
-        assertNull(toomany.getWarnings());
+        JDBC.assertNoWarnings(toomany.getWarnings());
         JDBC.assertFullResultSet(rs, new String[][] { { "2", "int" } });
         JDBC.assertNoMoreResults(toomany);
         toomany.close();

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ScrollCursors2Test.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ScrollCursors2Test.java?rev=627203&r1=627202&r2=627203&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ScrollCursors2Test.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ScrollCursors2Test.java
Tue Feb 12 16:40:38 2008
@@ -56,11 +56,10 @@
      */
 
     public void setUp() throws SQLException {
-        Connection conn = getConnection();
 
         Statement s_i_r;
 
-        s_i_r = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
+        s_i_r = createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
                 ResultSet.CONCUR_READ_ONLY);
 
         /* Create a table */
@@ -74,10 +73,8 @@
     }
 
     public void tearDown() throws SQLException, Exception {
-        Connection conn = getConnection();
-        Statement s = conn.createStatement();
-        s.execute("drop table t");
-        conn.commit();
+        dropTable("T");
+        commit();
         super.tearDown();
     }
 
@@ -85,14 +82,12 @@
         Connection conn = getConnection();
         PreparedStatement ps_f_r = null;
         ResultSet rs;
-        SQLWarning warning;
         Statement s_f_r = null;
 
-        s_f_r = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY,
+        s_f_r = createStatement(ResultSet.TYPE_FORWARD_ONLY,
                 ResultSet.CONCUR_READ_ONLY);
         // We should have gotten no warnings and a read only forward only cursor
-        warning = conn.getWarnings();
-        assertNull(warning);
+        JDBC.assertNoWarnings(conn.getWarnings());
 
         conn.clearWarnings();
 
@@ -210,11 +205,10 @@
         rs.close();
         s_f_r.close();
 
-        ps_f_r = conn.prepareStatement("select * from t",
+        ps_f_r = prepareStatement("select * from t",
                 ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
         // We should have gotten no warnings and a read only forward only cursor
-        warning = conn.getWarnings();
-        assertNull(warning);
+        JDBC.assertNoWarnings(conn.getWarnings());
         
         conn.clearWarnings();
 
@@ -251,16 +245,11 @@
 
     public void testForwardOnlyPositive() throws SQLException {
         Connection conn = getConnection();
-        boolean passed = true;
         ResultSet rs;
-        SQLWarning warning;
-        Statement s_f_r = null;
-
-        s_f_r = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY,
+        Statement s_f_r = createStatement(ResultSet.TYPE_FORWARD_ONLY,
                 ResultSet.CONCUR_READ_ONLY);
         // We should have gotten no warnings and a read only forward only cursor
-        warning = conn.getWarnings();
-        assertNull(warning);
+        JDBC.assertNoWarnings(conn.getWarnings());
         conn.clearWarnings();
 
         // Verify that setMaxRows(4) succeeds
@@ -269,7 +258,6 @@
 
         rs = s_f_r.executeQuery("values 1, 2, 3, 4, 5, 6");
         // Iterate straight thru RS, expect only 5 rows.
-        assertNotNull(rs);
         JDBC.assertDrainResults(rs, 5);
         
         s_f_r.close();
@@ -293,7 +281,7 @@
         Statement s_s_r = null; // sensitive, read only
         Statement s_s_u = null; // sensitive, updatable
 
-        s_s_r = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
+        s_s_r = createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
                 ResultSet.CONCUR_READ_ONLY);
 
         // We should have gotten a warning and a scroll insensitive cursor
@@ -311,7 +299,7 @@
         // Close the statement
         s_s_r.close();
 
-        s_s_u = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
+        s_s_u = createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
                 ResultSet.CONCUR_UPDATABLE);
         // We should have gotten 1 warning and a updatable scroll
         // insensitive cursor.
@@ -337,19 +325,16 @@
      */
     public void testScrollInsensitivePositive() throws SQLException {
         Connection conn = getConnection();
-        boolean passed = true;
-        PreparedStatement ps_i_r = null;
+
         ResultSet rs;
-        SQLWarning warning;
-        Statement s_i_r = null; // insensitive, read only
 
-        s_i_r = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
+        // insensitive, read only
+        Statement s_i_r = createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
                 ResultSet.CONCUR_READ_ONLY);
 
         // We should not have gotten any warnings
         // and should have gotten a scroll insensitive cursor
-        warning = conn.getWarnings();
-        assertNull(warning);
+        JDBC.assertNoWarnings(conn.getWarnings());
 
         conn.clearWarnings();
 
@@ -413,13 +398,12 @@
 
         rs.close();
 
-        ps_i_r = conn.prepareStatement("select * from t",
+        PreparedStatement ps_i_r = prepareStatement("select * from t",
                 ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
 
         // We should not have gotten any warnings
         // and should have gotten a prepared scroll insensitive cursor
-        warning = conn.getWarnings();
-        assertNull(warning);
+        JDBC.assertNoWarnings(conn.getWarnings());
 
         rs = ps_i_r.executeQuery();
         // make sure it's scrollable
@@ -491,18 +475,15 @@
      */
     public void testScrollInsensitiveNegative() throws SQLException {
         Connection conn = getConnection();
-        boolean passed = true;
-        ResultSet rs;
-        SQLWarning warning;
-        Statement s_i_r = null; // insensitive, read only
 
-        s_i_r = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
+        ResultSet rs;
+        // insensitive, read only
+        Statement s_i_r = createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
                 ResultSet.CONCUR_READ_ONLY);
 
         // We should not have gotten any warnings
         // and should have gotten a scroll insensitive cursor
-        warning = conn.getWarnings();
-        assertNull(warning);
+        JDBC.assertNoWarnings(conn.getWarnings());
         conn.clearWarnings();
 
         // Verify that setMaxRows(-1) fails
@@ -570,7 +551,7 @@
         CallableStatement cs_i_r = null; // insensitive, read only
         CallableStatement cs_f_r = null; // forward only, read only
 
-        cs_s_r = conn.prepareCall("values cast (? as Integer)",
+        cs_s_r = prepareCall("values cast (? as Integer)",
                 ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
 
         // We should have gotten 1 warnings
@@ -581,12 +562,12 @@
         else
             assertEquals("01J10", warning.getSQLState());
 
-        assertNull(warning.getNextWarning());
+        JDBC.assertNoWarnings(warning.getNextWarning());
 
         conn.clearWarnings();
         cs_s_r.close();
 
-        cs_s_u = conn.prepareCall("values cast (? as Integer)",
+        cs_s_u = prepareCall("values cast (? as Integer)",
                 ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
 
         // We should have gotten 1 warning
@@ -597,26 +578,24 @@
         else
             assertEquals("01J10", warning.getSQLState());
 
-        assertNull(warning.getNextWarning());
+        JDBC.assertNoWarnings(warning.getNextWarning());
         conn.clearWarnings();
         cs_s_u.close();
 
-        cs_i_r = conn.prepareCall("values cast (? as Integer)",
+        cs_i_r = prepareCall("values cast (? as Integer)",
                 ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
 
         // We should have gotten 0 warnings
-        warning = conn.getWarnings();
-        assertNull(warning);
+        JDBC.assertNoWarnings(conn.getWarnings());
 
         conn.clearWarnings();
         cs_i_r.close();
 
-        cs_f_r = conn.prepareCall("values cast (? as Integer)",
+        cs_f_r = prepareCall("values cast (? as Integer)",
                 ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
 
         // We should have gotten 0 warnings
-        warning = conn.getWarnings();
-        assertNull(warning);
+        JDBC.assertNoWarnings(conn.getWarnings());
 
         conn.clearWarnings();
         cs_f_r.close();
@@ -630,14 +609,13 @@
      *                Thrown if some unexpected error happens
      */
     public void testGetMetaData() throws SQLException {
-        Connection conn = getConnection();
+
         PreparedStatement ps_f_r = null; // forward only, read only
         ResultSet rs;
         ResultSetMetaData rsmd_ps;
         ResultSetMetaData rsmd_rs;
-        SQLWarning warning;
 
-        ps_f_r = conn.prepareStatement("select c50, i, 43 from t",
+        ps_f_r = prepareStatement("select c50, i, 43 from t",
                 ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
 
         rsmd_ps = ps_f_r.getMetaData();
@@ -684,11 +662,9 @@
      */
     private void scrollVerifyMaxRowWithFetchSize(int maxRows, int fetchSize)
             throws SQLException {
-        Connection conn = getConnection();
+
         ResultSet rs;
-        boolean passed = true;
-        Statement s_i_r = null;
-        s_i_r = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
+        Statement s_i_r = createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
                 ResultSet.CONCUR_READ_ONLY);
         s_i_r.setMaxRows(maxRows);
 

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/UpdatableResultSetTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/UpdatableResultSetTest.java?rev=627203&r1=627202&r2=627203&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/UpdatableResultSetTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/UpdatableResultSetTest.java
Tue Feb 12 16:40:38 2008
@@ -847,8 +847,7 @@
         getConnection().clearWarnings();
         Statement stmt = createStatement(
                 ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE);
-        assertNull("FAIL - should not get a warning",
-                getConnection().getWarnings());
+        JDBC.assertNoWarnings(getConnection().getWarnings());
         assertEquals("FAIL - wrong result set type",
                 ResultSet.TYPE_FORWARD_ONLY, stmt.getResultSetType());
         assertEquals("FAIL - wrong result set concurrency",
@@ -905,8 +904,7 @@
         getConnection().clearWarnings();
         Statement stmt = createStatement(
                 ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE);
-        assertNull("FAIL - should not get a warning",
-                getConnection().getWarnings());
+        JDBC.assertNoWarnings(getConnection().getWarnings());
         ResultSet rs = stmt.executeQuery("SELECT * FROM t1 FOR UPDATE");
         assertTrue("FAIL - row not found", rs.next());
         
@@ -964,8 +962,7 @@
         getConnection().clearWarnings();
         Statement stmt = createStatement(
                 ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE);
-        assertNull("FAIL - should not get a warning",
-                getConnection().getWarnings());
+        JDBC.assertNoWarnings(getConnection().getWarnings());
         assertEquals("FAIL - wrong result set type",
                 ResultSet.TYPE_FORWARD_ONLY, stmt.getResultSetType());
         assertEquals("FAIL - wrong result set concurrency",
@@ -1019,8 +1016,7 @@
         getConnection().clearWarnings();
         Statement stmt = createStatement(
                 ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE);
-        assertNull("FAIL - should not get a warning",
-                getConnection().getWarnings());
+        JDBC.assertNoWarnings(getConnection().getWarnings());
         ResultSet rs = stmt.executeQuery("SELECT * FROM t1");
         assertTrue("FAIL - row not found", rs.next());
         

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/JDBC.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/JDBC.java?rev=627203&r1=627202&r2=627203&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/JDBC.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/JDBC.java Tue Feb 12 16:40:38
2008
@@ -508,6 +508,21 @@
     }
     
     /**
+     * Assert that no warnings were returned from a JDBC getWarnings()
+     * method such as Connection.getWarnings. Reports the contents
+     * of the warning if it is not null.
+     * @param warning Warning that should be null.
+     */
+    public static void assertNoWarnings(SQLWarning warning)
+    {
+        if (warning == null)
+            return;
+        
+        Assert.fail("Expected no SQLWarnings - got: " + warning.getSQLState() 
+                + " " + warning.getMessage());
+    }
+    
+    /**
      * Assert that the statement has no more results. Logic taken
      * from javadoc for java.sql.Statement.getMoreResults.
      * @param s Statement holding no results.



Mime
View raw message