org.apache.derbyTesting.functionTests.tests.jdbcapi
Class ClosedObjectTest

java.lang.Object
  extended by junit.framework.Assert
      extended by junit.framework.TestCase
          extended by org.apache.derbyTesting.junit.BaseTestCase
              extended by org.apache.derbyTesting.junit.BaseJDBCTestCase
                  extended by org.apache.derbyTesting.functionTests.tests.jdbcapi.ClosedObjectTest
All Implemented Interfaces:
junit.framework.Test

public class ClosedObjectTest
extends BaseJDBCTestCase

Test that all methods on ResultSet, Statement, PreparedStatement, CallableStatement and Connection objects throw the appropriate exceptions when the objects are closed.


Nested Class Summary
private static class ClosedObjectTest.CallableStatementObjectDecorator
          Decorator class for testing methods on a closed callable statement.
private static class ClosedObjectTest.ConnectionObjectDecorator
          Decorator class for testing methods on a closed connection.
private static class ClosedObjectTest.DataSourceDecorator
          Decorator class used for obtaining connections through a DataSource.
private static class ClosedObjectTest.ObjectDecorator
          Abstract decorator class with functionality for obtaining a closed object.
private static class ClosedObjectTest.PoolDataSourceDecorator
          Decorator class used for obtaining connections through a ConnectionPoolDataSource.
private static class ClosedObjectTest.PreparedStatementObjectDecorator
          Decorator class for testing methods on a closed prepared statement.
private static class ClosedObjectTest.ResultSetObjectDecorator
          Decorator class for testing methods on a closed result set.
private static class ClosedObjectTest.StatementObjectDecorator
          Decorator class for testing methods on a closed statement.
private static class ClosedObjectTest.XADataSourceDecorator
          Decorator class used for obtaining connections through an XADataSource.
 
Field Summary
private  ClosedObjectTest.ObjectDecorator decorator_
          Test decorator which provides a closed object to invoke a method on.
private  java.lang.reflect.Method method_
          The method to test.
private  java.lang.String name_
          Name of the test.
 
Fields inherited from class org.apache.derbyTesting.junit.BaseTestCase
DEFAULT_DB_DIR, DERBY_LOG, ERRORSTACKTRACEFILE
 
Constructor Summary
ClosedObjectTest(java.lang.reflect.Method method, ClosedObjectTest.ObjectDecorator decorator)
          Creates a new ClosedObjectTest instance.
 
Method Summary
private static junit.framework.Test baseSuite(java.lang.String name)
          Creates the test suite and fills it with tests using DataSource, ConnectionPoolDataSource and XADataSource to obtain objects.
private static void fillDataSourceSuite(junit.framework.TestSuite suite, ClosedObjectTest.DataSourceDecorator dsDecorator)
          Fills a test suite which is contained in a DataSourceDecorator with tests for ResultSet, Statement, PreparedStatement, CallableStatement and Connection.
private static void fillObjectSuite(junit.framework.TestSuite suite, ClosedObjectTest.ObjectDecorator decorator, java.lang.Class iface)
          Fills a suite with tests for all the methods of an interface.
 java.lang.String getName()
          Gets the name of the test.
private static java.lang.Object[] getNullArguments(java.lang.Class[] params)
          Takes an array of classes and returns an array of objects with null values compatible with the classes.
private static java.lang.Object getNullValueForType(java.lang.Class type)
          Returns a null value compatible with the class.
static junit.framework.Test suite()
          Creates a suite with all tests in the class.
 void testClosedObjects()
          Runs a test case.
 
Methods inherited from class org.apache.derbyTesting.junit.BaseJDBCTestCase
assertCallError, assertCheckTable, assertCompileError, assertEquals, assertEquals, assertEquals, assertEquivalentDataType, assertGetIntError, assertNextError, assertPreparedStatementError, assertSQLExceptionEquals, assertSQLState, assertSQLState, assertStatementError, assertStatementError, assertStatementError, assertStatementError, assertTableRowCount, assertUpdateCount, assertUpdateCount, checkAllConsistency, checkEstimatedRowCount, commit, createStatement, createStatement, createStatement, dropTable, dropTable, getConnection, getDatabaseProperty, getLastSQLException, initializeConnection, openConnection, openDefaultConnection, openDefaultConnection, openUserConnection, prepareCall, prepareCall, prepareCall, prepareStatement, prepareStatement, prepareStatement, prepareStatement, prepareStatement, prepareStatement, rollback, runScript, runScript, runSQLCommands, setAutoCommit, tearDown, usingDB2Client, usingDerbyNetClient, usingEmbedded
 
