commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nia...@apache.org
Subject svn commit: r556003 - in /jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils: TestResultSet.java TestResultSetMetaData.java
Date Fri, 13 Jul 2007 14:02:10 GMT
Author: niallp
Date: Fri Jul 13 07:02:09 2007
New Revision: 556003

URL: http://svn.apache.org/viewvc?view=rev&rev=556003
Log:
Improve the test (proxy) ResultSet and ResultSetMetaData implementations:
- Provide ability to specify the ResultSetMetaData impl used by TestResultSet
- enable getObject(index) to work in TestResultSet
- Add a static proxy factory method to TestResultSetMetaData that allows the invocation handler
to be specified

Modified:
    jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/TestResultSet.java
    jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/TestResultSetMetaData.java

Modified: jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/TestResultSet.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/TestResultSet.java?view=diff&rev=556003&r1=556002&r2=556003
==============================================================================
--- jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/TestResultSet.java
(original)
+++ jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/TestResultSet.java
Fri Jul 13 07:02:09 2007
@@ -67,6 +67,10 @@
      */
     protected long timestamp = System.currentTimeMillis();
 
+    /**
+     * Meta data for the result set.
+     */
+    protected ResultSetMetaData resultSetMetaData;
 
     /**
      * Factory method for creating {@link ResultSet} proxies.
@@ -74,11 +78,37 @@
      * @return A result set proxy
      */
     public static ResultSet createProxy() {
+        return TestResultSet.createProxy(TestResultSetMetaData.createProxy());
+    }
+
+    /**
+     * Factory method for creating {@link ResultSet} proxies.
+     *
+     * @param resultSetMetaData The result set meta data
+     * @return A result set proxy
+     */
+    public static ResultSet createProxy(ResultSetMetaData resultSetMetaData) {
         ClassLoader classLoader = ResultSet.class.getClassLoader();
         Class[] interfaces = new Class[] { ResultSet.class };
-        InvocationHandler invocationHandler = new TestResultSet();
+        InvocationHandler invocationHandler = new TestResultSet(resultSetMetaData);
         return (ResultSet)Proxy.newProxyInstance(classLoader, interfaces, invocationHandler);
     }
+    
+    /**
+     * Create a proxy ResultSet.
+     */
+    public TestResultSet() {
+        this(TestResultSetMetaData.createProxy());
+    }
+    
+    /**
+     * Create a proxy ResultSet with the specified meta data.
+     *
+     * @param resultSetMetaData The result set meta data
+     */
+    public TestResultSet(ResultSetMetaData resultSetMetaData) {
+        this.resultSetMetaData = resultSetMetaData;
+    }
 
     /**
      * Handles method invocation on the ResultSet proxy. 
@@ -96,7 +126,13 @@
         } if ("getMetaData".equals(methodName)) {
             return getMetaData();
         } if ("getObject".equals(methodName)) {
-            return getObject((String)args[0]);
+            String columnName = null;
+            if (args[0] instanceof Integer) {
+                columnName = resultSetMetaData.getColumnName(((Integer)args[0]).intValue());
+            } else {
+                columnName = (String)args[0];
+            }
+            return getObject(columnName);
         } if ("next".equals(methodName)) {
             return (next() ? Boolean.TRUE : Boolean.FALSE);
         } if ("updateObject".equals(methodName)) {
@@ -117,7 +153,7 @@
 
 
     public ResultSetMetaData getMetaData() throws SQLException {
-        return TestResultSetMetaData.createProxy();
+        return resultSetMetaData;
     }
 
 

Modified: jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/TestResultSetMetaData.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/TestResultSetMetaData.java?view=diff&rev=556003&r1=556002&r2=556003
==============================================================================
--- jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/TestResultSetMetaData.java
(original)
+++ jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/TestResultSetMetaData.java
Fri Jul 13 07:02:09 2007
@@ -29,7 +29,7 @@
 /**
  * <p>Mock object that implements enough of
  * <code>java.sql.ResultSetMetaData</code>
- * to exercise the {@link ResultSetDyaClass} functionality.</p>
+ * to exercise the {@link ResultSetDynaClass} functionality.</p>
  *
  * @author Craig R. McClanahan
  * @version $Revision$ $Date$
@@ -45,19 +45,19 @@
      * <p>Array of column names and class names for metadata.</p>
      */
     protected String metadata[][] = {
-        { "bigDecimalProperty", "java.math.BigDecimal" },
+        { "bigDecimalProperty", java.math.BigDecimal.class.getName() },
         { "booleanProperty", Boolean.class.getName() },
         { "byteProperty", Byte.class.getName() },
-        { "dateProperty", "java.sql.Date" },
+        { "dateProperty", java.sql.Date.class.getName() },
         { "doubleProperty", Double.class.getName() },
         { "floatProperty", Float.class.getName() },
         { "intProperty", Integer.class.getName() },
         { "longProperty", Long.class.getName() },
-        { "nullProperty", "java.lang.String" },
+        { "nullProperty", String.class.getName() },
         { "shortProperty", Short.class.getName() },
-        { "stringProperty", "java.lang.String" },
-        { "timeProperty", "java.sql.Time" },
-        { "timestampProperty", "java.sql.Timestamp" },
+        { "stringProperty", String.class.getName() },
+        { "timeProperty", java.sql.Time.class.getName() },
+        { "timestampProperty", java.sql.Timestamp.class.getName() },
     };
 
 
@@ -67,9 +67,17 @@
      * @return A result set meta data proxy
      */
     public static ResultSetMetaData createProxy() {
+        return TestResultSetMetaData.createProxy(new TestResultSetMetaData());
+    }
+
+    /**
+     * Factory method for creating {@link ResultSetMetaData} proxies.
+     * @param invocationHandler Invocation Handler
+     * @return A result set meta data proxy
+     */
+    public static ResultSetMetaData createProxy(InvocationHandler invocationHandler) {
         ClassLoader classLoader = ResultSetMetaData.class.getClassLoader();
         Class[] interfaces = new Class[] { ResultSetMetaData.class };
-        InvocationHandler invocationHandler = new TestResultSetMetaData();
         return (ResultSetMetaData)Proxy.newProxyInstance(classLoader, interfaces, invocationHandler);
     }
 



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message