001/*
002 * Copyright 2012-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 *      http://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.boot.test.autoconfigure.web.servlet;
018
019import java.lang.annotation.Documented;
020import java.lang.annotation.ElementType;
021import java.lang.annotation.Inherited;
022import java.lang.annotation.Retention;
023import java.lang.annotation.RetentionPolicy;
024import java.lang.annotation.Target;
025
026import com.gargoylesoftware.htmlunit.WebClient;
027import org.openqa.selenium.WebDriver;
028
029import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
030import org.springframework.boot.test.autoconfigure.properties.PropertyMapping;
031import org.springframework.boot.test.autoconfigure.properties.SkipPropertyMapping;
032import org.springframework.test.web.servlet.MockMvc;
033import org.springframework.test.web.servlet.MvcResult;
034
035/**
036 * Annotation that can be applied to a test class to enable and configure
037 * auto-configuration of {@link MockMvc}.
038 *
039 * @author Phillip Webb
040 * @since 1.4.0
041 * @see MockMvcAutoConfiguration
042 * @see SpringBootMockMvcBuilderCustomizer
043 */
044@Target({ ElementType.TYPE, ElementType.METHOD })
045@Retention(RetentionPolicy.RUNTIME)
046@Documented
047@Inherited
048@ImportAutoConfiguration
049@PropertyMapping("spring.test.mockmvc")
050public @interface AutoConfigureMockMvc {
051
052        /**
053         * If filters from the application context should be registered with MockMVC. Defaults
054         * to {@code true}.
055         * @return if filters should be added
056         */
057        boolean addFilters() default true;
058
059        /**
060         * How {@link MvcResult} information should be printed after each MockMVC invocation.
061         * @return how information is printed
062         */
063        @PropertyMapping(skip = SkipPropertyMapping.ON_DEFAULT_VALUE)
064        MockMvcPrint print() default MockMvcPrint.DEFAULT;
065
066        /**
067         * If {@link MvcResult} information should be printed only if the test fails.
068         * @return {@code true} if printing only occurs on failure
069         */
070        boolean printOnlyOnFailure() default true;
071
072        /**
073         * If a {@link WebClient} should be auto-configured when HtmlUnit is on the classpath.
074         * Defaults to {@code true}.
075         * @return if a {@link WebClient} is auto-configured
076         */
077        @PropertyMapping("webclient.enabled")
078        boolean webClientEnabled() default true;
079
080        /**
081         * If a {@link WebDriver} should be auto-configured when Selenium is on the classpath.
082         * Defaults to {@code true}.
083         * @return if a {@link WebDriver} is auto-configured
084         */
085        @PropertyMapping("webdriver.enabled")
086        boolean webDriverEnabled() default true;
087
088        /**
089         * If Spring Security's {@link MockMvc} support should be auto-configured when it is
090         * on the classpath. Defaults to {@code true}.
091         * @return if Spring Security's MockMvc support is auto-configured
092         * @deprecated since 2.1.0 in favor of Spring Security's testing support
093         */
094        @Deprecated
095        boolean secure() default true;
096
097}