org.springframework.webflow.test
Class MockRequestContext

java.lang.Object
  extended by org.springframework.webflow.test.MockRequestContext
All Implemented Interfaces:
RequestContext
Direct Known Subclasses:
MockRequestControlContext

public class MockRequestContext
extends java.lang.Object
implements RequestContext

Mock implementation of the RequestContext interface to facilitate standalone flow artifact (e.g. action) unit tests.

Author:
Keith Donald, Erwin Vervaet
See Also:
RequestContext, Action

Constructor Summary
MockRequestContext()
          Creates a new mock request context with the following defaults: A flow execution context with a active session of flow "mockFlow" in state "mockState".
MockRequestContext(Flow flow)
          Creates a new mock request context with the following defaults: A flow execution context with an active session for the specified flow.
MockRequestContext(ParameterMap requestParameterMap)
          Creates a new mock request context with the following defaults: A flow execution context with a active session of flow "mockFlow" in state "mockState".
 
Method Summary
 FlowDefinition getActiveFlow()
          Returns the definition of the flow that is currently executing.
 MutableAttributeMap getAttributeMap()
          Returns the contained mutable context attribute map allowing setting of mock context attributes.
 AttributeMap getAttributes()
          Returns a context map for accessing arbitrary attributes about the state of the current request.
 MutableAttributeMap getConversationScope()
          Returns a mutable accessor for accessing and/or setting attributes in conversation scope.
 StateDefinition getCurrentState()
          Returns the current state of the executing flow.
 ExternalContext getExternalContext()
          Returns the external client context that originated (or triggered) this request.
 MutableAttributeMap getFlashScope()
          Returns a mutable accessor for accessing and/or setting attributes in flash scope.
 FlowExecutionContext getFlowExecutionContext()
          Returns contextual information about the flow execution itself.
 MutableAttributeMap getFlowScope()
          Returns a mutable accessor for accessing and/or setting attributes in flow scope.
 Event getLastEvent()
          Returns the last event signaled during this request.
 TransitionDefinition getLastTransition()
          Returns the last state transition that executed in this request.
 MockExternalContext getMockExternalContext()
          Returns the external context as a MockExternalContext.
 MockFlowExecutionContext getMockFlowExecutionContext()
          Returns the flow execution context as a MockFlowExecutionContext.
 AttributeMap getModel()
          Returns the data model capturing the state of this context, suitable for exposing to clients (mostly web views).
 ParameterMap getRequestParameters()
          Returns the immutable input parameters associated with this request into Spring Web Flow.
 MutableAttributeMap getRequestScope()
          Returns a mutable accessor for accessing and/or setting attributes in request scope.
 void putRequestParameter(java.lang.String parameterName, java.lang.String parameterValue)
          Adds a request parameter to the configured external context.
 void putRequestParameter(java.lang.String parameterName, java.lang.String[] parameterValues)
          Adds a multi-valued request parameter to the configured external context.
 void removeAttribute(java.lang.String attributeName)
          Remove a request context attribute.
 void setActiveSession(FlowSession flowSession)
          Sets the active flow session of the executing flow associated with this request.
 void setAttribute(java.lang.String attributeName, java.lang.Object attributeValue)
          Set a request context attribute.
 void setAttributes(AttributeMap attributes)
          Set the contextual attributes describing the state of this request.
 void setExternalContext(ExternalContext externalContext)
          Sets the external context.
 void setFlowExecutionContext(FlowExecutionContext flowExecutionContext)
          Sets the flow execution context.
 void setLastEvent(Event lastEvent)
          Set the last event that occured in this request context.
 void setLastTransition(Transition lastTransition)
          Set the last transition that executed in this request context.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MockRequestContext

public MockRequestContext()
Creates a new mock request context with the following defaults: To add request parameters to this request, use the putRequestParameter(String, String) method.


MockRequestContext

public MockRequestContext(Flow flow)
Creates a new mock request context with the following defaults: To add request parameters to this request, use the putRequestParameter(String, String) method.


MockRequestContext

public MockRequestContext(ParameterMap requestParameterMap)
Creates a new mock request context with the following defaults:

Method Detail

getActiveFlow

public FlowDefinition getActiveFlow()
Description copied from interface: RequestContext
Returns the definition of the flow that is currently executing.

Specified by:
getActiveFlow in interface RequestContext
Returns:
the flow definition for the active session

getCurrentState

public StateDefinition getCurrentState()
Description copied from interface: RequestContext
Returns the current state of the executing flow. May return null if this flow execution is in the process of starting and has not yet entered its start state.

Specified by:
getCurrentState in interface RequestContext
Returns:
the current state, or null if in the process of starting

getRequestScope

