Issue #23507 jts now uses junit5 instead of junit1/2
diff --git a/appserver/transaction/jts/pom.xml b/appserver/transaction/jts/pom.xml
index 27a43f2..2116409 100644
--- a/appserver/transaction/jts/pom.xml
+++ b/appserver/transaction/jts/pom.xml
@@ -109,16 +109,25 @@
             <optional>true</optional>
         </dependency>
         <dependency>
+            <groupId>org.glassfish.main.cluster</groupId>
+            <artifactId>gms-bootstrap</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.junit.jupiter</groupId>
+            <artifactId>junit-jupiter-engine</artifactId>
+        </dependency>
+         <dependency>
+            <groupId>org.hamcrest</groupId>
+            <artifactId>hamcrest</artifactId>
+        </dependency>
+        <dependency>
             <groupId>org.glassfish.main.connectors</groupId>
             <artifactId>connectors-runtime</artifactId>
             <version>${project.version}</version>
             <scope>test</scope>
         </dependency>
-        <dependency>
-            <groupId>org.glassfish.main.cluster</groupId>
-            <artifactId>gms-bootstrap</artifactId>
-            <version>${project.version}</version>
-        </dependency>
     </dependencies>
 
     <build>
diff --git a/appserver/transaction/jts/src/test/java/com/sun/enterprise/transaction/jts/AppTest.java b/appserver/transaction/jts/src/test/java/com/sun/enterprise/transaction/jts/AppTest.java
index 30d4401..b716890 100644
--- a/appserver/transaction/jts/src/test/java/com/sun/enterprise/transaction/jts/AppTest.java
+++ b/appserver/transaction/jts/src/test/java/com/sun/enterprise/transaction/jts/AppTest.java
@@ -1,5 +1,6 @@
 /*
  * Copyright (c) 2008, 2020 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021 Contributors to the Eclipse Foundation
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v. 2.0, which is available at
@@ -16,1545 +17,770 @@
 
 package com.sun.enterprise.transaction.jts;
 
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
-import java.util.logging.*;
-import jakarta.transaction.*;
-import javax.transaction.xa.*;
-import java.beans.PropertyChangeEvent;
-
 import com.sun.enterprise.config.serverbeans.ServerTags;
-
-import org.glassfish.api.invocation.InvocationManager;
-import com.sun.enterprise.transaction.spi.JavaEETransactionManagerDelegate;
-import com.sun.enterprise.transaction.api.JavaEETransactionManager;
-import com.sun.enterprise.transaction.UserTransactionImpl;
+import com.sun.enterprise.resource.ClientSecurityInfo;
+import com.sun.enterprise.resource.ResourceHandle;
+import com.sun.enterprise.resource.ResourceSpec;
+import com.sun.enterprise.resource.allocator.ResourceAllocator;
+import com.sun.enterprise.resource.pool.PoolManagerImpl;
 import com.sun.enterprise.transaction.JavaEETransactionManagerSimplified;
 import com.sun.enterprise.transaction.JavaEETransactionManagerSimplifiedDelegate;
 import com.sun.enterprise.transaction.TransactionServiceConfigListener;
 import com.sun.enterprise.transaction.TransactionSynchronizationRegistryImpl;
+import com.sun.enterprise.transaction.UserTransactionImpl;
+import com.sun.enterprise.transaction.api.JavaEETransactionManager;
+import com.sun.enterprise.transaction.spi.JavaEETransactionManagerDelegate;
+import java.beans.PropertyChangeEvent;
+import javax.transaction.xa.XAException;
+import javax.transaction.xa.XAResource;
+import javax.transaction.xa.Xid;
 
-import com.sun.jts.jtsxa.OTSResourceImpl;
-import com.sun.jts.jta.SynchronizationImpl;
+import org.glassfish.api.invocation.InvocationManager;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
 
-import com.sun.enterprise.resource.*;
-import com.sun.enterprise.resource.allocator.ResourceAllocator;
-import com.sun.enterprise.resource.pool.PoolManagerImpl;
+import jakarta.transaction.HeuristicMixedException;
+import jakarta.transaction.HeuristicRollbackException;
+import jakarta.transaction.InvalidTransactionException;
+import jakarta.transaction.NotSupportedException;
+import jakarta.transaction.RollbackException;
+import jakarta.transaction.Status;
+import jakarta.transaction.Synchronization;
+import jakarta.transaction.SystemException;
+import jakarta.transaction.Transaction;
+import jakarta.transaction.TransactionManager;
+import jakarta.transaction.TransactionSynchronizationRegistry;
+import jakarta.transaction.UserTransaction;
 
-import com.sun.logging.LogDomains;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.instanceOf;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
 
 /**
  * Unit test for simple App.
  */
