harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r386087 [41/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/ ...
Date Wed, 15 Mar 2006 14:57:17 GMT
Added: incubator/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/javax/transaction/xa/XAException.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/javax/transaction/xa/XAException.java?rev=386087&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/javax/transaction/xa/XAException.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/javax/transaction/xa/XAException.java Wed Mar 15 06:55:38 2006
@@ -0,0 +1,190 @@
+/* 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 javax.transaction.xa;
+import java.io.Serializable;
+
+/**
+ * An XAException is an exception thrown by a Resource Manager to inform the Transaction Manaqer
+ * of an error which has occurred in relation to a transaction branch.  In addition to the usual
+ * exception message, an XAException carries an errorCode value which provides information about
+ * the error, as defined by the series of integer values defined by the XAException class. 
+ * 
+ */
+public class XAException extends Exception implements Serializable {
+	
+	private static final long serialVersionUID = -8249683284832867751L;
+
+	/**
+	 * The errorCode which details the error that has occurred
+	 */
+	public int errorCode = 0;
+	
+	/**
+	 * Code which contains the inclusive lower bound of the rollback error codes
+	 */
+	public static final int XA_RBBASE		= 100;
+
+	/**
+	 * Code which means that the rollback occurred for an unspecified reason
+	 */
+	public static final int XA_RBROLLBACK	= 100;
+
+	/**
+	 * Code which means that rollback was caused by a communication failure
+	 */
+	public static final int XA_RBCOMMFAIL	= 101;
+
+	/**
+	 * Code which means that a failure occurred because a deadlock was detected
+	 */
+	public static final int XA_RBDEADLOCK	= 102;
+
+	/**
+	 * Code which means that a condition was detected than implies a violation of the integrity of
+	 * the resource
+	 */
+	public static final int XA_RBINTEGRITY	= 103;
+
+	/**
+	 * Code which means that the Resource Manager rolled back the transaction branch for a 
+	 * reason not separately listed
+	 */
+	public static final int XA_RBOTHER		= 104;
+
+	/**
+	 * Code which means that a protocol error occurred in the Resource Manager
+	 */
+	public static final int XA_RBPROTO		= 105;
+
+	/**
+	 * Code which means that a transaction branch took too long
+	 */
+	public static final int XA_RBTIMEOUT	= 106;
+
+	/**
+	 * Code which means that the caller may retry the transaction branch
+	 */
+	public static final int XA_RBTRANSIENT	= 107;
+
+	/**
+	 * Code which contains the inclusive upper bound of the rollback error codes
+	 */
+	public static final int XA_RBEND		= 107;
+
+	/**
+	 * Code which means that resumption must occur where the suspension occurred
+	 */
+	public static final int XA_NOMIGRATE	= 9;
+
+	/**
+	 * Code which means that the transaction branch may have been heuristically completed
+	 */
+	public static final int XA_HEURHAZ		= 8;
+
+	/**
+	 * Code which means that the transaction branch has been heuristically committed
+	 */
+	public static final int XA_HEURCOM		= 7;
+
+	/**
+	 * Code which means that the transaction branch has been neuristically rolled back
+	 */
+	public static final int XA_HEURRB		= 6;
+
+	/**
+	 * Code which means that the transaction branch has been heuristically committed and rolled back
+	 */
+	public static final int XA_HEURMIX		= 5;
+
+	/**
+	 * Code which means that the method returned with no effect and can be reissued
+	 */
+	public static final int XA_RETRY		= 4;
+
+	/**
+	 * Code which means that the transaction branch was read only and has been committed
+	 */
+	public static final int XA_RDONLY		= 3;
+
+	/**
+	 * Code which means that there is already an asynchronous operation outstanding
+	 */
+	public static final int XAER_ASYNC		= -2;
+
+	/**
+	 * Code which means that a Resource Manager error has occurred for the transaction branch
+	 */
+	public static final int XAER_RMERR		= -3;
+
+	/**
+	 * Code which means that the XID is not valid
+	 */
+	public static final int XAER_NOTA		= -4;
+
+	/**
+	 * Code which means that invalid arguments were supplied
+	 */
+	public static final int XAER_INVAL		= -5;
+	
+	/**
+	 * Code which means that the method was invoked in an impropoer context
+	 */
+	public static final int XAER_PROTO		= -6;
+
+	/**
+	 * Code which means that the Resource Manager is unavailable
+	 */
+	public static final int XAER_RMFAIL		= -7;
+
+	/**
+	 * Code which means that the XID already exists
+	 */
+	public static final int XAER_DUPID		= -8;
+
+	/**
+	 * Work is being done by the Resource Manager outside the boundaries of a
+	 * global transaction.
+	 */
+	public static final int XAER_OUTSIDE	= -9;
+	
+	/**
+	 * Creates an XAException with no message or errorcode
+	 */
+	public XAException() {
+		super();
+	} // end method XAException
+	
+	/**
+	 * Creates an XAException with a supplied message and no errorcode
+	 * @param theMessage a String containing the exception message 
+	 */
+	public XAException( String theMessage ) {
+		super( theMessage );
+	} // end method XAException( String )
+	
+	/**
+	 * Creates an XAException with a specified errorcode but no message
+	 * @param errcode an integer containing one of the XAException errorCode values
+	 */
+	public XAException(int errcode) {
+		super();
+		errorCode = errcode;
+	} // end method XAException( int )
+	
+} // end class XAException
+
+

Added: incubator/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/javax/transaction/xa/XAResource.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/javax/transaction/xa/XAResource.java?rev=386087&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/javax/transaction/xa/XAResource.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/javax/transaction/xa/XAResource.java Wed Mar 15 06:55:38 2006
@@ -0,0 +1,227 @@
+/* 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 javax.transaction.xa;
+
+/**
+ * An interface which provides a mapping of the X/Open CAE Specification (for Distributed Transaction
+ * processing) into Java.  The XAResource interface is used as the interface between a 
+ * Transaction Manager and a Resource Manager for handling distributed transaction processing.
+ * <p>
+ * Typically, a JDBC driver or a JMS driver will implement the XAResource interface to support
+ * Global Transactions on a database or on a message connection. 
+ * 
+ */
+public interface XAResource {
+	
+	/**
+	 * Flag to end a recovery scan
+	 */
+	public static final int TMENDRSCAN	= 0x800000;
+
+	/**
+	 * Flag to indicate that the caller is dissociation from a transaction branch and that it 
+	 * should be marked rollback only
+	 */
+	public static final int TMFAIL		= 0x20000000;
+
+	/**
+	 * Flag to indicate that the caller is joiing sn existing transaction branch.
+	 */
+	public static final int TMJOIN		= 0x200000;
+
+	/**
+	 * Flag that indicates that no flags options are selected. (ie a null flag)
+	 */
+	public static final int TMNOFLAGS	= 0;
+
+	/**
+	 * Flag that indicates the caller is using one-phase commit optimization
+	 */
+	public static final int TMONEPHASE	= 0x40000000;
+
+	/**
+	 * Flag that indicates the caller is resuming association with a suspended transaction branch
+	 */
+	public static final int TMRESUME	= 0x8000000;
+
+	/**
+	 * Flag that indicates the start of a recovery scan
+	 */
+	public static final int TMSTARTRSCAN	= 0x1000000;
+
+	/**
+	 * Flag that indicates the caller is dissociating from a transaction branch
+	 */
+	public static final int TMSUCCESS	= 0x4000000;
+
+	/**
+	 * Flag that indicates that the caller is suspending (not terminating) its association
+	 * with a transaction branch.
+	 */
+	public static final int TMSUSPEND	= 0x2000000;
+
+	/**
+	 * Flag that indicates that transaction work has been read only and has been 
+	 * committed normally
+	 */
+	public static final int XA_RDONLY	= 3;
+
+	/**
+	 * Flag that indicates that transaction work has been Prepared normally 
+	 */
+	public static final int XA_OK		= 0;
+	
+	/**
+	 * Commits a global transaction.
+	 * @param xid the XID which identifies the global transaction
+	 * @param onePhase true if the resource manager should use a one-phase commit protocol to 
+	 * commit the transaction
+	 * @throws XAException if an error occurred.
+	 * <p>
+	 * Possible errors are identified by the errorcode in the XAException and include:
+	 * XA_HEURHAZ, XA_HEURCOM, XA_HEURRB, XA_HEURMIX, XAER_RMERR, XAER_RMFAIL, XAER_NOTA, 
+	 * XAER_INVAL, or XAER_PROTO.  In addition, one of the XA_RB* errors can occur if the transaction
+	 * was not committed and <code>onePhase</code> was set to true.  On completion of this method,
+	 * the Resource Manager has rolled back the transaction and released resources held by the
+	 * transaction.
+	 */
+	public void commit(Xid xid, boolean onePhase) throws XAException;
+
+	/**
+	 * Ends the work done for a transaction branch. The Resource Manager
+	 * disconnects the XA resource from the transaction branch and allows the
+	 * transaction to complete.
+	 * 
+	 * @param xid
+	 *            the XID which identifies the global transaction. Should have
+	 *            previously been used as the parameter to a <code>start</code>
+	 *            method.
+	 * @param flags
+	 *            a flags integer - one of: XAResource.TMSUCCESS,
+	 *            XAResource.TMFAIL, or XAResource.TMSUSPEND.
+	 *            <p>
+	 *            TMSUCCESS means that this section of work completed
+	 *            successfully.
+	 *            <p>
+	 *            TMFAIL means that this section of work failed. The Resource
+	 *            Manager can mark the transaction for rollback only.
+	 *            <p>
+	 *            TMSUSPEND means that this section of work is suspended and not yet
+	 *            complete. The associated transaction context is also suspended
+	 *            and must be restarted with a call to {@link #start(Xid, int)}
+	 *            with the <code>TMRESUME</code> flag.
+	 * @throws XAException
+	 *             if an error occurs. Possible error identified in the
+	 *             errorcode include: XAER_RMERR, XAER_RMFAIL, XAER_NOTA,
+	 *             XAER_INVAL, XAER_PROTO, or XA_RB*.
+	 */
+	public void end(Xid xid, int flags) throws XAException;
+	
+	/**
+	 * Informs the Resource Manager that it can forget about a specified transaction branch.
+	 * @param xid the XID which identifies the global transaction.
+	 * @throws XAException if an error occurs. Possible error identified in the errorcode include:
+	 * XAER_RMERR, XAER_RMFAIL, XAER_NOTA, XAER_INVAL, or XAER_PROTO.
+	 */
+	public void forget(Xid xid) throws XAException;
+	
+	/**
+	 * Gets the transaction timeout value for this XAResource.  The default timeout value is the 
+	 * default timeout value set for the Resource Manager.
+	 * @return the transaction timeout value for this XAResource in seconds.
+	 * @throws XAException if an error occurs. Possible error identified in the errorcode include:
+	 * XAER_RMERR and XAER_RMFAIL.
+	 */
+	public int getTransactionTimeout() throws XAException;
+	
+	/**
+	 * Returns true if the ResourceManager for this XAResource is the same as the Resource Manager
+	 * for a supplied XAResource.
+	 * @param theXAResource an XAResource object
+	 * @return true if the Resource Manager for this XAResource is the same as the Resource Manager
+	 * for <code>theXAResource</code>.
+	 * @throws XAException if an error occurs. Possible error identified in the errorcode include:
+	 * XAER_RMERR and XAER_RMFAIL.
+	 */
+	public boolean isSameRM(XAResource theXAResource) throws XAException;
+	
+	/**
+	 * Requests the Resource manager to prepare to commit a specified transaction.
+	 * @param xid  the XID which identifies the global transaction.
+	 * @return  an integer: XA_RDONLY or XA_OK. XA_OK implies that the transaction work has 
+	 * been prepared normally, XA_RDONLY implies that the transaction branch is read only and 
+	 * has been committed.  If there is a failure which requires a rollback, an XAException
+	 * is raised.
+	 * @throws XAException if an error occurs. Possible error identified in the errorcode include:
+	 * XA_RB*, XAER_RMERR, XAER_RMFAIL, XAER_NOTA, XAER_INVAL, or XAER_PROTO.
+	 */
+	public int prepare(Xid xid) throws XAException;
+	
+	/**
+	 * Get a list of prepared transaction branches.
+	 * <p>
+	 * Typically used by a transaction manager during recovery to find transaction branches that
+	 * are in prepared or heuristically completed states.
+	 * @param flag an integer.  Must be one of: XAResource.TMSTARTRSCAN, XAResource.TMENDRSCAN, 
+	 * XAResource.TMNOFLAGS.
+	 * @return an array of zero or more XIDs identifying the transaction branches in the prepared
+	 * or heuristically completed states.
+	 * @throws XAException if an error occurs. Possible error identified in the errorcode include:
+	 * XAER_RMERR, XAER_RMFAIL, XAER_INVAL, and XAER_PROTO.
+	 */
+	public Xid[] recover(int flag) throws XAException;
+	
+	/**
+	 * Requests the Resource Manager to rollback a specified transaction branch.   
+	 * @param xid the XID which identifies the transaction branch.
+	 * @throws XAException if an error occurs. 
+	 */
+	public void rollback(Xid xid) throws XAException;
+	
+	/**
+	 * Sets the transaction timeout value for this XAResource. If the value is set to 0, the 
+	 * default timeout value for the Resource Manager is used.
+	 * @param seconds the new Timeout value in seconds
+	 * @return true if the transaction timeout value has been updated, false otherwise.
+	 * @throws XAException if an error occurs. Possible error identified in the errorcode include:
+	 * XAER_RMERR, XAER_RMFAIL, or XAER_INVAL.
+	 */
+	public boolean setTransactionTimeout(int seconds) throws XAException;
+	
+	/**
+	 * Starts work for a specified transaction branch.
+	 * @param xid the XID which identifies the transaction branch.
+	 * @param flags an integer.  Must be one of XAResource.TMNOFLAGS, XAResource.TMJOIN, or 
+	 * XAResource.TMRESUME.
+	 * <p>
+	 * TMJOIN implies that the start applies to joiing a transaction previously passed to the
+	 * Resource Manager.
+	 * <p>
+	 * TMRESUME implies that the start applies to a suspended transaction that should be restarted.
+	 * <p>
+	 * If TMNOFLAGS is specified, then if the transaction has been previously seen by the 
+	 * Resource Manager, an XAException is raised with the code XAER_DUPID.
+	 * @throws XAException if an error occurs. Possible error identified in the errorcode include:
+	 * XA_RB*, XAER_RMERR, XAER_RMFAIL, XAER_DUPID, XAER_OUTSIDE, XAER_NOTA, XAER_INVAL, or 
+	 * XAER_PROTO.
+	 */
+	public void start(Xid xid, int flags) throws XAException;
+
+
+} // end interface XAResource
+
+

Added: incubator/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/javax/transaction/xa/Xid.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/javax/transaction/xa/Xid.java?rev=386087&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/javax/transaction/xa/Xid.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/javax/transaction/xa/Xid.java Wed Mar 15 06:55:38 2006
@@ -0,0 +1,56 @@
+/* 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 javax.transaction.xa;
+
+/**
+ * An interface which provides a mapping for the X/Open XID transaction identifier structure.
+ * The Xid interface is used by the Transaction Manager and the Resource managers.  It is not
+ * typically used by application programs.
+ * 
+ */
+public interface Xid {
+	
+	/**
+	 * The maximum number of bytes which will be returned by getGlobaltransaction Id
+	 */
+	public static final int MAXGTRIDSIZE	= 64;
+
+	/**
+	 * The maximum number of bytes which will be returned by getBranchQualifier
+	 */
+	public static final int MAXBQUALSIZE	= 64;
+	
+	/**
+	 * Gets the transaction branch qualifier component of the XID.
+	 * @return an array of bytes containing the transaction branch qualifier.
+	 */
+	public byte[] getBranchQualifier();
+	
+	/**
+	 * Gets the format identifier component of the XID.
+	 * @return an integer containing the format identifier.  0 means the OSI CCR format.
+	 */
+	public int getFormatId();
+	
+	/**
+	 * Gets the global transaction identifier component of the XID.
+	 * @return an array of bytes containing the global transaction identifier.
+	 */
+	public byte[] getGlobalTransactionId();
+
+} // end interface Xid
+

Added: incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/tests/api/java/sql/AllTests.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/tests/api/java/sql/AllTests.java?rev=386087&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/tests/api/java/sql/AllTests.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/tests/api/java/sql/AllTests.java Wed Mar 15 06:55:38 2006
@@ -0,0 +1,67 @@
+/* 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 junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * Test suite for the java.sql package
+ * 
+ */
+public class AllTests {
+
+	public static Test suite() {
+		TestSuite suite = new TestSuite("Test for tests.api.java.sql");
+		// $JUnit-BEGIN$
+		suite.addTestSuite(BatchUpdateExceptionTest.class);
+		suite.addTestSuite(DataTruncationTest.class);
+		suite.addTestSuite(DateTest.class);
+		suite.addTestSuite(DriverManagerTest.class);
+		suite.addTestSuite(DriverPropertyInfoTest.class);
+		suite.addTestSuite(SQLPermissionTest.class);
+		suite.addTestSuite(DatabaseMetaDataTest.class);
+		suite.addTestSuite(ResultSetMetaDataTest.class);
+		suite.addTestSuite(ConnectionTest.class);
+		suite.addTestSuite(ParameterMetaDataTest.class);
+		suite.addTestSuite(ResultSetTest.class);
+		suite.addTestSuite(SQLExceptionTest.class);
+		suite.addTestSuite(SQLWarningTest.class);
+		suite.addTestSuite(StatementTest.class);
+		suite.addTestSuite(TimeTest.class);
+		suite.addTestSuite(TimestampTest.class);
+		suite.addTestSuite(TypesTest.class);
+		// Tests needed for the following interfaces are not mandatory but some
+		// are supplied to check Public Static values:
+		// Array
+		// Blob
+		// CallableStatement
+		// Clob
+		// Connection
+		// Driver
+		// ParameterMetaData
+		// PreparedStatement
+		// Ref
+		// Savepoint
+		// Struct
+		// SQLData
+		// SQLInput
+		// SQLOutput
+		// $JUnit-END$
+		return suite;
+	}
+}
+

Added: incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/tests/api/java/sql/ArrayTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/tests/api/java/sql/ArrayTest.java?rev=386087&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/tests/api/java/sql/ArrayTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/tests/api/java/sql/ArrayTest.java Wed Mar 15 06:55:38 2006
@@ -0,0 +1,22 @@
+/* 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 junit.framework.TestCase;
+
+public class ArrayTest extends TestCase {
+
+}
\ No newline at end of file

Added: incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/tests/api/java/sql/BatchUpdateExceptionTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/tests/api/java/sql/BatchUpdateExceptionTest.java?rev=386087&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/tests/api/java/sql/BatchUpdateExceptionTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/tests/api/java/sql/BatchUpdateExceptionTest.java Wed Mar 15 06:55:38 2006
@@ -0,0 +1,326 @@
+/* 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.BatchUpdateException;
+
+import junit.framework.TestCase;
+
+public class BatchUpdateExceptionTest extends TestCase {
+
+	/*
+	 * ConstructorTest
+	 */
+	public void testBatchUpdateException() {
+
+		int[] theFinalStates1 = { 0 }; // Error Code state
+		int[][] theFinalStates2 = { null }; // Update Counts array state
+		String[] theFinalStates3 = { null }; // SQL State state value
+		String[] theFinalStates4 = { null }; // Message state
+
+		Exception[] theExceptions = { null };
+
+		BatchUpdateException aBatchUpdateException;
+		int loopCount = 1;
+		for (int i = 0; i < loopCount; i++) {
+			try {
+				aBatchUpdateException = new BatchUpdateException();
+				if (theExceptions[i] != null)
+					assertTrue(false);
+				assertEquals(i + " Final state mismatch: ",
+						aBatchUpdateException.getErrorCode(),
+						theFinalStates1[i]);
+				assertEquals(i + " Final state mismatch: ",
+						aBatchUpdateException.getUpdateCounts(),
+						theFinalStates2[i]);
+				assertEquals(i + " Final state mismatch: ",
+						aBatchUpdateException.getSQLState(), theFinalStates3[i]);
+				assertEquals(i + " Final state mismatch: ",
+						aBatchUpdateException.getMessage(), theFinalStates4[i]);
+
+			} catch (Exception e) {
+				if (theExceptions[i] == null)
+					fail(i + "Unexpected exception");
+				assertEquals(i + "Exception mismatch", e.getClass(),
+						theExceptions[i].getClass());
+				assertEquals(i + "Exception mismatch", e.getMessage(),
+						theExceptions[i].getMessage());
+			} // end try
+		} // end for
+
+	} // end method testBatchUpdateException
+
+	/*
+	 * ConstructorTest
+	 */
+	public void testBatchUpdateExceptionintArray() {
+
+		int[][] init1 = { { 1, 2, 3 }, null };
+
+		int[] theFinalStates1 = { 0, 0 }; // Error Code state
+		int[][] theFinalStates2 = init1; // Update Counts array state
+		String[] theFinalStates3 = { null, null }; // SQL State state value
+		String[] theFinalStates4 = { null, null }; // Message state
+
+		Exception[] theExceptions = { null, null };
+
+		BatchUpdateException aBatchUpdateException;
+		int loopCount = init1.length;
+		for (int i = 0; i < loopCount; i++) {
+			try {
+				aBatchUpdateException = new BatchUpdateException(init1[i]);
+				if (theExceptions[i] != null)
+					assertTrue(false);
+				assertEquals(i + " Final state mismatch: ",
+						aBatchUpdateException.getErrorCode(),
+						theFinalStates1[i]);
+				assertEquals(i + " Final state mismatch: ",
+						aBatchUpdateException.getUpdateCounts(),
+						theFinalStates2[i]);
+				assertEquals(i + " Final state mismatch: ",
+						aBatchUpdateException.getSQLState(), theFinalStates3[i]);
+				assertEquals(i + " Final state mismatch: ",
+						aBatchUpdateException.getMessage(), theFinalStates4[i]);
+
+			} catch (Exception e) {
+				if (theExceptions[i] == null)
+					fail(i + "Unexpected exception");
+				assertEquals(i + "Exception mismatch", e.getClass(),
+						theExceptions[i].getClass());
+				assertEquals(i + "Exception mismatch", e.getMessage(),
+						theExceptions[i].getMessage());
+			} // end try
+		} // end for
+
+	} // end method testBatchUpdateExceptionintArray
+
+	/*
+	 * ConstructorTest
+	 */
+	public void testBatchUpdateExceptionStringintArray() {
+
+		String[] init1 = { "a", "1", "valid1", "----", "&valid*", null, "",
+				".", "a" };
+		int[][] init2 = { { 1, 2, 3 }, {}, { 3 }, null, { 5, 5 }, { 6 },
+				{ 121, 2, 1 }, { 1 }, { 1, 2 } };
+
+		int[] theFinalStates1 = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; // Error Code
+																// state
+		// Update Counts array state
+		int[][] theFinalStates2 = init2;
+		// SQL State state value
+		String[] theFinalStates3 = { null, null, null, null, null, null, null,
+				null, null };
+		String[] theFinalStates4 = init1; // Message state
+
+		Exception[] theExceptions = { null, null, null, null, null, null, null,
+				null, null };
+
+		BatchUpdateException aBatchUpdateException;
+		int loopCount = init1.length;
+		for (int i = 0; i < loopCount; i++) {
+			try {
+				aBatchUpdateException = new BatchUpdateException(init1[i],
+						init2[i]);
+				if (theExceptions[i] != null)
+					assertTrue(false);
+				assertEquals(i + " Final state mismatch: ",
+						aBatchUpdateException.getErrorCode(),
+						theFinalStates1[i]);
+				assertEquals(i + " Final state mismatch: ",
+						aBatchUpdateException.getUpdateCounts(),
+						theFinalStates2[i]);
+				assertEquals(i + " Final state mismatch: ",
+						aBatchUpdateException.getSQLState(), theFinalStates3[i]);
+				assertEquals(i + " Final state mismatch: ",
+						aBatchUpdateException.getMessage(), theFinalStates4[i]);
+
+			} catch (Exception e) {
+				if (theExceptions[i] == null)
+					fail(i + "Unexpected exception");
+				assertEquals(i + "Exception mismatch", e.getClass(),
+						theExceptions[i].getClass());
+				assertEquals(i + "Exception mismatch", e.getMessage(),
+						theExceptions[i].getMessage());
+			} // end try
+		} // end for
+
+	} // end method testBatchUpdateExceptionStringintArray
+
+	/*
+	 * ConstructorTest
+	 */
+	public void testBatchUpdateExceptionStringStringintArray() {
+
+		String[] init1 = { "a", "1", "valid1", "----", "&valid*", null, "",
+				".", "a", "a" };
+		String[] init2 = { "a", "1", "valid1", "----", "&valid*", "a", null,
+				"", ".", "a" };
+		int[][] init3 = { { 1, 2, 3 }, {}, { 3 }, { 5, 5 }, { 6 },
+				{ 121, 2, 1 }, { 1 }, { 1, 2 }, { 1 }, { 2 }, null };
+
+		int[] theFinalStates1 = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; // Error
+																		// Code
+																		// state
+		// Update Counts array state
+		int[][] theFinalStates2 = init3;
+		// SQL State state value
+		String[] theFinalStates3 = init2;
+		String[] theFinalStates4 = init1; // Message state
+
+		Exception[] theExceptions = { null, null, null, null, null, null, null,
+				null, null, null, null };
+
+		BatchUpdateException aBatchUpdateException;
+		int loopCount = init1.length;
+		for (int i = 0; i < loopCount; i++) {
+			try {
+				aBatchUpdateException = new BatchUpdateException(init1[i],
+						init2[i], init3[i]);
+				if (theExceptions[i] != null)
+					assertTrue(false);
+				assertEquals(i + " Final state mismatch: ",
+						aBatchUpdateException.getErrorCode(),
+						theFinalStates1[i]);
+				assertEquals(i + " Final state mismatch: ",
+						aBatchUpdateException.getUpdateCounts(),
+						theFinalStates2[i]);
+				assertEquals(i + " Final state mismatch: ",
+						aBatchUpdateException.getSQLState(), theFinalStates3[i]);
+				assertEquals(i + " Final state mismatch: ",
+						aBatchUpdateException.getMessage(), theFinalStates4[i]);
+
+			} catch (Exception e) {
+				if (theExceptions[i] == null)
+					fail(i + "Unexpected exception");
+				assertEquals(i + "Exception mismatch", e.getClass(),
+						theExceptions[i].getClass());
+				assertEquals(i + "Exception mismatch", e.getMessage(),
+						theExceptions[i].getMessage());
+			} // end try
+		} // end for
+
+	} // end method testBatchUpdateExceptionStringStringintArray
+
+	/*
+	 * ConstructorTest
+	 */
+	public void testBatchUpdateExceptionStringStringintintArray() {
+
+		String[] init1 = { "a", "1", "valid1", "----", "&valid*", null, "",
+				".", "a", "a" };
+		String[] init2 = { "a", "1", "valid1", "----", "&valid*", "a", null,
+				"", ".", "a" };
+		int[] init3 = { -2147483648, 2147483647, 0, -492417162, -156220255,
+				-173012890, -631026360, -2147483648, -2147483648, -2147483648,
+				-2147483648 };
+		int[][] init4 = { { 1, 2, 3 }, {}, { 3 }, { 5, 5 }, { 6 },
+				{ 121, 2, 1 }, { 1 }, { 1, 2 }, { 1 }, { 2 }, null };
+
+		int[] theFinalStates1 = init3; // Error Code state
+		// Update Counts array state
+		int[][] theFinalStates2 = init4;
+		// SQL State state value
+		String[] theFinalStates3 = init2;
+		String[] theFinalStates4 = init1; // Message state
+
+		Exception[] theExceptions = { null, null, null, null, null, null, null,
+				null, null, null, null };
+
+		BatchUpdateException aBatchUpdateException;
+		int loopCount = init1.length;
+		for (int i = 0; i < loopCount; i++) {
+			try {
+				aBatchUpdateException = new BatchUpdateException(init1[i],
+						init2[i], init3[i], init4[i]);
+				if (theExceptions[i] != null)
+					assertTrue(false);
+				assertEquals(i + " Final state mismatch: ",
+						aBatchUpdateException.getErrorCode(),
+						theFinalStates1[i]);
+				assertEquals(i + " Final state mismatch: ",
+						aBatchUpdateException.getUpdateCounts(),
+						theFinalStates2[i]);
+				assertEquals(i + " Final state mismatch: ",
+						aBatchUpdateException.getSQLState(), theFinalStates3[i]);
+				assertEquals(i + " Final state mismatch: ",
+						aBatchUpdateException.getMessage(), theFinalStates4[i]);
+
+			} catch (Exception e) {
+				if (theExceptions[i] == null)
+					fail(i + "Unexpected exception");
+				assertEquals(i + "Exception mismatch", e.getClass(),
+						theExceptions[i].getClass());
+				assertEquals(i + "Exception mismatch", e.getMessage(),
+						theExceptions[i].getMessage());
+			} // end try
+		} // end for
+
+	} // end method testBatchUpdateExceptionStringStringintintArray
+
+	/*
+	 * Method test for getUpdateCounts
+	 */
+	public void testGetUpdateCounts() {
+
+		BatchUpdateException aBatchUpdateException;
+		int[][] init1 = { { 1, 2, 3 }, {}, null };
+
+		int[] theReturn;
+		int[][] theReturns = init1;
+
+		int[] theFinalStates1 = { 0, 0, 0 }; // Error Code state
+		int[][] theFinalStates2 = init1; // Update Counts array state
+		String[] theFinalStates3 = { null, null, null }; // SQL State state
+															// value
+		String[] theFinalStates4 = { null, null, null }; // Message state
+
+		Exception[] theExceptions = { null, null, null };
+
+		int loopCount = init1.length;
+		for (int i = 0; i < loopCount; i++) {
+			try {
+				aBatchUpdateException = new BatchUpdateException(init1[i]);
+				theReturn = aBatchUpdateException.getUpdateCounts();
+				if (theExceptions[i] != null)
+					fail(i + "Exception missed");
+				assertEquals(i + "Return value mismatch", theReturn,
+						theReturns[i]);
+				assertEquals(i + " Final state mismatch: ",
+						aBatchUpdateException.getErrorCode(),
+						theFinalStates1[i]);
+				assertEquals(i + " Final state mismatch: ",
+						aBatchUpdateException.getUpdateCounts(),
+						theFinalStates2[i]);
+				assertEquals(i + " Final state mismatch: ",
+						aBatchUpdateException.getSQLState(), theFinalStates3[i]);
+				assertEquals(i + " Final state mismatch: ",
+						aBatchUpdateException.getMessage(), theFinalStates4[i]);
+
+			} catch (Exception e) {
+				if (theExceptions[i] == null)
+					fail(i + "Unexpected exception");
+				assertEquals(i + "Exception mismatch", e.getClass(),
+						theExceptions[i].getClass());
+				assertEquals(i + "Exception mismatch", e.getMessage(),
+						theExceptions[i].getMessage());
+			} // end try
+		} // end for
+
+	} // end method testGetUpdateCounts
+
+} // end class BatchUpdateExceptionTest
+

Added: incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/tests/api/java/sql/ConnectionTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/tests/api/java/sql/ConnectionTest.java?rev=386087&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/tests/api/java/sql/ConnectionTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/tests/api/java/sql/ConnectionTest.java Wed Mar 15 06:55:38 2006
@@ -0,0 +1,87 @@
+/* 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 ConnectionTest extends TestCase {
+
+	/*
+	 * Public statics test
+	 */
+	public void testPublicStatics() {
+
+		HashMap thePublicStatics = new HashMap();
+		thePublicStatics.put("TRANSACTION_SERIALIZABLE", new Integer(8));
+		thePublicStatics.put("TRANSACTION_REPEATABLE_READ", new Integer(4));
+		thePublicStatics.put("TRANSACTION_READ_COMMITTED", new Integer(2));
+		thePublicStatics.put("TRANSACTION_READ_UNCOMMITTED", new Integer(1));
+		thePublicStatics.put("TRANSACTION_NONE", new Integer(0));
+
+		/*
+		 * System.out.println( "TRANSACTION_SERIALIZABLE: " +
+		 * Connection.TRANSACTION_SERIALIZABLE ); System.out.println(
+		 * "TRANSACTION_REPEATABLE_READ: " +
+		 * Connection.TRANSACTION_REPEATABLE_READ ); System.out.println(
+		 * "TRANSACTION_READ_COMMITTED: " +
+		 * Connection.TRANSACTION_READ_COMMITTED ); System.out.println(
+		 * "TRANSACTION_READ_UNCOMMITTED: " +
+		 * Connection.TRANSACTION_READ_UNCOMMITTED ); System.out.println(
+		 * "TRANSACTION_NONE: " + Connection.TRANSACTION_NONE );
+		 */
+
+		Class connectionClass;
+		try {
+			connectionClass = Class.forName("java.sql.Connection");
+		} catch (ClassNotFoundException e) {
+			fail("java.sql.Connection class not found!");
+			return;
+		} // end try
+
+		Field[] theFields = connectionClass.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 ConnectionTest
+

Added: incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/tests/api/java/sql/DataTruncationTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/tests/api/java/sql/DataTruncationTest.java?rev=386087&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/tests/api/java/sql/DataTruncationTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/tests/api/java/sql/DataTruncationTest.java Wed Mar 15 06:55:38 2006
@@ -0,0 +1,439 @@
+/* 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.DataTruncation;
+
+import junit.framework.TestCase;
+
+public class DataTruncationTest extends TestCase {
+
+	/*
+	 * ConstructorTest
+	 */
+	public void testDataTruncationintbooleanbooleanintint() {
+
+		int[] init1 = { -2147483648, 2147483647, 0, 329751502, 318587557,
+				-1217247045, 329474146 };
+		boolean[] init2 = { false, true, false, false, false, true, false };
+		boolean[] init3 = { false, true, false, false, false, false, true };
+		int[] init4 = { -2147483648, 2147483647, 0, 1761409290, -1331044048,
+				-576231606, 661635011 };
+		int[] init5 = { -2147483648, 2147483647, 0, 540816689, -1890783845,
+				-105552912, -85923935 };
+
+		String[] theFinalStates1 = { "01004", "01004", "01004", "01004",
+				"01004", "01004", "01004" };
+		String state2 = "Data truncation";
+		String[] theFinalStates2 = { state2, state2, state2, state2, state2,
+				state2, state2 };
+		int[] theFinalStates3 = { 0, 0, 0, 0, 0, 0, 0 };
+		int[] theFinalStates4 = init1;
+		int[] theFinalStates5 = init4;
+		int[] theFinalStates6 = init5;
+		boolean[] theFinalStates7 = init2;
+		boolean[] theFinalStates8 = init3;
+
+		Exception[] theExceptions = { null, null, null, null, null, null, null };
+
+		DataTruncation aDataTruncation;
+		int loopCount = init1.length;
+		for (int i = 0; i < loopCount; i++) {
+			try {
+				aDataTruncation = new DataTruncation(init1[i], init2[i],
+						init3[i], init4[i], init5[i]);
+				if (theExceptions[i] != null)
+					assertTrue(false);
+				assertEquals(i + "  Final state mismatch", aDataTruncation
+						.getSQLState(), theFinalStates1[i]);
+				assertEquals(i + "  Final state mismatch", aDataTruncation
+						.getMessage(), theFinalStates2[i]);
+				assertEquals(i + "  Final state mismatch", aDataTruncation
+						.getErrorCode(), theFinalStates3[i]);
+				assertEquals(i + "  Final state mismatch", aDataTruncation
+						.getIndex(), theFinalStates4[i]);
+				assertEquals(i + "  Final state mismatch", aDataTruncation
+						.getDataSize(), theFinalStates5[i]);
+				assertEquals(i + "  Final state mismatch", aDataTruncation
+						.getTransferSize(), theFinalStates6[i]);
+				assertEquals(i + "  Final state mismatch", aDataTruncation
+						.getParameter(), theFinalStates7[i]);
+				assertEquals(i + "  Final state mismatch", aDataTruncation
+						.getRead(), theFinalStates8[i]);
+
+			} catch (Exception e) {
+				if (theExceptions[i] == null)
+					fail(i + "Unexpected exception");
+				assertEquals(i + "Exception mismatch", e.getClass(),
+						theExceptions[i].getClass());
+				assertEquals(i + "Exception mismatch", e.getMessage(),
+						theExceptions[i].getMessage());
+			} // end try
+		} // end for
+
+	} // end method testDataTruncationintbooleanbooleanintint
+
+	/*
+	 * Method test for getIndex
+	 */
+	public void testGetIndex() {
+
+		DataTruncation aDataTruncation;
+		int[] init1 = { -2147483648, 2147483647, 0, -2045829673, 1977156911,
+				478985827, 1687271915 };
+		boolean[] init2 = { false, true, false, false, true, true, true };
+		boolean[] init3 = { false, true, false, false, true, true, true };
+		int[] init4 = { -2147483648, 2147483647, 0, -631377748, 21025030,
+				1215194589, 1064137121 };
+		int[] init5 = { -2147483648, 2147483647, 0, -897998505, 997578180,
+				735015866, 264619424 };
+
+		int theReturn;
+		int[] theReturns = init1;
+		String[] theFinalStates1 = { "01004", "01004", "01004", "01004",
+				"01004", "01004", "01004" };
+		String state2 = "Data truncation";
+		String[] theFinalStates2 = { state2, state2, state2, state2, state2,
+				state2, state2 };
+		int[] theFinalStates3 = { 0, 0, 0, 0, 0, 0, 0 };
+		int[] theFinalStates4 = init1;
+		int[] theFinalStates5 = init4;
+		int[] theFinalStates6 = init5;
+		boolean[] theFinalStates7 = init2;
+		boolean[] theFinalStates8 = init3;
+
+		Exception[] theExceptions = { null, null, null, null, null, null, null };
+
+		int loopCount = 1;
+		for (int i = 0; i < loopCount; i++) {
+			try {
+				aDataTruncation = new DataTruncation(init1[i], init2[i],
+						init3[i], init4[i], init5[i]);
+				theReturn = aDataTruncation.getIndex();
+				if (theExceptions[i] != null)
+					fail(i + "Exception missed");
+				assertEquals(i + "Return value mismatch", theReturn,
+						theReturns[i]);
+				assertEquals(i + "  Final state mismatch", aDataTruncation
+						.getSQLState(), theFinalStates1[i]);
+				assertEquals(i + "  Final state mismatch", aDataTruncation
+						.getMessage(), theFinalStates2[i]);
+				assertEquals(i + "  Final state mismatch", aDataTruncation
+						.getErrorCode(), theFinalStates3[i]);
+				assertEquals(i + "  Final state mismatch", aDataTruncation
+						.getIndex(), theFinalStates4[i]);
+				assertEquals(i + "  Final state mismatch", aDataTruncation
+						.getDataSize(), theFinalStates5[i]);
+				assertEquals(i + "  Final state mismatch", aDataTruncation
+						.getTransferSize(), theFinalStates6[i]);
+				assertEquals(i + "  Final state mismatch", aDataTruncation
+						.getParameter(), theFinalStates7[i]);
+				assertEquals(i + "  Final state mismatch", aDataTruncation
+						.getRead(), theFinalStates8[i]);
+
+			} catch (Exception e) {
+				if (theExceptions[i] == null)
+					fail(i + "Unexpected exception");
+				assertEquals(i + "Exception mismatch", e.getClass(),
+						theExceptions[i].getClass());
+				assertEquals(i + "Exception mismatch", e.getMessage(),
+						theExceptions[i].getMessage());
+			} // end try
+		} // end for
+
+	} // end method testGetIndex
+
+	/*
+	 * Method test for getParameter
+	 */
+	public void testGetParameter() {
+
+		DataTruncation aDataTruncation;
+		int[] init1 = { -2147483648, 2147483647, 0, -492314242, 1637665948,
+				-305785075, 258819883 };
+		boolean[] init2 = { false, true, false, true, true, false, true };
+		boolean[] init3 = { false, true, false, false, false, true, true };
+		int[] init4 = { -2147483648, 2147483647, 0, 1134512579, 533874007,
+				1709608139, 990656593 };
+		int[] init5 = { -2147483648, 2147483647, 0, -1566784226, -744009101,
+				-444614454, 356465980 };
+
+		boolean theReturn;
+		boolean[] theReturns = init2;
+		String[] theFinalStates1 = { "01004", "01004", "01004", "01004",
+				"01004", "01004", "01004" };
+		String state2 = "Data truncation";
+		String[] theFinalStates2 = { state2, state2, state2, state2, state2,
+				state2, state2 };
+		int[] theFinalStates3 = { 0, 0, 0, 0, 0, 0, 0 };
+		int[] theFinalStates4 = init1;
+		int[] theFinalStates5 = init4;
+		int[] theFinalStates6 = init5;
+		boolean[] theFinalStates7 = init2;
+		boolean[] theFinalStates8 = init3;
+
+		Exception[] theExceptions = { null, null, null, null, null, null, null };
+
+		int loopCount = 1;
+		for (int i = 0; i < loopCount; i++) {
+			try {
+				aDataTruncation = new DataTruncation(init1[i], init2[i],
+						init3[i], init4[i], init5[i]);
+				theReturn = aDataTruncation.getParameter();
+				if (theExceptions[i] != null)
+					fail(i + "Exception missed");
+				assertEquals(i + "Return value mismatch", theReturn,
+						theReturns[i]);
+				assertEquals(i + "  Final state mismatch", aDataTruncation
+						.getSQLState(), theFinalStates1[i]);
+				assertEquals(i + "  Final state mismatch", aDataTruncation
+						.getMessage(), theFinalStates2[i]);
+				assertEquals(i + "  Final state mismatch", aDataTruncation
+						.getErrorCode(), theFinalStates3[i]);
+				assertEquals(i + "  Final state mismatch", aDataTruncation
+						.getIndex(), theFinalStates4[i]);
+				assertEquals(i + "  Final state mismatch", aDataTruncation
+						.getDataSize(), theFinalStates5[i]);
+				assertEquals(i + "  Final state mismatch", aDataTruncation
+						.getTransferSize(), theFinalStates6[i]);
+				assertEquals(i + "  Final state mismatch", aDataTruncation
+						.getParameter(), theFinalStates7[i]);
+				assertEquals(i + "  Final state mismatch", aDataTruncation
+						.getRead(), theFinalStates8[i]);
+
+			} catch (Exception e) {
+				if (theExceptions[i] == null)
+					fail(i + "Unexpected exception");
+				assertEquals(i + "Exception mismatch", e.getClass(),
+						theExceptions[i].getClass());
+				assertEquals(i + "Exception mismatch", e.getMessage(),
+						theExceptions[i].getMessage());
+			} // end try
+		} // end for
+
+	} // end method testGetParameter
+
+	/*
+	 * Method test for getRead
+	 */
+	public void testGetRead() {
+
+		DataTruncation aDataTruncation;
+		int[] init1 = { -2147483648, 2147483647, 0, 2092420209, -1695764964,
+				1832837995, -80199594 };
+		boolean[] init2 = { false, true, false, false, false, true, true };
+		boolean[] init3 = { false, true, false, false, true, true, false };
+		int[] init4 = { -2147483648, 2147483647, 0, 1762375167, -604897453,
+				1362491587, 1007466498 };
+		int[] init5 = { -2147483648, 2147483647, 0, 1494407222, -1696982311,
+				-940493360, -1777579868 };
+
+		boolean theReturn;
+		boolean[] theReturns = init3;
+		String[] theFinalStates1 = { "01004", "01004", "01004", "01004",
+				"01004", "01004", "01004" };
+		String state2 = "Data truncation";
+		String[] theFinalStates2 = { state2, state2, state2, state2, state2,
+				state2, state2 };
+		int[] theFinalStates3 = { 0, 0, 0, 0, 0, 0, 0 };
+		int[] theFinalStates4 = init1;
+		int[] theFinalStates5 = init4;
+		int[] theFinalStates6 = init5;
+		boolean[] theFinalStates7 = init2;
+		boolean[] theFinalStates8 = init3;
+
+		Exception[] theExceptions = { null, null, null, null, null, null, null };
+
+		int loopCount = 1;
+		for (int i = 0; i < loopCount; i++) {
+			try {
+				aDataTruncation = new DataTruncation(init1[i], init2[i],
+						init3[i], init4[i], init5[i]);
+				theReturn = aDataTruncation.getRead();
+				if (theExceptions[i] != null)
+					fail(i + "Exception missed");
+				assertEquals(i + "Return value mismatch", theReturn,
+						theReturns[i]);
+				assertEquals(i + "  Final state mismatch", aDataTruncation
+						.getSQLState(), theFinalStates1[i]);
+				assertEquals(i + "  Final state mismatch", aDataTruncation
+						.getMessage(), theFinalStates2[i]);
+				assertEquals(i + "  Final state mismatch", aDataTruncation
+						.getErrorCode(), theFinalStates3[i]);
+				assertEquals(i + "  Final state mismatch", aDataTruncation
+						.getIndex(), theFinalStates4[i]);
+				assertEquals(i + "  Final state mismatch", aDataTruncation
+						.getDataSize(), theFinalStates5[i]);
+				assertEquals(i + "  Final state mismatch", aDataTruncation
+						.getTransferSize(), theFinalStates6[i]);
+				assertEquals(i + "  Final state mismatch", aDataTruncation
+						.getParameter(), theFinalStates7[i]);
+				assertEquals(i + "  Final state mismatch", aDataTruncation
+						.getRead(), theFinalStates8[i]);
+
+			} catch (Exception e) {
+				if (theExceptions[i] == null)
+					fail(i + "Unexpected exception");
+				assertEquals(i + "Exception mismatch", e.getClass(),
+						theExceptions[i].getClass());
+				assertEquals(i + "Exception mismatch", e.getMessage(),
+						theExceptions[i].getMessage());
+			} // end try
+		} // end for
+
+	} // end method testGetRead
+
+	/*
+	 * Method test for getDataSize
+	 */
+	public void testGetDataSize() {
+
+		DataTruncation aDataTruncation;
+		int[] init1 = { -2147483648, 2147483647, 0, 1146707040, -2020665632,
+				1268632617, -1595624039 };
+		boolean[] init2 = { false, true, false, true, false, true, true };
+		boolean[] init3 = { false, true, false, true, true, false, false };
+		int[] init4 = { -2147483648, 2147483647, 0, -367493363, 328996907,
+				-1581326731, 835022052 };
+		int[] init5 = { -2147483648, 2147483647, 0, -886134194, 908213800,
+				1123419516, -429606389 };
+
+		int theReturn;
+		int[] theReturns = init4;
+		String[] theFinalStates1 = { "01004", "01004", "01004", "01004",
+				"01004", "01004", "01004" };
+		String state2 = "Data truncation";
+		String[] theFinalStates2 = { state2, state2, state2, state2, state2,
+				state2, state2 };
+		int[] theFinalStates3 = { 0, 0, 0, 0, 0, 0, 0 };
+		int[] theFinalStates4 = init1;
+		int[] theFinalStates5 = init4;
+		int[] theFinalStates6 = init5;
+		boolean[] theFinalStates7 = init2;
+		boolean[] theFinalStates8 = init3;
+
+		Exception[] theExceptions = { null, null, null, null, null, null, null };
+
+		int loopCount = 1;
+		for (int i = 0; i < loopCount; i++) {
+			try {
+				aDataTruncation = new DataTruncation(init1[i], init2[i],
+						init3[i], init4[i], init5[i]);
+				theReturn = aDataTruncation.getDataSize();
+				if (theExceptions[i] != null)
+					fail(i + "Exception missed");
+				assertEquals(i + "Return value mismatch", theReturn,
+						theReturns[i]);
+				assertEquals(i + "  Final state mismatch", aDataTruncation
+						.getSQLState(), theFinalStates1[i]);
+				assertEquals(i + "  Final state mismatch", aDataTruncation
+						.getMessage(), theFinalStates2[i]);
+				assertEquals(i + "  Final state mismatch", aDataTruncation
+						.getErrorCode(), theFinalStates3[i]);
+				assertEquals(i + "  Final state mismatch", aDataTruncation
+						.getIndex(), theFinalStates4[i]);
+				assertEquals(i + "  Final state mismatch", aDataTruncation
+						.getDataSize(), theFinalStates5[i]);
+				assertEquals(i + "  Final state mismatch", aDataTruncation
+						.getTransferSize(), theFinalStates6[i]);
+				assertEquals(i + "  Final state mismatch", aDataTruncation
+						.getParameter(), theFinalStates7[i]);
+				assertEquals(i + "  Final state mismatch", aDataTruncation
+						.getRead(), theFinalStates8[i]);
+
+			} catch (Exception e) {
+				if (theExceptions[i] == null)
+					fail(i + "Unexpected exception");
+				assertEquals(i + "Exception mismatch", e.getClass(),
+						theExceptions[i].getClass());
+				assertEquals(i + "Exception mismatch", e.getMessage(),
+						theExceptions[i].getMessage());
+			} // end try
+		} // end for
+
+	} // end method testGetDataSize
+
+	/*
+	 * Method test for getTransferSize
+	 */
+	public void testGetTransferSize() {
+
+		DataTruncation aDataTruncation;
+		int[] init1 = { -2147483648, 2147483647, 0, 78096124, 1719192600,
+				-1661234694, -1205825753 };
+		boolean[] init2 = { false, true, false, false, true, false, true };
+		boolean[] init3 = { false, true, false, false, false, false, false };
+		int[] init4 = { -2147483648, 2147483647, 0, -493779295, -2042560243,
+				-217347438, 1357818664 };
+		int[] init5 = { -2147483648, 2147483647, 0, -1647009002, -717544563,
+				-1368171905, -918209633 };
+
+		int theReturn;
+		int[] theReturns = init5;
+		String[] theFinalStates1 = { "01004", "01004", "01004", "01004",
+				"01004", "01004", "01004" };
+		String state2 = "Data truncation";
+		String[] theFinalStates2 = { state2, state2, state2, state2, state2,
+				state2, state2 };
+		int[] theFinalStates3 = { 0, 0, 0, 0, 0, 0, 0 };
+		int[] theFinalStates4 = init1;
+		int[] theFinalStates5 = init4;
+		int[] theFinalStates6 = init5;
+		boolean[] theFinalStates7 = init2;
+		boolean[] theFinalStates8 = init3;
+
+		Exception[] theExceptions = { null, null, null, null, null, null, null };
+
+		int loopCount = 1;
+		for (int i = 0; i < loopCount; i++) {
+			try {
+				aDataTruncation = new DataTruncation(init1[i], init2[i],
+						init3[i], init4[i], init5[i]);
+				theReturn = aDataTruncation.getTransferSize();
+				if (theExceptions[i] != null)
+					fail(i + "Exception missed");
+				assertEquals(i + "Return value mismatch", theReturn,
+						theReturns[i]);
+				assertEquals(i + "  Final state mismatch", aDataTruncation
+						.getSQLState(), theFinalStates1[i]);
+				assertEquals(i + "  Final state mismatch", aDataTruncation
+						.getMessage(), theFinalStates2[i]);
+				assertEquals(i + "  Final state mismatch", aDataTruncation
+						.getErrorCode(), theFinalStates3[i]);
+				assertEquals(i + "  Final state mismatch", aDataTruncation
+						.getIndex(), theFinalStates4[i]);
+				assertEquals(i + "  Final state mismatch", aDataTruncation
+						.getDataSize(), theFinalStates5[i]);
+				assertEquals(i + "  Final state mismatch", aDataTruncation
+						.getTransferSize(), theFinalStates6[i]);
+				assertEquals(i + "  Final state mismatch", aDataTruncation
+						.getParameter(), theFinalStates7[i]);
+				assertEquals(i + "  Final state mismatch", aDataTruncation
+						.getRead(), theFinalStates8[i]);
+
+			} catch (Exception e) {
+				if (theExceptions[i] == null)
+					fail(i + "Unexpected exception");
+				assertEquals(i + "Exception mismatch", e.getClass(),
+						theExceptions[i].getClass());
+				assertEquals(i + "Exception mismatch", e.getMessage(),
+						theExceptions[i].getMessage());
+			} // end try
+		} // end for
+
+	} // end method testGetTransferSize
+
+} // end class DataTruncationTest

