|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectjunit.framework.Assert
junit.framework.TestCase
org.apache.derbyTesting.junit.BaseTestCase
org.apache.derbyTesting.junit.BaseJDBCTestCase
public abstract class BaseJDBCTestCase
Base class for JDBC JUnit tests. A method for getting a default connection is provided, along with methods for telling if a specific JDBC client is used.
| Field Summary | |
|---|---|
private java.sql.Connection |
conn
Maintain a single connection to the default database, opened at the first call to getConnection. |
private java.util.List |
statements
Maintain a list of statement objects that were returned by utility methods and close them at teardown. |
| Fields inherited from class org.apache.derbyTesting.junit.BaseTestCase |
|---|
DEFAULT_DB_DIR, DERBY_LOG, ERRORSTACKTRACEFILE |
| Constructor Summary | |
|---|---|
BaseJDBCTestCase(java.lang.String name)
Create a test case with the given name. |
|
| Method Summary | |
|---|---|
private void |
addStatement(java.sql.Statement s)
Add a statement into the list we will close at tearDown. |
void |
assertCallError(java.lang.String expectedSE,
java.lang.String callSQL)
Executes the Callable statement that is expected to fail and verifies that it throws the expected SQL exception. |
void |
assertCheckTable(java.lang.String table)
Check the table using SYSCS_UTIL.SYSCS_CHECK_TABLE. |
void |
assertCompileError(java.lang.String sqlState,
java.lang.String sql)
Assert that the SQL statement does not compile and throws a SQLException with the expected state. |
static void |
assertEquals(java.sql.Blob b1,
java.sql.Blob b2)
Assert equality between two Blob objects. |
static void |
assertEquals(java.sql.Clob c1,
java.sql.Clob c2)
Assert equality between two Clob objects. |
static void |
assertEquals(java.lang.String msg,
java.sql.Time t1,
java.sql.Time t2)
Assert equality between two java.sql.Time objects. |
static void |
assertEquivalentDataType(int expectedType,
int type)
Compares two JDBC types to see if they are equivalent. |
private void |
assertEscapedTableRowCount(java.lang.String escapedTableName,
int rowCount)
Assert that the number of rows in a table is an expected value. |
static void |
assertGetIntError(int position,
java.lang.String sqlState,
java.sql.ResultSet rs)
Perform getInt(position) with expected error |
static void |
assertNextError(java.lang.String sqlState,
java.sql.ResultSet rs)
Perform a fetch on the ResultSet with an expected failure |
static void |
assertPreparedStatementError(java.lang.String sqlState,
java.sql.PreparedStatement ps)
Assert that the query fails (either in execution, or retrieval of results--doesn't matter) and throws a SQLException with the expected state and error code Parameters must have been already bound, if any. |
static void |
assertSQLExceptionEquals(java.sql.SQLException se1,
java.sql.SQLException se2)
Assert that the two (2) passed-in SQLException's are equals and not just '=='. |
static void |
assertSQLState(java.lang.String expected,
java.sql.SQLException exception)
Assert that SQLState is as expected. |
static void |
assertSQLState(java.lang.String message,
java.lang.String expected,
java.sql.SQLException exception)
Assert that SQLState is as expected. |
static void |
assertStatementError(java.lang.String[] sqlStates,
java.sql.Statement st,
java.lang.String query)
Assert that the query fails (either in compilation, execution, or retrieval of results--doesn't matter) and throws a SQLException with the expected states. |
static void |
assertStatementError(java.lang.String sqlState,
int errorCode,
java.sql.Statement st,
java.lang.String query)
Assert that the query fails (either in compilation, execution, or retrieval of results--doesn't matter) and throws a SQLException with the expected state and error code Assumption is that 'query' does *not* have parameters that need binding and thus can be executed using a simple Statement.execute() call. |
static void |
assertStatementError(java.lang.String sqlState,
java.sql.PreparedStatement pSt)
Assert that execution of the received PreparedStatement object fails (either in execution or when retrieving results) and throws a SQLException with the expected state. |
static void |
assertStatementError(java.lang.String sqlState,
java.sql.Statement st,
java.lang.String query)
Assert that the query fails with a single error |
protected void |
assertTableRowCount(java.lang.String table,
int rowCount)
Assert that the number of rows in a table is an expected value. |
static void |
assertUpdateCount(java.sql.PreparedStatement pSt,
int expectedRC)
Assert that a call to "executeUpdate()" on the received PreparedStatement object returns a row count that matches the received row count. |
static void |
assertUpdateCount(java.sql.Statement st,
int expectedRC,
java.lang.String sql)
Take a Statement object and a SQL statement, execute it via the "executeUpdate()" method, and assert that the resultant row count matches the received row count. |
protected void |
checkAllConsistency(java.sql.Connection conn)
Check consistency of all tables |
static void |
checkEstimatedRowCount(java.sql.Connection conn,
double expectedCount)
Return estimated row count for runtime statistics. |
void |
commit()
Utility method to commit using the connection returned by getConnection. |
java.sql.Statement |
createStatement()
Utility method to create a Statement using the connection returned by getConnection. |
java.sql.Statement |
createStatement(int resultSetType,
int resultSetConcurrency)
Utility method to create a Statement using the connection returned by getConnection. |
java.sql.Statement |
createStatement(int resultSetType,
int resultSetConcurrency,
int resultSetHoldability)
Utility method to create a Statement using the connection returned by getConnection. |
static void |
dropTable(java.sql.Connection conn,
java.lang.String tableName)
Execute a DROP TABLE command using the passed in tableName as-is. |
void |
dropTable(java.lang.String tableName)
Execute a DROP TABLE command using the passed in tableName as-is and the default connection. |
private static void |
fetchAndDiscardAllResults(java.sql.Statement st,
boolean haveRS)
Take the received Statement--on which a query has been executed--and fetch all rows of all result sets (if any) returned from execution. |
java.sql.Connection |
getConnection()
Obtain the connection to the default database. |
java.lang.String |
getDatabaseProperty(java.lang.String propertyName)
Get the value of a database property using the default connection |
java.sql.SQLException |
getLastSQLException(java.sql.SQLException sqle)
Get the last SQLException in chain. |
protected void |
initializeConnection(java.sql.Connection conn)
Allow a sub-class to initialize a connection to provide consistent connection state for its tests. |
java.sql.Connection |
openConnection(java.lang.String databaseName)
Open a connection to the specified database. |
java.sql.Connection |
openDefaultConnection()
Open a connection to the default database. |
java.sql.Connection |
openDefaultConnection(java.lang.String user,
java.lang.String password)
Open a connection to the current default database using the specified user name and password. |
java.sql.Connection |
openUserConnection(java.lang.String user)
Open a connection to the current default database using the specified user name. |
java.sql.CallableStatement |
prepareCall(java.lang.String sql)
Utility method to create a CallableStatement using the connection returned by getConnection. |
java.sql.CallableStatement |
prepareCall(java.lang.String sql,
int resultSetType,
int resultSetConcurrency)
Utility method to create a CallableStatement using the connection returned by getConnection. |
java.sql.CallableStatement |
prepareCall(java.lang.String sql,
int resultSetType,
int resultSetConcurrency,
int resultSetHoldability)
Utility method to create a CallableStatement using the connection returned by getConnection. |
java.sql.PreparedStatement |
prepareStatement(java.lang.String sql)
Utility method to create a PreparedStatement using the connection returned by getConnection. |
java.sql.PreparedStatement |
prepareStatement(java.lang.String sql,
int autoGeneratedKeys)
Utility method to create a PreparedStatement using the connection returned by getConnection and a flag that signals the driver whether the auto-generated keys produced by this Statement object should be made available for retrieval. |
java.sql.PreparedStatement |
prepareStatement(java.lang.String sql,
int[] columnIndexes)
Utility method to create a PreparedStatement using the connection returned by getConnection and an array of column indexes that indicates which auto-generated keys produced by this Statement object should be made available for retrieval. |
java.sql.PreparedStatement |
prepareStatement(java.lang.String sql,
int resultSetType,
int resultSetConcurrency)
Utility method to create a PreparedStatement using the connection returned by getConnection with result set type and concurrency. |
java.sql.PreparedStatement |
prepareStatement(java.lang.String sql,
int resultSetType,
int resultSetConcurrency,
int resultSetHoldability)
Utility method to create a PreparedStatement using the connection returned by getConnection with result set type and concurrency. |
java.sql.PreparedStatement |
prepareStatement(java.lang.String sql,
java.lang.String[] columnNames)
Utility method to create a PreparedStatement using the connection returned by getConnection and an array of column names that indicates which auto-generated keys produced by this Statement object should be made available for retrieval. |
void |
rollback()
Utility method to rollback using the connection returned by getConnection. |
int |
runScript(java.io.InputStream script,
java.lang.String encoding)
Run a SQL script through ij discarding the output using this object's default connection. |
int |
runScript(java.lang.String resource,
java.lang.String encoding)
Run a SQL script through ij discarding the output using this object's default connection. |
int |
runSQLCommands(java.lang.String sqlCommands)
Run a set of SQL commands from a String discarding the output. |
void |
setAutoCommit(boolean commit)
Utility method to set auto commit behaviour. |
protected void |
tearDown()
Tear down this fixture, sub-classes should call super.tearDown(). |
static boolean |
usingDB2Client()
Tell if the client is DB2Client. |
static boolean |
usingDerbyNetClient()
Tell if the client is DerbyNetClient. |
static boolean |
usingEmbedded()
Tell if the client is embedded. |
| 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 |
|---|
private java.sql.Connection conn
getConnection()private java.util.List statements
| Constructor Detail |
|---|
public BaseJDBCTestCase(java.lang.String name)
name - of the test case.| Method Detail |
|---|
public java.sql.Connection getConnection()
throws java.sql.SQLException
The tearDown method will close the connection if
it is open.
The connection will be initialized by calling initializeConnection.
A sub-class may provide an implementation of initializeConnection
to ensure its connections are in a consistent state that is different
to the default.
java.sql.SQLExceptionopenDefaultConnection()
protected void initializeConnection(java.sql.Connection conn)
throws java.sql.SQLException
conn - Connection to be intialized
java.sql.SQLException - Error setting the initial state.
public java.sql.Statement createStatement()
throws java.sql.SQLException
java.sql.SQLExceptionprivate void addStatement(java.sql.Statement s)
public java.sql.Statement createStatement(int resultSetType,
int resultSetConcurrency)
throws java.sql.SQLException
java.sql.SQLException
public java.sql.Statement createStatement(int resultSetType,
int resultSetConcurrency,
int resultSetHoldability)
throws java.sql.SQLException
java.sql.SQLException
public java.sql.PreparedStatement prepareStatement(java.lang.String sql)
throws java.sql.SQLException
java.sql.SQLException
public java.sql.PreparedStatement prepareStatement(java.lang.String sql,
int resultSetType,
int resultSetConcurrency)
throws java.sql.SQLException
java.sql.SQLException
public java.sql.PreparedStatement prepareStatement(java.lang.String sql,
int resultSetType,
int resultSetConcurrency,
int resultSetHoldability)
throws java.sql.SQLException
java.sql.SQLException
public java.sql.PreparedStatement prepareStatement(java.lang.String sql,
int autoGeneratedKeys)
throws java.sql.SQLException
java.sql.SQLException
public java.sql.PreparedStatement prepareStatement(java.lang.String sql,
int[] columnIndexes)
throws java.sql.SQLException
java.sql.SQLException
public java.sql.PreparedStatement prepareStatement(java.lang.String sql,
java.lang.String[] columnNames)
throws java.sql.SQLException
java.sql.SQLException
public java.sql.CallableStatement prepareCall(java.lang.String sql)
throws java.sql.SQLException
java.sql.SQLException
public java.sql.CallableStatement prepareCall(java.lang.String sql,
int resultSetType,
int resultSetConcurrency)
throws java.sql.SQLException
java.sql.SQLException
public java.sql.CallableStatement prepareCall(java.lang.String sql,
int resultSetType,
int resultSetConcurrency,
int resultSetHoldability)
throws java.sql.SQLException
java.sql.SQLException
public void setAutoCommit(boolean commit)
throws java.sql.SQLException
commit - false if autoCommit should be disabled.
java.sql.SQLException
public void commit()
throws java.sql.SQLException
java.sql.SQLException
public void rollback()
throws java.sql.SQLException
java.sql.SQLException
protected void tearDown()
throws java.lang.Exception
tearDown in class junit.framework.TestCasejava.lang.Exception
public java.sql.Connection openDefaultConnection()
throws java.sql.SQLException
java.sql.SQLExceptionTestConfiguration.openDefaultConnection(),
initializeConnection(Connection)
public java.sql.Connection openDefaultConnection(java.lang.String user,
java.lang.String password)
throws java.sql.SQLException
java.sql.SQLExceptioninitializeConnection(Connection)
public java.sql.Connection openUserConnection(java.lang.String user)
throws java.sql.SQLException
java.sql.SQLExceptionDatabasePropertyTestSetup.builtinAuthentication(Test, String[], String),
TestConfiguration.sqlAuthorizationDecorator(Test, String[], String),
initializeConnection(Connection)
public java.sql.Connection openConnection(java.lang.String databaseName)
throws java.sql.SQLException
java.sql.SQLExceptionTestConfiguration.additionalDatabaseDecorator(Test, String),
initializeConnection(Connection)
public int runScript(java.io.InputStream script,
java.lang.String encoding)
throws java.io.UnsupportedEncodingException,
java.sql.SQLException
java.io.UnsupportedEncodingException
java.sql.SQLException
public int runScript(java.lang.String resource,
java.lang.String encoding)
throws java.io.UnsupportedEncodingException,
java.sql.SQLException,
java.security.PrivilegedActionException,
java.io.IOException
java.io.UnsupportedEncodingException
java.security.PrivilegedActionException
java.sql.SQLException
java.io.IOException
public int runSQLCommands(java.lang.String sqlCommands)
throws java.io.UnsupportedEncodingException,
java.sql.SQLException
sqlCommands -
java.io.UnsupportedEncodingException
java.sql.SQLExceptionpublic static boolean usingEmbedded()
true if using the embedded client
false otherwise.public static boolean usingDerbyNetClient()
true if using the DerbyNetClient client
false otherwise.public static boolean usingDB2Client()
true if using the DB2 client driver,
false otherwise.
public java.lang.String getDatabaseProperty(java.lang.String propertyName)
throws java.sql.SQLException
propertyName - Property key
java.sql.SQLException
public static void assertEquals(java.sql.Blob b1,
java.sql.Blob b2)
throws java.io.IOException,
java.sql.SQLException
Blob objects.
If both input references are null, they are considered
equal. The same is true if both blobs have null-streams.
b1 - first Blob.b2 - second Blob.
junit.framework.AssertionFailedError - if blobs are not equal.
java.io.IOException - if reading or closing a stream fails
java.sql.SQLException - if obtaining a stream fails
public static void assertEquals(java.sql.Clob c1,
java.sql.Clob c2)
throws java.io.IOException,
java.sql.SQLException
Clob objects.
If both input references are null, they are considered
equal. The same is true if both clobs have null-streams.
c1 - first Clob.c2 - second Clob.
junit.framework.AssertionFailedError - if clobs are not equal.
java.io.IOException - if reading or closing a stream fails
java.sql.SQLException - if obtaining a stream fails
public static void assertEquals(java.lang.String msg,
java.sql.Time t1,
java.sql.Time t2)
java.sql.Time objects.
If both input references are null, they are considered
equal.
msg - String with message to supply with AssertionFailedErrort1 - first java.sql.Time object.t2 - second java.sql.Time object.
junit.framework.AssertionFailedError - if Time objects are not equal.
public static void assertSQLState(java.lang.String message,
java.lang.String expected,
java.sql.SQLException exception)
message - message to print on failure.expected - the expected SQLState.exception - the exception to check the SQLState of.
public static void assertSQLState(java.lang.String expected,
java.sql.SQLException exception)
expected - the expected SQLState.exception - the exception to check the SQLState of.
public void assertCompileError(java.lang.String sqlState,
java.lang.String sql)
sqlState - expected sql state.sql - the SQL to compile.
public void assertCheckTable(java.lang.String table)
throws java.sql.SQLException
java.sql.SQLException
protected void assertTableRowCount(java.lang.String table,
int rowCount)
throws java.sql.SQLException
table - Name of table in current schema, will be quotedrowCount - Number of rows expected in the table
java.sql.SQLException - Error accessing the database.
private void assertEscapedTableRowCount(java.lang.String escapedTableName,
int rowCount)
throws java.sql.SQLException
escapedTableName - Escaped name of table, will be used as-is.rowCount - Number of rows expected in the table
java.sql.SQLException - Error accessing the database.
public final void dropTable(java.lang.String tableName)
throws java.sql.SQLException
tableName - Table to be dropped.
java.sql.SQLException
public static void dropTable(java.sql.Connection conn,
java.lang.String tableName)
throws java.sql.SQLException
conn - Connection to execute the DROP TABLEtableName - Table to be dropped.
java.sql.SQLException
public static void assertStatementError(java.lang.String[] sqlStates,
java.sql.Statement st,
java.lang.String query)
sqlStates - expected sql states.st - Statement object on which to execute.query - the query to compile and execute.
public static void assertStatementError(java.lang.String sqlState,
java.sql.Statement st,
java.lang.String query)
sqlState - Expected SQLState of exceptionst - query - assertStatementError(String[], Statement, String)
public static void assertStatementError(java.lang.String sqlState,
int errorCode,
java.sql.Statement st,
java.lang.String query)
sqlState - expected sql state.errorCode - expected error code.st - Statement object on which to execute.query - the query to compile and execute.
public static void assertPreparedStatementError(java.lang.String sqlState,
java.sql.PreparedStatement ps)
sqlState - expected sql state.ps - PreparedStatement query object to execute.
public static void assertStatementError(java.lang.String sqlState,
java.sql.PreparedStatement pSt)
sqlState - expected sql state.pSt - A PreparedStatement or CallableStatement on
which to call "execute()".
public void assertCallError(java.lang.String expectedSE,
java.lang.String callSQL)
throws java.sql.SQLException
expectedSE - The expected SQL exceptioncallSQL - The SQL to execute
java.sql.SQLException
public static void assertNextError(java.lang.String sqlState,
java.sql.ResultSet rs)
sqlState - Expected SQLStaters - ResultSet upon which next() will be called
public static void assertGetIntError(int position,
java.lang.String sqlState,
java.sql.ResultSet rs)
position - position argument to pass to getIntsqlState - sqlState of expected errorrs - ResultSet upon which to call getInt(position)
public static void assertUpdateCount(java.sql.Statement st,
int expectedRC,
java.lang.String sql)
throws java.sql.SQLException
st - Statement object on which to execute.expectedRC - Expected row count.sql - SQL to execute.
java.sql.SQLException
public static void assertUpdateCount(java.sql.PreparedStatement pSt,
int expectedRC)
throws java.sql.SQLException
pSt - The PreparedStatement on which to execute.expectedRC - The expected row count.
java.sql.SQLExceptionpublic java.sql.SQLException getLastSQLException(java.sql.SQLException sqle)
sqle - SQLException
private static void fetchAndDiscardAllResults(java.sql.Statement st,
boolean haveRS)
throws java.sql.SQLException
st - An already-executed statement from which
we get the result set to process (if there is one).haveRS - Whether or not the the statement's
first result is a result set (as opposed to an
update count).
java.sql.SQLException
public static void assertSQLExceptionEquals(java.sql.SQLException se1,
java.sql.SQLException se2)
se1 - first SQLException to comparese2 - second SQLException to compare
public static void assertEquivalentDataType(int expectedType,
int type)
expectedType - Expected jdbctype from java.sql.Typestype - Actual type from metadata
public static void checkEstimatedRowCount(java.sql.Connection conn,
double expectedCount)
throws java.sql.SQLException
conn - expectedCount -
java.sql.SQLException
protected void checkAllConsistency(java.sql.Connection conn)
throws java.sql.SQLException
conn -
java.sql.SQLException
|
Built on Wed 2009-11-25 18:43:31-0800, from revision 884373 | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||