-public class AppTest extends TestCase {
+public class AppTest {
 
-    JavaEETransactionManager t;
+    private JavaEETransactionManager txManager;
 
-    /**
-     * Create the test case
-     *
-     * @param testName name of the test case
-     */
-    public AppTest(String testName) {
-        super(testName);
-    }
-
-    /**
-     * @return the suite of tests being tested
-     */
-    public static Test suite() throws Exception {
-        return new TestSuite(AppTest.class);
-    }
-
+    @BeforeEach
     public void setUp() {
-        try {
-            t = new JavaEETransactionManagerSimplified();
-            JavaEETransactionManagerDelegate d = new JavaEETransactionManagerJTSDelegate();
-            t.setDelegate(d);
-            d.setTransactionManager(t);
-        } catch (Exception ex) {
-            ex.printStackTrace();
-            assert (false);
-        }
-
+        txManager = new JavaEETransactionManagerSimplified();
+        JavaEETransactionManagerDelegate d = new JavaEETransactionManagerJTSDelegate();
+        txManager.setDelegate(d);
+        d.setTransactionManager(txManager);
     }
 
     /**
-     * Test that you can't replace delegate with a lower order.
+     * Test that you can'txManager replace delegate with a lower order.
      */
+    @Test
     public void testReplaceDelegate() {
         JavaEETransactionManagerDelegate d = new JavaEETransactionManagerSimplifiedDelegate();
-        t.setDelegate(d);
-        assertFalse(((JavaEETransactionManagerSimplified)t).isDelegate(d));
+        txManager.setDelegate(d);
+        assertFalse(((JavaEETransactionManagerSimplified)txManager).isDelegate(d));
     }
 
     /**
-     * Can't test more than null (but no NPE)
+     * Can'txManager test more than null (but no NPE)
      */
+    @Test
     public void testXAResourceWrapper() {
-        assertNull(t.getXAResourceWrapper("xxx"));
-        assertNull(t.getXAResourceWrapper("oracle.jdbc.xa.client.OracleXADataSource"));
+        assertNull(txManager.getXAResourceWrapper("xxx"));
+        assertNull(txManager.getXAResourceWrapper("oracle.jdbc.xa.client.OracleXADataSource"));
     }
 
     /**
      * Test ConfigListener call
      */
+    @Test
     public void testTransactionServiceConfigListener() {
         PropertyChangeEvent e1 = new PropertyChangeEvent("", ServerTags.KEYPOINT_INTERVAL, "1", "10");
         PropertyChangeEvent e2 = new PropertyChangeEvent("", ServerTags.RETRY_TIMEOUT_IN_SECONDS, "1", "10");
-        try {
-            TransactionServiceConfigListener l = new TransactionServiceConfigListener();
-            l.setTM(t);
-            l.changed(new PropertyChangeEvent[] {e1, e2});
-            assert(true);
-        } catch (Exception ex) {
-            ex.printStackTrace();
-            assert (false);
-        }
+        TransactionServiceConfigListener listener = new TransactionServiceConfigListener();
+        listener.setTM(txManager);
+        listener.changed(new PropertyChangeEvent[] {e1, e2});
     }
 
+    @Test
     public void testWrongTMCommit() {
-        System.out.println("**Testing Wrong TM commit ===>");
-        try {
-            System.out.println("**Calling TM commit ===>");
-            t.commit();
-            System.out.println("**WRONG: TM commit successful <===");
-            assert (false);
-        } catch (IllegalStateException ex) {
-            System.out.println("**Caught IllegalStateException <===");
-            assert (true);
-        } catch (Exception ex) {
-            ex.printStackTrace();
-            assert (false);
-        }
+        assertThrows(IllegalStateException.class, txManager::commit);
     }
 
+    @Test
     public void testWrongTMRollback() {
-        System.out.println("**Testing Wrong TM Rollback ===>");
-        try {
-            System.out.println("**Calling TM rollback ===>");
-            t.rollback();
-            System.out.println("**WRONG: TM rollback successful <===");
-            assert (false);
-        } catch (IllegalStateException ex) {
-            System.out.println("**Caught IllegalStateException <===");
-            assert (true);
-        } catch (Exception ex) {
-            ex.printStackTrace();
-            assert (false);
-        }
+        assertThrows(IllegalStateException.class, txManager::rollback);
     }
 
-    public void testWrongUTXCommit() {
-        System.out.println("**Testing Wrong UTX commit ===>");
-        try {
-            UserTransaction utx = createUtx();
-            System.out.println("**Calling UTX commit ===>");
-            utx.commit();
-            System.out.println("**WRONG: UTX commit successful <===");
-            assert (false);
-        } catch (IllegalStateException ex) {
-            System.out.println("**Caught IllegalStateException <===");
-            assert (true);
-        } catch (Exception ex) {
-            ex.printStackTrace();
-            assert (false);
-        }
+    @Test
+    public void testWrongUTXCommit() throws Exception {
+        UserTransaction utx = createUtx();
+        assertThrows(IllegalStateException.class, utx::commit);
     }
 
-/**
+    @Test
+    @Disabled("No exception throws. This test was commented out for years, but ... I would expect the exception too")
     public void testUTXTimeout() {
-        System.out.println("**Testing UTX Timeout ===>");
-        TestSync s = new TestSync(false);
-
-        long now = System.currentTimeMillis();
-        try {
+        final TestSync sync = new TestSync(false);
+        final long start = System.currentTimeMillis();
+        assertThrows(RollbackException.class, () -> {
             UserTransaction utx = createUtx();
             System.out.println("**Calling UTX setTransactionTimeout ===>");
-            utx.setTransactionTimeout(45);
+            utx.setTransactionTimeout(1);
             utx.begin();
 
-            Transaction tx = t.getTransaction();
+            Transaction tx = txManager.getTransaction();
             System.out.println("**Registering Synchronization ....");
-            tx.registerSynchronization(s);
+            tx.registerSynchronization(sync);
 
             TestResource theResource = new TestResource(tx);
-            t.enlistResource(tx, new TestResourceHandle(theResource));
+            txManager.enlistResource(tx, new TestResourceHandle(theResource));
 
-            Thread.sleep(40000);
-            t.delistResource(tx, new TestResourceHandle(theResource), XAResource.TMSUCCESS);
+            Thread.sleep(1100);
+            txManager.delistResource(tx, new TestResourceHandle(theResource), XAResource.TMSUCCESS);
 
             utx.commit();
-            //System.out.println("**WRONG: UTX commit successful <===");
-            System.out.println("**UTX commit successful after <===" + (System.currentTimeMillis() - now) + "millis");
-            assert (true);
-            //assert (false);
-        } catch (RollbackException ex) {
-            //ex.printStackTrace();
-            System.out.println("**Caught UNexpected RollbackException <===");
-            //assertFalse ("beforeCompletion was called", s.called_beforeCompletion);
-            //assertTrue ("afterCompletion was not called", s.called_afterCompletion);
-            assert (true);
-        } catch (Exception ex) {
-            ex.printStackTrace();
-            assert (false);
-        }
-    }
-**/
-
-    public void testWrongTMOperationsAfterCommit() {
-        System.out.println("**Testing Wrong TM Operations After Commit ===>");
-        try {
-            t.begin();
-            t.commit();
-        } catch (Exception ex) {
-            ex.printStackTrace();
-            assert (false);
-        }
-
-        try {
-            System.out.println("**Calling TM commit ===>");
-            t.commit();
-            System.out.println("**WRONG: TM commit successful <===");
-            assert (false);
-        } catch (IllegalStateException ex) {
-            System.out.println("**Caught IllegalStateException <===");
-            assert (true);
-        } catch (Exception ex) {
-            ex.printStackTrace();
-            assert (false);
-        }
-
-        try {
-            System.out.println("**Calling TM rollback ===>");
-            t.rollback();
-            System.out.println("**WRONG: TM rollback successful <===");
-            assert (false);
-        } catch (IllegalStateException ex) {
-            System.out.println("**Caught IllegalStateException <===");
-            assert (true);
-        } catch (Exception ex) {
-            ex.printStackTrace();
-            assert (false);
-        }
-
-        try {
-            System.out.println("**Calling TM setRollbackOnly ===>");
-            t.setRollbackOnly();
-            System.out.println("**WRONG: TM setRollbackOnly successful <===");
-            assert (false);
-        } catch (IllegalStateException ex) {
-            System.out.println("**Caught IllegalStateException <===");
-            assert (true);
-        } catch (Exception ex) {
-            ex.printStackTrace();
-            assert (false);
-        }
-
+            System.out.println("**UTX commit successful after <===" + (System.currentTimeMillis() - start) + "millis");
+        });
+        assertFalse(sync.called_beforeCompletion, "beforeCompletion was called");
+        assertTrue(sync.called_afterCompletion, "afterCompletion was not called");
     }
 
-    public void testResourceStatus() {
-        System.out.println("**=================Testing Resource Status ===>");
-        Transaction tx = null;
-        try {
-            t.begin();
-            tx = t.getTransaction();
+
+    @Test
+    public void testWrongTMOperationsAfterCommit() throws Exception {
+        txManager.begin();
+        txManager.commit();
+        assertThrows(IllegalStateException.class, txManager::commit);
+        assertThrows(IllegalStateException.class, txManager::rollback);
+        assertThrows(IllegalStateException.class, txManager::setRollbackOnly);
+    }
+
+    @Test
+    public void testResourceStatus() throws Exception {
+        {
+            txManager.begin();
+            Transaction tx = txManager.getTransaction();
             System.out.println("**Testing Resource Status in 2PC ===>");
-            //TestResource theResource = new TestResource(tx);
             TestResource theResource = new TestResource(tx, 1L);
             TestResource theResource2 = new TestResource(tx, 1L);
             TestResource theResource1 = new TestResource(tx);
-            t.enlistResource(tx, new TestResourceHandle(theResource));
-            t.enlistResource(tx, new TestResourceHandle(theResource2));
-            t.enlistResource(tx, new TestResourceHandle(theResource1));
-            t.delistResource(tx, new TestResourceHandle(theResource), XAResource.TMSUCCESS);
-            t.delistResource(tx, new TestResourceHandle(theResource2), XAResource.TMSUCCESS);
-            t.delistResource(tx, new TestResourceHandle(theResource1), XAResource.TMSUCCESS);
-            t.commit();
+            txManager.enlistResource(tx, new TestResourceHandle(theResource));
+            txManager.enlistResource(tx, new TestResourceHandle(theResource2));
+            txManager.enlistResource(tx, new TestResourceHandle(theResource1));
+            txManager.delistResource(tx, new TestResourceHandle(theResource), XAResource.TMSUCCESS);
+            txManager.delistResource(tx, new TestResourceHandle(theResource2), XAResource.TMSUCCESS);
+            txManager.delistResource(tx, new TestResourceHandle(theResource1), XAResource.TMSUCCESS);
+            txManager.commit();
 
-            String status = JavaEETransactionManagerSimplified.getStatusAsString(tx.getStatus());
-            System.out.println("**Status after commit: "  + status + " <===");
-            assert(theResource.prepareStatusOK());
-            assert(theResource1.prepareStatusOK());
-            assert(theResource.commitStatusOK());
-            assert(theResource1.commitStatusOK());
-
-        } catch (Throwable ex) {
-            ex.printStackTrace();
-            assert (false);
+            assertEquals("NoTransaction", JavaEETransactionManagerSimplified.getStatusAsString(tx.getStatus()));
+            assertTrue(theResource.prepareStatusOK());
+            assertTrue(theResource1.prepareStatusOK());
+            assertTrue(theResource.commitStatusOK());
+            assertTrue(theResource1.commitStatusOK());
         }
-        System.out.println("**=================End part1 Resource Status ===>");
-
-        try {
-            t.begin();
-            tx = t.getTransaction();
+        {
+            txManager.begin();
+            Transaction tx = txManager.getTransaction();
             System.out.println("**Testing resource status in rollback ===>");
             TestResource theResource = new TestResource(tx, 1L);
             TestResource theResource2 = new TestResource(tx, 1L);
             TestResource theResource1 = new TestResource(tx);
-            t.enlistResource(tx, new TestResourceHandle(theResource));
-            t.enlistResource(tx, new TestResourceHandle(theResource2));
-            t.enlistResource(tx, new TestResourceHandle(theResource1));
-            t.delistResource(tx, new TestResourceHandle(theResource), XAResource.TMSUCCESS);
-            t.delistResource(tx, new TestResourceHandle(theResource2), XAResource.TMSUCCESS);
-            t.delistResource(tx, new TestResourceHandle(theResource1), XAResource.TMSUCCESS);
+            txManager.enlistResource(tx, new TestResourceHandle(theResource));
+            txManager.enlistResource(tx, new TestResourceHandle(theResource2));
+            txManager.enlistResource(tx, new TestResourceHandle(theResource1));
+            txManager.delistResource(tx, new TestResourceHandle(theResource), XAResource.TMSUCCESS);
+            txManager.delistResource(tx, new TestResourceHandle(theResource2), XAResource.TMSUCCESS);
+            txManager.delistResource(tx, new TestResourceHandle(theResource1), XAResource.TMSUCCESS);
 
-            t.rollback();
+            txManager.rollback();
 
-            String status = JavaEETransactionManagerSimplified.getStatusAsString(tx.getStatus());
-            System.out.println("**Status after rollback: "  + status + " <===");
-            assert(theResource.rollbackStatusOK());
-            assert(theResource1.rollbackStatusOK());
-            assert(!theResource2.isAssociated());
-
-        } catch (Exception ex) {
-            ex.printStackTrace();
-            assert (false);
+            assertEquals("NoTransaction", JavaEETransactionManagerSimplified.getStatusAsString(tx.getStatus()));
+            assertTrue(theResource.rollbackStatusOK());
+            assertTrue(theResource1.rollbackStatusOK());
+            assertFalse(theResource2.isAssociated());
         }
-        System.out.println("**=================End part2 Resource Status ===>");
-
-        try {
-            t.begin();
-            tx = t.getTransaction();
+        {
+            txManager.begin();
+            Transaction tx = txManager.getTransaction();
             System.out.println("**Testing resource status in 1PC ===>");
             TestResource theResource = new TestResource(tx);
-            t.enlistResource(tx, new TestResourceHandle(theResource));
-            t.delistResource(tx, new TestResourceHandle(theResource), XAResource.TMSUCCESS);
-            t.commit();
+            txManager.enlistResource(tx, new TestResourceHandle(theResource));
+            txManager.delistResource(tx, new TestResourceHandle(theResource), XAResource.TMSUCCESS);
+            txManager.commit();
 
             String status = JavaEETransactionManagerSimplified.getStatusAsString(tx.getStatus());
-            System.out.println("**Status after commit: "  + status + " <===");
-            assert(theResource.commitStatusOK());
-
-        } catch (Exception ex) {
-            ex.printStackTrace();
-            assert (false);
+            assertEquals("NoTransaction", JavaEETransactionManagerSimplified.getStatusAsString(tx.getStatus()));
+            assertTrue(theResource.commitStatusOK());
         }
-
     }
 
-    public void testSetRollbackOnlyBeforeEnlist() {
-      try {
-            t.begin();
-            Transaction tx = t.getTransaction();
-            System.out.println("**Testing resource status in setRollbackOnly ===>");
+    @Test
+    public void testSetRollbackOnlyBeforeEnlist() throws Exception {
+        try {
+            txManager.begin();
+            Transaction tx = txManager.getTransaction();
             tx.setRollbackOnly();
-            String status = JavaEETransactionManagerSimplified.getStatusAsString(tx.getStatus());
-            System.out.println("**Status after setRollbackOnly: "  + status + " <===");
-            assertEquals(status, "MarkedRollback");
+            assertEquals("MarkedRollback", JavaEETransactionManagerSimplified.getStatusAsString(tx.getStatus()));
 
             TestResource theResource = new TestResource(tx);
-            try {
-                t.enlistResource(tx, new TestResourceHandle(theResource));
-                t.delistResource(tx, new TestResourceHandle(theResource), XAResource.TMSUCCESS);
-                System.out.println("**Did NOT get RollbackException from t.enlistResource <===");
-                assert (false);
-            } catch (RollbackException ex) {
-                System.out.println("**Caught expected RollbackException from t.enlistResource <===");
-            }
-
-            status = JavaEETransactionManagerSimplified.getStatusAsString(tx.getStatus());
-            System.out.println("**Status after setRollbackOnly & enlist: "  + status + " <===");
-            assertEquals(status, "MarkedRollback");
-        } catch (Exception ex) {
-            ex.printStackTrace();
-            assert (false);
+            assertThrows(RollbackException.class,() ->  txManager.enlistResource(tx, new TestResourceHandle(theResource)));
+            txManager.delistResource(tx, new TestResourceHandle(theResource), XAResource.TMSUCCESS);
+            assertEquals("MarkedRollback", JavaEETransactionManagerSimplified.getStatusAsString(tx.getStatus()));
         } finally {
-            try {
-                t.rollback();
-                String status = JavaEETransactionManagerSimplified.getStatusAsString(t.getStatus());
-                System.out.println("**Status after rollback: "  + status + " <===");
-            } catch (Exception ex) {
-                ex.printStackTrace();
-                assert (false);
-            }
-        }
-
-    }
-
-    public void testWrongTXOperationsAfterCommit() {
-        System.out.println("**Testing Wrong Tx Operations After Commit ===>");
-        Transaction tx = null;
-        try {
-            t.begin();
-            tx = t.getTransaction();
-            System.out.println("**Calling Tx enlistResource ===>");
-            TestResource theResource = new TestResource();
-            t.enlistResource(tx, new TestResourceHandle(theResource));
-            t.delistResource(tx, new TestResourceHandle(theResource), XAResource.TMSUCCESS);
-            t.commit();
-
-            String status = JavaEETransactionManagerSimplified.getStatusAsString(tx.getStatus());
-            System.out.println("**Status after commit: "  + status + " <===");
-
-        } catch (Exception ex) {
-            ex.printStackTrace();
-            assert (false);
-        }
-
-        try {
-            System.out.println("**Calling Tx commit ===>");
-            tx.commit();
-            System.out.println("**WRONG: Tx commit successful <===");
-            assert (false);
-        } catch (IllegalStateException ex) {
-            System.out.println("**Caught IllegalStateException <===");
-            assert (true);
-        } catch (Exception ex) {
-            ex.printStackTrace();
-            assert (false);
-        }
-
-        try {
-            System.out.println("**Calling Tx rollback ===>");
-            tx.rollback();
-            System.out.println("**WRONG: Tx rollback successful <===");
-            assert (false);
-        } catch (IllegalStateException ex) {
-            System.out.println("**Caught IllegalStateException <===");
-            assert (true);
-        } catch (Exception ex) {
-            ex.printStackTrace();
-            assert (false);
-        }
-
-        try {
-            System.out.println("**Calling Tx setRollbackOnly ===>");
-            tx.setRollbackOnly();
-            System.out.println("**WRONG: Tx setRollbackOnly successful <===");
-            assert (false);
-        } catch (IllegalStateException ex) {
-            System.out.println("**Caught IllegalStateException <===");
-            assert (true);
-        } catch (Exception ex) {
-            ex.printStackTrace();
-            assert (false);
-        }
-
-        try {
-            System.out.println("**Calling Tx enlistResource ===>");
-            tx.enlistResource(new TestResource());
-            System.out.println("**WRONG: Tx enlistResource successful <===");
-            assert (false);
-        } catch (IllegalStateException ex) {
-            System.out.println("**Caught IllegalStateException <===");
-            assert (true);
-        } catch (Exception ex) {
-            ex.printStackTrace();
-            assert (false);
-        }
-
-        try {
-            System.out.println("**Calling Tx delistResource ===>");
-            tx.delistResource(new TestResource(), XAResource.TMSUCCESS);
-            System.out.println("**WRONG: Tx delistResource successful <===");
-            assert (false);
-        } catch (IllegalStateException ex) {
-            System.out.println("**Caught IllegalStateException <===");
-            assert (true);
-        } catch (Exception ex) {
-            ex.printStackTrace();
-            assert (false);
-        }
-
-        try {
-            System.out.println("**Calling Tx registerSynchronization ===>");
-            TestSync s = new TestSync(false);
-            tx.registerSynchronization(s);
-            System.out.println("**WRONG: Tx registerSynchronization successful <===");
-            assert (false);
-        } catch (IllegalStateException ex) {
-            System.out.println("**Caught IllegalStateException <===");
-            assert (true);
-        } catch (Exception ex) {
-            ex.printStackTrace();
-            assert (false);
+            txManager.rollback();
+            assertEquals("NoTransaction", JavaEETransactionManagerSimplified.getStatusAsString(txManager.getStatus()));
         }
     }
 
-    public void testWrongResume() {
-        try {
-            System.out.println("**Null resume ....");
-            t.resume(null);
-            System.out.println("**WRONG: TM resume null successful <===");
-            assert (false);
-        } catch (InvalidTransactionException ex) {
-            System.out.println("**Caught InvalidTransactionException <===");
-            assert (true);
-        } catch (Exception ex) {
-            ex.printStackTrace();
-            assert (false);
-        }
-
-        Transaction tx = null;
-        try {
-            System.out.println("**Calling begin-resume(null) ===>");
-            t.begin();
-            tx = t.getTransaction();
-            t.resume(null);
-            System.out.println("**WRONG: begin-resume(null) successful <===");
-            assert (false);
-        } catch (IllegalStateException ex) {
-            System.out.println("**Caught IllegalStateException <===");
-            assert (true);
-        } catch (Exception ex) {
-            ex.printStackTrace();
-            assert (false);
-        }
-
-        try {
-            System.out.println("**Calling Tx rollback ===>");
-            t.rollback();
-            assert (true);
-        } catch (Exception ex) {
-            ex.printStackTrace();
-            assert (false);
-        }
-
-        try {
-            System.out.println("**Calling resume(tx) ===>");
-            t.resume(tx);
-            System.out.println("**WRONG: resume(tx) successful <===");
-            assert (false);
-        } catch (InvalidTransactionException ex) {
-            System.out.println("**Caught InvalidTransactionException <===");
-            assert (true);
-        } catch (Exception ex) {
-            ex.printStackTrace();
-            assert (false);
-        }
-
-    }
-
-    public void testWrongUTXOperationsAfterCommit() {
-        System.out.println("**Testing Wrong UTx Operations After Commit ===>");
-        UserTransaction utx = null;
-        try {
-            t.begin();
-            utx = createUtx();
-            t.commit();
-        } catch (Exception ex) {
-            ex.printStackTrace();
-            assert (false);
-        }
-
-        try {
-            System.out.println("**Calling UTx commit ===>");
-            utx.commit();
-            System.out.println("**WRONG: UTx commit successful <===");
-            assert (false);
-        } catch (IllegalStateException ex) {
-            System.out.println("**Caught IllegalStateException <===");
-            assert (true);
-        } catch (Exception ex) {
-            ex.printStackTrace();
-            assert (false);
-        }
-
-        try {
-            System.out.println("**Calling UTx rollback ===>");
-            utx.rollback();
-            System.out.println("**WRONG: UTx rollback successful <===");
-            assert (false);
-        } catch (IllegalStateException ex) {
-            System.out.println("**Caught IllegalStateException <===");
-            assert (true);
-        } catch (Exception ex) {
-            ex.printStackTrace();
-            assert (false);
-        }
-
-        try {
-            System.out.println("**Calling UTx setRollbackOnly ===>");
-            utx.setRollbackOnly();
-            System.out.println("**WRONG: UTx setRollbackOnly successful <===");
-            assert (false);
-        } catch (IllegalStateException ex) {
-            System.out.println("**Caught IllegalStateException <===");
-            assert (true);
-        } catch (Exception ex) {
-            ex.printStackTrace();
-            assert (false);
-        }
-    }
-
-    public void testWrongUTXBegin() {
-        System.out.println("**Testing Wrong UTX begin ===>");
-        try {
-            UserTransaction utx = createUtx();
-            utx.begin();
-            System.out.println("**Calling TWICE UTX begin ===>");
-            utx.begin();
-            System.out.println("**WRONG: TWICE UTX begin successful <===");
-            assert (false);
-        } catch (NotSupportedException ne) {
-            System.out.println("**Caught NotSupportedException <===");
-            assert (true);
-        } catch (SystemException ne) {
-            System.out.println("**Caught SystemException <===");
-            assert (true);
-        } catch (Exception ex) {
-            ex.printStackTrace();
-            assert (false);
-        }
-    }
-
-    public void testBegin() {
-        System.out.println("**Testing TM begin ===>");
-        try {
-            System.out.println("**Status before begin: "
-                    + JavaEETransactionManagerSimplified.getStatusAsString(t.getStatus()));
-
-            t.begin();
-            String status = JavaEETransactionManagerSimplified.getStatusAsString(t.getStatus());
-            System.out.println("**Status after begin: "  + status + " <===");
-            assertEquals (status, "Active");
-        } catch (Exception ex) {
-            ex.printStackTrace();
-            assert (false);
-        }
-    }
-
-    public void testCommit() {
-        System.out.println("**Testing TM commit ===>");
-        try {
-            System.out.println("**Starting transaction ....");
-            t.begin();
-            assertEquals (JavaEETransactionManagerSimplified.getStatusAsString(t.getStatus()),
-                "Active");
-
-            System.out.println("**Calling TM commit ===>");
-            t.commit();
-            String status = JavaEETransactionManagerSimplified.getStatusAsString(t.getStatus());
-            System.out.println("**Status after commit: " + status + " <===");
-            assert (true);
-        } catch (Exception ex) {
-            ex.printStackTrace();
-            assert (false);
-        }
-    }
-
-    public void testRollback() {
-        System.out.println("**Testing TM rollback ===>");
-        try {
-            System.out.println("**Starting transaction ....");
-            t.begin();
-            assertEquals (JavaEETransactionManagerSimplified.getStatusAsString(t.getStatus()),
-                "Active");
-
-            System.out.println("**Calling TM rollback ===>");
-            t.rollback();
-            System.out.println("**Status after rollback: "
-                    + JavaEETransactionManagerSimplified.getStatusAsString(t.getStatus())
-                    + " <===");
-            assert (true);
-        } catch (Exception ex) {
-            ex.printStackTrace();
-            assert (false);
-        }
-    }
-
-    public void testTxCommit() {
-        System.out.println("**Testing TX commit ===>");
-        try {
-            System.out.println("**Starting transaction ....");
-            t.begin();
-            Transaction tx = t.getTransaction();
-
-            System.out.println("**Registering Synchronization ....");
-            TestSync s = new TestSync(false);
-            tx.registerSynchronization(s);
-
-            String status = JavaEETransactionManagerSimplified.getStatusAsString(t.getStatus());
-            System.out.println("**TX Status after begin: " + status);
-
-            assertEquals (status, "Active");
-
-            System.out.println("**Calling TX commit ===>");
-            tx.commit();
-            System.out.println("**Status after commit: "
-                    + JavaEETransactionManagerSimplified.getStatusAsString(tx.getStatus())
-                    + " <===");
-            assertTrue ("beforeCompletion was not called", s.called_beforeCompletion);
-            assertTrue ("afterCompletion was not called", s.called_afterCompletion);
-            assert (true);
-        } catch (Exception ex) {
-            ex.printStackTrace();
-            assert (false);
-        }
-    }
-
-    public void testTxSuspendResume() {
-        System.out.println("**Testing TM suspend ===>");
-        try {
-            System.out.println("**No-tx suspend ....");
-            assertNull(t.suspend());
-
-            System.out.println("**Starting transaction ....");
-            t.begin();
-
-            Transaction tx = t.suspend();
-            assertNotNull(tx);
-
-            System.out.println("**TX suspended ....");
-
-            System.out.println("**No-tx suspend ....");
-            assertNull(t.suspend());
-
-            System.out.println("**Calling TM resume ===>");
-            t.resume(tx);
-
-            assertEquals (JavaEETransactionManagerSimplified.getStatusAsString(tx.getStatus()),
-                "Active");
-
-            System.out.println("**Calling TX commit ===>");
-            tx.commit();
-            String status = JavaEETransactionManagerSimplified.getStatusAsString(tx.getStatus());
-            System.out.println("**Status after commit: " + status + " <===");
-            assert (true);
-        } catch (Exception ex) {
-            ex.printStackTrace();
-            assert (false);
-        }
-    }
-
-    public void testTxRollback() {
-        System.out.println("**Testing TX rollback ===>");
-        try {
-            System.out.println("**Starting transaction ....");
-            t.begin();
-            Transaction tx = t.getTransaction();
-
-            System.out.println("**Registering Synchronization ....");
-            TestSync s = new TestSync(false);
-            tx.registerSynchronization(s);
-
-            String status = JavaEETransactionManagerSimplified.getStatusAsString(t.getStatus());
-            System.out.println("**TX Status after begin: " + status);
-
-            assertEquals (status, "Active");
-
-            System.out.println("**Calling TX rollback ===>");
-            tx.rollback();
-            System.out.println("**Status after rollback: "
-                    + JavaEETransactionManagerSimplified.getStatusAsString(tx.getStatus())
-                    + " <===");
-            assertFalse ("beforeCompletion was called", s.called_beforeCompletion);
-            assertTrue ("afterCompletion was not called", s.called_afterCompletion);
-            assert (true);
-        } catch (Exception ex) {
-            ex.printStackTrace();
-            assert (false);
-        }
-    }
-
-    public void testUTxCommit() {
-        System.out.println("**Testing UTX commit ===>");
-        try {
-            UserTransaction utx = createUtx();
-            System.out.println("**Starting transaction ....");
-            utx.begin();
-            String status = JavaEETransactionManagerSimplified.getStatusAsString(t.getStatus());
-            System.out.println("**UTX Status after begin: " + status);
-
-            assertEquals (status, "Active");
-
-            System.out.println("**Calling UTX commit ===>");
-            utx.commit();
-            System.out.println("**Status after commit: "
-                    + JavaEETransactionManagerSimplified.getStatusAsString(utx.getStatus())
-                    + " <===");
-            assert (true);
-        } catch (Exception ex) {
-            ex.printStackTrace();
-            assert (false);
-        }
-    }
-
-    public void testUTxRollback() {
-        System.out.println("**Testing UTX rollback ===>");
-        try {
-            UserTransaction utx = createUtx();
-            System.out.println("**Starting transaction ....");
-            utx.begin();
-
-            assertEquals (JavaEETransactionManagerSimplified.getStatusAsString(utx.getStatus()),
-                "Active");
-
-            System.out.println("**Calling UTX rollback ===>");
-            utx.rollback();
-            System.out.println("**Status after rollback: "
-                    + JavaEETransactionManagerSimplified.getStatusAsString(utx.getStatus())
-                    + " <===");
-            assert (true);
-        } catch (Exception ex) {
-            ex.printStackTrace();
-            assert (false);
-        }
-    }
-
-    public void testTxCommitFailBC2PC() {
-        System.out.println("**Testing TX commit with exception in beforeCompletion of 2PC ===>");
-        try {
-            // Suppress warnings from beforeCompletion() logging
-            ((JavaEETransactionManagerSimplified)t).getLogger().setLevel(Level.SEVERE);
-            LogDomains.getLogger(SynchronizationImpl.class, LogDomains.TRANSACTION_LOGGER).setLevel(Level.SEVERE);
-
-            System.out.println("**Starting transaction ....");
-            t.begin();
-            Transaction tx = t.getTransaction();
-
-            System.out.println("**Registering Synchronization ....");
-            TestSync s = new TestSync(true);
-            tx.registerSynchronization(s);
-
-            String status = JavaEETransactionManagerSimplified.getStatusAsString(t.getStatus());
-            System.out.println("**TX Status after begin: " + status);
-
-            assertEquals (status, "Active");
-
-            TestResource theResource = new TestResource();
-            TestResource theResource1 = new TestResource();
-
-            t.enlistResource(tx, new TestResourceHandle(theResource));
-            t.enlistResource(tx, new TestResourceHandle(theResource1));
-
-            theResource.setCommitErrorCode(9999);
-            theResource1.setCommitErrorCode(9999);
-
-            t.delistResource(tx, new TestResourceHandle(theResource), XAResource.TMSUCCESS);
-            t.delistResource(tx, new TestResourceHandle(theResource1), XAResource.TMSUCCESS);
-
-            System.out.println("**Calling TX commit ===>");
-            try {
-                tx.commit();
-                assert (false);
-            } catch (RollbackException ex) {
-                System.out.println("**Caught expected exception...");
-                Throwable te = ex.getCause();
-                if (te != null && te instanceof MyRuntimeException) {
-                    System.out.println("**Caught expected nested exception...");
-                } else {
-                    System.out.println("**Unexpected nested exception: " + te);
-                    assert (false);
-                }
-            }
-            System.out.println("**Status after commit: "
-                    + JavaEETransactionManagerSimplified.getStatusAsString(tx.getStatus())
-                    + " <===");
-            assertTrue ("beforeCompletion was not called", s.called_beforeCompletion);
-            assertTrue ("afterCompletion was not called", s.called_afterCompletion);
-            assert (true);
-        } catch (Exception ex) {
-            ex.printStackTrace();
-            assert (false);
-        }
-    }
-
-    public void testTMCommitFailBC2PC() {
-        System.out.println("**Testing TM commit with exception in beforeCompletion of 2PC ===>");
-        try {
-            // Suppress warnings from beforeCompletion() logging
-            ((JavaEETransactionManagerSimplified)t).getLogger().setLevel(Level.SEVERE);
-            LogDomains.getLogger(SynchronizationImpl.class, LogDomains.TRANSACTION_LOGGER).setLevel(Level.SEVERE);
-
-            System.out.println("**Starting transaction ....");
-            t.begin();
-            Transaction tx = t.getTransaction();
-
-            System.out.println("**Registering Synchronization ....");
-            TestSync s = new TestSync(true);
-            tx.registerSynchronization(s);
-
-            String status = JavaEETransactionManagerSimplified.getStatusAsString(t.getStatus());
-            System.out.println("**TX Status after begin: " + status);
-
-            assertEquals (status, "Active");
-
-            TestResource theResource = new TestResource();
-            TestResource theResource1 = new TestResource();
-
-            t.enlistResource(tx, new TestResourceHandle(theResource));
-            t.enlistResource(tx, new TestResourceHandle(theResource1));
-
-            theResource.setCommitErrorCode(9999);
-            theResource1.setCommitErrorCode(9999);
-
-            t.delistResource(tx, new TestResourceHandle(theResource), XAResource.TMSUCCESS);
-            t.delistResource(tx, new TestResourceHandle(theResource1), XAResource.TMSUCCESS);
-
-            System.out.println("**Calling TM commit ===>");
-            try {
-                t.commit();
-                assert (false);
-            } catch (RollbackException ex) {
-                System.out.println("**Caught expected exception...");
-                Throwable te = ex.getCause();
-                if (te != null && te instanceof MyRuntimeException) {
-                    System.out.println("**Caught expected nested exception...");
-                } else {
-                    System.out.println("**Unexpected nested exception: " + te);
-                    assert (false);
-                }
-            }
-            System.out.println("**Status after commit: "
-                    + JavaEETransactionManagerSimplified.getStatusAsString(tx.getStatus())
-                    + " <===");
-            assertTrue ("beforeCompletion was not called", s.called_beforeCompletion);
-            assertTrue ("afterCompletion was not called", s.called_afterCompletion);
-            assert (true);
-        } catch (Exception ex) {
-            ex.printStackTrace();
-            assert (false);
-        }
-    }
-
-    public void testTxCommitFailBC1PC() {
-        System.out.println("**Testing TX commit with exception in beforeCompletion of 1PC ===>");
-        try {
-            // Suppress warnings from beforeCompletion() logging
-            ((JavaEETransactionManagerSimplified)t).getLogger().setLevel(Level.SEVERE);
-            LogDomains.getLogger(SynchronizationImpl.class, LogDomains.TRANSACTION_LOGGER).setLevel(Level.SEVERE);
-
-            System.out.println("**Starting transaction ....");
-            t.begin();
-            Transaction tx = t.getTransaction();
-
-            System.out.println("**Registering Synchronization ....");
-            TestSync s = new TestSync(true);
-            tx.registerSynchronization(s);
-
-            String status = JavaEETransactionManagerSimplified.getStatusAsString(t.getStatus());
-            System.out.println("**TX Status after begin: " + status);
-
-            assertEquals (status, "Active");
-
-            TestResource theResource = new TestResource();
-            t.enlistResource(tx, new TestResourceHandle(theResource));
-
-            theResource.setCommitErrorCode(9999);
-            t.delistResource(tx, new TestResourceHandle(theResource), XAResource.TMSUCCESS);
-
-            System.out.println("**Calling TX commit ===>");
-            try {
-                tx.commit();
-                assert (false);
-            } catch (RollbackException ex) {
-                System.out.println("**Caught expected exception...");
-
-                Throwable te = ex.getCause();
-                if (te != null && te instanceof MyRuntimeException) {
-                    System.out.println("**Caught expected nested exception...");
-                } else {
-                    System.out.println("**Unexpected nested exception: " + te);
-                    assert (false);
-                }
-            }
-            System.out.println("**Status after commit: "
-                    + JavaEETransactionManagerSimplified.getStatusAsString(tx.getStatus())
-                    + " <===");
-            assertTrue ("beforeCompletion was not called", s.called_beforeCompletion);
-            assertTrue ("afterCompletion was not called", s.called_afterCompletion);
-            assert (true);
-        } catch (Exception ex) {
-            ex.printStackTrace();
-            assert (false);
-        }
-    }
-
-    public void testTxCommitFailBC2PCInterposedSynchronization() {
-        System.out.println("**Testing TX commit with exception in InterposedSynchronization in beforeCompletion of 2PC ===>");
-        try {
-            // Suppress warnings from beforeCompletion() logging
-            ((JavaEETransactionManagerSimplified)t).getLogger().setLevel(Level.SEVERE);
-            LogDomains.getLogger(SynchronizationImpl.class, LogDomains.TRANSACTION_LOGGER).setLevel(Level.SEVERE);
-
-            System.out.println("**Starting transaction ....");
-            t.begin();
-            Transaction tx = t.getTransaction();
-
-            System.out.println("**Registering Synchronization ....");
-            TestSync s = new TestSync(true);
-
-            TransactionSynchronizationRegistry ts = new TransactionSynchronizationRegistryImpl(t);
-            ts.registerInterposedSynchronization(s);
-
-            String status = JavaEETransactionManagerSimplified.getStatusAsString(t.getStatus());
-            System.out.println("**TX Status after begin: " + status);
-
-            assertEquals (status, "Active");
-
-            TestResource theResource = new TestResource();
-            TestResource theResource1 = new TestResource();
-
-            t.enlistResource(tx, new TestResourceHandle(theResource));
-            t.enlistResource(tx, new TestResourceHandle(theResource1));
-
-            theResource.setCommitErrorCode(9999);
-            theResource1.setCommitErrorCode(9999);
-
-            t.delistResource(tx, new TestResourceHandle(theResource), XAResource.TMSUCCESS);
-            t.delistResource(tx, new TestResourceHandle(theResource1), XAResource.TMSUCCESS);
-
-            System.out.println("**Calling TX commit ===>");
-            try {
-                tx.commit();
-                assert (false);
-            } catch (RollbackException ex) {
-                System.out.println("**Caught expected exception...");
-
-                Throwable te = ex.getCause();
-                if (te != null && te instanceof MyRuntimeException) {
-                    System.out.println("**Caught expected nested exception...");
-                } else {
-                    System.out.println("**Unexpected nested exception: " + te);
-                    assert (false);
-                }
-            }
-            System.out.println("**Status after commit: "
-                    + JavaEETransactionManagerSimplified.getStatusAsString(tx.getStatus())
-                    + " <===");
-            assertTrue ("beforeCompletion was not called", s.called_beforeCompletion);
-            assertTrue ("afterCompletion was not called", s.called_afterCompletion);
-            assert (true);
-        } catch (Exception ex) {
-            ex.printStackTrace();
-            assert (false);
-        }
-    }
-
-    public void testTxCommitFailBC1PCInterposedSynchronization() {
-        System.out.println("**Testing TX commit with exception in InterposedSynchronization in beforeCompletion of 1PC ===>");
-        try {
-            // Suppress warnings from beforeCompletion() logging
-            ((JavaEETransactionManagerSimplified)t).getLogger().setLevel(Level.SEVERE);
-            LogDomains.getLogger(SynchronizationImpl.class, LogDomains.TRANSACTION_LOGGER).setLevel(Level.SEVERE);
-
-            System.out.println("**Starting transaction ....");
-            t.begin();
-            Transaction tx = t.getTransaction();
-
-            System.out.println("**Registering Synchronization ....");
-            TestSync s = new TestSync(true);
-            TransactionSynchronizationRegistry ts = new TransactionSynchronizationRegistryImpl(t);
-            ts.registerInterposedSynchronization(s);
-
-            String status = JavaEETransactionManagerSimplified.getStatusAsString(t.getStatus());
-            System.out.println("**TX Status after begin: " + status);
-
-            assertEquals (status, "Active");
-
-            TestResource theResource = new TestResource();
-            t.enlistResource(tx, new TestResourceHandle(theResource));
-
-            theResource.setCommitErrorCode(9999);
-            t.delistResource(tx, new TestResourceHandle(theResource), XAResource.TMSUCCESS);
-
-            System.out.println("**Calling TX commit ===>");
-            try {
-                tx.commit();
-                assert (false);
-            } catch (RollbackException ex) {
-                System.out.println("**Caught expected exception...");
-
-                Throwable te = ex.getCause();
-                if (te != null && te instanceof MyRuntimeException) {
-                    System.out.println("**Caught expected nested exception...");
-                } else {
-                    System.out.println("**Unexpected nested exception: " + te);
-                    assert (false);
-                }
-            }
-            System.out.println("**Status after commit: "
-                    + JavaEETransactionManagerSimplified.getStatusAsString(tx.getStatus())
-                    + " <===");
-            assertTrue ("beforeCompletion was not called", s.called_beforeCompletion);
-            assertTrue ("afterCompletion was not called", s.called_afterCompletion);
-            assert (true);
-        } catch (Exception ex) {
-            ex.printStackTrace();
-            assert (false);
-        }
-    }
-
-    public void testTxCommitRollbackBC() {
-        System.out.println("**Testing TX commit with rollback in beforeCompletion ===>");
-        try {
-            // Suppress warnings from beforeCompletion() logging
-            ((JavaEETransactionManagerSimplified)t).getLogger().setLevel(Level.SEVERE);
-
-            System.out.println("**Starting transaction ....");
-            t.begin();
-            Transaction tx = t.getTransaction();
-
-            System.out.println("**Registering Synchronization ....");
-            TestSync s = new TestSync(t);
-            tx.registerSynchronization(s);
-
-            String status = JavaEETransactionManagerSimplified.getStatusAsString(t.getStatus());
-            System.out.println("**TX Status after begin: " + status);
-
-            assertEquals (status, "Active");
-
-            System.out.println("**Calling TX commit ===>");
-            try {
-                tx.commit();
-                assert (false);
-            } catch (RollbackException ex) {
-                System.out.println("**Caught expected exception...");
-            }
-            System.out.println("**Status after commit: "
-                    + JavaEETransactionManagerSimplified.getStatusAsString(tx.getStatus())
-                    + " <===");
-            assertTrue ("beforeCompletion was not called", s.called_beforeCompletion);
-            assertTrue ("afterCompletion was not called", s.called_afterCompletion);
-            assert (true);
-        } catch (Exception ex) {
-            ex.printStackTrace();
-            assert (false);
-        }
-    }
-
-    public void testCommit2PCWithRollbackExc1() {
-        System.out.println("**Testing XA_RBROLLBACK in prepare & XA_HEURRB in rollback ===>");
-        _testCommit2PCWithRollbackExc(XAException.XA_RBROLLBACK, XAException.XA_HEURRB);
-    }
-
-    public void testCommit2PCWithRollbackExc2() {
-        System.out.println("**Testing XA_RBROLLBACK in prepare & 2 XA_HEURRB in rollback ===>");
-        _testCommit2PCWithRollbackExc(XAException.XA_RBROLLBACK, XAException.XA_HEURRB, XAException.XA_HEURRB);
-    }
-
-    public void testCommit2PCWithRollbackExc3() {
-        System.out.println("**Testing XA_RDONLY in prepare & 2 XA_HEURRB in rollback ===>");
-        _testCommit2PCWithRollbackExc(XAException.XA_RDONLY, XAException.XA_HEURRB, 9999);
-    }
-
-    private void _testCommit2PCWithRollbackExc(int preapareErrCode, int... rollbackErrorCode) {
-        System.out.println("**Testing different rollback errors in prepare & rollback ===>");
-        TestResource theResourceP = new TestResource();
-        TestResource[] theResourceR = null;
-        try {
-            System.out.println("**Starting transaction ....");
-            t.begin();
-            assertEquals (JavaEETransactionManagerSimplified.getStatusAsString(t.getStatus()),
-                "Active");
-
-            // Create and set invMgr
-            createUtx();
-            Transaction tx = t.getTransaction();
-            t.enlistResource(tx, new TestResourceHandle(theResourceP));
-            theResourceP.setPrepareErrorCode(preapareErrCode);
-            theResourceR = enlistForRollback(tx, rollbackErrorCode);
-
-            t.delistResource(tx, new TestResourceHandle(theResourceP), XAResource.TMSUCCESS);
-
-            System.out.println("**Calling TM commit ===>");
-            t.commit();
-            String status = JavaEETransactionManagerSimplified.getStatusAsString(t.getStatus());
-            System.out.println("**Error - successful commit - Status after commit: " + status + " <===");
-            assert (false);
-        } catch (RollbackException ex) {
-            System.out.println("**Caught expected RollbackException...");
-            try {
-                String status = JavaEETransactionManagerSimplified.getStatusAsString(t.getStatus());
-                System.out.println("**Status after commit: " + status + " <===");
-            } catch (Exception ex1) {
-                System.out.println("**Caught exception checking for status ...");
-                ex1.printStackTrace();
-            }
-            boolean status = theResourceP.forgetCalled();
-            System.out.println("**Forget 1 was called: " + theResourceP.forgetCalled());
-
-            for (int i = 0; i < theResourceR.length; i++) {
-                System.out.println("**Forget 2 was called for resourceR " + i + ": " + theResourceR[i].forgetCalled());
-                status = status && theResourceR[i].forgetCalled();
-            }
-            assert (status);
-        } catch (Throwable ex) {
-            System.out.println("**Caught NOT a RollbackException during 2PC...");
-            ex.printStackTrace();
-            assert (false);
-        }
-    }
-
-    public void testCommitOnePhaseWithHeuristicRlbExc1() {
-        _testCommitOnePhaseWithExc(XAException.XA_HEURRB, HeuristicRollbackException.class, false, true);
-    }
-
-    public void testCommitOnePhaseWithHeuristicMixedExc2() {
-        _testCommitOnePhaseWithExc(XAException.XA_HEURMIX, HeuristicMixedException.class, false, true);
-    }
-
-    public void testCommitOnePhaseWithRlbExc1() {
-        System.out.println("**Testing XAER_NOTA in 1PC ===>");
-        _testCommitOnePhaseWithExc(XAException.XAER_NOTA, RollbackException.class, false, false);
-    }
-
-    public void testCommitOnePhaseWithRlbExc2() {
-        System.out.println("**Testing XAER_RMERR in 1PC ===>");
-        _testCommitOnePhaseWithExc(XAException.XAER_RMERR, RollbackException.class, false, false);
-    }
-
-    public void testCommitOnePhaseWithRlbExc3() {
-        System.out.println("**Testing XA_RBROLLBACK in rollback part of 1PC ===>");
-        _testCommitOnePhaseWithExc(XAException.XA_RBROLLBACK, RollbackException.class, true, false);
-    }
-
-    public void testCommitOnePhaseWithRlbExc4() {
-        System.out.println("**Testing XAER_RMERR in rollback part of 1PC ===>");
-        _testCommitOnePhaseWithExc(XAException.XAER_RMERR, RollbackException.class, true, false);
-    }
-
-    public void testCommitOnePhaseWithRlbExc5() {
-        System.out.println("**Testing XAER_RMFAIL in rollback part of 1PC ===>");
-        _testCommitOnePhaseWithExc(XAException.XAER_RMFAIL, RollbackException.class, true, false);
-    }
-
-    public void testCommitOnePhaseWithRlbExc6() {
-        System.out.println("================= **Testing XA Exception on start ===>");
-        int falures[] = {XAException.XAER_RMFAIL,
-                XAException.XAER_RMERR,
-                XAException.XAER_NOTA,
-                XAException.XAER_INVAL,
-                XAException.XAER_PROTO,
-                XAException.XAER_DUPID};
-        boolean result = true;
-        for (int failure : falures) {
-            try {
-                boolean rc = _testCommitOnePhaseWithExc(failure, SystemException.class, false, false, true, true);
-                result &= rc;
-                if (rc) {
-                    System.out.println("================= **Testing code " + failure + " OK");
-                } else {
-                    System.out.println("================= **ERROR Testing code " + failure);
-                }
-            } catch (Exception e) {
-                e.printStackTrace();
-            }
-        }
-        assert (result);
-    }
-
-    public void testCommitOnePhaseWithXAExc1() {
-        System.out.println("**Testing TM with failed 1PC commit ===>");
-        _testCommitOnePhaseWithExc(XAException.XAER_RMFAIL, SystemException.class, false, false);
-    }
-
-    public void testCommitOnePhaseWithXAExc2() {
-        System.out.println("**Testing TM with XA_HEURCOM in 1PC commit ===>");
-        _testCommitOnePhaseWithExc(XAException.XA_HEURCOM, null, false, true);
-    }
-
-    public void testRollbackWithErrorNoExc1() {
-        System.out.println("**Testing XA_RBROLLBACK in rollback ===>");
-        _testXARollback(XAException.XA_RBROLLBACK);
-    }
-
-    public void testRollbackWithErrorNoExc2() {
-        System.out.println("**Testing XAER_RMERR in rollback ===>");
-        _testXARollback(XAException.XAER_RMERR);
-    }
-
-    public void testRollbackWithErrorNoExc3() {
-        System.out.println("**Testing XAER_NOTA in rollback ===>");
-        _testXARollback(XAException.XAER_NOTA);
-    }
-
-    public void testRollbackWithErrorNoExc4() {
-        System.out.println("**Testing XAER_RMFAIL in rollback ===>");
-        _testXARollback(XAException.XAER_RMFAIL);
-    }
-
-    public void testRollbackWithErrorNoExc5() {
-        System.out.println("**Testing XA_HEURRB in rollback ===>");
-        _testXARollback(XAException.XA_HEURRB);
-    }
-
-    public void testRollbackWithErrorNoExc6() {
-        System.out.println("**Testing 2 XA_HEURRB in rollback ===>");
-        _testXARollback(XAException.XA_HEURRB, XAException.XA_HEURRB);
-    }
-
-    private void _testCommitOnePhaseWithExc(int errorCode, Class exType, boolean setRollbackOnly, boolean isHeuristic) {
-        _testCommitOnePhaseWithExc(errorCode, exType, setRollbackOnly, isHeuristic, false, false);
-    }
-
-    private boolean _testCommitOnePhaseWithExc(int errorCode, Class exType,
-            boolean setRollbackOnly, boolean isHeuristic, boolean failAtEnlist, boolean returnStatus) {
-        boolean rc = true;
-
-        System.out.println("**Testing TM with " + ((exType == null)? "success" : exType.getName()) + " during 1PC commit ===>");
-        ((JavaEETransactionManagerSimplified)t).getLogger().setLevel(Level.SEVERE);
-        LogDomains.getLogger(OTSResourceImpl.class, LogDomains.TRANSACTION_LOGGER).setLevel(Level.SEVERE);
+    @Test
+    public void testWrongTXOperationsAfterCommit() throws Exception {
+        txManager.begin();
+        Transaction tx = txManager.getTransaction();
         TestResource theResource = new TestResource();
-        boolean enlist_status = true;
-        try {
-            System.out.println("**Starting transaction ....");
-            t.begin();
-            assertEquals (JavaEETransactionManagerSimplified.getStatusAsString(t.getStatus()),
-                "Active");
+        txManager.enlistResource(tx, new TestResourceHandle(theResource));
+        txManager.delistResource(tx, new TestResourceHandle(theResource), XAResource.TMSUCCESS);
+        txManager.commit();
 
-            // Create and set invMgr
-            createUtx();
-            Transaction tx = t.getTransaction();
-            if (setRollbackOnly) {
-                theResource.setRollbackErrorCode(errorCode);
-            } else if (failAtEnlist) {
-                theResource.setStartErrorCode(errorCode);
-            } else {
-                theResource.setCommitErrorCode(errorCode);
-            }
-
-            try {
-                t.enlistResource(tx, new TestResourceHandle(theResource));
-            } catch (Exception ex) {
-                if (failAtEnlist && exType != null && exType.isInstance(ex)) {
-                    System.out.println("**Caught expected " + exType.getName() + " ...");
-                } else {
-                    System.out.println("**Caught unexpected exception" );
-                    ex.printStackTrace();
-                    enlist_status = false;
-                }
-            }
-
-            t.delistResource(tx, new TestResourceHandle(theResource), XAResource.TMSUCCESS);
-
-            if (setRollbackOnly) {
-                System.out.println("**Calling TM setRollbackOnly ===>");
-                t.setRollbackOnly();
-            }
-
-            System.out.println("**Calling TM commit ===>");
-            t.commit();
-            String status = JavaEETransactionManagerSimplified.getStatusAsString(t.getStatus());
-            if (!failAtEnlist && exType != null) {
-                System.out.println("**Error - successful commit - Status after commit: " + status + " <===");
-                if (returnStatus) {
-                    rc = false;
-                } else {
-                    assert (false);
-                }
-            } else {
-                System.out.println("**Successful commit - Status after commit: " + status + " <===");
-                if (returnStatus) {
-                    rc = rc && enlist_status;
-                } else {
-                    assert (enlist_status);
-                }
-            }
-        } catch (Exception ex) {
-            if (exType != null && exType.isInstance(ex)) {
-                System.out.println("**Caught expected " + exType.getName() + " ...");
-                try {
-                    String status = JavaEETransactionManagerSimplified.getStatusAsString(t.getStatus());
-                    System.out.println("**Status after commit: " + status + " <===");
-                } catch (Exception ex1) {
-                    ex1.printStackTrace();
-                }
-
-                boolean status = true;
-                if (isHeuristic) {
-                   status = theResource.forgetCalled();
-                   System.out.println("**Forget was called: " + status);
-                }
-
-                if (returnStatus) {
-                    rc = rc && enlist_status && status;
-                } else {
-                    assert (enlist_status && status);
-                }
-            } else {
-                System.out.println("**Caught " + ((exType == null)? " unexpected " : " NOT a " + exType.getName()) + " during 2PC...");
-                ex.printStackTrace();
-                if (returnStatus) {
-                    rc = false;
-                } else {
-                    assert (false);
-                }
-            }
-        }
-        return rc;
+        assertEquals("NoTransaction", JavaEETransactionManagerSimplified.getStatusAsString(tx.getStatus()));
+        assertThrows(IllegalStateException.class, tx::commit);
+        assertThrows(IllegalStateException.class, tx::rollback);
+        assertThrows(IllegalStateException.class, tx::setRollbackOnly);
+        assertThrows(IllegalStateException.class, () -> tx.enlistResource(new TestResource()));
+        assertThrows(IllegalStateException.class, () -> tx.delistResource(new TestResource(), XAResource.TMSUCCESS));
+        assertThrows(IllegalStateException.class, () -> tx.registerSynchronization(new TestSync(false)));
     }
 
-    private void _testXARollback(int... errorCode) {
-        System.out.println("**Testing TM with XA error during XA rollback ===>");
-        ((JavaEETransactionManagerSimplified)t).getLogger().setLevel(Level.SEVERE);
-        LogDomains.getLogger(OTSResourceImpl.class, LogDomains.TRANSACTION_LOGGER).setLevel(Level.SEVERE);
-        try {
-            System.out.println("**Starting transaction ....");
-            t.begin();
-            assertEquals (JavaEETransactionManagerSimplified.getStatusAsString(t.getStatus()),
-                "Active");
+    @Test
+    public void testWrongResume() throws Exception {
+        assertThrows(InvalidTransactionException.class, () -> txManager.resume(null));
+        txManager.begin();
+        final Transaction tx = txManager.getTransaction();
+        assertThrows(IllegalStateException.class, () -> txManager.resume(null));
+        txManager.rollback();
+        assertThrows(InvalidTransactionException.class, () -> txManager.resume(tx));
+    }
 
-            // Create and set invMgr
-            createUtx();
-            Transaction tx = t.getTransaction();
-            enlistForRollback(tx, errorCode);
+    @Test
+    public void testWrongUTXOperationsAfterCommit() throws Exception {
+        txManager.begin();
+        UserTransaction utx = createUtx();
+        txManager.commit();
+        assertThrows(IllegalStateException.class, utx::commit);
+        assertThrows(IllegalStateException.class, utx::rollback);
+        assertThrows(IllegalStateException.class, utx::setRollbackOnly);
+    }
 
-            System.out.println("**Calling TM rollback ===>");
-            t.rollback();
-            System.out.println("**Status after rollback: "
-                    + JavaEETransactionManagerSimplified.getStatusAsString(t.getStatus())
-                    + " <===");
-            assert (true);
-        } catch (Exception ex) {
-            System.out.println("**Caught unexpected exception");
-            ex.printStackTrace();
-            assert (false);
+    @Test
+    public void testWrongUTXBegin() throws Exception {
+        UserTransaction utx = createUtx();
+        utx.begin();
+        assertThrows(NotSupportedException.class, utx::begin);
+    }
+
+    @Test
+    public void testBegin() throws Exception {
+        assertEquals("NoTransaction", JavaEETransactionManagerSimplified.getStatusAsString(txManager.getStatus()));
+        txManager.begin();
+        assertEquals("Active", JavaEETransactionManagerSimplified.getStatusAsString(txManager.getStatus()));
+    }
+
+    @Test
+    public void testCommit() throws Exception {
+        txManager.begin();
+        assertEquals("Active", JavaEETransactionManagerSimplified.getStatusAsString(txManager.getStatus()));
+        txManager.commit();
+        assertEquals("NoTransaction", JavaEETransactionManagerSimplified.getStatusAsString(txManager.getStatus()));
+    }
+
+    @Test
+    public void testRollback() throws Exception {
+        txManager.begin();
+        assertEquals("Active", JavaEETransactionManagerSimplified.getStatusAsString(txManager.getStatus()));
+        txManager.rollback();
+        assertEquals("NoTransaction", JavaEETransactionManagerSimplified.getStatusAsString(txManager.getStatus()));
+    }
+
+    @Test
+    public void testTxCommit() throws Exception {
+        txManager.begin();
+        final Transaction tx = txManager.getTransaction();
+
+        TestSync sync = new TestSync(false);
+        tx.registerSynchronization(sync);
+        assertEquals("Active", JavaEETransactionManagerSimplified.getStatusAsString(txManager.getStatus()));
+
+        tx.commit();
+        assertEquals("NoTransaction", JavaEETransactionManagerSimplified.getStatusAsString(txManager.getStatus()));
+        assertTrue(sync.called_beforeCompletion, "beforeCompletion was not called");
+        assertTrue(sync.called_afterCompletion, "afterCompletion was not called");
+    }
+
+    @Test
+    public void testTxSuspendResume() throws Exception {
+        assertNull(txManager.suspend());
+        txManager.begin();
+        final Transaction tx = txManager.suspend();
+        assertNotNull(tx);
+        assertNull(txManager.suspend());
+
+        txManager.resume(tx);
+        assertEquals("Active", JavaEETransactionManagerSimplified.getStatusAsString(txManager.getStatus()));
+
+        tx.commit();
+        assertEquals("Committed", JavaEETransactionManagerSimplified.getStatusAsString(tx.getStatus()));
+        assertEquals("NoTransaction", JavaEETransactionManagerSimplified.getStatusAsString(txManager.getStatus()));
+    }
+
+    @Test
+    public void testTxRollback() throws Exception {
+        txManager.begin();
+        final Transaction tx = txManager.getTransaction();
+        final TestSync sync = new TestSync(false);
+        tx.registerSynchronization(sync);
+        assertEquals("Active", JavaEETransactionManagerSimplified.getStatusAsString(txManager.getStatus()));
+
+        tx.rollback();
+        assertEquals("RolledBack", JavaEETransactionManagerSimplified.getStatusAsString(tx.getStatus()));
+        assertFalse(sync.called_beforeCompletion, "beforeCompletion was called");
+        assertTrue(sync.called_afterCompletion, "afterCompletion was not called");
+    }
+
+    @Test
+    public void testUTxCommit() throws Exception {
+        final UserTransaction utx = createUtx();
+        utx.begin();
+        assertEquals("Active", JavaEETransactionManagerSimplified.getStatusAsString(utx.getStatus()));
+
+        utx.commit();
+        assertEquals("NoTransaction", JavaEETransactionManagerSimplified.getStatusAsString(utx.getStatus()));
+    }
+
+    @Test
+    public void testUTxRollback() throws Exception {
+        final UserTransaction utx = createUtx();
+        utx.begin();
+        assertEquals("Active", JavaEETransactionManagerSimplified.getStatusAsString(utx.getStatus()));
+
+        utx.rollback();
+        assertEquals("NoTransaction", JavaEETransactionManagerSimplified.getStatusAsString(utx.getStatus()));
+    }
+
+    @Test
+    public void testTxCommitFailBC2PC() throws Exception {
+        txManager.begin();
+        final Transaction tx = txManager.getTransaction();
+        final TestSync sync = new TestSync(true);
+        tx.registerSynchronization(sync);
+        assertEquals("Active", JavaEETransactionManagerSimplified.getStatusAsString(txManager.getStatus()));
+
+        final TestResource theResource = new TestResource();
+        final TestResource theResource1 = new TestResource();
+        txManager.enlistResource(tx, new TestResourceHandle(theResource));
+        txManager.enlistResource(tx, new TestResourceHandle(theResource1));
+        theResource.setCommitErrorCode(9999);
+        theResource1.setCommitErrorCode(9999);
+        txManager.delistResource(tx, new TestResourceHandle(theResource), XAResource.TMSUCCESS);
+        txManager.delistResource(tx, new TestResourceHandle(theResource1), XAResource.TMSUCCESS);
+
+        final RollbackException e = assertThrows(RollbackException.class, tx::commit);
+        assertThat("e.cause", e.getCause(), instanceOf(MyRuntimeException.class));
+        assertEquals("NoTransaction", JavaEETransactionManagerSimplified.getStatusAsString(tx.getStatus()));
+        assertEquals("NoTransaction", JavaEETransactionManagerSimplified.getStatusAsString(txManager.getStatus()));
+        assertTrue(sync.called_beforeCompletion, "beforeCompletion was not called");
+        assertTrue(sync.called_afterCompletion, "afterCompletion was not called");
+    }
+
+    @Test
+    public void testTMCommitFailBC2PC() throws Exception {
+        txManager.begin();
+        final Transaction tx = txManager.getTransaction();
+        final TestSync sync = new TestSync(true);
+        tx.registerSynchronization(sync);
+        assertEquals("Active", JavaEETransactionManagerSimplified.getStatusAsString(txManager.getStatus()));
+
+        final TestResource theResource = new TestResource();
+        final TestResource theResource1 = new TestResource();
+        txManager.enlistResource(tx, new TestResourceHandle(theResource));
+        txManager.enlistResource(tx, new TestResourceHandle(theResource1));
+        theResource.setCommitErrorCode(9999);
+        theResource1.setCommitErrorCode(9999);
+        txManager.delistResource(tx, new TestResourceHandle(theResource), XAResource.TMSUCCESS);
+        txManager.delistResource(tx, new TestResourceHandle(theResource1), XAResource.TMSUCCESS);
+
+        final RollbackException e = assertThrows(RollbackException.class, txManager::commit);
+        assertThat("e.cause", e.getCause(), instanceOf(MyRuntimeException.class));
+        assertEquals("NoTransaction", JavaEETransactionManagerSimplified.getStatusAsString(txManager.getStatus()));
+        assertTrue(sync.called_beforeCompletion, "beforeCompletion was not called");
+        assertTrue(sync.called_afterCompletion, "afterCompletion was not called");
+    }
+
+    @Test
+    public void testTxCommitFailBC1PC() throws Exception {
+        txManager.begin();
+        final Transaction tx = txManager.getTransaction();
+        final TestSync sync = new TestSync(true);
+        tx.registerSynchronization(sync);
+        assertEquals("Active", JavaEETransactionManagerSimplified.getStatusAsString(txManager.getStatus()));
+
+        final TestResource theResource = new TestResource();
+        txManager.enlistResource(tx, new TestResourceHandle(theResource));
+        theResource.setCommitErrorCode(9999);
+        txManager.delistResource(tx, new TestResourceHandle(theResource), XAResource.TMSUCCESS);
+
+        final RollbackException e = assertThrows(RollbackException.class, tx::commit);
+        assertThat("e.cause", e.getCause(), instanceOf(MyRuntimeException.class));
+        assertEquals("NoTransaction", JavaEETransactionManagerSimplified.getStatusAsString(tx.getStatus()));
+        assertTrue(sync.called_beforeCompletion, "beforeCompletion was not called");
+        assertTrue(sync.called_afterCompletion, "afterCompletion was not called");
+    }
+
+    @Test
+    public void testTxCommitFailBC2PCInterposedSynchronization() throws Exception {
+        txManager.begin();
+        final Transaction tx = txManager.getTransaction();
+        final TestSync sync = new TestSync(true);
+        final TransactionSynchronizationRegistry ts = new TransactionSynchronizationRegistryImpl(txManager);
+        ts.registerInterposedSynchronization(sync);
+        assertEquals("Active", JavaEETransactionManagerSimplified.getStatusAsString(txManager.getStatus()));
+
+        final TestResource theResource = new TestResource();
+        final TestResource theResource1 = new TestResource();
+        txManager.enlistResource(tx, new TestResourceHandle(theResource));
+        txManager.enlistResource(tx, new TestResourceHandle(theResource1));
+        theResource.setCommitErrorCode(9999);
+        theResource1.setCommitErrorCode(9999);
+        txManager.delistResource(tx, new TestResourceHandle(theResource), XAResource.TMSUCCESS);
+        txManager.delistResource(tx, new TestResourceHandle(theResource1), XAResource.TMSUCCESS);
+
+        final RollbackException e = assertThrows(RollbackException.class, tx::commit);
+        assertThat("e.cause", e.getCause(), instanceOf(MyRuntimeException.class));
+        assertEquals("NoTransaction", JavaEETransactionManagerSimplified.getStatusAsString(tx.getStatus()));
+        assertTrue(sync.called_beforeCompletion, "beforeCompletion was not called");
+        assertTrue(sync.called_afterCompletion, "afterCompletion was not called");
+    }
+
+    @Test
+    public void testTxCommitFailBC1PCInterposedSynchronization() throws Exception {
+        txManager.begin();
+        final Transaction tx = txManager.getTransaction();
+        final TestSync sync = new TestSync(true);
+        final TransactionSynchronizationRegistry ts = new TransactionSynchronizationRegistryImpl(txManager);
+        ts.registerInterposedSynchronization(sync);
+        assertEquals("Active", JavaEETransactionManagerSimplified.getStatusAsString(txManager.getStatus()));
+
+        final TestResource theResource = new TestResource();
+        txManager.enlistResource(tx, new TestResourceHandle(theResource));
+        theResource.setCommitErrorCode(9999);
+        txManager.delistResource(tx, new TestResourceHandle(theResource), XAResource.TMSUCCESS);
+        final RollbackException e = assertThrows(RollbackException.class, tx::commit);
+        assertThat("e.cause", e.getCause(), instanceOf(MyRuntimeException.class));
+        assertEquals("NoTransaction", JavaEETransactionManagerSimplified.getStatusAsString(tx.getStatus()));
+        assertTrue(sync.called_beforeCompletion, "beforeCompletion was not called");
+        assertTrue(sync.called_afterCompletion, "afterCompletion was not called");
+    }
+
+    @Test
+    public void testTxCommitRollbackBC() throws Exception {
+        txManager.begin();
+        final Transaction tx = txManager.getTransaction();
+        final TestSync sync = new TestSync(txManager);
+        tx.registerSynchronization(sync);
+        assertEquals("Active", JavaEETransactionManagerSimplified.getStatusAsString(txManager.getStatus()));
+
+        final RollbackException e = assertThrows(RollbackException.class, tx::commit);
+        assertNull(e.getCause(), "e.cause");
+        assertEquals("RolledBack", JavaEETransactionManagerSimplified.getStatusAsString(tx.getStatus()));
+        assertTrue(sync.called_beforeCompletion, "beforeCompletion was not called");
+        assertTrue(sync.called_afterCompletion, "afterCompletion was not called");
+    }
+
+    @Test
+    public void testCommit2PCWithRollbackExc1() throws Exception {
+        verifyCommit2PCWithRollbackException(XAException.XA_RBROLLBACK, XAException.XA_HEURRB);
+    }
+
+    @Test
+    public void testCommit2PCWithRollbackExc2() throws Exception {
+        verifyCommit2PCWithRollbackException(XAException.XA_RBROLLBACK, XAException.XA_HEURRB, XAException.XA_HEURRB);
+    }
+
+    @Test
+    public void testCommit2PCWithRollbackExc3() throws Exception {
+        verifyCommit2PCWithRollbackException(XAException.XA_RDONLY, XAException.XA_HEURRB, 9999);
+    }
+
+    private void verifyCommit2PCWithRollbackException(int preapareErrCode, int... rollbackErrorCode) throws Exception {
+        final TestResource theResourceP = new TestResource();
+        txManager.begin();
+        assertEquals("Active", JavaEETransactionManagerSimplified.getStatusAsString(txManager.getStatus()));
+
+        assertNotNull(createUtx(), "createUtx()");
+        final Transaction tx = txManager.getTransaction();
+        txManager.enlistResource(tx, new TestResourceHandle(theResourceP));
+        theResourceP.setPrepareErrorCode(preapareErrCode);
+        final TestResource[] theResourceR = enlistForRollback(tx, rollbackErrorCode);
+        txManager.delistResource(tx, new TestResourceHandle(theResourceP), XAResource.TMSUCCESS);
+        final RollbackException e = assertThrows(RollbackException.class, txManager::commit);
+        assertEquals("NoTransaction", JavaEETransactionManagerSimplified.getStatusAsString(txManager.getStatus()));
+        final boolean status = theResourceP.forgetCalled();
+        assertTrue(status, "result of theResourceP.forgetCalled()");
+
+        for (TestResource element : theResourceR) {
+            boolean rStatus = element.forgetCalled();
+            assertTrue(rStatus, "result of theResourceR.forgetCalled()");
         }
     }
 
-    public void testCommit2PCWithXAExc1() {
-        System.out.println("**Testing TM with 1 XAER_RMFAIL 2PC commit ===>");
-        _testCommit2PCWithXAExc(XAException.XAER_RMFAIL, 9999, SystemException.class);
+    @Test
+    public void testCommitOnePhaseWithHeuristicRlbExc1() throws Exception {
+        verifyCommitOnePhaseWithException(XAException.XA_HEURRB, HeuristicRollbackException.class, false);
     }
 
-    public void testCommit2PCWithXAExc2() {
-        System.out.println("**Testing TM with both XA_HEURRB 2PC commit ===>");
-        _testCommit2PCWithXAExc(XAException.XA_HEURRB, XAException.XA_HEURRB, HeuristicRollbackException.class, true);
+    @Test
+    public void testCommitOnePhaseWithHeuristicMixedExc2() throws Exception {
+        verifyCommitOnePhaseWithException(XAException.XA_HEURMIX, HeuristicMixedException.class, false);
     }
 
-    public void testCommit2PCWithXAExc3() {
-        System.out.println("**Testing TM with 1 XA_HEURRB & 1 XA_HEURMIX 2PC commit ===>");
-        _testCommit2PCWithXAExc(XAException.XA_HEURRB, XAException.XA_HEURMIX, HeuristicMixedException.class, true);
+    @Test
+    public void testCommitOnePhaseWithRlbExc1() throws Exception {
+        verifyCommitOnePhaseWithException(XAException.XAER_NOTA, RollbackException.class, false);
     }
 
-    public void testCommit2PCWithXAExc4() {
-        System.out.println("**Testing TM with 1 XA_HEURRB & 1 XA_HEURCOM 2PC commit ===>");
-        _testCommit2PCWithXAExc(XAException.XA_HEURRB, XAException.XA_HEURCOM, HeuristicMixedException.class, true);
+    @Test
+    public void testCommitOnePhaseWithRlbExc2() throws Exception {
+        verifyCommitOnePhaseWithException(XAException.XAER_RMERR, RollbackException.class, false);
     }
 
-    public void testCommit2PCWithXAExc5() {
-        System.out.println("**Testing TM with 1 XA_HEURCOM & 1 XA_HEURRB 2PC commit ===>");
-        _testCommit2PCWithXAExc(XAException.XA_HEURCOM, XAException.XA_HEURRB, HeuristicMixedException.class, true);
+    @Test
+    public void testCommitOnePhaseWithRlbExc3() throws Exception {
+        verifyCommitOnePhaseWithException(XAException.XA_RBROLLBACK, RollbackException.class, true);
     }
 
-    public void testCommit2PCWithXAExc6() {
-        System.out.println("**Testing TM with 2 XA_HEURCOM 2PC commit ===>");
-        _testCommit2PCWithXAExc(XAException.XA_HEURCOM, XAException.XA_HEURCOM, true, null, true);
+    @Test
+    public void testCommitOnePhaseWithRlbExc4() throws Exception {
+        verifyCommitOnePhaseWithException(XAException.XAER_RMERR, RollbackException.class, true);
     }
 
-    public void testCommit2PCWithXAExc7() {
-        System.out.println("**Testing TM with 1 XA_HEURCOM & 1 OK 2PC commit ===>");
-        _testCommit2PCWithXAExc(XAException.XA_HEURCOM, 9999, true, null, true);
+    @Test
+    public void testCommitOnePhaseWithRlbExc5() throws Exception {
+        verifyCommitOnePhaseWithException(XAException.XAER_RMFAIL, RollbackException.class, true);
     }
 
-    public void testCommit2PCWithXAExc8() {
-        System.out.println("**Testing TM with 1 XA_HEURRB 2PC commit ===>");
-        _testCommit2PCWithXAExc(XAException.XA_HEURRB, 9999, HeuristicMixedException.class, true);
-    }
+    @Test
+    public void testCommitOnePhaseWithRlbExc6() throws Exception {
+        final int[] falures = {
+            XAException.XAER_RMFAIL,
+            XAException.XAER_RMERR,
+            XAException.XAER_NOTA,
+            XAException.XAER_INVAL,
+            XAException.XAER_PROTO,
+            XAException.XAER_DUPID
+        };
 
-    public void testCommit2PCWithXAExc9() {
-        System.out.println("**Testing TM with 2nd XAER_PROTO in *prepare* of 2PC commit ===>");
-        _testCommit2PCWithXAExc(9999, XAException.XAER_PROTO, false, SystemException.class);
-    }
-
-    public void testCommit2PCWithXAExc10() {
-        System.out.println("**Testing TM with 1st XAER_PROTO in *prepare* of 2PC commit ===>");
-        _testCommit2PCWithXAExc(XAException.XAER_PROTO, 9999, false, SystemException.class);
-    }
-
-    public void testCommit2PCWithXAExc11() {
-        System.out.println("**Testing TM with 2nd XAER_INVAL in *prepare* of 2PC commit ===>");
-        _testCommit2PCWithXAExc(9999, XAException.XAER_INVAL, false, SystemException.class);
-    }
-
-    public void testCommit2PCWithXAExc12() {
-        System.out.println("**Testing TM with 1st XAER_INVAL in *prepare* of 2PC commit ===>");
-        _testCommit2PCWithXAExc(XAException.XAER_INVAL, 9999, false, SystemException.class);
-
-    }
-
-    private void _testCommit2PCWithXAExc(int errorCode1, int errorCode2, Class exType) {
-        _testCommit2PCWithXAExc(errorCode1, errorCode2, true, exType, false);
-    }
-
-    private void _testCommit2PCWithXAExc(int errorCode1, int errorCode2, boolean failOnCommit, Class exType) {
-        _testCommit2PCWithXAExc(errorCode1, errorCode2, failOnCommit, exType, false);
-    }
-
-    private void _testCommit2PCWithXAExc(int errorCode1, int errorCode2, Class exType, boolean isHeuristic) {
-        _testCommit2PCWithXAExc(errorCode1, errorCode2, true, exType, isHeuristic);
-    }
-
-    private void _testCommit2PCWithXAExc(int errorCode1, int errorCode2, boolean failOnCommit, Class exType, boolean isHeuristic) {
-        System.out.println("**Testing TM with " + ((exType == null)? "success" : exType.getName()) + " during 2PC commit ===>");
-        TestResource theResource1 = new TestResource();
-        TestResource theResource2 = new TestResource();
-        TestSync s = new TestSync(false);
-        try {
-            System.out.println("**Starting transaction ....");
-            t.begin();
-            assertEquals (JavaEETransactionManagerSimplified.getStatusAsString(t.getStatus()),
-                "Active");
-
-            // Create and set invMgr
-            createUtx();
-            Transaction tx = t.getTransaction();
-
-            tx.registerSynchronization(s);
-
-            t.enlistResource(tx, new TestResourceHandle(theResource1));
-            t.enlistResource(tx, new TestResourceHandle(theResource2));
-
-            if (failOnCommit) {
-                theResource1.setCommitErrorCode(errorCode1);
-                theResource2.setCommitErrorCode(errorCode2);
-            } else {
-                theResource1.setPrepareErrorCode(errorCode1);
-                theResource2.setPrepareErrorCode(errorCode2);
-            }
-
-            t.delistResource(tx, new TestResourceHandle(theResource1), XAResource.TMSUCCESS);
-            t.delistResource(tx, new TestResourceHandle(theResource2), XAResource.TMSUCCESS);
-
-            System.out.println("**Calling TM commit ===>");
-            t.commit();
-            String status = JavaEETransactionManagerSimplified.getStatusAsString(t.getStatus());
-            if (exType != null) {
-                System.out.println("**Error - successful commit - Status after commit: " + status + " <===");
-                assert (false);
-            } else {
-                System.out.println("**Successful commit - Status after commit: " + status + " <===");
-                assertTrue ("beforeCompletion was not called", s.called_beforeCompletion);
-                assertTrue ("afterCompletion was not called", s.called_afterCompletion);
-                assert (true);
-            }
-        } catch (Throwable ex) {
-            if (exType != null && exType.isInstance(ex)) {
-                System.out.println("**Caught expected " + exType.getName() + " ...");
-                try {
-                    String status = JavaEETransactionManagerSimplified.getStatusAsString(t.getStatus());
-                    System.out.println("**Status after commit: " + status + " <===");
-                } catch (Exception ex1) {
-                    System.out.println("**Caught exception checking for status ...");
-                    ex1.printStackTrace();
-                }
-                boolean status = true;
-                if (isHeuristic) {
-                   status = theResource1.forgetCalled() && theResource2.forgetCalled();
-                   System.out.println("**Forget 1 was called: " + theResource1.forgetCalled());
-                   System.out.println("**Forget 2 was called: " + theResource2.forgetCalled());
-                }
-
-                assertTrue ("beforeCompletion was not called", s.called_beforeCompletion);
-                assertTrue ("afterCompletion was not called", s.called_afterCompletion);
-                assert (status);
-            } else {
-                System.out.println("**Caught " + ((exType == null)? " unexpected " : " NOT a " + exType.getName()) + " during 2PC...");
-                ex.printStackTrace();
-                assert (false);
-            }
+        for (int errorCode : falures) {
+            final TestResource theResource = new TestResource();
+            txManager.begin();
+            assertEquals("Active", JavaEETransactionManagerSimplified.getStatusAsString(txManager.getStatus()));
+            assertNotNull(createUtx());
+            final Transaction tx = txManager.getTransaction();
+            theResource.setStartErrorCode(errorCode);
+            assertThrows(SystemException.class, () -> txManager.enlistResource(tx, new TestResourceHandle(theResource)));
+            txManager.delistResource(tx, new TestResourceHandle(theResource), XAResource.TMSUCCESS);
+            txManager.commit();
+            assertEquals("NoTransaction", JavaEETransactionManagerSimplified.getStatusAsString(txManager.getStatus()));
         }
     }
 
+    @Test
+    public void testCommitOnePhaseWithXAExc1() throws Exception {
+        verifyCommitOnePhaseWithException(XAException.XAER_RMFAIL, SystemException.class, false);
+    }
+
+    @Test
+    public void testCommitOnePhaseWithXAExc2() throws Exception {
+        final TestResource theResource = new TestResource();
+        txManager.begin();
+        assertEquals("Active", JavaEETransactionManagerSimplified.getStatusAsString(txManager.getStatus()));
+        final Transaction tx = txManager.getTransaction();
+        theResource.setCommitErrorCode(XAException.XA_HEURCOM);
+        txManager.enlistResource(tx, new TestResourceHandle(theResource));
+        txManager.delistResource(tx, new TestResourceHandle(theResource), XAResource.TMSUCCESS);
+        txManager.commit();
+        assertEquals("NoTransaction", JavaEETransactionManagerSimplified.getStatusAsString(txManager.getStatus()));
+        assertEquals("NoTransaction", JavaEETransactionManagerSimplified.getStatusAsString(tx.getStatus()));
+    }
+
+    @Test
+    public void testRollbackWithErrorNoExc1() throws Exception {
+        verifyXARollback(XAException.XA_RBROLLBACK);
+    }
+
+    @Test
+    public void testRollbackWithErrorNoExc2() throws Exception {
+        verifyXARollback(XAException.XAER_RMERR);
+    }
+
+    @Test
+    public void testRollbackWithErrorNoExc3() throws Exception {
+        verifyXARollback(XAException.XAER_NOTA);
+    }
+
+    @Test
+    public void testRollbackWithErrorNoExc4() throws Exception {
+        verifyXARollback(XAException.XAER_RMFAIL);
+    }
+
+    @Test
+    public void testRollbackWithErrorNoExc5() throws Exception {
+        verifyXARollback(XAException.XA_HEURRB);
+    }
+
+    @Test
+    public void testRollbackWithErrorNoExc6() throws Exception {
+        verifyXARollback(XAException.XA_HEURRB, XAException.XA_HEURRB);
+    }
+
+    private void verifyCommitOnePhaseWithException(int errorCode, Class<? extends Exception> exType, boolean setRollbackOnly) throws Exception {
+        final TestResource theResource = new TestResource();
+        txManager.begin();
+        assertEquals("Active", JavaEETransactionManagerSimplified.getStatusAsString(txManager.getStatus()));
+
+        final UserTransaction utx = createUtx();
+        final Transaction tx = txManager.getTransaction();
+        if (setRollbackOnly) {
+            theResource.setRollbackErrorCode(errorCode);
+        } else {
+            theResource.setCommitErrorCode(errorCode);
+        }
+        txManager.enlistResource(tx, new TestResourceHandle(theResource));
+        txManager.delistResource(tx, new TestResourceHandle(theResource), XAResource.TMSUCCESS);
+        if (setRollbackOnly) {
+            txManager.setRollbackOnly();
+        }
+        assertThrows(exType, txManager::commit);
+        assertEquals("NoTransaction", JavaEETransactionManagerSimplified.getStatusAsString(txManager.getStatus()));
+        assertEquals("NoTransaction", JavaEETransactionManagerSimplified.getStatusAsString(utx.getStatus()));
+        assertTrue(theResource.forgetCalled(), "theResource.forgetCalled()");
+    }
+
+    private void verifyXARollback(int... errorCode) throws Exception {
+        txManager.begin();
+        assertEquals("Active", JavaEETransactionManagerSimplified.getStatusAsString(txManager.getStatus()));
+        createUtx();
+        Transaction tx = txManager.getTransaction();
+        enlistForRollback(tx, errorCode);
+        txManager.rollback();
+        assertEquals("NoTransaction", JavaEETransactionManagerSimplified.getStatusAsString(txManager.getStatus()));
+    }
+
+    @Test
+    public void testCommit2PCWithXAExc1() throws Exception {
+        verifyCommit2PCWithXAException(XAException.XAER_RMFAIL, 9999, true, SystemException.class);
+    }
+
+    @Test
+    public void testCommit2PCWithXAExc2() throws Exception {
+        verifyCommit2PCWithXAException(XAException.XA_HEURRB, XAException.XA_HEURRB, HeuristicRollbackException.class);
+    }
+
+    @Test
+    public void testCommit2PCWithXAExc3() throws Exception {
+        verifyCommit2PCWithXAException(XAException.XA_HEURRB, XAException.XA_HEURMIX, HeuristicMixedException.class);
+    }
+
+    @Test
+    public void testCommit2PCWithXAExc4() throws Exception {
+        verifyCommit2PCWithXAException(XAException.XA_HEURRB, XAException.XA_HEURCOM, HeuristicMixedException.class);
+    }
+
+    @Test
+    public void testCommit2PCWithXAExc5() throws Exception {
+        verifyCommit2PCWithXAException(XAException.XA_HEURCOM, XAException.XA_HEURRB, HeuristicMixedException.class);
+    }
+
+    @Test
+    public void testCommit2PCWithXAExc6() throws Exception {
+        verifyCommit2PCWithXAException(XAException.XA_HEURCOM, XAException.XA_HEURCOM, true, null);
+    }
+
+    @Test
+    public void testCommit2PCWithXAExc7() throws Exception {
+        verifyCommit2PCWithXAException(XAException.XA_HEURCOM, 9999, true, null);
+    }
+
+    @Test
+    public void testCommit2PCWithXAExc8() throws Exception {
+        verifyCommit2PCWithXAException(XAException.XA_HEURRB, 9999, HeuristicMixedException.class);
+    }
+
+    @Test
+    public void testCommit2PCWithXAExc9() throws Exception {
+        verifyCommit2PCWithXAException(9999, XAException.XAER_PROTO, false, SystemException.class);
+    }
+
+    @Test
+    public void testCommit2PCWithXAExc10() throws Exception {
+        verifyCommit2PCWithXAException(XAException.XAER_PROTO, 9999, false, SystemException.class);
+    }
+
+    @Test
+    public void testCommit2PCWithXAExc11() throws Exception {
+        verifyCommit2PCWithXAException(9999, XAException.XAER_INVAL, false, SystemException.class);
+    }
+
+    @Test
+    public void testCommit2PCWithXAExc12() throws Exception {
+        verifyCommit2PCWithXAException(XAException.XAER_INVAL, 9999, false, SystemException.class);
+    }
+
+    private void verifyCommit2PCWithXAException(int errorCode1, int errorCode2, Class<? extends Exception> exType) throws Exception {
+        verifyCommit2PCWithXAException(errorCode1, errorCode2, true, exType);
+    }
+
+    private void verifyCommit2PCWithXAException(int errorCode1, int errorCode2, boolean failOnCommit, Class<? extends Exception> exType) throws Exception {
+        final TestResource theResource1 = new TestResource();
+        final TestResource theResource2 = new TestResource();
+        final TestSync s = new TestSync(false);
+        txManager.begin();
+        assertEquals("Active", JavaEETransactionManagerSimplified.getStatusAsString(txManager.getStatus()));
+
+        createUtx();
+        final Transaction tx = txManager.getTransaction();
+        tx.registerSynchronization(s);
+        txManager.enlistResource(tx, new TestResourceHandle(theResource1));
+        txManager.enlistResource(tx, new TestResourceHandle(theResource2));
+        if (failOnCommit) {
+            theResource1.setCommitErrorCode(errorCode1);
+            theResource2.setCommitErrorCode(errorCode2);
+        } else {
+            theResource1.setPrepareErrorCode(errorCode1);
+            theResource2.setPrepareErrorCode(errorCode2);
+        }
+        txManager.delistResource(tx, new TestResourceHandle(theResource1), XAResource.TMSUCCESS);
+        txManager.delistResource(tx, new TestResourceHandle(theResource2), XAResource.TMSUCCESS);
+        if (exType == null) {
+            txManager.commit();
+        } else {
+            assertThrows(exType, txManager::commit);
+        }
+        assertEquals("NoTransaction", JavaEETransactionManagerSimplified.getStatusAsString(txManager.getStatus()));
+        assertTrue(s.called_beforeCompletion, "beforeCompletion was not called");
+        assertTrue(s.called_afterCompletion, "afterCompletion was not called");
+        assertTrue(theResource1.forgetCalled());
+        assertTrue(theResource2.forgetCalled());
+    }
+
     private UserTransaction createUtx() throws javax.naming.NamingException {
         UserTransaction utx = new UserTransactionImpl();
         InvocationManager im = new org.glassfish.api.invocation.InvocationManagerImpl();
-        ((UserTransactionImpl)utx).setForTesting(t, im);
+        ((UserTransactionImpl)utx).setForTesting(txManager, im);
         return utx;
     }
 
@@ -1562,12 +788,12 @@
         TestResource[] theResources = new TestResource[errorCode.length];
         for (int i = 0; i < errorCode.length; i++) {
             theResources[i] = new TestResource();
-            t.enlistResource(tx, new TestResourceHandle(theResources[i]));
+            txManager.enlistResource(tx, new TestResourceHandle(theResources[i]));
             theResources[i].setRollbackErrorCode(errorCode[i]);
         }
 
         for (int i = 0; i < errorCode.length; i++) {
-            t.delistResource(tx, new TestResourceHandle(theResources[i]), XAResource.TMSUCCESS);
+            txManager.delistResource(tx, new TestResourceHandle(theResources[i]), XAResource.TMSUCCESS);
         }
 
         return theResources;
@@ -1592,6 +818,7 @@
             this.t = t;
         }
 
+        @Override
         public void beforeCompletion() {
             System.out.println("**Called beforeCompletion  **");
             called_beforeCompletion = true;
@@ -1610,6 +837,7 @@
             }
         }
 
+        @Override
         public void afterCompletion(int status) {
             System.out.println("**Called afterCompletion with status:  "
                     + JavaEETransactionManagerSimplified.getStatusAsString(status));
@@ -1683,7 +911,8 @@
           }
       }
 
-      public void commit(Xid xid, boolean onePhase) throws XAException{
+      @Override
+    public void commit(Xid xid, boolean onePhase) throws XAException{
         // test goes here
         System.out.println("in XA commit");
         commit_status = getStatus("COMMIT");
@@ -1693,13 +922,15 @@
         }
       }
 
-      public boolean isSameRM(XAResource xaresource)
+      @Override
+    public boolean isSameRM(XAResource xaresource)
         throws XAException {
           return xaresource == this || this.id == ((TestResource)xaresource).id;
       }
 
 
-      public void rollback(Xid xid)
+      @Override
+    public void rollback(Xid xid)
             throws XAException {
           System.out.println("in XA rollback");
         rollback_status = getStatus("ROLLBACK");
@@ -1709,7 +940,8 @@
         }
       }
 
-      public int prepare(Xid xid)
+      @Override
+    public int prepare(Xid xid)
             throws XAException {
           System.out.println("in XA prepare");
         prepare_status = getStatus("PREPARE");
@@ -1720,25 +952,30 @@
           return XAResource.XA_OK;
       }
 
-      public boolean setTransactionTimeout(int i)
+      @Override
+    public boolean setTransactionTimeout(int i)
             throws XAException {
           return true;
        }
 
-       public int getTransactionTimeout()
+       @Override
+    public int getTransactionTimeout()
             throws XAException {
             return 0;
         }
-       public void forget(Xid xid)
+       @Override
+    public void forget(Xid xid)
             throws XAException {
             _forgetCalled = true;
             inUse = false;
         }
 
-       public void start(Xid xid, int flags)
+       @Override
+    public void start(Xid xid, int flags)
             throws XAException {
-              if (inUse)
+              if (inUse) {
                 throw new XAException(XAException.XAER_NOTA);
+            }
               inUse = true;
               if (startErrorCode != 9999) {
                 System.out.println("throwing XAException." + startErrorCode + " during start" );
@@ -1747,13 +984,15 @@
        }
 
 
-         public void end(Xid xid, int flags)
+         @Override
+        public void end(Xid xid, int flags)
             throws XAException {
               inUse = false;
         }
 
 
-       public Xid[] recover(int flags)
+       @Override
+    public Xid[] recover(int flags)
             throws XAException {
             return null;
         }
@@ -1795,7 +1034,7 @@
     }
 
     static class TestResourceHandle extends ResourceHandle {
-        private XAResource resource;
+        private final XAResource resource;
         private static PoolManagerImpl poolMgr = new PoolManagerImpl();
 
         public TestResourceHandle(XAResource resource) {
@@ -1803,41 +1042,51 @@
           this.resource = resource;
         }
 
+        @Override
         public boolean isTransactional() {
           return true;
         }
 
+        @Override
         public boolean isShareable() {
           return true;
         }
 
+        @Override
         public boolean supportsXA() {
           return true;
         }
 
+        @Override
         public ResourceAllocator getResourceAllocator() {
           return null;
         }
 
+        @Override
         public Object getResource() {
           return resource;
         }
 
+        @Override
         public XAResource getXAResource() {
           return resource;
         }
 
+        @Override
         public Object getUserConnection() {
           return null;
         }
 
+        @Override
         public ClientSecurityInfo getClientSecurityInfo() {
           return null;
         }
 
+        @Override
         public void fillInResourceObjects(Object userConnection, XAResource xares) {
         }
 
+        @Override
         public void enlistedInTransaction(Transaction tran) throws IllegalStateException {
             poolMgr.resourceEnlisted(tran, this);
         }