JTR 5.0 API Documentation

jtr.runners
Class AbstractRunnerAncestor

java.lang.Object
  extended by jtr.runners.AbstractRunnerAncestor
All Implemented Interfaces:
java.lang.Runnable, IRunner, IRunnerClean, IRunnerParameterized, IRunnerPooled
Direct Known Subclasses:
AbstractJMSRunner, AbstractRunner, AbstractWsRunner, JUnitFacadeRunner

public abstract class AbstractRunnerAncestor
extends java.lang.Object
implements IRunner

This base abstract class is the ancestor common to every JTR abstract runner. It is not meant to be available to test-suite developers.

Since:
1.1
Version:
5.0
Author:
Francesco Russo (frusso@dev.java.net)

Field Summary
protected  org.apache.log4j.Logger logger
           
 
Constructor Summary
AbstractRunnerAncestor()
           
 
Method Summary
 void addMessage(java.lang.String msg)
          This method allows the straight addition of a user-message to the outcome of each run.
 void afterTest()
           
 void beforeTest()
          This optional method must be implemented if the user-defined runner has to prepare one or more resources before executing its testing-logic.
 IRunnerClean clean()
          This method cleans all the configurations/parameters assigned to the current IRunner.
 void enrichOutcome(IOutcome outcome)
          This abstract method must be used either when the user needs to enrich the given outcome with a JTR UserObject or in case the default IOutcomeFactory has been replaced with a custom one.
 int getCurrentRun()
          Read which run the runner is in.
 java.lang.String getDefaultName()
          Get the default name provided by this.getClass().getName()
 EnterpriseConfig getEnterprise()
          Return the enterprise configuration assigned to the current IRunner
 int getEpoch()
          Return the current epoch assigned to the IRunner
 int getFailures()
          Get the number of failures
 java.lang.String getFqn()
          Obtains the runner FQN.
 int getInstanceCount()
          Get the number of instances that must be active, according to the jtr.xml, during the test-suite.
 int getInstanceID()
          Returns the progressive ID assigned to this runner instance at creation time.
 java.lang.String getName()
          Return the name of the IRunner
 IOutcomeFactory getOutcomeFactory()
          Get the current IOutcomeTable
 ParametersMap getParameters()
          Return the set of runtime parameters configured for the IRunner
 IParamsAssigner getParamsAssigner()
          Get the IParamsAssigner in charge of assigning parameters to the current IRunner
 RunnerPool getPool()
          Get the pool this IRunner belongs to
 int getRuns()
          Return the number of runs assigned to the IRunner
 long getSleepTime()
          Get the sleep runDuration assigned to this IRunner
 IStatFunction getStatFunction(java.lang.String paramName)
          Returns the reference to the IStatFunction implementation associated with the parameter named paramName, if present, otherwies null is returned.
 int getSuccesses()
          Get the number of successes.
 TestOutcomeTable getTestOutcomeTable()
          Return the current TestOutcomeTable
 java.lang.String getUserMessage()
          Read the content of the user-message.
protected  void handleFailure(int run, java.lang.Throwable t)
          Whenever an exception is caught during the execution of the test() method of the IRunner interface, the AbstractRunner takes care of instantiating a new IOutcome and of adding it to the current TestOutcomeTable.
