db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
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 GMT
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.
+	 * <BR>
+	 * 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();
 	}
 }



Mime
View raw message