Package Name | Comment |
net.sourceforge.sqlunit |
Classes for the SQLUnit core package. The SQLUnit package is designed as a set of individual XML handlers for the various elements of the SQLUnit test suite authoring XML. There is a one to one correspondence between the SQLUnit element and the SQLUnit handler class as illustrated in the table below:
XML Element |
SQLUnit Handler Class |
sqlunit
- connection
- setup
- test
- prepare
- sql or call
- result
- teardown
|
- net.sourceforge.sqlunit.ConnectionHandler
- net.sourceforge.sqlunit.SetupHandler
- net.sourceforge.sqlunit.SqlHandler
- net.sourceforge.sqlunit.IncludeHandler
- net.sourceforge.sqlunit.TestHandler
- net.sourceforge.sqlunit.PrepareHandler
- net.sourceforge.sqlunit.SqlHandler|CallHandler
- net.sourceforge.sqlunit.ResultHandler
- net.sourceforge.sqlunit.TeardownHandler
- net.sourceforge.sqlunit.SqlHandler
- net.sourceforge.sqlunit.IncludeHandler
|
Each handler class reads the JDOM element and extracts the information to pass back to the SQLUnit class. The SQLUnit class is designed as a JUnit test class. The JUnit class contains a single test method called testWrapper() which is responsible for reading the XML file and carrying out the operations specified in the setup element, followed by each test in sequence, followed by the operations in the teardown element. The ConnectionHandler class is called before all the other operations to get a JDBC connection to the database.
All handler classes implement the IHandler interface, which specifies a single process method which takes a JDOM Element org.jdom.Element and a java.sql.Connection object and returns a java.lang.Object. A given handler implementation may not need to return an Object, in which case it must return null. The HandlerFactory uses the handlers.properties Java properties file to instantiate the appropriate instance of a handler given the JDOM Element name.
Apart from the handlers, there are some auxilliary classes that provide utilities to the handlers. The SymbolTable class is a container of variables that are declared within an SQLUnit test script. The DatabaseResult object is a HashMap of fields and values returned from processing a SQL statement or stored procedure, or parsed out of a SQLUnit result element. The key for this HashMap is a DatabaseResultKey which is really a tuple of (resultsetId, rowId, colId) for each column returned by a SQL statement or stored procedure specified by the SQLUnit sql or call elements and parsed out of the SQLUnit result element. The SqlTypeUtils class is responsible for converting between database type to String and back, depending on the method called.
The SQLUnitException class is a common class that is shared by the SQLUnit package. The content of the SQLUnitException error messages is handled by specifying constant Strings in the IErrorCodes interface class.
|
net.sourceforge.sqlunit.ant |
The SQLUnit Ant Task.
|
net.sourceforge.sqlunit.beans |
Beans for the SQLUnit handlers.
|
net.sourceforge.sqlunit.handlers |
Handler implementations for SQLUnit. The SQLUnit package is designed as a set of individual XML handlers for the various elements of the SQLUnit test suite authoring XML. There is a one to one correspondence between the SQLUnit element and the SQLUnit handler class as illustrated in the table below:
XML Element |
SQLUnit Handler Class |
sqlunit
- connection
- setup
- test
- prepare
- sql or call
- result
- teardown
|
- net.sourceforge.sqlunit.ConnectionHandler
- net.sourceforge.sqlunit.SetupHandler
- net.sourceforge.sqlunit.SqlHandler
- net.sourceforge.sqlunit.IncludeHandler
- net.sourceforge.sqlunit.TestHandler
- net.sourceforge.sqlunit.PrepareHandler
- net.sourceforge.sqlunit.SqlHandler|CallHandler
- net.sourceforge.sqlunit.ResultHandler
- net.sourceforge.sqlunit.TeardownHandler
- net.sourceforge.sqlunit.SqlHandler
- net.sourceforge.sqlunit.IncludeHandler
|
Each handler class reads the JDOM element and extracts the information to pass back to the SQLUnit class. The SQLUnit class is designed as a JUnit test class. The JUnit class contains a single test method called testWrapper() which is responsible for reading the XML file and carrying out the operations specified in the setup element, followed by each test in sequence, followed by the operations in the teardown element. The ConnectionHandler class is called before all the other operations to get a JDBC connection to the database.
All handler classes implement the IHandler interface, which specifies a single process method which takes a JDOM Element org.jdom.Element and a java.sql.Connection object and returns a java.lang.Object. A given handler implementation may not need to return an Object, in which case it must return null. The HandlerFactory uses the handlers.properties Java properties file to instantiate the appropriate instance of a handler given the JDOM Element name.
Apart from the handlers, there are some auxilliary classes that provide utilities to the handlers. The SymbolTable class is a container of variables that are declared within an SQLUnit test script. The DatabaseResult object is a HashMap of fields and values returned from processing a SQL statement or stored procedure, or parsed out of a SQLUnit result element. The key for this HashMap is a DatabaseResultKey which is really a tuple of (resultsetId, rowId, colId) for each column returned by a SQL statement or stored procedure specified by the SQLUnit sql or call elements and parsed out of the SQLUnit result element. The SqlTypeUtils class is responsible for converting between database type to String and back, depending on the method called.
The SQLUnitException class is a common class that is shared by the SQLUnit package. The content of the SQLUnitException error messages is handled by specifying constant Strings in the IErrorCodes interface class.
|
net.sourceforge.sqlunit.matchers |
Matcher plug-ins for SQLUnit. Matcher plug-in classes define rules to match between two columns. The default matching is an exact match, but Matchers can be built that match within a percentage or a range. This is not an exhaustive list, more are expected to be added as users contribute them.
|
net.sourceforge.sqlunit.parsers | |
net.sourceforge.sqlunit.reporters |
Reporter plug-ins for SQLUnit. SQLUnit comes configured with the default text reporter, but provides the ability to hook in a reporter of your choice that works with your existing system.
All reporter plug-ins should implement the IReporter interface, and needs to provide code that will be executed by SQLUnit for reporting.
Acknowledgement
The plug-in code was contributed largely by Rob Nielsen. He needed to use SQLUnit with Canoo, so he factored out the reporting code from SQLUnit and made it into the TextReporter, and built the CanooWebTestReporter plug-in.
|
net.sourceforge.sqlunit.test |
Miscellaneous Testing classes. These are JUnit test classes and some other
classes that support the JUnit or the Mock test frameworks.
|
net.sourceforge.sqlunit.test.mock |
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:
- The count of the number of results (used for the Statement.execute() and CallableStatement.getMoreResults()) is returned in wrapped in result set 0.
- 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.
- Exceptions are not thrown directly, but they are wrapped in the resultset that is being made to throw the exception.
- 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:
- 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.
- SQLUnitMockDriver extends com.mockrunner.mock.jdbc.MockDriver. This version provides a URL signature which the mock framework will respond to.
- SQLUnitMockStatement extends com.mockrunner.mock.jdbc.MockStatement. Calls the Introspecting version of the ResultSetHandler.
- SQLUnitMockPreparedStatement extends com.mockrunner.mock.jdbc.MockPreparedStatement. Calls the Introspecting version of the ResultSetHandler.
- SQLUnitMockCallableStatement extends com.mockrunner.mock.jdbc.MockStatement. Calls the Introspecting version of the ResultSetHandler.
- IntrospectingStatementResultSetHandler extends com.mockrunner.jdbc.StatementResultSetHandler. Invokes the IntrospectingResultSetFactory to execute Statement objects.
- IntrospectingPreparedStatementResultSetHandler extends com.mockrunner.jdbc.PreparedStatementResultSetHandler. Invokes the IntrospectingResultSetFactory to execute PreparedStatement objects.
- IntrospectingCallableStatementResultSetHandler extends com.mockrunner.jdbc.CallableStatementResultSetHandler. Invokes the IntrospectingResultSetFactory to execute CallableStatement objects.
- 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.
|
net.sourceforge.sqlunit.tools |
Contains tools to build SQLUnit test cases. These tools were moved from their
old locations and merged into a single tools package to take advantage of
code reuse possibilities.
Backward compatibility information
To those using these tools for the first time, there should be no issues at all. Each tool has an associated configuration file which can be used to predefine information such as JDBC parameters. The only changes to this file are as follows:
guiconfig.properties.sample: The addition of a new indentsize property which allows you to specify how many characters per indent you want. It defaults to 2, so if thats OK, you dont need to change your properties file.
tuirc.properties.sample: The captureFile property has been renamed to capturefile so as to be in line with the similarly named property in the guiconfig.properties.sample file. This was necessary to take advantage of the code sharing mentioned above.
|
net.sourceforge.sqlunit.types |
Implementations of various datatypes.
|
net.sourceforge.sqlunit.utils |
Utility classes for SQLUnit.
|