Package org.springframework.webflow.test
Class MockRequestContext
java.lang.Object
org.springframework.webflow.test.MockRequestContext
- All Implemented Interfaces:
RequestContext
- Direct Known Subclasses:
MockRequestControlContext
Mock implementation of the
RequestContext
interface to facilitate standalone flow artifact (e.g. action)
unit tests.- Author:
- Keith Donald, Erwin Vervaet
- See Also:
-
Constructor Summary
ConstructorDescriptionConvenience constructor that creates a new mock request context with the following defaults: A mock flow execution context with a active session of flow "mockFlow" in state "mockState".MockRequestContext
(ParameterMap requestParameterMap) Convenience constructor that creates a new mock request context with the following defaults: A mock flow execution context with a active session of flow "mockFlow" in state "mockState".MockRequestContext
(Flow flow) Convenience constructor that creates a new mock request context with the following defaults: A mock flow execution context with an active session for the specified flow.MockRequestContext
(FlowExecutionContext flowExecutionContext) Creates a new mock request context with the provided flow execution context. -
Method Summary
Modifier and TypeMethodDescriptionReturns the definition of the flow that is currently executing.Returns the contained mutable contextattribute map
allowing setting of mock context attributes.Returns a context map for accessing attributes about the state of the current request.Returns a mutable accessor for accessing and/or setting attributes in conversation scope.Returns the current event being processed by this flow.Returns the current state of the executing flow.Returns the current transition executing in this request.Returns the current view in use; if not null, the view returned is about to be rendered, is rendering, is processing a user event, or has finished user event processing and the current ViewState is exiting due to a state transition.Returns the external client context that originated (or triggered) this request.Returns a mutable map for accessing and/or setting attributes in flash scope.Returns contextual information about the flow execution itself.Returns the URL of this flow execution.Returns a mutable map for accessing and/or setting attributes in flow scope.getMatchingTransition
(String eventId) Returns the transition that would execute on the occurrence of the given event.Returns the message context of this request.Returns the external context as aMockExternalContext
.Returns the flow execution context as aMockFlowExecutionContext
.Returns the immutable input parameters associated with this request into Spring Web Flow.Returns a mutable map for accessing and/or setting attributes in request scope.Returns the root flow definition for this request context.Returns a mutable map for accessing and/or setting attributes in view scope.boolean
Returns true if the flow is currently active and in a view state.void
putRequestParameter
(String parameterName, String parameterValue) Adds a request parameter to the configured external context.void
putRequestParameter
(String parameterName, String[] parameterValues) Adds a multi-valued request parameter to the configured external context.void
putRequestParameter
(String parameterName, List<org.springframework.web.multipart.MultipartFile> parameterValue) Puts a multi-valued MultipartFile request parameter into the mock parameter map.void
putRequestParameter
(String parameterName, org.springframework.web.multipart.MultipartFile parameterValue) Puts a MultipartFile request parameter into the mock parameter map.void
removeAttribute
(String attributeName) Remove a request context attribute.void
void
setActiveSession
(FlowSession flowSession) Sets the active flow session of the executing flow associated with this request.void
setAttribute
(String attributeName, Object attributeValue) Set a request context attribute.void
setCurrentEvent
(Event event) Set the current event being processed by this flow.void
setCurrentTransition
(Transition transition) Set the current transition executing in this request context.void
setCurrentView
(View currentView) Set the current view in this request context.void
setExternalContext
(ExternalContext externalContext) Sets the external context.void
setFlowExecutionContext
(FlowExecutionContext flowExecutionContext) Sets the flow execution context.
-
Constructor Details
-
MockRequestContext
public MockRequestContext()Convenience constructor that creates a new mock request context with the following defaults:- A mock flow execution context with a active session of flow "mockFlow" in state "mockState".
- A mock external context with no request parameters set.
putRequestParameter(String, String)
method. -
MockRequestContext
Convenience constructor that creates a new mock request context with the following defaults:- A mock flow execution context with an active session for the specified flow.
- A mock external context with no request parameters set.
putRequestParameter(String, String)
method.- Parameters:
flow
- the flow definition
-
MockRequestContext
Convenience constructor that creates a new mock request context with the following defaults:- A mock flow execution context with a active session of flow "mockFlow" in state "mockState".
- A mock external context with the provided parameters set.
-
MockRequestContext
Creates a new mock request context with the provided flow execution context. To add request parameters to this request, use theputRequestParameter(String, String)
method.- Parameters:
flowExecutionContext
- the flow execution context
-
-
Method Details
-
getActiveFlow
Description copied from interface:RequestContext
Returns the definition of the flow that is currently executing.- Specified by:
getActiveFlow
in interfaceRequestContext
- Returns:
- the flow definition for the active session
- See Also:
-
getCurrentState
Description copied from interface:RequestContext
Returns the current state of the executing flow. Returnsnull
if the active flow's start state has not yet been entered.- Specified by:
getCurrentState
in interfaceRequestContext
- Returns:
- the current state, or
null
if in the process of starting - See Also:
-
getMatchingTransition
Description copied from interface:RequestContext
Returns the transition that would execute on the occurrence of the given event.- Specified by:
getMatchingTransition
in interfaceRequestContext
- Parameters:
eventId
- the id of the user event- Returns:
- the transition that would trigger, or
null
if no transition matches - Throws:
IllegalStateException
- if this flow execution is not active- See Also:
-
inViewState
public boolean inViewState()Description copied from interface:RequestContext
Returns true if the flow is currently active and in a view state. When in a view stateRequestContext.getViewScope()
, can be safely called.- Specified by:
inViewState
in interfaceRequestContext
- Returns:
- true if in a view state, false if not
- See Also:
-
getRequestScope
Description copied from interface:RequestContext
Returns a mutable map for accessing and/or setting attributes in request scope. Request scoped attributes exist for the duration of this request only.- Specified by:
getRequestScope
in interfaceRequestContext
- Returns:
- the request scope
-
getFlashScope
Description copied from interface:RequestContext
Returns a mutable map for accessing and/or setting attributes in flash scope. Flash scoped attributes exist until the next event is signaled in the flow execution.- Specified by:
getFlashScope
in interfaceRequestContext
- Returns:
- the flash scope
-
getViewScope
Description copied from interface:RequestContext
Returns a mutable map for accessing and/or setting attributes in view scope. View scoped attributes exist for the life of the current view state.- Specified by:
getViewScope
in interfaceRequestContext
- Returns:
- the view scope
- Throws:
IllegalStateException
- if this flow is not in a view-state or the flow execution is not active- See Also:
-
getFlowScope
Description copied from interface:RequestContext
Returns a mutable map for accessing and/or setting attributes in flow scope. Flow scoped attributes exist for the life of the active flow session.- Specified by:
getFlowScope
in interfaceRequestContext
- Returns:
- the flow scope
- See Also:
-
getConversationScope
Description copied from interface:RequestContext
Returns a mutable accessor for accessing and/or setting attributes in conversation scope. Conversation scoped attributes exist for the life of the executing flow and are shared across all flow sessions.- Specified by:
getConversationScope
in interfaceRequestContext
- Returns:
- the conversation scope
- See Also:
-
getRequestParameters
Description copied from interface:RequestContext
Returns the immutable input parameters associated with this request into Spring Web Flow. The map returned is immutable and cannot be changed.This is typically a convenient shortcut for accessing the
ExternalContext.getRequestParameterMap()
directly.- Specified by:
getRequestParameters
in interfaceRequestContext
- See Also:
-
getMessageContext
Description copied from interface:RequestContext
Returns the message context of this request. Useful for recording messages during the course of flow execution for display to the client.- Specified by:
getMessageContext
in interfaceRequestContext
- Returns:
- the message context
-
getExternalContext
Description copied from interface:RequestContext
Returns the external client context that originated (or triggered) this request.Acting as a facade, the returned context object provides a single point of access to the calling client's environment. It provides normalized access to attributes of the client environment without tying you to specific constructs within that environment.
In addition, this context may be downcastable to a specific context type for a specific client environment, such as Servlets. Such downcasting will give you full access to a native HttpServletRequest, for example. With that said, for portability reasons you should avoid coupling your flow artifacts to a specific deployment environment when possible.
- Specified by:
getExternalContext
in interfaceRequestContext
- Returns:
- the originating external context, the one that triggered the current execution request
-
getFlowExecutionContext
Description copied from interface:RequestContext
Returns contextual information about the flow execution itself. Information in this context typically spans more than one request.- Specified by:
getFlowExecutionContext
in interfaceRequestContext
- Returns:
- the flow execution context
-
getCurrentEvent
Description copied from interface:RequestContext
Returns the current event being processed by this flow. The event may or may not have caused a state transition to happen.- Specified by:
getCurrentEvent
in interfaceRequestContext
- Returns:
- the current event, or null if no event has been signaled yet
-
getCurrentTransition
Description copied from interface:RequestContext
Returns the current transition executing in this request.- Specified by:
getCurrentTransition
in interfaceRequestContext
- Returns:
- the current transition, or
null
if no transition has occurred yet
-
getCurrentView
Description copied from interface:RequestContext
Returns the current view in use; if not null, the view returned is about to be rendered, is rendering, is processing a user event, or has finished user event processing and the current ViewState is exiting due to a state transition. Returnsnull
if the flow is not in a view state.- Specified by:
getCurrentView
in interfaceRequestContext
- Returns:
- the current view, or
null
if the flow is not in a view state
-
getAttributes
Description copied from interface:RequestContext
Returns a context map for accessing attributes about the state of the current request. These attributes may be used to influence flow execution behavior.- Specified by:
getAttributes
in interfaceRequestContext
- Returns:
- the current attributes of this request, or empty if none are set
-
getFlowExecutionUrl
Description copied from interface:RequestContext
Returns the URL of this flow execution. Needed by response writers that write out the URL of this flow execution to allow calling back this execution in a subsequent request.- Specified by:
getFlowExecutionUrl
in interfaceRequestContext
- Returns:
- the flow execution URL
-
sendFlowExecutionRedirect
public void sendFlowExecutionRedirect() -
setActiveSession
Sets the active flow session of the executing flow associated with this request. This will influencegetActiveFlow()
andgetCurrentState()
, as well asgetFlowScope()
andgetFlashScope()
. -
setExternalContext
Sets the external context. -
setFlowExecutionContext
Sets the flow execution context. -
setCurrentEvent
Set the current event being processed by this flow.- Parameters:
event
- the current event
-
setCurrentTransition
Set the current transition executing in this request context.- Parameters:
transition
- the current transition to set
-
setCurrentView
Set the current view in this request context.- Parameters:
currentView
- the current view
-
setAttribute
Set a request context attribute.- Parameters:
attributeName
- the attribute nameattributeValue
- the attribute value
-
removeAttribute
Remove a request context attribute.- Parameters:
attributeName
- the attribute name
-
putRequestParameter
Adds a request parameter to the configured external context.- Parameters:
parameterName
- the parameter nameparameterValue
- the parameter value
-
putRequestParameter
Adds a multi-valued request parameter to the configured external context.- Parameters:
parameterName
- the parameter nameparameterValues
- the parameter values
-
putRequestParameter
public void putRequestParameter(String parameterName, org.springframework.web.multipart.MultipartFile parameterValue) Puts a MultipartFile request parameter into the mock parameter map.- Parameters:
parameterName
- the parameter nameparameterValue
- the parameter value
-
putRequestParameter
public void putRequestParameter(String parameterName, List<org.springframework.web.multipart.MultipartFile> parameterValue) Puts a multi-valued MultipartFile request parameter into the mock parameter map.- Parameters:
parameterName
- the parameter nameparameterValue
- the parameter value
-
getRootFlow
Returns the root flow definition for this request context. Assumes aFlow
implementation. -
getAttributeMap
Returns the contained mutable contextattribute map
allowing setting of mock context attributes.- Returns:
- the attribute map
-
getMockFlowExecutionContext
Returns the flow execution context as aMockFlowExecutionContext
. -
getMockExternalContext
Returns the external context as aMockExternalContext
.
-