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.data.jdbc;
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 org.junit.jupiter.api.extension.ExtendWith;
027
028import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
029import org.springframework.boot.autoconfigure.SpringBootApplication;
030import org.springframework.boot.test.autoconfigure.OverrideAutoConfiguration;
031import org.springframework.boot.test.autoconfigure.core.AutoConfigureCache;
032import org.springframework.boot.test.autoconfigure.filter.TypeExcludeFilters;
033import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase;
034import org.springframework.context.annotation.ComponentScan.Filter;
035import org.springframework.core.annotation.AliasFor;
036import org.springframework.core.env.Environment;
037import org.springframework.test.context.BootstrapWith;
038import org.springframework.test.context.junit.jupiter.SpringExtension;
039
040/**
041 * Annotation that can be used in combination with {@code @RunWith(SpringRunner.class)}
042 * for a typical Data JDBC test. Can be used when a test focuses <strong>only</strong> on
043 * Data JDBC components.
044 * <p>
045 * Using this annotation will disable full auto-configuration and instead apply only
046 * configuration relevant to Data JDBC tests.
047 *
048 * @author Andy Wilkinson
049 * @since 2.1.0
050 */
051@Target(ElementType.TYPE)
052@Retention(RetentionPolicy.RUNTIME)
053@Documented
054@Inherited
055@BootstrapWith(DataJdbcTestContextBootstrapper.class)
056@ExtendWith(SpringExtension.class)
057@OverrideAutoConfiguration(enabled = false)
058@TypeExcludeFilters(DataJdbcTypeExcludeFilter.class)
059@AutoConfigureCache
060@AutoConfigureDataJdbc
061@AutoConfigureTestDatabase
062@ImportAutoConfiguration
063public @interface DataJdbcTest {
064
065        /**
066         * Properties in form {@literal key=value} that should be added to the Spring
067         * {@link Environment} before the test runs.
068         * @return the properties to add
069         */
070        String[] properties() default {};
071
072        /**
073         * Determines if default filtering should be used with
074         * {@link SpringBootApplication @SpringBootApplication}. By default no beans are
075         * included.
076         * @see #includeFilters()
077         * @see #excludeFilters()
078         * @return if default filters should be used
079         */
080        boolean useDefaultFilters() default true;
081
082        /**
083         * A set of include filters which can be used to add otherwise filtered beans to the
084         * application context.
085         * @return include filters to apply
086         */
087        Filter[] includeFilters() default {};
088
089        /**
090         * A set of exclude filters which can be used to filter beans that would otherwise be
091         * added to the application context.
092         * @return exclude filters to apply
093         */
094        Filter[] excludeFilters() default {};
095
096        /**
097         * Auto-configuration exclusions that should be applied for this test.
098         * @return auto-configuration exclusions to apply
099         */
100        @AliasFor(annotation = ImportAutoConfiguration.class, attribute = "exclude")
101        Class<?>[] excludeAutoConfiguration() default {};
102
103}