Spring Web Flow

org.springframework.webflow.test
Class MockRequestControlContext

java.lang.Object
  extended by org.springframework.webflow.test.MockRequestContext
      extended by org.springframework.webflow.test.MockRequestControlContext
All Implemented Interfaces:
RequestControlContext, RequestContext

public class MockRequestControlContext
extends MockRequestContext
implements RequestControlContext

Mock implementation of the RequestControlContext interface to facilitate standalone Flow and State unit tests.

Author:
Keith Donald
See Also:
RequestContext, FlowSession, State

Constructor Summary
MockRequestControlContext()
          Creates a new mock request control context.
MockRequestControlContext(Flow flow)
          Creates a new mock request control context for controlling a mock execution of the provided flow definition.
MockRequestControlContext(FlowExecutionContext flowExecutionContext)
          Creates a new mock request control context for controlling a flow execution.
 
Method Summary
 FlowExecutionKey assignFlowExecutionKey()
          Assign the ongoing flow execution its flow execution key.
 void endActiveFlowSession(java.lang.String outcome, MutableAttributeMap<java.lang.Object> output)
          End the active flow session of the current flow execution.
 boolean execute(Transition transition)
          Execute this transition out of the current source state.
 boolean getEmbeddedMode()
          Returns true if the flow current flow execution was launched in embedded page mode.
 boolean getRedirectInSameState()
          Returns the value of the 'redirect in same state' flow execution attribute if set or otherwise it falls back on the value returned by RequestControlContext.getRedirectOnPause().
 boolean getRedirectOnPause()
          Returns true if the 'redirect on pause' flow execution attribute is set to true, false otherwise.
 boolean handleEvent(Event event)
          Signals the occurrence of an event in the current state of this flow execution request context.
 void removeAllFlowExecutionSnapshots()
          Remove all flow execution snapshots associated with the ongoing conversation.
 void removeCurrentFlowExecutionSnapshot()
          Remove the current flow execution snapshot to invalidate the current state.
 void setAlwaysRedirectOnPause(boolean alwaysRedirectOnPause)
           
 void setCurrentState(State state)
          Record the current state that has entered in the executing flow.
 void setEmbeddedMode()
           
 void setRedirectInSameState(boolean redirectInSameState)
           
 void start(Flow flow, MutableAttributeMap<?> input)
          Spawn a new flow session and activate it in the currently executing flow.
 void updateCurrentFlowExecutionSnapshot()
          Update the current flow execution snapshot to save the current state.
 void viewRendered(View view)
          Called when the current view has completed rendering in the current view state.
 void viewRendering(View view)
          Called when the current view is about to be rendered in the current view state.
 
Methods inherited from class org.springframework.webflow.test.MockRequestContext
getActiveFlow, getAttributeMap, getAttributes, getConversationScope, getCurrentEvent, getCurrentState, getCurrentTransition, getCurrentView, getExternalContext, getFlashScope, getFlowExecutionContext, getFlowExecutionUrl, getFlowScope, getMatchingTransition, getMessageContext, getMockExternalContext, getMockFlowExecutionContext, getRequestParameters, getRequestScope, getRootFlow, getViewScope, inViewState, putRequestParameter, putRequestParameter, putRequestParameter, removeAttribute, sendFlowExecutionRedirect, setActiveSession, setAttribute, setCurrentEvent, setCurrentTransition, setCurrentView, setExternalContext, setFlowExecutionContext
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.springframework.webflow.engine.RequestControlContext
setCurrentTransition, setCurrentView
 
Methods inherited from interface org.springframework.webflow.execution.RequestContext
getActiveFlow, getAttributes, getConversationScope, getCurrentEvent, getCurrentState, getCurrentTransition, getCurrentView, getExternalContext, getFlashScope, getFlowExecutionContext, getFlowExecutionUrl, getFlowScope, getMatchingTransition, getMessageContext, getRequestParameters, getRequestScope, getViewScope, inViewState
 

Constructor Detail

MockRequestControlContext

public MockRequestControlContext()
Creates a new mock request control context.


MockRequestControlContext

public MockRequestControlContext(Flow flow)
Creates a new mock request control context for controlling a mock execution of the provided flow definition.

Parameters:
flow - the flow definition

MockRequestControlContext

public MockRequestControlContext(FlowExecutionContext flowExecutionContext)
Creates a new mock request control context for controlling a flow execution.

Parameters:
flowExecutionContext - the flow execution context
Method Detail

setCurrentState

public void setCurrentState(State state)
Description copied from interface: RequestControlContext
Record the current state that has entered in the executing flow. This method will be called as part of entering a new state by the State type itself.

Specified by:
setCurrentState in interface RequestControlContext
Parameters:
state - the current state
See Also:
State.enter(RequestControlContext)

assignFlowExecutionKey

