All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.springframework.test.web.servlet.setup.ConfigurableMockMvcBuilder Maven / Gradle / Ivy

There is a newer version: 6.1.6
Show newest version
/*
 * Copyright 2002-2018 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.springframework.test.web.servlet.setup;

import javax.servlet.Filter;

import org.springframework.test.web.servlet.MockMvcBuilder;
import org.springframework.test.web.servlet.RequestBuilder;
import org.springframework.test.web.servlet.ResultHandler;
import org.springframework.test.web.servlet.ResultMatcher;

/**
 * Defines common methods for building a {@code MockMvc}.
 *
 * @author Rossen Stoyanchev
 * @since 4.1
 * @param  a self reference to the builder type
 */
public interface ConfigurableMockMvcBuilder> extends MockMvcBuilder {

	/**
	 * Add filters mapped to any request (i.e. "/*"). For example:
	 * 
	 * mockMvcBuilder.addFilters(springSecurityFilterChain);
	 * 
*

is the equivalent of the following web.xml configuration: *

	 * <filter-mapping>
	 *     <filter-name>springSecurityFilterChain</filter-name>
	 *     <url-pattern>/*</url-pattern>
	 * </filter-mapping>
	 * 
*

Filters will be invoked in the order in which they are provided. * @param filters the filters to add */ T addFilters(Filter... filters); /** * Add a filter mapped to a specific set of patterns. For example: *

	 * mockMvcBuilder.addFilters(myResourceFilter, "/resources/*");
	 * 
*

is the equivalent of: *

	 * <filter-mapping>
	 *     <filter-name>myResourceFilter</filter-name>
	 *     <url-pattern>/resources/*</url-pattern>
	 * </filter-mapping>
	 * 
*

Filters will be invoked in the order in which they are provided. * @param filter the filter to add * @param urlPatterns the URL patterns to map to; if empty, "/*" is used by default */ T addFilter(Filter filter, String... urlPatterns); /** * Define default request properties that should be merged into all * performed requests. In effect this provides a mechanism for defining * common initialization for all requests such as the content type, request * parameters, session attributes, and any other request property. * *

Properties specified at the time of performing a request override the * default properties defined here. * @param requestBuilder a RequestBuilder; see static factory methods in * {@link org.springframework.test.web.servlet.request.MockMvcRequestBuilders} */ T defaultRequest(RequestBuilder requestBuilder); /** * Define a global expectation that should always be applied to * every response. For example, status code 200 (OK), content type * {@code "application/json"}, etc. * @param resultMatcher a ResultMatcher; see static factory methods in * {@link org.springframework.test.web.servlet.result.MockMvcResultMatchers} */ T alwaysExpect(ResultMatcher resultMatcher); /** * Define a global action that should always be applied to every * response. For example, writing detailed information about the performed * request and resulting response to {@code System.out}. * @param resultHandler a ResultHandler; see static factory methods in * {@link org.springframework.test.web.servlet.result.MockMvcResultHandlers} */ T alwaysDo(ResultHandler resultHandler); /** * Whether to enable the DispatcherServlet property * {@link org.springframework.web.servlet.DispatcherServlet#setDispatchOptionsRequest * dispatchOptionsRequest} which allows processing of HTTP OPTIONS requests. */ T dispatchOptions(boolean dispatchOptions); /** * Add a {@code MockMvcConfigurer} that automates MockMvc setup and * configures it for some specific purpose (e.g. security). *

There is a built-in {@link SharedHttpSessionConfigurer} that can be * used to re-use the HTTP session across requests. 3rd party frameworks * like Spring Security also use this mechanism to provide configuration * shortcuts. * @see SharedHttpSessionConfigurer */ T apply(MockMvcConfigurer configurer); }