net.sourceforge.sqlunit.test.mock
Class SQLUnitMockDatabase

java.lang.Object
  extended by net.sourceforge.sqlunit.test.mock.AbstractMockDatabase
      extended by net.sourceforge.sqlunit.test.mock.SQLUnitMockDatabase
All Implemented Interfaces:
IMockDatabase

public class SQLUnitMockDatabase
extends AbstractMockDatabase

Mock database to supply results.

Version:
$Revision: 1.21 $
Author:
Sujit Pal (spal@users.sourceforge.net)

Constructor Summary
SQLUnitMockDatabase()
           
 
Method Summary
 com.mockrunner.mock.jdbc.MockResultSet anotherInResultSet(java.lang.Integer index)
          A method that returns the string "another" as a single column in a single row in a single resultset.
 com.mockrunner.mock.jdbc.MockResultSet anotherMultipleResultsDifferentTypes(java.lang.Integer index)
          Another method returning multiple result sets.
 com.mockrunner.mock.jdbc.MockResultSet anotherSimpleResult(java.lang.Integer index)
          A simple method returning a single resultset with a single int column.
 com.mockrunner.mock.jdbc.MockResultSet aSimpleMultiColResult(java.lang.Integer index)
          Returns a single resultset with multiple columns in each row.
 com.mockrunner.mock.jdbc.MockResultSet aSimpleNullResult(java.lang.Integer index)
          A simple method returning a single resultset with a single int column which contains a NULL.
 com.mockrunner.mock.jdbc.MockResultSet aSimpleResult(java.lang.Integer index)
          A simple method returning a single resultset with a single int column.
 com.mockrunner.mock.jdbc.MockResultSet aSimpleStringResult(java.lang.Integer index)
          Returns a MockResult with a single row and a single column named 'foo' containing the String value 'foo'.
 com.mockrunner.mock.jdbc.MockResultSet blobResult(java.lang.Integer index)
          Returns a BLOB datatype which is the contents of SQLUnit.class.
 com.mockrunner.mock.jdbc.MockResultSet bytesInResultSet(java.lang.Integer index)
          Returns a Java object in a single result set.
 com.mockrunner.mock.jdbc.MockResultSet clobResult(java.lang.Integer index)
          Returns a CLOB datatype from the same canned XML file as the method above, but specifies this as a CLOB data type.
 com.mockrunner.mock.jdbc.MockResultSet deleteRows(java.lang.Integer index)
          Method to test the foreach tag.
 com.mockrunner.mock.jdbc.MockResultSet exceptionResult(java.lang.Integer index)
          A method that is designed to throw an SQLException.
 com.mockrunner.mock.jdbc.MockResultSet incrementDecimalAndReturn(java.lang.Integer index)
          Same as incrementNumericAndReturn1 since the underlying datatype is BigDecimal in both cases, and the scalar is built based on actual datatype.
 com.mockrunner.mock.jdbc.MockResultSet incrementNumericAndReturn(java.lang.Integer index)
          Returns a canned NUMERIC value in an INOUT Param.
 com.mockrunner.mock.jdbc.MockResultSet insert1Row(java.lang.Integer index)
          Method to test the foreach tag.
 com.mockrunner.mock.jdbc.MockResultSet insert2Row(java.lang.Integer index)
          Method to test the foreach tag.
 com.mockrunner.mock.jdbc.MockResultSet javaObjectResult(java.lang.Integer index)
          Returns a JAVA_OBJECT which is the same as that serialized in Dictionary.
 com.mockrunner.mock.jdbc.MockResultSet lobInResultSet(java.lang.Integer index)
          Returns an inputstream in a single result set.
 com.mockrunner.mock.jdbc.MockResultSet multipleResults(java.lang.Integer index)
          A method returning multiple result sets.
 com.mockrunner.mock.jdbc.MockResultSet refCursorReturn(java.lang.Integer index)
          Returns an Oracle style REF CURSOR in the first outparam element.
 com.mockrunner.mock.jdbc.MockResultSet resultAndException(java.lang.Integer index)
          Returns the result code and the exception.
 com.mockrunner.mock.jdbc.MockResultSet resultAndMultilineException(java.lang.Integer index)
          Returns an error code and a multi-line exception message.
 com.mockrunner.mock.jdbc.MockResultSet resultAndOneResultSet(java.lang.Integer index)
          Returns a result code and a single resultset.
 com.mockrunner.mock.jdbc.MockResultSet returnCountOfRowsInserted(java.lang.Integer index)
          Method to test the foreach tag.
 com.mockrunner.mock.jdbc.MockResultSet returnDecimalOutParam(java.lang.Integer index)
          Same as returnNumericOutParam since underlying datatype is BigDecimal in both cases, and the scalar is built based on actual datatype.
 com.mockrunner.mock.jdbc.MockResultSet returnNumericAndDecimalInResultSet(java.lang.Integer index)
          Returns a single row with 2 columns, one NUMERIC and one DECIMAL.
 com.mockrunner.mock.jdbc.MockResultSet returnNumericOutParam(java.lang.Integer index)
          Returns a NUMERIC in an OUT Param.
 com.mockrunner.mock.jdbc.MockResultSet selectDatabase(java.lang.Integer index)
          Takes no parameters and returns the name of the database.
 com.mockrunner.mock.jdbc.MockResultSet simpleReturnCode(java.lang.Integer index)
          A method returning a return code only.
 com.mockrunner.mock.jdbc.MockResultSet superHeroesSortedByAlias(java.lang.Integer index)
          Same as superHeroesSortedNaturally() but rows are returned sorted by alias.
 com.mockrunner.mock.jdbc.MockResultSet superHeroesSortedByAliasAndName(java.lang.Integer index)
          Same as superHeroesSortedNaturally() but rows are returned sorted by last name (lname).
 com.mockrunner.mock.jdbc.MockResultSet superHeroesSortedByAliasDesc(java.lang.Integer index)
          Same as superHeroesSortedNaturally() but rows are returned sorted descending by alias.
 com.mockrunner.mock.jdbc.MockResultSet superHeroesSortedNaturally(java.lang.Integer index)
          Returns a resultset which is sorted "naturally", ie by ascending order of columns as they appear in the resultset.
 com.mockrunner.mock.jdbc.MockResultSet updateCount1(java.lang.Integer index)
          Returns a update count of 1.
 com.mockrunner.mock.jdbc.MockResultSet updateCount2(java.lang.Integer index)
          Returns a update count of 2.
 com.mockrunner.mock.jdbc.MockResultSet updateCountExecuteFailed(java.lang.Integer index)
          Returns an update count of Statement.EXECUTE_FAILED.
 com.mockrunner.mock.jdbc.MockResultSet voidReturnAndNoResultSet(java.lang.Integer index)
          Returns no return code and no resultset.
 com.mockrunner.mock.jdbc.MockResultSet xmlResultSet(java.lang.Integer index)
          Returns a canned XML string from an included file.
 
