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

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

public class DataSourceTest
extends BaseJDBCTestCase

Test the various DataSource implementations of Derby, but not ConnectionPoolDataSource or XADataSource; those are tested in J2EEDataSourceTest. Performs SecurityCheck analysis on the JDBC objects returned. This is because this test returns to the client a number of different implementations of Connection, Statement etc.

See Also:
SecurityCheck

Field Summary
protected static java.util.Hashtable conns
          A hashtable of opened connections.
private static java.lang.String CONNSTRING_FORMAT
          The expected format of a connection string.
private static java.lang.String dbName
           
private  java.lang.Object nogc
          Hang onto the SecurityCheck class while running the tests so that it is not garbage collected during the test and lose the information it has collected, in case it should get printed out.
 
Fields inherited from class org.apache.derbyTesting.junit.BaseTestCase
DEFAULT_DB_DIR, DERBY_LOG, ERRORSTACKTRACEFILE
 
Constructor Summary
DataSourceTest(java.lang.String name)
           
 
Method Summary
private  void assertConnectionOK(java.lang.Object[] expectedValues, java.lang.String dsName, java.sql.Connection conn)
           
private  void assertConnectionPreClose(java.lang.String dsName, java.sql.Connection conn)
           
private static void assertMessageText(java.sql.Connection conn, java.lang.String retrieveMessageTextValue)
           
private  void assertStatementOK(java.lang.String dsName, java.sql.Connection conn, java.sql.Statement s)
           
private static void assertStringFormat(java.sql.Connection conn)
          Check the format of the connection string.
private static java.lang.String assertStringPrefix(java.lang.Object conn)
          Make sure the connection string starts with the right prefix, which is the classname@hashcode.
private  void assertTenConnectionsUnique()
          Get connections using getConnection() and make sure they're unique
private static void assertToString(java.sql.Connection conn)
          Make sure this connection's string is unique (DERBY-243)
private static void assertToString(javax.sql.DataSource ds)
          Check uniqueness of connection strings coming from a DataSouce
private static void assertTraceFilesExist()
          Check that trace file exists in directory
private static junit.framework.Test baseSuite(java.lang.String postfix)
          Return a suite of tests that are run with both client and embedded
private static void clearConnections()
          Clear out and close connections in the connections hashtable.
private static void dsConnectionRequest(java.lang.String expectedValue, javax.sql.DataSource ds, java.lang.String user, java.lang.String ConnAttr)
           
private static void dsConnectionRequests(java.lang.String[] expectedValues, javax.sql.DataSource ds)
           
private static void dsGetBadConnection(javax.sql.DataSource ds)
           
private static junit.framework.Test getClientSuite()
          Return a suite of tests that are run with client only
private static junit.framework.Test getEmbeddedSuite(java.lang.String postfix)
          Return a suite of tests that are run with embedded only
private static void setDatabaseProperty(java.lang.String property, java.lang.String value)
           
private  void subTestDataSourceDescription(javax.sql.DataSource ds)
          Utility method for testing setting and fetching the description property on a data source.
static junit.framework.Test suite()
           
 void tearDown()
          Tear down this fixture, sub-classes should call super.tearDown().
 void testAllDataSources()
           
 void testBadConnectionAttributeSyntax()
           
 void testClientDSConnectionAttributes()
          Check that database name set using setConnectionAttributes is not used by ClientDataSource.
 void testClientMessageTextConnectionAttribute()
          Check that messageText connection attribute functions correctly.
 void testClientTraceFileDSConnectionAttribute()
          Check that traceFile connection attribute functions correctly.
 void testDescriptionProperty()
          Check that messageText connection attribute functions correctly.
 void testDSRequestAuthentication()
           
 void testJira95ds()
           
 
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, 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

dbName

private static final java.lang.String dbName

conns

protected static java.util.Hashtable conns
A hashtable of opened connections. This is used when checking to make sure connection strings are unique; we need to make sure all the connections are closed when we are done, so they are stored in this hashtable


CONNSTRING_FORMAT

private static final java.lang.String CONNSTRING_FORMAT
The expected format of a connection string. In English: "@ (XID=), (SESSION = ), (DATABASE=), (DRDAID = )"

See Also:
Constant Field Values

nogc

private final java.lang.Object nogc
Hang onto the SecurityCheck class while running the tests so that it is not garbage collected during the test and lose the information it has collected, in case it should get printed out.

Constructor Detail

DataSourceTest

public DataSourceTest(java.lang.String name)
Method Detail

baseSuite

private static junit.framework.Test baseSuite(java.lang.String postfix)
Return a suite of tests that are run with both client and embedded

Parameters:
postfix - suite name postfix
Returns:
A suite of tests to be run with client and/or embedded

getClientSuite

private static junit.framework.Test getClientSuite()
Return a suite of tests that are run with client only

Returns:
A suite of tests being run with client only

getEmbeddedSuite

private static junit.framework.Test getEmbeddedSuite(java.lang.String postfix)
Return a suite of tests that are run with embedded only

Parameters:
postfix - suite name postfix
Returns:
A suite of tests being run with embedded only

suite

public static junit.framework.Test suite()

tearDown

public void tearDown()
              throws java.lang.Exception
Description copied from class: BaseJDBCTestCase
Tear down this fixture, sub-classes should call super.tearDown(). This cleanups & closes the connection if it is open and any statement objects returned through the utility methods.

