public class DataSourceReferenceTest extends BaseJDBCTestCase
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.
Modifier and Type | Class and Description |
---|---|
private static class |
DataSourceReferenceTest.DataSourceDescriptor
A class describing the bean properties of a data source.
|
Modifier and Type | Field and Description |
---|---|
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.
|
DEFAULT_DB_DIR, DERBY_LOG, ERRORSTACKTRACEFILE
Constructor and Description |
---|
DataSourceReferenceTest(java.lang.String name)
Creates a new fixture.
|
Modifier and Type | Method and Description |
---|---|
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.
|
assertCallError, assertCheckTable, assertCommitError, assertCompileError, assertEquals, assertEquals, assertEquals, assertEquivalentDataType, assertErrorCode, assertGetIntError, assertNextError, assertPreparedStatementError, assertResults, assertResults, assertSQLExceptionEquals, assertSQLState, assertSQLState, assertStatementError, assertStatementError, assertStatementError, assertStatementError, assertStatementErrorUnordered, assertTableRowCount, assertUpdateCount, assertUpdateCount, assertWarning, chattyPrepare, chattyPrepareCall, checkAllConsistency, checkEstimatedRowCount, closeStatement, commit, createStatement, createStatement, createStatement, dropTable, dropTable, dropView, dropView, dumpRs, dumpRs, emptyStatementCache, executeQuery, expectCompilationError, expectCompilationError, expectExecutionError, getClientTransactionID, getConnection, getDatabaseProperty, getLastSQLException, goodStatement, goodUpdate, initializeConnection, openConnection, openDefaultConnection, openDefaultConnection, openDefaultConnection, openUserConnection, prepareCall, prepareCall, prepareCall, prepareStatement, prepareStatement, prepareStatement, prepareStatement, prepareStatement, prepareStatement, rollback, runBare, runBareOverridable, runScript, runScript, runSQLCommands, setAutoCommit, tearDown, usingDB2Client, usingDerbyNetClient, usingEmbedded
alarm, assertDirectoryDeleted, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertExecJavaCmdAsExpected, assertLaunchedJUnitTestMethod, assertLaunchedJUnitTestMethod, assertSameNullness, assertSecurityManager, assertThrowableEquals, currentDirectory, execJavaCmd, execJavaCmd, execJavaCmd, fail, getClassVersionMajor, getEmmaJar, getFailureFolder, getFilesWith, getJavaExecutableName, getSystemProperty, getTestConfiguration, getTestResource, hasInterruptibleIO, isCVM, isIBMJVM, isJ9Platform, isJava5, isJava7, isPhoneME, isPlatform, isSunJVM, isWindowsPlatform, newAssertionFailedError, openTestResource, println, printStackTrace, readProcessOutput, removeDirectory, removeDirectory, removeFiles, removeSystemProperty, runsWithEmma, runsWithJaCoCo, setSystemErr, setSystemOut, setSystemProperty, sleep, sleepAtLeastOneTick, traceit, vmAtLeast
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, countTestCases, createResult, fail, fail, failNotEquals, failNotSame, failSame, format, getName, run, run, runTest, setName, setUp, toString
private static final int BASE_DS
private static final int POOL_DS
private static final int XA_DS
private static final DataSourceReferenceTest.DataSourceDescriptor BASE_EMBEDDED_DS
private static final DataSourceReferenceTest.DataSourceDescriptor BASE_CLIENT_DS
private static final DataSourceReferenceTest.DataSourceDescriptor POOL_CLIENT_DS
public DataSourceReferenceTest(java.lang.String name)
name
- fixture namepublic static junit.framework.Test suite()
public void testDataSourceReference() throws java.lang.Exception
For each data source, the following actions are performed:
java.lang.Exception
- on a wide variety of error conditions...private void assertDataSourceReference(DataSourceReferenceTest.DataSourceDescriptor dsDesc, java.lang.String className) throws java.lang.Exception
dsDesc
- data source descriptorclassName
- class name of the data sourcejava.lang.Exception
- on a wide variety of error conditions...testDataSourceReference()
private void assertDataSourceProperties(DataSourceReferenceTest.DataSourceDescriptor dsDesc, java.lang.String[] properties)
No property values are verified in this assert method.
dsDesc
- data source descriptorproperties
- list of actual data source propertiesprivate void assertDataSourceReferenceEmpty(DataSourceReferenceTest.DataSourceDescriptor dsDesc, java.lang.String className) throws java.lang.Exception
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.dsDesc
- data source descriptorclassName
- data source class namejava.lang.Exception
- on a wide variety of error conditions...private void assertDataSourceReferencePopulated(DataSourceReferenceTest.DataSourceDescriptor dsDesc, java.lang.String className) throws java.lang.Exception
Populated means the various bean properties have non-default values set.
dsDesc
- data source descriptorclassName
- data source class namejava.lang.Exception
- on a wide variety of error conditions...private void compareDataSources(DataSourceReferenceTest.DataSourceDescriptor dsDesc, java.lang.Object ds, java.lang.Object rds, boolean useDefaultsForComparison) throws java.lang.Exception
The data source descriptor is expected to contain both default values and set values for the relevant bean properties of the data source(s).
dsDesc
- data source descriptords
- original data sourcerds
- recreated data sourceuseDefaultsForComparison
- true
if the default values
should be verified, false
if the set values should be
used for verificationjava.lang.Exception
- on a wide variety of error conditions...AssertionFailedError
- if the data sources are not equalprivate static java.lang.String[] getPropertyBeanList(java.lang.Object ds)
ds
- the data source to investigateprivate static java.lang.reflect.Method getGet(java.lang.String property, java.lang.Object ds) throws java.lang.NoSuchMethodException
property
- property/method nameds
- data source objectjava.lang.NoSuchMethodException
- if the method does not existprivate static java.lang.reflect.Method getSet(java.lang.reflect.Method getMethod, java.lang.Object ds) throws java.lang.NoSuchMethodException
getMethod
- the corresponding get methodds
- data source objectjava.lang.NoSuchMethodException
- if the method does not existApache Derby V10.13 Internals - Copyright © 2004,2016 The Apache Software Foundation. All Rights Reserved.