Package net.sourceforge.sqlunit.test.mock

Mock Testing framework for SQLUnit.

See:
          Description

Interface Summary
IMockDatabase Provides a convenient abstraction of what a mock database should look like for SQLUnit mock testing.
 

Class Summary
AbstractMockDatabase Abstract base class from which all IMockDatabase objects must extend.
ColumnMetaData Container for Column Metadata information.
IntrospectingCallableStatementResultSetHandler Extends the CallableStatementResultSetHandler to use introspection.
IntrospectingPreparedStatementResultSetHandler Extends the PreparedStatementResultSetHandler to use introspection.
IntrospectingResultSetFactory Introspects a given IMockDataStore object and invokes the named method to return ResultSet objects.
IntrospectingStatementResultSetHandler Extends the StatementResultSetHandler to use introspection.
MockInitialContext Overrides the InitialContext to provide an in-memory lookup mechanism instead of network lookup.
MockInitialContextFactory Builds a MockInitialContext using an environment Hashtable.
MockResultSetUtils Collection of utility methods to manipulate MockResultSets.
SQLUnitMockCallableStatement Overrides certain methods in the MockCallableStatement class for mock testing of SQLUnit.
SQLUnitMockConnection Represents a Connection object that depends on an underlying IDatabase.
SQLUnitMockDatabase Mock database to supply results.
SQLUnitMockDriver Implements a Mock JDBC driver for SQLUnit.
SQLUnitMockPreparedStatement Overrides certain methods in the MockPreparedStatement class for mock testing of SQLUnit.
SQLUnitMockStatement Overrides certain methods in the MockStatement class for mock testing of SQLUnit.
VarSetter Simple class whose method is called from the set tag.
 

Package net.sourceforge.sqlunit.test.mock Description

Mock Testing framework for SQLUnit. Provides a framework to test SQLUnit code without a database. The database independence is achieved by using the MockRunner JDBC framework.

Instead of a real database, the testing framework relies on introspecting a specified class. The class implements the IMockDatabase interface and contains methods with the signature: public MockResultSet methodName(Integer resultSetId); The IMockDatabase interface mandates a getResultSet(String,int) method which returns a MockResultSet. The implementation of this method is provided in the AbstractMockDatabase class. Clients wishing to develop their own mock database classes should extend this class.

Examples of methods that mimic the behavior of stored procedures can be found in the SQLUnitMockDatabase class which extends AbstractMockDatabase. Things to note are:

  1. The count of the number of results (used for the Statement.execute() and CallableStatement.getMoreResults()) is returned in wrapped in result set 0.
  2. Outparam values are generated internally using the negative of the supplied index. Thus, the value of OUTPARAM at position 1 will be wrapped in the resultset that is returned by invoking the appropriate method with -1. Scalar OUTPARAM values are specified as Strings, but are converted to the appropriate Object on retrieval. REF CURSOR OUTPARAM objects are returned as themselves since they are essentially ResultSet objects.
  3. Exceptions are not thrown directly, but they are wrapped in the resultset that is being made to throw the exception.
  4. ResultSets are returned from the method using the supplied index. Thus the first ResultSet will be returned by invoking the method with Integer(1).
The functionality of wrapping and unwrapping scalar and SQLException objects back and forth from MockResultSet objects can be found in the MockResultSetUtils class.

To make this work with the MockRunner framework, the following classes were extended from the MockRunner distribution:

  1. SQLUnitMockConnection extends com.mockrunner.mock.jdbc.MockConnection. The extensions were mainly to call the Introspecting versions of the ResultSetHandler classes instead of MockRunner's ResultSetHandlers.
  2. SQLUnitMockDriver extends com.mockrunner.mock.jdbc.MockDriver. This version provides a URL signature which the mock framework will respond to.
  3. SQLUnitMockStatement extends com.mockrunner.mock.jdbc.MockStatement. Calls the Introspecting version of the ResultSetHandler.
  4. SQLUnitMockPreparedStatement extends com.mockrunner.mock.jdbc.MockPreparedStatement. Calls the Introspecting version of the ResultSetHandler.
  5. SQLUnitMockCallableStatement extends com.mockrunner.mock.jdbc.MockStatement. Calls the Introspecting version of the ResultSetHandler.
  6. IntrospectingStatementResultSetHandler extends com.mockrunner.jdbc.StatementResultSetHandler. Invokes the IntrospectingResultSetFactory to execute Statement objects.
  7. IntrospectingPreparedStatementResultSetHandler extends com.mockrunner.jdbc.PreparedStatementResultSetHandler. Invokes the IntrospectingResultSetFactory to execute PreparedStatement objects.
  8. IntrospectingCallableStatementResultSetHandler extends com.mockrunner.jdbc.CallableStatementResultSetHandler. Invokes the IntrospectingResultSetFactory to execute CallableStatement objects.
  9. IntrospectingResultSetHandler implements the com.mockrunner.jdbc.ResultSetHandler. Implements multi-resultset handling and getting the result sets using Introspection.
A sample test file which uses the SQLUnit mock testing framework can be found at test/mock/test.xml in the distribution.