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

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.DataSourceReferenceTest
All Implemented Interfaces:
junit.framework.Test

public class DataSourceReferenceTest
extends BaseJDBCTestCase

Test obtaining a javax.naming.Reference from a Derby data source and recreating a Derby data source from it.

Tests that the recreated value has the same value for all the properties the data source supports. The list of properties is obtained dynamically from the getter methods that return int, String, boolean, short and long. Should Derby data sources support any other bean property types then this test should be modified to pick them up and handle them. The test will fail when such a property is added.

Default values of the properties are also tested. Default and set values of the properties must be specified by creating a data source descriptor.

At no point does this test attempt to connect using these data sources.


Nested Class Summary
private static class DataSourceReferenceTest.DataSourceDescriptor
          A class describing the bean properties of a data source.
 
Field Summary
private static DataSourceReferenceTest.DataSourceDescriptor BASE_CLIENT_DS
          Descriptor for the basic client data source.
private static int BASE_DS
          Lookup constant for the descriptor array.
private static DataSourceReferenceTest.DataSourceDescriptor BASE_EMBEDDED_DS
          Descriptor for the basic embedded data source.
private static DataSourceReferenceTest.DataSourceDescriptor POOL_CLIENT_DS
          Descriptor for the client connection pool data source.
private static int POOL_DS
          Lookup constant for the descriptor array.
private static int XA_DS
          Lookup constant for the descriptor array.
 
Fields inherited from class org.apache.derbyTesting.junit.BaseTestCase
DEFAULT_DB_DIR, DERBY_LOG, ERRORSTACKTRACEFILE
 
Constructor Summary
DataSourceReferenceTest(java.lang.String name)
          Creates a new fixture.
 
Method Summary
private  void assertDataSourceProperties(DataSourceReferenceTest.DataSourceDescriptor dsDesc, java.lang.String[] properties)
          Asserts that the properties that are in the data source descriptor are found in the list of data source properties, and that the data source does not contain properties that are not in the descriptor.
private  void assertDataSourceReference(DataSourceReferenceTest.DataSourceDescriptor dsDesc, java.lang.String className)
          Performs the test sequence in the data source.
private  void assertDataSourceReferenceEmpty(DataSourceReferenceTest.DataSourceDescriptor dsDesc, java.lang.String className)
          Make sure it is possible to create a new data source using Referencable, that the new instance has the correct default values set for the bean properties and finally that the data source can be serialized/deserialized.
private  void assertDataSourceReferencePopulated(DataSourceReferenceTest.DataSourceDescriptor dsDesc, java.lang.String className)
          Make sure it is possible to recreate and serialize/deserialize a populated data source.
private  void compareDataSources(DataSourceReferenceTest.DataSourceDescriptor dsDesc, java.lang.Object ds, java.lang.Object rds, boolean useDefaultsForComparison)
          Compares two data sources expected to be equal.
private static java.lang.reflect.Method getGet(java.lang.String property, java.lang.Object ds)
          Obtains the specified get method.
private static java.lang.String[] getPropertyBeanList(java.lang.Object ds)
          Obtains a list of bean properties through reflection.
private static java.lang.reflect.Method getSet(java.lang.reflect.Method getMethod, java.lang.Object ds)
          Obtains the specified set method.
static junit.framework.Test suite()
          Creates a suite with tests for both embedded and client data sources.
 void testDataSourceReference()
          Tests a data source, with focus on serialization/deserialization.
 
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, getName, 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

BASE_DS

private static final int BASE_DS
Lookup constant for the descriptor array.

See Also:
Constant Field Values

POOL_DS

private static final int POOL_DS
Lookup constant for the descriptor array.

See Also:
Constant Field Values

XA_DS

private static final int XA_DS
Lookup constant for the descriptor array.

See Also:
Constant Field Values

BASE_EMBEDDED_DS

private static final DataSourceReferenceTest.DataSourceDescriptor BASE_EMBEDDED_DS
Descriptor for the basic embedded data source.


BASE_CLIENT_DS

private static final DataSourceReferenceTest.DataSourceDescriptor BASE_CLIENT_DS
Descriptor for the basic client data source.


POOL_CLIENT_DS

private static final DataSourceReferenceTest.DataSourceDescriptor POOL_CLIENT_DS
Descriptor for the client connection pool data source.

Constructor Detail

DataSourceReferenceTest

