db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From krist...@apache.org
Subject svn commit: r1351212 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting: functionTests/tests/jdbcapi/DatabaseMetaDataTest.java junit/JDBC.java
Date Mon, 18 Jun 2012 06:18:03 GMT
Author: kristwaa
Date: Mon Jun 18 06:18:02 2012
New Revision: 1351212

URL: http://svn.apache.org/viewvc?rev=1351212&view=rev
Log:
DERBY-5764: Make DatabaseMetaDataTest more robust wrt changes made by other tests

Added some additional tests to test code paths where schema is set to null.
Added utility method JDBC.assertResultSetContains, used where the query may
return more rows due to data added by other tests but we still want to assert
that a specific subset of rows exists in the result.

Patch file: derby-5764-3b-add_test_case_schema_null.diff

Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/DatabaseMetaDataTest.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/DatabaseMetaDataTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/DatabaseMetaDataTest.java?rev=1351212&r1=1351211&r2=1351212&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/DatabaseMetaDataTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/DatabaseMetaDataTest.java
Mon Jun 18 06:18:02 2012
@@ -4098,7 +4098,7 @@ public class DatabaseMetaDataTest extend
         rs = getExportedKeys(null, schema, "REFTAB");
        assertFullResultSet(rs, expRS2, true);
 
-        rs = getExportedKeys(null, schema, "KT1");
+        rs = getExportedKeys(null, null, "KT1");
         assertFullResultSet(rs, expRS1, true);
 
         rs = getExportedKeys(null, "", "KT1");
@@ -4169,10 +4169,14 @@ public class DatabaseMetaDataTest extend
                 {"",schema,"KT1","VC10","",schema,"REFTAB2","T2_VC10","1","3","3","T2_FKEY1","PRIMKEY","7"},
                 {"",schema,"KT1","I","",schema,"REFTAB2","T2_I","2","3","3","T2_FKEY1","PRIMKEY","7"}};
         JDBC.assertFullResultSet(rs[1], expRS, true);
+        // Test also with null for schema.
+        rs = getCrossReference(null, null, "%", null, null, "%");
+        JDBC.assertEmpty(rs[0]);
+        JDBC.assertResultSetContains(rs[1], expRS);
         
         // tablename may not be null
         try {
-            rs[0] = dmd.getCrossReference(null, schema, null, null, schema, null);
+            rs[0] = dmd.getCrossReference(null, null, null, null, null, null);
             fail ("table name may not be null, should've given error");
         } catch (SQLException sqle) {
             if (usingDerbyNetClient())
@@ -4193,7 +4197,7 @@ public class DatabaseMetaDataTest extend
         }
         // tablename may not be null
         try {
-            rs[0] = dmd.getCrossReference(null, schema, "", null, schema, null);
+            rs[0] = dmd.getCrossReference(null, null, "", null, null, null);
             fail ("table name may not be null, should've given error");
         } catch (SQLException sqle) {
             if (usingDerbyNetClient())

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=1351212&r1=1351211&r2=1351212&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 Mon Jun 18 06:18:02
2012
@@ -1304,9 +1304,46 @@ public class JDBC {
     public static void assertUnorderedResultSet(
             ResultSet rs, Object[][] expectedRows, boolean asTrimmedStrings)
                 throws SQLException {
+        assertRSContains(rs, expectedRows, asTrimmedStrings, true);
+    }
+
+    /**
+     * Asserts that the {@code ResultSet} contains the rows specified by the
+     * two-dimensional array.
+     * <p>
+     * The order of the rows are ignored, and there may be more rows in the
+     * result set than in the array. All values are compared as trimmed strings.
+     *
+     * @param rs the result set to check
+     * @param expectedRows the rows that must exist in the result set
+     * @throws SQLException if accessing the result set fails
+     */
+    public static void assertResultSetContains(
+                ResultSet rs, Object[][] expectedRows)
+            throws SQLException {
+        assertRSContains(rs, expectedRows, true, false);
+    }
 
+    /**
+     * Asserts that the {@code ResultSet} contains the rows specified by the
+     * two-dimensional array.
+     *
+     * @param rs the result set to check
+     * @param expectedRows the rows that must exist in the result set
+     * @param asTrimmedStrings whether the objects should be compared as
+     *      trimmed strings
+     * @param rowCountsMustMatch whether the number of rows must be the same in
+     *      the result set and the array of expected rows
+     * @throws SQLException if accessing the result set fails
+     */
+    private static void assertRSContains(
+                ResultSet rs, Object[][] expectedRows, boolean asTrimmedStrings,
+                boolean rowCountsMustMatch)
+            throws SQLException {
         if (expectedRows.length == 0) {
-            assertEmpty(rs);
+            if (rowCountsMustMatch) {
+                assertEmpty(rs);
+            }
             return;
         }
 
@@ -1346,13 +1383,12 @@ public class JDBC {
         }
         rs.close();
 
-        Assert.assertEquals("Unexpected row count",
-                            expectedRows.length, actual.size());
+        if (rowCountsMustMatch) {
+            Assert.assertEquals("Unexpected row count",
+                                expectedRows.length, actual.size());
+        }
         Assert.assertTrue("Missing rows in ResultSet",
                           actual.containsAll(expected));
-
-        actual.removeAll(expected);
-        Assert.assertTrue("Extra rows in ResultSet", actual.isEmpty());
     }
 
     /**



Mime
View raw message