Overrides:
tearDown in class BaseJDBCTestCase
Throws:
java.lang.Exception

testAllDataSources

public void testAllDataSources()
                        throws java.sql.SQLException,
                               java.lang.Exception
Throws:
java.sql.SQLException
java.lang.Exception

testJira95ds

public void testJira95ds()
                  throws java.sql.SQLException
Throws:
java.sql.SQLException

testBadConnectionAttributeSyntax

public void testBadConnectionAttributeSyntax()
                                      throws java.sql.SQLException
Throws:
java.sql.SQLException

testClientDSConnectionAttributes

public void testClientDSConnectionAttributes()
                                      throws java.sql.SQLException
Check that database name set using setConnectionAttributes is not used by ClientDataSource. This method tests DERBY-1130. this fixture has a counterpart for Pooled and XA DataSources in J2EEDataSourceTest

Throws:
java.sql.SQLException

testDSRequestAuthentication

public void testDSRequestAuthentication()
                                 throws java.sql.SQLException
Throws:
java.sql.SQLException

testClientTraceFileDSConnectionAttribute

public void testClientTraceFileDSConnectionAttribute()
                                              throws java.sql.SQLException
Check that traceFile connection attribute functions correctly. tracefile was tested in checkDriver, but not for DataSources. tracefile= was used in datasourcepermissions_net, but that's incorrect syntax. Note that we're not checking the contents of the tracefile. This fixture has a counterpart for Pooled and XA DataSources in J2EEDataSourceTest Note also that this test cannot run against a remote server.

Throws:
java.sql.SQLException

dsGetBadConnection

private static void dsGetBadConnection(javax.sql.DataSource ds)

assertTraceFilesExist

private static void assertTraceFilesExist()
Check that trace file exists in directory


testClientMessageTextConnectionAttribute

public void testClientMessageTextConnectionAttribute()
                                              throws java.sql.SQLException
Check that messageText connection attribute functions correctly. retrievemessagetext was tested in checkdriver, and derbynet/testij, but not tested for datasources, and in datasourcepermissions_net, but as it has nothing to do with permissions/authentication, this test seems a better place for it. This fixture has a counterpart for Pooled and XA DataSources in J2EEDataSourceTest

Throws:
java.sql.SQLException

assertMessageText

private static void assertMessageText(java.sql.Connection conn,
                                      java.lang.String retrieveMessageTextValue)
                               throws java.sql.SQLException
Throws:
java.sql.SQLException

testDescriptionProperty

public void testDescriptionProperty()
                             throws java.sql.SQLException,
                                    java.lang.Exception
Check that messageText connection attribute functions correctly. retrievemessagetext was tested in checkdriver, and derbynet/testij (but not tested for datasources), and in datasourcepermissions_net, but as it has nothing to do with permissions/authentication, this test seems a better place for it. This fixture has a counterpart for Pooled and XA DataSources in J2EEDataSourceTest

Throws:
java.sql.SQLException
java.lang.Exception

subTestDataSourceDescription

private void subTestDataSourceDescription(javax.sql.DataSource ds)
                                   throws java.lang.Exception
Utility method for testing setting and fetching the description property on a data source.

Throws:
java.lang.Exception

setDatabaseProperty

private static void setDatabaseProperty(java.lang.String property,
                                        java.lang.String value)
                                 throws java.sql.SQLException
Throws:
java.sql.SQLException

dsConnectionRequests

private static void dsConnectionRequests(java.lang.String[] expectedValues,
                                         javax.sql.DataSource ds)

dsConnectionRequest

private static void dsConnectionRequest(java.lang.String expectedValue,
                                        javax.sql.DataSource ds,
                                        java.lang.String user,
                                        java.lang.String ConnAttr)

assertConnectionOK

private void assertConnectionOK(java.lang.Object[] expectedValues,
                                java.lang.String dsName,
                                java.sql.Connection conn)
                         throws java.sql.SQLException
Throws:
java.sql.SQLException

assertConnectionPreClose

private void assertConnectionPreClose(java.lang.String dsName,
                                      java.sql.Connection conn)
                               throws java.sql.SQLException
Throws:
java.sql.SQLException

assertStatementOK

private void assertStatementOK(java.lang.String dsName,
                               java.sql.Connection conn,
                               java.sql.Statement s)
                        throws java.sql.SQLException
Throws:
java.sql.SQLException

assertToString

private static void assertToString(java.sql.Connection conn)
                            throws java.lang.Exception
Make sure this connection's string is unique (DERBY-243)

Throws:
java.lang.Exception

assertStringFormat

private static void assertStringFormat(java.sql.Connection conn)
Check the format of the connection string. This is the default test to run if this is not a BrokeredConnection class


assertStringPrefix

private static java.lang.String assertStringPrefix(java.lang.Object conn)
Make sure the connection string starts with the right prefix, which is the classname@hashcode.

Returns:
the expected prefix string, this is used in further string format checking

assertToString

private static void assertToString(javax.sql.DataSource ds)
                            throws java.lang.Exception
Check uniqueness of connection strings coming from a DataSouce

Throws:
java.lang.Exception

clearConnections

private static void clearConnections()
                              throws java.sql.SQLException
Clear out and close connections in the connections hashtable.

Throws:
java.sql.SQLException

assertTenConnectionsUnique

private void assertTenConnectionsUnique()
                                 throws java.lang.Exception
Get connections using getConnection() and make sure they're unique

Throws:
java.lang.Exception

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.