001/*
002 * Copyright 2002-2016 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.context;
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.springframework.core.annotation.AliasFor;
027
028/**
029 * {@code ActiveProfiles} is a class-level annotation that is used to declare
030 * which <em>active bean definition profiles</em> should be used when loading
031 * an {@link org.springframework.context.ApplicationContext ApplicationContext}
032 * for test classes.
033 *
034 * <p>As of Spring Framework 4.0, this annotation may be used as a
035 * <em>meta-annotation</em> to create custom <em>composed annotations</em>.
036 *
037 * @author Sam Brannen
038 * @since 3.1
039 * @see SmartContextLoader
040 * @see MergedContextConfiguration
041 * @see ContextConfiguration
042 * @see ActiveProfilesResolver
043 * @see org.springframework.context.ApplicationContext
044 * @see org.springframework.context.annotation.Profile
045 */
046@Target(ElementType.TYPE)
047@Retention(RetentionPolicy.RUNTIME)
048@Documented
049@Inherited
050public @interface ActiveProfiles {
051
052        /**
053         * Alias for {@link #profiles}.
054         * <p>This attribute may <strong>not</strong> be used in conjunction with
055         * {@link #profiles}, but it may be used <em>instead</em> of {@link #profiles}.
056         */
057        @AliasFor("profiles")
058        String[] value() default {};
059
060        /**
061         * The bean definition profiles to activate.
062         * <p>This attribute may <strong>not</strong> be used in conjunction with
063         * {@link #value}, but it may be used <em>instead</em> of {@link #value}.
064         */
065        @AliasFor("value")
066        String[] profiles() default {};
067
068        /**
069         * The type of {@link ActiveProfilesResolver} to use for resolving the active
070         * bean definition profiles programmatically.
071         * @since 4.0
072         * @see ActiveProfilesResolver
073         */
074        Class<? extends ActiveProfilesResolver> resolver() default ActiveProfilesResolver.class;
075
076        /**
077         * Whether or not bean definition profiles from superclasses should be
078         * <em>inherited</em>.
079         * <p>The default value is {@code true}, which means that a test
080         * class will <em>inherit</em> bean definition profiles defined by a
081         * test superclass. Specifically, the bean definition profiles for a test
082         * class will be appended to the list of bean definition profiles
083         * defined by a test superclass. Thus, subclasses have the option of
084         * <em>extending</em> the list of bean definition profiles.
085         * <p>If {@code inheritProfiles} is set to {@code false}, the bean
086         * definition profiles for the test class will <em>shadow</em> and
087         * effectively replace any bean definition profiles defined by a superclass.
088         * <p>In the following example, the {@code ApplicationContext} for
089         * {@code BaseTest} will be loaded using only the &quot;base&quot;
090         * bean definition profile; beans defined in the &quot;extended&quot; profile
091         * will therefore not be loaded. In contrast, the {@code ApplicationContext}
092         * for {@code ExtendedTest} will be loaded using the &quot;base&quot;
093         * <strong>and</strong> &quot;extended&quot; bean definition profiles.
094         * <pre class="code">
095         * &#064;ActiveProfiles(&quot;base&quot;)
096         * &#064;ContextConfiguration
097         * public class BaseTest {
098         *     // ...
099         * }
100         *
101         * &#064;ActiveProfiles(&quot;extended&quot;)
102         * &#064;ContextConfiguration
103         * public class ExtendedTest extends BaseTest {
104         *     // ...
105         * }
106         * </pre>
107         * <p>Note: {@code @ActiveProfiles} can be used when loading an
108         * {@code ApplicationContext} from path-based resource locations or
109         * annotated classes.
110         * @see ContextConfiguration#locations
111         * @see ContextConfiguration#classes
112         * @see ContextConfiguration#inheritLocations
113         */
114        boolean inheritProfiles() default true;
115
116}