public void testSuspendResumeCommitTransaction() throws Exception {
    UserTransaction ut = UserTransaction.getUserTransaction();
    TransactionManager tm = TransactionManager.getTransactionManager();

    ut.begin();

    TxContext ctx = tm.suspend();

    System.out.println("Suspended: " + ctx);

    tm.resume(ctx);

    System.out.println("\nResumed");

    ut.commit();
  }
  /** Suspend the current transaction. */
  protected void suspendTransaction() {
    try {
      /*
       * There should either be an Atomic Transaction *or* a Business Activity
       * associated with the thread.
       */
      final TransactionManager transactionManager = TransactionManagerFactory.transactionManager();
      final BusinessActivityManager businessActivityManager =
          BusinessActivityManagerFactory.businessActivityManager();

      if (transactionManager != null) {
        transactionManager.suspend();
      }

      if (businessActivityManager != null) {
        businessActivityManager.suspend();
      }
    } catch (final Throwable th) {
      wstxLogger.i18NLogger.warn_mw_wst11_service_JaxHC11P_1(
          "com.arjuna.mw.wst11.service.JaxBaseHeaderContextProcessor.suspendTransaction()", th);
    }
  }
  @Test
  public void testSubTransactionCommitRollbackInPrepare() throws Exception {
    final UserTransaction ut = UserTransactionFactory.userTransaction();
    final UserTransaction ust = UserTransactionFactory.userSubordinateTransaction();
    final TransactionManager tm = TransactionManager.getTransactionManager();

    final DemoDurableParticipant p1 = new DemoDurableParticipant();
    final DemoVolatileParticipant p2 = new DemoVolatileParticipant();
    final FailureParticipant p3 =
        new FailureParticipant(FailureParticipant.FAIL_IN_PREPARE, FailureParticipant.NONE);
    final DemoVolatileParticipant p4 = new DemoVolatileParticipant();

    ut.begin();
    final TxContext tx = tm.suspend();
    tm.resume(tx);
    tm.enlistForDurableTwoPhase(p1, p1.identifier());
    tm.enlistForVolatileTwoPhase(p2, p2.identifier());
    ust.begin();
    final TxContext stx = tm.suspend();
    tm.resume(stx);
    tm.enlistForDurableTwoPhase(p3, "failure in prepare");
    tm.enlistForVolatileTwoPhase(p4, p4.identifier());

    tm.resume(tx);
    try {
      ut.commit();
      fail("expecting TransactionRolledBackException");
    } catch (TransactionRolledBackException trbe) {
      // expect this
    }
    assertTrue(p1.prepared() && p1.resolved() && !p1.passed());
    assertTrue(p2.prepared() && p2.resolved() && !p2.passed());
    assertTrue(!p3.passed());
    assertTrue(p4.prepared() && p4.resolved() && !p4.passed());
  }