Class AbstractFlowExecutionTests
java.lang.Object
junit.framework.Assert
junit.framework.TestCase
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:
- That the flow execution starts as expected (see
startFlow(MutableAttributeMap, ExternalContext)
). - That a state executes the appropriate transition when an event is signaled. A test case should be authored for
each logical event that can occur, where an event triggers a transition representing a path through the flow. The
goal should be to exercise all state transitions (see the
resumeFlow(ExternalContext)
variants and thesetCurrentState(String)
for more information). - That given a transition that leads to an interactive state type (such as a view state or an end state), the view selected matches what was expected and the current state of the flow matches what is expected.
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 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
ConstructorDescriptionConstructs a default flow execution test.Constructs a flow execution test with given name. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
assertActiveFlowEquals
(String expectedActiveFlowId) Assert that the active flow session is for the flow with the provided id.protected void
assertCurrentStateEquals
(String expectedCurrentStateId) Assert that the current state of the flow execution equals the provided state id.protected void
Assert that the entire flow execution is active; that is, it has not ended and has been started.protected void
Assert that the flow execution has ended; that is, it is no longer active.protected void
assertFlowExecutionOutcomeEquals
(String outcome) Assert that the flow execution has ended with the outcome specified.protected void
assertResponseWrittenEquals
(String response, MockExternalContext context) Assert that the response written to the mock context equals the response provided.protected FlowExecutionFactory
Factory method to create the flow execution factory.protected Object
getConversationAttribute
(String attributeName) Returns the attribute in conversation scope.protected MutableAttributeMap<Object>
Returns conversation scope.protected Object
getFlowAttribute
(String attributeName) Returns the attribute in flow scope.protected abstract FlowDefinition
Returns the flow definition to be tested.protected FlowExecution
Returns the flow execution being tested.protected FlowExecutionFactory
Gets the factory that will create the flow execution to test.protected FlowExecutionOutcome
Returns the flow execution outcome that was reached.protected MutableAttributeMap<Object>
Returns flow scope.protected Object
getRequiredConversationAttribute
(String attributeName) Returns the required attribute in conversation scope; asserts the attribute is present.protected Object
getRequiredConversationAttribute
(String attributeName, Class<?> requiredType) Returns the required attribute in conversation scope; asserts the attribute is present and of the required type.protected Object
getRequiredFlowAttribute
(String attributeName) Returns the required attribute in flow scope; asserts the attribute is present.protected Object
getRequiredFlowAttribute
(String attributeName, Class<Object> requiredType) Returns the required attribute in flow scope; asserts the attribute is present and of the correct type.protected Object
getRequiredViewAttribute
(String attributeName) Returns the required attribute in view scope; asserts the attribute is present.protected Object
getRequiredViewAttribute
(String attributeName, Class<Object> requiredType) Returns the required attribute in view scope; asserts the attribute is present and of the correct type.protected Object
getViewAttribute
(String attributeName) Returns the attribute in view scope.protected MutableAttributeMap<Object>
Returns view scope.protected void
resumeFlow
(ExternalContext context) Resume the flow execution to be tested.protected void
setCurrentState
(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
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, countTestCases, createResult, fail, fail, failNotEquals, failNotSame, failSame, format, getName, run, run, runBare, runTest, setName, setUp, tearDown, toString
-
Constructor Details
-
AbstractFlowExecutionTests
public AbstractFlowExecutionTests()Constructs a default flow execution test.- See Also:
-
TestCase.setName(String)
-
AbstractFlowExecutionTests
Constructs a flow execution test with given name.- Parameters:
name
- the name of the test
-
-
Method Details
-
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:
-
startFlow
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 flowcontext
- 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
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
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
Returns the flow execution being tested.- Returns:
- the flow execution
- Throws:
IllegalStateException
- the execution has not been started
-
getFlowExecutionOutcome
Returns the flow execution outcome that was reached.- Returns:
- the flow execution outcome, or null if the flow execution has not ended
-
getViewScope
Returns view scope.- Returns:
- view scope
- Throws:
IllegalStateException
-
getFlowScope
Returns flow scope.- Returns:
- flow scope
- Throws:
IllegalStateException
-
getConversationScope
Returns conversation scope.- Returns:
- conversation scope
- Throws:
IllegalStateException
-
getViewAttribute
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
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:
IllegalStateException
- if the attribute was not present
-
getRequiredViewAttribute
protected Object getRequiredViewAttribute(String attributeName, Class<Object> requiredType) throws 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:
IllegalStateException
- if the attribute was not present or was of the wrong type
-
getFlowAttribute
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
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:
IllegalStateException
- if the attribute was not present
-
getRequiredFlowAttribute
protected Object getRequiredFlowAttribute(String attributeName, Class<Object> requiredType) throws 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:
IllegalStateException
- if the attribute was not present or was of the wrong type
-
getConversationAttribute
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 Object getRequiredConversationAttribute(String attributeName) throws 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:
IllegalStateException
- if the attribute was not present
-
getRequiredConversationAttribute
protected Object getRequiredConversationAttribute(String attributeName, Class<?> requiredType) throws 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:
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
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
Assert that the flow execution has ended with the outcome specified.- Parameters:
outcome
- the name of the flow execution outcome
-
assertCurrentStateEquals
Assert that the current state of the flow execution equals the provided state id.- Parameters:
expectedCurrentStateId
- the expected current state
-
assertResponseWrittenEquals
Assert that the response written to the mock context equals the response provided.- Parameters:
response
- the expected responsecontext
- the mock external context that was written to
-
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 aFlowExecutionImplFactory
instance.- Returns:
- the flow execution factory
-
updateFlowExecution
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
Returns the flow definition to be tested. Subclasses must implement.- Returns:
- the flow definition
-