db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kahat...@apache.org
Subject svn commit: r468296 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting: functionTests/master/ functionTests/suites/ functionTests/tests/jdbc4/ junit/
Date Fri, 27 Oct 2006 06:36:04 GMT
Author: kahatlen
Date: Thu Oct 26 23:36:03 2006
New Revision: 468296

URL: http://svn.apache.org/viewvc?view=rev&rev=468296
Log:
DERBY-1989: Convert jdbc4/TestDbMetaData.java to JUnit

The new TestDbMetaData tests everything the old one did, except for
the constants in JDBC40Translation. All but one of them are already
tested in JDBC40TranslationTest, and the patch adds the missing one to
that test.

The patch also makes a couple of small changes in junit/JDBC.java:

  * assertColumnNames:
      - declare it as "throws SQLException" instead of "throws
        Exception"
      - changed order in call to Assert.assertEquals() so that errors
        are not shown with expected/actual mixed up.

  * assertRowInResultSet:
      - since a result set can contain values that vary slightly from
        time to time (for instance, identifiers which contain
        timestamps), one needs a way to accept different values for a
        column. With a small change (only changing the order of a call
        to equals()), it was possible to give assertRowInResultSet()
        an object whose equals() method returned true for all
        acceptable values. This makes it possible to use
        assertRowInResultSet() where the old harness used sed scripts
        to filter out varying values.

Removed:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/TestDbMetaData.out
Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/DerbyNetClient.exclude
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/jdbc40.runall
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/JDBC40TranslationTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/README.html
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/TestDbMetaData.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/_Suite.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/JDBC.java

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/DerbyNetClient.exclude
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/DerbyNetClient.exclude?view=diff&rev=468296&r1=468295&r2=468296
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/DerbyNetClient.exclude
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/DerbyNetClient.exclude
Thu Oct 26 23:36:03 2006
@@ -10,15 +10,11 @@
 lang/errorStream.java
 # lang/scrollCursors2.java
 #
-# Currently, we exclude jdbc4/TestDbMetaData.java from the jdbc40 suite.
-# Eventually, we hope it will run under the network client.
-#
 jdbcapi/batchUpdate.java
 jdbcapi/statementJdbc20.java
 jdbcapi/statementJdbc30.java
 jdbcapi/dataSourceReference.java
 largedata/LobLimits.java
-jdbc4/TestDbMetaData.java
 #
 # This test brings the network server up and down by itself
 # and so should not be run with a competing server.

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/jdbc40.runall
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/jdbc40.runall?view=diff&rev=468296&r1=468295&r2=468296
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/jdbc40.runall
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/jdbc40.runall
Thu Oct 26 23:36:03 2006
@@ -1,5 +1,4 @@
 jdbc4/TestConnectionMethods.java
-jdbc4/TestDbMetaData.java
 jdbc4/TestPreparedStatementMethods.java
 jdbc4/TestResultSetMethods.java
 jdbc4/AutoloadBooting.junit

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/JDBC40TranslationTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/JDBC40TranslationTest.java?view=diff&rev=468296&r1=468295&r2=468296
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/JDBC40TranslationTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/JDBC40TranslationTest.java
Thu Oct 26 23:36:03 2006
@@ -51,6 +51,11 @@
                      JDBC40Translation.FUNCTION_PARAMETER_INOUT);
     }
 
