com.mockrunner.mock.web
Class WebMockObjectFactory

java.lang.Object
  extended by com.mockrunner.mock.web.WebMockObjectFactory
Direct Known Subclasses:
ActionMockObjectFactory

public class WebMockObjectFactory
extends java.lang.Object

Used to create all types of web mock objects. Maintains the necessary dependencies between the mock objects. If you use the mock objects returned by this factory in your tests you can be sure that they are all up to date.


Constructor Summary
WebMockObjectFactory()
          Creates a new set of mock objects.
WebMockObjectFactory(WebMockObjectFactory factory)
          Creates a set of mock objects based on another one.
WebMockObjectFactory(WebMockObjectFactory factory, boolean createNewSession)
          Creates a set of mock objects based on another one.
 
Method Summary
 void addRequestWrapper(java.lang.Class wrapper)
          Can be used to add a request wrapper.
 void addRequestWrapper(javax.servlet.http.HttpServletRequest wrapper)
          Can be used to add a request wrapper.
 void addResponseWrapper(java.lang.Class wrapper)
          Can be used to add a response wrapper.
 void addResponseWrapper(javax.servlet.http.HttpServletResponse wrapper)
          Can be used to add a response wrapper.
 MockFilterChain createMockFilterChain()
          Creates the MockFilterChain using new.
 MockFilterConfig createMockFilterConfig()
          Creates the MockFilterConfig using new.
 MockJspFactory createMockJspFactory()
          Creates the MockJspFactory using new.
 MockPageContext createMockPageContext()
          Creates the MockPageContext using new.
 MockHttpServletRequest createMockRequest()
          Creates the MockHttpServletRequest using new.
 MockHttpServletResponse createMockResponse()
          Creates the MockHttpServletResponse using new.
 MockServletConfig createMockServletConfig()
          Creates the MockServletConfig using new.
 MockServletContext createMockServletContext()
          Creates the MockServletContext using new.
 MockHttpSession createMockSession()
          Creates the MockHttpSession using new.
 javax.servlet.jsp.JspFactory getJspFactory()
          Returns the JspFactory.
 MockFilterChain getMockFilterChain()
          Returns the MockFilterChain.
 MockFilterConfig getMockFilterConfig()
          Returns the MockFilterConfig.
 MockJspFactory getMockJspFactory()
          Returns the MockJspFactory.
 MockPageContext getMockPageContext()
          Returns the MockPageContext.
 MockHttpServletRequest getMockRequest()
          Returns the MockHttpServletRequest.
 MockHttpServletResponse getMockResponse()
          Returns the MockHttpServletResponse.
 MockServletConfig getMockServletConfig()
          Returns the MockServletConfig
 MockServletContext getMockServletContext()
          Returns the MockServletContext.
 MockHttpSession getMockSession()
          Returns the MockHttpSession.
 MockHttpSession getSession()
          Deprecated. use getMockSession()
 javax.servlet.http.HttpServletRequest getWrappedRequest()
          Returns the wrapped HttpServletRequest.
 javax.servlet.http.HttpServletResponse getWrappedResponse()
          Returns the wrapped HttpServletResponse.
 void refresh()
          Refreshes the mock objects dependencies.
 void setDefaultJspFactory(javax.servlet.jsp.JspFactory jspFactory)
          Sets the default JspFactory by calling JspFactory.setDefaultFactory().
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WebMockObjectFactory

public WebMockObjectFactory()
Creates a new set of mock objects.


WebMockObjectFactory

public WebMockObjectFactory(WebMockObjectFactory factory)
Creates a set of mock objects based on another one. The created mock objects will have their own request and session objects, but they will share one ServletContext.

Parameters:
factory - the other factory
See Also:
BaseTestCase.createWebMockObjectFactory(WebMockObjectFactory)

WebMockObjectFactory

public WebMockObjectFactory(WebMockObjectFactory factory,
                            boolean createNewSession)
Creates a set of mock objects based on another one. You can specify, if the created mock objects should share the same session. They will share one ServletContext anyway.

Parameters:
factory - the other factory
createNewSession - true creates a new session, false uses the session from factory
See Also:
BaseTestCase.createWebMockObjectFactory(WebMockObjectFactory, boolean)
Method Detail

setDefaultJspFactory

public void setDefaultJspFactory(javax.servlet.jsp.JspFactory jspFactory)
Sets the default JspFactory by calling JspFactory.setDefaultFactory().

Parameters:
jspFactory - the JspFactory

refresh

public void refresh()
Refreshes the mock objects dependencies. May be called after setting request and response wrappers.


createMockServletContext

public MockServletContext createMockServletContext()
Creates the MockServletContext using new. This method can be overridden to return a subclass of MockServletContext.

Returns:
the MockServletContext

createMockServletConfig

public MockServletConfig createMockServletConfig()
Creates the MockServletConfig using new. This method can be overridden to return a subclass of MockServletConfig.

Returns:
the MockServletConfig

createMockResponse

public MockHttpServletResponse createMockResponse()
Creates the MockHttpServletResponse using new. This method can be overridden to return a subclass of MockHttpServletResponse.

Returns:
the MockHttpServletResponse

createMockRequest

public MockHttpServletRequest createMockRequest()
Creates the MockHttpServletRequest using new. This method can be overridden to return a subclass of MockHttpServletRequest.

