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 the setCurrentState(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 Details

    • AbstractFlowExecutionTests

      public AbstractFlowExecutionTests()
      Constructs a default flow execution test.
      See Also:
      • TestCase.setName(String)
    • AbstractFlowExecutionTests

      public AbstractFlowExecutionTests(String name)
      Constructs a flow execution test with given name.
      Parameters:
      name - the name of the test
  • Method Details

    • 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:
    • 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(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 IllegalStateException
      Returns the flow execution being tested.
      Returns:
      the flow execution
      Throws:
      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<Object> getViewScope() throws IllegalStateException
      Returns view scope.
      Returns:
      view scope
      Throws:
      IllegalStateException
    • getFlowScope

      protected MutableAttributeMap<Object> getFlowScope() throws IllegalStateException
      Returns flow scope.
      Returns:
      flow scope
      Throws:
      IllegalStateException
    • getConversationScope

      protected MutableAttributeMap<Object> getConversationScope() throws IllegalStateException
      Returns conversation scope.
      Returns:
      conversation scope
      Throws:
      IllegalStateException
    • getViewAttribute

      protected Object getViewAttribute(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 Object getRequiredViewAttribute(String attributeName) throws 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:
      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

      protected Object getFlowAttribute(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 Object getRequiredFlowAttribute(String attributeName) throws 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:
      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

      protected Object getConversationAttribute(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 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

      protected void assertActiveFlowEquals(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(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(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(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