public MutableAttributeMap getRequestScope()
Description copied from interface: RequestContext
Returns a mutable accessor for accessing and/or setting attributes in request scope. Request scoped attributes exist for the duration of this request only.

Specified by:
getRequestScope in interface RequestContext
Returns:
the request scope

getFlashScope

public MutableAttributeMap getFlashScope()
Description copied from interface: RequestContext
Returns a mutable accessor for accessing and/or setting attributes in flash scope. Flash scoped attributes exist untill the next event is signaled in the flow execution.

Specified by:
getFlashScope in interface RequestContext
Returns:
the flash scope

getFlowScope

public MutableAttributeMap getFlowScope()
Description copied from interface: RequestContext
Returns a mutable accessor 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 interface RequestContext
Returns:
the flow scope
See Also:
FlowSession

getConversationScope

public MutableAttributeMap 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 interface RequestContext
Returns:
the conversation scope
See Also:
FlowExecutionContext

getRequestParameters

public ParameterMap 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 interface RequestContext
See Also:
RequestContext.getExternalContext()

getExternalContext

public ExternalContext 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 a ServletExternalContext for servlets or a PortletExternalContext for portlets. 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 interface RequestContext
Returns:
the originating external context, the one that triggered the current execution request

getFlowExecutionContext

public FlowExecutionContext 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 interface RequestContext
Returns:
the flow execution context

getLastEvent

public Event getLastEvent()
Description copied from interface: RequestContext
Returns the last event signaled during this request. The event may or may not have caused a state transition to happen.

Specified by:
getLastEvent in interface RequestContext
Returns:
the last signaled event, or null if no event has been signaled yet

getLastTransition

public TransitionDefinition getLastTransition()
Description copied from interface: RequestContext
Returns the last state transition that executed in this request.

Specified by:
getLastTransition in interface RequestContext
Returns:
the last transition, or null if no transition has occured yet

getAttributes

public AttributeMap getAttributes()
Description copied from interface: RequestContext
Returns a context map for accessing arbitrary attributes about the state of the current request. These attributes may be used to influence flow execution behavior.

Specified by:
getAttributes in interface RequestContext
Returns:
the current attributes of this request, or empty if not set

setAttributes

public void setAttributes(AttributeMap attributes)
Description copied from interface: RequestContext
Set the contextual attributes describing the state of this request. Overwrites any pre-existing collection.

Specified by:
setAttributes in interface RequestContext
Parameters:
attributes - the attributes

getModel

public AttributeMap getModel()
Description copied from interface: RequestContext
Returns the data model capturing the state of this context, suitable for exposing to clients (mostly web views). Typically the model will contain the union of the data available in request, flash, session and conversation scope.

Specified by:
getModel in interface RequestContext
Returns:
the model that can be exposed to a client view for rendering purposes

setActiveSession

public void setActiveSession(FlowSession flowSession)
Sets the active flow session of the executing flow associated with this request. This will influence getActiveFlow() and getCurrentState(), as well as getFlowScope() and getFlashScope().


setExternalContext

public void setExternalContext(ExternalContext externalContext)
Sets the external context.


setFlowExecutionContext

public void setFlowExecutionContext(FlowExecutionContext flowExecutionContext)
Sets the flow execution context.


setLastEvent

public void setLastEvent(Event lastEvent)
Set the last event that occured in this request context.

Parameters:
lastEvent - the event to set

setLastTransition

public void setLastTransition(Transition lastTransition)
Set the last transition that executed in this request context.

Parameters:
lastTransition - the last transition to set

setAttribute

public void setAttribute(java.lang.String attributeName,
                         java.lang.Object attributeValue)
Set a request context attribute.

Parameters:
attributeName - the attribute name
attributeValue - the attribute value

removeAttribute

public void removeAttribute(java.lang.String attributeName)
Remove a request context attribute.

Parameters:
attributeName - the attribute name

getAttributeMap

public MutableAttributeMap getAttributeMap()
Returns the contained mutable context attribute map allowing setting of mock context attributes.

Returns:
the attribute map

getMockFlowExecutionContext

public MockFlowExecutionContext getMockFlowExecutionContext()
Returns the flow execution context as a MockFlowExecutionContext.


getMockExternalContext

public MockExternalContext getMockExternalContext()
Returns the external context as a MockExternalContext.


putRequestParameter

public void putRequestParameter(java.lang.String parameterName,
                                java.lang.String parameterValue)
Adds a request parameter to the configured external context.

Parameters:
parameterName - the parameter name
parameterValue - the parameter value

putRequestParameter

public void putRequestParameter(java.lang.String parameterName,
                                java.lang.String[] parameterValues)
Adds a multi-valued request parameter to the configured external context.

Parameters:
parameterName - the parameter name
parameterValues - the parameter values


Copyright © 2004-2007. All Rights Reserved.