public final class MockMvc
extends java.lang.Object
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; import static org.springframework.test.web.servlet.setup.MockMvcBuilders.*; // ... WebApplicationContext wac = ...; MockMvc mockMvc = webAppContextSetup(wac).build(); mockMvc.perform(get("/form")) .andExpect(status().isOk()) .andExpect(content().mimeType("text/html")) .andExpect(forwardedUrl("/WEB-INF/layouts/main.jsp"));
Modifier and Type | Field and Description |
---|---|
private RequestBuilder |
defaultRequestBuilder |
private java.util.List<ResultHandler> |
defaultResultHandlers |
private java.util.List<ResultMatcher> |
defaultResultMatchers |
private Filter[] |
filters |
(package private) static java.lang.String |
MVC_RESULT_ATTRIBUTE |
private TestDispatcherServlet |
servlet |
private ServletContext |
servletContext |
Constructor and Description |
---|
MockMvc(TestDispatcherServlet servlet,
Filter... filters)
Private constructor, not for direct instantiation.
|
Modifier and Type | Method and Description |
---|---|
private void |
applyDefaultResultActions(MvcResult mvcResult) |
ResultActions |
perform(RequestBuilder requestBuilder)
Perform a request and return a type that allows chaining further
actions, such as asserting expectations, on the result.
|
(package private) void |
setDefaultRequest(RequestBuilder requestBuilder)
A default request builder merged into every performed request.
|
(package private) void |
setGlobalResultHandlers(java.util.List<ResultHandler> resultHandlers)
General actions to apply after every performed request.
|
(package private) void |
setGlobalResultMatchers(java.util.List<ResultMatcher> resultMatchers)
Expectations to assert after every performed request.
|
private MockHttpServletResponse |
unwrapResponseIfNecessary(ServletResponse servletResponse) |
static java.lang.String MVC_RESULT_ATTRIBUTE
private final TestDispatcherServlet servlet
private final Filter[] filters
private final ServletContext servletContext
@Nullable private RequestBuilder defaultRequestBuilder
private java.util.List<ResultMatcher> defaultResultMatchers
private java.util.List<ResultHandler> defaultResultHandlers
MockMvc(TestDispatcherServlet servlet, Filter... filters)
MockMvcBuilders
void setDefaultRequest(@Nullable RequestBuilder requestBuilder)
void setGlobalResultMatchers(java.util.List<ResultMatcher> resultMatchers)
void setGlobalResultHandlers(java.util.List<ResultHandler> resultHandlers)
public ResultActions perform(RequestBuilder requestBuilder) throws java.lang.Exception
requestBuilder
- used to prepare the request to execute;
see static factory methods in
MockMvcRequestBuilders
ResultActions
; never null
java.lang.Exception
MockMvcRequestBuilders
,
MockMvcResultMatchers
private MockHttpServletResponse unwrapResponseIfNecessary(ServletResponse servletResponse)
private void applyDefaultResultActions(MvcResult mvcResult) throws java.lang.Exception
java.lang.Exception