Methods inherited from class net.sourceforge.sqlunit.test.mock.AbstractMockDatabase
getResultSet, getResultSet
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SQLUnitMockDatabase

public SQLUnitMockDatabase()
Method Detail

aSimpleResult

public final com.mockrunner.mock.jdbc.MockResultSet aSimpleResult(java.lang.Integer index)
A simple method returning a single resultset with a single int column.

Parameters:
index - the result set id.
Returns:
a single MockResult with a single row and single column.

anotherSimpleResult

public final com.mockrunner.mock.jdbc.MockResultSet anotherSimpleResult(java.lang.Integer index)
A simple method returning a single resultset with a single int column.

Parameters:
index - the result set id.
Returns:
a single MockResult with a single row and single column.

anotherInResultSet

public final com.mockrunner.mock.jdbc.MockResultSet anotherInResultSet(java.lang.Integer index)
A method that returns the string "another" as a single column in a single row in a single resultset.

Parameters:
index - the result set id.
Returns:
a single MockResultSet with single row and single column.

aSimpleNullResult

public final com.mockrunner.mock.jdbc.MockResultSet aSimpleNullResult(java.lang.Integer index)
A simple method returning a single resultset with a single int column which contains a NULL.

Parameters:
index - the result set id.
Returns:
a single MockResult with a single row and single column.

aSimpleStringResult

public final com.mockrunner.mock.jdbc.MockResultSet aSimpleStringResult(java.lang.Integer index)
Returns a MockResult with a single row and a single column named 'foo' containing the String value 'foo'.

Parameters:
index - the result set id.
Returns:
a single MockResult with a single row and single column.

aSimpleMultiColResult

public final com.mockrunner.mock.jdbc.MockResultSet aSimpleMultiColResult(java.lang.Integer index)
Returns a single resultset with multiple columns in each row. This is used to test the functionality of the assert-resultset-equals assertion.

Parameters:
index - the result set id.
Returns:
a single MockResult with two rows and three columns.

multipleResults

public final com.mockrunner.mock.jdbc.MockResultSet multipleResults(java.lang.Integer index)
A method returning multiple result sets. Each call returns a single result set, but different values of index will return different result sets. Mimics a stored procedure call with multiple result sets returned, such as found in Sybase T-SQL.

