Package org.springframework.webflow.test
Class MockExternalContext
java.lang.Object
org.springframework.webflow.test.MockExternalContext
- All Implemented Interfaces:
ExternalContext
Mock implementation of the
ExternalContext
interface.- Author:
- Keith Donald
- See Also:
-
Constructor Summary
ConstructorDescriptionCreates a mock external context with an empty request parameter map.MockExternalContext
(ParameterMap requestParameterMap) Creates a mock external context with the specified parameters in the request parameter map. -
Method Summary
Modifier and TypeMethodDescriptionProvides access to the external application map, providing a storage for data local to the current user application and accessible to both internal and external SWF artifacts.Returns the logical path to the application hosting this external context.Provides access to the user's principal security object.boolean
Returns the flag indicating if an external redirect response has been requested by the flow.Returns the URL to redirect to.boolean
Returns the flag indicating if a flow definition redirect response has been requested by the flow.boolean
Returns the flag indicating if a flow execution redirect response has been requested by the flow.getFlowExecutionUrl
(String flowId, String flowExecutionKey) Get a flow execution URL for the execution with the provided key.Returns the id of the flow definition to redirect to.Returns the input to pass the flow definition through the redirect.Provides access to the global external session map, providing a storage for data globally accross the user session and accessible to both internal and external SWF artifacts.Returns the client locale.Returns the request parameter map as aMockParameterMap
for convenient access in a unit test.Returns the implementation of this mock context's response writer.Provides access to the context object for the current environment.Provides access to the request object for the current environment.Provides access to the response object for the current environment.boolean
If a redirect response has been requested, indicates if the redirect should be issued from a popup dialog.Provides access to the external request attribute map, providing a storage for data local to the current user request and accessible to both internal and external SWF artifacts.Provides access to the parameters associated with the user request that led to SWF being called.Get a writer for writing out a response.Provides access to the external session map, providing a storage for data local to the current user session and accessible to both internal and external SWF artifacts.boolean
Returns true if the current request is an asynchronous Ajax request.boolean
boolean
Is a render response allowed to be written for this request? Always return false after a response has been completed.boolean
Has the response been completed? Response complete status can be achieved by: Writing out the response and callingExternalContext.recordResponseComplete()
, or Calling one of the redirect request methodsboolean
Returns true if the response has been completed with flow execution redirect request.void
putRequestParameter
(String parameterName, String parameterValue) Puts a request parameter into the mock parameter map.void
putRequestParameter
(String parameterName, String[] parameterValues) Puts a multi-valued request parameter into the mock parameter map.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
Called by flow artifacts such as View states and end states to indicate they handled the response, typically by writing out content to the response stream.void
Request a redirect to an arbitrary resource location.void
requestFlowDefinitionRedirect
(String flowId, MutableAttributeMap<?> input) Request that a flow definition redirect be performed by the calling environment.void
Request that a flow execution redirect be performed by the calling environment.void
Request that the current redirect requested be sent to the client in a manner that causes the client to issue the redirect from a popup dialog.void
setAjaxRequest
(boolean ajaxRequest) Set whether this request is an ajax request.void
setApplicationMap
(SharedAttributeMap<Object> applicationMap) Set the application attribute map.void
setContextPath
(String contextPath) Set the context path of the application.void
setCurrentUser
(String currentUser) Convenience method that sets the current user principal as a string.void
setCurrentUser
(Principal currentUser) Sets the current user principal.void
setEventId
(String eventId) Sets the id of the event that should be signaled by this context.void
setGlobalSessionMap
(SharedAttributeMap<Object> globalSessionMap) Set the global session attribute map.void
Sets the client locale.void
setNativeContext
(Object nativeContext) Set the native context object.void
setNativeRequest
(Object nativeRequest) Set the native request object.void
setNativeResponse
(Object nativeResponse) Set the native response object.void
setRequestMap
(MutableAttributeMap<Object> requestMap) Set the request attribute map.void
setRequestParameterMap
(ParameterMap requestParameterMap) Set the request parameter map.void
setResponseAllowed
(boolean responseAllowed) Set the response allows flag to a value for testing.void
setSessionMap
(SharedAttributeMap<Object> sessionMap) Set the session attribute map.
-
Constructor Details
-
MockExternalContext
public MockExternalContext()Creates a mock external context with an empty request parameter map. Allows for bean style usage. -
MockExternalContext
Creates a mock external context with the specified parameters in the request parameter map. All other properties of the external context can be set using the appropriate setter.- Parameters:
requestParameterMap
- the request parameters
-
-
Method Details
-
getContextPath
Description copied from interface:ExternalContext
Returns the logical path to the application hosting this external context.- Specified by:
getContextPath
in interfaceExternalContext
- Returns:
- the context path
-
getRequestParameterMap
Description copied from interface:ExternalContext
Provides access to the parameters associated with the user request that led to SWF being called. This map is expected to be immutable and cannot be changed.- Specified by:
getRequestParameterMap
in interfaceExternalContext
- Returns:
- the immutable request parameter map
-
getRequestMap
Description copied from interface:ExternalContext
Provides access to the external request attribute map, providing a storage for data local to the current user request and accessible to both internal and external SWF artifacts.- Specified by:
getRequestMap
in interfaceExternalContext
- Returns:
- the mutable request attribute map
-
getSessionMap
Description copied from interface:ExternalContext
Provides access to the external session map, providing a storage for data local to the current user session and accessible to both internal and external SWF artifacts.- Specified by:
getSessionMap
in interfaceExternalContext
- Returns:
- the mutable session attribute map
-
getGlobalSessionMap
Description copied from interface:ExternalContext
Provides access to the global external session map, providing a storage for data globally accross the user session and accessible to both internal and external SWF artifacts.Note: most external context implementations do not distinguish between the concept of a "local" user session scope and a "global" session scope. Otherwise this method returns the same map as calling
ExternalContext.getSessionMap()
.- Specified by:
getGlobalSessionMap
in interfaceExternalContext
- Returns:
- the mutable global session attribute map
-
getApplicationMap
Description copied from interface:ExternalContext
Provides access to the external application map, providing a storage for data local to the current user application and accessible to both internal and external SWF artifacts.- Specified by:
getApplicationMap
in interfaceExternalContext
- Returns:
- the mutable application attribute map
-
getCurrentUser
Description copied from interface:ExternalContext
Provides access to the user's principal security object.- Specified by:
getCurrentUser
in interfaceExternalContext
- Returns:
- the user principal
-
getLocale
Description copied from interface:ExternalContext
Returns the client locale.- Specified by:
getLocale
in interfaceExternalContext
- Returns:
- the locale
-
getNativeContext
Description copied from interface:ExternalContext
Provides access to the context object for the current environment.- Specified by:
getNativeContext
in interfaceExternalContext
- Returns:
- the environment specific context object
-
getNativeRequest
Description copied from interface:ExternalContext
Provides access to the request object for the current environment.- Specified by:
getNativeRequest
in interfaceExternalContext
- Returns:
- the environment specific request object.
-
getNativeResponse
Description copied from interface:ExternalContext
Provides access to the response object for the current environment.- Specified by:
getNativeResponse
in interfaceExternalContext
- Returns:
- the environment specific response object.
-
isAjaxRequest
public boolean isAjaxRequest()Description copied from interface:ExternalContext
Returns true if the current request is an asynchronous Ajax request.- Specified by:
isAjaxRequest
in interfaceExternalContext
- Returns:
- true if the current request is an Ajax request
-
getFlowExecutionUrl
Description copied from interface:ExternalContext
Get a flow execution URL for the execution with the provided key. Typically used by response writers that write out references to the flow execution to support postback on a subsequent request. The URL returned is encoded.- Specified by:
getFlowExecutionUrl
in interfaceExternalContext
- Parameters:
flowId
- the flow definition idflowExecutionKey
- the flow execution key- Returns:
- the flow execution URL
-
getResponseWriter
Description copied from interface:ExternalContext
Get a writer for writing out a response.- Specified by:
getResponseWriter
in interfaceExternalContext
- Returns:
- the writer
-
isResponseAllowed
public boolean isResponseAllowed()Description copied from interface:ExternalContext
Is a render response allowed to be written for this request? Always return false after a response has been completed. May return false before that to indicate a response is not allowed to be completed.- Specified by:
isResponseAllowed
in interfaceExternalContext
- Returns:
- true if yes, false otherwise
-
isResponseComplete
public boolean isResponseComplete()Description copied from interface:ExternalContext
Has the response been completed? Response complete status can be achieved by:- Writing out the response and calling
ExternalContext.recordResponseComplete()
, or - Calling one of the redirect request methods
- Specified by:
isResponseComplete
in interfaceExternalContext
- Returns:
- true if yes, false otherwise
- See Also:
- Writing out the response and calling
-
recordResponseComplete
public void recordResponseComplete()Description copied from interface:ExternalContext
Called by flow artifacts such as View states and end states to indicate they handled the response, typically by writing out content to the response stream. Setting this flag allows this external context to know the response was handled, and that it not need to take additional response handling action itself.- Specified by:
recordResponseComplete
in interfaceExternalContext
-
isResponseCompleteFlowExecutionRedirect
public boolean isResponseCompleteFlowExecutionRedirect()Description copied from interface:ExternalContext
Returns true if the response has been completed with flow execution redirect request.- Specified by:
isResponseCompleteFlowExecutionRedirect
in interfaceExternalContext
- Returns:
- true if a redirect response has been completed
- See Also:
-
requestFlowExecutionRedirect
Description copied from interface:ExternalContext
Request that a flow execution redirect be performed by the calling environment. Typically called from within a flow execution to request a refresh operation, usually to support "refresh after event processing" behavior. Calling this method also sets responseComplete status to true.- Specified by:
requestFlowExecutionRedirect
in interfaceExternalContext
- Throws:
IllegalStateException
- if the response has completed- See Also:
-
requestFlowDefinitionRedirect
public void requestFlowDefinitionRedirect(String flowId, MutableAttributeMap<?> input) throws IllegalStateException Description copied from interface:ExternalContext
Request that a flow definition redirect be performed by the calling environment. Typically called from within a flow execution end state to request starting a new, independent execution of a flow in a chain-like manner. Calling this method also sets responseComplete status to true.- Specified by:
requestFlowDefinitionRedirect
in interfaceExternalContext
- Parameters:
flowId
- the id of the flow definition to redirect toinput
- input to pass the flow; this input is generally encoded the url to launch the flow- Throws:
IllegalStateException
- if the response has completed- See Also:
-
requestExternalRedirect
Description copied from interface:ExternalContext
Request a redirect to an arbitrary resource location. May not be supported in some environments. Calling this method also sets responseComplete status to true.- Specified by:
requestExternalRedirect
in interfaceExternalContext
- Parameters:
uri
- the location of the resource to redirect to- Throws:
IllegalStateException
- if the response has completed- See Also:
-
requestRedirectInPopup
Description copied from interface:ExternalContext
Request that the current redirect requested be sent to the client in a manner that causes the client to issue the redirect from a popup dialog. Only call this method after a redirect has been requested.- Specified by:
requestRedirectInPopup
in interfaceExternalContext
- Throws:
IllegalStateException
- if a redirect has not been requested- See Also:
-
setContextPath
Set the context path of the application.- Parameters:
contextPath
- the context path
-
setRequestParameterMap
Set the request parameter map.- See Also:
-
setRequestMap
Set the request attribute map.- See Also:
-
setNativeContext
Set the native context object.- Parameters:
nativeContext
- the native context
-
setNativeRequest
Set the native request object.- Parameters:
nativeRequest
- the native request object
-
setNativeResponse
Set the native response object.- Parameters:
nativeResponse
- the native response object
-
setCurrentUser
Sets the current user principal.- Parameters:
currentUser
- the current user
-
setCurrentUser
Convenience method that sets the current user principal as a string.- Parameters:
currentUser
- the current user name
-
setLocale
Sets the client locale.- Parameters:
locale
- the locale
-
getMockRequestParameterMap
Returns the request parameter map as aMockParameterMap
for convenient access in a unit test.- See Also:
-
putRequestParameter
Puts a request parameter into the mock parameter map.- Parameters:
parameterName
- the parameter nameparameterValue
- the parameter value
-
putRequestParameter
Puts a multi-valued request parameter into the mock parameter map.- 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
-
setEventId
Sets the id of the event that should be signaled by this context. For use when resuming a flow. This method depends on a MockViewFactory being configured for parsing the event id on a resume operation.- Parameters:
eventId
- the id of the event to signal
-
setAjaxRequest
public void setAjaxRequest(boolean ajaxRequest) Set whether this request is an ajax request.- Parameters:
ajaxRequest
- true or false
-
setResponseAllowed
public void setResponseAllowed(boolean responseAllowed) Set the response allows flag to a value for testing.- Parameters:
responseAllowed
- true or false
-
getMockResponseWriter
Returns the implementation of this mock context's response writer.- Returns:
- the underlying string writer to use for asserting a specific response was written
-
getFlowExecutionRedirectRequested
public boolean getFlowExecutionRedirectRequested()Returns the flag indicating if a flow execution redirect response has been requested by the flow. -
getFlowDefinitionRedirectRequested
public boolean getFlowDefinitionRedirectRequested()Returns the flag indicating if a flow definition redirect response has been requested by the flow. -
getFlowRedirectFlowId
Returns the id of the flow definition to redirect to. Only set whengetFlowDefinitionRedirectRequested()
returns true. -
getFlowRedirectFlowInput
Returns the input to pass the flow definition through the redirect. Only set whengetFlowDefinitionRedirectRequested()
returns true. -
getExternalRedirectRequested
public boolean getExternalRedirectRequested()Returns the flag indicating if an external redirect response has been requested by the flow. -
getExternalRedirectUrl
Returns the URL to redirect to. Only set ifgetExternalRedirectRequested()
returns true. -
getRedirectInPopup
public boolean getRedirectInPopup()If a redirect response has been requested, indicates if the redirect should be issued from a popup dialog. -
isRedirectRequested
public boolean isRedirectRequested()
-