harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From smish...@apache.org
Subject svn commit: r436644 [2/6] - /incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/
Date Fri, 25 Aug 2006 04:29:36 GMT
Modified: incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/DatabaseMetaDataTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/DatabaseMetaDataTest.java?rev=436644&r1=436643&r2=436644&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/DatabaseMetaDataTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/DatabaseMetaDataTest.java Thu Aug 24 21:29:34 2006
@@ -1,117 +1,117 @@
-/* Copyright 2004 The Apache Software Foundation or its licensors, as applicable
- * 
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- *     http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.sql.tests.java.sql;
-
-import java.lang.reflect.Field;
-import java.lang.reflect.Modifier;
-import java.util.HashMap;
-
-import junit.framework.TestCase;
-
-public class DatabaseMetaDataTest extends TestCase {
-
-	/*
-	 * Public statics test
-	 */
-	public void testPublicStatics() {
-
-		HashMap thePublicStatics = new HashMap();
-		thePublicStatics.put("sqlStateSQL99", new Integer(2));
-		thePublicStatics.put("sqlStateXOpen", new Integer(1));
-		thePublicStatics.put("attributeNullableUnknown", new Short((short) 2));
-		thePublicStatics.put("attributeNullable", new Short((short) 1));
-		thePublicStatics.put("attributeNoNulls", new Short((short) 0));
-		thePublicStatics.put("tableIndexOther", new Short((short) 3));
-		thePublicStatics.put("tableIndexHashed", new Short((short) 2));
-		thePublicStatics.put("tableIndexClustered", new Short((short) 1));
-		thePublicStatics.put("tableIndexStatistic", new Short((short) 0));
-		thePublicStatics.put("typeSearchable", new Integer(3));
-		thePublicStatics.put("typePredBasic", new Integer(2));
-		thePublicStatics.put("typePredChar", new Integer(1));
-		thePublicStatics.put("typePredNone", new Integer(0));
-		thePublicStatics.put("typeNullableUnknown", new Integer(2));
-		thePublicStatics.put("typeNullable", new Integer(1));
-		thePublicStatics.put("typeNoNulls", new Integer(0));
-		thePublicStatics.put("importedKeyNotDeferrable", new Integer(7));
-		thePublicStatics.put("importedKeyInitiallyImmediate", new Integer(6));
-		thePublicStatics.put("importedKeyInitiallyDeferred", new Integer(5));
-		thePublicStatics.put("importedKeySetDefault", new Integer(4));
-		thePublicStatics.put("importedKeyNoAction", new Integer(3));
-		thePublicStatics.put("importedKeySetNull", new Integer(2));
-		thePublicStatics.put("importedKeyRestrict", new Integer(1));
-		thePublicStatics.put("importedKeyCascade", new Integer(0));
-		thePublicStatics.put("versionColumnPseudo", new Integer(2));
-		thePublicStatics.put("versionColumnNotPseudo", new Integer(1));
-		thePublicStatics.put("versionColumnUnknown", new Integer(0));
-		thePublicStatics.put("bestRowPseudo", new Integer(2));
-		thePublicStatics.put("bestRowNotPseudo", new Integer(1));
-		thePublicStatics.put("bestRowUnknown", new Integer(0));
-		thePublicStatics.put("bestRowSession", new Integer(2));
-		thePublicStatics.put("bestRowTransaction", new Integer(1));
-		thePublicStatics.put("bestRowTemporary", new Integer(0));
-		thePublicStatics.put("columnNullableUnknown", new Integer(2));
-		thePublicStatics.put("columnNullable", new Integer(1));
-		thePublicStatics.put("columnNoNulls", new Integer(0));
-		thePublicStatics.put("procedureNullableUnknown", new Integer(2));
-		thePublicStatics.put("procedureNullable", new Integer(1));
-		thePublicStatics.put("procedureNoNulls", new Integer(0));
-		thePublicStatics.put("procedureColumnResult", new Integer(3));
-		thePublicStatics.put("procedureColumnReturn", new Integer(5));
-		thePublicStatics.put("procedureColumnOut", new Integer(4));
-		thePublicStatics.put("procedureColumnInOut", new Integer(2));
-		thePublicStatics.put("procedureColumnIn", new Integer(1));
-		thePublicStatics.put("procedureColumnUnknown", new Integer(0));
-		thePublicStatics.put("procedureReturnsResult", new Integer(2));
-		thePublicStatics.put("procedureNoResult", new Integer(1));
-		thePublicStatics.put("procedureResultUnknown", new Integer(0));
-
-		Class databaseMetaDataClass;
-		try {
-			databaseMetaDataClass = Class.forName("java.sql.DatabaseMetaData");
-		} catch (ClassNotFoundException e) {
-			fail("java.sql.DatabaseMetaData class not found!");
-			return;
-		} // end try
-
-		Field[] theFields = databaseMetaDataClass.getDeclaredFields();
-		int requiredModifier = Modifier.PUBLIC + Modifier.STATIC
-				+ Modifier.FINAL;
-
-		int countPublicStatics = 0;
-		for (int i = 0; i < theFields.length; i++) {
-			String fieldName = theFields[i].getName();
-			int theMods = theFields[i].getModifiers();
-			if (Modifier.isPublic(theMods) && Modifier.isStatic(theMods)) {
-				try {
-					Object fieldValue = theFields[i].get(null);
-					Object expectedValue = thePublicStatics.get(fieldName);
-					if (expectedValue == null) {
-						fail("Field " + fieldName + " missing!");
-					} // end
-					assertEquals("Field " + fieldName + " value mismatch: ",
-							expectedValue, fieldValue);
-					assertEquals("Field " + fieldName + " modifier mismatch: ",
-							requiredModifier, theMods);
-					countPublicStatics++;
-				} catch (IllegalAccessException e) {
-					fail("Illegal access to Field " + fieldName);
-				} // end try
-			} // end if
-		} // end for
-
-	} // end method testPublicStatics
-
-} // end class DatabaseMetaDataTest
+/* Copyright 2004 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.harmony.sql.tests.java.sql;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
+import java.util.HashMap;
+
+import junit.framework.TestCase;
+
+public class DatabaseMetaDataTest extends TestCase {
+
+	/*
+	 * Public statics test
+	 */
+	public void testPublicStatics() {
+
+		HashMap thePublicStatics = new HashMap();
+		thePublicStatics.put("sqlStateSQL99", new Integer(2));
+		thePublicStatics.put("sqlStateXOpen", new Integer(1));
+		thePublicStatics.put("attributeNullableUnknown", new Short((short) 2));
+		thePublicStatics.put("attributeNullable", new Short((short) 1));
+		thePublicStatics.put("attributeNoNulls", new Short((short) 0));
+		thePublicStatics.put("tableIndexOther", new Short((short) 3));
+		thePublicStatics.put("tableIndexHashed", new Short((short) 2));
+		thePublicStatics.put("tableIndexClustered", new Short((short) 1));
+		thePublicStatics.put("tableIndexStatistic", new Short((short) 0));
+		thePublicStatics.put("typeSearchable", new Integer(3));
+		thePublicStatics.put("typePredBasic", new Integer(2));
+		thePublicStatics.put("typePredChar", new Integer(1));
+		thePublicStatics.put("typePredNone", new Integer(0));
+		thePublicStatics.put("typeNullableUnknown", new Integer(2));
+		thePublicStatics.put("typeNullable", new Integer(1));
+		thePublicStatics.put("typeNoNulls", new Integer(0));
+		thePublicStatics.put("importedKeyNotDeferrable", new Integer(7));
+		thePublicStatics.put("importedKeyInitiallyImmediate", new Integer(6));
+		thePublicStatics.put("importedKeyInitiallyDeferred", new Integer(5));
+		thePublicStatics.put("importedKeySetDefault", new Integer(4));
+		thePublicStatics.put("importedKeyNoAction", new Integer(3));
+		thePublicStatics.put("importedKeySetNull", new Integer(2));
+		thePublicStatics.put("importedKeyRestrict", new Integer(1));
+		thePublicStatics.put("importedKeyCascade", new Integer(0));
+		thePublicStatics.put("versionColumnPseudo", new Integer(2));
+		thePublicStatics.put("versionColumnNotPseudo", new Integer(1));
+		thePublicStatics.put("versionColumnUnknown", new Integer(0));
+		thePublicStatics.put("bestRowPseudo", new Integer(2));
+		thePublicStatics.put("bestRowNotPseudo", new Integer(1));
+		thePublicStatics.put("bestRowUnknown", new Integer(0));
+		thePublicStatics.put("bestRowSession", new Integer(2));
+		thePublicStatics.put("bestRowTransaction", new Integer(1));
+		thePublicStatics.put("bestRowTemporary", new Integer(0));
+		thePublicStatics.put("columnNullableUnknown", new Integer(2));
+		thePublicStatics.put("columnNullable", new Integer(1));
+		thePublicStatics.put("columnNoNulls", new Integer(0));
+		thePublicStatics.put("procedureNullableUnknown", new Integer(2));
+		thePublicStatics.put("procedureNullable", new Integer(1));
+		thePublicStatics.put("procedureNoNulls", new Integer(0));
+		thePublicStatics.put("procedureColumnResult", new Integer(3));
+		thePublicStatics.put("procedureColumnReturn", new Integer(5));
+		thePublicStatics.put("procedureColumnOut", new Integer(4));
+		thePublicStatics.put("procedureColumnInOut", new Integer(2));
+		thePublicStatics.put("procedureColumnIn", new Integer(1));
+		thePublicStatics.put("procedureColumnUnknown", new Integer(0));
+		thePublicStatics.put("procedureReturnsResult", new Integer(2));
+		thePublicStatics.put("procedureNoResult", new Integer(1));
+		thePublicStatics.put("procedureResultUnknown", new Integer(0));
+
+		Class databaseMetaDataClass;
+		try {
+			databaseMetaDataClass = Class.forName("java.sql.DatabaseMetaData");
+		} catch (ClassNotFoundException e) {
+			fail("java.sql.DatabaseMetaData class not found!");
+			return;
+		} // end try
+
+		Field[] theFields = databaseMetaDataClass.getDeclaredFields();
+		int requiredModifier = Modifier.PUBLIC + Modifier.STATIC
+				+ Modifier.FINAL;
+
+		int countPublicStatics = 0;
+		for (int i = 0; i < theFields.length; i++) {
+			String fieldName = theFields[i].getName();
+			int theMods = theFields[i].getModifiers();
+			if (Modifier.isPublic(theMods) && Modifier.isStatic(theMods)) {
+				try {
+					Object fieldValue = theFields[i].get(null);
+					Object expectedValue = thePublicStatics.get(fieldName);
+					if (expectedValue == null) {
+						fail("Field " + fieldName + " missing!");
+					} // end
+					assertEquals("Field " + fieldName + " value mismatch: ",
+							expectedValue, fieldValue);
+					assertEquals("Field " + fieldName + " modifier mismatch: ",
+							requiredModifier, theMods);
+					countPublicStatics++;
+				} catch (IllegalAccessException e) {
+					fail("Illegal access to Field " + fieldName);
+				} // end try
+			} // end if
+		} // end for
+
+	} // end method testPublicStatics
+
+} // end class DatabaseMetaDataTest

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/DatabaseMetaDataTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/DateTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/DateTest.java?rev=436644&r1=436643&r2=436644&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/DateTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/DateTest.java Thu Aug 24 21:29:34 2006
@@ -1,395 +1,395 @@
-/* Copyright 2004 The Apache Software Foundation or its licensors, as applicable
- * 
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- *     http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.sql.tests.java.sql;
-
-import java.sql.Date;
-import java.util.Calendar;
-import java.util.TimeZone;
-
-import junit.framework.TestCase;
-
-/**
- * JUnit Testcase for the java.sql.Date class
- * 
- */
-public class DateTest extends TestCase {
-
-	// A calendar object created in the GMT time zone
-	static Calendar aCal = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
-
-	// Some interesting millisecond time values
-	// These millisecond times are all in GMT, effectively
-	static long TIME_AN_HOUR = 3600000; // 1000 * 60 * 60 ms
-
-	static long TIME_EPOCH = 0;
-
-	static long TIME_NOW = System.currentTimeMillis();
-
-	static long TIME_NEGATIVE = -3600001;
-
-	static long TIME_TESTDATE1 = getTime(1999, Calendar.DECEMBER, 31, 23, 59,
-			59);
-
-	static long TIME_TESTDATE2 = getTime(2010, Calendar.JUNE, 10, 20, 3, 16);
-
-	static long TIME_TESTDATE3 = getTime(1931, Calendar.APRIL, 21, 1, 25, 1);
-
-	static long TIME_LOWERLIMIT = Long.MIN_VALUE;
-
-	static long TIME_UPPERLIMIT = Long.MAX_VALUE;
-
-	// Date strings
-	static String SQL_DATESTRING1 = "1999-12-31";
-
-	static String SQL_DATESTRING2 = "2010-06-10";
-
-	static String SQL_DATESTRING3 = "1931-04-21";
-
-	static String SQL_EPOCHSTRING = "1970-01-01";
-
-	static String SQL_DATEDAY1 = "1970-01-02";
-
-	static String SQL_NEGATIVE = "1969-12-31";
-
-	static long[] TIME_ARRAY = new long[] { TIME_TESTDATE1, TIME_TESTDATE2,
-			TIME_TESTDATE3, TIME_NEGATIVE, TIME_EPOCH };
-
-	// Date string array for London (GMT)
-	static String[] SQL_DATEARRAY = new String[] { SQL_DATESTRING1,
-			SQL_DATESTRING2, SQL_DATESTRING3, SQL_NEGATIVE, SQL_EPOCHSTRING };
-
-	// Date string array for New York - sometimes a day earlier than London
-	static String[] SQL_NYARRAY = new String[] { "1999-12-31", "2010-06-10",
-			"1931-04-20", "1969-12-31", "1969-12-31" };
-
-	// Date string for Tokyo
-	static String[] SQL_JAPANARRAY = new String[] { "2000-01-01", "2010-06-11",
-			"1931-04-21", "1970-01-01", "1970-01-01" };
-
-	static String[][] SQL_TZ_DATEARRAYS = new String[][] { SQL_DATEARRAY,
-			SQL_NYARRAY, SQL_JAPANARRAY };
-
-	// Timezones
-	static String TZ_LONDON = "Europe/London"; // Note: != GMT
-
-	static String TZ_PACIFIC = "America/Los_Angeles"; // GNT - 8
-
-	static String TZ_JAPAN = "Asia/Tokyo"; // GMT + 9
-
-	static String[] TIMEZONES = { TZ_LONDON, TZ_PACIFIC, TZ_JAPAN };
-
-	/*
-	 * Helper method to create a long milliseconds time from a supplied date and
-	 * time
-	 */
-	static private long getTime(int year, int month, int date, int hour,
-			int minute, int second) {
-		aCal.set(year, month, date, hour, minute, second);
-		return aCal.getTimeInMillis();
-	} // end method getTime( int, int, int, int, int, int )
-
-	/*
-	 * Test of the Date(int, int, int) constructor - now deprecated but still
-	 * funtioning
-	 */
-	public void testDateintintint() {
-
-		int init1[] = { 99, 8099, 9000, 99999, 99, 99, -1, -100 };
-		int init2[] = { 11, 0, 0, 0, 999, 0, 0, -111 };
-		int init3[] = { 31, 0, 0, 0, 0, 999, 0, -999 };
-
-		Exception theExceptions[] = { null, null, null, null, null, null, null,
-				null };
-
-		for (int i = 0; i < init1.length; i++) {
-			try {
-				Date theDate = new Date(init1[i], init2[i], init3[i]);
-
-				assertNotNull(theDate);
-				if (theExceptions[i] != null) {
-					fail(i + "Exception expected - none thrown.");
-				} // end if
-			} catch (Exception e) {
-				if (theExceptions[i] != null) {
-					assertEquals(i + "Incorrect exception generated: ",
-							theExceptions[i].getClass(), e.getClass());
-				} else {
-					fail(i + "Exception: " + e.getClass()
-							+ " not expected");
-				} // end if
-			} // end try
-		} // end for
-
-	} // end method testDateintintint
-
-	/*
-	 * Test of the Date( long ) constructor
-	 */
-	public void testDatelong() {
-
-		long init1[] = { TIME_TESTDATE1, TIME_TESTDATE2, TIME_TESTDATE3,
-				TIME_NEGATIVE, TIME_LOWERLIMIT, TIME_UPPERLIMIT, TIME_EPOCH,
-				TIME_NOW };
-
-		Exception theExceptions[] = { null, null, null, null, null, null, null,
-				null };
-
-		for (int i = 0; i < init1.length; i++) {
-			try {
-				Date theDate = new Date(init1[i]);
-
-				assertNotNull(theDate);
-				if (theExceptions[i] != null) {
-					fail(i + "Exception expected - none thrown.");
-				} // end if
-			} catch (Exception e) {
-				if (theExceptions[i] != null) {
-					assertEquals(i + "Incorrect exception generated: ",
-							theExceptions[i].getClass(), e.getClass());
-				} else {
-					fail(i + "Exception: " + e.getClass()
-							+ " not expected");
-				} // end if
-			} // end try
-		} // end for
-
-	} // end method testDatelong
-
-	/*
-	 * Test of the (deprecated) int Date.getHours() method - which always throws
-	 * an IllegalArgumentException
-	 */
-	public void testGetHours() {
-		Date theDate = new Date(TIME_TESTDATE1);
-
-		try {
-			int theHours = theDate.getHours();
-
-			// If it worked, it should get the Hours setting
-			assertEquals(23, theHours);
-			assertTrue(false);
-		} catch (IllegalArgumentException ie) {
-			/*
-			 * System.out.println("getHours: IllegalArgumentException thrown as
-			 * expected");
-			 */
-		} // end try
-	} // end method testGetHours()
-
-	/*
-	 * Test of the (deprecated) int Date.getMinutes() method - which always
-	 * throws an IllegalArgumentException
-	 */
-	public void testGetMinutes() {
-		Date theDate = new Date(TIME_TESTDATE1);
-
-		try {
-			int theMinutes = theDate.getMinutes();
-
-			// If it worked, it should get the Hours setting
-			assertEquals(59, theMinutes);
-			assertTrue(false);
-		} catch (IllegalArgumentException ie) {
-			/*
-			 * System.out.println("getMinutes: IllegalArgumentException thrown
-			 * as expected");
-			 */
-		} // end try
-	} // end method testGetMinutes()
-
-	/*
-	 * Test of the (deprecated) int Date.getSeconds() method - which always
-	 * throws an IllegalArgumentException
-	 */
-	public void testGetSeconds() {
-		Date theDate = new Date(TIME_TESTDATE1);
-
-		try {
-			int theSeconds = theDate.getSeconds();
-
-			// If it worked, it should get the Hours setting
-			assertEquals(23, theSeconds);
-			assertTrue(false);
-		} catch (IllegalArgumentException ie) {
-			/*
-			 * System.out.println("getSeconds: IllegalArgumentException thrown
-			 * as expected");
-			 */
-		} // end try
-	} // end method testGetSeconds()
-
-	/*
-	 * Test of the (deprecated) Date.setHours( int ) method - which always
-	 * throws an IllegalArgumentException
-	 */
-	public void testSetHours() {
-		Date theDate = new Date(TIME_TESTDATE1);
-
-		try {
-			theDate.setHours(22);
-
-			// If it worked, this is incorrect
-			assertTrue(false);
-		} catch (IllegalArgumentException ie) {
-			/*
-			 * System.out.println("setHours: IllegalArgumentException thrown as
-			 * expected");
-			 */
-		} // end try
-	} // end method testSetHours( int )
-
-	/*
-	 * Test of the (deprecated) Date.setMinutes( int ) method - which always
-	 * throws an IllegalArgumentException
-	 */
-	public void testSetMinutes() {
-		Date theDate = new Date(TIME_TESTDATE1);
-
-		try {
-			theDate.setMinutes(54);
-
-			// If it worked, this is incorrect
-			assertTrue(false);
-		} catch (IllegalArgumentException ie) {
-			/*
-			 * System.out.println("setMinutes: IllegalArgumentException thrown
-			 * as expected");
-			 */
-		} // end try
-
-	} // end method testSetMinutes( int )
-
-	/*
-	 * Test of the (deprecated) Date.setSeconds( int ) method - which always
-	 * throws an IllegalArgumentException
-	 */
-	public void testSetSeconds() {
-		Date theDate = new Date(TIME_TESTDATE1);
-
-		try {
-			theDate.setSeconds(36);
-
-			// If it worked, this is incorrect
-			assertTrue(false);
-		} catch (IllegalArgumentException ie) {
-			/*
-			 * System.out.println("setSeconds: IllegalArgumentException thrown
-			 * as expected");
-			 */
-		} // end try
-	} // end method testSetSeconds( int )
-
-	/*
-	 * Test of the String Date.toString() method This method is sensitive to the
-	 * time zone setting and this test sets the time zone before calling the
-	 * toString() method.
-	 */
-	public void testToString() {
-		// This test is set up for GMT time zone, so need to set the time zone
-		// to GMT first
-		TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
-
-		for (int i = 0; i < TIME_ARRAY.length; i++) {
-			Date theDate = new Date(TIME_ARRAY[i]);
-
-			String theString = theDate.toString();
-
-			assertTrue(theString.equals(SQL_DATEARRAY[i]));
-		} // end for
-
-	} // end method testToString()
-
-	/*
-	 * Test of the void setTime(int) method This does depend on the Time Zone
-	 * settings and sets up the time zone to one of a group of specific time
-	 * zones and tests the method using each of these time zones in turn.
-	 */
-	public void testSetTimelong() {
-
-		// Loop over the array of test timezones
-		for (int i = 0; i < TIMEZONES.length; i++) {
-			testSetTimelong(TIMEZONES[i], SQL_TZ_DATEARRAYS[i]);
-		} // end for
-
-	} // end method testSetTimelong()
-
-	/*
-	 * Internal method for testing Date.setTime with a specific time zone
-	 */
-	private void testSetTimelong(String timeZoneName, String[] dateArray) {
-
-		if (timeZoneName != null) {
-			TimeZone.setDefault(TimeZone.getTimeZone(timeZoneName));
-			/*
-			 * System.out.println("Timezone set to: " +
-			 * TimeZone.getDefault().getDisplayName() );
-			 */
-		} // end if
-
-		Date theDate = new Date(TIME_TESTDATE1);
-
-		// Loop over the array of test times & dates
-		for (int i = 0; i < dateArray.length; i++) {
-			theDate.setTime(TIME_ARRAY[i]);
-			String theString = theDate.toString();
-			assertTrue(theString.equals(dateArray[i]));
-		} // end for
-
-	} // end method testSetTimelong()
-
-	/*
-	 * Test of the Date.valueOf( String ) method This test is not dependent on
-	 * the default Time Zone setting
-	 */
-	public void testValueOf() {
-		String SQL_NOTVALID1 = "ABCDEF"; // Invalid date string
-		String SQL_NOTVALID2 = "12321.43.56"; // Invalid date string
-		String SQL_NOTVALID3 = null; // Invalid date string
-		String[] SQL_INVALIDARRAY = { SQL_NOTVALID1, SQL_NOTVALID2,
-				SQL_NOTVALID3 };
-		Exception[] theExceptions = { new IllegalArgumentException(),
-				new IllegalArgumentException(), new IllegalArgumentException() };
-
-		Date theDate;
-
-		// Cases where the input date string is a valid format
-		for (int i = 0; i < SQL_DATEARRAY.length; i++) {
-			theDate = Date.valueOf(SQL_DATEARRAY[i]);
-
-			assertTrue(theDate.toString().equals(SQL_DATEARRAY[i]));
-		} // end for
-
-		// Cases where the input date string has an invalid format
-		for (int i = 0; i < SQL_INVALIDARRAY.length; i++) {
-			try {
-				theDate = Date.valueOf(SQL_INVALIDARRAY[i]);
-				// Shouldn't get here
-				assertTrue(false);
-			} catch (Exception e) {
-				// System.out.println("DateTest.testValueOf: Exception thrown: "
-				// + e.toString() );
-				// System.out.println("DateTest.testValueOf: Exception data: " +
-				// e.getMessage() );
-				assertTrue(e.getClass().equals(theExceptions[i].getClass()));
-				assertTrue(e.getMessage() == theExceptions[i].getMessage());
-			} // end try
-		} // end for
-
-	} // end method testValueOf()
-
-} // end class DateTest
-
-
+/* Copyright 2004 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.harmony.sql.tests.java.sql;
+
+import java.sql.Date;
+import java.util.Calendar;
+import java.util.TimeZone;
+
+import junit.framework.TestCase;
+
+/**
+ * JUnit Testcase for the java.sql.Date class
+ * 
+ */
+public class DateTest extends TestCase {
+
+	// A calendar object created in the GMT time zone
+	static Calendar aCal = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
+
+	// Some interesting millisecond time values
+	// These millisecond times are all in GMT, effectively
+	static long TIME_AN_HOUR = 3600000; // 1000 * 60 * 60 ms
+
+	static long TIME_EPOCH = 0;
+
+	static long TIME_NOW = System.currentTimeMillis();
+
+	static long TIME_NEGATIVE = -3600001;
+
+	static long TIME_TESTDATE1 = getTime(1999, Calendar.DECEMBER, 31, 23, 59,
+			59);
+
+	static long TIME_TESTDATE2 = getTime(2010, Calendar.JUNE, 10, 20, 3, 16);
+
+	static long TIME_TESTDATE3 = getTime(1931, Calendar.APRIL, 21, 1, 25, 1);
+
+	static long TIME_LOWERLIMIT = Long.MIN_VALUE;
+
+	static long TIME_UPPERLIMIT = Long.MAX_VALUE;
+
+	// Date strings
+	static String SQL_DATESTRING1 = "1999-12-31";
+
+	static String SQL_DATESTRING2 = "2010-06-10";
+
+	static String SQL_DATESTRING3 = "1931-04-21";
+
+	static String SQL_EPOCHSTRING = "1970-01-01";
+
+	static String SQL_DATEDAY1 = "1970-01-02";
+
+	static String SQL_NEGATIVE = "1969-12-31";
+
+	static long[] TIME_ARRAY = new long[] { TIME_TESTDATE1, TIME_TESTDATE2,
+			TIME_TESTDATE3, TIME_NEGATIVE, TIME_EPOCH };
+
+	// Date string array for London (GMT)
+	static String[] SQL_DATEARRAY = new String[] { SQL_DATESTRING1,
+			SQL_DATESTRING2, SQL_DATESTRING3, SQL_NEGATIVE, SQL_EPOCHSTRING };
+
+	// Date string array for New York - sometimes a day earlier than London
+	static String[] SQL_NYARRAY = new String[] { "1999-12-31", "2010-06-10",
+			"1931-04-20", "1969-12-31", "1969-12-31" };
+
+	// Date string for Tokyo
+	static String[] SQL_JAPANARRAY = new String[] { "2000-01-01", "2010-06-11",
+			"1931-04-21", "1970-01-01", "1970-01-01" };
+
+	static String[][] SQL_TZ_DATEARRAYS = new String[][] { SQL_DATEARRAY,
+			SQL_NYARRAY, SQL_JAPANARRAY };
+
+	// Timezones
+	static String TZ_LONDON = "Europe/London"; // Note: != GMT
+
+	static String TZ_PACIFIC = "America/Los_Angeles"; // GNT - 8
+
+	static String TZ_JAPAN = "Asia/Tokyo"; // GMT + 9
+
+	static String[] TIMEZONES = { TZ_LONDON, TZ_PACIFIC, TZ_JAPAN };
+
+	/*
+	 * Helper method to create a long milliseconds time from a supplied date and
+	 * time
+	 */
+	static private long getTime(int year, int month, int date, int hour,
+			int minute, int second) {
+		aCal.set(year, month, date, hour, minute, second);
+		return aCal.getTimeInMillis();
+	} // end method getTime( int, int, int, int, int, int )
+
+	/*
+	 * Test of the Date(int, int, int) constructor - now deprecated but still
+	 * funtioning
+	 */
+	public void testDateintintint() {
+
+		int init1[] = { 99, 8099, 9000, 99999, 99, 99, -1, -100 };
+		int init2[] = { 11, 0, 0, 0, 999, 0, 0, -111 };
+		int init3[] = { 31, 0, 0, 0, 0, 999, 0, -999 };
+
+		Exception theExceptions[] = { null, null, null, null, null, null, null,
+				null };
+
+		for (int i = 0; i < init1.length; i++) {
+			try {
+				Date theDate = new Date(init1[i], init2[i], init3[i]);
+
+				assertNotNull(theDate);
+				if (theExceptions[i] != null) {
+					fail(i + "Exception expected - none thrown.");
+				} // end if
+			} catch (Exception e) {
+				if (theExceptions[i] != null) {
+					assertEquals(i + "Incorrect exception generated: ",
+							theExceptions[i].getClass(), e.getClass());
+				} else {
+					fail(i + "Exception: " + e.getClass()
+							+ " not expected");
+				} // end if
+			} // end try
+		} // end for
+
+	} // end method testDateintintint
+
+	/*
+	 * Test of the Date( long ) constructor
+	 */
+	public void testDatelong() {
+
+		long init1[] = { TIME_TESTDATE1, TIME_TESTDATE2, TIME_TESTDATE3,
+				TIME_NEGATIVE, TIME_LOWERLIMIT, TIME_UPPERLIMIT, TIME_EPOCH,
+				TIME_NOW };
+
+		Exception theExceptions[] = { null, null, null, null, null, null, null,
+				null };
+
+		for (int i = 0; i < init1.length; i++) {
+			try {
+				Date theDate = new Date(init1[i]);
+
+				assertNotNull(theDate);
+				if (theExceptions[i] != null) {
+					fail(i + "Exception expected - none thrown.");
+				} // end if
+			} catch (Exception e) {
+				if (theExceptions[i] != null) {
+					assertEquals(i + "Incorrect exception generated: ",
+							theExceptions[i].getClass(), e.getClass());
+				} else {
+					fail(i + "Exception: " + e.getClass()
+							+ " not expected");
+				} // end if
+			} // end try
+		} // end for
+
+	} // end method testDatelong
+
+	/*
+	 * Test of the (deprecated) int Date.getHours() method - which always throws
+	 * an IllegalArgumentException
+	 */
+	public void testGetHours() {
+		Date theDate = new Date(TIME_TESTDATE1);
+
+		try {
+			int theHours = theDate.getHours();
+
+			// If it worked, it should get the Hours setting
+			assertEquals(23, theHours);
+			assertTrue(false);
+		} catch (IllegalArgumentException ie) {
+			/*
+			 * System.out.println("getHours: IllegalArgumentException thrown as
+			 * expected");
+			 */
+		} // end try
+	} // end method testGetHours()
+
+	/*
+	 * Test of the (deprecated) int Date.getMinutes() method - which always
+	 * throws an IllegalArgumentException
+	 */
+	public void testGetMinutes() {
+		Date theDate = new Date(TIME_TESTDATE1);
+
+		try {
+			int theMinutes = theDate.getMinutes();
+
+			// If it worked, it should get the Hours setting
+			assertEquals(59, theMinutes);
+			assertTrue(false);
+		} catch (IllegalArgumentException ie) {
+			/*
+			 * System.out.println("getMinutes: IllegalArgumentException thrown
+			 * as expected");
+			 */
+		} // end try
+	} // end method testGetMinutes()
+
+	/*
+	 * Test of the (deprecated) int Date.getSeconds() method - which always
+	 * throws an IllegalArgumentException
+	 */
+	public void testGetSeconds() {
+		Date theDate = new Date(TIME_TESTDATE1);
+
+		try {
+			int theSeconds = theDate.getSeconds();
+
+			// If it worked, it should get the Hours setting
+			assertEquals(23, theSeconds);
+			assertTrue(false);
+		} catch (IllegalArgumentException ie) {
+			/*
+			 * System.out.println("getSeconds: IllegalArgumentException thrown
+			 * as expected");
+			 */
+		} // end try
+	} // end method testGetSeconds()
+
+	/*
+	 * Test of the (deprecated) Date.setHours( int ) method - which always
+	 * throws an IllegalArgumentException
+	 */
+	public void testSetHours() {
+		Date theDate = new Date(TIME_TESTDATE1);
+
+		try {
+			theDate.setHours(22);
+
+			// If it worked, this is incorrect
+			assertTrue(false);
+		} catch (IllegalArgumentException ie) {
+			/*
+			 * System.out.println("setHours: IllegalArgumentException thrown as
+			 * expected");
+			 */
+		} // end try
+	} // end method testSetHours( int )
+
+	/*
+	 * Test of the (deprecated) Date.setMinutes( int ) method - which always
+	 * throws an IllegalArgumentException
+	 */
+	public void testSetMinutes() {
+		Date theDate = new Date(TIME_TESTDATE1);
+
+		try {
+			theDate.setMinutes(54);
+
+			// If it worked, this is incorrect
+			assertTrue(false);
+		} catch (IllegalArgumentException ie) {
+			/*
+			 * System.out.println("setMinutes: IllegalArgumentException thrown
+			 * as expected");
+			 */
+		} // end try
+
+	} // end method testSetMinutes( int )
+
+	/*
+	 * Test of the (deprecated) Date.setSeconds( int ) method - which always
+	 * throws an IllegalArgumentException
+	 */
+	public void testSetSeconds() {
+		Date theDate = new Date(TIME_TESTDATE1);
+
+		try {
+			theDate.setSeconds(36);
+
+			// If it worked, this is incorrect
+			assertTrue(false);
+		} catch (IllegalArgumentException ie) {
+			/*
+			 * System.out.println("setSeconds: IllegalArgumentException thrown
+			 * as expected");
+			 */
+		} // end try
+	} // end method testSetSeconds( int )
+
+	/*
+	 * Test of the String Date.toString() method This method is sensitive to the
+	 * time zone setting and this test sets the time zone before calling the
+	 * toString() method.
+	 */
+	public void testToString() {
+		// This test is set up for GMT time zone, so need to set the time zone
+		// to GMT first
+		TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
+
+		for (int i = 0; i < TIME_ARRAY.length; i++) {
+			Date theDate = new Date(TIME_ARRAY[i]);
+
+			String theString = theDate.toString();
+
+			assertTrue(theString.equals(SQL_DATEARRAY[i]));
+		} // end for
+
+	} // end method testToString()
+
+	/*
+	 * Test of the void setTime(int) method This does depend on the Time Zone
+	 * settings and sets up the time zone to one of a group of specific time
+	 * zones and tests the method using each of these time zones in turn.
+	 */
+	public void testSetTimelong() {
+
+		// Loop over the array of test timezones
+		for (int i = 0; i < TIMEZONES.length; i++) {
+			testSetTimelong(TIMEZONES[i], SQL_TZ_DATEARRAYS[i]);
+		} // end for
+
+	} // end method testSetTimelong()
+
+	/*
+	 * Internal method for testing Date.setTime with a specific time zone
+	 */
+	private void testSetTimelong(String timeZoneName, String[] dateArray) {
+
+		if (timeZoneName != null) {
+			TimeZone.setDefault(TimeZone.getTimeZone(timeZoneName));
+			/*
+			 * System.out.println("Timezone set to: " +
+			 * TimeZone.getDefault().getDisplayName() );
+			 */
+		} // end if
+
+		Date theDate = new Date(TIME_TESTDATE1);
+
+		// Loop over the array of test times & dates
+		for (int i = 0; i < dateArray.length; i++) {
+			theDate.setTime(TIME_ARRAY[i]);
+			String theString = theDate.toString();
+			assertTrue(theString.equals(dateArray[i]));
+		} // end for
+
+	} // end method testSetTimelong()
+
+	/*
+	 * Test of the Date.valueOf( String ) method This test is not dependent on
+	 * the default Time Zone setting
+	 */
+	public void testValueOf() {
+		String SQL_NOTVALID1 = "ABCDEF"; // Invalid date string
+		String SQL_NOTVALID2 = "12321.43.56"; // Invalid date string
+		String SQL_NOTVALID3 = null; // Invalid date string
+		String[] SQL_INVALIDARRAY = { SQL_NOTVALID1, SQL_NOTVALID2,
+				SQL_NOTVALID3 };
+		Exception[] theExceptions = { new IllegalArgumentException(),
+				new IllegalArgumentException(), new IllegalArgumentException() };
+
+		Date theDate;
+
+		// Cases where the input date string is a valid format
+		for (int i = 0; i < SQL_DATEARRAY.length; i++) {
+			theDate = Date.valueOf(SQL_DATEARRAY[i]);
+
+			assertTrue(theDate.toString().equals(SQL_DATEARRAY[i]));
+		} // end for
+
+		// Cases where the input date string has an invalid format
+		for (int i = 0; i < SQL_INVALIDARRAY.length; i++) {
+			try {
+				theDate = Date.valueOf(SQL_INVALIDARRAY[i]);
+				// Shouldn't get here
+				assertTrue(false);
+			} catch (Exception e) {
+				// System.out.println("DateTest.testValueOf: Exception thrown: "
+				// + e.toString() );
+				// System.out.println("DateTest.testValueOf: Exception data: " +
+				// e.getMessage() );
+				assertTrue(e.getClass().equals(theExceptions[i].getClass()));
+				assertTrue(e.getMessage() == theExceptions[i].getMessage());
+			} // end try
+		} // end for
+
+	} // end method testValueOf()
+
+} // end class DateTest
+
+

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/DateTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/DriverManagerTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/DriverManagerTest.java?rev=436644&r1=436643&r2=436644&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/DriverManagerTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/DriverManagerTest.java Thu Aug 24 21:29:34 2006
@@ -1,667 +1,667 @@
-/* Copyright 2004 The Apache Software Foundation or its licensors, as applicable
- * 
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- *     http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.sql.tests.java.sql;
-
-import java.io.ByteArrayOutputStream;
-import java.io.PrintStream;
-import java.io.PrintWriter;
-import java.lang.reflect.Method;
-import java.security.Permission;
-import java.sql.Connection;
-import java.sql.Driver;
-import java.sql.DriverManager;
-import java.sql.SQLException;
-import java.sql.SQLPermission;
-import java.util.Enumeration;
-import java.util.Properties;
-
-import junit.framework.TestCase;
-
-/**
- * JUnit Testcase for the java.sql.DriverManager class
- * 
- */
-public class DriverManagerTest extends TestCase {
-
-	// Set of driver names to use
-	static final String DRIVER1 = "org.apache.harmony.sql.tests.java.sql.TestHelper_Driver1";
-
-	static final String DRIVER2 = "org.apache.harmony.sql.tests.java.sql.TestHelper_Driver2";
-
-	static final String DRIVER3 = "org.apache.harmony.sql.tests.java.sql.TestHelper_Driver3";
-
-	static final String DRIVER4 = "org.apache.harmony.sql.tests.java.sql.TestHelper_Driver4";
-
-	static final String DRIVER5 = "org.apache.harmony.sql.tests.java.sql.TestHelper_Driver5";
-
-	static final String INVALIDDRIVER1 = "abc.klm.Foo";
-
-	static String[] driverNames = { DRIVER1, DRIVER2 };
-
-	static int numberLoaded;
-
-	static String baseURL1 = "jdbc:mikes1";
-
-	static String baseURL4 = "jdbc:mikes4";
-
-	static final String JDBC_PROPERTY = "jdbc.drivers";
-
-	static TestHelper_ClassLoader testClassLoader = new TestHelper_ClassLoader();
-
-	// Static initializer to load the drivers so that they are available to all
-	// the
-	// test methods as needed.
-	public void setUp() {
-		numberLoaded = loadDrivers();
-	} // end setUp()
-
-	/**
-	 * Test for the method DriverManager.deregisterDriver
-	 */
-	public void testDeregisterDriver() {
-		// First get one of the drivers loaded by the test
-		Driver aDriver;
-		try {
-			aDriver = DriverManager.getDriver(baseURL4);
-		} catch (SQLException e) {
-			fail(
-					"testDeregisterDriver: Got exception when getting valid driver.");
-			return;
-		} // end try
-
-		// printClassLoader( aDriver );
-
-		// Deregister this driver
-		try {
-			DriverManager.deregisterDriver(aDriver);
-		} catch (Exception e) {
-			fail(
-					"testDeregisterDriver: Got exception when deregistering valid driver.");
-		} // end try
-
-		assertFalse("testDeregisterDriver: Driver was not deregistered.",
-				isDriverLoaded(aDriver));
-
-		// Re-register this driver (so subsequent tests have it available)
-		try {
-			DriverManager.registerDriver(aDriver);
-		} catch (Exception e) {
-			fail(
-					"testDeregisterDriver: Got exception when reregistering valid driver.");
-		} // end try
-
-		assertTrue("testDeregisterDriver: Driver did not reload.",
-				isDriverLoaded(aDriver));
-
-		// Test deregistering a null driver
-		try {
-			DriverManager.deregisterDriver(null);
-		} catch (SQLException e) {
-			fail(
-					"testDeregisterDriver: Got exception when deregistering null driver.");
-		} // end try
-
-		// Test deregistering a driver which was not loaded by this test's
-		// classloader
-		// TODO - need to load a driver with a different classloader!!
-		try {
-			aDriver = DriverManager.getDriver(baseURL1);
-		} catch (SQLException e) {
-			fail(
-					"testDeregisterDriver: Got exception when getting valid driver1.");
-			return;
-		} // end try
-
-		TestHelper_DriverManager testHelper;
-		try {
-			Class driverClass = Class.forName(
-					"org.apache.harmony.sql.tests.java.sql.TestHelper_DriverManager", true,
-					testClassLoader);
-
-			// Give the Helper class one of our drivers....
-			Class[] methodClasses = { Class.forName("java.sql.Driver") };
-			Method theMethod = driverClass.getDeclaredMethod("setDriver",
-					methodClasses);
-			Object[] args = { aDriver };
-			theMethod.invoke(null, args);
-		} catch (Exception e) {
-			System.out
-					.println("testDeregisterDriver: Got exception allocating TestHelper");
-			e.printStackTrace();
-			return;
-		} // end try
-
-		// Check that the driver was not deregistered
-		assertTrue(
-				"testDeregisterDriver: Driver was incorrectly deregistered.",
-				DriverManagerTest.isDriverLoaded(aDriver));
-
-	} // end method testDeregisterDriver()
-
-	static void printClassLoader(Object theObject) {
-		Class theClass = theObject.getClass();
-		ClassLoader theClassLoader = theClass.getClassLoader();
-		System.out.println("ClassLoader is: " + theClassLoader.toString()
-				+ " for object: " + theObject.toString());
-	} // end method printClassLoader( Object )
-
-	static boolean isDriverLoaded(Driver theDriver) {
-		Enumeration driverList = DriverManager.getDrivers();
-		while (driverList.hasMoreElements()) {
-			if ((Driver) driverList.nextElement() == theDriver)
-				return true;
-		} // end while
-		return false;
-	} // end method isDriverLoaded( Driver )
-
-	/*
-	 * Class under test for Connection getConnection(String)
-	 */
-	// valid connection - data1 does not require a user and password...
-	static String validConnectionURL = "jdbc:mikes1:data1";
-
-	// invalid connection - data2 requires a user & password
-	static String invalidConnectionURL1 = "jdbc:mikes1:data2";
-
-	// invalid connection - URL is gibberish
-	static String invalidConnectionURL2 = "xyz1:abc3:456q";
-
-	// invalid connection - URL is null
-	static String invalidConnectionURL3 = null;
-
-	static String[] invalidConnectionURLs = { invalidConnectionURL1,
-			invalidConnectionURL2, invalidConnectionURL3 };
-
-	static String[] exceptionMessages = {
-			"Userid and/or password not supplied", "No suitable driver",
-			"The url cannot be null" };
-
-	public void testGetConnectionString() {
-		Connection theConnection = null;
-		// validConnection - no user & password required
-		try {
-			theConnection = DriverManager.getConnection(validConnectionURL);
-			assertNotNull(theConnection);
-		} catch (SQLException e) {
-			assertTrue(false);
-		} // end try
-
-		// invalid connections
-		for (int i = 0; i < invalidConnectionURLs.length; i++) {
-			theConnection = null;
-			try {
-				theConnection = DriverManager
-						.getConnection(invalidConnectionURLs[i]);
-				assertFalse(theConnection != null);
-			} catch (SQLException e) {
-				assertNull(theConnection);
-				// System.out.println("testGetConnectionString: exception
-				// message: " +
-				// e.getMessage() );
-				assertTrue(e.getMessage().equals(exceptionMessages[i]));
-			} // end try
-		} // end for
-	} // end method testGetConnectionString()
-
-	/*
-	 * Class under test for Connection getConnection(String, Properties)
-	 */
-	public void testGetConnectionStringProperties() {
-		String validURL1 = "jdbc:mikes1:data2";
-		String validuser1 = "theuser";
-		String validpassword1 = "thepassword";
-		String invalidURL1 = "xyz:abc1:foo";
-		String invalidURL2 = "jdbc:mikes1:crazyone";
-		String invalidURL3 = "";
-		String invaliduser1 = "jonny nouser";
-		String invalidpassword1 = "whizz";
-		Properties nullProps = null;
-		Properties validProps = new Properties();
-		validProps.setProperty("user", validuser1);
-		validProps.setProperty("password", validpassword1);
-		Properties invalidProps1 = new Properties();
-		invalidProps1.setProperty("user", invaliduser1);
-		invalidProps1.setProperty("password", invalidpassword1);
-		String[] invalidURLs = { null, validURL1, validURL1, invalidURL1,
-				invalidURL2, invalidURL3 };
-		Properties[] invalidProps = { validProps, nullProps, invalidProps1,
-				validProps, validProps, validProps };
-		String[] excMessage = { "The url cannot be null",
-				"Properties bundle is null",
-				"Userid and/or password not valid", "No suitable driver",
-				"No suitable driver", "No suitable driver" };
-
-		Connection theConnection = null;
-		Properties theProperties = null;
-		// validConnection - user & password required
-		try {
-			theConnection = DriverManager.getConnection(validURL1, validProps);
-			assertNotNull(theConnection);
-		} catch (SQLException e) {
-			assertTrue(false);
-		} // end try
-
-		// invalid Connections
-		for (int i = 0; i < invalidURLs.length; i++) {
-			theConnection = null;
-			try {
-				theConnection = DriverManager.getConnection(invalidURLs[i],
-						invalidProps[i]);
-				assertFalse(theConnection != null);
-			} catch (SQLException e) {
-				// System.out.println("testGetConnectionStringStringString:
-				// exception message: " +
-				// e.getMessage() );
-				assertTrue(e.getMessage().equals(excMessage[i]));
-			} // end try
-		} // end for
-	} // end method testGetConnectionStringProperties()
-
-	/*
-	 * Class under test for Connection getConnection(String, String, String)
-	 */
-	public void testGetConnectionStringStringString() {
-		String validURL1 = "jdbc:mikes1:data2";
-		String validuser1 = "theuser";
-		String validpassword1 = "thepassword";
-		String invalidURL1 = "xyz:abc1:foo";
-		String invaliduser1 = "jonny nouser";
-		String invalidpassword1 = "whizz";
-		String[] invalid1 = { null, validuser1, validpassword1 };
-		String[] invalid2 = { validURL1, null, validpassword1 };
-		String[] invalid3 = { validURL1, validuser1, null };
-		String[] invalid4 = { invalidURL1, validuser1, validpassword1 };
-		String[] invalid5 = { validURL1, invaliduser1, invalidpassword1 };
-		String[] invalid6 = { validURL1, validuser1, invalidpassword1 };
-		String[][] invalid = { invalid1, invalid2, invalid3, invalid4,
-				invalid5, invalid6 };
-		String[] excMessage = { "The url cannot be null",
-				"Userid and/or password not supplied",
-				"Userid and/or password not supplied", "No suitable driver",
-				"Userid and/or password not valid",
-				"Userid and/or password not valid" };
-
-		Connection theConnection = null;
-		// validConnection - user & password required
-		try {
-			theConnection = DriverManager.getConnection(validURL1, validuser1,
-					validpassword1);
-			assertNotNull(theConnection);
-		} catch (SQLException e) {
-			assertTrue(false);
-		} // end try
-
-		// invalid Connections
-		for (int i = 0; i < invalid.length; i++) {
-			theConnection = null;
-			String[] theData = invalid[i];
-			try {
-				theConnection = DriverManager.getConnection(theData[0],
-						theData[1], theData[2]);
-				assertFalse(theConnection != null);
-			} catch (SQLException e) {
-				// System.out.println("testGetConnectionStringStringString:
-				// exception message: " +
-				// e.getMessage() );
-				assertTrue(e.getMessage().equals(excMessage[i]));
-			} // end try
-		} // end for
-	} // end method testGetConnectionStringStringString()
-
-	static String validURL1 = "jdbc:mikes1";
-
-	static String validURL2 = "jdbc:mikes2";
-
-	static String invalidURL1 = "xyz:acb";
-
-	static String invalidURL2 = null;
-
-	static String[] validURLs = { validURL1, validURL2 };
-
-	static String[] invalidURLs = { invalidURL1, invalidURL2 };
-
-	static String exceptionMsg1 = "No suitable driver";
-
-	public void testGetDriver() {
-		// valid URLs
-		for (int i = 0; i < validURLs.length; i++) {
-			try {
-				Driver validDriver = DriverManager.getDriver(validURLs[i]);
-			} catch (SQLException e) {
-				fail(
-						"DriverManagerTest: getDriver failed for valid driver"
-								+ i);
-			} // end try
-		} // end for
-
-		// invalid URLs
-		for (int i = 0; i < invalidURLs.length; i++) {
-			try {
-				Driver invalidDriver = DriverManager.getDriver(invalidURLs[i]);
-			} catch (SQLException e) {
-				assertTrue(true);
-				// System.out.println("DriverManagerTest: getDriver failed for
-				// invalid driver");
-				// System.out.println("DriverManagerTest: exception message = "
-				// + e.getMessage() );
-				assertTrue(e.getMessage().equals(exceptionMsg1));
-			} // end try
-		} // end for
-
-	} // end method testGetDriver()
-
-	public void testGetDrivers() {
-		// Load a driver manager
-		Enumeration driverList = DriverManager.getDrivers();
-		int i = 0;
-		while (driverList.hasMoreElements()) {
-			Driver theDriver = (Driver) driverList.nextElement();
-			i++;
-		} // end while
-
-		// Check that all the drivers are in the list...
-		assertEquals("testGetDrivers: Don't see all the loaded drivers - ", i,
-				numberLoaded);
-	} // end method testGetDrivers()
-
-	static int timeout1 = 25;
-
-	public void testGetLoginTimeout() {
-		int theTimeout = DriverManager.getLoginTimeout();
-		// System.out.println("Default Login Timeout: " + theTimeout );
-
-		DriverManager.setLoginTimeout(timeout1);
-
-		assertTrue(DriverManager.getLoginTimeout() == timeout1);
-	} // end method testGetLoginTimeout()
-
-	public void testGetLogStream() {
-		assertNull(DriverManager.getLogStream());
-
-		DriverManager.setLogStream(testPrintStream);
-
-		assertTrue(DriverManager.getLogStream() == testPrintStream);
-
-		DriverManager.setLogStream(null);
-	} // end method testGetLogStream()
-
-	public void testGetLogWriter() {
-		assertNull(DriverManager.getLogWriter());
-
-		DriverManager.setLogWriter(testPrintWriter);
-
-		assertTrue(DriverManager.getLogWriter() == testPrintWriter);
-
-		DriverManager.setLogWriter(null);
-	} // end method testGetLogWriter()
-
-	static String testMessage = "DriverManagerTest: test message for print stream";
-
-	public void testPrintln() {
-		// System.out.println("testPrintln");
-		DriverManager.println(testMessage);
-
-		DriverManager.setLogWriter(testPrintWriter);
-		DriverManager.println(testMessage);
-
-		String theOutput = outputStream.toString();
-		// System.out.println("testPrintln: output= " + theOutput );
-		assertTrue(theOutput.startsWith(testMessage));
-
-		DriverManager.setLogWriter(null);
-
-		DriverManager.setLogStream(testPrintStream);
-		DriverManager.println(testMessage);
-
-		theOutput = outputStream2.toString();
-		// System.out.println("testPrintln: output= " + theOutput );
-		assertTrue(theOutput.startsWith(testMessage));
-
-		DriverManager.setLogStream(null);
-	} // end method testPrintln()
-
-	public void testRegisterDriver() {
-		String EXTRA_DRIVER_NAME = "org.apache.harmony.sql.tests.java.sql.TestHelper_Driver3";
-
-		try {
-			DriverManager.registerDriver(null);
-			fail(
-					"testRegisterDriver: Expected exception not thrown when registering null driver");
-		} catch (Exception e) {
-
-		} // end try
-
-		Driver theDriver = null;
-		// Load another Driver that isn't in the basic set
-		try {
-			Class driverClass = Class.forName(EXTRA_DRIVER_NAME);
-			theDriver = (Driver) driverClass.newInstance();
-			DriverManager.registerDriver(theDriver);
-		} catch (ClassNotFoundException cfe) {
-			fail("testRegisterDriver: Could not load extra driver");
-		} catch (Exception e) {
-			fail(
-					"testRegisterDriver: Exception while registering additional driver");
-		} // end try
-
-		assertTrue("testRegisterDriver: driver not in loaded set",
-				isDriverLoaded(theDriver));
-
-	} // end testRegisterDriver()
-
-	static int validTimeout1 = 15;
-
-	static int validTimeout2 = 0;
-
-	static int[] validTimeouts = { validTimeout1, validTimeout2 };
-
-	static int invalidTimeout1 = -10;
-
-	public void testSetLoginTimeout() {
-		// Valid timeouts
-		for (int i = 0; i < validTimeouts.length; i++) {
-			DriverManager.setLoginTimeout(validTimeouts[i]);
-
-			assertTrue(DriverManager.getLoginTimeout() == validTimeouts[i]);
-		} // end for
-		// Invalid timeouts
-		try {
-			DriverManager.setLoginTimeout(invalidTimeout1);
-			assertTrue(DriverManager.getLoginTimeout() == invalidTimeout1);
-		} catch (IllegalArgumentException e) {
-			System.out.println("DriverManagerTest: exception message = "
-					+ e.getMessage());
-		} // end try
-	} // end testSetLoginTimeout()
-
-	static ByteArrayOutputStream outputStream2 = new ByteArrayOutputStream();
-
-	static PrintStream testPrintStream = new PrintStream(outputStream2);
-
-	public void testSetLogStream() {
-		// System.out.println("testSetLogStream");
-		DriverManager.setLogStream(testPrintStream);
-
-		assertTrue(DriverManager.getLogStream() == testPrintStream);
-
-		DriverManager.setLogStream(null);
-
-		assertNull(DriverManager.getLogStream());
-
-		// Now let's deal with the case where there is a SecurityManager in
-		// place
-		TestSecurityManager theSecManager = new TestSecurityManager();
-		System.setSecurityManager(theSecManager);
-
-		theSecManager.setLogAccess(false);
-
-		try {
-			DriverManager.setLogStream(testPrintStream);
-			fail("testSetLogStream: Did not get security exception ");
-		} catch (SecurityException s) {
-
-		} catch (Throwable t) {
-			fail(
-					"testSetLogStream: Got exception but not get security exception ");
-		} // end try
-
-		theSecManager.setLogAccess(true);
-
-		try {
-			DriverManager.setLogStream(testPrintStream);
-		} catch (SecurityException s) {
-			fail(
-					"testSetLogStream: Got security exception but should not have");
-		} catch (Throwable t) {
-			fail(
-					"testSetLogStream: Got exception but not get security exception ");
-		} // end try
-
-		System.setSecurityManager(null);
-	} // end method testSetLogStream()
-
-	static ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
-
-	static PrintWriter testPrintWriter = new PrintWriter(outputStream);
-
-	/**
-	 * Test for the setLogWriter method
-	 */
-	public void testSetLogWriter() {
-		// System.out.println("testSetLogWriter");
-		DriverManager.setLogWriter(testPrintWriter);
-
-		assertTrue("testDriverManager: Log writer not set:", DriverManager
-				.getLogWriter() == testPrintWriter);
-
-		DriverManager.setLogWriter(null);
-
-		assertNull("testDriverManager: Log writer not null:", DriverManager
-				.getLogWriter());
-
-		// Now let's deal with the case where there is a SecurityManager in
-		// place
-		TestSecurityManager theSecManager = new TestSecurityManager();
-		System.setSecurityManager(theSecManager);
-
-		theSecManager.setLogAccess(false);
-
-		try {
-			DriverManager.setLogWriter(testPrintWriter);
-			fail("testSetLogWriter: Did not get security exception ");
-		} catch (SecurityException s) {
-
-		} catch (Throwable t) {
-			fail(
-					"testSetLogWriter: Got exception but not get security exception ");
-		} // end try
-
-		theSecManager.setLogAccess(true);
-
-		try {
-			DriverManager.setLogWriter(testPrintWriter);
-		} catch (SecurityException s) {
-			fail(
-					"testSetLogWriter: Got security exception but should not have");
-		} catch (Throwable t) {
-			fail(
-					"testSetLogWriter: Got exception but not get security exception ");
-		} // end try
-
-		System.setSecurityManager(null);
-	} // end method testSetLogWriter()
-
-	/*
-	 * Method which loads a set of JDBC drivers ready for use by the various
-	 * tests @return the number of drivers loaded
-	 */
-	static boolean driversLoaded = false;
-
-	private static int loadDrivers() {
-		if (driversLoaded)
-			return numberLoaded;
-		/*
-		 * First define a value for the System property "jdbc.drivers" - before
-		 * the DriverManager class is loaded - this property defines a set of
-		 * drivers which the DriverManager will load during its initialization
-		 * and which will be loaded on the System ClassLoader - unlike the ones
-		 * loaded later by this method which are loaded on the Application
-		 * ClassLoader.
-		 */
-		int numberLoaded = 0;
-		String theSystemDrivers = DRIVER4 + ":" + DRIVER5 + ":"
-				+ INVALIDDRIVER1;
-		System.setProperty(JDBC_PROPERTY, theSystemDrivers);
-		numberLoaded += 2;
-
-		/*
-		 * Next, dynamically load a set of drivers
-		 */
-		for (int i = 0; i < driverNames.length; i++) {
-			try {
-				Class driverClass = Class.forName(driverNames[i]);
-				// System.out.println("Loaded driver - classloader = " +
-				// driverClass.getClassLoader());
-				numberLoaded++;
-			} catch (ClassNotFoundException e) {
-				System.out.println("DriverManagerTest: failed to load Driver: "
-						+ driverNames[i]);
-			} // end try
-		} // end for
-		/*
-		 * System.out.println("DriverManagerTest: number of drivers loaded: " +
-		 * numberLoaded);
-		 */
-		driversLoaded = true;
-		return numberLoaded;
-	} // end method loadDrivers()
-
-	class TestSecurityManager extends SecurityManager {
-
-		boolean logAccess = true;
-
-		SQLPermission sqlPermission = new SQLPermission("setLog");
-
-		RuntimePermission setManagerPermission = new RuntimePermission(
-				"setSecurityManager");
-
-		TestSecurityManager() {
-			super();
-		} // end method TestSecurityManager()
-
-		void setLogAccess(boolean allow) {
-			logAccess = allow;
-		} // end method setLogAccess( boolean )
-
-		public void checkPermission(Permission thePermission) {
-			if (thePermission.equals(sqlPermission)) {
-				if (!logAccess) {
-					throw new SecurityException("Cannot set the sql Log Writer");
-				} // end if
-				return;
-			} // end if
-
-			if (thePermission.equals(setManagerPermission)) {
-				return;
-			} // end if
-			// super.checkPermission( thePermission );
-		} // end method checkPermission( Permission )
-
-	} // end class TestSecurityManager
-
-} // end class DriverManagerTest
-
-
+/* Copyright 2004 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.harmony.sql.tests.java.sql;
+
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+import java.io.PrintWriter;
+import java.lang.reflect.Method;
+import java.security.Permission;
+import java.sql.Connection;
+import java.sql.Driver;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+import java.sql.SQLPermission;
+import java.util.Enumeration;
+import java.util.Properties;
+
+import junit.framework.TestCase;
+
+/**
+ * JUnit Testcase for the java.sql.DriverManager class
+ * 
+ */
+public class DriverManagerTest extends TestCase {
+
+	// Set of driver names to use
+	static final String DRIVER1 = "org.apache.harmony.sql.tests.java.sql.TestHelper_Driver1";
+
+	static final String DRIVER2 = "org.apache.harmony.sql.tests.java.sql.TestHelper_Driver2";
+
+	static final String DRIVER3 = "org.apache.harmony.sql.tests.java.sql.TestHelper_Driver3";
+
+	static final String DRIVER4 = "org.apache.harmony.sql.tests.java.sql.TestHelper_Driver4";
+
+	static final String DRIVER5 = "org.apache.harmony.sql.tests.java.sql.TestHelper_Driver5";
+
+	static final String INVALIDDRIVER1 = "abc.klm.Foo";
+
+	static String[] driverNames = { DRIVER1, DRIVER2 };
+
+	static int numberLoaded;
+
+	static String baseURL1 = "jdbc:mikes1";
+
+	static String baseURL4 = "jdbc:mikes4";
+
+	static final String JDBC_PROPERTY = "jdbc.drivers";
+
+	static TestHelper_ClassLoader testClassLoader = new TestHelper_ClassLoader();
+
+	// Static initializer to load the drivers so that they are available to all
+	// the
+	// test methods as needed.
+	public void setUp() {
+		numberLoaded = loadDrivers();
+	} // end setUp()
+
+	/**
+	 * Test for the method DriverManager.deregisterDriver
+	 */
+	public void testDeregisterDriver() {
+		// First get one of the drivers loaded by the test
+		Driver aDriver;
+		try {
+			aDriver = DriverManager.getDriver(baseURL4);
+		} catch (SQLException e) {
+			fail(
+					"testDeregisterDriver: Got exception when getting valid driver.");
+			return;
+		} // end try
+
+		// printClassLoader( aDriver );
+
+		// Deregister this driver
+		try {
+			DriverManager.deregisterDriver(aDriver);
+		} catch (Exception e) {
+			fail(
+					"testDeregisterDriver: Got exception when deregistering valid driver.");
+		} // end try
+
+		assertFalse("testDeregisterDriver: Driver was not deregistered.",
+				isDriverLoaded(aDriver));
+
+		// Re-register this driver (so subsequent tests have it available)
+		try {
+			DriverManager.registerDriver(aDriver);
+		} catch (Exception e) {
+			fail(
+					"testDeregisterDriver: Got exception when reregistering valid driver.");
+		} // end try
+
+		assertTrue("testDeregisterDriver: Driver did not reload.",
+				isDriverLoaded(aDriver));
+
+		// Test deregistering a null driver
+		try {
+			DriverManager.deregisterDriver(null);
+		} catch (SQLException e) {
+			fail(
+					"testDeregisterDriver: Got exception when deregistering null driver.");
+		} // end try
+
+		// Test deregistering a driver which was not loaded by this test's
+		// classloader
+		// TODO - need to load a driver with a different classloader!!
+		try {
+			aDriver = DriverManager.getDriver(baseURL1);
+		} catch (SQLException e) {
+			fail(
+					"testDeregisterDriver: Got exception when getting valid driver1.");
+			return;
+		} // end try
+
+		TestHelper_DriverManager testHelper;
+		try {
+			Class driverClass = Class.forName(
+					"org.apache.harmony.sql.tests.java.sql.TestHelper_DriverManager", true,
+					testClassLoader);
+
+			// Give the Helper class one of our drivers....
+			Class[] methodClasses = { Class.forName("java.sql.Driver") };
+			Method theMethod = driverClass.getDeclaredMethod("setDriver",
+					methodClasses);
+			Object[] args = { aDriver };
+			theMethod.invoke(null, args);
+		} catch (Exception e) {
+			System.out
+					.println("testDeregisterDriver: Got exception allocating TestHelper");
+			e.printStackTrace();
+			return;
+		} // end try
+
+		// Check that the driver was not deregistered
+		assertTrue(
+				"testDeregisterDriver: Driver was incorrectly deregistered.",
+				DriverManagerTest.isDriverLoaded(aDriver));
+
+	} // end method testDeregisterDriver()
+
+	static void printClassLoader(Object theObject) {
+		Class theClass = theObject.getClass();
+		ClassLoader theClassLoader = theClass.getClassLoader();
+		System.out.println("ClassLoader is: " + theClassLoader.toString()
+				+ " for object: " + theObject.toString());
+	} // end method printClassLoader( Object )
+
+	static boolean isDriverLoaded(Driver theDriver) {
+		Enumeration driverList = DriverManager.getDrivers();
+		while (driverList.hasMoreElements()) {
+			if ((Driver) driverList.nextElement() == theDriver)
+				return true;
+		} // end while
+		return false;
+	} // end method isDriverLoaded( Driver )
+
+	/*
+	 * Class under test for Connection getConnection(String)
+	 */
+	// valid connection - data1 does not require a user and password...
+	static String validConnectionURL = "jdbc:mikes1:data1";
+
+	// invalid connection - data2 requires a user & password
+	static String invalidConnectionURL1 = "jdbc:mikes1:data2";
+
+	// invalid connection - URL is gibberish
+	static String invalidConnectionURL2 = "xyz1:abc3:456q";
+
+	// invalid connection - URL is null
+	static String invalidConnectionURL3 = null;
+
+	static String[] invalidConnectionURLs = { invalidConnectionURL1,
+			invalidConnectionURL2, invalidConnectionURL3 };
+
+	static String[] exceptionMessages = {
+			"Userid and/or password not supplied", "No suitable driver",
+			"The url cannot be null" };
+
+	public void testGetConnectionString() {
+		Connection theConnection = null;
+		// validConnection - no user & password required
+		try {
+			theConnection = DriverManager.getConnection(validConnectionURL);
+			assertNotNull(theConnection);
+		} catch (SQLException e) {
+			assertTrue(false);
+		} // end try
+
+		// invalid connections
+		for (int i = 0; i < invalidConnectionURLs.length; i++) {
+			theConnection = null;
+			try {
+				theConnection = DriverManager
+						.getConnection(invalidConnectionURLs[i]);
+				assertFalse(theConnection != null);
+			} catch (SQLException e) {
+				assertNull(theConnection);
+				// System.out.println("testGetConnectionString: exception
+				// message: " +
+				// e.getMessage() );
+				assertTrue(e.getMessage().equals(exceptionMessages[i]));
+			} // end try
+		} // end for
+	} // end method testGetConnectionString()
+
+	/*
+	 * Class under test for Connection getConnection(String, Properties)
+	 */
+	public void testGetConnectionStringProperties() {
+		String validURL1 = "jdbc:mikes1:data2";
+		String validuser1 = "theuser";
+		String validpassword1 = "thepassword";
+		String invalidURL1 = "xyz:abc1:foo";
+		String invalidURL2 = "jdbc:mikes1:crazyone";
+		String invalidURL3 = "";
+		String invaliduser1 = "jonny nouser";
+		String invalidpassword1 = "whizz";
+		Properties nullProps = null;
+		Properties validProps = new Properties();
+		validProps.setProperty("user", validuser1);
+		validProps.setProperty("password", validpassword1);
+		Properties invalidProps1 = new Properties();
+		invalidProps1.setProperty("user", invaliduser1);
+		invalidProps1.setProperty("password", invalidpassword1);
+		String[] invalidURLs = { null, validURL1, validURL1, invalidURL1,
+				invalidURL2, invalidURL3 };
+		Properties[] invalidProps = { validProps, nullProps, invalidProps1,
+				validProps, validProps, validProps };
+		String[] excMessage = { "The url cannot be null",
+				"Properties bundle is null",
+				"Userid and/or password not valid", "No suitable driver",
+				"No suitable driver", "No suitable driver" };
+
+		Connection theConnection = null;
+		Properties theProperties = null;
+		// validConnection - user & password required
+		try {
+			theConnection = DriverManager.getConnection(validURL1, validProps);
+			assertNotNull(theConnection);
+		} catch (SQLException e) {
+			assertTrue(false);
+		} // end try
+
+		// invalid Connections
+		for (int i = 0; i < invalidURLs.length; i++) {
+			theConnection = null;
+			try {
+				theConnection = DriverManager.getConnection(invalidURLs[i],
+						invalidProps[i]);
+				assertFalse(theConnection != null);
+			} catch (SQLException e) {
+				// System.out.println("testGetConnectionStringStringString:
+				// exception message: " +
+				// e.getMessage() );
+				assertTrue(e.getMessage().equals(excMessage[i]));
+			} // end try
+		} // end for
+	} // end method testGetConnectionStringProperties()
+
+	/*
+	 * Class under test for Connection getConnection(String, String, String)
+	 */
+	public void testGetConnectionStringStringString() {
+		String validURL1 = "jdbc:mikes1:data2";
+		String validuser1 = "theuser";
+		String validpassword1 = "thepassword";
+		String invalidURL1 = "xyz:abc1:foo";
+		String invaliduser1 = "jonny nouser";
+		String invalidpassword1 = "whizz";
+		String[] invalid1 = { null, validuser1, validpassword1 };
+		String[] invalid2 = { validURL1, null, validpassword1 };
+		String[] invalid3 = { validURL1, validuser1, null };
+		String[] invalid4 = { invalidURL1, validuser1, validpassword1 };
+		String[] invalid5 = { validURL1, invaliduser1, invalidpassword1 };
+		String[] invalid6 = { validURL1, validuser1, invalidpassword1 };
+		String[][] invalid = { invalid1, invalid2, invalid3, invalid4,
+				invalid5, invalid6 };
+		String[] excMessage = { "The url cannot be null",
+				"Userid and/or password not supplied",
+				"Userid and/or password not supplied", "No suitable driver",
+				"Userid and/or password not valid",
+				"Userid and/or password not valid" };
+
+		Connection theConnection = null;
+		// validConnection - user & password required
+		try {
+			theConnection = DriverManager.getConnection(validURL1, validuser1,
+					validpassword1);
+			assertNotNull(theConnection);
+		} catch (SQLException e) {
+			assertTrue(false);
+		} // end try
+
+		// invalid Connections
+		for (int i = 0; i < invalid.length; i++) {
+			theConnection = null;
+			String[] theData = invalid[i];
+			try {
+				theConnection = DriverManager.getConnection(theData[0],
+						theData[1], theData[2]);
+				assertFalse(theConnection != null);
+			} catch (SQLException e) {
+				// System.out.println("testGetConnectionStringStringString:
+				// exception message: " +
+				// e.getMessage() );
+				assertTrue(e.getMessage().equals(excMessage[i]));
+			} // end try
+		} // end for
+	} // end method testGetConnectionStringStringString()
+
+	static String validURL1 = "jdbc:mikes1";
+
+	static String validURL2 = "jdbc:mikes2";
+
+	static String invalidURL1 = "xyz:acb";
+
+	static String invalidURL2 = null;
+
+	static String[] validURLs = { validURL1, validURL2 };
+
+	static String[] invalidURLs = { invalidURL1, invalidURL2 };
+
+	static String exceptionMsg1 = "No suitable driver";
+
+	public void testGetDriver() {
+		// valid URLs
+		for (int i = 0; i < validURLs.length; i++) {
+			try {
+				Driver validDriver = DriverManager.getDriver(validURLs[i]);
+			} catch (SQLException e) {
+				fail(
+						"DriverManagerTest: getDriver failed for valid driver"
+								+ i);
+			} // end try
+		} // end for
+
+		// invalid URLs
+		for (int i = 0; i < invalidURLs.length; i++) {
+			try {
+				Driver invalidDriver = DriverManager.getDriver(invalidURLs[i]);
+			} catch (SQLException e) {
+				assertTrue(true);
+				// System.out.println("DriverManagerTest: getDriver failed for
+				// invalid driver");
+				// System.out.println("DriverManagerTest: exception message = "
+				// + e.getMessage() );
+				assertTrue(e.getMessage().equals(exceptionMsg1));
+			} // end try
+		} // end for
+
+	} // end method testGetDriver()
+
+	public void testGetDrivers() {
+		// Load a driver manager
+		Enumeration driverList = DriverManager.getDrivers();
+		int i = 0;
+		while (driverList.hasMoreElements()) {
+			Driver theDriver = (Driver) driverList.nextElement();
+			i++;
+		} // end while
+
+		// Check that all the drivers are in the list...
+		assertEquals("testGetDrivers: Don't see all the loaded drivers - ", i,
+				numberLoaded);
+	} // end method testGetDrivers()
+
+	static int timeout1 = 25;
+
+	public void testGetLoginTimeout() {
+		int theTimeout = DriverManager.getLoginTimeout();
+		// System.out.println("Default Login Timeout: " + theTimeout );
+
+		DriverManager.setLoginTimeout(timeout1);
+
+		assertTrue(DriverManager.getLoginTimeout() == timeout1);
+	} // end method testGetLoginTimeout()
+
+	public void testGetLogStream() {
+		assertNull(DriverManager.getLogStream());
+
+		DriverManager.setLogStream(testPrintStream);
+
+		assertTrue(DriverManager.getLogStream() == testPrintStream);
+
+		DriverManager.setLogStream(null);
+	} // end method testGetLogStream()
+
+	public void testGetLogWriter() {
+		assertNull(DriverManager.getLogWriter());
+
+		DriverManager.setLogWriter(testPrintWriter);
+
+		assertTrue(DriverManager.getLogWriter() == testPrintWriter);
+
+		DriverManager.setLogWriter(null);
+	} // end method testGetLogWriter()
+
+	static String testMessage = "DriverManagerTest: test message for print stream";
+
+	public void testPrintln() {
+		// System.out.println("testPrintln");
+		DriverManager.println(testMessage);
+
+		DriverManager.setLogWriter(testPrintWriter);
+		DriverManager.println(testMessage);
+
+		String theOutput = outputStream.toString();
+		// System.out.println("testPrintln: output= " + theOutput );
+		assertTrue(theOutput.startsWith(testMessage));
+
+		DriverManager.setLogWriter(null);
+
+		DriverManager.setLogStream(testPrintStream);
+		DriverManager.println(testMessage);
+
+		theOutput = outputStream2.toString();
+		// System.out.println("testPrintln: output= " + theOutput );
+		assertTrue(theOutput.startsWith(testMessage));
+
+		DriverManager.setLogStream(null);
+	} // end method testPrintln()
+
+	public void testRegisterDriver() {
+		String EXTRA_DRIVER_NAME = "org.apache.harmony.sql.tests.java.sql.TestHelper_Driver3";
+
+		try {
+			DriverManager.registerDriver(null);
+			fail(
+					"testRegisterDriver: Expected exception not thrown when registering null driver");
+		} catch (Exception e) {
+
+		} // end try
+
+		Driver theDriver = null;
+		// Load another Driver that isn't in the basic set
+		try {
+			Class driverClass = Class.forName(EXTRA_DRIVER_NAME);
+			theDriver = (Driver) driverClass.newInstance();
+			DriverManager.registerDriver(theDriver);
+		} catch (ClassNotFoundException cfe) {
+			fail("testRegisterDriver: Could not load extra driver");
+		} catch (Exception e) {
+			fail(
+					"testRegisterDriver: Exception while registering additional driver");
+		} // end try
+
+		assertTrue("testRegisterDriver: driver not in loaded set",
+				isDriverLoaded(theDriver));
+
+	} // end testRegisterDriver()
+
+	static int validTimeout1 = 15;
+
+	static int validTimeout2 = 0;
+
+	static int[] validTimeouts = { validTimeout1, validTimeout2 };
+
+	static int invalidTimeout1 = -10;
+
+	public void testSetLoginTimeout() {
+		// Valid timeouts
+		for (int i = 0; i < validTimeouts.length; i++) {
+			DriverManager.setLoginTimeout(validTimeouts[i]);
+
+			assertTrue(DriverManager.getLoginTimeout() == validTimeouts[i]);
+		} // end for
+		// Invalid timeouts
+		try {
+			DriverManager.setLoginTimeout(invalidTimeout1);
+			assertTrue(DriverManager.getLoginTimeout() == invalidTimeout1);
+		} catch (IllegalArgumentException e) {
+			System.out.println("DriverManagerTest: exception message = "
+					+ e.getMessage());
+		} // end try
+	} // end testSetLoginTimeout()
+
+	static ByteArrayOutputStream outputStream2 = new ByteArrayOutputStream();
+
+	static PrintStream testPrintStream = new PrintStream(outputStream2);
+
+	public void testSetLogStream() {
+		// System.out.println("testSetLogStream");
+		DriverManager.setLogStream(testPrintStream);
+
+		assertTrue(DriverManager.getLogStream() == testPrintStream);
+
+		DriverManager.setLogStream(null);
+
+		assertNull(DriverManager.getLogStream());
+
+		// Now let's deal with the case where there is a SecurityManager in
+		// place
+		TestSecurityManager theSecManager = new TestSecurityManager();
+		System.setSecurityManager(theSecManager);
+
+		theSecManager.setLogAccess(false);
+
+		try {
+			DriverManager.setLogStream(testPrintStream);
+			fail("testSetLogStream: Did not get security exception ");
+		} catch (SecurityException s) {
+
+		} catch (Throwable t) {
+			fail(
+					"testSetLogStream: Got exception but not get security exception ");
+		} // end try
+
+		theSecManager.setLogAccess(true);
+
+		try {
+			DriverManager.setLogStream(testPrintStream);
+		} catch (SecurityException s) {
+			fail(
+					"testSetLogStream: Got security exception but should not have");
+		} catch (Throwable t) {
+			fail(
+					"testSetLogStream: Got exception but not get security exception ");
+		} // end try
+
+		System.setSecurityManager(null);
+	} // end method testSetLogStream()
+
+	static ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+
+	static PrintWriter testPrintWriter = new PrintWriter(outputStream);
+
+	/**
+	 * Test for the setLogWriter method
+	 */
+	public void testSetLogWriter() {
+		// System.out.println("testSetLogWriter");
+		DriverManager.setLogWriter(testPrintWriter);
+
+		assertTrue("testDriverManager: Log writer not set:", DriverManager
+				.getLogWriter() == testPrintWriter);
+
+		DriverManager.setLogWriter(null);
+
+		assertNull("testDriverManager: Log writer not null:", DriverManager
+				.getLogWriter());
+
+		// Now let's deal with the case where there is a SecurityManager in
+		// place
+		TestSecurityManager theSecManager = new TestSecurityManager();
+		System.setSecurityManager(theSecManager);
+
+		theSecManager.setLogAccess(false);
+
+		try {
+			DriverManager.setLogWriter(testPrintWriter);
+			fail("testSetLogWriter: Did not get security exception ");
+		} catch (SecurityException s) {
+
+		} catch (Throwable t) {
+			fail(
+					"testSetLogWriter: Got exception but not get security exception ");
+		} // end try
+
+		theSecManager.setLogAccess(true);
+
+		try {
+			DriverManager.setLogWriter(testPrintWriter);
+		} catch (SecurityException s) {
+			fail(
+					"testSetLogWriter: Got security exception but should not have");
+		} catch (Throwable t) {
+			fail(
+					"testSetLogWriter: Got exception but not get security exception ");
+		} // end try
+
+		System.setSecurityManager(null);
+	} // end method testSetLogWriter()
+
+	/*
+	 * Method which loads a set of JDBC drivers ready for use by the various
+	 * tests @return the number of drivers loaded
+	 */
+	static boolean driversLoaded = false;
+
+	private static int loadDrivers() {
+		if (driversLoaded)
+			return numberLoaded;
+		/*
+		 * First define a value for the System property "jdbc.drivers" - before
+		 * the DriverManager class is loaded - this property defines a set of
+		 * drivers which the DriverManager will load during its initialization
+		 * and which will be loaded on the System ClassLoader - unlike the ones
+		 * loaded later by this method which are loaded on the Application
+		 * ClassLoader.
+		 */
+		int numberLoaded = 0;
+		String theSystemDrivers = DRIVER4 + ":" + DRIVER5 + ":"
+				+ INVALIDDRIVER1;
+		System.setProperty(JDBC_PROPERTY, theSystemDrivers);
+		numberLoaded += 2;
+
+		/*
+		 * Next, dynamically load a set of drivers
+		 */
+		for (int i = 0; i < driverNames.length; i++) {
+			try {
+				Class driverClass = Class.forName(driverNames[i]);
+				// System.out.println("Loaded driver - classloader = " +
+				// driverClass.getClassLoader());
+				numberLoaded++;
+			} catch (ClassNotFoundException e) {
+				System.out.println("DriverManagerTest: failed to load Driver: "
+						+ driverNames[i]);
+			} // end try
+		} // end for
+		/*
+		 * System.out.println("DriverManagerTest: number of drivers loaded: " +
+		 * numberLoaded);
+		 */
+		driversLoaded = true;
+		return numberLoaded;
+	} // end method loadDrivers()
+
+	class TestSecurityManager extends SecurityManager {
+
+		boolean logAccess = true;
+
+		SQLPermission sqlPermission = new SQLPermission("setLog");
+
+		RuntimePermission setManagerPermission = new RuntimePermission(
+				"setSecurityManager");
+
+		TestSecurityManager() {
+			super();
+		} // end method TestSecurityManager()
+
+		void setLogAccess(boolean allow) {
+			logAccess = allow;
+		} // end method setLogAccess( boolean )
+
+		public void checkPermission(Permission thePermission) {
+			if (thePermission.equals(sqlPermission)) {
+				if (!logAccess) {
+					throw new SecurityException("Cannot set the sql Log Writer");
+				} // end if
+				return;
+			} // end if
+
+			if (thePermission.equals(setManagerPermission)) {
+				return;
+			} // end if
+			// super.checkPermission( thePermission );
+		} // end method checkPermission( Permission )
+
+	} // end class TestSecurityManager
+
+} // end class DriverManagerTest
+
+

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/DriverManagerTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/DriverPropertyInfoTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/DriverPropertyInfoTest.java?rev=436644&r1=436643&r2=436644&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/DriverPropertyInfoTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/DriverPropertyInfoTest.java Thu Aug 24 21:29:34 2006
@@ -1,104 +1,104 @@
-/* Copyright 2004 The Apache Software Foundation or its licensors, as applicable
- * 
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- *     http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.sql.tests.java.sql;
-
-import java.sql.DriverPropertyInfo;
-
-import junit.framework.TestCase;
-
-/**
- * JUnit Testcase for the java.sql.DriverPropertyInfo class
- * 
- */
-
-public class DriverPropertyInfoTest extends TestCase {
-
-	/*
-	 * Public statics test
-	 */
-	public void testPublicStatics() {
-
-	} // end method testPublicStatics
-
-	/*
-	 * Constructor test
-	 */
-	public void testDriverPropertyInfoStringString() {
-
-		DriverPropertyInfo aDriverPropertyInfo = new DriverPropertyInfo(
-				validName, validValue);
-
-		assertNotNull(aDriverPropertyInfo);
-
-		aDriverPropertyInfo = new DriverPropertyInfo(null, null);
-
-	} // end method testDriverPropertyInfoStringString
-
-	/*
-	 * Public fields test
-	 */
-	static String validName = "testname";
-
-	static String validValue = "testvalue";
-
-	static String[] updateChoices = { "Choice1", "Choice2", "Choice3" };
-
-	static String updateValue = "updateValue";
-
-	static boolean updateRequired = true;
-
-	static String updateDescription = "update description";
-
-	static String updateName = "updateName";
-
-	public void testPublicFields() {
-
-		// Constructor here...
-		DriverPropertyInfo aDriverPropertyInfo = new DriverPropertyInfo(
-				validName, validValue);
-
-		assertTrue(aDriverPropertyInfo.choices == testChoices);
-		assertTrue(aDriverPropertyInfo.value == testValue);
-		assertTrue(aDriverPropertyInfo.required == testRequired);
-		assertTrue(aDriverPropertyInfo.description == testDescription);
-		assertTrue(aDriverPropertyInfo.name == testName);
-
-		aDriverPropertyInfo.choices = updateChoices;
-		aDriverPropertyInfo.value = updateValue;
-		aDriverPropertyInfo.required = updateRequired;
-		aDriverPropertyInfo.description = updateDescription;
-		aDriverPropertyInfo.name = updateName;
-
-		assertTrue(aDriverPropertyInfo.choices == updateChoices);
-		assertTrue(aDriverPropertyInfo.value == updateValue);
-		assertTrue(aDriverPropertyInfo.required == updateRequired);
-		assertTrue(aDriverPropertyInfo.description == updateDescription);
-		assertTrue(aDriverPropertyInfo.name == updateName);
-
-	} // end method testPublicFields
-
-	// Default values...
-	static String[] testChoices = null;
-
-	static java.lang.String testValue = validValue;
-
-	static boolean testRequired = false;
-
-	static java.lang.String testDescription = null;
-
-	static java.lang.String testName = validName;
-
-} // end class DriverPropertyInfoTest
+/* Copyright 2004 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.harmony.sql.tests.java.sql;
+
+import java.sql.DriverPropertyInfo;
+
+import junit.framework.TestCase;
+
+/**
+ * JUnit Testcase for the java.sql.DriverPropertyInfo class
+ * 
+ */
+
+public class DriverPropertyInfoTest extends TestCase {
+
+	/*
+	 * Public statics test
+	 */
+	public void testPublicStatics() {
+
+	} // end method testPublicStatics
+
+	/*
+	 * Constructor test
+	 */
+	public void testDriverPropertyInfoStringString() {
+
+		DriverPropertyInfo aDriverPropertyInfo = new DriverPropertyInfo(
+				validName, validValue);
+
+		assertNotNull(aDriverPropertyInfo);
+
+		aDriverPropertyInfo = new DriverPropertyInfo(null, null);
+
+	} // end method testDriverPropertyInfoStringString
+
+	/*
+	 * Public fields test
+	 */
+	static String validName = "testname";
+
+	static String validValue = "testvalue";
+
+	static String[] updateChoices = { "Choice1", "Choice2", "Choice3" };
+
+	static String updateValue = "updateValue";
+
+	static boolean updateRequired = true;
+
+	static String updateDescription = "update description";
+
+	static String updateName = "updateName";
+
+	public void testPublicFields() {
+
+		// Constructor here...
+		DriverPropertyInfo aDriverPropertyInfo = new DriverPropertyInfo(
+				validName, validValue);
+
+		assertTrue(aDriverPropertyInfo.choices == testChoices);
+		assertTrue(aDriverPropertyInfo.value == testValue);
+		assertTrue(aDriverPropertyInfo.required == testRequired);
+		assertTrue(aDriverPropertyInfo.description == testDescription);
+		assertTrue(aDriverPropertyInfo.name == testName);
+
+		aDriverPropertyInfo.choices = updateChoices;
+		aDriverPropertyInfo.value = updateValue;
+		aDriverPropertyInfo.required = updateRequired;
+		aDriverPropertyInfo.description = updateDescription;
+		aDriverPropertyInfo.name = updateName;
+
+		assertTrue(aDriverPropertyInfo.choices == updateChoices);
+		assertTrue(aDriverPropertyInfo.value == updateValue);
+		assertTrue(aDriverPropertyInfo.required == updateRequired);
+		assertTrue(aDriverPropertyInfo.description == updateDescription);
+		assertTrue(aDriverPropertyInfo.name == updateName);
+
+	} // end method testPublicFields
+
+	// Default values...
+	static String[] testChoices = null;
+
+	static java.lang.String testValue = validValue;
+
+	static boolean testRequired = false;
+
+	static java.lang.String testDescription = null;
+
+	static java.lang.String testName = validName;
+
+} // end class DriverPropertyInfoTest

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/DriverPropertyInfoTest.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message