Spring Web Flow

org.springframework.webflow.test.execution
Class AbstractFlowExecutionTests

java.lang.Object
  extended by junit.framework.Assert
      extended by junit.framework.TestCase
          extended by org.springframework.webflow.test.execution.AbstractFlowExecutionTests
All Implemented Interfaces:
junit.framework.Test
Direct Known Subclasses:
AbstractExternalizedFlowExecutionTests

public abstract class AbstractFlowExecutionTests
extends junit.framework.TestCase

Base class for tests that verify a flow executes as expected. Flow execution tests authored by subclasses should test that a flow responds to all supported transition criteria correctly, transitioning to the correct states and producing the expected results on the occurrence of external events.

A typical flow execution test case will test:

A flow execution test can effectively automate and validate the orchestration required to drive an end-to-end business task that spans several steps involving the user to complete. Such tests are a good way to test your system top-down starting at the web-tier and pushing through all the way to the DB without having to deploy to a servlet or portlet container. In addition, they can be used to effectively test a flow's execution (the web layer) standalone, typically with a mock service layer.

Author:
Keith Donald

Constructor Summary
AbstractFlowExecutionTests()
          Constructs a default flow execution test.
AbstractFlowExecutionTests(java.lang.String name)
          Constructs a flow execution test with given name.
 
Method Summary
protected  void assertActiveFlowEquals(java.lang.String expectedActiveFlowId)
          Assert that the active flow session is for the flow with the provided id.
protected  void assertCurrentStateEquals(java.lang.String expectedCurrentStateId)
          Assert that the current state of the flow execution equals the provided state id.
protected  void assertFlowExecutionActive()
          Assert that the entire flow execution is active; that is, it has not ended and has been started.
protected  void assertFlowExecutionEnded()
          Assert that the flow execution has ended; that is, it is no longer active.
protected  void assertFlowExecutionOutcomeEquals(java.lang.String outcome)
          Assert that the flow execution has ended with the outcome specified.
protected  void assertResponseWrittenEquals(java.lang.String response, MockExternalContext context)
          Assert that the response written to the mock context equals the response provided.
protected  FlowExecutionFactory createFlowExecutionFactory()
          Factory method to create the flow execution factory.
protected  java.lang.Object getConversationAttribute(java.lang.String attributeName)
          Returns the attribute in conversation scope.
protected  MutableAttributeMap<java.lang.Object> getConversationScope()
          Returns conversation scope.
protected  java.lang.Object getFlowAttribute(java.lang.String attributeName)
          Returns the attribute in flow scope.
protected abstract  FlowDefinition getFlowDefinition()
          Returns the flow definition to be tested.
protected  FlowExecution getFlowExecution()
          Returns the flow execution being tested.
protected  FlowExecutionFactory getFlowExecutionFactory()
          Gets the factory that will create the flow execution to test.
protected  FlowExecutionOutcome getFlowExecutionOutcome()
          Returns the flow execution outcome that was reached.
protected  MutableAttributeMap<java.lang.Object> getFlowScope()
          Returns flow scope.
protected  java.lang.Object getRequiredConversationAttribute(java.lang.String attributeName)
          Returns the required attribute in conversation scope; asserts the attribute is present.
protected  java.lang.Object getRequiredConversationAttribute(java.lang.String attributeName, java.lang.Class<?> requiredType)
          Returns the required attribute in conversation scope; asserts the attribute is present and of the required type.
protected  java.lang.Object getRequiredFlowAttribute(java.lang.String attributeName)
          Returns the required attribute in flow scope; asserts the attribute is present.
protected  java.lang.Object getRequiredFlowAttribute(java.lang.String attributeName, java.lang.Class<java.lang.Object> requiredType)
          Returns the required attribute in flow scope; asserts the attribute is present and of the correct type.
protected  java.lang.Object getRequiredViewAttribute(java.lang.String attributeName)
          Returns the required attribute in view scope; asserts the attribute is present.
protected  java.lang.Object getRequiredViewAttribute(java.lang.String attributeName, java.lang.Class<java.lang.Object> requiredType)
          Returns the required attribute in view scope; asserts the attribute is present and of the correct type.
protected  java.lang.Object getViewAttribute(java.lang.String attributeName)
          Returns the attribute in view scope.
protected  MutableAttributeMap<java.lang.Object> getViewScope()
          Returns view scope.
protected  void resumeFlow(ExternalContext context)
          Resume the flow execution to be tested.
protected  void setCurrentState(java.lang.String stateId)
          Sets the current state of the flow execution being tested.