public DataSourceReferenceTest(java.lang.String name)
Creates a new fixture.

Parameters:
name - fixture name
Method Detail

suite

public static junit.framework.Test suite()
Creates a suite with tests for both embedded and client data sources.

Returns:
A suite with the appropriate tests.

testDataSourceReference

public void testDataSourceReference()
                             throws java.lang.Exception
Tests a data source, with focus on serialization/deserialization.

For each data source, the following actions are performed:

  1. Create an empty data source from the class name.
  2. Discover and validate the bean property list.
  3. Create a reference and recreate the data source.
  4. Compare the original and the empty recreated data source.
  5. Serialize the data source and recreate.
  6. Compare the original and the deserialized data source.
  7. Set a value for every property of the data source.
  8. Create a reference and recreate the data source.
  9. Compare the populated original and the recreated data source.
  10. Serialize the populated data source and recreate.
  11. Compare the populated original and the deserialized data source.

Throws:
java.lang.Exception - on a wide variety of error conditions...

assertDataSourceReference

private void assertDataSourceReference(DataSourceReferenceTest.DataSourceDescriptor dsDesc,
                                       java.lang.String className)
                                throws java.lang.Exception
Performs the test sequence in the data source.

Parameters:
dsDesc - data source descriptor
className - class name of the data source
Throws:
java.lang.Exception - on a wide variety of error conditions...
See Also:
testDataSourceReference()

assertDataSourceProperties

private void assertDataSourceProperties(DataSourceReferenceTest.DataSourceDescriptor dsDesc,
                                        java.lang.String[] properties)
Asserts that the properties that are in the data source descriptor are found in the list of data source properties, and that the data source does not contain properties that are not in the descriptor.

No property values are verified in this assert method.

Parameters:
dsDesc - data source descriptor
properties - list of actual data source properties

assertDataSourceReferenceEmpty

private void assertDataSourceReferenceEmpty(DataSourceReferenceTest.DataSourceDescriptor dsDesc,
                                            java.lang.String className)
                                     throws java.lang.Exception
Make sure it is possible to create a new data source using Referencable, that the new instance has the correct default values set for the bean properties and finally that the data source can be serialized/deserialized.

Parameters:
dsDesc - data source descriptor
className - data source class name
Throws:
java.lang.Exception - on a wide variety of error conditions...

assertDataSourceReferencePopulated

private void assertDataSourceReferencePopulated(DataSourceReferenceTest.DataSourceDescriptor dsDesc,
                                                java.lang.String className)
                                         throws java.lang.Exception
Make sure it is possible to recreate and serialize/deserialize a populated data source.

Populated means the various bean properties have non-default values set.

Parameters:
dsDesc - data source descriptor
className - data source class name
Throws:
java.lang.Exception - on a wide variety of error conditions...

compareDataSources

private void compareDataSources(DataSourceReferenceTest.DataSourceDescriptor dsDesc,
                                java.lang.Object ds,
                                java.lang.Object rds,
                                boolean useDefaultsForComparison)
                         throws java.lang.Exception
Compares two data sources expected to be equal.

The data source descriptor is expected to contain both default values and set values for the relevant bean properties of the data source(s).

Parameters:
dsDesc - data source descriptor
ds - original data source
rds - recreated data source
useDefaultsForComparison - true if the default values should be verified, false if the set values should be used for verification
Throws:
java.lang.Exception - on a wide variety of error conditions...
AssertionFailedError - if the data sources are not equal

getPropertyBeanList

private static java.lang.String[] getPropertyBeanList(java.lang.Object ds)
Obtains a list of bean properties through reflection.

Parameters:
ds - the data source to investigate
Returns:
A list of bean property names.

getGet

private static java.lang.reflect.Method getGet(java.lang.String property,
                                               java.lang.Object ds)
                                        throws java.lang.NoSuchMethodException
Obtains the specified get method.

Parameters:
property - property/method name
ds - data source object
Returns:
A method object.
Throws:
java.lang.NoSuchMethodException - if the method does not exist

getSet

private static java.lang.reflect.Method getSet(java.lang.reflect.Method getMethod,
                                               java.lang.Object ds)
                                        throws java.lang.NoSuchMethodException
Obtains the specified set method.

Parameters:
getMethod - the corresponding get method
ds - data source object
Returns:
A method object.
Throws:
java.lang.NoSuchMethodException - if the method does not exist

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.