spring-framework / org.springframework.test.web.servlet / ResultActions

ResultActions

interface ResultActions

Allows applying actions, such as expectations, on the result of an executed request.

See static factory methods in org.springframework.test.web.servlet.result.MockMvcResultMatchers and org.springframework.test.web.servlet.result.MockMvcResultHandlers.

Author
Rossen Stoyanchev

Since
3.2

Functions

andDo

abstract fun andDo(handler: ResultHandler): ResultActions

Perform a general action. Example

 static imports: MockMvcRequestBuilders.*, MockMvcResultMatchers.* mockMvc.perform(get("/form")).andDo(print()); 

andExpect

abstract fun andExpect(matcher: ResultMatcher): ResultActions

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!")); 

andReturn

abstract fun andReturn(): MvcResult

Return the result of the executed request for direct access to the results.