protected  void startFlow(ExternalContext context)
          Start the flow execution to be tested.
protected  void startFlow(MutableAttributeMap<?> input, ExternalContext context)
          Start the flow execution to be tested.
protected  void updateFlowExecution(FlowExecution flowExecution)
          Directly update the flow execution used by the test by setting it to given flow execution.
 
Methods inherited from class junit.framework.TestCase
countTestCases, createResult, getName, run, run, runBare, runTest, setName, setUp, tearDown, toString
 
Methods inherited from class junit.framework.Assert
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, fail, fail, failNotEquals, failNotSame, failSame
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AbstractFlowExecutionTests

public AbstractFlowExecutionTests()
Constructs a default flow execution test.

See Also:
TestCase.setName(String)

AbstractFlowExecutionTests

public AbstractFlowExecutionTests(java.lang.String name)
Constructs a flow execution test with given name.

Parameters:
name - the name of the test
Method Detail

getFlowExecutionFactory

protected FlowExecutionFactory getFlowExecutionFactory()
Gets the factory that will create the flow execution to test. This method will create the factory if it is not already set.

Returns:
the flow execution factory
See Also:
createFlowExecutionFactory()

startFlow

protected void startFlow(ExternalContext context)
                  throws FlowExecutionException
Start the flow execution to be tested.

Parameters:
context - the external context providing information about the caller's environment, used by the flow execution during the start operation
Throws:
FlowExecutionException - if an exception was thrown while starting the flow execution

startFlow

protected void startFlow(MutableAttributeMap<?> input,
                         ExternalContext context)
                  throws FlowExecutionException
Start the flow execution to be tested.

Parameters:
input - input to pass the flow
context - the external context providing information about the caller's environment, used by the flow execution during the start operation
Throws:
FlowExecutionException - if an exception was thrown while starting the flow execution

resumeFlow

protected void resumeFlow(ExternalContext context)
                   throws FlowExecutionException
Resume the flow execution to be tested.

Parameters:
context - the external context providing information about the caller's environment, used by the flow execution during the start operation
Throws:
FlowExecutionException - if an exception was thrown while starting the flow execution

setCurrentState

protected void setCurrentState(java.lang.String stateId)
Sets the current state of the flow execution being tested. If the execution has not been started, it will be created and activated.

Parameters:
stateId - the state id

getFlowExecution

protected FlowExecution getFlowExecution()
                                  throws java.lang.IllegalStateException
Returns the flow execution being tested.

Returns:
the flow execution
Throws:
java.lang.IllegalStateException - the execution has not been started

getFlowExecutionOutcome

protected FlowExecutionOutcome getFlowExecutionOutcome()
Returns the flow execution outcome that was reached.

Returns:
the flow execution outcome, or null if the flow execution has not ended

getViewScope

protected MutableAttributeMap<java.lang.Object> getViewScope()
                                                      throws java.lang.IllegalStateException
Returns view scope.

Returns:
view scope
Throws:
java.lang.IllegalStateException

getFlowScope

protected MutableAttributeMap<java.lang.Object> getFlowScope()
                                                      throws java.lang.IllegalStateException
Returns flow scope.

Returns:
flow scope
Throws:
java.lang.IllegalStateException

getConversationScope

protected MutableAttributeMap<java.lang.Object> getConversationScope()
                                                              throws java.lang.IllegalStateException
Returns conversation scope.

Returns:
conversation scope
Throws:
java.lang.IllegalStateException

getViewAttribute

protected java.lang.Object getViewAttribute(java.lang.String attributeName)
Returns the attribute in view scope. View-scoped attributes are local to the current view state and are cleared when the view state exits.

Parameters:
attributeName - the name of the attribute
Returns:
the attribute value

getRequiredViewAttribute

protected java.lang.Object getRequiredViewAttribute(java.lang.String attributeName)
                                             throws java.lang.IllegalStateException
Returns the required attribute in view scope; asserts the attribute is present. View-scoped attributes are local to the current view state and are cleared when the view state exits.

Parameters:
attributeName - the name of the attribute
Returns:
the attribute value
Throws:
java.lang.IllegalStateException - if the attribute was not present

getRequiredViewAttribute

protected java.lang.Object getRequiredViewAttribute(java.lang.String attributeName,
                                                    java.lang.Class<java.lang.Object> requiredType)
                                             throws java.lang.IllegalStateException
Returns the required attribute in view scope; asserts the attribute is present and of the correct type. View-scoped attributes are local to the current view state and are cleared when the view state exits.