Returns:
the MockHttpServletRequest

createMockSession

public MockHttpSession createMockSession()
Creates the MockHttpSession using new. This method can be overridden to return a subclass of MockHttpSession.

Returns:
the MockHttpSession

createMockPageContext

public MockPageContext createMockPageContext()
Creates the MockPageContext using new. This method can be overridden to return a subclass of MockPageContext.

Returns:
the MockPageContext

createMockFilterConfig

public MockFilterConfig createMockFilterConfig()
Creates the MockFilterConfig using new. This method can be overridden to return a subclass of MockFilterConfig.

Returns:
the MockFilterConfig

createMockFilterChain

public MockFilterChain createMockFilterChain()
Creates the MockFilterChain using new. This method can be overridden to return a subclass of MockFilterChain.

Returns:
the MockFilterChain

createMockJspFactory

public MockJspFactory createMockJspFactory()
Creates the MockJspFactory using new. This method can be overridden to return a subclass of MockJspFactory.

Returns:
the MockJspFactory

getMockServletConfig

public MockServletConfig getMockServletConfig()
Returns the MockServletConfig

Returns:
the MockServletConfig

getMockServletContext

public MockServletContext getMockServletContext()
Returns the MockServletContext.

Returns:
the MockServletContext

getMockRequest

public MockHttpServletRequest getMockRequest()
Returns the MockHttpServletRequest.

Returns:
the MockHttpServletRequest

getMockResponse

public MockHttpServletResponse getMockResponse()
Returns the MockHttpServletResponse.

Returns:
the MockHttpServletResponse

getWrappedRequest

public javax.servlet.http.HttpServletRequest getWrappedRequest()
Returns the wrapped HttpServletRequest. If no wrapper is specified, this method returns the mock request itself.

Returns:
the wrapped HttpServletRequest

getWrappedResponse

public javax.servlet.http.HttpServletResponse getWrappedResponse()
Returns the wrapped HttpServletResponse. If no wrapper is specified, this method returns the mock response itself.

Returns:
the wrapped HttpServletRequest

getMockSession

public MockHttpSession getMockSession()
Returns the MockHttpSession.

Returns:
the MockHttpSession

getSession

public MockHttpSession getSession()
Deprecated. use getMockSession()

Returns the MockHttpSession.

Returns:
the MockHttpSession

getMockPageContext

public MockPageContext getMockPageContext()
Returns the MockPageContext.

Returns:
the MockPageContext

getMockFilterConfig

public MockFilterConfig getMockFilterConfig()
Returns the MockFilterConfig.

Returns:
the MockFilterConfig

getMockFilterChain

public MockFilterChain getMockFilterChain()
Returns the MockFilterChain.

Returns:
the MockFilterChain

getMockJspFactory

public MockJspFactory getMockJspFactory()
Returns the MockJspFactory. If the current JspFactory is not an instance of MockJspFactory, null will be returned.

Returns:
the MockJspFactory

getJspFactory

public javax.servlet.jsp.JspFactory getJspFactory()
Returns the JspFactory.

Returns:
the JspFactory

addRequestWrapper

public void addRequestWrapper(java.lang.Class wrapper)
Can be used to add a request wrapper. All the test modules are using the wrapped request returned by getWrappedRequest(). The method getMockRequest() returns the mock request without any wrapper. Usually the wrapper is of type javax.servlet.http.HttpServletRequestWrapper. That's not absolutely necessary but the wrapper must define a constructor that takes a single javax.servlet.http.HttpServletRequest argument and must implement javax.servlet.http.HttpServletRequest.

Parameters:
wrapper - the wrapper class

addRequestWrapper

public void addRequestWrapper(javax.servlet.http.HttpServletRequest wrapper)
Can be used to add a request wrapper. All the test modules are using the wrapped request returned by getWrappedRequest(). The method getMockRequest() returns the mock request without any wrapper. Usually the wrapper is an instance of javax.servlet.http.HttpServletRequestWrapper and wraps the current request but that's not absolutely necessary. However, be careful if you want to add custom mock versions of javax.servlet.http.HttpServletRequest.

Parameters:
wrapper - the request wrapper

addResponseWrapper

public void addResponseWrapper(java.lang.Class wrapper)
Can be used to add a response wrapper. All the test modules are using the wrapped response returned by getWrappedResponse(). The method getMockResponse() returns the mock response without any wrapper. Usually the wrapper is of type javax.servlet.http.HttpServletResponseWrapper. That's not absolutely necessary but the wrapper must define a constructor that takes a single javax.servlet.http.HttpServletResponse argument and must implement javax.servlet.http.HttpServletResponse.

Parameters:
wrapper - the wrapper class

addResponseWrapper

public void addResponseWrapper(javax.servlet.http.HttpServletResponse wrapper)
Can be used to add a response wrapper. All the test modules are using the wrapped response returned by getWrappedResponse(). The method getMockResponse() returns the mock response without any wrapper. Usually the wrapper is an instance of javax.servlet.http.HttpServletResponseWrapper and wraps the current response but that's not absolutely necessary. However, be careful if you want to add custom mock versions of javax.servlet.http.HttpServletResponse.

Parameters:
wrapper - the wrapper