+    public void testDatabaseMetaDataFUNCTION_PARAMETER_OUT() {
+        assertEquals(DatabaseMetaData.functionColumnOut,
+                     JDBC40Translation.FUNCTION_PARAMETER_OUT);
+    }
+
     public void testDatabaseMetaDataFUNCTION_RETURN() {
         assertEquals(DatabaseMetaData.functionReturn,
                      JDBC40Translation.FUNCTION_RETURN);

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/README.html
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/README.html?view=diff&rev=468296&r1=468295&r2=468296
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/README.html
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/README.html
Thu Oct 26 23:36:03 2006
@@ -32,14 +32,6 @@
 </ul>
 
 <p>
-Note that one of the tests in this suite
-(<i>jdbc4/TestDbMetaData.java</i>) is excluded from the
-<i>DerbyNetClient</i> run. Eventually, we hope to run this test
-under <i>DerbyNetClient</i>. At that time, we can remove this test
-from <i>suites/DerbyNetClient.exclude</i>.
-</p>
-
-<p>
 Before running these tests, you must first build the optional jkd16
 support as described in <i>trunk/BUILDING.txt</i>.
 </p>

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/TestDbMetaData.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/TestDbMetaData.java?view=diff&rev=468296&r1=468295&r2=468296
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/TestDbMetaData.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/TestDbMetaData.java
Thu Oct 26 23:36:03 2006
@@ -25,96 +25,38 @@
 import java.sql.DatabaseMetaData;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
-import java.sql.ResultSetMetaData;
 import java.sql.SQLException;
 import java.sql.Statement;
 
-import org.apache.derby.tools.ij;
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
 import org.apache.derbyTesting.functionTests.util.SQLStateConstants;
-import org.apache.derby.shared.common.reference.JDBC40Translation;
+import org.apache.derbyTesting.junit.BaseJDBCTestCase;
+import org.apache.derbyTesting.junit.CleanDatabaseTestSetup;
+import org.apache.derbyTesting.junit.JDBC;
 
 /**
  * Test of database metadata for new methods in JDBC 40.
  */
-public class TestDbMetaData { 
+public class TestDbMetaData extends BaseJDBCTestCase {
 
-	public static void main(String[] args) {
-		try
-		{
-			// use the ij utility to read the property file and
-			// make the initial connection.
-			ij.getPropertyArg(args);
-		
-			Connection	conn_main = ij.startJBMS();
+    private DatabaseMetaData meta;
 
-            runTests( conn_main );
-        }
-        catch (SQLException e) {
-            dumpSQLExceptions(e);
-        }
-        catch (Throwable e) {
-            System.out.println("FAIL -- unexpected exception:");
-            e.printStackTrace(System.out);
-        }
+    public TestDbMetaData(String name) {
+        super(name);
     }
 
-    // Run all the tests.
-    private static void runTests(Connection con) throws Exception {
-        testDatabaseMetaDataMethods(con);
-        testStoredProcEscapeSyntax(con);
-        testAutoCommitFailure(con);
-        con.close();
-    }
-
-    // Simply call each new metadata method and print the result.
-    private static void testDatabaseMetaDataMethods(Connection con)
-        throws Exception
-    {
-        con.setAutoCommit(true); // make sure it is true
-        Statement s = con.createStatement();
-        DatabaseMetaData met = con.getMetaData();
-
-        if (!met.supportsStoredFunctionsUsingCallSyntax()) {
-            System.out.println
-                ("FAIL: supportsStoredFunctionsUsingCallSyntax() " +
-                 "should return true");
-        }
-
-        if (met.autoCommitFailureClosesAllResultSets()) {
-            System.out.println
-                ("FAIL: autoCommitFailureClosesAllResultSets() " +
-                 "should return false");
-        }
+    protected void setUp() throws SQLException {
+        meta = getConnection().getMetaData();
+    }
 
-        checkEmptyRS(met.getClientInfoProperties());
+    protected void tearDown() throws Exception {
+        meta = null;
+        super.tearDown();
+    }
 
-		// Make sure the constants provided in JDBC40Translation is correct
-  		System.out.println(""+(JDBC40Translation.FUNCTION_PARAMETER_UNKNOWN == 
- 							   DatabaseMetaData.functionColumnUnknown));
-		System.out.println(""+(JDBC40Translation.FUNCTION_PARAMETER_IN == 
-							   DatabaseMetaData.functionColumnIn));
-		System.out.println(""+(JDBC40Translation.FUNCTION_PARAMETER_INOUT == 
-							   DatabaseMetaData.functionColumnInOut));
-		System.out.println(""+(JDBC40Translation.FUNCTION_PARAMETER_OUT == 
-							   DatabaseMetaData.functionColumnOut));
-		System.out.println(""+(JDBC40Translation.FUNCTION_RETURN == 
-							   DatabaseMetaData.functionReturn));
-    
-		System.out.println(""+(JDBC40Translation.FUNCTION_NO_NULLS ==
-							   DatabaseMetaData.functionNoNulls));
-		System.out.println(""+(JDBC40Translation.FUNCTION_NULLABLE ==
-							   DatabaseMetaData.functionNullable));
-		System.out.println(""+(JDBC40Translation.FUNCTION_NULLABLE_UNKNOWN ==
-							   DatabaseMetaData.functionNullableUnknown));
-
-		// Since JDBC40Translation cannot be accessed in queries in
-		// metadata.properties, the query has to use
-		// DatabaseMetaData.procedureNullable. Hence it is necessary
-		// to verify that that value of
-		// DatabaseMetaData.functionNullable is the same.
-		System.out.println(""+(DatabaseMetaData.functionNullable == 
-							   DatabaseMetaData.procedureNullable));
-		
+    private static void createFunctions(Statement s) throws SQLException {
         // Create some functions in the default schema (app) to make
         // the output from getFunctions() and getFunctionColumns
         // more interesting
@@ -130,67 +72,293 @@
         s.execute("CREATE FUNCTION DUMMY4 ( X VARCHAR(128), Y INTEGER ) "+
                   "RETURNS INTEGER PARAMETER STYLE JAVA NO SQL LANGUAGE "+
                   "JAVA EXTERNAL NAME 'java.some.func'");
+    }
+
+    public static Test suite() {
+        TestSuite testSuite = new TestSuite();
+        testSuite.addTestSuite(TestDbMetaData.class);
+        return new CleanDatabaseTestSetup(testSuite) {
+                protected void decorateSQL(Statement s) throws SQLException {
+                    createFunctions(s);
+                }
+            };
+    }
+
+    public void testSupportsStoredFunctionsUsingCallSyntax()
+            throws SQLException {
+        assertTrue(meta.supportsStoredFunctionsUsingCallSyntax());
+    }
+
+    public void testAutoCommitFailureClosesAllResultSets() throws SQLException {
+        assertFalse(meta.autoCommitFailureClosesAllResultSets());
+    }
+
+    public void testGetClientInfoProperties() throws SQLException {
+        ResultSet rs = meta.getClientInfoProperties();
+        JDBC.assertColumnNames(rs, new String[] {
+            "NAME", "MAX_LEN", "DEFAULT_VALUE", "DESCRIPTION" });
+        JDBC.assertDrainResults(rs, 0);
+    }
 
+    /**
+     * Since JDBC40Translation cannot be accessed in queries in
+     * metadata.properties, the query has to use
+     * DatabaseMetaData.procedureNullable. Hence it is necessary
+     * to verify that that value of
+     * DatabaseMetaData.functionNullable is the same.
+     */
+    public void testFunctionNullable() {
+        assertEquals(DatabaseMetaData.procedureNullable,
+                     DatabaseMetaData.functionNullable);
+    }
+
+    /** Check that the column names are as expected from getFunctions(). */
+    private void assertGetFunctionsRs(ResultSet rs) throws SQLException {
+        JDBC.assertColumnNames(rs, new String[] {
+            "FUNCTION_CAT", "FUNCTION_SCHEM", "FUNCTION_NAME", "REMARKS",
+            "SPECIFIC_NAME" });
+    }
+
+    /** Expected rows from getFunctions() when all functions match. */
+    private static final Object[][] ALL_FUNCTIONS = {
+        { null, "APP", "DUMMY1", "java.some.func", new GeneratedId() },
+        { null, "APP", "DUMMY2", "java.some.func", new GeneratedId() },
+        { null, "APP", "DUMMY3", "java.some.func", new GeneratedId() },
+        { null, "APP", "DUMMY4", "java.some.func", new GeneratedId() },
+        { null, "SYSCS_UTIL", "SYSCS_CHECK_TABLE",
+          "org.apache.derby.catalog.SystemProcedures.SYSCS_CHECK_TABLE",
+          new GeneratedId() },
+        { null, "SYSCS_UTIL", "SYSCS_GET_DATABASE_PROPERTY",
+          "org.apache.derby.catalog.SystemProcedures." +
+          "SYSCS_GET_DATABASE_PROPERTY", new GeneratedId() },
+        { null, "SYSCS_UTIL", "SYSCS_GET_RUNTIMESTATISTICS",
+          "org.apache.derby.catalog.SystemProcedures." +
+          "SYSCS_GET_RUNTIMESTATISTICS", new GeneratedId() },
+    };
+
+    public void testGetFunctionsNullNullNull() throws SQLException {
         // Any function in any schema in any catalog
-        dumpRS(met.getFunctions(null, null, null));
+        ResultSet rs = meta.getFunctions(null, null, null);
+        assertGetFunctionsRs(rs);
+        JDBC.assertFullResultSet(rs, ALL_FUNCTIONS, false);
+    }
+
+    public void testGetFunctionsDummySchema() throws SQLException {
         // Any function in any schema in "Dummy
         // Catalog". Same as above since the catalog
         // argument is ignored (is always null)
-        dumpRS(met.getFunctions("Dummy Catalog", null, null));
+        ResultSet rs = meta.getFunctions("Dummy Catalog", null, null);
+        assertGetFunctionsRs(rs);
+        JDBC.assertFullResultSet(rs, ALL_FUNCTIONS, false);
+    }
+
+    public void testGetFunctionsFromSysSchemas() throws SQLException {
         // Any function in a schema starting with "SYS"
-        dumpRS(met.getFunctions(null, "SYS%", null));
+        ResultSet rs = meta.getFunctions(null, "SYS%", null);
+        assertGetFunctionsRs(rs);
+        Object[][] sysFunctions = {
+            { null, "SYSCS_UTIL", "SYSCS_CHECK_TABLE",
+              "org.apache.derby.catalog.SystemProcedures.SYSCS_CHECK_TABLE",
+              new GeneratedId() },
+            { null, "SYSCS_UTIL", "SYSCS_GET_DATABASE_PROPERTY",
+              "org.apache.derby.catalog.SystemProcedures." +
+              "SYSCS_GET_DATABASE_PROPERTY", new GeneratedId() },
+            { null, "SYSCS_UTIL", "SYSCS_GET_RUNTIMESTATISTICS",
+              "org.apache.derby.catalog.SystemProcedures." +
+              "SYSCS_GET_RUNTIMESTATISTICS", new GeneratedId() },
+        };
+        JDBC.assertFullResultSet(rs, sysFunctions, false);
+    }
+
+    public void testGetFunctionsContainingGET() throws SQLException {
         // All functions containing "GET" in any schema 
         // (and any catalog)
-        dumpRS(met.getFunctions(null, null, "%GET%"));
+        ResultSet rs = meta.getFunctions(null, null, "%GET%");
+        assertGetFunctionsRs(rs);
+        Object[][] getFunctions = {
+            { null, "SYSCS_UTIL", "SYSCS_GET_DATABASE_PROPERTY",
+              "org.apache.derby.catalog.SystemProcedures." +
+              "SYSCS_GET_DATABASE_PROPERTY", new GeneratedId() },
+            { null, "SYSCS_UTIL", "SYSCS_GET_RUNTIMESTATISTICS",
+              "org.apache.derby.catalog.SystemProcedures." +
+              "SYSCS_GET_RUNTIMESTATISTICS", new GeneratedId() },
+        };
+        JDBC.assertFullResultSet(rs, getFunctions, false);
+    }
+
+    public void testGetFunctionsNoSchemaNoCatalog() throws SQLException {
         // Any function that belongs to NO schema and 
         // NO catalog (none)
-        checkEmptyRS(met.getFunctions("", "", null));
+        ResultSet rs = meta.getFunctions("", "", null);
+        assertGetFunctionsRs(rs);
+        JDBC.assertDrainResults(rs, 0);
+    }
+
+    /** Check that the column names are as expected from
+     * getFunctionColumns(). */
+    private void assertGetFunctionColumnsRs(ResultSet rs) throws SQLException {
+        JDBC.assertColumnNames(rs, new String[] {
+            "FUNCTION_CAT", "FUNCTION_SCHEM", "FUNCTION_NAME", "COLUMN_NAME",
+            "COLUMN_TYPE", "DATA_TYPE", "TYPE_NAME", "PRECISION", "LENGTH",
+            "SCALE", "RADIX", "NULLABLE", "REMARKS", "CHAR_OCTET_LENGTH",
+            "ORDINAL_POSITION", "IS_NULLABLE", "SPECIFIC_NAME",
+            "METHOD_ID", "PARAMETER_ID"
+        });
+    }
 
+    public void testGetFunctionColumnsStartingWithDUMMY() throws SQLException {
 		// Test getFunctionColumns
-		// Dump parameters for all functions beigging with DUMMY
-		dumpRS(met.getFunctionColumns(null,null,"DUMMY%",null));
-		
+        // Dump parameters for all functions beginning with DUMMY
+        ResultSet rs = meta.getFunctionColumns(null, null, "DUMMY%", null);
+        assertGetFunctionColumnsRs(rs);
+        Object[][] expectedRows = {
+            { null, "APP", "DUMMY1", "", new Integer(4), new Integer(5),
+              "SMALLINT", new Integer(5), new Integer(2), new Integer(0),
+              new Integer(10), new Integer(1), null, null, new Integer(0),
+              "YES", new GeneratedId(), new Integer(1), new Integer(-1) },
+            { null, "APP", "DUMMY1", "X", new Integer(1), new Integer(5),
+              "SMALLINT", new Integer(5), new Integer(2), new Integer(0),
+              new Integer(10), new Integer(1), null, null, new Integer(1),
+              "YES", new GeneratedId(), new Integer(1), new Integer(0) },
+            { null, "APP", "DUMMY2", "", new Integer(4), new Integer(4),
+              "INTEGER", new Integer(10), new Integer(4), new Integer(0),
+              new Integer(10), new Integer(1), null, null, new Integer(0),
+              "YES", new GeneratedId(), new Integer(2), new Integer(-1) },
+            { null, "APP", "DUMMY2", "X", new Integer(1), new Integer(4),
+              "INTEGER", new Integer(10), new Integer(4), new Integer(0),
+              new Integer(10), new Integer(1), null, null, new Integer(1),
+              "YES", new GeneratedId(), new Integer(2), new Integer(0) },
+            { null, "APP", "DUMMY2", "Y", new Integer(1), new Integer(5),
+              "SMALLINT", new Integer(5), new Integer(2), new Integer(0),
+              new Integer(10), new Integer(1), null, null, new Integer(2),
+              "YES", new GeneratedId(), new Integer(2), new Integer(1) },
+            { null, "APP", "DUMMY3", "", new Integer(4), new Integer(12),
+              "VARCHAR", new Integer(16), new Integer(32), null, null,
+              new Integer(1), null, 32, new Integer(0), "YES",
+              new GeneratedId(), new Integer(2), new Integer(-1) },
+            { null, "APP", "DUMMY3", "X", new Integer(1), new Integer(12),
+              "VARCHAR", new Integer(16), new Integer(32), null, null,
+              new Integer(1), null, 32, new Integer(1), "YES",
+              new GeneratedId(), new Integer(2), new Integer(0) },
+            { null, "APP", "DUMMY3", "Y", new Integer(1), new Integer(4),
+              "INTEGER", new Integer(10), new Integer(4), new Integer(0),
+              new Integer(10), new Integer(1), null, null, new Integer(2),
+              "YES", new GeneratedId(), new Integer(2), new Integer(1) },
+            { null, "APP", "DUMMY4", "", new Integer(4), new Integer(4),
+              "INTEGER", new Integer(10), new Integer(4), new Integer(0),
+              new Integer(10), new Integer(1), null, null, new Integer(0),
+              "YES", new GeneratedId(), new Integer(2), new Integer(-1) },
+            { null, "APP", "DUMMY4", "X", new Integer(1), new Integer(12),
+              "VARCHAR", new Integer(128), new Integer(256),
+              null, null, new Integer(1), null, 256, new Integer(1), "YES",
+              new GeneratedId(),
+              new Integer(2), new Integer(0) },
+            { null, "APP", "DUMMY4", "Y", new Integer(1), new Integer(4),
+              "INTEGER", new Integer(10), new Integer(4), new Integer(0),
+              new Integer(10), new Integer(1), null, null, new Integer(2),
+              "YES", new GeneratedId(), new Integer(2), new Integer(1) },
+        };
+        JDBC.assertFullResultSet(rs, expectedRows, false);
+    }
+
+    public void testGetFunctionColumnsForDummyFunctions() throws SQLException {
 		// Dump return value for all DUMMY functions
-		dumpRS(met.getFunctionColumns(null,null,"DUMMY%",""));
+        ResultSet rs = meta.getFunctionColumns(null, null, "DUMMY%", "");
+        assertGetFunctionColumnsRs(rs);
+        Object[][] expectedRows = {
+            { null, "APP", "DUMMY1", "", new Integer(4), new Integer(5),
+              "SMALLINT", new Integer(5), new Integer(2), new Integer(0),
+              new Integer(10), new Integer(1), null, null, new Integer(0),
+              "YES", new GeneratedId(), new Integer(1), new Integer(-1) },
+            { null, "APP", "DUMMY2", "", new Integer(4), new Integer(4),
+              "INTEGER", new Integer(10), new Integer(4), new Integer(0),
+              new Integer(10), new Integer(1), null, null, new Integer(0),
+              "YES", new GeneratedId(), new Integer(2), new Integer(-1) },
+            { null, "APP", "DUMMY3", "", new Integer(4), new Integer(12),
+              "VARCHAR", new Integer(16), new Integer(32),
+              null, null, new Integer(1), null, 32, new Integer(0), "YES",
+              new GeneratedId(),
+              new Integer(2), new Integer(-1) },
+            { null, "APP", "DUMMY4", "", new Integer(4), new Integer(4),
+              "INTEGER", new Integer(10), new Integer(4), new Integer(0),
+              new Integer(10), new Integer(1), null, null, new Integer(0),
+              "YES", new GeneratedId(), new Integer(2), new Integer(-1) },
+        };
+        JDBC.assertFullResultSet(rs, expectedRows, false);
+    }
+
+    /** Check that the column names are as expected from getSchemas(). */
+    private void assertGetSchemasRs(ResultSet rs) throws SQLException {
+        JDBC.assertColumnNames(rs, new String[] {
+            "TABLE_SCHEM", "TABLE_CATALOG" });
+    }
 
+    public void testGetSchemasNullNull() throws SQLException {
         // Test the new getSchemas() with no schema qualifiers
-        dumpRS(met.getSchemas(null, null));
+        ResultSet rs = meta.getSchemas(null, null);
+        assertGetSchemasRs(rs);
+        Object[][] expectedRows = {
+            { "APP", null },
+            { "NULLID", null },
+            { "SQLJ", null },
+            { "SYS", null },
+            { "SYSCAT", null },
+            { "SYSCS_DIAG", null },
+            { "SYSCS_UTIL", null },
+            { "SYSFUN", null },
+            { "SYSIBM", null },
+            { "SYSPROC", null },
+            { "SYSSTAT", null },
+        };
+        JDBC.assertFullResultSet(rs, expectedRows, false);
+    }
+
+    public void testGetSchemasStartingWithSYS() throws SQLException {
         // Test the new getSchemas() with a schema wildcard qualifier
-        dumpRS(met.getSchemas(null, "SYS%"));
+        ResultSet rs = meta.getSchemas(null, "SYS%");
+        assertGetSchemasRs(rs);
+        Object[][] expectedRows = {
+            { "SYS", null },
+            { "SYSCAT", null },
+            { "SYSCS_DIAG", null },
+            { "SYSCS_UTIL", null },
+            { "SYSFUN", null },
+            { "SYSIBM", null },
+            { "SYSPROC", null },
+            { "SYSSTAT", null },
+        };
+        JDBC.assertFullResultSet(rs, expectedRows, false);
+    }
+
+    public void testGetSchemasMatchingAPP() throws SQLException {
         // Test the new getSchemas() with an exact match
-        dumpRS(met.getSchemas(null, "APP"));
+        ResultSet rs = meta.getSchemas(null, "APP");
+        assertGetSchemasRs(rs);
+        Object[][] expectedRows = {
+            { "APP", null },
+        };
+        JDBC.assertFullResultSet(rs, expectedRows, false);
+    }
+
+    public void testGetSchemasMatchingBLAH() throws SQLException {
         // Make sure that getSchemas() returns an empty result
         // set when a schema is passed with no match
-        checkEmptyRS(met.getSchemas(null, "BLAH"));
-        
-        t_wrapper(met);
-        
-        s.close();
+        ResultSet rs = meta.getSchemas(null, "BLAH");
+        assertGetSchemasRs(rs);
+        JDBC.assertDrainResults(rs, 0);
     }
 
     /**
-     * <p>
-     * Return true if we're running under the embedded client.
-     * </p>
-     */
-    private	static	boolean	usingEmbeddedClient() {
-        return "embedded".equals( System.getProperty( "framework" ) );
-    }
-    
-    /**
      * Test supportsStoredFunctionsUsingCallSyntax() by checking
      * whether calling a stored procedure using the escape syntax
      * succeeds.
      *
-     * @param con <code>Connection</code> object used in test
      * @exception SQLException if an unexpected database error occurs
      */
-    private static void testStoredProcEscapeSyntax(Connection con)
-        throws SQLException
-    {
-        con.setAutoCommit(false);
+    public void testStoredProcEscapeSyntax() throws SQLException {
+        getConnection().setAutoCommit(false);
         String call = "{CALL SYSCS_UTIL.SYSCS_SET_RUNTIMESTATISTICS(0)}";
-        Statement stmt = con.createStatement();
+        Statement stmt = createStatement();
 
         boolean success;
         try {
@@ -200,15 +368,11 @@
             success = false;
         }
 
-        DatabaseMetaData dmd = con.getMetaData();
-        boolean supported = dmd.supportsStoredFunctionsUsingCallSyntax();
-        if (success != supported) {
-            System.out.println("supportsStoredFunctionsUsingCallSyntax() " +
-                               "returned " + supported + ", but executing " +
-                               call + (success ? " succeeded." : " failed."));
-        }
+        assertEquals("supportsStoredFunctionsUsingCallSyntax() returned " +
+                     "value which doesn't match actual behaviour.",
+                     success, meta.supportsStoredFunctionsUsingCallSyntax());
+
         stmt.close();
-        con.rollback();
     }
 
     /**
@@ -216,15 +380,10 @@
      * a failure in auto-commit mode will close all result sets, even
      * holdable ones.
      *
-     * @param con <code>Connection</code> object used in test
      * @exception SQLException if an unexpected database error occurs
      */
-    private static void testAutoCommitFailure(Connection con)
-        throws SQLException
-    {
-        DatabaseMetaData dmd = con.getMetaData();
-        boolean shouldBeClosed = dmd.autoCommitFailureClosesAllResultSets();
-
+    public void testAutoCommitFailure() throws SQLException {
+        Connection con = getConnection();
         con.setAutoCommit(true);
 
         Statement s1 =
@@ -238,148 +397,56 @@
             String query =
                 "SELECT dummy, nonexistent, phony FROM imaginarytable34521";
             s2.execute(query);
-            System.out.println("\"" + query + "\" is expected to fail, " +
-                               "but it didn't.");
+            fail("Query didn't fail.");
         } catch (SQLException e) {
             // should fail, but we don't care how
         }
 
-        boolean isClosed = resultSet.isClosed();
-        if (isClosed != shouldBeClosed) {
-            System.out.println("autoCommitFailureClosesAllResultSets() " +
-                               "returned " + shouldBeClosed +
-                               ", but ResultSet is " +
-                               (isClosed ? "closed." : "not closed."));
-        }
+        assertEquals("autoCommitFailureClosesAllResultSets() returned value " +
+                     "which doesn't match actual behaviour.",
+                     resultSet.isClosed(),
+                     meta.autoCommitFailureClosesAllResultSets());
+
         resultSet.close();
         s1.close();
         s2.close();
     }
 
-	static private void dumpSQLExceptions (SQLException se) {
-		System.out.println("FAIL -- unexpected exception");
-		while (se != null) {
-			System.out.print("SQLSTATE("+se.getSQLState()+"):");
-			se.printStackTrace(System.out);
-			se = se.getNextException();
-		}
-	}
-
-	static void dumpRS(ResultSet s) throws SQLException {
-		ResultSetMetaData rsmd = s.getMetaData ();
-
-		// Get the number of columns in the result set
-		int numCols = rsmd.getColumnCount ();
-
-		if (numCols <= 0) {
-			System.out.println("(no columns!)");
-			return;
-		}
-		
-		// Display column headings
-		for (int i=1; i<=numCols; i++) {
-			if (i > 1) System.out.print(",");
-			System.out.print(rsmd.getColumnLabel(i));
-		}
-		System.out.println();
-	
-		// Display data, fetching until end of the result set
-		while (s.next()) {
-			// Loop through each column, getting the
-			// column data and displaying
-			for (int i=1; i<=numCols; i++) {
-				if (i > 1) System.out.print(",");
-				System.out.print(s.getString(i));
-			}
-			System.out.println();
-		}
-		s.close();
-	}
-
-	/**
-	 * Checks for a ResultSet with no rows.
-	 *
-	 */
-	static void checkEmptyRS(ResultSet rs) throws Exception
-	{		
-		boolean passed = false;
-
-		try {
-			if ( rs == null )
-            {
-                throw new Exception("Metadata result set can not be null");
-            }
-            int numrows = 0;
-            while (rs.next())
-                numrows++;
-            // Zero rows is what we want.
-            if (numrows != 0) {
-                throw new Exception("Result set is not empty");
-            }
-		}
-		catch (SQLException e)
-		{
-			throw new Exception("Unexpected SQL Exception: " + e.getMessage(), e);
-		}
-	}
-        
-        
-    /**
-     * Tests the wrapper methods isWrapperFor and unwrap. There are two cases
-     * to be tested
-     * Case 1: isWrapperFor returns true and we call unwrap
-     * Case 2: isWrapperFor returns false and we call unwrap
-     *
-     * @param dmd The DatabaseMetaData object on which the wrapper methods are 
-     *           called
-     */
-        
-    static void t_wrapper(DatabaseMetaData dmd) {
-        //test for the case when isWrapper returns true
-        //Begin test for Case 1
-        Class<DatabaseMetaData> wrap_class = DatabaseMetaData.class;
-        
-        //The if succeeds and we call the unwrap method on the conn object        
+    public void testIsWrapperForPositive() throws SQLException {
+        assertTrue("DatabaseMetaData should be wrapper for itself.",
+                   meta.isWrapperFor(DatabaseMetaData.class));
+    }
+
+    public void testIsWrapperForNegative() throws SQLException {
+        assertFalse("DatabaseMetaData should not wrap PreparedStatement.",
+                    meta.isWrapperFor(PreparedStatement.class));
+    }
+
+    public void testGetWrapperPositive() throws SQLException {
+        DatabaseMetaData dmd = meta.unwrap(DatabaseMetaData.class);
+        assertSame("Unwrap should return same object.", meta, dmd);
+    }
+
+    public void testGetWrapperNegative() {
         try {
-            if(dmd.isWrapperFor(wrap_class)) {
-                DatabaseMetaData dmd1 = 
-                        (DatabaseMetaData)dmd.unwrap(wrap_class);
-            }
-            else {
-                System.out.println("isWrapperFor wrongly returns false");
-            }
-        }
-        catch(SQLException sqle) {
-            dumpSQLExceptions(sqle);
+            PreparedStatement ps = meta.unwrap(PreparedStatement.class);
+            fail("Unwrap should not return PreparedStatement.");
+        } catch (SQLException e) {
+            assertSQLState(SQLStateConstants.UNABLE_TO_UNWRAP, e);
         }
-        
-        //Begin the test for Case 2
-        //test for the case when isWrapper returns false
-        //using some class that will return false when 
-        //passed to isWrapperFor
-        
-        Class<PreparedStatement> wrap_class1 = PreparedStatement.class;
-        
-        try {
-            //returning false is the correct behaviour in this case
-            //Generate a message if it returns true
-            if(dmd.isWrapperFor(wrap_class1)) {
-                System.out.println("isWrapperFor wrongly returns true");
-            }
-            else {
-                PreparedStatement ps1 = (PreparedStatement)
-                                           dmd.unwrap(wrap_class1);
-                System.out.println("unwrap does not throw the expected " +
-                                   "exception");
-            }
+    }
+
+    /**
+     * Helper class whose <code>equals()</code> method returns
+     * <code>true</code> for all strings on this format: SQL061021105830900
+     */
+    private static class GeneratedId {
+        public boolean equals(Object o) {
+            return o instanceof String &&
+                ((String) o).matches("SQL[0-9]{15}");
         }
-        catch (SQLException sqle) {
-            //calling unwrap in this case throws an 
-            //SQLException ensure that the SQLException 
-            //has the correct SQLState
-            if(!SQLStateConstants.UNABLE_TO_UNWRAP.equals(sqle.getSQLState())) {
-                sqle.printStackTrace();
-            }
+        public String toString() {
+            return "xxxxGENERATED-IDxxxx";
         }
     }
 }

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/_Suite.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/_Suite.java?view=diff&rev=468296&r1=468295&r2=468296
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/_Suite.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/_Suite.java
Thu Oct 26 23:36:03 2006
@@ -64,6 +64,7 @@
 		suite.addTest(RowIdNotImplementedTest.suite());
 		suite.addTest(StatementEventsTest.suite());
 		suite.addTest(StatementTest.suite());
+		suite.addTest(TestDbMetaData.suite());
 		suite.addTest(TestJDBC40Exception.suite());
 		suite.addTestSuite(UnsupportedVetter.class);		
 		suite.addTest(XA40Test.suite());

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?view=diff&rev=468296&r1=468295&r2=468296
==============================================================================
--- 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 Thu Oct 26 23:36:03
2006
@@ -371,13 +371,13 @@
      * @param expectedColNames Array of expected column names.
      */
     public static void assertColumnNames(ResultSet rs,
-        String [] expectedColNames) throws Exception
+        String [] expectedColNames) throws SQLException
     {
         ResultSetMetaData rsmd = rs.getMetaData();
         int actualCols = rsmd.getColumnCount();
 
         Assert.assertEquals("Unexpected column count:",
-            rsmd.getColumnCount(), expectedColNames.length);
+            expectedColNames.length, rsmd.getColumnCount());
 
         for (int i = 0; i < actualCols; i++)
         {
@@ -455,10 +455,18 @@
      * array.  This means that the order of the columns in the result
      * set must match the order of the values in expectedRow.
      *
+     * <p>
      * If the expected value for a given row/column is a SQL NULL,
      * then the corresponding value in the array should be a Java
      * null.
      *
+     * <p>
+     * If a given row/column could have different values (for instance,
+     * because it contains a timestamp), the expected value of that
+     * row/column could be an object whose <code>equals()</code> method
+     * returns <code>true</code> for all acceptable values. (This does
+     * not work if one of the acceptable values is <code>null</code>.)
+     *
      * @param rs Result set whose current row we'll check.
      * @param rowNum Row number (w.r.t expected rows) that we're
      *  checking.
@@ -523,7 +531,7 @@
             ok = (rs.wasNull() && (expectedRow[i] == null))
                 || (!rs.wasNull()
                     && (expectedRow[i] != null)
-                    && obj.equals(expectedRow[i]));
+                    && expectedRow[i].equals(obj));
 
             if (!ok)
             {



Mime
View raw message