Return-Path: Delivered-To: apmail-db-derby-commits-archive@www.apache.org Received: (qmail 97532 invoked from network); 27 Jul 2006 00:47:05 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 27 Jul 2006 00:47:05 -0000 Received: (qmail 91904 invoked by uid 500); 27 Jul 2006 00:47:05 -0000 Delivered-To: apmail-db-derby-commits-archive@db.apache.org Received: (qmail 91872 invoked by uid 500); 27 Jul 2006 00:47:05 -0000 Mailing-List: contact derby-commits-help@db.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: "Derby Development" List-Id: Delivered-To: mailing list derby-commits@db.apache.org Received: (qmail 91861 invoked by uid 99); 27 Jul 2006 00:47:05 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 26 Jul 2006 17:47:05 -0700 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: local policy) Received: from [140.211.166.113] (HELO eris.apache.org) (140.211.166.113) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 26 Jul 2006 17:47:04 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id 57E081A981A; Wed, 26 Jul 2006 17:46:44 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r425923 - /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/JDBC.java Date: Thu, 27 Jul 2006 00:46:44 -0000 To: derby-commits@db.apache.org From: djd@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20060727004644.57E081A981A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: djd Date: Wed Jul 26 17:46:43 2006 New Revision: 425923 URL: http://svn.apache.org/viewvc?rev=425923&view=rev Log: Add some JUnit JDBC utility methods, compare the meta data for a select list with DatabaseMetaData and a method to drain a ResultSet. Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/JDBC.java Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/JDBC.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/JDBC.java?rev=425923&r1=425922&r2=425923&view=diff ============================================================================== --- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/JDBC.java (original) +++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/JDBC.java Wed Jul 26 17:46:43 2006 @@ -21,6 +21,8 @@ import java.sql.*; +import junit.framework.Assert; + /** * JDBC utility methods for the JUnit tests. * @@ -62,5 +64,69 @@ sqle.setNextException(e); throw sqle; } + } + + /** + * Assert all columns in the ResultSetMetaData match the + * table's defintion through DatabaseMetadDta. Only works + * if the complete select list correspond to columns from + * base tables. + *
+ * Does not require that the complete set of any table's columns are + * returned. + * @throws SQLException + * + */ + public static void assertMetaDataMatch(DatabaseMetaData dmd, + ResultSetMetaData rsmd) throws SQLException + { + for (int col = 1; col <= rsmd.getColumnCount(); col++) + { + // Only expect a single column back + ResultSet column = dmd.getColumns( + rsmd.getCatalogName(col), + rsmd.getSchemaName(col), + rsmd.getTableName(col), + rsmd.getColumnName(col)); + + Assert.assertTrue("Column missing " + rsmd.getColumnName(col), + column.next()); + + Assert.assertEquals(column.getInt("DATA_TYPE"), + rsmd.getColumnType(col)); + + Assert.assertEquals(column.getInt("NULLABLE"), + rsmd.isNullable(col)); + + Assert.assertEquals(column.getString("TYPE_NAME"), + rsmd.getColumnTypeName(col)); + + column.close(); + } + } + + /** + * Drain a single ResultSet by reading all of its + * rows and columns. Each column is accessed using + * getString() and asserted that the returned value + * matches the state of ResultSet.wasNull(). + * Provides simple testing of the ResultSet when then contents + * are not important. + * @param rs + * @throws SQLException + */ + public static void assertDrainResults(ResultSet rs) + throws SQLException + { + ResultSetMetaData rsmd = rs.getMetaData(); + + while (rs.next()) { + for (int col = 1; col <= rsmd.getColumnCount(); col++) + { + String s = rs.getString(col); + Assert.assertEquals(s == null, rs.wasNull()); + } + } + rs.close(); } }