org.jtestcase
Class JTestCase

java.lang.Object
  extended by org.jtestcase.JTestCase

public class JTestCase
extends java.lang.Object

This utility class is used for unit test to help reading data (test cases) from xml file.

Author:
Fausto Lelli, Yuqing Wang, Christian Koelle $Id: JTestCase.java,v 1.14 2005/10/19 19:11:29 faustothegrey Exp $

Constructor Summary
JTestCase(java.lang.String fileName, java.lang.String className)
          Constructed from full file name and class name.
 
Method Summary
 Asserter getAsserter()
           
 java.lang.String getClassUnderTest()
          Returns the class name used to find the class tags in XML
 java.util.Hashtable getControlParams()
          Retrieves all control parameters.
 int getCountOfTestCasesInMethod(java.lang.String methodName)
          Get number of test cases for a given method.
 JTestCaseDigester getDigester()
           
 java.util.Locale getGlobalParamLocale()
          Helps setting the Locale for DateFormats
 java.util.Hashtable getGlobalParams()
          Retrieves all global (class-wide) params into Hashtable.
 HashMapper getMapper()
           
 java.lang.String getMClassName()
           
 java.util.Vector getTestCasesInstancesInMethod(java.lang.String methodName)
          Get all test cases' name for a given method into Vector.
 ComplexTypeConverter getTypeConverter()
           
 void setAsserter(Asserter asserter)
           
 void setMapper(HashMapper mapper)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JTestCase

public JTestCase(java.lang.String fileName,
                 java.lang.String className)
          throws JTestCaseException,
                 java.io.FileNotFoundException
Constructed from full file name and class name. This class name is specifed in data file under "/tests/class@name". It's recommended that its value equals to the real testing class's name.
JTestCase looks for data files in following orders: 1) looks from filesystem path. For example, if you specified XML file as "/aa/bb/my-data.xml", then JTestCase will look for /aa/bb/my-data.xml from your filesystem directory.
2) if JTestCase fails above search, it then looks from $CLASSPATH based directories. For example, if you have classpathroot/myclass/my-data.xml in your CLASSPATH, you can retrieve the XML file using "myclass/my-date.xml". 3) If fails again, JTestCase will then throw FileNotFoundException exception.
(Note: providing filesystem path will improve the performance).

Parameters:
fileName - - name of data file. Will be searched by absolute path first. If not found, then will be searched based on classpath.
className - - name of test program. Is defined in data file in /tests/class@name
Throws:
JTestCaseException - Problem with reading the file, validating the XML or with the XML structure
java.io.FileNotFoundException - Thrown if the fileName (xml data file) in not found
Method Detail

getAsserter

public Asserter getAsserter()

setAsserter

public void setAsserter(Asserter asserter)

getMapper

public HashMapper getMapper()

setMapper

public void setMapper(HashMapper mapper)

getDigester

public JTestCaseDigester getDigester()

getTypeConverter

public ComplexTypeConverter getTypeConverter()

getMClassName

public java.lang.String getMClassName()

getControlParams

public java.util.Hashtable getControlParams()
                                     throws JTestCaseException,
                                            java.io.FileNotFoundException
Retrieves all control parameters. Control parameters are parameters that are defined for the whole JTestCase data set. They are valid for all class-tags in the file.

Returns:
A hashtable with the control parameters. Key is defined in /tests/params/param@name, value is param's object value with type as indicated in /test/class/params/param@type. If "type" is not specified in data file, then "String" is default type.
Throws:
java.io.FileNotFoundException - in case the file in not found
JTestCaseException - in case of any other error

getGlobalParams

public java.util.Hashtable getGlobalParams()
                                    throws JTestCaseException,
                                           java.io.FileNotFoundException,
                                           java.lang.InstantiationException,
                                           java.lang.IllegalAccessException
Retrieves all global (class-wide) params into Hashtable. HashKey is param's name, HashValue is param's value. These params are common to all tested methods for the specified tested class, and should be retrieved in testing class's constructor.

Returns:
Hashtable. Key is param's name defined in /tests/class/params/param@name, value is param's Object value with type as indicated in /test/class/params/param@type. If not "type" specified in data file, then "String" is default type.
Throws:
JTestCaseException - if an internal error occurs
java.io.FileNotFoundException
java.lang.IllegalAccessException
java.lang.InstantiationException

getGlobalParamLocale

public java.util.Locale getGlobalParamLocale()
                                      throws JTestCaseException,
                                             java.io.FileNotFoundException
Helps setting the Locale for DateFormats

Returns:
the Locale as specified in the global Parameter named 'locale'
Throws:
JTestCaseException
java.io.FileNotFoundException

getCountOfTestCasesInMethod

public int getCountOfTestCasesInMethod(java.lang.String methodName)
                                throws JTestCaseException
Get number of test cases for a given method. This method name is specified in data file in /tests/class/method@name. It's recommended that its value equals to the real testing method's name.

Parameters:
methodName - - name of tested method. Defined in data file in /tests/class/method@name.
Returns:
int. Number of test cases that are defined for this method in data file.
Throws:
JTestCaseException - if an internal error occurs

getTestCasesInstancesInMethod

public java.util.Vector getTestCasesInstancesInMethod(java.lang.String methodName)
                                               throws JTestCaseException
Get all test cases' name for a given method into Vector. This method requires that for a given method, each test case should be named uniquely.

Parameters:
methodName - - name of tested method. Defined in data file in /tests/class/method@test-case.
Returns:
Vector of names of test cases that are defined for this method in data file in /tests/class/method@test-case.
Throws:
JTestCaseException - if an internal error occurs

getClassUnderTest

public java.lang.String getClassUnderTest()
Returns the class name used to find the class tags in XML

Returns:
the class name