All Packages Class Hierarchy This Package Previous Next Index
Class jdsltools.testers.GenericTester
java.lang.Object
|
+----jdsltools.testers.GenericTester
- public class GenericTester
- extends Object
A generic tester which allows testing of data structures easily and
quickly.
- Author:
- Marco da Silva(mds) and Michael Boilen(mgb)
-
currentRefStruct_
-
-
lastRefReturn_
-
-
NO_LOCATION
-
-
opts_
-
-
parser_
-
-
testStructure_
-
-
WAIT_TIME
-
-
GenericTester(Factory, StructureComparator)
-
-
assert(String)
- Checks to see if the set of tests given by
name
succeeded.
-
autoRefCheck(String, String)
-
enables automatic checking of reference structure to the test
structure.
-
comparator()
- Returns the
StructureComparator
-
container()
- Returns the current
Container
on which this Tester is
operating.
-
currentMethodName()
- returns the name of the current method as a string
-
dieOnAssertFailure(boolean)
- Whether or not to cancel the tests on assertion failure.
-
disableAutoRefCheck()
- Disables autoRefCheck
-
disableError()
- Disables the automatic printing of
error
if an error
occurs.
-
disableNoException()
- Disables handling of an expected exception not being thrown.
-
disableRefStructure()
- This disables the reference structure, so it won't be operated on
-
disableReturnFail()
- Disables handling of an incorrect return.
-
disableStackTrace()
- Disables the printing of the stack trace when an unexpected exception
is thrown.
-
disableUnexpectedException()
- Disables handling of an unexpected exception.
-
enableDefaultErrorHandling()
- This enables all error handling and sets messages to their default values
-
enablePrintStackTrace(PrintStream)
- Enables the printing of the stack trace when an unexpected exception is
thrown.
-
enablePrintStackTrace(PrintWriter)
- Enables the printing of the stack trace when an unexpected exception is
thrown.
-
endTests()
- Ends a set of tests.
-
equals(Enumeration)
- Compares the current container to an enumeration.
-
equals(String)
- Compares the current container to an string.
-
exceptionCatcher(Throwable)
- If default exception handling is turned off, the thrown exception will
be sent here.
-
exceptionThrower(Throwable)
- The following two methods are used so that test writer can override
default exception handling in the subclass of GenericTester.
-
execute(String, String)
- Executes a method on the last data structure created.
-
execute(String, String, String, int)
- Executes a method on a data structure.
-
execute(String, String, String, int, int)
- Executes a method on a single data structure.
-
executeCheckException(String, String, String)
- Executes a method with the intent of causing an exception to be raised.
-
executeCheckException(String, String, String, String, int)
- Executes a method with the intent of causing an exception to be raised.
-
executeCheckException(String, String, String, String, int, int)
- Executes a method with the intent of causing an exception to be raised.
-
executeCheckReturn(String, String, String)
- Executes a method and checks its return type.
-
executeCheckReturn(String, String, String, String, int)
- Executes a method and checks its return type.
-
executeCheckReturn(String, String, String, String, int, int)
- Executes a method and checks its return type.
-
executeOnAll(String, String)
- This version executes given method on all the structures last created by
the factory
-
executeOnAll(String, String, int, int)
- This version executes the given method on all the structures created by
the factory
-
exeOnMultiple(String, String, String)
- This method takes a string of paired numbers, parses to pairs of ints
and calls execute on all structures, and returns their returns as
an array of objects.
-
factory()
- Returns the factory.
-
getAnswer()
- This method returns the last string passed in as an answer or as
an exception
-
getExecuteTime()
- Gets the execution time in milliseconds of the last method invocation.
-
getImportPath()
- Gets the default class paths
-
getLocation()
- This method returns an object representing the last location
generated by the factory, if one was indeed made.
-
getLocations()
- This method returns an array of locations made in the last call to
generate.
-
getParameter(int)
- This method gets the parameters at a given index and wraps them
in a new TesterArrays
-
getStructure()
- This method returns the last structure created by the factory
-
getStructures()
- This method returns an array of objects which are all the structures
made in the last call to generate on the factory.
-
importPath(String)
- Sets the default class path for objects in this test
-
locationName(int)
- This method returns the string name of a location given its index.
-
out(boolean)
- If nu is false output is shut off.
-
out(boolean, String)
-
-
printError(PrintStream)
- Enables the printing of the return from
error
automatically if an error occurs.
-
printError(PrintWriter)
- Enables the printing of the return from
error
automatically if an error occurs.
-
recentReturn()
- Returns the return value of the most recent
execute
call.
-
refStructEnum()
- Overriding method in subclass will allow writer of test to pass an
enumeration generated from the reference to equals(Enumeration)
in order to compare current structure to reference structure
-
setBaseParameter(Object, int)
- Sets a parameter that can be passed in during a call to an
execute
method.
-
setBaseParameter(String, int)
- Sets a parameter that can be passed in during a call to an
execute
method.
-
setNoException(String, PrintStream)
- Sets the error message if
executeCheckException
does not
throw the expected exception.
-
setNoException(String, PrintWriter)
- Sets the error message if
executeCheckException
does not
throw the expected exception.
-
setOptions(String[], String)
- This method allows the user to set the TesterGetOpts object
The TesterGetOpts gets command line options and sets variables based
on those options.
-
setParameter(Object, int)
- Sets a parameter that can be passed in during a call to an
execute
method.
-
setParameter(String, int)
- Sets a parameter that can be passed in during a call to an
execute
method.
-
setRefFactory(Factory)
- This sets the reference factory to ref and sets the flag
to use a reference structure to true, so that reference structures
will be operated on.
-
setReturnFail(String, String, PrintStream)
- Sets the error message if the return of the
execute
d
method doesn't match the specified return.
-
setReturnFail(String, String, PrintWriter)
- Sets the error message if the return of the
execute
d
method doesn't match the specified return.
-
setTestInfo(boolean)
- Enable or disable the tester to print test info
-
setUnexpectedException(String, PrintStream)
- Sets the error message if any of the
execute
methods
throws an unexpected exception.
-
setUnexpectedException(String, PrintWriter)
- Sets the error message if any of the
execute
methods
throws an unexpected exception.
-
startTests(String)
- Declares a set of tests.
-
structName(int)
- This method returns the string name of a structure indicated by the
given index.
-
testSuccess(boolean)
- Sets the success or failure of the current set of tests.
-
toArray(String)
- Parses a string into an array.
NO_LOCATION
public static int NO_LOCATION
parser_
protected TesterStringParser parser_
testStructure_
protected TestStructure testStructure_
currentRefStruct_
protected TestStructure currentRefStruct_
lastRefReturn_
protected Object lastRefReturn_
opts_
protected TesterGetOpts opts_
WAIT_TIME
public static int WAIT_TIME
GenericTester
public GenericTester(Factory factory,
StructureComparator comparator)
recentReturn
public final TesterArrays recentReturn()
- Returns the return value of the most recent
execute
call.
factory
public final Factory factory()
- Returns the factory.
- Returns:
- the factory
comparator
public final StructureComparator comparator()
- Returns the
StructureComparator
- Returns:
- the
StructureComparator
container
public final Object container()
- Returns the current
Container
on which this Tester is
operating.
- Returns:
- the current
Container
.
getAnswer
public final String getAnswer()
- This method returns the last string passed in as an answer or as
an exception
- Returns:
- The answer or exception string
toArray
public Object[] toArray(String string)
- Parses a string into an array. The string can contain either a comma
separated sequence of primitive types, or a comma separated sequence of
fully qualified class names and the parameters to pass into the
constructor of that class in parentheses. For example:
"3,4,true,jdsl.core.api.Locator(3 5),3.2"
"true,false,false,3,jdsl.core.api.Locator(String(\"foo\"),4)"
No distinction will be made between primitive types and their wrapper
classes.
- Parameters:
- string - The string to be converted
- Returns:
- an Object array equivalent to the string passed in.
execute
public Object execute(String struct,
String method,
String parameters,
int structure,
int location)
- Executes a method on a single data structure.
- Parameters:
- struct - the string name of the structure to operate on
- method - the string name of the method to execute
- parameters - a string representing the parameter list.
- structure - the key for the structure on which to execute this
method.
- location - the key for the location on which to execute this
method.
- Returns:
- the return of the invoked method.
- See Also:
- Factory
execute
public Object execute(String struct,
String method,
String parameters,
int structure)
- Executes a method on a data structure.
- Parameters:
- struct - the name of the structure to operate on
- method - the string name of the method to execute
- parameters - a string representing the parameter list.
- structure - the key for the structure on which to execute this
method.
- Returns:
- the return of the invoked method.
- See Also:
- Factory
execute
public Object execute(String method,
String parameters)
- Executes a method on the last data structure created.
NOTE: Can only be called if only one data structure was created.
- Parameters:
- method - the string name of the method to execute
- parameters - a string representing the parameter list.
- Returns:
- the return of the invoked method.
- See Also:
- Factory
executeCheckException
public boolean executeCheckException(String struct,
String method,
String parameters,
String exception,
int structure,
int location)
- Executes a method with the intent of causing an exception to be raised.
Works similar to execute, except that the circumstances of the method's
invocation are such that an exception is expected to be raised. If the
expected exception is thrown, then the method will return true. If no
exception is thrown, it will return false.
- Parameters:
- struct - the name of the structure to operate on
- method - the string name of the method to execute
- parameters - a string representing the parameter list.
- exception - A string equal to the fully qualified name of the
expected exception
- structure - the key for the structure on which to execute this
method.
- location - the key for the location on which to execute this
method.
- Returns:
- true if the exception was thrown, false if no exception was
thrown.
- See Also:
- Factory, execute
executeCheckException
public boolean executeCheckException(String struct,
String method,
String parameters,
String exception,
int structure)
- Executes a method with the intent of causing an exception to be raised.
Works similar to execute, except that the circumstances of the method's
invocation are such that an exception is expected to be raised. If the
expected exception is thrown, then the method will return true. If no
exception is thrown, it will return false.
- Parameters:
- struct - the name of the structure to operate on
- method - the string name of the method to execute
- parameters - a string representing the parameter list.
- exception - A string equal to the fully qualified name of the
expected exception
- structure - the key for the structure on which to execute this
method.
- Returns:
- true if the exception was thrown, false if no exception was
thrown
- See Also:
- Factory, execute
executeCheckException
public boolean executeCheckException(String method,
String parameters,
String exception)
- Executes a method with the intent of causing an exception to be raised.
Works similar to execute, except that the circumstances of the method's
invocation are such that an exception is expected to be raised. If the
expected exception is thrown, then the method will return true. If no
exception is thrown, it will return false.
NOTE: Can only be called if only one data structure was created.
- Parameters:
- method - the string name of the method to execute
- parameters - a string representing the parameter list.
- exception - A string equal to the fully qualified name of the
expected exception
- Returns:
- true if the exception was thrown, false if no exception was
thrown
- See Also:
- Factory, execute
executeCheckReturn
public boolean executeCheckReturn(String struct,
String method,
String parameters,
String answer,
int structure,
int location)
- Executes a method and checks its return type. Works similar to execute,
except that rather than returning the return from the method, it checks
it against a given value. If the method returns the expected value, then
the method will return true.
- Parameters:
- struct - the name of the structure to operate on
- method - the string name of the method to execute
- parameters - a string representing the parameter list.
- answer - A string representing the expected return value.
- structure - the key for the structure on which to execute this
method.
- location - the key for the location on which to execute this
method.
- Returns:
- true if the returned object matched the object formed by
parsing answer.
- See Also:
- Factory, execute
executeCheckReturn
public boolean executeCheckReturn(String struct,
String method,
String parameters,
String answer,
int structure)
- Executes a method and checks its return type. Works similar to execute,
except that rather than returning the return from the method, it checks
it against a given value. If the method returns the expected value, then
the method will return true.
- Parameters:
- struct - the name of the structure to operate on
- method - the string name of the method to execute
- parameters - a string representing the parameter list.
- answer - A string representing the expected return value.
- structure - the key for the structure on which to execute this
method.
- Returns:
- true if the returned object matched the object formed by
parsing answer.
- See Also:
- Factory, execute
executeCheckReturn
public boolean executeCheckReturn(String method,
String parameters,
String answer)
- Executes a method and checks its return type. Works similar to execute,
except that rather than returning the return from the method, it checks
it against a given value. If the method returns the expected value, then
the method will return true.
NOTE: Can only be called if only one data structure was created.
- Parameters:
- method - the string name of the method to execute
- parameters - a string representing the parameter list.
- answer - A string representing the expected return value.
- Returns:
- true if the returned object matched the object formed by
parsing answer.
- See Also:
- Factory, execute
equals
public boolean equals(Enumeration enumeration)
- Compares the current container to an enumeration. This utilizes the
equals method of
StructureComparator
.
- Parameters:
- enumeration - an Enumeration to test against the current
container.
- Returns:
- true if the enumeration and container are compatible, false if
not.
with this
StructureComparator
.
equals
public boolean equals(String string)
- Compares the current container to an string. This utilizes the
equals method of
StructureComparator
.
- Parameters:
- string - the string to test the container against.
- Returns:
- true if the enumeration and container are compatible, false if
not.
enableDefaultErrorHandling
public void enableDefaultErrorHandling()
- This enables all error handling and sets messages to their default values
setReturnFail
public void setReturnFail(String msg,
String message,
PrintStream stream)
- Sets the error message if the return of the
execute
d
method doesn't match the specified return.
- Parameters:
- message - The message to print on failure.
- msg - The message to print on success.
- stream - the
PrintStream
to write the message to.
setReturnFail
public void setReturnFail(String msg,
String message,
PrintWriter stream)
- Sets the error message if the return of the
execute
d
method doesn't match the specified return.
- Parameters:
- message - The message to print out on failure.
- msg - The message to print on success.
- writer - the
PrintWriter
to write the message to.
setNoException
public void setNoException(String message,
PrintStream stream)
- Sets the error message if
executeCheckException
does not
throw the expected exception.
- Parameters:
- message - The message to print out
- stream - the
PrintStream
to write the message to.
setNoException
public void setNoException(String message,
PrintWriter stream)
- Sets the error message if
executeCheckException
does not
throw the expected exception.
- Parameters:
- message - The message to print out
- writer - the
PrintWriter
to write the message to.
setUnexpectedException
public void setUnexpectedException(String message,
PrintStream stream)
- Sets the error message if any of the
execute
methods
throws an unexpected exception. An ExecutionException
will not be thrown if this is enabled.
- Parameters:
- message - The message to print out
- stream - the
PrintStream
to write the message to.
setUnexpectedException
public void setUnexpectedException(String message,
PrintWriter stream)
- Sets the error message if any of the
execute
methods
throws an unexpected exception. An ExecutionException
will not be thrown if this is enabled.
- Parameters:
- message - The message to print out
- writer - the
PrintWriter
to write the message to.
disableReturnFail
public void disableReturnFail()
- Disables handling of an incorrect return.
disableUnexpectedException
public void disableUnexpectedException()
- Disables handling of an unexpected exception.
disableNoException
public void disableNoException()
- Disables handling of an expected exception not being thrown.
setParameter
public void setParameter(String parameter,
int number)
- Sets a parameter that can be passed in during a call to an
execute
method. These can be accessed with the
$PARAMETER[number] code.
- Parameters:
- parameter - The string name of the object
- number - The location of this parameter
setParameter
public void setParameter(Object parameter,
int number)
- Sets a parameter that can be passed in during a call to an
execute
method. These can be accessed with the
$PARAMETER[number] code.
- Parameters:
- parameter - The object that will become a parameter.
- number - The parameter number that this will set.
setBaseParameter
public void setBaseParameter(String parameter,
int number)
- Sets a parameter that can be passed in during a call to an
execute
method. These can be accessed with the
$PARAMETER[number] code. For a base type
- Parameters:
- parameter - The string name of the object
- number - The location of this parameter
setBaseParameter
public void setBaseParameter(Object parameter,
int number)
- Sets a parameter that can be passed in during a call to an
execute
method. This version takes a wrapped base type
rather than an arbitrary object. This must be used if the parameter is
supposed to be a base type rather that the wrapper class.
- Parameters:
- parameter - The object that will become a parameter.
- number - The parameter number that this will set.
printError
public void printError(PrintStream stream)
- Enables the printing of the return from
error
automatically if an error occurs.
- Parameters:
- stream - The
PrintStream
to print the error message
to.
printError
public void printError(PrintWriter stream)
- Enables the printing of the return from
error
automatically if an error occurs.
- Parameters:
- stream - The
PrintWriter
to print the error message
to.
disableError
public void disableError()
- Disables the automatic printing of
error
if an error
occurs.
enablePrintStackTrace
public void enablePrintStackTrace(PrintStream stream)
- Enables the printing of the stack trace when an unexpected exception is
thrown.
- Parameters:
- stream - The
PrintStream
to print the error message
to.
enablePrintStackTrace
public void enablePrintStackTrace(PrintWriter stream)
- Enables the printing of the stack trace when an unexpected exception is
thrown.
- Parameters:
- stream - The
PrintWriter
to print the error message
to.
disableStackTrace
public void disableStackTrace()
- Disables the printing of the stack trace when an unexpected exception
is thrown.
autoRefCheck
public void autoRefCheck(String message,
String mesg)
- enables automatic checking of reference structure to the test
structure. takes string which will be error message to print out
if the test structure doesn't match the reference structure.
Also, takes string that will print if the test strucuture matches
the reference structure
- Parameters:
- message - The error message to spit out on failure
- msg - The message to print on success.
disableAutoRefCheck
public void disableAutoRefCheck()
- Disables autoRefCheck
setTestInfo
public void setTestInfo(boolean toSet)
- Enable or disable the tester to print test info
startTests
public void startTests(String name)
- Declares a set of tests. Will be used for assertions. You may not nest
test sets.
- Parameters:
- name - The name for these tests.
endTests
public void endTests()
- Ends a set of tests. Will be used for assertions.
assert
public boolean assert(String name)
- Checks to see if the set of tests given by
name
succeeded.
A set of tests succeeds if all executeCheckReturn
and
executeCheckException
calls return true, and no call to
testSuccess
is ever supplied a parameter of
false
.
- Parameters:
- name - the name of the set of tests.
- Returns:
-
true
if the set of tests succeeded,
false
if the set either failed or does not exist.
dieOnAssertFailure
public void dieOnAssertFailure(boolean die)
- Whether or not to cancel the tests on assertion failure.
- Parameters:
- die - Whether or not to die if an assertion is failed
testSuccess
public void testSuccess(boolean success)
- Sets the success or failure of the current set of tests.
- Parameters:
- success - The success or failure of the current set of tests.
importPath
public void importPath(String path)
- Sets the default class path for objects in this test
- Parameters:
- path - a string to be parsed
getImportPath
public String[] getImportPath()
- Gets the default class paths
- Returns:
- a string array of the class paths
getParameter
public TesterArrays getParameter(int index)
- This method gets the parameters at a given index and wraps them
in a new TesterArrays
- Parameters:
- index - referring to the requested parameter
- Returns:
- a TesterArrays holding the parameter and its type
getStructure
public Object getStructure()
- This method returns the last structure created by the factory
- Returns:
- the structure
getStructures
public Object[] getStructures()
- This method returns an array of objects which are all the structures
made in the last call to generate on the factory. It checks to see
if multiple structures were actually made and prints an error if they
were not.
- Returns:
- the array of structures
structName
public String structName(int index)
- This method returns the string name of a structure indicated by the
given index. The structure can only be from the last group of
structures made.
- Parameters:
- index - is an integer referring to the specific structure
- Returns:
- the string name of the structure
getLocation
public Object getLocation()
- This method returns an object representing the last location
generated by the factory, if one was indeed made.
- Returns:
- an object which is the location
locationName
public String locationName(int index)
- This method returns the string name of a location given its index. The
location is assumed to be part of the last batch of locations made.
- Parameters:
- index - is an integer referring to the specific location
- Returns:
- the string name of the location
getLocations
public Object[] getLocations()
- This method returns an array of locations made in the last call to
generate. It first checks to see if multiple locations were actually
created. If not, it return null and prints out an error message.
- Returns:
- an array of objects which are locations
out
protected void out(boolean nu)
- If nu is false output is shut off. Otherwise it is on.
out
protected void out(boolean toCheck,
String toPrint)
currentMethodName
public String currentMethodName()
- returns the name of the current method as a string
exceptionThrower
protected void exceptionThrower(Throwable e) throws Throwable
- The following two methods are used so that test writer can override
default exception handling in the subclass of GenericTester.
- Parameters:
- e - a throwable
exceptionCatcher
protected void exceptionCatcher(Throwable e)
- If default exception handling is turned off, the thrown exception will
be sent here. Override this method to do something with the thrown
exception
- Parameters:
- e - a throwable
setRefFactory
public void setRefFactory(Factory ref)
- This sets the reference factory to ref and sets the flag
to use a reference structure to true, so that reference structures
will be operated on.
- Parameters:
- ref - The
Factory
that will produce the
reference structure.
disableRefStructure
public void disableRefStructure()
- This disables the reference structure, so it won't be operated on
refStructEnum
public Enumeration refStructEnum()
- Overriding method in subclass will allow writer of test to pass an
enumeration generated from the reference to equals(Enumeration)
in order to compare current structure to reference structure
- Returns:
- The
Enumeration
representing reference structure
executeOnAll
public Object[] executeOnAll(String method,
String parameters,
int structure,
int location)
- This version executes the given method on all the structures created by
the factory
- Parameters:
- method - the string name of the method to execute
- parameters - a string representing the parameter list.
- structure - the key for the structure on which to execute this
method.
- location - the key for the location on which to execute this
method
- Returns:
- the returns of the invoked method.
- See Also:
- Factory
executeOnAll
public Object[] executeOnAll(String method,
String parameters)
- This version executes given method on all the structures last created by
the factory
- Parameters:
- method - the string name of the method to execute
- parameters - a string representing the parameter list.
- structure - the key for the structure on which to execute this
method.
- location - the key for the location on which to execute this
method.
- Returns:
- the returns of the invoked method.
- See Also:
- Factory
exeOnMultiple
public Object[] exeOnMultiple(String pairs,
String method,
String parameters)
- This method takes a string of paired numbers, parses to pairs of ints
and calls execute on all structures, and returns their returns as
an array of objects.
- Parameters:
- pairs - The teststructures to run method on
- method - The method to invoke
- parameters - The parameters to send to the parameter
- Returns:
- an array of objects returned by execute
setOptions
public TesterGetOpts setOptions(String argv[],
String params)
- This method allows the user to set the TesterGetOpts object
The TesterGetOpts gets command line options and sets variables based
on those options.
- Parameters:
- argv - an array of strings representing the command line
arguments
- params - a string of all the one letter arguments
- Returns:
- The newly created TesterGetOpts
getExecuteTime
public long getExecuteTime()
- Gets the execution time in milliseconds of the last method invocation.
- Returns:
- The time as a
long
All Packages Class Hierarchy This Package Previous Next Index