Parameters:
index - the result set id.
Returns:
a single MockResultSet per index call.

anotherMultipleResultsDifferentTypes

public final com.mockrunner.mock.jdbc.MockResultSet anotherMultipleResultsDifferentTypes(java.lang.Integer index)
Another method returning multiple result sets. This is similar to the multipleResults() call, but returns different datatypes than that one.

Parameters:
index - the result set id.
Returns:
a single MockResultSet per index call.

simpleReturnCode

public final com.mockrunner.mock.jdbc.MockResultSet simpleReturnCode(java.lang.Integer index)
A method returning a return code only.

Parameters:
index - the result set id.
Returns:
a MockResult.

exceptionResult

public final com.mockrunner.mock.jdbc.MockResultSet exceptionResult(java.lang.Integer index)
A method that is designed to throw an SQLException. Since the framework does not allow us to throw an SQLException directly, we will wrap this in a ResultSet with type = Integer.MAX_INT.

Parameters:
index - the result set id.
Returns:
a MockResultSet at index 1 containing an embedded SQLException.

refCursorReturn

public final com.mockrunner.mock.jdbc.MockResultSet refCursorReturn(java.lang.Integer index)
Returns an Oracle style REF CURSOR in the first outparam element.

Parameters:
index - the result set id.
Returns:
a MockResultSet at the specified index.

resultAndOneResultSet

public final com.mockrunner.mock.jdbc.MockResultSet resultAndOneResultSet(java.lang.Integer index)
Returns a result code and a single resultset.

Parameters:
index - the result set id.
Returns:
a MockResultSet at the specified index.

voidReturnAndNoResultSet

public final com.mockrunner.mock.jdbc.MockResultSet voidReturnAndNoResultSet(java.lang.Integer index)
Returns no return code and no resultset.

Parameters:
index - the result set id.
Returns:
a MockResultSet at the specified index.

resultAndException

public final com.mockrunner.mock.jdbc.MockResultSet resultAndException(java.lang.Integer index)
Returns the result code and the exception. This models the case in Sybase ASA where T-SQL allows you to continue and throw a return code even after an exception is raised.

Parameters:
index - the result set id.
Returns:
a MockResultSet at the specified index.

resultAndMultilineException

public final com.mockrunner.mock.jdbc.MockResultSet resultAndMultilineException(java.lang.Integer index)
Returns an error code and a multi-line exception message. This is used to test cases such as Sybase ASA which may return a trailing newline.

Parameters:
index - the result set id.
Returns:
a MockResultSet at the specified index.

updateCount1

public final com.mockrunner.mock.jdbc.MockResultSet updateCount1(java.lang.Integer index)
Returns a update count of 1.

Parameters:
index - the result set id.
Returns:
a MockResultSet at the specified index.

updateCount2

public final com.mockrunner.mock.jdbc.MockResultSet updateCount2(java.lang.Integer index)
Returns a update count of 2.

Parameters:
index - the result set id.
Returns:
a MockResultSet at the specified index.

updateCountExecuteFailed

public final com.mockrunner.mock.jdbc.MockResultSet updateCountExecuteFailed(java.lang.Integer index)
Returns an update count of Statement.EXECUTE_FAILED.

Parameters:
index - the result set id.
Returns:
a MockResultSet with an embedded updatecount.

bytesInResultSet

public final com.mockrunner.mock.jdbc.MockResultSet bytesInResultSet(java.lang.Integer index)
Returns a Java object in a single result set.

Parameters:
index - the result set id.
Returns:
a MockResultSet with an embedded Java object.

lobInResultSet

public final com.mockrunner.mock.jdbc.MockResultSet lobInResultSet(java.lang.Integer index)
Returns an inputstream in a single result set.

Parameters:
index - the result set id.
Returns:
a MockResultSet with an embedded InputStream.

xmlResultSet

public final com.mockrunner.mock.jdbc.MockResultSet xmlResultSet(java.lang.Integer index)
Returns a canned XML string from an included file. The test for this is to compare the XML returned from the method with that in the included file.

Parameters:
index - the result set id.
Returns:
a MockResultSet object.

clobResult

public final com.mockrunner.mock.jdbc.MockResultSet clobResult(java.lang.Integer index)
Returns a CLOB datatype from the same canned XML file as the method above, but specifies this as a CLOB data type.

Parameters:
index - the result set id.
Returns:
a MockResultSet object.

blobResult

public final com.mockrunner.mock.jdbc.MockResultSet blobResult(java.lang.Integer index)
Returns a BLOB datatype which is the contents of SQLUnit.class.

Parameters:
index - the resultset id.
Returns:
a MockResultSet.