Once this steps have been performed, the receiveFailureNotification(Throwable,String)" of the IRunner interface is called.
 void run()
          Implements the logic that manages the execution of every test.
 void setCurrentRun(int val)
          Tell the runner the current run value.
 void setEnterprise(EnterpriseConfig enterprise)
          Assign the given enterprise configuration to the current IRunner
 void setEpoch(int epoch)
          Assign the current epoch to the IRunner
 void setFqn(java.lang.String name)
          Assigns the runner its FQN.
 void setInstanceCount(int i)
          Set the number of instances that must be active, according to the jtr.xml, during the test-suite.
 void setInstanceID(int id)
          Sets the progressive ID assigned to this runner instance at creation time.
 void setName(java.lang.String name)
          Set the name of the IRunner.
 void setOutcomeFactory(IOutcomeFactory outcomeFactory)
          Set the current IOutcomeTable
 void setParameters(ParametersMap params)
          Provides the IRunner with its runtime parameters.
 void setParamsAssigner(IParamsAssigner paramsAssigner)
          Set the IParamsAssigner in charge of assigning parameters to the current IRunner
 IRunnerPooled setPool(RunnerPool pool)
          Set the pool this IRunner will belong to
 void setRuns(int runs)
          Set the number of runs assigned to the IRunner
 void setSleepTime(long sleepTime)
          Get the sleep runDuration assigned to this IRunner
 void setStatFunction(java.lang.String paramName, IStatFunction f)
          Sets the reference to the IStatFunction implementation associated with the parameter named paramName.
 void setTestCompletionListener(ITestCompletionListener testComplLsnr)
          This method assigns an ITestCompletionListener instance to a runner in CLEAN state.
 void setTestOutcomeTable(TestOutcomeTable testOutcomeTable)
          Set the current TestOutcomeTable
protected abstract  void specializedBeforeRunTest()
          This method allows more specialized subclasses to perform preparatory activities right before the actual test is launched.

Note: implementations of this method must always be final.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface jtr.runners.IRunner
receiveFailureNotification, test
 
Methods inherited from interface jtr.runners.IRunnerPooled
cleanupResources
 

Field Detail

logger

protected org.apache.log4j.Logger logger
Constructor Detail

AbstractRunnerAncestor

public AbstractRunnerAncestor()
Method Detail

clean

public IRunnerClean clean()
This method cleans all the configurations/parameters assigned to the current IRunner. It should be overridden by an application-level runner using the delegation pattern for adding the clean up of resources. This method is invoked every time an IRunner implementation completes one of its runs. It is used for reinitializing a runner between two consecutive runs if this is required by the associated assignment policy (i.e. cyclic).
This method is not intended for finalizing "expensive resources": you might want to avoid the reinitialization of a JDBC or JMS connection every time a run completes, maybe because you think it would be too much expensive obtaining it every time.
In such a case you should avoid putting such clean up activity in this method: you should think about using the IRunnerPooled.cleanupResources() method instead.

Returns:
IRunnerClean The same runner in the CLEAN state.
See Also:
IRunnerPooled.cleanupResources()

getStatFunction

public IStatFunction getStatFunction(java.lang.String paramName)
Returns the reference to the IStatFunction implementation associated with the parameter named paramName, if present, otherwies null is returned.

Specified by:
getStatFunction in interface IRunnerClean
Parameters:
paramName -
Returns:

setStatFunction

public void setStatFunction(java.lang.String paramName,
                            IStatFunction f)
Sets the reference to the IStatFunction implementation associated with the parameter named paramName.

Specified by:
setStatFunction in interface IRunnerClean
Parameters:
paramName -
f -

setEpoch

public void setEpoch(int epoch)
Assign the current epoch to the IRunner

Specified by:
setEpoch in interface IRunnerClean
Parameters:
epoch - The current epoch

getEpoch

public int getEpoch()
Return the current epoch assigned to the IRunner

Specified by:
getEpoch in interface IRunnerClean
Returns:
int The current epoch

setCurrentRun

public void setCurrentRun(int val)
Tell the runner the current run value.

Specified by:
setCurrentRun in interface IRunnerClean
Parameters:
val -

getCurrentRun

public int getCurrentRun()
Read which run the runner is in.

Specified by:
getCurrentRun in interface IRunnerClean
Returns:

setName

public void setName(java.lang.String name)
Set the name of the IRunner. This is by default its FQN followed by an increasing integer stating that this is the i-th IRunner of that class.

Specified by:
setName in interface IRunnerClean
Parameters:
name - The name

getName

public java.lang.String getName()
Return the name of the IRunner

Specified by:
getName in interface IRunnerClean
Returns:
String

setFqn

public void setFqn(java.lang.String name)
Assigns the runner its FQN.

