db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fuzzylo...@apache.org
Subject svn commit: r387605 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests: tests/jdbcapi/ tests/junitTests/lang/ util/
Date Tue, 21 Mar 2006 19:27:38 GMT
Author: fuzzylogic
Date: Tue Mar 21 11:27:36 2006
New Revision: 387605

URL: http://svn.apache.org/viewcvs?rev=387605&view=rev
Log:
DERBY-993: Enable running junitTests in J2ME environments.

Committed for Myrna Van Lunteren <m.v.lunteren@gmail.com> and
Andreas Korneliussen <Andreas.Korneliussen@sun.com>

Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/SURBaseTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/SURDataModelSetup.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/junitTests/lang/BooleanTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/junitTests/lang/default_app.properties
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/BaseJDBCTestCase.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/BaseTestCase.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/TestUtil.java

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/SURBaseTest.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/SURBaseTest.java?rev=387605&r1=387604&r2=387605&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/SURBaseTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/SURBaseTest.java
Tue Mar 21 11:27:36 2006
@@ -18,12 +18,10 @@
  * language governing permissions and limitations under the License.
  */
 package org.apache.derbyTesting.functionTests.tests.jdbcapi;
-import org.apache.derbyTesting.functionTests.util.DerbyJUnitTest;
 import org.apache.derbyTesting.functionTests.util.TestUtil;
-import org.apache.derby.tools.ij;
+import org.apache.derbyTesting.functionTests.util.BaseJDBCTestCase;
 import junit.framework.*;
 import java.sql.*;
-import java.util.Properties;
 
 /**
  * Base class for testing Scrollable Updatable ResultSets. 
@@ -34,7 +32,7 @@
  * 
  * @author Andreas Korneliussen 
  */
