spring-framework / org.springframework.mock.web

Package org.springframework.mock.web

Types

DelegatingServletInputStream

open class DelegatingServletInputStream : ServletInputStream

Delegating implementation of javax.servlet.ServletInputStream.

Used by MockHttpServletRequest; typically not directly used for testing application controllers.

DelegatingServletOutputStream

open class DelegatingServletOutputStream : ServletOutputStream

Delegating implementation of javax.servlet.ServletOutputStream.

Used by MockHttpServletResponse; typically not directly used for testing application controllers.

MockAsyncContext

open class MockAsyncContext : AsyncContext

Mock implementation of the AsyncContext interface.

MockBodyContent

open class MockBodyContent : BodyContent

Mock implementation of the javax.servlet.jsp.tagext.BodyContent class. Only necessary for testing applications when testing custom JSP tags.

MockExpressionEvaluator

open class MockExpressionEvaluator : ExpressionEvaluator

Mock implementation of the JSP 2.0 javax.servlet.jsp.el.ExpressionEvaluator interface, delegating to the Apache JSTL ExpressionEvaluatorManager. Only necessary for testing applications when testing custom JSP tags.

Note that the Apache JSTL implementation (jstl.jar, standard.jar) has to be available on the class path to use this expression evaluator.

MockFilterChain

open class MockFilterChain : FilterChain

Mock implementation of the javax.servlet.FilterChain interface.

A MockFilterChain can be configured with one or more filters and a Servlet to invoke. The first time the chain is called, it invokes all filters and the Servlet, and saves the request and response. Subsequent invocations raise an IllegalStateException unless #reset() is called.

MockFilterConfig

open class MockFilterConfig : FilterConfig

Mock implementation of the javax.servlet.FilterConfig interface.

Used for testing the web framework; also useful for testing custom javax.servlet.Filter implementations.

MockJspWriter

open class MockJspWriter : JspWriter

Mock implementation of the javax.servlet.jsp.JspWriter class. Only necessary for testing applications when testing custom JSP tags.

MockMultipartHttpServletRequest

open class MockMultipartHttpServletRequest : MockHttpServletRequest, MultipartHttpServletRequest

Mock implementation of the org.springframework.web.multipart.MultipartHttpServletRequest interface.

As of Spring 5.0, this set of mocks is designed on a Servlet 4.0 baseline.

Useful for testing application controllers that access multipart uploads. MockMultipartFile can be used to populate these mock requests with files.

MockPageContext

open class MockPageContext : PageContext

Mock implementation of the javax.servlet.jsp.PageContext interface. Only necessary for testing applications when testing custom JSP tags.

Note: Expects initialization via the constructor rather than via the PageContext.initialize method. Does not support writing to a JspWriter, request dispatching, or handlePageException calls.

MockPart

open class MockPart : Part

Mock implementation of javax.servlet.http.Part.

MockRequestDispatcher

open class MockRequestDispatcher : RequestDispatcher

Mock implementation of the javax.servlet.RequestDispatcher interface.

MockServletContext

open class MockServletContext : ServletContext

Mock implementation of the javax.servlet.ServletContext interface.

As of Spring 5.0, this set of mocks is designed on a Servlet 4.0 baseline.

Compatible with Servlet 3.1 but can be configured to expose a specific version through #setMajorVersion/#setMinorVersion; default is 3.1. Note that Servlet 3.1 support is limited: servlet, filter and listener registration methods are not supported; neither is JSP configuration. We generally do not recommend to unit test your ServletContainerInitializers and WebApplicationInitializers which is where those registration methods would be used.

For setting up a full WebApplicationContext in a test environment, you can use AnnotationConfigWebApplicationContext, XmlWebApplicationContext, or GenericWebApplicationContext, passing in a corresponding MockServletContext instance. Consider configuring your MockServletContext with a FileSystemResourceLoader in order to interpret resource paths as relative filesystem locations.

MockSessionCookieConfig

open class MockSessionCookieConfig : SessionCookieConfig

Mock implementation of the javax.servlet.SessionCookieConfig interface.

PassThroughFilterChain

open class PassThroughFilterChain : FilterChain

Implementation of the javax.servlet.FilterConfig interface which simply passes the call through to a given Filter/FilterChain combination (indicating the next Filter in the chain along with the FilterChain that it is supposed to work on) or to a given Servlet (indicating the end of the chain).