public class TestTransaction extends Object
TestTransaction
provides a collection of static utility methods for
programmatic interaction with test-managed transactions within
test methods, before methods, and after methods.
Consult the javadocs for TransactionalTestExecutionListener
for a detailed explanation of test-managed transactions.
Support for TestTransaction
is automatically available whenever
the TransactionalTestExecutionListener
is enabled. Note that the
TransactionalTestExecutionListener
is typically enabled by default,
but it can also be manually enabled via the
@TestExecutionListeners
annotation.
TransactionalTestExecutionListener
Constructor and Description |
---|
TestTransaction() |
Modifier and Type | Method and Description |
---|---|
static void |
end()
Immediately force a commit or rollback of the
current test-managed transaction, according to the
rollback flag.
|
static void |
flagForCommit()
Flag the current test-managed transaction for commit.
|
static void |
flagForRollback()
Flag the current test-managed transaction for rollback.
|
static boolean |
isActive()
Determine whether a test-managed transaction is currently active.
|
static boolean |
isFlaggedForRollback()
Determine whether the current test-managed transaction has been
flagged for rollback or
flagged for commit.
|
static void |
start()
Start a new test-managed transaction.
|
public static boolean isActive()
public static boolean isFlaggedForRollback()
true
if the current test-managed transaction is flagged
to be rolled back; false
if the current test-managed transaction
is flagged to be committedIllegalStateException
- if a transaction is not active for the
current testisActive()
,
flagForRollback()
,
flagForCommit()
public static void flagForRollback()
Invoking this method will not end the current transaction. Rather, the value of this flag will be used to determine whether or not the current test-managed transaction should be rolled back or committed once it is ended.
IllegalStateException
- if no transaction is active for the current testisActive()
,
isFlaggedForRollback()
,
start()
,
end()
public static void flagForCommit()
Invoking this method will not end the current transaction. Rather, the value of this flag will be used to determine whether or not the current test-managed transaction should be rolled back or committed once it is ended.
IllegalStateException
- if no transaction is active for the current testisActive()
,
isFlaggedForRollback()
,
start()
,
end()
public static void start()
Only call this method if end()
has been called or if no
transaction has been previously started.
IllegalStateException
- if the transaction context could not be
retrieved or if a transaction is already active for the current testisActive()
,
end()
public static void end()
IllegalStateException
- if the transaction context could not be
retrieved or if a transaction is not active for the current testisActive()
,
start()