-abstract public class SURBaseTest extends TestCase {
+abstract public class SURBaseTest extends BaseJDBCTestCase {
     
     /** Creates a new instance of SURBaseTest */
     public SURBaseTest(String name) {
@@ -62,19 +60,11 @@
         return rcon;
     }
 
-    static Connection getConnection() 
-        throws SQLException
-    {
-        String url = TestUtil.getJdbcUrlPrefix() + "wombat;create=true";
-        return DriverManager.getConnection(url);        
-    }
-    
     /**
      * Set up the connection to the database.
      */
     public void setUp() throws  Exception {       
         println("SetUp");
-        TestUtil.loadDriver();
         con = getNewConnection();
     }
     
@@ -296,17 +286,4 @@
     final static String RESULTSET_NOT_UPDATABLE_SQL_STATE = "XJ083";
     final static String LOCK_TIMEOUT_SQL_STATE = "40XL1";
     final static String LOCK_TIMEOUT_EXPRESSION_SQL_STATE = "38000";
-    
-    static void println(String text) {
-        DerbyJUnitTest.println(text);
-    }
-    
-    /**
-     * Prints the stack trace. If run in the harness, the
-     * harness will mark the test as failed if this method
-     * has been called.
-     */
-    static void printStackTrace(Throwable t) {
-        DerbyJUnitTest.printStackTrace(t);
-    }
 }

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/SURDataModelSetup.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/SURDataModelSetup.java?rev=387605&r1=387604&r2=387605&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/SURDataModelSetup.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/SURDataModelSetup.java
Tue Mar 21 11:27:36 2006
@@ -18,17 +18,16 @@
  * language governing permissions and limitations under the License.
  */
 package org.apache.derbyTesting.functionTests.tests.jdbcapi;
-import org.apache.derbyTesting.functionTests.util.DerbyJUnitTest;
+import org.apache.derbyTesting.functionTests.util.TestConfiguration;
 import org.apache.derbyTesting.functionTests.util.TestUtil;
+import org.apache.derbyTesting.functionTests.util.BaseJDBCTestCase;
 import java.sql.Connection;
-import java.sql.DriverManager;
 import java.sql.PreparedStatement;
 import java.sql.SQLException;
 import java.sql.Statement;
 import junit.extensions.TestSetup;
 import junit.framework.Test;
 import java.util.Set;
-import java.util.Iterator;
 import java.util.HashSet;
 import java.util.Arrays;
 import java.util.Collections;
@@ -40,6 +39,16 @@
  */
 public class SURDataModelSetup extends TestSetup
 {
+	
+	 /**
+     * Configuration for the test case.
+     * The configuration is created based on system properties.
+     *
+     * @see TestConfiguration
+     */
+    public static final TestConfiguration CONFIG = 
+        TestConfiguration.DERBY_TEST_CONFIG;
+    
     /**
      * Constructor.
      * @param test test to decorate with this setup
@@ -126,7 +135,6 @@
      * and populates the database model with data.
      */
     public void setUp() throws  Exception {       
-        TestUtil.loadDriver();
         println("Setting up datamodel: " + model);
         try {
             con = getNewConnection();
@@ -253,12 +261,12 @@
 
     /**
      * <p>
-     * Debug code to print chatty informational messages.
+     * Println code to print chatty informational messages.
      * </p>
      */
     public static void println(String text)
     {
-        DerbyJUnitTest.println(text);
+        BaseJDBCTestCase.println(text);
     }
     
     /**
@@ -267,7 +275,7 @@
      * has been called.
      */
     static void printStackTrace(Throwable t) {
-        DerbyJUnitTest.printStackTrace(t);
+        BaseJDBCTestCase.printStackTrace(t);
     }
     
     /**

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/junitTests/lang/BooleanTest.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/junitTests/lang/BooleanTest.java?rev=387605&r1=387604&r2=387605&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/junitTests/lang/BooleanTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/junitTests/lang/BooleanTest.java
Tue Mar 21 11:27:36 2006
@@ -33,6 +33,8 @@
 
 import junit.framework.*;
 
+import org.apache.derby.tools.ij;
+import org.apache.derbyTesting.functionTests.util.BigDecimalHandler;
 import org.apache.derbyTesting.functionTests.util.DerbyJUnitTest;
 
 public	class	BooleanTest	extends	DerbyJUnitTest
@@ -50,6 +52,14 @@
 	private	static	final	Boolean	FALSE = Boolean.FALSE;
 
 	private	static	final	String	NEGATE_BOOLEAN_FUNC = "negateBooleanFunc";
+    private static boolean HAVE_BIG_DECIMAL;
+	
+    static{
+    if(BigDecimalHandler.representation != BigDecimalHandler.BIGDECIMAL_REPRESENTATION)
+        HAVE_BIG_DECIMAL = false;
+    else
+        HAVE_BIG_DECIMAL = true;
+    }
 
 	/////////////////////////////////////////////////////////////
 	//
@@ -133,7 +143,7 @@
 	{
 		//setDebug( true );
 		
-		Connection	conn = getConnection();
+		Connection	conn = ij.startJBMS();
 
 		createSchema( conn );
 		populateTables( conn );
@@ -375,76 +385,172 @@
 			 "( 1, true ), ( 2, false ), ( 3, null )"
 			 );
 
-		PreparedStatement	ps = prepare
-			(
-			 conn,
-			 "select\n" +
-			 "keyCol\n" +
-			 ", cast ( booleanCol as smallint )\n" +
-			 ", cast ( booleanCol as integer )\n" +
-			 ", cast ( booleanCol as bigint )\n" +
-			 ",cast ( booleanCol as decimal )\n" +
-			 ",cast ( booleanCol as real )\n" +
-			 ",cast ( booleanCol as double )\n" +
-			 ",cast ( booleanCol as float )\n" +
-			 ",cast ( booleanCol as char(5) )\n" +
-			 ",cast ( booleanCol as varchar(5) )\n" +
-			 ",cast ( booleanCol as long varchar )\n" +
-			 ",cast ( booleanCol as clob )\n" +
-			 "from " + BOOLEAN_TABLE + " order by keyCol"
-			 );
+		PreparedStatement ps = null;
+		if (HAVE_BIG_DECIMAL)
+		{
+			ps = prepare
+			(
+				conn,
+				"select\n" +
+				"keyCol\n" +
+				", cast ( booleanCol as smallint )\n" +
+				", cast ( booleanCol as integer )\n" +
+				", cast ( booleanCol as bigint )\n" +
+				",cast ( booleanCol as decimal )\n" +
+				",cast ( booleanCol as real )\n" +
+				",cast ( booleanCol as double )\n" +
+				",cast ( booleanCol as float )\n" +
+				",cast ( booleanCol as char(5) )\n" +
+				",cast ( booleanCol as varchar(5) )\n" +
+				",cast ( booleanCol as long varchar )\n" +
+				",cast ( booleanCol as clob )\n" +
+				"from " + BOOLEAN_TABLE + " order by keyCol"
+			);
+		}
+		else
+		{
+			ps = prepare
+			(
+				conn,
+				"select\n" +
+				"keyCol\n" +
+				", cast ( booleanCol as smallint )\n" +
+				", cast ( booleanCol as integer )\n" +
+				", cast ( booleanCol as bigint )\n" +
+				",cast ( booleanCol as real )\n" +
+				",cast ( booleanCol as double )\n" +
+				",cast ( booleanCol as float )\n" +
+				",cast ( booleanCol as char(5) )\n" +
+				",cast ( booleanCol as varchar(5) )\n" +
+				",cast ( booleanCol as long varchar )\n" +
+				",cast ( booleanCol as clob )\n" +
+				"from " + BOOLEAN_TABLE + " order by keyCol"
+			);
+		}
+				
 		ResultSet			rs = ps.executeQuery();
 
 		rs.next();
-		assertRow
-			(
-			 rs,
-			 new Object[]
-				{
-					new Integer( 1 ),
-					new Integer( 1 ),
-					new Integer( 1 ),
-					new Long( 1L ),
-					new BigDecimal( 1.0 ),
-					new Float( 1.0 ),
-					new Double( 1.0 ),
-					new Float( 1.0 ),
-					"true ",
-					"true",
-					"true",
-					"true",
-				}
-			 );
+		if (HAVE_BIG_DECIMAL)
+		{
+			assertRow
+		    (
+		     rs,
+		     new Object[]
+			    {
+				    new Integer( 1 ),
+				    new Integer( 1 ),
+				    new Integer( 1 ),
+				    new Long( 1L ),
+				    new BigDecimal( 1.0 ),
+				    new Float( 1.0 ),
+				    new Double( 1.0 ),
+				    new Float( 1.0 ),
+				    "true ",
+				    "true",
+				    "true",
+				    "true",
+			    }
+		     );
+		}
+		else
+		{
+		    assertRow
+			    (
+			     rs,
+			     new Object[]
+				    {
+					    new Integer( 1 ),
+					    new Integer( 1 ),
+					    new Integer( 1 ),
+					    new Long( 1L ),
+					    new Float( 1.0 ),
+					    new Double( 1.0 ),
+					    new Float( 1.0 ),
+					    "true ",
+					    "true",
+					    "true",
+					    "true",
+				    }
+			     );
+		}
 
 		rs.next();
-		assertRow
-			(
-			 rs,
-			 new Object[]
-				{
-					new Integer( 2 ),
-					new Integer( 0 ),
-					new Integer( 0 ),
-					new Long( 0L ),
-					new BigDecimal( 0.0 ),
-					new Float( 0.0 ),
-					new Double( 0.0 ),
-					new Float( 0.0 ),
-					"false",
-					"false",
-					"false",
-					"false",
-				}
-			 );
-
+		if (HAVE_BIG_DECIMAL)
+		{
+			assertRow
+				(
+			     rs,
+			     new Object[]
+				    {
+			     		new Integer( 2 ),
+						new Integer( 0 ),
+						new Integer( 0 ),
+						new Long( 0L ),
+						new BigDecimal( 0.0 ),
+						new Float( 0.0 ),
+						new Double( 0.0 ),
+						new Float( 0.0 ),
+						"false",
+						"false",
+						"false",
+						"false",
+				    }
+				);
+		}
+		else
+		{
+			assertRow
+				(
+			     rs,
+			     new Object[]
+				    {
+			     		new Integer( 2 ),
+						new Integer( 0 ),
+						new Integer( 0 ),
+						new Long( 0L ),
+						new Float( 0.0 ),
+						new Double( 0.0 ),
+						new Float( 0.0 ),
+						"false",
+						"false",
+						"false",
+						"false",
+				    }
+				);
+		}
+		
 		rs.next();
-		assertRow
+		if (HAVE_BIG_DECIMAL)
+		{
+			assertRow
+				(
+				    rs,
+					new Object[]
+					{
+					    new Integer( 3 ),
+						null,
+						null,
+						null,
+						null,
+						null,
+						null,
+						null,
+						null,
+						null,
+						null,
+						null,
+					}
+				);
+		}
+		else
+		{
+			assertRow
 			(
-			 rs,
-			 new Object[]
+			    rs,
+				new Object[]
 				{
-					new Integer( 3 ),
-					null,
+				    new Integer( 3 ),
 					null,
 					null,
 					null,
@@ -456,8 +562,9 @@
 					null,
 					null,
 				}
-			 );
-
+			);
+		}
+	
 		close( rs );
 		close( ps );			 
 	}

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/junitTests/lang/default_app.properties
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/junitTests/lang/default_app.properties?rev=387605&r1=387604&r2=387605&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/junitTests/lang/default_app.properties
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/junitTests/lang/default_app.properties
Tue Mar 21 11:27:36 2006
@@ -26,5 +26,6 @@
 ij.showNoConnectionsAtStart=true
 ij.showNoCountForSelect=true
 
-# this test does not run with J2ME/JSR169
-runwithfoundation=false
+# DataSource properties, only used if ij.dataSource is set
+ij.dataSource.databaseName=wombat
+ij.dataSource.createDatabase=create

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/BaseJDBCTestCase.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/BaseJDBCTestCase.java?rev=387605&r1=387604&r2=387605&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/BaseJDBCTestCase.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/BaseJDBCTestCase.java
Tue Mar 21 11:27:36 2006
@@ -20,6 +20,8 @@
 package org.apache.derbyTesting.functionTests.util;
 
 import java.sql.*;
+import javax.sql.DataSource;
+import java.util.Properties;
 
 /**
  * Base class for JDBC JUnit tests.
@@ -73,10 +75,12 @@
                     CONFIG.getUserName(),
                     CONFIG.getUserPassword());
         } else {
-            throw new UnsupportedOperationException(
-                    "Creating a connection in a JSR-169 " +
-                    "environment is not yet supported. " +
-                    "Please implement :)");
+            //Use DataSource for JSR169
+            Properties prop = new Properties();
+            prop.setProperty("databaseName", CONFIG.getDatabaseName());
+            prop.setProperty("connectionAttributes", "create=true");
+            DataSource ds = TestUtil.getDataSource(prop);
+            con = ds.getConnection();
         }
         return con;
     }
@@ -133,4 +137,4 @@
         }
     }
 
-} // Enc class BaseJDBCTestCase
+} // End class BaseJDBCTestCase

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/BaseTestCase.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/BaseTestCase.java?rev=387605&r1=387604&r2=387605&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/BaseTestCase.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/BaseTestCase.java
Tue Mar 21 11:27:36 2006
@@ -20,7 +20,8 @@
 package org.apache.derbyTesting.functionTests.util;
 
 import junit.framework.TestCase;
-
+import java.io.PrintStream;
+import java.sql.SQLException;
 /**
  * Base class for JUnit tests.
  */
@@ -53,5 +54,42 @@
     public BaseTestCase(String name) {
         super(name);
     }
+    
+    /**
+     * Print alarm string
+     * @param text String to print
+     */
+    public static void alarm(final String text) {
+        out.println("ALARM: " + text);
+    }
+
+    /**
+     * Print debug string.
+     * @param text String to print
+     */
+    public static void println(final String text) {
+        if (CONFIG.isVerbose()) {
+            out.println("DEBUG: " + text);
+        }
+    }
+
+    /**
+     * Print debug string.
+     * @param t Throwable object to print stack trace from
+     */
+    public static void printStackTrace(Throwable t) 
+    {
+        while ( t!= null) {
+            t.printStackTrace(out);
+            
+            if (t instanceof SQLException)  {
+                t = ((SQLException) t).getNextException();
+            } else {
+                break;
+            }
+        }
+    }
+
+    private final static PrintStream out = System.out;
     
 } // End class BaseTestCase

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/TestUtil.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/TestUtil.java?rev=387605&r1=387604&r2=387605&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/TestUtil.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/TestUtil.java
Tue Mar 21 11:27:36 2006
@@ -790,7 +790,7 @@
                 if (framework == DERBY_NET_FRAMEWORK)
                 {
                     if (( connAttrs == null) || ((connAttrs != null) && (connAttrs.indexOf("user")
< 0)))
-                        url += ":" + "user=me;password=mine;retrieveMessagesFromServerOnGetMessage=true;";
+                        url += ":" + "user=APP;password=APP;retrieveMessagesFromServerOnGetMessage=true;";
                 }
                 conn = DriverManager.getConnection(url);
     	    }



Mime
View raw message