org.springframework.test.annotation.IfProfileValue Maven / Gradle / Ivy
/*
* Copyright 2002-2009 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
*
* http://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.annotation;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
*
* Test annotation to indicate that a test is enabled for a specific testing
* profile or environment. If the configured {@link ProfileValueSource} returns
* a matching {@link #value() value} for the provided {@link #name() name}, the
* test will be enabled.
*
*
* Note: @IfProfileValue
can be applied at the class level,
* the method level, or both. @IfProfileValue
at the class
* level overrides method-level usage of @IfProfileValue
for
* any methods within that class.
*
*
* Examples: when using {@link SystemProfileValueSource} as the
* {@link ProfileValueSource} implementation, you can configure a test method to
* run only on Java VMs from Sun Microsystems as follows:
*
*
*
* @IfProfileValue(name = "java.vendor", value = "Sun Microsystems Inc.")
* public void testSomething() {
* // ...
* }
*
*
* You can alternatively configure @IfProfileValue
with
* OR semantics for multiple {@link #values() values} as follows
* (assuming a {@link ProfileValueSource} has been appropriately configured for
* the "test-groups" name):
*
*
*
* @IfProfileValue(name = "test-groups", values = { "unit-tests", "integration-tests" })
* public void testWhichRunsForUnitOrIntegrationTestGroups() {
* // ...
* }
*
*
* @author Rod Johnson
* @author Sam Brannen
* @since 2.0
* @see ProfileValueSource
* @see ProfileValueSourceConfiguration
* @see ProfileValueUtils
* @see org.springframework.test.context.junit38.AbstractJUnit38SpringContextTests
* @see org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests
* @see org.springframework.test.context.junit4.SpringJUnit4ClassRunner
*/
@Documented
@Inherited
@Retention(RetentionPolicy.RUNTIME)
@Target( { ElementType.TYPE, ElementType.METHOD })
public @interface IfProfileValue {
/**
* The name
of the profile value against which to
* test.
*/
String name();
/**
* A single, permissible value
of the profile value
* for the given {@link #name() name}.
*
* Note: Assigning values to both {@link #value()} and {@link #values()}
* will lead to a configuration conflict.
*/
String value() default "";
/**
* A list of all permissible values
of the
* profile value for the given {@link #name() name}.
*
* Note: Assigning values to both {@link #value()} and {@link #values()}
* will lead to a configuration conflict.
*/
String[] values() default {};
}