db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
Subject svn commit: r472707 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting: functionTests/tests/jdbcapi/DataSourcePropertiesTest.java junit/JDBCDataSource.java junit/TestConfiguration.java
Date Thu, 09 Nov 2006 00:00:17 GMT
Author: djd
Date: Wed Nov  8 16:00:17 2006
New Revision: 472707

URL: http://svn.apache.org/viewvc?view=rev&rev=472707
Log:
DERBY-2047 (partial) Expose the generic data source (bean) property setting method in JDBCDataSource
and change DataSourcePropertiesTest to use it as part of clean up to ensure clean separation
between
old harness code and JUnit code.

Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/DataSourcePropertiesTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/JDBCDataSource.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/TestConfiguration.java

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/DataSourcePropertiesTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/DataSourcePropertiesTest.java?view=diff&rev=472707&r1=472706&r2=472707
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/DataSourcePropertiesTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/DataSourcePropertiesTest.java
Wed Nov  8 16:00:17 2006
@@ -31,6 +31,7 @@
 import junit.framework.TestSuite;
 import org.apache.derbyTesting.functionTests.util.TestUtil;
 import org.apache.derbyTesting.junit.BaseJDBCTestCase;
+import org.apache.derbyTesting.junit.CleanDatabaseTestSetup;
 import org.apache.derbyTesting.junit.J2EEDataSource;
 import org.apache.derbyTesting.junit.JDBC;
 import org.apache.derbyTesting.junit.JDBCDataSource;
@@ -80,39 +81,7 @@
                 }
             }
         }
-        return suite;
-    }
-
-    // HELPER METHODS
-
-    /**
-     * Sets a property of a data source object.
-     *
-     * @param dataSource the data source
-     * @param name name of the property to set
-     * @param value property value
-     * @param type property type (useful for setting <code>null</code> or
-     * primitive types)
-     */
-    private void setDataSourceProperty(Object dataSource, String name,
-                                       Object value, Class type)
-        throws Exception
-    {
-        Method setter = dataSource.getClass().
-            getMethod(TestUtil.getSetterName(name), new Class[] { type });
-        setter.invoke(dataSource, new Object[] { value });
-    }
-
-    /**
-     * Sets a property of a data source object.
-     *
-     * @param dataSource the data source
-     * @param name name of the property to set
-     * @param value property value
-     */
-    private void setDataSourceProperty(Object dataSource, String name,
-                                       Object value) throws Exception {
-        setDataSourceProperty(dataSource, name, value, value.getClass());
+        return new CleanDatabaseTestSetup(suite);
     }
 
     // TEST METHODS
@@ -126,9 +95,8 @@
         throws Exception
     {
         DataSource ds = JDBCDataSource.getDataSource();
-        setDataSourceProperty(ds, "password", "mypassword");
-        setDataSourceProperty(ds, "attributesAsPassword", Boolean.TRUE,
-                              Boolean.TYPE);
+        JDBCDataSource.setBeanProperty(ds, "password",  "mypassword");
+        JDBCDataSource.setBeanProperty(ds, "attributesAsPassword", Boolean.TRUE);
         Connection c = ds.getConnection();
         c.close();
     }
@@ -143,10 +111,9 @@
     {
         ConnectionPoolDataSource ds =
             J2EEDataSource.getConnectionPoolDataSource();
-        setDataSourceProperty(ds, "password", "mypassword");
-        setDataSourceProperty(ds, "attributesAsPassword", Boolean.TRUE,
-                              Boolean.TYPE);
-        // DERBY-1586 caused a malformed url error here
+        JDBCDataSource.setBeanProperty(ds, "password",  "mypassword");
+        JDBCDataSource.setBeanProperty(ds, "attributesAsPassword", Boolean.TRUE);
+       // DERBY-1586 caused a malformed url error here
         PooledConnection pc = ds.getPooledConnection();
         Connection c = pc.getConnection();
         c.close();
@@ -161,9 +128,8 @@
         throws Exception
     {
         XADataSource ds = J2EEDataSource.getXADataSource();
-        setDataSourceProperty(ds, "password", "mypassword");
-        setDataSourceProperty(ds, "attributesAsPassword", Boolean.TRUE,
-                              Boolean.TYPE);
+        JDBCDataSource.setBeanProperty(ds, "password",  "mypassword");
+        JDBCDataSource.setBeanProperty(ds, "attributesAsPassword", Boolean.TRUE);
         XAConnection xa = ds.getXAConnection();
         Connection c = xa.getConnection();
         c.close();
@@ -178,8 +144,7 @@
         throws Exception
     {
         DataSource ds = JDBCDataSource.getDataSource();
-        setDataSourceProperty(ds, "attributesAsPassword", Boolean.TRUE,
-                              Boolean.TYPE);
+        JDBCDataSource.setBeanProperty(ds, "attributesAsPassword", Boolean.TRUE);
         try {
             Connection c = ds.getConnection("username", "mypassword");
             fail("Expected getConnection to fail.");
@@ -199,8 +164,7 @@
     {
         ConnectionPoolDataSource ds =
             J2EEDataSource.getConnectionPoolDataSource();
-        setDataSourceProperty(ds, "attributesAsPassword", Boolean.TRUE,
-                              Boolean.TYPE);
+        JDBCDataSource.setBeanProperty(ds, "attributesAsPassword", Boolean.TRUE);
         try {
             PooledConnection pc =
                 ds.getPooledConnection("username", "mypassword");
@@ -220,8 +184,7 @@
         throws Exception
     {
         XADataSource ds = J2EEDataSource.getXADataSource();
-        setDataSourceProperty(ds, "attributesAsPassword", Boolean.TRUE,
-                              Boolean.TYPE);
+        JDBCDataSource.setBeanProperty(ds, "attributesAsPassword", Boolean.TRUE);
         try {
             XAConnection xa = ds.getXAConnection("username", "mypassword");
             fail("Expected getXAConnection to fail.");

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/JDBCDataSource.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/JDBCDataSource.java?view=diff&rev=472707&r1=472706&r2=472707
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/JDBCDataSource.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/JDBCDataSource.java Wed
Nov  8 16:00:17 2006
@@ -107,7 +107,14 @@
         }
     }
     
-    static void setBeanProperty(Object ds, String property, Object value)
+    /**
+     * Set a bean property for a data source. This code can be used
+     * on any data source type.
+     * @param ds DataSource to have property set
+     * @param property name of property.
+     * @param value Value, type is derived from value's class.
+     */
+    public static void setBeanProperty(Object ds, String property, Object value)
     {
         String setterName = getSetterName(property);
         

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/TestConfiguration.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/TestConfiguration.java?view=diff&rev=472707&r1=472706&r2=472707
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/TestConfiguration.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/TestConfiguration.java
Wed Nov  8 16:00:17 2006
@@ -823,7 +823,7 @@
      * @param connAttrs connection attributes
      * @return
      */
-    public static Properties getDataSourcePropertiesForDatabase
+    private static Properties getDataSourcePropertiesForDatabase
     	(String databaseName, String connAttrs) 
     {
         Properties attrs = new Properties();



Mime
View raw message