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)

Variable Index

 o currentRefStruct_
 o lastRefReturn_
 o NO_LOCATION
 o opts_
 o parser_
 o testStructure_
 o WAIT_TIME

Constructor Index

 o GenericTester(Factory, StructureComparator)

Method Index

 o assert(String)
Checks to see if the set of tests given by name succeeded.
 o autoRefCheck(String, String)
enables automatic checking of reference structure to the test structure.
 o comparator()
Returns the StructureComparator
 o container()
Returns the current Container on which this Tester is operating.
 o currentMethodName()
returns the name of the current method as a string
 o dieOnAssertFailure(boolean)
Whether or not to cancel the tests on assertion failure.
 o disableAutoRefCheck()
Disables autoRefCheck
 o disableError()
Disables the automatic printing of error if an error occurs.
 o disableNoException()
Disables handling of an expected exception not being thrown.
 o disableRefStructure()
This disables the reference structure, so it won't be operated on
 o disableReturnFail()
Disables handling of an incorrect return.
 o disableStackTrace()
Disables the printing of the stack trace when an unexpected exception is thrown.
 o disableUnexpectedException()
Disables handling of an unexpected exception.
 o enableDefaultErrorHandling()
This enables all error handling and sets messages to their default values
 o enablePrintStackTrace(PrintStream)
Enables the printing of the stack trace when an unexpected exception is thrown.
 o enablePrintStackTrace(PrintWriter)
Enables the printing of the stack trace when an unexpected exception is thrown.
 o endTests()
Ends a set of tests.
 o equals(Enumeration)
Compares the current container to an enumeration.
 o equals(String)
Compares the current container to an string.
 o exceptionCatcher(Throwable)
If default exception handling is turned off, the thrown exception will be sent here.
 o exceptionThrower(Throwable)
The following two methods are used so that test writer can override default exception handling in the subclass of GenericTester.
 o execute(String, String)
Executes a method on the last data structure created.
 o execute(String, String, String, int)
Executes a method on a data structure.
 o execute(String, String, String, int, int)
Executes a method on a single data structure.
 o executeCheckException(String, String, String)
Executes a method with the intent of causing an exception to be raised.
 o executeCheckException(String, String, String, String, int)
Executes a method with the intent of causing an exception to be raised.
 o executeCheckException(String, String, String, String, int, int)
Executes a method with the intent of causing an exception to be raised.
 o executeCheckReturn(String, String, String)
Executes a method and checks its return type.
 o executeCheckReturn(String, String, String, String, int)
Executes a method and checks its return type.
 o executeCheckReturn(String, String, String, String, int, int)
Executes a method and checks its return type.
 o executeOnAll(String, String)
This version executes given method on all the structures last created by the factory
 o executeOnAll(String, String, int, int)
This version executes the given method on all the structures created by the factory
 o 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.
 o factory()
Returns the factory.
 o getAnswer()
This method returns the last string passed in as an answer or as an exception
 o getExecuteTime()
Gets the execution time in milliseconds of the last method invocation.
 o getImportPath()
Gets the default class paths
 o getLocation()
This method returns an object representing the last location generated by the factory, if one was indeed made.
 o getLocations()
This method returns an array of locations made in the last call to generate.
 o getParameter(int)
This method gets the parameters at a given index and wraps them in a new TesterArrays
 o getStructure()
This method returns the last structure created by the factory
 o getStructures()
This method returns an array of objects which are all the structures made in the last call to generate on the factory.
 o importPath(String)
Sets the default class path for objects in this test
 o locationName(int)
This method returns the string name of a location given its index.
 o out(boolean)
If nu is false output is shut off.
 o out(boolean, String)
 o printError(PrintStream)
Enables the printing of the return from error automatically if an error occurs.
 o printError(PrintWriter)
Enables the printing of the return from error automatically if an error occurs.
 o recentReturn()
Returns the return value of the most recent execute call.
 o 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
 o setBaseParameter(Object, int)
Sets a parameter that can be passed in during a call to an execute method.
 o setBaseParameter(String, int)
Sets a parameter that can be passed in during a call to an execute method.
 o setNoException(String, PrintStream)
Sets the error message if executeCheckException does not throw the expected exception.
 o setNoException(String, PrintWriter)
Sets the error message if executeCheckException does not throw the expected exception.
 o 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.
 o setParameter(Object, int)
