001/* 002 * Copyright 2002-2015 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.test.web.servlet; 018 019/** 020 * Allows applying actions, such as expectations, on the result of an executed 021 * request. 022 * 023 * <p>See static factory methods in 024 * {@link org.springframework.test.web.servlet.result.MockMvcResultMatchers} and 025 * {@link org.springframework.test.web.servlet.result.MockMvcResultHandlers}. 026 * 027 * @author Rossen Stoyanchev 028 * @since 3.2 029 */ 030public interface ResultActions { 031 032 /** 033 * Perform an expectation. 034 * 035 * <h4>Example</h4> 036 * <pre class="code"> 037 * static imports: MockMvcRequestBuilders.*, MockMvcResultMatchers.* 038 * 039 * mockMvc.perform(get("/person/1")) 040 * .andExpect(status().isOk()) 041 * .andExpect(content().contentType(MediaType.APPLICATION_JSON)) 042 * .andExpect(jsonPath("$.person.name").value("Jason")); 043 * 044 * mockMvc.perform(post("/form")) 045 * .andExpect(status().isOk()) 046 * .andExpect(redirectedUrl("/person/1")) 047 * .andExpect(model().size(1)) 048 * .andExpect(model().attributeExists("person")) 049 * .andExpect(flash().attributeCount(1)) 050 * .andExpect(flash().attribute("message", "success!")); 051 * </pre> 052 */ 053 ResultActions andExpect(ResultMatcher matcher) throws Exception; 054 055 /** 056 * Perform a general action. 057 * 058 * <h4>Example</h4> 059 * <pre class="code"> 060 * static imports: MockMvcRequestBuilders.*, MockMvcResultMatchers.* 061 * 062 * mockMvc.perform(get("/form")).andDo(print()); 063 * </pre> 064 */ 065 ResultActions andDo(ResultHandler handler) throws Exception; 066 067 /** 068 * Return the result of the executed request for direct access to the results. 069 * 070 * @return the result of the request 071 */ 072 MvcResult andReturn(); 073 074}