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