Interface ResultActions
public interface ResultActions
Allows applying actions, such as expectations, on the result of an executed request.See static factory methods in
MockMvcResultMatchersandMockMvcResultHandlers.- Since:
- 3.2
- Author:
- Rossen Stoyanchev
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description ResultActionsandDo(ResultHandler handler)Perform a general action.ResultActionsandExpect(ResultMatcher matcher)Perform an expectation.MvcResultandReturn()Return the result of the executed request for direct access to the results.
Method Detail
andExpect
ResultActions andExpect(ResultMatcher matcher) throws Exception
Perform an expectation.Example
static imports: MockMvcRequestBuilders.*, MockMvcResultMatchers.* mockMvc.perform(get("/person/1")) .andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON)) .andExpect(jsonPath("$.person.name").value("Jason")); mockMvc.perform(post("/form")) .andExpect(status().isOk()) .andExpect(redirectedUrl("/person/1")) .andExpect(model().size(1)) .andExpect(model().attributeExists("person")) .andExpect(flash().attributeCount(1)) .andExpect(flash().attribute("message", "success!"));- Throws:
Exception
andDo
ResultActions andDo(ResultHandler handler) throws Exception
Perform a general action.Example
static imports: MockMvcRequestBuilders.*, MockMvcResultMatchers.* mockMvc.perform(get("/form")).andDo(print());- Throws:
Exception