Sets a parameter that can be passed in during a call to an execute method.
 o setParameter(String, int)
Sets a parameter that can be passed in during a call to an execute method.
 o 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.
 o setReturnFail(String, String, PrintStream)
Sets the error message if the return of the executed method doesn't match the specified return.
 o setReturnFail(String, String, PrintWriter)
Sets the error message if the return of the executed method doesn't match the specified return.
 o setTestInfo(boolean)
Enable or disable the tester to print test info
 o setUnexpectedException(String, PrintStream)
Sets the error message if any of the execute methods throws an unexpected exception.
 o setUnexpectedException(String, PrintWriter)
Sets the error message if any of the execute methods throws an unexpected exception.
 o startTests(String)
Declares a set of tests.
 o structName(int)
This method returns the string name of a structure indicated by the given index.
 o testSuccess(boolean)
Sets the success or failure of the current set of tests.
 o toArray(String)
Parses a string into an array.

Variables

 o NO_LOCATION
 public static int NO_LOCATION
 o parser_
 protected TesterStringParser parser_
 o testStructure_
 protected TestStructure testStructure_
 o currentRefStruct_
 protected TestStructure currentRefStruct_
 o lastRefReturn_
 protected Object lastRefReturn_
 o opts_
 protected TesterGetOpts opts_
 o WAIT_TIME
 public static int WAIT_TIME

Constructors

 o GenericTester
 public GenericTester(Factory factory,
                      StructureComparator comparator)

Methods

 o recentReturn
 public final TesterArrays recentReturn()
Returns the return value of the most recent execute call.

 o factory
 public final Factory factory()
Returns the factory.

Returns:
the factory
 o comparator
 public final StructureComparator comparator()
Returns the StructureComparator

Returns:
the StructureComparator
 o container
 public final Object container()
Returns the current Container on which this Tester is operating.

Returns:
the current Container.
 o 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
 o 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.
 o 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
 o 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
 o 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
 o 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
 o 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
 o 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
 o 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
 o 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
 o 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
 o 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.
 o 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.
 o enableDefaultErrorHandling
 public void enableDefaultErrorHandling()
This enables all error handling and sets messages to their default values

 o setReturnFail
 public void setReturnFail(String msg,
                           String message,
                           PrintStream stream)
Sets the error message if the return of the executed 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.
 o setReturnFail
 public void setReturnFail(String msg,
                           String message,
                           PrintWriter stream)
Sets the error message if the return of the executed 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.
 o 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.
 o 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.
 o 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.
 o 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.
 o disableReturnFail
 public void disableReturnFail()
Disables handling of an incorrect return.

 o disableUnexpectedException
 public void disableUnexpectedException()
Disables handling of an unexpected exception.

 o disableNoException
 public void disableNoException()
Disables handling of an expected exception not being thrown.

 o 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
 o 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.
 o 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
 o 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.
 o 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.
 o 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.
 o disableError
 public void disableError()
Disables the automatic printing of error if an error occurs.

 o 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.
 o 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.
 o disableStackTrace
 public void disableStackTrace()
Disables the printing of the stack trace when an unexpected exception is thrown.

 o 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.
 o disableAutoRefCheck
 public void disableAutoRefCheck()
Disables autoRefCheck

 o setTestInfo
 public void setTestInfo(boolean toSet)
Enable or disable the tester to print test info

 o 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.
 o endTests
 public void endTests()
Ends a set of tests. Will be used for assertions.

 o 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.
 o 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
 o 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.
 o importPath
 public void importPath(String path)
Sets the default class path for objects in this test

Parameters:
path - a string to be parsed
 o getImportPath
 public String[] getImportPath()
Gets the default class paths

Returns:
a string array of the class paths
 o 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
 o getStructure
 public Object getStructure()
This method returns the last structure created by the factory

Returns:
the structure
 o 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
 o 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
 o 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
 o 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
 o 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
 o out
 protected void out(boolean nu)
If nu is false output is shut off. Otherwise it is on.

 o out
 protected void out(boolean toCheck,
                    String toPrint)
 o currentMethodName
 public String currentMethodName()
returns the name of the current method as a string

 o 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
 o 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
 o 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.
 o disableRefStructure
 public void disableRefStructure()
This disables the reference structure, so it won't be operated on

 o 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
 o 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
 o 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
 o 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
 o 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
 o 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