Specified by:
setFqn in interface IRunnerClean
Parameters:
name - The FQN

getFqn

public java.lang.String getFqn()
Obtains the runner FQN.

Specified by:
getFqn in interface IRunnerClean
Returns:
The FQN

getDefaultName

public java.lang.String getDefaultName()
Get the default name provided by this.getClass().getName()

Specified by:
getDefaultName in interface IRunnerClean
Returns:
String The default name.

getEnterprise

public EnterpriseConfig getEnterprise()
Return the enterprise configuration assigned to the current IRunner

Specified by:
getEnterprise in interface IRunnerClean
Returns:
EnterpriseConfig The enterprise configuration

setEnterprise

public void setEnterprise(EnterpriseConfig enterprise)
Assign the given enterprise configuration to the current IRunner

Specified by:
setEnterprise in interface IRunnerClean
Parameters:
enterprise - The enterprise configuration

setInstanceCount

public void setInstanceCount(int i)
Set the number of instances that must be active, according to the jtr.xml, during the test-suite.

Specified by:
setInstanceCount in interface IRunnerClean
Parameters:
i - The number of instances

getInstanceCount

public int getInstanceCount()
Get the number of instances that must be active, according to the jtr.xml, during the test-suite.

Specified by:
getInstanceCount in interface IRunnerClean
Returns:
int The number of instances

setInstanceID

public void setInstanceID(int id)
Sets the progressive ID assigned to this runner instance at creation time. This is an integer ranging in [0..n-1] if the jtr.xml states that there must be n instances of runners belonging to a given category.

Specified by:
setInstanceID in interface IRunnerClean
Parameters:
id -

getInstanceID

public int getInstanceID()
Returns the progressive ID assigned to this runner instance at creation time. This is an integer ranging in [0..n-1] if the jtr.xml states that there must be n instances of runners belonging to a given category.

Specified by:
getInstanceID in interface IRunnerClean
Returns:

getRuns

public int getRuns()
Return the number of runs assigned to the IRunner

Specified by:
getRuns in interface IRunnerClean
Returns:
int The number of runs

setRuns

public void setRuns(int runs)
Set the number of runs assigned to the IRunner

Specified by:
setRuns in interface IRunnerClean
Parameters:
runs - The number of runs

getSleepTime

public long getSleepTime()
Get the sleep runDuration assigned to this IRunner

Specified by:
getSleepTime in interface IRunnerClean
Returns:
long The sleep runDuration

setSleepTime

public void setSleepTime(long sleepTime)
Get the sleep runDuration assigned to this IRunner

Specified by:
setSleepTime in interface IRunnerClean
Parameters:
sleepTime - The sleep runDuration

setParameters

public void setParameters(ParametersMap params)
Provides the IRunner with its runtime parameters.

Specified by:
setParameters in interface IRunnerClean
Parameters:
params - The parameters

getParameters

public ParametersMap getParameters()
Return the set of runtime parameters configured for the IRunner

Specified by:
getParameters in interface IRunnerClean
Returns:
ParametersMap

setPool

public IRunnerPooled setPool(RunnerPool pool)
Set the pool this IRunner will belong to

Specified by:
setPool in interface IRunnerParameterized
Parameters:
pool - The pool
Returns:
IRunnerPooled The same runner in its POOLED state

getPool

public RunnerPool getPool()
Get the pool this IRunner belongs to

Specified by:
getPool in interface IRunnerPooled
Returns:
RunnerPool The pool

getParamsAssigner

public IParamsAssigner getParamsAssigner()
Get the IParamsAssigner in charge of assigning parameters to the current IRunner

Specified by:
getParamsAssigner in interface IRunnerClean
Returns:
IParamsAssigner The assigner

setParamsAssigner

public void setParamsAssigner(IParamsAssigner paramsAssigner)
Set the IParamsAssigner in charge of assigning parameters to the current IRunner

Specified by:
setParamsAssigner in interface IRunnerClean
Parameters:
paramsAssigner - IParamsAssigner

getFailures

public int getFailures()
Get the number of failures