javaObjectResult

public final com.mockrunner.mock.jdbc.MockResultSet javaObjectResult(java.lang.Integer index)
Returns a JAVA_OBJECT which is the same as that serialized in Dictionary.

Parameters:
index - the result set id.
Returns:
a ResultSet.

deleteRows

public final com.mockrunner.mock.jdbc.MockResultSet deleteRows(java.lang.Integer index)
Method to test the foreach tag. This method is meant to be used with the insert[12]Row() and returnCountOfRows() methods. Side effect of this method is to zero out the static variable foreachUpdateCount.

Parameters:
index - the result set id.
Returns:
an update count.

insert1Row

public final com.mockrunner.mock.jdbc.MockResultSet insert1Row(java.lang.Integer index)
Method to test the foreach tag. This method is meant to be used with the deleteRows(), insert2Row() and returnCountOfRowsInserted() methods.

Parameters:
index - the result set id.
Returns:
an updatecount.

insert2Row

public final com.mockrunner.mock.jdbc.MockResultSet insert2Row(java.lang.Integer index)
Method to test the foreach tag. This method is meant to be used with the deleteRows(), insert1Row() and returnCountOfRowsInserted() methods.

Parameters:
index - the result set id.
Returns:
an updatecount.

returnCountOfRowsInserted

public final com.mockrunner.mock.jdbc.MockResultSet returnCountOfRowsInserted(java.lang.Integer index)
Method to test the foreach tag. This method is meant to be used with the deleteRows(), insert1Row() and insert2Row() methods.

Parameters:
index - the result set id.
Returns:
a count of the number of rows inserted.

superHeroesSortedNaturally

public final com.mockrunner.mock.jdbc.MockResultSet superHeroesSortedNaturally(java.lang.Integer index)
Returns a resultset which is sorted "naturally", ie by ascending order of columns as they appear in the resultset.

Parameters:
index - the result set id.
Returns:
a resultset.

superHeroesSortedByAliasAndName

public final com.mockrunner.mock.jdbc.MockResultSet superHeroesSortedByAliasAndName(java.lang.Integer index)
Same as superHeroesSortedNaturally() but rows are returned sorted by last name (lname).

Parameters:
index - the result set id.
Returns:
a resultset.

superHeroesSortedByAlias

public final com.mockrunner.mock.jdbc.MockResultSet superHeroesSortedByAlias(java.lang.Integer index)
Same as superHeroesSortedNaturally() but rows are returned sorted by alias.

Parameters:
index - the result set id.
Returns:
a result set.

superHeroesSortedByAliasDesc

public final com.mockrunner.mock.jdbc.MockResultSet superHeroesSortedByAliasDesc(java.lang.Integer index)
Same as superHeroesSortedNaturally() but rows are returned sorted descending by alias.

Parameters:
index - the result set id.
Returns:
a result set.

returnNumericAndDecimalInResultSet

public final com.mockrunner.mock.jdbc.MockResultSet returnNumericAndDecimalInResultSet(java.lang.Integer index)
Returns a single row with 2 columns, one NUMERIC and one DECIMAL.

Parameters:
index - the result set id.
Returns:
a result set.

returnNumericOutParam

public final com.mockrunner.mock.jdbc.MockResultSet returnNumericOutParam(java.lang.Integer index)
Returns a NUMERIC in an OUT Param.

Parameters:
index - the result set id.
Returns:
the result set.

incrementNumericAndReturn

public final com.mockrunner.mock.jdbc.MockResultSet incrementNumericAndReturn(java.lang.Integer index)
Returns a canned NUMERIC value in an INOUT Param. The INOUT param will always contain 300.01 when it is returned from this method.

Parameters:
index - the result set id.
Returns:
the result set.

returnDecimalOutParam

public final com.mockrunner.mock.jdbc.MockResultSet returnDecimalOutParam(java.lang.Integer index)
Same as returnNumericOutParam since underlying datatype is BigDecimal in both cases, and the scalar is built based on actual datatype.

Parameters:
index - the result set id.
Returns:
the result set.

incrementDecimalAndReturn

public final com.mockrunner.mock.jdbc.MockResultSet incrementDecimalAndReturn(java.lang.Integer index)
Same as incrementNumericAndReturn1 since the underlying datatype is BigDecimal in both cases, and the scalar is built based on actual datatype.

Parameters:
index - the result set id.
Returns:
the result set.

selectDatabase

public final com.mockrunner.mock.jdbc.MockResultSet selectDatabase(java.lang.Integer index)
Takes no parameters and returns the name of the database. Used in testing the functionality of the func tag.

Parameters:
index - the result set id.
Returns:
the result set.