Parameters:
attributeName - the name of the attribute
Returns:
the attribute value
Throws:
java.lang.IllegalStateException - if the attribute was not present or was of the wrong type

getFlowAttribute

protected java.lang.Object getFlowAttribute(java.lang.String attributeName)
Returns the attribute in flow scope. Flow-scoped attributes are local to the active flow session.

Parameters:
attributeName - the name of the attribute
Returns:
the attribute value

getRequiredFlowAttribute

protected java.lang.Object getRequiredFlowAttribute(java.lang.String attributeName)
                                             throws java.lang.IllegalStateException
Returns the required attribute in flow scope; asserts the attribute is present. Flow-scoped attributes are local to the active flow session.

Parameters:
attributeName - the name of the attribute
Returns:
the attribute value
Throws:
java.lang.IllegalStateException - if the attribute was not present

getRequiredFlowAttribute

protected java.lang.Object getRequiredFlowAttribute(java.lang.String attributeName,
                                                    java.lang.Class<java.lang.Object> requiredType)
                                             throws java.lang.IllegalStateException
Returns the required attribute in flow scope; asserts the attribute is present and of the correct type. Flow-scoped attributes are local to the active flow session.

Parameters:
attributeName - the name of the attribute
Returns:
the attribute value
Throws:
java.lang.IllegalStateException - if the attribute was not present or was of the wrong type

getConversationAttribute

protected java.lang.Object getConversationAttribute(java.lang.String attributeName)
Returns the attribute in conversation scope. Conversation-scoped attributes are shared by all flow sessions.

Parameters:
attributeName - the name of the attribute
Returns:
the attribute value

getRequiredConversationAttribute

protected java.lang.Object getRequiredConversationAttribute(java.lang.String attributeName)
                                                     throws java.lang.IllegalStateException
Returns the required attribute in conversation scope; asserts the attribute is present. Conversation-scoped attributes are shared by all flow sessions.

Parameters:
attributeName - the name of the attribute
Returns:
the attribute value
Throws:
java.lang.IllegalStateException - if the attribute was not present

getRequiredConversationAttribute

protected java.lang.Object getRequiredConversationAttribute(java.lang.String attributeName,
                                                            java.lang.Class<?> requiredType)
                                                     throws java.lang.IllegalStateException
Returns the required attribute in conversation scope; asserts the attribute is present and of the required type. Conversation-scoped attributes are shared by all flow sessions.

Parameters:
attributeName - the name of the attribute
Returns:
the attribute value
Throws:
java.lang.IllegalStateException - if the attribute was not present or not of the required type

assertFlowExecutionActive

protected void assertFlowExecutionActive()
Assert that the entire flow execution is active; that is, it has not ended and has been started.


assertActiveFlowEquals

protected void assertActiveFlowEquals(java.lang.String expectedActiveFlowId)
Assert that the active flow session is for the flow with the provided id.

Parameters:
expectedActiveFlowId - the flow id that should have a session active in the tested flow execution

assertFlowExecutionEnded

protected void assertFlowExecutionEnded()
Assert that the flow execution has ended; that is, it is no longer active.


assertFlowExecutionOutcomeEquals

protected void assertFlowExecutionOutcomeEquals(java.lang.String outcome)
Assert that the flow execution has ended with the outcome specified.

Parameters:
outcome - the name of the flow execution outcome

assertCurrentStateEquals

protected void assertCurrentStateEquals(java.lang.String expectedCurrentStateId)
Assert that the current state of the flow execution equals the provided state id.

Parameters:
expectedCurrentStateId - the expected current state

assertResponseWrittenEquals

protected void assertResponseWrittenEquals(java.lang.String response,
                                           MockExternalContext context)
Assert that the response written to the mock context equals the response provided.

Parameters:
response - the expected response
context - the mock external context that was written to

createFlowExecutionFactory

protected FlowExecutionFactory createFlowExecutionFactory()
Factory method to create the flow execution factory. Subclasses could override this if they want to use a custom flow execution factory or custom configuration of the flow execution factory, registering flow execution listeners for instance. The default implementation just returns a FlowExecutionImplFactory instance.

Returns:
the flow execution factory

updateFlowExecution

protected void updateFlowExecution(FlowExecution flowExecution)
Directly update the flow execution used by the test by setting it to given flow execution. Use this if you have somehow manipulated the flow execution being tested and want to continue the test with another flow execution.

Parameters:
flowExecution - the flow execution to use

getFlowDefinition

protected abstract FlowDefinition getFlowDefinition()
Returns the flow definition to be tested. Subclasses must implement.

Returns:
the flow definition

Spring Web Flow