public final class MockMvc extends 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")) .andExpectAll( status().isOk(), content().contentType("text/html"), forwardedUrl("/WEB-INF/layouts/main.jsp") );
Modifier and Type | Method and Description |
---|---|
DispatcherServlet |
getDispatcherServlet()
Return the underlying
DispatcherServlet instance that this
MockMvc was initialized with. |
ResultActions |
perform(RequestBuilder requestBuilder)
Perform a request and return a type that allows chaining further
actions, such as asserting expectations, on the result.
|
public DispatcherServlet getDispatcherServlet()
DispatcherServlet
instance that this
MockMvc
was initialized with.
This is intended for use in custom request processing scenario where a
request handling component happens to delegate to the DispatcherServlet
at runtime and therefore needs to be injected with it.
For most processing scenarios, simply use perform(org.springframework.test.web.servlet.RequestBuilder)
,
or if you need to configure the DispatcherServlet
, provide a
DispatcherServletCustomizer
to the MockMvcBuilder
.
public ResultActions perform(RequestBuilder requestBuilder) throws Exception
requestBuilder
- used to prepare the request to execute;
see static factory methods in
MockMvcRequestBuilders
ResultActions
(never null
)Exception
MockMvcRequestBuilders
,
MockMvcResultMatchers