001/* 002 * Copyright 2002-2014 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.setup; 018 019import org.springframework.test.web.servlet.request.RequestPostProcessor; 020import org.springframework.web.context.WebApplicationContext; 021 022 023/** 024 * Allows a sub-class to encapsulate logic for pre-configuring a 025 * {@code ConfigurableMockMvcBuilder} for some specific purpose. A 3rd party 026 * library may use this to provide shortcuts for setting up MockMvc. 027 * 028 * <p>Can be plugged in via {@link ConfigurableMockMvcBuilder#apply} with 029 * instances of this type likely created via static methods, e.g.: 030 * 031 * <pre class="code"> 032 * MockMvcBuilders.webAppContextSetup(context).apply(mySetup("foo","bar")).build(); 033 * </pre> 034 * 035 * @author Rossen Stoyanchev 036 * @since 4.1 037 * @see org.springframework.test.web.servlet.setup.MockMvcConfigurerAdapter 038 */ 039public interface MockMvcConfigurer { 040 041 /** 042 * Invoked immediately after a {@code MockMvcConfigurer} is added via 043 * {@link ConfigurableMockMvcBuilder#apply}. 044 */ 045 void afterConfigurerAdded(ConfigurableMockMvcBuilder<?> builder); 046 047 /** 048 * Invoked just before the MockMvc instance is created. Implementations may 049 * return a RequestPostProcessor to be applied to every request performed 050 * through the created {@code MockMvc} instance. 051 */ 052 RequestPostProcessor beforeMockMvcCreated(ConfigurableMockMvcBuilder<?> builder, WebApplicationContext context); 053 054}