public FlowExecutionKey assignFlowExecutionKey()
Description copied from interface: RequestControlContext
Assign the ongoing flow execution its flow execution key. This method will be called before a state is about to render a view and pause the flow execution.

Specified by:
assignFlowExecutionKey in interface RequestControlContext

viewRendering

public void viewRendering(View view)
Description copied from interface: RequestControlContext
Called when the current view is about to be rendered in the current view state.

Specified by:
viewRendering in interface RequestControlContext
Parameters:
view - the view to be rendered

viewRendered

public void viewRendered(View view)
Description copied from interface: RequestControlContext
Called when the current view has completed rendering in the current view state.

Specified by:
viewRendered in interface RequestControlContext
Parameters:
view - the view that rendered

handleEvent

public boolean handleEvent(Event event)
Description copied from interface: RequestControlContext
Signals the occurrence of an event in the current state of this flow execution request context. This method should be called by clients that report internal event occurrences, such as action states. The onEvent() method of the flow involved in the flow execution will be called.

Specified by:
handleEvent in interface RequestControlContext
Parameters:
event - the event that occurred
Returns:
a boolean indicating if handling this event caused the current state to exit and a new state to enter
See Also:
Flow.handleEvent(RequestControlContext)

execute

public boolean execute(Transition transition)
Description copied from interface: RequestControlContext
Execute this transition out of the current source state. Allows for privileged execution of an arbitrary transition.

Specified by:
execute in interface RequestControlContext
Parameters:
transition - the transition
See Also:
Transition.execute(State, RequestControlContext)

removeAllFlowExecutionSnapshots

public void removeAllFlowExecutionSnapshots()
Description copied from interface: RequestControlContext
Remove all flow execution snapshots associated with the ongoing conversation. Invalidates previous states.

Specified by:
removeAllFlowExecutionSnapshots in interface RequestControlContext

removeCurrentFlowExecutionSnapshot

public void removeCurrentFlowExecutionSnapshot()
Description copied from interface: RequestControlContext
Remove the current flow execution snapshot to invalidate the current state.

Specified by:
removeCurrentFlowExecutionSnapshot in interface RequestControlContext

updateCurrentFlowExecutionSnapshot

public void updateCurrentFlowExecutionSnapshot()
Description copied from interface: RequestControlContext
Update the current flow execution snapshot to save the current state.

Specified by:
updateCurrentFlowExecutionSnapshot in interface RequestControlContext

start

public void start(Flow flow,
                  MutableAttributeMap<?> input)
           throws java.lang.IllegalStateException
Description copied from interface: RequestControlContext
Spawn a new flow session and activate it in the currently executing flow. Also transitions the spawned flow to its start state. This method should be called by clients that wish to spawn new flows, such as subflow states.

This will start a new flow session in the current flow execution, which is already active.

Specified by:
start in interface RequestControlContext
Parameters:
flow - the flow to start, its start() method will be called
input - initial contents of the newly created flow session (may be null, e.g. empty)
Throws:
java.lang.IllegalStateException
See Also:
Flow.start(RequestControlContext, MutableAttributeMap)

endActiveFlowSession

public void endActiveFlowSession(java.lang.String outcome,
                                 MutableAttributeMap<java.lang.Object> output)
                          throws java.lang.IllegalStateException
Description copied from interface: RequestControlContext
End the active flow session of the current flow execution. This method should be called by clients that terminate flows, such as end states. The end() method of the flow involved in the flow execution will be called.

Specified by:
endActiveFlowSession in interface RequestControlContext
Parameters:
outcome - the logical outcome the ending session should return
output - output the ending session should return
Throws:
java.lang.IllegalStateException - when the flow execution is not active
See Also:
Flow.end(RequestControlContext, String, MutableAttributeMap)

getRedirectOnPause

public boolean getRedirectOnPause()
Description copied from interface: RequestControlContext
Returns true if the 'redirect on pause' flow execution attribute is set to true, false otherwise.

Specified by:
getRedirectOnPause in interface RequestControlContext
Returns:
true or false

getRedirectInSameState

public boolean getRedirectInSameState()
Description copied from interface: RequestControlContext
Returns the value of the 'redirect in same state' flow execution attribute if set or otherwise it falls back on the value returned by RequestControlContext.getRedirectOnPause().

Specified by:
getRedirectInSameState in interface RequestControlContext
Returns:
true or false

getEmbeddedMode

public boolean getEmbeddedMode()
Description copied from interface: RequestControlContext
Returns true if the flow current flow execution was launched in embedded page mode. When a flow is embedded on a page it can make different assumptions with regards to whether redirect after post is necessary.

Specified by:
getEmbeddedMode in interface RequestControlContext

setAlwaysRedirectOnPause

public void setAlwaysRedirectOnPause(boolean alwaysRedirectOnPause)

setRedirectInSameState

public void setRedirectInSameState(boolean redirectInSameState)

setEmbeddedMode

public void setEmbeddedMode()

Spring Web Flow