Nitido Inc.

com.nitido.qabase
Class BaseTestCore

java.lang.Object
  extended by com.nitido.qabase.BaseTestCore

public abstract class BaseTestCore
extends java.lang.Object

This is the base class for a set of tests to be run in the QA environment. There are four concepts involved: TestCore, TestDriver, TestCase and TestStep.

A TestCore is an object that contains the logic of QA tests for a specific set of interfaces (or abstract implementation). Each TestCore is composed of test methods called TestCases. The method name of the TestCase methods are stored in the member variable methodNames (which is a java.util.Vector object). The QA execution code will invoke these method according to the sequence that they are stored.

A TestDriver is the first object to be invoked by the QA tests. It is responsible for setting up the environment for QA. Each TestDriver is designed for a specific implementation of certain modules. Figuratively speaking, TestDriver object "drives" one or more TestCore objects for QA testing. As a result, TestDriver object also contains the access methods for the TestCore it is designed to be executed with.

For example, the DataControl interface has different implementations, depending on the backend storage system. The LDAP-based DataControl will need a TestDriver that initialize the directory related parameter. (Note: it only set up the directory parameters, but it doesn't really connect to the server.) A hashtable-based DataControl will also has a TestDriver. However, both TestDriver will be able to use the same TestCore, which is designed for the DataControl interface instead of a specific implementation.

A TestCase is intended to encapsulate a set of test steps that requires certain setup and cleanup. The basic format of TestCase should be a big try-catch-finally block. A programmer can assume that the testing environment would return to the same state before the TestCase is executed, no matter the test succeed or failed. The TestCase may return one of the ResultStatus value. If it returns ResultStatus.FATAL, the execution will be stoped even if the methodNames vector still has more TestCase methods to be invoked.

For example, if a TestCase for a DataControl failed to contact the backend storage system, it should return ResultStatus.FATAL to stop executing the rest of TestCases.

A TestStep is a block of code within a TestCase method. It performs certain test action and check the result. If an major error occur, it would throw an exception to direct the logic to the TestCase's "finally" block (for cleaning up the TestCase).


Field Summary
protected  java.lang.String _caseId
          The _caseId String is printed out by the default header (invoked through _stepHeader) and step completion message.
protected  java.lang.String _className
          Just a quick temp store for the current runtime classname.
protected  BaseTestDriver _driver
          The test driver object that is used by the test core.
protected  java.util.Vector _methodNames
          The methodNames Vector contains all the TestCase method names.
protected  Logger _qaLogger
          The _qaLogger member variable is an instance of com.nitido.util.Logger object.
protected  java.lang.String _stepDesc
          The _stepDesc will appear as part of the error message.
protected  java.lang.String _stepId
          The _stepId String is used in the same maner as _caseId.
 
Constructor Summary
BaseTestCore(BaseTestDriver driver)
          Class constructor.
 
Method Summary
protected  void checkEitherValueFromObject(java.lang.Object exp1, java.lang.Object exp2, java.lang.Object tempObj)
          Check whether the object matches one of the epxected value.
protected  void checkEmptyArray(java.lang.Object[] array)
          Check whether the array is empty.
protected  void checkEmptyEnum(java.util.Enumeration en)
          Check whether the enumeration is empty.
protected  void checkEmptyVector(java.util.Vector vec)
          Check whether the vector is empty.
protected  void checkIntValueFromInt(int expected, int tempInt)
          Check whether an int matches the expected value.
protected  void checkNotNullFromObject(java.lang.Object tempObj)
          Check whether an object is a non-null object.
protected  void checkSingleValueFromEnum(java.lang.Object expected, java.util.Enumeration en)
          Check whether the enumeration contain only a single object, which also matches the expected value.
protected  void checkSingleValueFromObject(java.lang.Object expected, java.lang.Object tempObj)
          Check whether an object matches the expected value.
protected  void checkSingleValueFromVector(java.lang.Object expected, java.util.Vector vec)
          Check whether the vector contain only a single object, which also matches the expected value.
protected  void checkValuesFromArray(java.lang.Object[] expectedValues, int[] expectedCounts, java.lang.Object[] array)
          Check whether the array contains the expected values (and also the expected times of appearance).
protected  void checkValuesFromEnum(java.lang.Object[] expectedValues, int[] expectedCounts, java.util.Enumeration en)
          Check whether the enumeration contains the expected values (and also the expected times of appearance).
protected  void checkValuesFromVector(java.lang.Object[] expectedValues, int[] expectedCounts, java.util.Vector vec)
          Check whether the vector contains the expected values (and also the expected times of appearance).
protected static Logger getLogger(java.lang.Class categoryClass)
          This method returns a Category class used for logging QA executions.
 java.util.Enumeration getMethodNames()
          This method returns an enumeration with all the methods that are to be executed by the test driver.
 java.lang.String getProperty(java.lang.String propKey)
          Retrieves the value associated to the key from the default property section.
 java.lang.String getProperty(java.lang.String section, java.lang.String propKey)
          Retrieves the value associated to the key from the specified property section.
 java.lang.String getPropertyWithDefault(java.lang.String propKey, java.lang.String defaultValue)
          Retrieves the value associated to the key from the default property section.
 java.lang.String getPropertyWithDefault(java.lang.String section, java.lang.String propKey, java.lang.String defaultValue)
          Retrieves the value associated to the key from the specified property section.
protected  BaseTestDriver getTestDriver()
          This method returns the test driver used that runs the test cases described by this class.
protected  void handleFailureException(java.lang.Exception failEx)
          Print out the standard failure Exception message.
protected  void stepHeader(java.lang.String msg)
          Print out the Header for a step.
protected  void stepOK()
          Print out the message "case_id: step_id completed successfully".
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_driver

protected BaseTestDriver _driver
The test driver object that is used by the test core. Each test driver is designed to "drive" a certain test core implementation. As a result, the actual interface of each test driver can varies quite much. All the QA code guarantee that an instance of driver will be assigned to _driver member variable before invoking any of the TestCase methods listed in methodNames vector.

This member variable should be accessed by implementor of BaseTestCore only.


_caseId

protected java.lang.String _caseId
The _caseId String is printed out by the default header (invoked through _stepHeader) and step completion message. It is just a simple way for indicating which TestCase method is being executed. The test case methods

This member variable should be accessed by implementor of BaseTestCore only.


_stepId

protected java.lang.String _stepId
The _stepId String is used in the same maner as _caseId. This String should be set before the corresponding TestStep is executed. If error has occurred, the error message would contain the value of _stepId as an indicator of where the error has occurred.

This member variable should be accessed by implementor of BaseTestCore only.


_stepDesc

protected java.lang.String _stepDesc
The _stepDesc will appear as part of the error message. It contains a brief description of what the TestStep is doing and may also contain probable cause if the error has occurred.


_methodNames

protected java.util.Vector _methodNames
The methodNames Vector contains all the TestCase method names. The QA module will execute these TestCase in sequence.


_qaLogger

protected Logger _qaLogger
The _qaLogger member variable is an instance of com.nitido.util.Logger object. QA developers should use this object to output all debug/info/error messages.


_className

protected java.lang.String _className
Just a quick temp store for the current runtime classname.

Constructor Detail

BaseTestCore

public BaseTestCore(BaseTestDriver driver)
Class constructor.

Parameters:
driver - The test driver that executes the TestCase defined in this test core. Constructors of all child classes should always call this constructor.
Method Detail

getTestDriver

protected final BaseTestDriver getTestDriver()
This method returns the test driver used that runs the test cases described by this class.

Returns:
The test driver that executes the test cases described in this test core.

getMethodNames

public java.util.Enumeration getMethodNames()
This method returns an enumeration with all the methods that are to be executed by the test driver.

Returns:
An enumeration listing the methods names that are to be executed by the test driver
See Also:
BaseTestDriver

getLogger

protected static final Logger getLogger(java.lang.Class categoryClass)
This method returns a Category class used for logging QA executions.

Parameters:
categoryClass - The class of the new logger instance
Returns:
The Category class used to log QA executions

stepHeader

protected void stepHeader(java.lang.String msg)
Print out the Header for a step. This method can be used to print out the starting message for the step to the qa_execution log.

Parameters:
msg - The message to be printed in the header.

stepOK

protected void stepOK()
Print out the message "case_id: step_id completed successfully".


checkNotNullFromObject

protected void checkNotNullFromObject(java.lang.Object tempObj)
                               throws java.lang.Exception
Check whether an object is a non-null object.

If the object turns out to be null, an error message "case_id: step_id failed to get a non-null object." will be printed to the qa_execution log at INFO level, while the detail information of the object will be printed at DEBUG level.

Parameters:
tempObj - The object to be check.
Throws:
java.lang.Exception - Exception will be thrown if the check failed.

checkSingleValueFromObject

protected void checkSingleValueFromObject(java.lang.Object expected,
                                          java.lang.Object tempObj)
                                   throws java.lang.Exception
Check whether an object matches the expected value.

If the object doesn't matches the expected value, an error message "case_id: step_id failed to get expected value." will be printed to the qa_execution log at INFO level, while the detail information of the object will be printed at DEBUG level. The comparison is done through Object.equals().

Parameters:
expected - The expected value. This can be null object.
tempObj - The object to be check.
Throws:
java.lang.Exception - Exception will be thrown if the check failed.

checkIntValueFromInt

protected void checkIntValueFromInt(int expected,
                                    int tempInt)
                             throws java.lang.Exception
Check whether an int matches the expected value.

If the int does not match the expected value, an error message "case_id: step_id failed to get expected int value." will be printed to the qa_execution log at INFO level, while the detail information of the object will be printed at DEBUG level.

Parameters:
expected - The expected value.
tempInt - The int to be check.
Throws:
java.lang.Exception - Exception will be thrown if the check failed.

checkEitherValueFromObject

protected void checkEitherValueFromObject(java.lang.Object exp1,
                                          java.lang.Object exp2,
                                          java.lang.Object tempObj)
                                   throws java.lang.Exception
Check whether the object matches one of the epxected value.

If the object does not match any of the expected values, an error message "case_id: step_id failed to get expected value." will be printed to the qa_execution log at INFO level, while the detail information of the object and expected values will be printed at DEBUG level. The comparison is done through Object.equals().

Parameters:
exp1 - The first expected value. This can be null object.
exp2 - The second expected value. This can be null object.
tempObj - The object to be compared.
Throws:
java.lang.Exception - Exception will be thrown if the check failed.

checkSingleValueFromEnum

protected void checkSingleValueFromEnum(java.lang.Object expected,
                                        java.util.Enumeration en)
                                 throws java.lang.Exception
Check whether the enumeration contain only a single object, which also matches the expected value.

If the object does not match any of the expected values, an error message "case_id: step_id failed to get expected value." will be printed to the qa_execution log at INFO level, while the detail information of the object and expected values will be printed at DEBUG level. The comparison is done through Object.equals().

Parameters:
expected - The expected value. This can be null object.
en - The enumeration to be compared.
Throws:
java.lang.Exception - Exception will be thrown if the check failed.

checkSingleValueFromVector

protected void checkSingleValueFromVector(java.lang.Object expected,
                                          java.util.Vector vec)
                                   throws java.lang.Exception
Check whether the vector contain only a single object, which also matches the expected value.

If the object does not match any of the expected values, an error message "case_id: step_id failed to get expected value." will be printed to the qa_execution log at INFO level, while the detail information of the object and expected values will be printed at DEBUG level. The comparison is done through Object.equals().

Parameters:
expected - The expected value. This can be null object.
vec - The vector to be compared.
Throws:
java.lang.Exception - Exception will be thrown if the check failed.

checkEmptyEnum

protected void checkEmptyEnum(java.util.Enumeration en)
                       throws java.lang.Exception
Check whether the enumeration is empty. (i.e. contains no element.)

If the object does not match any of the expected values, an error message "case_id: step_id got unexpected enumeration instead of an empty one." will be printed to the qa_execution log at INFO level, while the detail information of the object and expected values will be printed at DEBUG level. The comparison is done through Object.equals().

Parameters:
en - The enumeration to be compared.
Throws:
java.lang.Exception - Exception will be thrown if the check failed.

checkEmptyVector

protected void checkEmptyVector(java.util.Vector vec)
                         throws java.lang.Exception
Check whether the vector is empty. (i.e. contains no element.)

If the object does not match any of the expected values, an error message "case_id: step_id got unexpected vector instead of an empty one." will be printed to the qa_execution log at INFO level, while the detail information of the object and expected values will be printed at DEBUG level. The comparison is done through Object.equals().

Parameters:
vec - The vector to be compared.
Throws:
java.lang.Exception - Exception will be thrown if the check failed.

checkEmptyArray

protected void checkEmptyArray(java.lang.Object[] array)
                        throws java.lang.Exception
Check whether the array is empty. (i.e. contains no element.)

If the object does not match any of the expected values, an error message "case_id: step_id got unexpected array instead of an empty one." will be printed to the qa_execution log at INFO level, while the detail information of the object and expected values will be printed at DEBUG level. The comparison is done through Object.equals().

Parameters:
array - The array to be compared.
Throws:
java.lang.Exception - Exception will be thrown if the check failed.

checkValuesFromEnum

protected void checkValuesFromEnum(java.lang.Object[] expectedValues,
                                   int[] expectedCounts,
                                   java.util.Enumeration en)
                            throws java.lang.Exception
Check whether the enumeration contains the expected values (and also the expected times of appearance).

If at least one of the matches failed, an error message will be printed to the qa_execution log at INFO level, while the detail information of the object and expected values will be printed at DEBUG level. The comparison is done through Object.equals().

The error messages are:

Parameters:
expectedValues - An array of object that contains all the expected values.
expectedCounts - If this parameter is declared null, this method will only check if the specificed value appears at least once in the enumeration. Otherwise, this parameter should be an array of int values that represent the count of the expected number of appearance of the associated value. (i.e. the object that has the same index in the expectedValues array).
Throws:
java.lang.Exception - Exception will be thrown if an unexpected value exists in the enumeration, or the expected occurrence count doesn't match the actual count of appearance.

checkValuesFromVector

protected void checkValuesFromVector(java.lang.Object[] expectedValues,
                                     int[] expectedCounts,
                                     java.util.Vector vec)
                              throws java.lang.Exception
Check whether the vector contains the expected values (and also the expected times of appearance).

If at least one of the matches failed, an error message will be printed to the qa_execution log at INFO level, while the detail information of the object and expected values will be printed at DEBUG level. The comparison is done through Object.equals().

The error messages are:

Parameters:
expectedValues - An array of object that contains all the expected values.
expectedCounts - If this parameter is declared null, this method will only check if the specificed value appears at least once in the enumeration. Otherwise, this parameter should be an array of int values that represent the count of the expected number of appearance of the associated value. (i.e. the object that has the same index in the expectedValues array).
Throws:
java.lang.Exception - Exception will be thrown if an unexpected value exists in the enumeration, or the expected occurrence count doesn't match the actual count of appearance.

checkValuesFromArray

protected void checkValuesFromArray(java.lang.Object[] expectedValues,
                                    int[] expectedCounts,
                                    java.lang.Object[] array)
                             throws java.lang.Exception
Check whether the array contains the expected values (and also the expected times of appearance).

If at least one of the matches failed, an error message will be printed to the qa_execution log at INFO level, while the detail information of the object and expected values will be printed at DEBUG level. The comparison is done through Object.equals().

The error messages are:

Parameters:
expectedValues - An array of object that contains all the expected values.
expectedCounts - If this parameter is declared null, this method will only check if the specificed value appears at least once in the array. Otherwise, this parameter should be an array of int values that represent the count of the expected number of appearance of the associated value. (i.e. the object that has the same index in the expectedValues array).
Throws:
java.lang.Exception - Exception will be thrown if an unexpected value exists in the array, or the expected occurrence count doesn't match the actual count of appearance.

getProperty

public final java.lang.String getProperty(java.lang.String propKey)
Retrieves the value associated to the key from the default property section.

Parameters:
propKey - The property key.
Returns:
The string value associated to the property key. If the key has no associated value, returns null.

getProperty

public final java.lang.String getProperty(java.lang.String section,
                                          java.lang.String propKey)
Retrieves the value associated to the key from the specified property section.

Parameters:
section - The section name.
propKey - The property key.
Returns:
The string value associated to the property key. If the key has no associated value, returns null.

getPropertyWithDefault

public final java.lang.String getPropertyWithDefault(java.lang.String propKey,
                                                     java.lang.String defaultValue)
Retrieves the value associated to the key from the default property section. If the key has no value, returns the default value.

Parameters:
propKey - The property key.
defaultValue - The default value to be returned if the property key has no value.
Returns:
The string value associated to the property key. If the key has no associated value, returns the default value.

getPropertyWithDefault

public final java.lang.String getPropertyWithDefault(java.lang.String section,
                                                     java.lang.String propKey,
                                                     java.lang.String defaultValue)
Retrieves the value associated to the key from the specified property section. If the key has no value, returns the default value.

Parameters:
section - The section name.
propKey - The property key.
defaultValue - The default value to be returned if the property key has no value.
Returns:
The string value associated to the property key. If the key has no associated value, returns the default value.

handleFailureException

protected void handleFailureException(java.lang.Exception failEx)
Print out the standard failure Exception message. This will contain the _caseId, _stepId, _StepDesc, Exception classname, Excpetion message and stack info.

Parameters:
failEx - The failed exception object.

Nitido NiM 2.5 Java API

These JavaDoc pages are generated for release/nim_2_5-2.5.44

Copyright © 1999-2009 Nitido Inc.    Proprietary and Confidential.    All Rights Reserved.