001/* 002 * Copyright 2002-2018 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 * </pre> 044 * 045 * <p>Or alternatively provide all matchers as a vararg: 046 * <pre class="code"> 047 * static imports: MockMvcRequestBuilders.*, MockMvcResultMatchers.*, ResultMatcher.matchAll 048 * 049 * mockMvc.perform(post("/form")) 050 * .andExpect(matchAll( 051 * status().isOk(), 052 * redirectedUrl("/person/1"), 053 * model().size(1), 054 * model().attributeExists("person"), 055 * flash().attributeCount(1), 056 * flash().attribute("message", "success!")) 057 * ); 058 * </pre> 059 */ 060 ResultActions andExpect(ResultMatcher matcher) throws Exception; 061 062 /** 063 * Perform a general action. 064 * 065 * <h4>Example</h4> 066 * <pre class="code"> 067 * static imports: MockMvcRequestBuilders.*, MockMvcResultMatchers.* 068 * 069 * mockMvc.perform(get("/form")).andDo(print()); 070 * </pre> 071 */ 072 ResultActions andDo(ResultHandler handler) throws Exception; 073 074 /** 075 * Return the result of the executed request for direct access to the results. 076 * 077 * @return the result of the request 078 */ 079 MvcResult andReturn(); 080 081}