harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From py...@apache.org
Subject svn commit: r483084 - in /harmony/enhanced/classlib/trunk/modules/sql/src: main/java/java/sql/ main/java/org/apache/harmony/sql/internal/nls/ test/java/org/apache/harmony/sql/tests/java/sql/
Date Wed, 06 Dec 2006 14:15:44 GMT
Author: pyang
Date: Wed Dec  6 06:15:43 2006
New Revision: 483084

URL: http://svn.apache.org/viewvc?view=rev&rev=483084
Log:
Fix compatibility issue: DriverManager.getConnection(String, String, String) should not throw
SQLException if given username/password is null. The original test cases cover this case,
but the mocked Driver did too much so that the DriverManager's behavior is overridden.

Modified:
    harmony/enhanced/classlib/trunk/modules/sql/src/main/java/java/sql/DriverManager.java
    harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/nls/messages.properties
    harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/DriverManagerTest.java
    harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/TestHelper_Driver1.java

Modified: harmony/enhanced/classlib/trunk/modules/sql/src/main/java/java/sql/DriverManager.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/java/sql/DriverManager.java?view=diff&rev=483084&r1=483083&r2=483084
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/main/java/java/sql/DriverManager.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/main/java/java/sql/DriverManager.java
Wed Dec  6 06:15:43 2006
@@ -203,13 +203,13 @@
      */
     public static Connection getConnection(String url, String user,
             String password) throws SQLException {
-        if (user == null || password == null) {
-            // sql.7=Userid and/or password not supplied
-            throw new SQLException(Messages.getString("sql.7")); //$NON-NLS-1$
-        }
         Properties theProperties = new Properties();
-        theProperties.setProperty("user", user); //$NON-NLS-1$
-        theProperties.setProperty("password", password); //$NON-NLS-1$
+        if(null != user){
+            theProperties.setProperty("user", user); //$NON-NLS-1$
+        }
+        if(null != password){
+            theProperties.setProperty("password", password); //$NON-NLS-1$
+        }
         return getConnection(url, theProperties);
     }
 

Modified: harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/nls/messages.properties
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/nls/messages.properties?view=diff&rev=483084&r1=483083&r2=483084
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/nls/messages.properties
(original)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/nls/messages.properties
Wed Dec  6 06:15:43 2006
@@ -22,7 +22,6 @@
 sql.4=Bad input string format: expected '.' not {0}
 sql.5=The url cannot be null
 sql.6=No suitable driver
-sql.7=Userid and/or password not supplied
 sql.8=SQLWarning chain holds value that is not a SQLWarning
 sql.9=Cannot instantiate a SerialRef object with a null Ref object
 sql.10=Cannot instantiate a SerialRef object that returns a null base type name

Modified: harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/DriverManagerTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/DriverManagerTest.java?view=diff&rev=483084&r1=483083&r2=483084
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/DriverManagerTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/DriverManagerTest.java
Wed Dec  6 06:15:43 2006
@@ -156,14 +156,15 @@
 	// invalid connection - URL is null
 	static String invalidConnectionURL3 = null;
 
-	static String[] invalidConnectionURLs = { invalidConnectionURL1,
-			invalidConnectionURL2, invalidConnectionURL3 };
+	static String[] invalidConnectionURLs = { invalidConnectionURL2,
+            invalidConnectionURL3 };
 
 	public void testGetConnectionString() throws SQLException {
 		Connection theConnection = null;
 		// validConnection - no user & password required
 		theConnection = DriverManager.getConnection(validConnectionURL);
 		assertNotNull(theConnection);
+        assertNotNull(DriverManager.getConnection(invalidConnectionURL1));
 
 		for (String element : invalidConnectionURLs) {
 			try {
@@ -216,10 +217,11 @@
 		Properties invalidProps1 = new Properties();
 		invalidProps1.setProperty("user", invaliduser1);
 		invalidProps1.setProperty("password", invalidpassword1);
-		String[] invalidURLs = { null, validURL1, validURL1, invalidURL1,
+		String[] invalidURLs = { null, invalidURL1,
 				invalidURL2, invalidURL3 };
-		Properties[] invalidProps = { validProps, nullProps, invalidProps1,
-				validProps, validProps, validProps };
+		Properties[] invalidProps = { nullProps, invalidProps1};
+        
+        
 
 		Connection theConnection = null;
 		// validConnection - user & password required
@@ -231,12 +233,15 @@
 			theConnection = null;
 			try {
 				theConnection = DriverManager.getConnection(invalidURLs[i],
-						invalidProps[i]);
+						validProps);
 				fail("Should throw SQLException");
 			} catch (SQLException e) {
                 //expected
 			} // end try
 		} // end for
+        for (Properties invalidProp : invalidProps) {
+            assertNotNull(DriverManager.getConnection(validURL1, invalidProp));
+        } 
 	} // end method testGetConnectionStringProperties()
 
 	/*
@@ -255,16 +260,15 @@
 		String[] invalid4 = { invalidURL1, validuser1, validpassword1 };
 		String[] invalid5 = { validURL1, invaliduser1, invalidpassword1 };
 		String[] invalid6 = { validURL1, validuser1, invalidpassword1 };
-		String[][] invalid = { invalid1, invalid2, invalid3, invalid4,
-				invalid5, invalid6 };
+		String[][] invalids1 = { invalid1, invalid4};
+        String[][] invalids2 = {invalid2, invalid3, invalid5, invalid6 };
 
 		Connection theConnection = null;
 		// validConnection - user & password required
         theConnection = DriverManager.getConnection(validURL1, validuser1,
                 validpassword1);
         assertNotNull(theConnection);
-
-		for (String[] theData : invalid) {
+		for (String[] theData : invalids1) {
 			theConnection = null;
 			try {
 				theConnection = DriverManager.getConnection(theData[0],
@@ -274,6 +278,10 @@
                 //expected
 			} // end try
 		} // end for
+        for (String[] theData : invalids2) {
+            assertNotNull(DriverManager.getConnection(theData[0], theData[1],
+                    theData[2]));
+        } 
 	} // end method testGetConnectionStringStringString()
 
 	static String validURL1 = "jdbc:mikes1";

Modified: harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/TestHelper_Driver1.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/TestHelper_Driver1.java?view=diff&rev=483084&r1=483083&r2=483084
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/TestHelper_Driver1.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/TestHelper_Driver1.java
Wed Dec  6 06:15:43 2006
@@ -85,21 +85,6 @@
                      * data1 which is set up not to require a user/password
                      * combination
                      */
-                    if (datasource.equals("data1")) {
-                        // do nothing...
-                    } else {
-                        if (info == null) {
-                            throw new SQLException("Properties bundle is null");
-                        }
-                        String user = (String) info.get(userProperty);
-                        String password = (String) info.get(passwordProperty);
-                        if (user == null || password == null) {
-                            throw new SQLException("Userid and/or password not supplied");
-                        }
-                        if (!user.equals(validuser) || !password.equals(validpassword)) {
-                            throw new SQLException("Userid and/or password not valid");
-                        } // end if
-                    } // end if
                     // It all checks out - so return a connection
                     Connection connection = new TestHelper_Connection1();
                     return connection;



Mime
View raw message