Specified by:
getFailures in interface IRunner
Returns:
int The failures

getSuccesses

public int getSuccesses()
Get the number of successes.

Specified by:
getSuccesses in interface IRunner
Returns:
int The successes

getTestOutcomeTable

public TestOutcomeTable getTestOutcomeTable()
Return the current TestOutcomeTable

Specified by:
getTestOutcomeTable in interface IRunnerClean
Returns:
TestOutcomeTable

setTestOutcomeTable

public void setTestOutcomeTable(TestOutcomeTable testOutcomeTable)
Set the current TestOutcomeTable

Specified by:
setTestOutcomeTable in interface IRunnerClean
Parameters:
testOutcomeTable - TestOutcomeTable

getOutcomeFactory

public IOutcomeFactory getOutcomeFactory()
Get the current IOutcomeTable

Specified by:
getOutcomeFactory in interface IRunnerClean
Returns:
IOutcomeFactory

setOutcomeFactory

public void setOutcomeFactory(IOutcomeFactory outcomeFactory)
Set the current IOutcomeTable

Specified by:
setOutcomeFactory in interface IRunnerClean
Parameters:
outcomeFactory - IOutcomeFactory

setTestCompletionListener

public void setTestCompletionListener(ITestCompletionListener testComplLsnr)
This method assigns an ITestCompletionListener instance to a runner in CLEAN state. This assignment can be performed for just one time in a JTR test-session for each runner instance.
Note: it is legal for this instance to be always null for runner instances started on JTR passive-nodes.

Specified by:
setTestCompletionListener in interface IRunnerClean
Parameters:
testComplLsnr - The listener instance

run

public final void run()
Implements the logic that manages the execution of every test. This is the only method allowed to invoke the IRunner.test() method over concrete runner instances.
Subclasses are allowed to perform preparatory activities implementing the jtr.runners.AbstractRunnerAncetor#specializedBeforeRunTest() method that should always be defined as final.

Specified by:
run in interface java.lang.Runnable
Specified by:
run in interface IRunnerParameterized
Specified by:
run in interface IRunnerPooled
See Also:
Runnable.run()

specializedBeforeRunTest

protected abstract void specializedBeforeRunTest()
                                          throws java.lang.Throwable
This method allows more specialized subclasses to perform preparatory activities right before the actual test is launched.

Note: implementations of this method must always be final.

Throws:
java.lang.Throwable

beforeTest

public void beforeTest()
                throws java.lang.Throwable
This optional method must be implemented if the user-defined runner has to prepare one or more resources before executing its testing-logic. This method is called before starting each run.

Specified by:
beforeTest in interface IRunnerPooled
Throws:
java.lang.Throwable

afterTest

public void afterTest()
               throws java.lang.Throwable
Specified by:
afterTest in interface IRunnerPooled
Throws:
java.lang.Throwable

handleFailure

protected final void handleFailure(int run,
                                   java.lang.Throwable t)
Whenever an exception is caught during the execution of the test() method of the IRunner interface, the AbstractRunner takes care of instantiating a new IOutcome and of adding it to the current TestOutcomeTable.
Once this steps have been performed, the receiveFailureNotification(Throwable,String)" of the IRunner interface is called. At this point your custom IRunner gets notified of the exception and can decide what to do with it.

Parameters:
run - The run of the exception
t - The exceptioin

enrichOutcome

public void enrichOutcome(IOutcome outcome)
This abstract method must be used either when the user needs to enrich the given outcome with a JTR UserObject or in case the default IOutcomeFactory has been replaced with a custom one. Responsability of this method is filling in the provided IOutcome instance. That instance will then be put into the TestOutcomeTable by the JTR runtime.

Parameters:
outcome - The empty outcome of a single run

addMessage

public void addMessage(java.lang.String msg)
This method allows the straight addition of a user-message to the outcome of each run.

Parameters:
msg -

getUserMessage

public java.lang.String getUserMessage()
Read the content of the user-message.

Returns:

The JTR Project is licensed under GPL version 2