txContext = new TransactionContext(testContext, tm, transactionAttribute, isRollback(testContext)); runBeforeTransactionMethods(testContext); txContext.startTransaction(); TransactionContextHolder.setCurrentTransactionContext(txContext);
/** * 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); } } }
/** * Determine whether the current test-managed transaction has been * {@linkplain #flagForRollback() flagged for rollback} or * {@linkplain #flagForCommit() flagged for commit}. * @return {@code true} if the current test-managed transaction is flagged * to be rolled back; {@code false} if the current test-managed transaction * is flagged to be committed * @throws IllegalStateException if a transaction is not active for the * current test * @see #isActive() * @see #flagForRollback() * @see #flagForCommit() */ public static boolean isFlaggedForRollback() { return requireCurrentTransactionContext().isFlaggedForRollback(); }
/** * Start a new test-managed transaction. * <p>Only call this method if {@link #end} has been called or if no * transaction has been previously started. * @throws IllegalStateException if the transaction context could not be * retrieved or if a transaction is already active for the current test * @see #isActive() * @see #end() */ public static void start() { requireCurrentTransactionContext().startTransaction(); }
/** * 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(); }
private static void setFlaggedForRollback(boolean flag) { requireCurrentTransactionContext().setFlaggedForRollback(flag); }
/** * Determine whether a test-managed transaction is currently <em>active</em>. * @return {@code true} if a test-managed transaction is currently active * @see #start() * @see #end() */ public static boolean isActive() { TransactionContext transactionContext = TransactionContextHolder.getCurrentTransactionContext(); if (transactionContext != null) { TransactionStatus transactionStatus = transactionContext.getTransactionStatus(); return (transactionStatus != null && !transactionStatus.isCompleted()); } return false; }
/** * Start a new test-managed transaction. * <p>Only call this method if {@link #end} has been called or if no * transaction has been previously started. * @throws IllegalStateException if the transaction context could not be * retrieved or if a transaction is already active for the current test * @see #isActive() * @see #end() */ public static void start() { requireCurrentTransactionContext().startTransaction(); }
/** * 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(); }
private static void setFlaggedForRollback(boolean flag) { requireCurrentTransactionContext().setFlaggedForRollback(flag); }
/** * Determine whether a test-managed transaction is currently <em>active</em>. * @return {@code true} if a test-managed transaction is currently active * @see #start() * @see #end() */ public static boolean isActive() { TransactionContext transactionContext = TransactionContextHolder.getCurrentTransactionContext(); if (transactionContext != null) { TransactionStatus transactionStatus = transactionContext.getTransactionStatus(); return (transactionStatus != null && !transactionStatus.isCompleted()); } return false; }
/** * 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); } } }
txContext = new TransactionContext(testContext, tm, transactionAttribute, isRollback(testContext)); runBeforeTransactionMethods(testContext); txContext.startTransaction(); TransactionContextHolder.setCurrentTransactionContext(txContext);
/** * Start a new test-managed transaction. * <p>Only call this method if {@link #end} has been called or if no * transaction has been previously started. * @throws IllegalStateException if the transaction context could not be * retrieved or if a transaction is already active for the current test * @see #isActive() * @see #end() */ public static void start() { requireCurrentTransactionContext().startTransaction(); }
/** * 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(); }
private static void setFlaggedForRollback(boolean flag) { requireCurrentTransactionContext().setFlaggedForRollback(flag); }
/** * Determine whether a test-managed transaction is currently <em>active</em>. * @return {@code true} if a test-managed transaction is currently active * @see #start() * @see #end() */ public static boolean isActive() { TransactionContext transactionContext = TransactionContextHolder.getCurrentTransactionContext(); if (transactionContext != null) { TransactionStatus transactionStatus = transactionContext.getTransactionStatus(); return (transactionStatus != null && !transactionStatus.isCompleted()); } return false; }
/** * Determine whether the current test-managed transaction has been * {@linkplain #flagForRollback() flagged for rollback} or * {@linkplain #flagForCommit() flagged for commit}. * @return {@code true} if the current test-managed transaction is flagged * to be rolled back; {@code false} if the current test-managed transaction * is flagged to be committed * @throws IllegalStateException if a transaction is not active for the * current test * @see #isActive() * @see #flagForRollback() * @see #flagForCommit() */ public static boolean isFlaggedForRollback() { return requireCurrentTransactionContext().isFlaggedForRollback(); }
/** * 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); } } }
txContext = new TransactionContext(testContext, tm, transactionAttribute, isRollback(testContext)); runBeforeTransactionMethods(testContext); txContext.startTransaction(); TransactionContextHolder.setCurrentTransactionContext(txContext);