All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.springframework.test.context.TestExecutionListeners Maven / Gradle / Ivy

There is a newer version: 6.1.6
Show newest version
/*
 * Copyright 2002-2019 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
 *
 *      https://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.context;

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;

import org.springframework.core.annotation.AliasFor;

/**
 * {@code TestExecutionListeners} defines class-level metadata for configuring
 * which {@link TestExecutionListener TestExecutionListeners} should be
 * registered with a {@link TestContextManager}.
 *
 * 

Typically, {@code @TestExecutionListeners} will be used in conjunction * with {@link ContextConfiguration @ContextConfiguration}. * *

This annotation may be used as a meta-annotation to create custom * composed annotations. * * @author Sam Brannen * @since 2.5 * @see TestExecutionListener * @see TestContextManager * @see ContextConfiguration */ @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) @Documented @Inherited public @interface TestExecutionListeners { /** * Alias for {@link #listeners}. *

This attribute may not be used in conjunction with * {@link #listeners}, but it may be used instead of {@link #listeners}. */ @AliasFor("listeners") Class[] value() default {}; /** * The {@link TestExecutionListener TestExecutionListeners} to register with * the {@link TestContextManager}. *

This attribute may not be used in conjunction with * {@link #value}, but it may be used instead of {@link #value}. * @see org.springframework.test.context.web.ServletTestExecutionListener * @see org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener * @see org.springframework.test.context.support.DependencyInjectionTestExecutionListener * @see org.springframework.test.context.support.DirtiesContextTestExecutionListener * @see org.springframework.test.context.transaction.TransactionalTestExecutionListener * @see org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener * @see org.springframework.test.context.event.EventPublishingTestExecutionListener */ @AliasFor("value") Class[] listeners() default {}; /** * Whether or not {@link #listeners TestExecutionListeners} from superclasses * should be inherited. *

The default value is {@code true}, which means that an annotated * class will inherit the listeners defined by an annotated * superclass. Specifically, the listeners for an annotated class will be * appended to the list of listeners defined by an annotated superclass. * Thus, subclasses have the option of extending the list of * listeners. In the following example, {@code AbstractBaseTest} will * be configured with {@code DependencyInjectionTestExecutionListener} * and {@code DirtiesContextTestExecutionListener}; whereas, * {@code TransactionalTest} will be configured with * {@code DependencyInjectionTestExecutionListener}, * {@code DirtiesContextTestExecutionListener}, and * {@code TransactionalTestExecutionListener}, in that order. *

	 * @TestExecutionListeners({
	 *     DependencyInjectionTestExecutionListener.class,
	 *     DirtiesContextTestExecutionListener.class
	 * })
	 * public abstract class AbstractBaseTest {
	 * 	 // ...
	 * }
	 *
	 * @TestExecutionListeners(TransactionalTestExecutionListener.class)
	 * public class TransactionalTest extends AbstractBaseTest {
	 * 	 // ...
	 * }
*

If {@code inheritListeners} is set to {@code false}, the listeners for * the annotated class will shadow and effectively replace any * listeners defined by a superclass. */ boolean inheritListeners() default true; /** * The merge mode to use when {@code @TestExecutionListeners} is * declared on a class that does not inherit listeners * from a superclass. *

Can be set to {@link MergeMode#MERGE_WITH_DEFAULTS MERGE_WITH_DEFAULTS} * to have locally declared listeners merged with the default * listeners. *

The mode is ignored if listeners are inherited from a superclass. *

Defaults to {@link MergeMode#REPLACE_DEFAULTS REPLACE_DEFAULTS} * for backwards compatibility. * @see MergeMode * @since 4.1 */ MergeMode mergeMode() default MergeMode.REPLACE_DEFAULTS; /** * Enumeration of modes that dictate whether or not explicitly * declared listeners are merged with the default listeners when * {@code @TestExecutionListeners} is declared on a class that does * not inherit listeners from a superclass. * @since 4.1 */ enum MergeMode { /** * Indicates that locally declared listeners should replace the default * listeners. */ REPLACE_DEFAULTS, /** * Indicates that locally declared listeners should be merged with the * default listeners. *

The merging algorithm ensures that duplicates are removed from * the list and that the resulting set of merged listeners is sorted * according to the semantics of * {@link org.springframework.core.annotation.AnnotationAwareOrderComparator * AnnotationAwareOrderComparator}. If a listener implements * {@link org.springframework.core.Ordered Ordered} or is annotated * with {@link org.springframework.core.annotation.Order @Order} it can * influence the position in which it is merged with the defaults; otherwise, * locally declared listeners will simply be appended to the list of default * listeners when merged. */ MERGE_WITH_DEFAULTS } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy