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.transaction;
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
026/**
027 * {@code TransactionConfiguration} defines class-level metadata for configuring
028 * transactional tests.
029 *
030 * <p>As of Spring Framework 4.0, this annotation may be used as a
031 * <em>meta-annotation</em> to create custom <em>composed annotations</em>.
032 *
033 * @author Sam Brannen
034 * @since 2.5
035 * @see TransactionalTestExecutionListener
036 * @see org.springframework.transaction.annotation.Transactional
037 * @see org.springframework.test.annotation.Commit
038 * @see org.springframework.test.annotation.Rollback
039 * @see org.springframework.test.context.jdbc.Sql
040 * @see org.springframework.test.context.jdbc.SqlConfig
041 * @see org.springframework.test.context.jdbc.SqlConfig#transactionManager
042 * @see org.springframework.test.context.ContextConfiguration
043 * @deprecated As of Spring Framework 4.2, use {@code @Rollback} or
044 * {@code @Commit} at the class level and the {@code transactionManager}
045 * qualifier in {@code @Transactional}.
046 */
047@Deprecated
048@Documented
049@Inherited
050@Retention(RetentionPolicy.RUNTIME)
051@Target(ElementType.TYPE)
052public @interface TransactionConfiguration {
053
054        /**
055         * The bean name of the {@link org.springframework.transaction.PlatformTransactionManager
056         * PlatformTransactionManager} that should be used to drive <em>test-managed transactions</em>.
057         *
058         * <p>The name is only used if there is more than one bean of type
059         * {@code PlatformTransactionManager} in the test's {@code ApplicationContext}.
060         * If there is only one such bean, it is not necessary to specify a bean name.
061         *
062         * <p>Defaults to an empty string, requiring that one of the following is
063         * true:
064         * <ol>
065         * <li>There is only one bean of type {@code PlatformTransactionManager} in
066         * the test's {@code ApplicationContext}.</li>
067         * <li>{@link org.springframework.transaction.annotation.TransactionManagementConfigurer
068         * TransactionManagementConfigurer} has been implemented to specify which
069         * {@code PlatformTransactionManager} bean should be used for annotation-driven
070         * transaction management.</li>
071         * <li>The {@code PlatformTransactionManager} to use is named
072         * {@code "transactionManager"}.</li>
073         * </ol>
074         *
075         * <p><b>NOTE:</b> The XML {@code <tx:annotation-driven>} element also refers
076         * to a bean named {@code "transactionManager"} by default. If you are using both
077         * features in combination, make sure to point to the same transaction manager
078         * bean &mdash; here in {@code @TransactionConfiguration} and also in
079         * {@code <tx:annotation-driven transaction-manager="...">}.
080         */
081        String transactionManager() default "";
082
083        /**
084         * Whether <em>test-managed transactions</em> should be rolled back by default.
085         */
086        boolean defaultRollback() default true;
087
088}