Methods inherited from class org.apache.derbyTesting.junit.BaseTestCase
alarm, assertEquals, assertEquals, assertEquals, assertExecJavaCmdAsExpected, assertSecurityManager, assertThrowableEquals, execJavaCmd, fail, getFailureFolder, getJavaExecutableName, getSystemProperty, getTestConfiguration, getTestResource, openTestResource, println, printStackTrace, readProcessOutput, removeDirectory, removeDirectory, removeSystemProperty, runBare, setSystemProperty, traceit
 
Methods inherited from class junit.framework.TestCase
countTestCases, createResult, run, run, runTest, setName, setUp, toString
 
Methods inherited from class junit.framework.Assert
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, fail, fail
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

method_

private final java.lang.reflect.Method method_
The method to test.


decorator_

private final ClosedObjectTest.ObjectDecorator decorator_
Test decorator which provides a closed object to invoke a method on.


name_

private java.lang.String name_
Name of the test.

Constructor Detail

ClosedObjectTest

public ClosedObjectTest(java.lang.reflect.Method method,
                        ClosedObjectTest.ObjectDecorator decorator)
Creates a new ClosedObjectTest instance.

Parameters:
method - the method to test
decorator - a decorator which provides a closed object
Method Detail

getName

public java.lang.String getName()
Gets the name of the test.

Overrides:
getName in class junit.framework.TestCase
Returns:
name of the test

testClosedObjects

public void testClosedObjects()
                       throws java.lang.Throwable
Runs a test case. A method is called on a closed object, and it is checked that the appropriate exception is thrown.

Throws:
java.lang.Throwable - if an error occurs

suite

public static junit.framework.Test suite()
Creates a suite with all tests in the class.


baseSuite

private static junit.framework.Test baseSuite(java.lang.String name)
Creates the test suite and fills it with tests using DataSource, ConnectionPoolDataSource and XADataSource to obtain objects.

Returns:
a Test value
Throws:
java.lang.Exception - if an error occurs while building the test suite

fillDataSourceSuite

private static void fillDataSourceSuite(junit.framework.TestSuite suite,
                                        ClosedObjectTest.DataSourceDecorator dsDecorator)
Fills a test suite which is contained in a DataSourceDecorator with tests for ResultSet, Statement, PreparedStatement, CallableStatement and Connection.

Parameters:
suite - the test suite to fill
dsDecorator - the decorator for the test suite

fillObjectSuite

private static void fillObjectSuite(junit.framework.TestSuite suite,
                                    ClosedObjectTest.ObjectDecorator decorator,
                                    java.lang.Class iface)
Fills a suite with tests for all the methods of an interface.

Parameters:
suite - the suite to fill
decorator - a decorator for the test (used for obtaining a closed object to test the method on)
iface - the interface which contains the methods to test

getNullArguments

private static java.lang.Object[] getNullArguments(java.lang.Class[] params)
Takes an array of classes and returns an array of objects with null values compatible with the classes. Helper method for converting a parameter list to an argument list.

Parameters:
params - a Class[] value
Returns:
an Object[] value

getNullValueForType

private static java.lang.Object getNullValueForType(java.lang.Class type)
Returns a null value compatible with the class. For instance, return Boolean.FALSE for primitive booleans, 0 for primitive integers and null for non-primitive types.

Parameters:
type - a Class value
Returns:
a null value

Built on Thu 2009-11-26 18:42:53-0800, from revision 884739

Apache Derby V10.6 Internals - Copyright © 2004,2008 The Apache Software Foundation. All Rights Reserved.