Added: incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/tests/api/java/sql/DatabaseMetaDataTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/tests/api/java/sql/DatabaseMetaDataTest.java?rev=386087&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/tests/api/java/sql/DatabaseMetaDataTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/tests/api/java/sql/DatabaseMetaDataTest.java Wed Mar 15 06:55:38 2006
@@ -0,0 +1,191 @@
+/* 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 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));
+
+		/*
+		 * System.out.println( "sqlStateSQL99: " +
+		 * DatabaseMetaData.sqlStateSQL99 ); System.out.println( "sqlStateXOpen: " +
+		 * DatabaseMetaData.sqlStateXOpen ); System.out.println(
+		 * "attributeNullableUnknown: " +
+		 * DatabaseMetaData.attributeNullableUnknown ); System.out.println(
+		 * "attributeNullable: " + DatabaseMetaData.attributeNullable );
+		 * System.out.println( "attributeNoNulls: " +
+		 * DatabaseMetaData.attributeNoNulls ); System.out.println(
+		 * "tableIndexOther: " + DatabaseMetaData.tableIndexOther );
+		 * System.out.println( "tableIndexHashed: " +
+		 * DatabaseMetaData.tableIndexHashed ); System.out.println(
+		 * "tableIndexClustered: " + DatabaseMetaData.tableIndexClustered );
+		 * System.out.println( "tableIndexStatistic: " +
+		 * DatabaseMetaData.tableIndexStatistic ); System.out.println(
+		 * "typeSearchable: " + DatabaseMetaData.typeSearchable );
+		 * System.out.println( "typePredBasic: " +
+		 * DatabaseMetaData.typePredBasic ); System.out.println( "typePredChar: " +
+		 * DatabaseMetaData.typePredChar ); System.out.println( "typePredNone: " +
+		 * DatabaseMetaData.typePredNone ); System.out.println(
+		 * "typeNullableUnknown: " + DatabaseMetaData.typeNullableUnknown );
+		 * System.out.println( "typeNullable: " + DatabaseMetaData.typeNullable );
+		 * System.out.println( "typeNoNulls: " + DatabaseMetaData.typeNoNulls );
+		 * System.out.println( "importedKeyNotDeferrable: " +
+		 * DatabaseMetaData.importedKeyNotDeferrable ); System.out.println(
+		 * "importedKeyInitiallyImmediate: " +
+		 * DatabaseMetaData.importedKeyInitiallyImmediate ); System.out.println(
+		 * "importedKeyInitiallyDeferred: " +
+		 * DatabaseMetaData.importedKeyInitiallyDeferred ); System.out.println(
+		 * "importedKeySetDefault: " + DatabaseMetaData.importedKeySetDefault );
+		 * System.out.println( "importedKeyNoAction: " +
+		 * DatabaseMetaData.importedKeyNoAction ); System.out.println(
+		 * "importedKeySetNull: " + DatabaseMetaData.importedKeySetNull );
+		 * System.out.println( "importedKeyRestrict: " +
+		 * DatabaseMetaData.importedKeyRestrict ); System.out.println(
+		 * "importedKeyCascade: " + DatabaseMetaData.importedKeyCascade );
+		 * System.out.println( "versionColumnPseudo: " +
+		 * DatabaseMetaData.versionColumnPseudo ); System.out.println(
+		 * "versionColumnNotPseudo: " + DatabaseMetaData.versionColumnNotPseudo );
+		 * System.out.println( "versionColumnUnknown: " +
+		 * DatabaseMetaData.versionColumnUnknown ); System.out.println(
+		 * "bestRowPseudo: " + DatabaseMetaData.bestRowPseudo );
+		 * System.out.println( "bestRowNotPseudo: " +
+		 * DatabaseMetaData.bestRowNotPseudo ); System.out.println(
+		 * "bestRowUnknown: " + DatabaseMetaData.bestRowUnknown );
+		 * System.out.println( "bestRowSession: " +
+		 * DatabaseMetaData.bestRowSession ); System.out.println(
+		 * "bestRowTransaction: " + DatabaseMetaData.bestRowTransaction );
+		 * System.out.println( "bestRowTemporary: " +
+		 * DatabaseMetaData.bestRowTemporary ); System.out.println(
+		 * "columnNullableUnknown: " + DatabaseMetaData.columnNullableUnknown );
+		 * System.out.println( "columnNullable: " +
+		 * DatabaseMetaData.columnNullable ); System.out.println(
+		 * "columnNoNulls: " + DatabaseMetaData.columnNoNulls );
+		 * System.out.println( "procedureNullableUnknown: " +
+		 * DatabaseMetaData.procedureNullableUnknown ); System.out.println(
+		 * "procedureNullable: " + DatabaseMetaData.procedureNullable );
+		 * System.out.println( "procedureNoNulls: " +
+		 * DatabaseMetaData.procedureNoNulls ); System.out.println(
+		 * "procedureColumnResult: " + DatabaseMetaData.procedureColumnResult );
+		 * System.out.println( "procedureColumnReturn: " +
+		 * DatabaseMetaData.procedureColumnReturn ); System.out.println(
+		 * "procedureColumnOut: " + DatabaseMetaData.procedureColumnOut );
+		 * System.out.println( "procedureColumnInOut: " +
+		 * DatabaseMetaData.procedureColumnInOut ); System.out.println(
+		 * "procedureColumnIn: " + DatabaseMetaData.procedureColumnIn );
+		 * System.out.println( "procedureColumnUnknown: " +
+		 * DatabaseMetaData.procedureColumnUnknown ); System.out.println(
+		 * "procedureReturnsResult: " + DatabaseMetaData.procedureReturnsResult );
+		 * System.out.println( "procedureNoResult: " +
+		 * DatabaseMetaData.procedureNoResult ); System.out.println(
+		 * "procedureResultUnknown: " + DatabaseMetaData.procedureResultUnknown );
+		 */
+
+		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

Added: incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/tests/api/java/sql/DateTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/tests/api/java/sql/DateTest.java?rev=386087&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/tests/api/java/sql/DateTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/tests/api/java/sql/DateTest.java Wed Mar 15 06:55:38 2006
@@ -0,0 +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 tests.api.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]);
+
+				assertTrue(theDate != null);
+				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]);
+
+				assertTrue(theDate != null);
+				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
+			assertTrue(theHours == 23);
+			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
+			assertTrue(theMinutes == 59);
+			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
+			assertTrue(theSeconds == 23);
+			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
+
+



Mime
View raw message