You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by te...@apache.org on 2006/03/15 15:57:17 UTC
svn commit: r386087 [43/45] - in /incubator/harmony/enhanced/classlib/trunk:
make/ make/patternsets/ modules/jndi/ modules/jndi/META-INF/
modules/jndi/make/ modules/jndi/make/common/ modules/jndi/src/
modules/jndi/src/main/ modules/jndi/src/main/java/ ...
Added: incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/tests/api/java/sql/ResultSetTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/tests/api/java/sql/ResultSetTest.java?rev=386087&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/tests/api/java/sql/ResultSetTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/tests/api/java/sql/ResultSetTest.java Wed Mar 15 06:55:38 2006
@@ -0,0 +1,99 @@
+/* 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 tests.api.java.sql;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
+import java.util.HashMap;
+
+import junit.framework.TestCase;
+
+public class ResultSetTest extends TestCase {
+
+ /*
+ * Public statics test
+ */
+ public void testPublicStatics() {
+
+ HashMap thePublicStatics = new HashMap();
+ thePublicStatics.put("CLOSE_CURSORS_AT_COMMIT",
+ new java.lang.Integer(2));
+ thePublicStatics.put("HOLD_CURSORS_OVER_COMMIT", new java.lang.Integer(
+ 1));
+ thePublicStatics.put("CONCUR_UPDATABLE", new java.lang.Integer(1008));
+ thePublicStatics.put("CONCUR_READ_ONLY", new java.lang.Integer(1007));
+ thePublicStatics.put("TYPE_SCROLL_SENSITIVE", new java.lang.Integer(
+ 1005));
+ thePublicStatics.put("TYPE_SCROLL_INSENSITIVE", new java.lang.Integer(
+ 1004));
+ thePublicStatics.put("TYPE_FORWARD_ONLY", new java.lang.Integer(1003));
+ thePublicStatics.put("FETCH_UNKNOWN", new java.lang.Integer(1002));
+ thePublicStatics.put("FETCH_REVERSE", new java.lang.Integer(1001));
+ thePublicStatics.put("FETCH_FORWARD", new java.lang.Integer(1000));
+
+ /*
+ * System.out.println( "CLOSE_CURSORS_AT_COMMIT: " +
+ * ResultSet.CLOSE_CURSORS_AT_COMMIT ); System.out.println(
+ * "HOLD_CURSORS_OVER_COMMIT: " + ResultSet.HOLD_CURSORS_OVER_COMMIT );
+ * System.out.println( "CONCUR_UPDATABLE: " + ResultSet.CONCUR_UPDATABLE );
+ * System.out.println( "CONCUR_READ_ONLY: " + ResultSet.CONCUR_READ_ONLY );
+ * System.out.println( "TYPE_SCROLL_SENSITIVE: " +
+ * ResultSet.TYPE_SCROLL_SENSITIVE ); System.out.println(
+ * "TYPE_SCROLL_INSENSITIVE: " + ResultSet.TYPE_SCROLL_INSENSITIVE );
+ * System.out.println( "TYPE_FORWARD_ONLY: " +
+ * ResultSet.TYPE_FORWARD_ONLY ); System.out.println( "FETCH_UNKNOWN: " +
+ * ResultSet.FETCH_UNKNOWN ); System.out.println( "FETCH_REVERSE: " +
+ * ResultSet.FETCH_REVERSE ); System.out.println( "FETCH_FORWARD: " +
+ * ResultSet.FETCH_FORWARD );
+ */
+
+ Class resultSetClass;
+ try {
+ resultSetClass = Class.forName("java.sql.ResultSet");
+ } catch (ClassNotFoundException e) {
+ fail("java.sql.ResultSet class not found!");
+ return;
+ } // end try
+
+ Field[] theFields = resultSetClass.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 ResultSetTest
Added: incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/tests/api/java/sql/SQLExceptionTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/tests/api/java/sql/SQLExceptionTest.java?rev=386087&view=auto
==============================================================================
Binary files /tmp/tmpug6FOI and /tmp/tmp8pMotF differ
Added: incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/tests/api/java/sql/SQLPermissionTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/tests/api/java/sql/SQLPermissionTest.java?rev=386087&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/tests/api/java/sql/SQLPermissionTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/tests/api/java/sql/SQLPermissionTest.java Wed Mar 15 06:55:38 2006
@@ -0,0 +1,71 @@
+/* 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 tests.api.java.sql;
+
+import java.sql.SQLPermission;
+
+import junit.framework.TestCase;
+
+/**
+ * JUnit Testcase for the java.sql.SQLPermission class
+ *
+ * Note that the SQLPermission class only defines 2 constructors and all other
+ * methods are inherited. This testcase explicity tets the constructors but also
+ * implicitly tests some of the inherited query methods.
+ *
+ */
+
+public class SQLPermissionTest extends TestCase {
+
+ /*
+ * Constructor test
+ */
+ public void testSQLPermissionStringString() {
+ String validName = "setLog";
+ String validActions = "theActions";
+
+ SQLPermission thePermission = new SQLPermission(validName, validActions);
+
+ assertTrue(thePermission != null);
+ assertTrue(thePermission.getName().equals(validName));
+ // System.out.println("The actions: " + thePermission.getActions() + "."
+ // );
+ assertTrue(thePermission.getActions().equals(""));
+ } // end method testSQLPermissionStringString
+
+ /*
+ * Constructor test
+ */
+ public void testSQLPermissionString() {
+ String validName = "setLog";
+
+ SQLPermission thePermission = new SQLPermission(validName);
+
+ assertTrue(thePermission != null);
+ assertTrue(thePermission.getName().equals(validName));
+
+ // Set an invalid name ...
+ String invalidName = "foo";
+
+ thePermission = new SQLPermission(invalidName);
+
+ assertTrue(thePermission != null);
+ assertTrue(thePermission.getName().equals(invalidName));
+ assertTrue(thePermission.getActions().equals(""));
+ } // end method testSQLPermissionString
+
+} // end class SQLPermissionTest
+
Added: incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/tests/api/java/sql/SQLWarningTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/tests/api/java/sql/SQLWarningTest.java?rev=386087&view=auto
==============================================================================
Binary files /tmp/tmpRco7PN and /tmp/tmp7nyFDN differ
Added: incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/tests/api/java/sql/StatementTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/tests/api/java/sql/StatementTest.java?rev=386087&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/tests/api/java/sql/StatementTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/tests/api/java/sql/StatementTest.java Wed Mar 15 06:55:38 2006
@@ -0,0 +1,90 @@
+/* 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 tests.api.java.sql;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
+import java.util.HashMap;
+
+import junit.framework.TestCase;
+
+public class StatementTest extends TestCase {
+
+ /*
+ * Public statics test
+ */
+ public void testPublicStatics() {
+
+ HashMap thePublicStatics = new HashMap();
+ thePublicStatics.put("NO_GENERATED_KEYS", new Integer(2));
+ thePublicStatics.put("RETURN_GENERATED_KEYS", new Integer(1));
+ thePublicStatics.put("EXECUTE_FAILED", new Integer(-3));
+ thePublicStatics.put("SUCCESS_NO_INFO", new Integer(-2));
+ thePublicStatics.put("CLOSE_ALL_RESULTS", new Integer(3));
+ thePublicStatics.put("KEEP_CURRENT_RESULT", new Integer(2));
+ thePublicStatics.put("CLOSE_CURRENT_RESULT", new Integer(1));
+
+ /*
+ * System.out.println( "NO_GENERATED_KEYS: " +
+ * Statement.NO_GENERATED_KEYS ); System.out.println(
+ * "RETURN_GENERATED_KEYS: " + Statement.RETURN_GENERATED_KEYS );
+ * System.out.println( "EXECUTE_FAILED: " + Statement.EXECUTE_FAILED );
+ * System.out.println( "SUCCESS_NO_INFO: " + Statement.SUCCESS_NO_INFO );
+ * System.out.println( "CLOSE_ALL_RESULTS: " +
+ * Statement.CLOSE_ALL_RESULTS ); System.out.println(
+ * "KEEP_CURRENT_RESULT: " + Statement.KEEP_CURRENT_RESULT );
+ * System.out.println( "CLOSE_CURRENT_RESULT: " +
+ * Statement.CLOSE_CURRENT_RESULT );
+ */
+
+ Class statementClass;
+ try {
+ statementClass = Class.forName("java.sql.Statement");
+ } catch (ClassNotFoundException e) {
+ fail("java.sql.Statement class not found!");
+ return;
+ } // end try
+
+ Field[] theFields = statementClass.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 StatementTest
+
Added: incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/tests/api/java/sql/TestHelper_ClassLoader.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/tests/api/java/sql/TestHelper_ClassLoader.java?rev=386087&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/tests/api/java/sql/TestHelper_ClassLoader.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/tests/api/java/sql/TestHelper_ClassLoader.java Wed Mar 15 06:55:38 2006
@@ -0,0 +1,229 @@
+/* Copyright 2005 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 tests.api.java.sql;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+
+/**
+ * TODO Type description
+ *
+ */
+public class TestHelper_ClassLoader extends ClassLoader {
+
+ public TestHelper_ClassLoader() {
+ super(null);
+ // System.out.println("Test class loader - loaded.");
+ /*
+ * System.out.println("Test class loader = " + this );
+ * System.out.println("Test class loader parent = " + this.getParent() );
+ */
+ } // end method TestClassLoader
+
+ /**
+ * Loads a class specified by its name
+ * <p>
+ * This classloader makes the assumption that any class it is asked to load
+ * is in the current directory....
+ */
+ public Class findClass(String className) throws ClassNotFoundException {
+ Class theClass = null;
+
+ if (!className.equals("tests.api.java.sql.TestHelper_DriverManager"))
+ return null;
+
+ String classNameAsFile = className.replace('.', '/') + ".class";
+ // System.out.println("findClass - class filename = " + classNameAsFile
+ // );
+
+ String classPath = System.getProperty("java.class.path");
+ // System.out.println("Test class loader - classpath = " + classPath );
+
+ String theSeparator = String.valueOf(File.pathSeparatorChar);
+ String[] theClassPaths = classPath.split(theSeparator);
+ for (int i = 0; (i < theClassPaths.length) && (theClass == null); i++) {
+ // Ignore jar files...
+ if (theClassPaths[i].endsWith(".jar")) {
+ theClass = loadClassFromJar(theClassPaths[i], className,
+ classNameAsFile);
+ } else {
+ theClass = loadClassFromFile(theClassPaths[i], className,
+ classNameAsFile);
+ } // end if
+ } // end for
+
+ return theClass;
+ } // end method findClass( String )
+
+ public Class loadClass(String className) throws ClassNotFoundException {
+ // Allowed classes:
+ String[] disallowedClasses = { "tests.api.java.sql.TestHelper_Driver1",
+ "tests.api.java.sql.TestHelper_Driver2",
+ "tests.api.java.sql.TestHelper_Driver4",
+ "tests.api.java.sql.TestHelper_Driver5" };
+
+ Class theClass;
+
+ theClass = findLoadedClass(className);
+ if (theClass != null)
+ return theClass;
+
+ theClass = this.findClass(className);
+
+ if (theClass == null) {
+ for (int i = 0; i < disallowedClasses.length; i++) {
+ if (disallowedClasses[i].equals(className)) {
+ return null;
+ } // end if
+ } // end for
+ theClass = Class.forName(className);
+ } // end if
+
+ return theClass;
+ } // end method loadClass( String )
+
+ private Class loadClassFromFile(String pathName, String className,
+ String classNameAsFile) {
+ Class theClass = null;
+ FileInputStream theInput = null;
+ File theFile = null;
+ try {
+ theFile = new File(pathName, classNameAsFile);
+ if (theFile.exists()) {
+ /*
+ * System.out.println("findClass - class filename = " +
+ * classNameAsFile ); System.out.println("findClass: class file
+ * found");
+ */
+ int length = (int) theFile.length();
+ theInput = new FileInputStream(theFile);
+ byte[] theBytes = new byte[length + 100];
+ int dataRead = 0;
+ while (dataRead < length) {
+ int count = theInput.read(theBytes, dataRead,
+ theBytes.length - dataRead);
+ if (count == -1)
+ break;
+ dataRead += count;
+ } // end while
+
+ // System.out.println("loadClassFromFile: read " + dataRead + "
+ // bytes from class file");
+ if (dataRead > 0) {
+ // Create the class from the bytes read in...
+ theClass = this.defineClass(className, theBytes, 0,
+ dataRead);
+ /* System.out.println("findClass: created Class object."); */
+ ClassLoader testClassLoader = theClass.getClassLoader();
+ if (testClassLoader != this) {
+ System.out.println("findClass - wrong classloader!!");
+ } else {
+ System.out.println("Testclassloader loaded class "
+ + className);
+ } // end if
+ } // end if
+ } // end if
+ } catch (Exception e) {
+ System.out.println("findClass - exception reading class file.");
+ e.printStackTrace();
+ } finally {
+ try {
+ if (theInput != null)
+ theInput.close();
+ } catch (Exception e) {
+ } // end try
+ } // end try
+ return theClass;
+ } // end method loadClassFromFile( )
+
+ /*
+ * Loads a named class from a specified JAR file
+ */
+ private Class loadClassFromJar(String jarfileName, String className,
+ String classNameAsFile) {
+ Class theClass = null;
+
+ // First, try to open the Jar file
+ JarFile theJar = null;
+ try {
+ theJar = new JarFile(jarfileName);
+ JarEntry theEntry = theJar.getJarEntry(classNameAsFile);
+
+ if (theEntry == null) {
+ // System.out.println("TestHelper_Classloader - did not find
+ // class file in Jar " + jarfileName );
+ return theClass;
+ } // end if
+
+ int theMethod = theEntry.getMethod();
+ InputStream theStream = theJar.getInputStream(theEntry);
+
+ long size = theEntry.getSize();
+ if (size < 0)
+ size = 100000;
+ byte[] theBytes = new byte[(int) size + 100];
+
+ int dataRead = 0;
+ while (dataRead < size) {
+ int count = theStream.read(theBytes, dataRead, theBytes.length
+ - dataRead);
+ if (count == -1)
+ break;
+ dataRead += count;
+ } // end while
+
+ // System.out.println("loadClassFromJar: read " + dataRead + " bytes
+ // from class file");
+ if (dataRead > 0) {
+ // Create the class from the bytes read in...
+ theClass = this.defineClass(className, theBytes, 0, dataRead);
+ /* System.out.println("findClass: created Class object."); */
+ ClassLoader testClassLoader = theClass.getClassLoader();
+ if (testClassLoader != this) {
+ System.out.println("findClass - wrong classloader!!");
+ } else {
+ System.out
+ .println("Testclassloader loaded class from jar: "
+ + className);
+ } // end if
+ } // end if
+ } catch (IOException ie) {
+ System.out
+ .println("TestHelper_ClassLoader: IOException opening Jar "
+ + jarfileName);
+ } catch (Exception e) {
+ System.out
+ .println("TestHelper_ClassLoader: Exception loading class from Jar ");
+ } catch (ClassFormatError ce) {
+ System.out
+ .println("TestHelper_ClassLoader: ClassFormatException loading class from Jar ");
+ } finally {
+ try {
+ if (theJar != null)
+ theJar.close();
+ } catch (Exception e) {
+ } // end try
+ } // end try
+
+ return theClass;
+ } // end method loadClassFromJar(
+
+} // end class TestHelper_ClassLoader
+
Added: incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/tests/api/java/sql/TestHelper_Connection1.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/tests/api/java/sql/TestHelper_Connection1.java?rev=386087&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/tests/api/java/sql/TestHelper_Connection1.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/tests/api/java/sql/TestHelper_Connection1.java Wed Mar 15 06:55:38 2006
@@ -0,0 +1,410 @@
+/* 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 tests.api.java.sql;
+
+import java.sql.CallableStatement;
+import java.sql.Connection;
+import java.sql.DatabaseMetaData;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import java.sql.SQLWarning;
+import java.sql.Savepoint;
+import java.sql.Statement;
+import java.util.Map;
+
+/**
+ * Helper class for the java.sql tests - a skeletong class which implements the
+ * java.sql.Connection interface
+ *
+ */
+public class TestHelper_Connection1 implements Connection {
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.sql.Connection#clearWarnings()
+ */
+ public void clearWarnings() throws SQLException {
+ // TODO Auto-generated method stub
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.sql.Connection#close()
+ */
+ public void close() throws SQLException {
+ // TODO Auto-generated method stub
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.sql.Connection#commit()
+ */
+ public void commit() throws SQLException {
+ // TODO Auto-generated method stub
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.sql.Connection#createStatement()
+ */
+ public Statement createStatement() throws SQLException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.sql.Connection#createStatement(int, int)
+ */
+ public Statement createStatement(int resultSetType, int resultSetConcurrency)
+ throws SQLException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.sql.Connection#createStatement(int, int, int)
+ */
+ public Statement createStatement(int resultSetType,
+ int resultSetConcurrency, int resultSetHoldability)
+ throws SQLException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.sql.Connection#getAutoCommit()
+ */
+ public boolean getAutoCommit() throws SQLException {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.sql.Connection#getCatalog()
+ */
+ public String getCatalog() throws SQLException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.sql.Connection#getHoldability()
+ */
+ public int getHoldability() throws SQLException {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.sql.Connection#getMetaData()
+ */
+ public DatabaseMetaData getMetaData() throws SQLException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.sql.Connection#getTransactionIsolation()
+ */
+ public int getTransactionIsolation() throws SQLException {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.sql.Connection#getTypeMap()
+ */
+ public Map getTypeMap() throws SQLException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.sql.Connection#getWarnings()
+ */
+ public SQLWarning getWarnings() throws SQLException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.sql.Connection#isClosed()
+ */
+ public boolean isClosed() throws SQLException {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.sql.Connection#isReadOnly()
+ */
+ public boolean isReadOnly() throws SQLException {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.sql.Connection#nativeSQL(java.lang.String)
+ */
+ public String nativeSQL(String sql) throws SQLException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.sql.Connection#prepareCall(java.lang.String)
+ */
+ public CallableStatement prepareCall(String sql) throws SQLException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.sql.Connection#prepareCall(java.lang.String, int, int)
+ */
+ public CallableStatement prepareCall(String sql, int resultSetType,
+ int resultSetConcurrency) throws SQLException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.sql.Connection#prepareCall(java.lang.String, int, int, int)
+ */
+ public CallableStatement prepareCall(String sql, int resultSetType,
+ int resultSetConcurrency, int resultSetHoldability)
+ throws SQLException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.sql.Connection#prepareStatement(java.lang.String)
+ */
+ public PreparedStatement prepareStatement(String sql) throws SQLException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.sql.Connection#prepareStatement(java.lang.String, int)
+ */
+ public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys)
+ throws SQLException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.sql.Connection#prepareStatement(java.lang.String, int[])
+ */
+ public PreparedStatement prepareStatement(String sql, int[] columnIndexes)
+ throws SQLException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.sql.Connection#prepareStatement(java.lang.String, int, int)
+ */
+ public PreparedStatement prepareStatement(String sql, int resultSetType,
+ int resultSetConcurrency) throws SQLException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.sql.Connection#prepareStatement(java.lang.String, int, int,
+ * int)
+ */
+ public PreparedStatement prepareStatement(String sql, int resultSetType,
+ int resultSetConcurrency, int resultSetHoldability)
+ throws SQLException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.sql.Connection#prepareStatement(java.lang.String,
+ * java.lang.String[])
+ */
+ public PreparedStatement prepareStatement(String sql, String[] columnNames)
+ throws SQLException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.sql.Connection#releaseSavepoint(java.sql.Savepoint)
+ */
+ public void releaseSavepoint(Savepoint savepoint) throws SQLException {
+ // TODO Auto-generated method stub
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.sql.Connection#rollback()
+ */
+ public void rollback() throws SQLException {
+ // TODO Auto-generated method stub
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.sql.Connection#rollback(java.sql.Savepoint)
+ */
+ public void rollback(Savepoint savepoint) throws SQLException {
+ // TODO Auto-generated method stub
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.sql.Connection#setAutoCommit(boolean)
+ */
+ public void setAutoCommit(boolean autoCommit) throws SQLException {
+ // TODO Auto-generated method stub
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.sql.Connection#setCatalog(java.lang.String)
+ */
+ public void setCatalog(String catalog) throws SQLException {
+ // TODO Auto-generated method stub
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.sql.Connection#setHoldability(int)
+ */
+ public void setHoldability(int holdability) throws SQLException {
+ // TODO Auto-generated method stub
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.sql.Connection#setReadOnly(boolean)
+ */
+ public void setReadOnly(boolean readOnly) throws SQLException {
+ // TODO Auto-generated method stub
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.sql.Connection#setSavepoint()
+ */
+ public Savepoint setSavepoint() throws SQLException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.sql.Connection#setSavepoint(java.lang.String)
+ */
+ public Savepoint setSavepoint(String name) throws SQLException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.sql.Connection#setTransactionIsolation(int)
+ */
+ public void setTransactionIsolation(int level) throws SQLException {
+ // TODO Auto-generated method stub
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.sql.Connection#setTypeMap(java.util.Map)
+ */
+ public void setTypeMap(Map map) throws SQLException {
+ // TODO Auto-generated method stub
+
+ }
+
+}
+
Added: incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/tests/api/java/sql/TestHelper_Driver1.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/tests/api/java/sql/TestHelper_Driver1.java?rev=386087&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/tests/api/java/sql/TestHelper_Driver1.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/tests/api/java/sql/TestHelper_Driver1.java Wed Mar 15 06:55:38 2006
@@ -0,0 +1,174 @@
+/* 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 tests.api.java.sql;
+
+import java.sql.Connection;
+import java.sql.Driver;
+import java.sql.DriverManager;
+import java.sql.DriverPropertyInfo;
+import java.sql.SQLException;
+import java.util.Properties;
+
+/**
+ * A simple implementation of a class implementing a JDBC Driver, for use in the
+ * testing of the java.sql.DriverManager class
+ *
+ */
+public class TestHelper_Driver1 implements Driver {
+
+ int majorVersion = 1;
+
+ int minorVersion = 0;
+
+ String baseURL = "jdbc:mikes1";
+
+ String[] dataSources = { "data1", "data2", "data3" };
+
+ static Driver theDriver;
+
+ static {
+ theDriver = new TestHelper_Driver1();
+ /*
+ * System.out.println("Driver1 classloader: " +
+ * theDriver.getClass().getClassLoader() ); System.out.println("Driver1
+ * object is: " + theDriver );
+ */
+ try {
+ DriverManager.registerDriver(theDriver);
+ } catch (SQLException e) {
+ System.out.println("Failed to register driver!");
+ }
+ } // end static block initializer
+
+ protected TestHelper_Driver1() {
+ super();
+ } // end constructor TestHelper_Driver1()
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.sql.Driver#acceptsURL(java.lang.String) @param url a url
+ * specification for a datasource or a general url for this driver
+ */
+ public boolean acceptsURL(String url) throws SQLException {
+ // Check on the supplied String...
+ if (url == null)
+ return false;
+ // Everything's fine if the quoted url starts with the base url for this
+ // driver
+ if (url.startsWith(baseURL))
+ return true;
+ return false;
+ } // end method acceptsURL
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.sql.Driver#connect(java.lang.String, java.util.Properties)
+ */
+ static String validuser = "theuser";
+
+ static String validpassword = "thepassword";
+
+ static String userProperty = "user";
+
+ static String passwordProperty = "password";
+
+ public Connection connect(String url, Properties info) throws SQLException {
+ // Does the URL have the right form?
+ if (this.acceptsURL(url)) {
+ // The datasource name is the remainder of the url after the ":"
+ String datasource = url.substring(baseURL.length() + 1);
+ // Loop over the valid datasources supported by this driver
+ for (int i = 0; i < dataSources.length; i++) {
+ if (datasource.equals(dataSources[i])) {
+ // Check for user and password, except for datasource =
+ // 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");
+ } else {
+ if (!user.equals(validuser)
+ || !password.equals(validpassword)) {
+ throw new SQLException(
+ "Userid and/or password not valid");
+ } // end if
+ } // end if
+ } // end if
+ // It all checks out - so return a connection
+ Connection connection = new TestHelper_Connection1();
+ return connection;
+ } // end if
+ } // end for
+ } // end if
+ return null;
+ } // end method connect(String, Properties)
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.sql.Driver#getMajorVersion()
+ */
+ public int getMajorVersion() {
+
+ return majorVersion;
+ } // end method getMajorVersion()
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.sql.Driver#getMinorVersion()
+ */
+ public int getMinorVersion() {
+
+ return minorVersion;
+ } // end method getMinorVersion()
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.sql.Driver#getPropertyInfo(java.lang.String,
+ * java.util.Properties)
+ */
+ public DriverPropertyInfo[] getPropertyInfo(String url, Properties info)
+ throws SQLException {
+ DriverPropertyInfo[] theInfos = {
+ new DriverPropertyInfo(userProperty, "*"),
+ new DriverPropertyInfo(passwordProperty, "*"), };
+ return theInfos;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.sql.Driver#jdbcCompliant()
+ */
+ public boolean jdbcCompliant() {
+ // Basic version here returns false
+ return false;
+ }
+
+}
+
Added: incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/tests/api/java/sql/TestHelper_Driver2.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/tests/api/java/sql/TestHelper_Driver2.java?rev=386087&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/tests/api/java/sql/TestHelper_Driver2.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/tests/api/java/sql/TestHelper_Driver2.java Wed Mar 15 06:55:38 2006
@@ -0,0 +1,48 @@
+/* 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 tests.api.java.sql;
+
+import java.sql.Driver;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+
+/**
+ * Basic JDBC driver implementation to help with tests
+ *
+ */
+public class TestHelper_Driver2 extends TestHelper_Driver1 {
+
+ static {
+ Driver theDriver = new TestHelper_Driver2();
+ /*
+ * System.out.println("Driver2 classloader: " +
+ * theDriver.getClass().getClassLoader() ); System.out.println("Driver2
+ * object is: " + theDriver );
+ */
+ try {
+ DriverManager.registerDriver(theDriver);
+ } catch (SQLException e) {
+ System.out.println("Failed to register driver!");
+ }
+ } // end static block initializer
+
+ protected TestHelper_Driver2() {
+ super();
+ baseURL = "jdbc:mikes2";
+ } // end constructor TestHelper_Driver1()
+
+} // end class TestHelper_Driver2
+
Added: incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/tests/api/java/sql/TestHelper_Driver3.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/tests/api/java/sql/TestHelper_Driver3.java?rev=386087&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/tests/api/java/sql/TestHelper_Driver3.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/tests/api/java/sql/TestHelper_Driver3.java Wed Mar 15 06:55:38 2006
@@ -0,0 +1,34 @@
+/* Copyright 2005 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 tests.api.java.sql;
+
+
+/**
+ * TODO Type description
+ *
+ */
+public class TestHelper_Driver3 extends TestHelper_Driver1 {
+
+ /*
+ * This driver does NOT automatically register itself...
+ */
+
+ public TestHelper_Driver3() {
+ super();
+ baseURL = "jdbc:mikes3";
+ } // end constructor TestHelper_Driver1()
+
+} // end class TestHelper_Driver3
Added: incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/tests/api/java/sql/TestHelper_Driver4.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/tests/api/java/sql/TestHelper_Driver4.java?rev=386087&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/tests/api/java/sql/TestHelper_Driver4.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/tests/api/java/sql/TestHelper_Driver4.java Wed Mar 15 06:55:38 2006
@@ -0,0 +1,167 @@
+/* Copyright 2005 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 tests.api.java.sql;
+
+import java.sql.Connection;
+import java.sql.Driver;
+import java.sql.DriverManager;
+import java.sql.DriverPropertyInfo;
+import java.sql.SQLException;
+import java.util.Properties;
+
+/**
+ * Basic JDBC driver implementation to help with tests
+ *
+ */
+public class TestHelper_Driver4 implements Driver {
+
+ int majorVersion = 1;
+
+ int minorVersion = 0;
+
+ String baseURL;
+
+ String[] dataSources = { "data1", "data2", "data3" };
+
+ static {
+ Driver theDriver = new TestHelper_Driver4();
+ try {
+ DriverManager.registerDriver(theDriver);
+ } catch (SQLException e) {
+ System.out.println("Failed to register driver!");
+ }
+ } // end static block initializer
+
+ protected TestHelper_Driver4() {
+ super();
+ baseURL = "jdbc:mikes4";
+ } // end constructor TestHelper_Driver4()
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.sql.Driver#acceptsURL(java.lang.String) @param url a url
+ * specification for a datasource or a general url for this driver
+ */
+ public boolean acceptsURL(String url) throws SQLException {
+ // Check on the supplied String...
+ if (url == null)
+ return false;
+ // Everything's fine if the quoted url starts with the base url for this
+ // driver
+ if (url.startsWith(baseURL))
+ return true;
+ return false;
+ } // end method acceptsURL
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.sql.Driver#connect(java.lang.String, java.util.Properties)
+ */
+ static String validuser = "theuser";
+
+ static String validpassword = "thepassword";
+
+ static String userProperty = "user";
+
+ static String passwordProperty = "password";
+
+ public Connection connect(String url, Properties info) throws SQLException {
+ // Does the URL have the right form?
+ if (this.acceptsURL(url)) {
+ // The datasource name is the remainder of the url after the ":"
+ String datasource = url.substring(baseURL.length() + 1);
+ // Loop over the valid datasources supported by this driver
+ for (int i = 0; i < dataSources.length; i++) {
+ if (datasource.equals(dataSources[i])) {
+ // Check for user and password, except for datasource =
+ // 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");
+ } else {
+ if (!user.equals(validuser)
+ || !password.equals(validpassword)) {
+ throw new SQLException(
+ "Userid and/or password not valid");
+ } // end if
+ } // end if
+ } // end if
+ // It all checks out - so return a connection
+ Connection connection = new TestHelper_Connection1();
+ return connection;
+ } // end if
+ } // end for
+ } // end if
+ return null;
+ } // end method connect(String, Properties)
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.sql.Driver#getMajorVersion()
+ */
+ public int getMajorVersion() {
+
+ return majorVersion;
+ } // end method getMajorVersion()
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.sql.Driver#getMinorVersion()
+ */
+ public int getMinorVersion() {
+
+ return minorVersion;
+ } // end method getMinorVersion()
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.sql.Driver#getPropertyInfo(java.lang.String,
+ * java.util.Properties)
+ */
+ public DriverPropertyInfo[] getPropertyInfo(String url, Properties info)
+ throws SQLException {
+ DriverPropertyInfo[] theInfos = {
+ new DriverPropertyInfo(userProperty, "*"),
+ new DriverPropertyInfo(passwordProperty, "*"), };
+ return theInfos;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.sql.Driver#jdbcCompliant()
+ */
+ public boolean jdbcCompliant() {
+ // Basic version here returns false
+ return false;
+ }
+
+} // end class TestHelper_Driver4
+
Added: incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/tests/api/java/sql/TestHelper_Driver5.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/tests/api/java/sql/TestHelper_Driver5.java?rev=386087&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/tests/api/java/sql/TestHelper_Driver5.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/tests/api/java/sql/TestHelper_Driver5.java Wed Mar 15 06:55:38 2006
@@ -0,0 +1,42 @@
+/* Copyright 2005 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 tests.api.java.sql;
+
+import java.sql.Driver;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+
+/**
+ * Basic JDBC driver implementation to help with tests
+ *
+ */
+public class TestHelper_Driver5 extends TestHelper_Driver4 {
+
+ static {
+ Driver theDriver = new TestHelper_Driver5();
+ try {
+ DriverManager.registerDriver(theDriver);
+ } catch (SQLException e) {
+ System.out.println("Failed to register driver!");
+ }
+ } // end static block initializer
+
+ protected TestHelper_Driver5() {
+ super();
+ baseURL = "jdbc:mikes5";
+ } // end constructor TestHelper_Driver5()
+
+} // end class TestHelper_Driver5
Added: incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/tests/api/java/sql/TestHelper_DriverManager.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/tests/api/java/sql/TestHelper_DriverManager.java?rev=386087&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/tests/api/java/sql/TestHelper_DriverManager.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/tests/api/java/sql/TestHelper_DriverManager.java Wed Mar 15 06:55:38 2006
@@ -0,0 +1,111 @@
+/* Copyright 2005 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 tests.api.java.sql;
+
+import java.sql.Driver;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+
+import junit.framework.TestCase;
+
+/**
+ * Helper class for the Driver manager tes - it allows the test code to be
+ * loaded under a different classloader, necessary for testing the
+ * DeregisterDriver function of DriverManager
+ *
+ */
+public class TestHelper_DriverManager extends TestCase {
+
+ static Driver testDriver = null;
+
+ static TestHelper_DriverManager theHelper;
+
+ static {
+ theHelper = new TestHelper_DriverManager();
+ // theHelper.testDeregister();
+ } // end static
+
+ public TestHelper_DriverManager() {
+ super();
+ } // end constructor TestHelper_DriverManager()
+
+ public static void setDriver(Driver theDriver) {
+ testDriver = theDriver;
+ // System.out.println("TestHelper_DriverManager: Test Driver set!");
+
+ theHelper.checkDeregister();
+ } // end method setDriver( Driver )
+
+ public void checkDeregister() {
+
+ String baseURL = "jdbc:mikes1";
+
+ // System.out.println("Calling checkDeregister in
+ // TestHelper_DriverManager....");
+
+ Driver aDriver;
+
+ // System.out.println("checkDeregister classloader: " +
+ // this.getClass().getClassLoader() );
+
+ // Try to get a driver from the general pool... this should fail
+ try {
+ aDriver = DriverManager.getDriver(baseURL);
+ fail(
+ "testDeregisterDriver: Didn't get exception when getting valid driver from other classloader.");
+ } catch (SQLException e) {
+ // e.printStackTrace();
+ assertTrue(
+ "testDeregisterDriver: Got exception when getting valid driver from other classloader.",
+ true);
+ // return;
+ } // end try
+
+ // OK, now THIS driver was loaded by someone else....
+ aDriver = testDriver;
+
+ // printClassLoader( aDriver );
+
+ // Deregister this driver
+ try {
+ DriverManager.deregisterDriver(aDriver);
+ // We shouldn't get here - but if we do, we need to re-register the
+ // driver to
+ // prevent subsequent tests from failing due to inability to get to
+ // this driver...
+ DriverManager.registerDriver(aDriver);
+ fail(
+ "checkDeregisterDriver: Didn't get Security Exception deregistering invalid driver.");
+ } catch (SecurityException s) {
+ // This is the exception we should get...
+ // System.out.println("checkDeregisterDriver: got expected Security
+ // Exception");
+ } catch (Exception e) {
+ fail(
+ "checkDeregisterDriver: Got wrong exception type when deregistering invalid driver.");
+ } // end try
+
+ } // end method testDeRegister
+
+ 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 )
+
+} // end class TestHelper_DriverManager
+
Added: incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/tests/api/java/sql/TimeTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/tests/api/java/sql/TimeTest.java?rev=386087&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/tests/api/java/sql/TimeTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/tests/api/java/sql/TimeTest.java Wed Mar 15 06:55:38 2006
@@ -0,0 +1,259 @@
+/* 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 tests.api.java.sql;
+
+import java.sql.Time;
+import java.util.TimeZone;
+
+import junit.framework.TestCase;
+
+/**
+ * JUnit Testcase for the java.sql.Time class
+ *
+ */
+public class TimeTest extends TestCase {
+
+ static long TIME_TEST1 = 38720000; // 10:45:20 GMT
+
+ static long TIME_TEST2 = 80279000; // 22:17:59 GMT
+
+ static long TIME_TEST3 = -38720000; // 13:14:40 GMT
+
+ static String STRING_TEST1 = "10:45:20";
+
+ static String STRING_TEST2 = "22:17:59";
+
+ static String STRING_TEST3 = "13:14:40";
+
+ static String STRING_INVALID1 = "ABCDEFGHI";
+
+ static String STRING_INVALID2 = "233104";
+
+ static String STRING_INVALID3 = "21-43-48";
+
+ static String STRING_OUTRANGE = "35:99:66";
+
+ static long[] TIME_ARRAY = { TIME_TEST1, TIME_TEST2, TIME_TEST3 };
+
+ static String[] STRING_GMT_ARRAY = { STRING_TEST1, STRING_TEST2,
+ STRING_TEST3 };
+
+ static String[] STRING_LA_ARRAY = { "02:45:20", "14:17:59", "05:14:40" };
+
+ static String[] STRING_JP_ARRAY = { "19:45:20", "07:17:59", "22:14:40" };
+
+ static String[] INVALID_STRINGS = { STRING_INVALID1, STRING_INVALID2,
+ STRING_INVALID3 };
+
+ // Timezones
+ static String TZ_LONDON = "GMT"; // GMT (!) PS London != GMT (?!?)
+
+ static String TZ_PACIFIC = "America/Los_Angeles"; // GMT - 8
+
+ static String TZ_JAPAN = "Asia/Tokyo"; // GMT + 9
+
+ static String[] TIMEZONES = { TZ_LONDON, TZ_PACIFIC, TZ_JAPAN };
+
+ static String[][] STRING_ARRAYS = { STRING_GMT_ARRAY, STRING_LA_ARRAY,
+ STRING_JP_ARRAY };
+
+ public void testTimeintintint() {
+ Time theTime = new Time(10, 45, 20);
+
+ // The date should have been created
+ assertTrue(theTime != null);
+ } // end method testTimeintintint()
+
+ public void testTime() {
+ Time theTime = new Time(TIME_TEST1);
+
+ // The date should have been created
+ assertTrue(theTime != null);
+ } // end method testTime()
+
+ public void testToString() {
+
+ // Loop through the timezones testing the String conversion for each
+ for (int i = 0; i < TIME_ARRAY.length; i++) {
+ testToString(TIMEZONES[i], TIME_ARRAY, STRING_ARRAYS[i]);
+ } // end for
+
+ } // end method test
+
+ private void testToString(String timeZone, long[] theTimes,
+ String[] theTimeStrings) {
+ // Set the timezone
+ TimeZone.setDefault(TimeZone.getTimeZone(timeZone));
+ String theTimeZoneName = TimeZone.getDefault().getDisplayName();
+ /* System.out.println("testToString: Timezone is: " + theTimeZoneName ); */
+
+ for (int i = 0; i < theTimes.length; i++) {
+ // Create the Time object
+ Time theTime = new Time(theTimes[i]);
+ // Convert to a time string ... and compare
+ String JDBCString = theTime.toString();
+ assertTrue(JDBCString.equals(theTimeStrings[i]));
+ } // end for
+
+ } // end testToString( String, long[], String[] )
+
+ /*
+ * Method test for valueOf
+ */
+ public void testValueOfString() {
+
+ TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
+
+ Time theReturn;
+ Time[] theReturns = { new Time(38720000), new Time(80279000),
+ new Time(47680000), new Time(0), new Time(0), new Time(0),
+ new Time(0) };
+ String[] parm1 = { "10:45:20", "22:17:59", "13:14:40", null,
+ "ABCDEFGHI", "233104", "21-43-48" };
+ Exception[] theExceptions = { null, null, null,
+ new IllegalArgumentException(), new IllegalArgumentException(),
+ new IllegalArgumentException(), new IllegalArgumentException() };
+
+ int loopCount = parm1.length;
+ for (int i = 0; i < loopCount; i++) {
+ try {
+ theReturn = Time.valueOf(parm1[i]);
+ if (theExceptions[i] != null)
+ assertTrue(false);
+ assertTrue(theReturn.equals(theReturns[i]));
+ } catch (Exception e) {
+ assertTrue(e.getClass().equals(theExceptions[i].getClass()));
+ assertTrue(e.getMessage() == theExceptions[i].getMessage());
+ } // end try
+ } // end for
+
+ } // end method testValueOfString
+
+ public void testSetTime() {
+
+ // Ensure that the timezone is set to GMT
+ TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
+
+ Time theTime = new Time(TIME_TEST1);
+
+ assertTrue(theTime.toString().equals(STRING_TEST1));
+
+ theTime.setTime(TIME_TEST2);
+
+ assertTrue(theTime.toString().equals(STRING_TEST2));
+
+ } // end method testSetTime()
+
+ public void testSetDate() {
+ Time theTime = new Time(TIME_TEST1);
+
+ try {
+ theTime.setDate(10);
+ assertTrue(false);
+ } catch (Exception e) {
+ /*
+ * System.out.println("testSetDate: IllegalArgumentException thrown
+ * as expected");
+ */
+ } // end try
+ } // end method testSetDate()
+
+ public void testSetMonth() {
+ Time theTime = new Time(TIME_TEST1);
+
+ try {
+ theTime.setMonth(2);
+ assertTrue(false);
+ } catch (Exception e) {
+ /*
+ * System.out.println("testSetMonth: IllegalArgumentException thrown
+ * as expected");
+ */
+ } // end try
+ } // end method testSetMonth()
+
+ public void testSetYear() {
+ Time theTime = new Time(TIME_TEST1);
+
+ try {
+ theTime.setYear(99);
+ assertTrue(false);
+ } catch (Exception e) {
+ /*
+ * System.out.println("testSetYear: IllegalArgumentException thrown
+ * as expected");
+ */
+ } // end try
+ } // end method testSetYear()
+
+ public void testGetDate() {
+ Time theTime = new Time(TIME_TEST1);
+
+ try {
+ int theDate = theTime.getDate();
+ assertTrue(false);
+ } catch (Exception e) {
+ /*
+ * System.out.println("testGetDate: IllegalArgumentException thrown
+ * as expected");
+ */
+ } // end try
+ } // end method test
+
+ public void testGetDay() {
+ Time theTime = new Time(TIME_TEST1);
+
+ try {
+ int theDay = theTime.getDay();
+ assertTrue(false);
+ } catch (Exception e) {
+ /*
+ * System.out.println("testGetDay: IllegalArgumentException thrown
+ * as expected");
+ */
+ } // end try
+ } // end method test
+
+ public void testGetMonth() {
+ Time theTime = new Time(TIME_TEST1);
+
+ try {
+ int theDate = theTime.getMonth();
+ assertTrue(false);
+ } catch (Exception e) {
+ /*
+ * System.out.println("testGetMonth: IllegalArgumentException thrown
+ * as expected");
+ */
+ } // end try
+ } // end method test
+
+ public void testGetYear() {
+ Time theTime = new Time(TIME_TEST1);
+
+ try {
+ int theDate = theTime.getYear();
+ assertTrue(false);
+ } catch (Exception e) {
+ /*
+ * System.out.println("testGetYear: IllegalArgumentException thrown
+ * as expected");
+ */
+ } // end try
+ } // end method test
+
+} // end class TimeTest
+
Added: incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/tests/api/java/sql/TimestampTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/tests/api/java/sql/TimestampTest.java?rev=386087&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/tests/api/java/sql/TimestampTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/tests/api/java/sql/TimestampTest.java Wed Mar 15 06:55:38 2006
@@ -0,0 +1,597 @@
+/* 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 tests.api.java.sql;
+
+import java.sql.Timestamp;
+import java.util.TimeZone;
+
+import junit.framework.TestCase;
+
+/**
+ * JUnit Testcase for the java.sql.Timestamp class
+ *
+ */
+
+public class TimestampTest extends TestCase {
+
+ static long TIME_TEST1 = 38720231; // 10:45:20.231 GMT
+
+ static long TIME_TEST2 = 80279000; // 22:17:59.000 GMT
+
+ static long TIME_TEST3 = -38720691; // 13:14:39.309 GMT
+
+ static long TIME_COMPARE = 123498845;
+
+ static long TIME_EARLY = -2347889122L;// A time well before the Epoch
+
+ static long TIME_LATE = 2347889122L; // A time well after the Epoch
+
+ static String STRING_TEST1 = "1970-01-01 10:45:20.231"; // "1970-01-01
+ // 10:45:20.231000000";
+
+ static String STRING_TEST2 = "1970-01-01 22:17:59.0"; // "1970-01-01
+ // 22:17:59.000000000";
+
+ static String STRING_TEST3 = "1969-12-31 13:14:39.309"; // "1969-12-31
+ // 13:14:39.309000000";
+
+ static String STRING_INVALID1 = "ABCDEFGHI";
+
+ static String STRING_INVALID2 = "233104";
+
+ static String STRING_INVALID3 = "21-43-48";
+
+ // A timepoint in the correct format but with numeric values out of range
+ // ...this is accepted despite being a crazy date specification
+ // ...it is treated as the correct format date 3000-06-08 12:40:06.875 !!
+ static String STRING_OUTRANGE = "2999-15-99 35:99:66.875";
+
+ static long[] TIME_ARRAY = { TIME_TEST1, TIME_TEST2, TIME_TEST3 };
+
+ static int[] YEAR_ARRAY = { 70, 70, 69 };
+
+ static int[] MONTH_ARRAY = { 0, 0, 11 };
+
+ static int[] DATE_ARRAY = { 1, 1, 31 };
+
+ static int[] HOURS_ARRAY = { 10, 22, 13 };
+
+ static int[] MINUTES_ARRAY = { 45, 17, 14 };
+
+ static int[] SECONDS_ARRAY = { 20, 59, 39 };
+
+ static int[] NANOS_ARRAY = { 231000000, 000000000, 309000000 };
+
+ static int[] NANOS_ARRAY2 = { 137891990, 635665198, 109985421 };
+
+ static String[] STRING_NANOS_ARRAY = { "1970-01-01 10:45:20.13789199",
+ "1970-01-01 22:17:59.635665198", "1969-12-31 13:14:39.109985421" };
+
+ static String[] STRING_GMT_ARRAY = { STRING_TEST1, STRING_TEST2,
+ STRING_TEST3 };
+
+ static String[] STRING_LA_ARRAY = { "02:45:20", "14:17:59", "05:14:40" };
+
+ static String[] STRING_JP_ARRAY = { "19:45:20", "07:17:59", "22:14:40" };
+
+ static String[] INVALID_STRINGS = { STRING_INVALID1, STRING_INVALID2,
+ STRING_INVALID3 };
+
+ // Timezones
+ static String TZ_LONDON = "GMT"; // GMT (!) PS London != GMT (?!?)
+
+ static String TZ_PACIFIC = "America/Los_Angeles"; // GMT - 8
+
+ static String TZ_JAPAN = "Asia/Tokyo"; // GMT + 9
+
+ static String[] TIMEZONES = { TZ_LONDON, TZ_PACIFIC, TZ_JAPAN };
+
+ static String[][] STRING_ARRAYS = { STRING_GMT_ARRAY, STRING_LA_ARRAY,
+ STRING_JP_ARRAY };
+
+ /*
+ * Constructor test
+ */
+ public void testTimestamplong() {
+ Timestamp theTimestamp = new Timestamp(TIME_TEST1);
+
+ // The Timestamp should have been created
+ assertTrue(theTimestamp != null);
+ } // end method testTimestamplong
+
+ /*
+ * Constructor test
+ */
+ public void testTimestampintintintintintintint() {
+ int[][] initParms = { { 99, 2, 14, 17, 52, 3, 213577212 }, // 0 valid
+ { 0, 0, 1, 0, 0, 0, 0 }, // 1 valid
+ { 106, 11, 31, 23, 59, 59, 999999999 }, // 2 valid
+ { 106, 11, 31, 23, 59, 59, 1999999999 }, // 3 invalid - Nanos
+ // out of range
+ { 106, 11, 31, 23, 59, 59, -999999999 }, // 4 invalid - Nanos
+ // out of range
+ { 106, 11, 31, 23, 59, 61, 999999999 }, // 5 Seconds out of
+ // range
+ { 106, 11, 31, 23, 59, -1, 999999999 }, // 6 Seconds out of
+ // range
+ { 106, 11, 31, 23, 61, 59, 999999999 }, // 7 Minutes out of
+ // range
+ { 106, 11, 31, 23, -1, 59, 999999999 }, // 8 Minutes out of
+ // range
+ { 106, 11, 31, 25, 59, 59, 999999999 }, // 9 Hours out of range
+ { 106, 11, 31, -1, 59, 59, 999999999 }, // 10 Hours out of range
+ { 106, 11, 35, 23, 59, 59, 999999999 }, // 11 Days out of range
+ { 106, 11, -1, 23, 59, 59, 999999999 }, // 12 Days out of range
+ { 106, 15, 31, 23, 59, 59, 999999999 }, // 13 Months out of
+ // range
+ { 106, -1, 31, 23, 59, 59, 999999999 }, // 14 Months out of
+ // range
+ { -10, 11, 31, 23, 59, 59, 999999999 }, // 15 valid - Years
+ // negative
+ };
+
+ Exception[] theExceptions = { null, null, null,
+ new IllegalArgumentException(), new IllegalArgumentException(),
+ null, null, null, null, null, null, null, null, null, null,
+ null };
+
+ for (int i = 0; i < initParms.length; i++) {
+ try {
+ Timestamp theTimestamp = new Timestamp(initParms[i][0],
+ initParms[i][1], initParms[i][2], initParms[i][3],
+ initParms[i][4], initParms[i][5], initParms[i][6]);
+ assertTrue("Timestamp not generated: ", theTimestamp != null);
+ if (theExceptions[i] != null)
+ fail(i + ": Did not get exception");
+ } catch (Exception e) {
+ assertEquals(i + ": Incorrect exception generated: ",
+ theExceptions[i].getClass(), e.getClass());
+ } // end try
+ } // end for
+
+ } // end method testTimestampintintintintintintint
+
+ /*
+ * Method test for setTime
+ */
+ public void testSetTimelong() {
+ // First set the timezone to GMT
+ TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
+
+ Timestamp theTimestamp = new Timestamp(TIME_TEST1);
+
+ for (int i = 0; i < TIME_ARRAY.length; i++) {
+ theTimestamp.setTime(TIME_ARRAY[i]);
+
+ assertTrue(theTimestamp.getTime() == TIME_ARRAY[i]);
+ assertTrue(theTimestamp.getNanos() == NANOS_ARRAY[i]);
+ } // end for
+
+ } // end method testsetTimelong
+
+ /*
+ * Method test for getTime
+ */
+ public void testGetTime() {
+ // First set the timezone to GMT
+ TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
+
+ for (int i = 0; i < TIME_ARRAY.length; i++) {
+ Timestamp theTimestamp = new Timestamp(TIME_ARRAY[i]);
+
+ assertTrue(theTimestamp.getTime() == TIME_ARRAY[i]);
+ } // end for
+
+ } // end method testgetTime
+
+ /*
+ * Method test for getYear
+ */
+ public void testGetYear() {
+
+ for (int i = 0; i < TIME_ARRAY.length; i++) {
+ Timestamp theTimestamp = new Timestamp(TIME_ARRAY[i]);
+ int theYear = theTimestamp.getYear();
+ assertTrue(theYear == YEAR_ARRAY[i]);
+ } // end for
+
+ } // end method testgetYear
+
+ /*
+ * Method test for getMonth
+ */
+ public void testGetMonth() {
+ for (int i = 0; i < TIME_ARRAY.length; i++) {
+ Timestamp theTimestamp = new Timestamp(TIME_ARRAY[i]);
+ int theMonth = theTimestamp.getMonth();
+ assertTrue(theMonth == MONTH_ARRAY[i]);
+ } // end for
+
+ } // end method testgetMonth
+
+ /*
+ * Method test for getDate
+ */
+ public void testGetDate() {
+ for (int i = 0; i < TIME_ARRAY.length; i++) {
+ Timestamp theTimestamp = new Timestamp(TIME_ARRAY[i]);
+ int theDate = theTimestamp.getDate();
+ assertTrue(theDate == DATE_ARRAY[i]);
+ } // end for
+
+ } // end method testgetDate
+
+ /*
+ * Method test for getHours
+ */
+ public void testGetHours() {
+ for (int i = 0; i < TIME_ARRAY.length; i++) {
+ Timestamp theTimestamp = new Timestamp(TIME_ARRAY[i]);
+ int theHours = theTimestamp.getHours();
+ assertTrue(theHours == HOURS_ARRAY[i]);
+ } // end for
+
+ } // end method testgetHours
+
+ /*
+ * Method test for getMinutes
+ */
+ public void testGetMinutes() {
+ for (int i = 0; i < TIME_ARRAY.length; i++) {
+ Timestamp theTimestamp = new Timestamp(TIME_ARRAY[i]);
+ int theMinutes = theTimestamp.getMinutes();
+ assertTrue(theMinutes == MINUTES_ARRAY[i]);
+ } // end for
+
+ } // end method testgetMinutes
+
+ /*
+ * Method test for getSeconds
+ */
+ public void testGetSeconds() {
+ for (int i = 0; i < TIME_ARRAY.length; i++) {
+ Timestamp theTimestamp = new Timestamp(TIME_ARRAY[i]);
+ int theSeconds = theTimestamp.getSeconds();
+ assertTrue(theSeconds == SECONDS_ARRAY[i]);
+ } // end for
+
+ } // end method testgetSeconds
+
+ /*
+ * Method test for valueOf
+ */
+ static String theExceptionMessage = "Timestamp format must be yyyy-mm-dd hh:mm:ss.fffffffff";
+
+ public void testValueOfString() {
+ for (int i = 0; i < TIME_ARRAY.length; i++) {
+ Timestamp theTimestamp = new Timestamp(TIME_ARRAY[i]);
+ Timestamp theTimestamp2 = Timestamp.valueOf(STRING_GMT_ARRAY[i]);
+ // System.out.println("testValueOfString: " +
+ // theTimestamp2.toString() );
+ assertTrue(theTimestamp2.equals(theTimestamp));
+ } // end for
+
+ // Test for a string in correct format but with number values out of
+ // range
+ Timestamp theTimestamp = Timestamp.valueOf(STRING_OUTRANGE);
+ /*
+ * System.out.println("testValueOfString: outrange timestamp: " +
+ * theTimestamp.toString() );
+ */
+
+ // Now test some truly invalid strings that should cause exceptions
+ for (int i = 0; i < INVALID_STRINGS.length; i++) {
+ try {
+ Timestamp theTimestamp2 = Timestamp.valueOf(INVALID_STRINGS[i]);
+ assertTrue(false);
+ } catch (IllegalArgumentException e) {
+ /*
+ * System.out.println("testValueOfString: exception message: " +
+ * e.getMessage() );
+ */
+ assertTrue(e.getMessage().equals(theExceptionMessage));
+ } // end try
+
+ } // end for
+
+ } // end method testvalueOfString
+
+ /*
+ * Method test for valueOf
+ */
+ public void testValueOfString1() {
+
+ Timestamp theReturn;
+ Timestamp[] theReturns = {};
+ long[] theReturnTime = { 38720231, 38720231, 80279000, -38720691,
+ 38720000, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
+ int[] theReturnNanos = { 231000000, 231987654, 0, 309000000, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0 };
+ String[] parm1 = { "1970-01-01 10:45:20.231",
+ "1970-01-01 10:45:20.231987654", "1970-01-01 22:17:59.0",
+ "1969-12-31 13:14:39.309", "1970-01-01 10:45:20", null,
+ "ABCDEFGHI", "233104", "1970-01-01 22:17:59.",
+ "1970-01-01 10:45:20.231987654690645322",
+ "1970-01-01 10:45:20&231987654",
+ "1970-01-01 10:45:20.-31987654",
+ "1970-01-01 10:45:20.ABCD87654", "21-43-48" };
+ Exception[] theExceptions = {
+ null,
+ null,
+ null,
+ null,
+ null,
+ new IllegalArgumentException("null string"),
+ new IllegalArgumentException(
+ "Timestamp format must be yyyy-mm-dd hh:mm:ss.fffffffff"),
+ new IllegalArgumentException(
+ "Timestamp format must be yyyy-mm-dd hh:mm:ss.fffffffff"),
+ new IllegalArgumentException(
+ "Timestamp format must be yyyy-mm-dd hh:mm:ss.fffffffff"),
+ new IllegalArgumentException(
+ "Timestamp format must be yyyy-mm-dd hh:mm:ss.fffffffff"),
+ new NumberFormatException("For input string \"20&231987654\""),
+ new IllegalArgumentException(
+ "Timestamp format must be yyyy-mm-dd hh:mm:ss.fffffffff"),
+ new IllegalArgumentException(
+ "Timestamp format must be yyyy-mm-dd hh:mm:ss.fffffffff"),
+ new IllegalArgumentException(
+ "Timestamp format must be yyyy-mm-dd hh:mm:ss.fffffffff") };
+
+ int loopCount = parm1.length;
+ for (int i = 0; i < loopCount; i++) {
+ try {
+ theReturn = Timestamp.valueOf(parm1[i]);
+ if (theExceptions[i] != null)
+ assertTrue(false);
+ assertEquals(i + " Times do not match: ", theReturn.getTime(),
+ theReturnTime[i]);
+ assertEquals(i + " Nanos do not match: ", theReturn.getNanos(),
+ theReturnNanos[i]);
+ } catch (Exception e) {
+ if (theExceptions[i] != null) {
+ assertEquals(i + " Unexpected exception: ", e.getClass(),
+ theExceptions[i].getClass());
+ } else {
+ assertEquals(i + " Exception when none expected: ", e
+ .getClass(), null);
+ } // end if
+ } // end try
+ } // end for
+
+ } // end method testValueOfString
+
+ /*
+ * Method test for toString
+ */
+ public void testToString() {
+ for (int i = 0; i < TIME_ARRAY.length; i++) {
+ Timestamp theTimestamp = new Timestamp(TIME_ARRAY[i]);
+ String theString = theTimestamp.toString();
+ assertTrue(theString.equals(STRING_GMT_ARRAY[i]));
+ } // end for
+
+ } // end method testtoString
+
+ /*
+ * Method test for getNanos
+ */
+ public void testGetNanos() {
+ for (int i = 0; i < TIME_ARRAY.length; i++) {
+ Timestamp theTimestamp = new Timestamp(TIME_ARRAY[i]);
+
+ assertTrue(theTimestamp.getNanos() == NANOS_ARRAY[i]);
+ } // end for
+
+ } // end method testgetNanos
+
+ /*
+ * Method test for setNanos
+ */
+ public void testSetNanosint() {
+ int[] NANOS_INVALID = { -137891990, 1635665198, -1 };
+ Exception[] theExceptions = { new IllegalArgumentException(),
+ new IllegalArgumentException(), new IllegalArgumentException() };
+
+ for (int i = 0; i < TIME_ARRAY.length; i++) {
+ Timestamp theTimestamp = new Timestamp(TIME_ARRAY[i]);
+
+ theTimestamp.setNanos(NANOS_ARRAY2[i]);
+
+ assertTrue(theTimestamp.getNanos() == NANOS_ARRAY2[i]);
+ // Also check that these Timestamps with detailed nanos values
+ // convert to
+ // strings correctly
+ assertTrue(theTimestamp.toString().equals(STRING_NANOS_ARRAY[i]));
+ } // end for
+
+ for (int i = 0; i < NANOS_INVALID.length; i++) {
+ Timestamp theTimestamp = new Timestamp(TIME_ARRAY[i]);
+ int originalNanos = theTimestamp.getNanos();
+ try {
+ theTimestamp.setNanos(NANOS_INVALID[i]);
+ fail("Should have got exception and did not");
+ } catch (Exception e) {
+ assertEquals("Exception mismatch: ", e.getClass(),
+ theExceptions[i].getClass());
+ } // end try
+
+ assertTrue(theTimestamp.getNanos() == originalNanos);
+ } // end for
+
+ } // end method testsetNanosint
+
+ /*
+ * Method test for equals
+ */
+ public void testEqualsTimestamp() {
+ for (int i = 0; i < TIME_ARRAY.length; i++) {
+ Timestamp theTimestamp = new Timestamp(TIME_ARRAY[i]);
+
+ Timestamp theTimestamp2 = new Timestamp(TIME_ARRAY[i]);
+
+ assertTrue(theTimestamp.equals(theTimestamp2));
+ } // end for
+
+ Timestamp theTest = new Timestamp(TIME_COMPARE);
+
+ for (int i = 0; i < TIME_ARRAY.length; i++) {
+ Timestamp theTimestamp = new Timestamp(TIME_ARRAY[i]);
+
+ assertFalse(theTimestamp.equals(theTest));
+ } // end for
+ } // end method testequalsTimestamp
+
+ /*
+ * Method test for equals
+ */
+ public void testEqualsObject() {
+ for (int i = 0; i < TIME_ARRAY.length; i++) {
+ Timestamp theTimestamp = new Timestamp(TIME_ARRAY[i]);
+
+ Object theTimestamp2 = new Timestamp(TIME_ARRAY[i]);
+
+ assertTrue(theTimestamp.equals(theTimestamp2));
+ } // end for
+
+ Object theTest = new Timestamp(TIME_COMPARE);
+
+ for (int i = 0; i < TIME_ARRAY.length; i++) {
+ Timestamp theTimestamp = new Timestamp(TIME_ARRAY[i]);
+
+ assertFalse(theTimestamp.equals(theTest));
+ } // end for
+
+ Object nastyTest = new String("Test ");
+ Timestamp theTimestamp = new Timestamp(TIME_ARRAY[1]);
+ assertFalse(theTimestamp.equals(nastyTest));
+
+ } // end method testequalsObject
+
+ /*
+ * Method test for before
+ */
+ public void testBeforeTimestamp() {
+ Timestamp theTest = new Timestamp(TIME_LATE);
+
+ for (int i = 0; i < TIME_ARRAY.length; i++) {
+ Timestamp theTimestamp = new Timestamp(TIME_ARRAY[i]);
+
+ assertTrue(theTimestamp.before(theTest));
+ } // end for
+
+ theTest = new Timestamp(TIME_EARLY);
+
+ for (int i = 0; i < TIME_ARRAY.length; i++) {
+ Timestamp theTimestamp = new Timestamp(TIME_ARRAY[i]);
+
+ assertFalse(theTimestamp.before(theTest));
+ } // end for
+
+ for (int i = 0; i < TIME_ARRAY.length; i++) {
+ theTest = new Timestamp(TIME_ARRAY[i]);
+ Timestamp theTimestamp = new Timestamp(TIME_ARRAY[i]);
+
+ assertFalse(theTimestamp.before(theTest));
+ theTest.setNanos(theTest.getNanos() + 1);
+ assertTrue(theTimestamp.before(theTest));
+ } // end for
+
+ } // end method testbeforeTimestamp
+
+ /*
+ * Method test for after
+ */
+ public void testAfterTimestamp() {
+ Timestamp theTest = new Timestamp(TIME_LATE);
+
+ for (int i = 0; i < TIME_ARRAY.length; i++) {
+ Timestamp theTimestamp = new Timestamp(TIME_ARRAY[i]);
+
+ assertFalse(theTimestamp.after(theTest));
+ } // end for
+
+ theTest = new Timestamp(TIME_EARLY);
+
+ for (int i = 0; i < TIME_ARRAY.length; i++) {
+ Timestamp theTimestamp = new Timestamp(TIME_ARRAY[i]);
+
+ assertTrue(theTimestamp.after(theTest));
+ } // end for
+
+ for (int i = 0; i < TIME_ARRAY.length; i++) {
+ theTest = new Timestamp(TIME_ARRAY[i]);
+ Timestamp theTimestamp = new Timestamp(TIME_ARRAY[i]);
+
+ assertFalse(theTimestamp.after(theTest));
+ theTimestamp.setNanos(theTimestamp.getNanos() + 1);
+ assertTrue(theTimestamp.after(theTest));
+ } // end for
+
+ } // end method testafterTimestamp
+
+ /*
+ * Method test for compareTo
+ */
+ public void testCompareToTimestamp() {
+ Timestamp theTest = new Timestamp(TIME_EARLY);
+ Timestamp theTest2 = new Timestamp(TIME_LATE);
+
+ for (int i = 0; i < TIME_ARRAY.length; i++) {
+ Timestamp theTimestamp = new Timestamp(TIME_ARRAY[i]);
+ Timestamp theTimestamp2 = new Timestamp(TIME_ARRAY[i]);
+
+ assertTrue(theTimestamp.compareTo(theTest) > 0);
+ assertTrue(theTimestamp.compareTo(theTest2) < 0);
+ assertTrue(theTimestamp.compareTo(theTimestamp2) == 0);
+ } // end for
+
+ } // end method testcompareToTimestamp
+
+ /*
+ * Method test for compareTo
+ */
+ public void testCompareToObject() {
+ Object theTest = new Timestamp(TIME_EARLY);
+ Object theTest2 = new Timestamp(TIME_LATE);
+
+ for (int i = 0; i < TIME_ARRAY.length; i++) {
+ Timestamp theTimestamp = new Timestamp(TIME_ARRAY[i]);
+ Object theTimestamp2 = new Timestamp(TIME_ARRAY[i]);
+
+ assertTrue(theTimestamp.compareTo(theTest) > 0);
+ assertTrue(theTimestamp.compareTo(theTest2) < 0);
+ assertTrue(theTimestamp.compareTo(theTimestamp2) == 0);
+ } // end for
+
+ Object nastyTest = new String("Test ");
+ Timestamp theTimestamp = new Timestamp(TIME_ARRAY[1]);
+ try {
+ theTimestamp.compareTo(nastyTest);
+ fail(
+ "testCompareToObject: Did not get expected ClassCastException");
+ } catch (ClassCastException e) {
+ // Should get here
+ /*
+ * System.out.println("testCompareToObject: ClassCastException as
+ * expected"); System.out.println("Exception message: " +
+ * e.getMessage());
+ */
+ } // end try
+
+ } // end method testcompareToObject
+
+} // end class TimestampTest
Added: incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/tests/api/java/sql/TypesTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/tests/api/java/sql/TypesTest.java?rev=386087&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/tests/api/java/sql/TypesTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/tests/api/java/sql/TypesTest.java Wed Mar 15 06:55:38 2006
@@ -0,0 +1,126 @@
+/* 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 tests.api.java.sql;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
+import java.util.HashMap;
+
+import junit.framework.TestCase;
+
+public class TypesTest extends TestCase {
+
+ /*
+ * Public statics test
+ */
+ public void testPublicStatics() {
+
+ HashMap thePublicStatics = new HashMap();
+ thePublicStatics.put("BOOLEAN", new Integer(16));
+ thePublicStatics.put("DATALINK", new Integer(70));
+ thePublicStatics.put("REF", new Integer(2006));
+ thePublicStatics.put("CLOB", new Integer(2005));
+ thePublicStatics.put("BLOB", new Integer(2004));
+ thePublicStatics.put("ARRAY", new Integer(2003));
+ thePublicStatics.put("STRUCT", new Integer(2002));
+ thePublicStatics.put("DISTINCT", new Integer(2001));
+ thePublicStatics.put("JAVA_OBJECT", new Integer(2000));
+ thePublicStatics.put("OTHER", new Integer(1111));
+ thePublicStatics.put("NULL", new Integer(0));
+ thePublicStatics.put("LONGVARBINARY", new Integer(-4));
+ thePublicStatics.put("VARBINARY", new Integer(-3));
+ thePublicStatics.put("BINARY", new Integer(-2));
+ thePublicStatics.put("TIMESTAMP", new Integer(93));
+ thePublicStatics.put("TIME", new Integer(92));
+ thePublicStatics.put("DATE", new Integer(91));
+ thePublicStatics.put("LONGVARCHAR", new Integer(-1));
+ thePublicStatics.put("VARCHAR", new Integer(12));
+ thePublicStatics.put("CHAR", new Integer(1));
+ thePublicStatics.put("DECIMAL", new Integer(3));
+ thePublicStatics.put("NUMERIC", new Integer(2));
+ thePublicStatics.put("DOUBLE", new Integer(8));
+ thePublicStatics.put("REAL", new Integer(7));
+ thePublicStatics.put("FLOAT", new Integer(6));
+ thePublicStatics.put("BIGINT", new Integer(-5));
+ thePublicStatics.put("INTEGER", new Integer(4));
+ thePublicStatics.put("SMALLINT", new Integer(5));
+ thePublicStatics.put("TINYINT", new Integer(-6));
+ thePublicStatics.put("BIT", new Integer(-7));
+
+ /*
+ * System.out.println( "BOOLEAN: " + Types.BOOLEAN );
+ * System.out.println( "DATALINK: " + Types.DATALINK );
+ * System.out.println( "REF: " + Types.REF ); System.out.println( "CLOB: " +
+ * Types.CLOB ); System.out.println( "BLOB: " + Types.BLOB );
+ * System.out.println( "ARRAY: " + Types.ARRAY ); System.out.println(
+ * "STRUCT: " + Types.STRUCT ); System.out.println( "DISTINCT: " +
+ * Types.DISTINCT ); System.out.println( "JAVA_OBJECT: " +
+ * Types.JAVA_OBJECT ); System.out.println( "OTHER: " + Types.OTHER );
+ * System.out.println( "NULL: " + Types.NULL ); System.out.println(
+ * "LONGVARBINARY: " + Types.LONGVARBINARY ); System.out.println(
+ * "VARBINARY: " + Types.VARBINARY ); System.out.println( "BINARY: " +
+ * Types.BINARY ); System.out.println( "TIMESTAMP: " + Types.TIMESTAMP );
+ * System.out.println( "TIME: " + Types.TIME ); System.out.println(
+ * "DATE: " + Types.DATE ); System.out.println( "LONGVARCHAR: " +
+ * Types.LONGVARCHAR ); System.out.println( "VARCHAR: " + Types.VARCHAR );
+ * System.out.println( "CHAR: " + Types.CHAR ); System.out.println(
+ * "DECIMAL: " + Types.DECIMAL ); System.out.println( "NUMERIC: " +
+ * Types.NUMERIC ); System.out.println( "DOUBLE: " + Types.DOUBLE );
+ * System.out.println( "REAL: " + Types.REAL ); System.out.println(
+ * "FLOAT: " + Types.FLOAT ); System.out.println( "BIGINT: " +
+ * Types.BIGINT ); System.out.println( "INTEGER: " + Types.INTEGER );
+ * System.out.println( "SMALLINT: " + Types.SMALLINT );
+ * System.out.println( "TINYINT: " + Types.TINYINT );
+ * System.out.println( "BIT: " + Types.BIT );
+ */
+
+ Class typesClass;
+ try {
+ typesClass = Class.forName("java.sql.Types");
+ } catch (ClassNotFoundException e) {
+ fail("java.sql.Types class not found!");
+ return;
+ } // end try
+
+ Field[] theFields = typesClass.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 TypesTest
Added: incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/tests/api/javax/sql/AllTests.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/tests/api/javax/sql/AllTests.java?rev=386087&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/tests/api/javax/sql/AllTests.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/tests/api/javax/sql/AllTests.java Wed Mar 15 06:55:38 2006
@@ -0,0 +1,50 @@
+/* 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 tests.api.javax.sql;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * Test suite for the javax.sql package
+ *
+ */
+public class AllTests {
+
+ public static Test suite() {
+ TestSuite suite = new TestSuite("Test for tests.api.java.sql");
+ // $JUnit-BEGIN$
+ suite.addTestSuite(ConnectionEventTest.class);
+ suite.addTestSuite(RowSetEventTest.class);
+ // Tests needed for the following interfaces are not mandatory
+ // are supplied to check Public Static values:
+ suite.addTestSuite(ConnectionEventListenerTest.class);
+ suite.addTestSuite(ConnectionPoolDataSourceTest.class);
+ suite.addTestSuite(DataSourceTest.class);
+ suite.addTestSuite(PooledConnectionTest.class);
+ suite.addTestSuite(RowSetInternalTest.class);
+ suite.addTestSuite(RowSetListenerTest.class);
+ suite.addTestSuite(RowSetMetaDataTest.class);
+ suite.addTestSuite(RowSetReaderTest.class);
+ suite.addTestSuite(RowSetTest.class);
+ suite.addTestSuite(RowSetWriterTest.class);
+ suite.addTestSuite(XAConnectionTest.class);
+ suite.addTestSuite(XADataSourceTest.class);
+
+ // $JUnit-END$
+ return suite;
+ }
+}