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.annotation; 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 @Rollback} is a test annotation that is used to indicate whether 028 * a <em>test-managed transaction</em> should be <em>rolled back</em> after 029 * the test method has completed. 030 * 031 * <p>Consult the class-level Javadoc for 032 * {@link org.springframework.test.context.transaction.TransactionalTestExecutionListener} 033 * for an explanation of <em>test-managed transactions</em>. 034 * 035 * <p>When declared as a class-level annotation, {@code @Rollback} defines 036 * the default rollback semantics for all test methods within the test class 037 * hierarchy. When declared as a method-level annotation, {@code @Rollback} 038 * defines rollback semantics for the specific test method, potentially 039 * overriding class-level default commit or rollback semantics. 040 * 041 * <p>As of Spring Framework 4.2, {@code @Commit} can be used as direct 042 * replacement for {@code @Rollback(false)}. 043 * 044 * <p><strong>Warning</strong>: Declaring {@code @Commit} and {@code @Rollback} 045 * on the same test method or on the same test class is unsupported and may 046 * lead to unpredictable results. 047 * 048 * <p>This annotation may be used as a <em>meta-annotation</em> to create 049 * custom <em>composed annotations</em>. Consult the source code for 050 * {@link Commit @Commit} for a concrete example. 051 * 052 * @author Sam Brannen 053 * @since 2.5 054 * @see Commit 055 * @see org.springframework.test.context.transaction.TransactionalTestExecutionListener 056 */ 057@Target({ElementType.TYPE, ElementType.METHOD}) 058@Retention(RetentionPolicy.RUNTIME) 059@Documented 060@Inherited 061public @interface Rollback { 062 063 /** 064 * Whether the <em>test-managed transaction</em> should be rolled back 065 * after the test method has completed. 066 * <p>If {@code true}, the transaction will be rolled back; otherwise, 067 * the transaction will be committed. 068 * <p>Defaults to {@code true}. 069 */ 070 boolean value() default true; 071 072}