Expresso 5-6

com.jcorporate.expresso.ext.controller
Class TestController

java.lang.Object
  extended byorg.apache.struts.action.Action
      extended bycom.jcorporate.expresso.core.controller.Controller
          extended bycom.jcorporate.expresso.core.controller.DBController
              extended bycom.jcorporate.expresso.ext.controller.TestController
All Implemented Interfaces:
Serializable, junit.framework.TestListener

public class TestController
extends DBController
implements junit.framework.TestListener

TestController is a controller that can access and run JUnit unit tests, but from within an Expresso environment (e.g. with the DBConnection pool, Cache, and other Expresso items available, and from a servlet (such as ControllerServlet). This allows tests that require the servlet environment or Expresso components to be executed.

Author:
Michael Nash
See Also:
Serialized Form

Field Summary
protected  junit.runner.TestSuiteLoader fTestLoader
           
 
Fields inherited from class com.jcorporate.expresso.core.controller.Controller
CONTROLLER_PARAM_KEY, CTL_SUCC_CTL, CTL_SUCC_STATE, CTL_SUCC_TRAN, mLog, NEWSTATE_EXCEPTION_KEY, ORIGINAL_URL_KEY, REQUEST_KEY, RESPONSE_KEY, RETURN_TO_SENDER_TRAN, STATE_ERR_CTL, STATE_ERR_STATE, STATE_ERR_TRAN, STATE_PARAM_KEY, STATE_SUCC_CTL, STATE_SUCC_STATE, STATE_SUCC_TRAN
 
Fields inherited from class org.apache.struts.action.Action
ACTION_SERVLET_KEY, APPLICATION_KEY, DATA_SOURCE_KEY, defaultLocale, ERROR_KEY, EXCEPTION_KEY, FORM_BEANS_KEY, FORWARDS_KEY, LOCALE_KEY, MAPPING_KEY, MAPPINGS_KEY, MESSAGE_KEY, MESSAGES_KEY, MULTIPART_KEY, PLUG_INS_KEY, REQUEST_PROCESSOR_KEY, servlet, SERVLET_KEY, TRANSACTION_TOKEN_KEY
 
Constructor Summary
TestController()
          Default constructor
 
Method Summary
 void addError(junit.framework.Test test, Throwable t)
           
 void addFailure(junit.framework.Test test, junit.framework.AssertionFailedError t)
          Added since JUnit 3.7
 void addFailure(junit.framework.Test test, Throwable t)
           
protected  void clearStatus()
          Clears the status message.
protected  junit.framework.TestResult createTestResult()
          Creates the TestResult to be used for the test run.
protected  junit.framework.TestResult doRun(junit.framework.Test suite, boolean wait)
           
 String elapsedTimeAsString(long runTime)
          Returns the formatted string of the elapsed time.
 void endTest(junit.framework.Test test)
           
 String extractClassName(String className)
           
static junit.runner.TestSuiteLoader getLoader()
          Returns the loader to be used.
 junit.framework.Test getTest(String suiteClassName)
          Returns the Test corresponding to the given suite.
 String getTitle()
          Return the title of this Controller
static boolean inVAJava()
           
protected  Class loadSuiteClass(String suiteClassName)
          Returns the loaded Class for a suite name.
 ControllerResponse newState(String newState, ControllerRequest params)
          Standard method to select the appropriate next state as the controller moves from state to state.
 void print(junit.framework.TestResult result)
          Prints failures to the log
 void printErrors(junit.framework.TestResult result)
          Prints the errors to the log
 void printFailures(junit.framework.TestResult result)
          Prints failures to the log
 void printHeader(junit.framework.TestResult result)
          Prints the header of the report
static void run(Class testClass)
          Runs a suite extracted from a TestCase subclass.
static void run(junit.framework.Test suite)
          Runs a single test and collects its results.
protected  void runFailed(String message)
           
protected  void runPromptTestState(ControllerRequest request, ControllerResponse response)
          test a transition to a controller/state which requires a form
protected  void runTransition2FormTestState(ControllerRequest request, ControllerResponse response)
          test a transition to a controller/state which requires a form
protected  void runTransitionFromFormTestState(ControllerRequest request, ControllerResponse response)
          test a transition from a controller/state which uses a form to one that does not use a form
protected  void runTransitionTestState(ControllerRequest request, ControllerResponse response)
          test a transition to a controller/state note that the ControllerSecurityMatrix output uses the default layout, so the title at the top of that page will show this test controller.
protected  junit.framework.TestResult start(String testName)
          Starts a test run.
 void startTest(junit.framework.Test test)
           
static String truncate(String s)
          Truncates a String to the maximum length.
 
Methods inherited from class com.jcorporate.expresso.core.controller.DBController
getString, isAllowed, stateAllowed
 
Methods inherited from class com.jcorporate.expresso.core.controller.Controller
addFinalState, addPromptTransitions, addRegDomainParamtoSession, addRequestedURLtoSession, addState, addStatePairing, endTimer, execute, findControllerForm, generateToken, getActionForward, getControllerChainingTransition, getControllerSecurityTransition, getFinalState, getInitialState, getLogger, getParamValues, getRequestURL, getSchema, getSchemaHierarchy, getSchemaInstance, getSchemaStack, getState, getStates, getString, getString, handleException, instantiate, isFinalState, isHandleState, isPromptState, isTokenValid, loadStateForm, nextHandleState, nextPromptState, populateStateForm, postPerform, prePerform, previousPromptState, processRequestTransitions, processTransitions, redirectRequest, redirectRequest, remapFromExtension, resetToken, saveToken, setControllerChainingTransition, setControllerSecurityTransition, setCurrentState, setInitialState, setSchema, setSchema, setupDefaultValues, setupReturnToSender, setupSubclassLog, transition, transition, transition, unloadStateForm
 
Methods inherited from class org.apache.struts.action.Action
execute, generateToken, getDataSource, getDataSource, getLocale, getResources, getResources, getResources, getServlet, isCancelled, isTokenValid, isTokenValid, perform, perform, resetToken, saveErrors, saveMessages, saveToken, setLocale, setServlet, toHex
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

fTestLoader

protected junit.runner.TestSuiteLoader fTestLoader
Constructor Detail

TestController

public TestController()
Default constructor

Method Detail

newState

public ControllerResponse newState(String newState,
                                   ControllerRequest params)
                            throws ControllerException,
                                   NonHandleableException
Standard method to select the appropriate next state as the controller moves from state to state.

Overrides:
newState in class Controller
Parameters:
newState -
params - The calling controllerRequest object.
Returns:
a newly instantiated ControllerResponse for this state.
Throws:
ControllerException - on Error
NonHandleableException - if the error should not be handled by an error controller

addError

public void addError(junit.framework.Test test,
                     Throwable t)
Specified by:
addError in interface junit.framework.TestListener
Parameters:
test -
t -

addFailure

public void addFailure(junit.framework.Test test,
                       Throwable t)
Parameters:
test -
t -

createTestResult

protected junit.framework.TestResult createTestResult()
Creates the TestResult to be used for the test run.

Returns:

doRun

protected junit.framework.TestResult doRun(junit.framework.Test suite,
                                           boolean wait)
Parameters:
suite -
wait -
Returns:

endTest

public void endTest(junit.framework.Test test)
Specified by:
endTest in interface junit.framework.TestListener
Parameters:
test -

addFailure

public void addFailure(junit.framework.Test test,
                       junit.framework.AssertionFailedError t)
Added since JUnit 3.7

Specified by:
addFailure in interface junit.framework.TestListener

print

public void print(junit.framework.TestResult result)
Prints failures to the log

Parameters:
result -

printErrors

public void printErrors(junit.framework.TestResult result)
Prints the errors to the log

Parameters:
result -

printFailures

public void printFailures(junit.framework.TestResult result)
Prints failures to the log

Parameters:
result -

printHeader

public void printHeader(junit.framework.TestResult result)
Prints the header of the report

Parameters:
result -

run

public static void run(Class testClass)
Runs a suite extracted from a TestCase subclass.

Parameters:
testClass -

run

public static void run(junit.framework.Test suite)
Runs a single test and collects its results. This method can be used to start a test run from your program.
 public static void main (String[] args) {
     test.textui.TestRunner.run(suite());
 }
 

Parameters:
suite -

start

protected junit.framework.TestResult start(String testName)
                                    throws Exception
Starts a test run. Analyzes the command line arguments and runs the given test suite.

Parameters:
testName -
Returns:
Throws:
Exception

runFailed

protected void runFailed(String message)
Parameters:
message -

startTest

public void startTest(junit.framework.Test test)
Specified by:
startTest in interface junit.framework.TestListener
Parameters:
test -

getTest

public junit.framework.Test getTest(String suiteClassName)
Returns the Test corresponding to the given suite. This is a template method, subclasses override runFailed(), clearStatus().

Parameters:
suiteClassName -
Returns:

elapsedTimeAsString

public String elapsedTimeAsString(long runTime)
Returns the formatted string of the elapsed time.

Parameters:
runTime -
Returns:

extractClassName

public String extractClassName(String className)
Parameters:
className -
Returns:

truncate

public static String truncate(String s)
Truncates a String to the maximum length.

Parameters:
s -
Returns:

loadSuiteClass

protected Class loadSuiteClass(String suiteClassName)
                        throws ClassNotFoundException
Returns the loaded Class for a suite name.

Parameters:
suiteClassName -
Returns:
Throws:
ClassNotFoundException

clearStatus

protected void clearStatus()
Clears the status message.


getLoader

public static junit.runner.TestSuiteLoader getLoader()
Returns the loader to be used.

Returns:

inVAJava

public static boolean inVAJava()
Returns:

getTitle

public String getTitle()
Description copied from class: Controller
Return the title of this Controller

Overrides:
getTitle in class Controller
Returns:
java.lang.String The Title of the controller

runTransition2FormTestState

protected void runTransition2FormTestState(ControllerRequest request,
                                           ControllerResponse response)
                                    throws ControllerException,
                                           NonHandleableException
test a transition to a controller/state which requires a form

Throws:
ControllerException
NonHandleableException

runTransitionTestState

protected void runTransitionTestState(ControllerRequest request,
                                      ControllerResponse response)
                               throws ControllerException,
                                      NonHandleableException
test a transition to a controller/state note that the ControllerSecurityMatrix output uses the default layout, so the title at the top of that page will show this test controller.

Throws:
ControllerException
NonHandleableException

runPromptTestState

protected void runPromptTestState(ControllerRequest request,
                                  ControllerResponse response)
                           throws ControllerException,
                                  NonHandleableException
test a transition to a controller/state which requires a form

Throws:
ControllerException
NonHandleableException

runTransitionFromFormTestState

protected void runTransitionFromFormTestState(ControllerRequest request,
                                              ControllerResponse response)
                                       throws ControllerException,
                                              NonHandleableException
test a transition from a controller/state which uses a form to one that does not use a form

Throws:
ControllerException
NonHandleableException

Expresso 5-6

Please see www.jcorporate.com for information about new Expresso releases.