/** * Immediately force a <em>commit</em> or <em>rollback</em> of the * current test-managed transaction, according to the * {@linkplain #isFlaggedForRollback rollback flag}. * @throws IllegalStateException if the transaction context could not be * retrieved or if a transaction is not active for the current test * @see #isActive() * @see #start() */ public static void end() { requireCurrentTransactionContext().endTransaction(); }
/** * If a transaction is currently active for the supplied * {@linkplain TestContext test context}, this method will end the transaction * and run {@link AfterTransaction @AfterTransaction} methods. * <p>{@code @AfterTransaction} methods are guaranteed to be invoked even if * an error occurs while ending the transaction. */ @Override public void afterTestMethod(TestContext testContext) throws Exception { Method testMethod = testContext.getTestMethod(); Assert.notNull(testMethod, "The test method of the supplied TestContext must not be null"); TransactionContext txContext = TransactionContextHolder.removeCurrentTransactionContext(); // If there was (or perhaps still is) a transaction... if (txContext != null) { TransactionStatus transactionStatus = txContext.getTransactionStatus(); try { // If the transaction is still active... if (transactionStatus != null && !transactionStatus.isCompleted()) { txContext.endTransaction(); } } finally { runAfterTransactionMethods(testContext); } } }
/** * Immediately force a <em>commit</em> or <em>rollback</em> of the * current test-managed transaction, according to the * {@linkplain #isFlaggedForRollback rollback flag}. * @throws IllegalStateException if the transaction context could not be * retrieved or if a transaction is not active for the current test * @see #isActive() * @see #start() */ public static void end() { requireCurrentTransactionContext().endTransaction(); }
/** * Immediately force a <em>commit</em> or <em>rollback</em> of the * current test-managed transaction, according to the * {@linkplain #isFlaggedForRollback rollback flag}. * @throws IllegalStateException if the transaction context could not be * retrieved or if a transaction is not active for the current test * @see #isActive() * @see #start() */ public static void end() { requireCurrentTransactionContext().endTransaction(); }
/** * If a transaction is currently active for the supplied * {@linkplain TestContext test context}, this method will end the transaction * and run {@link AfterTransaction @AfterTransaction} methods. * <p>{@code @AfterTransaction} methods are guaranteed to be invoked even if * an error occurs while ending the transaction. */ @Override public void afterTestMethod(TestContext testContext) throws Exception { Method testMethod = testContext.getTestMethod(); Assert.notNull(testMethod, "The test method of the supplied TestContext must not be null"); TransactionContext txContext = TransactionContextHolder.removeCurrentTransactionContext(); // If there was (or perhaps still is) a transaction... if (txContext != null) { TransactionStatus transactionStatus = txContext.getTransactionStatus(); try { // If the transaction is still active... if (transactionStatus != null && !transactionStatus.isCompleted()) { txContext.endTransaction(); } } finally { runAfterTransactionMethods(testContext); } } }
/** * If a transaction is currently active for the supplied * {@linkplain TestContext test context}, this method will end the transaction * and run {@link AfterTransaction @AfterTransaction} methods. * <p>{@code @AfterTransaction} methods are guaranteed to be invoked even if * an error occurs while ending the transaction. */ @Override public void afterTestMethod(TestContext testContext) throws Exception { Method testMethod = testContext.getTestMethod(); Assert.notNull(testMethod, "The test method of the supplied TestContext must not be null"); TransactionContext txContext = TransactionContextHolder.removeCurrentTransactionContext(); // If there was (or perhaps still is) a transaction... if (txContext != null) { TransactionStatus transactionStatus = txContext.getTransactionStatus(); try { // If the transaction is still active... if (transactionStatus != null && !transactionStatus.isCompleted()) { txContext.endTransaction(); } } finally { runAfterTransactionMethods(testContext); } } }