(no commit message)
authorerik <erik@77661180-640e-0410-b3a8-9f9b13e6d0e0>
Thu, 22 Jul 2010 17:30:01 +0000 (17:30 +0000)
committererik <erik@77661180-640e-0410-b3a8-9f9b13e6d0e0>
Thu, 22 Jul 2010 17:30:01 +0000 (17:30 +0000)
test/enterprise/src/test/java/org/wamblee/test/transactions/SimpleTransactionManagerIntegrationTest.java
test/enterprise/src/test/java/org/wamblee/test/transactions/SimpleTransactionManagerTest.java

index 1ad1a2b3c8523cffd72c72f6d0f888485c43c7ec..f200de51a6460aea9a955af59982c91ecbb569a6 100644 (file)
@@ -65,4 +65,14 @@ public class SimpleTransactionManagerIntegrationTest {
         verifyNoMoreInteractions(resource1, resource2);
     }
 
+    @Test
+    public void testTwoTransactions() throws Exception { 
+        UserTransaction transaction = manager.getTransaction();
+        transaction.begin();
+        transaction.commit();
+        
+        transaction.begin();
+        transaction.commit();    
+    }
+    
 }
index d0630ad8349ad8bf60f8d809034bb78e330dff38..1f7afc645306fe19d48f065815243a531be980b1 100644 (file)
@@ -23,6 +23,7 @@ import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
 
+import javax.transaction.SystemException;
 import javax.transaction.UserTransaction;
 
 import org.junit.After;
@@ -63,6 +64,7 @@ public class SimpleTransactionManagerTest {
 
     @Test
     public void testTransactionsAreThreadSpecific() throws Exception {
+        manager.getTransaction().getStatus();
         UserTransaction transaction = manager.getThreadSpecificTransaction();
         assertNotNull(transaction);
         assertSame(transaction, manager.getThreadSpecificTransaction());
@@ -70,7 +72,13 @@ public class SimpleTransactionManagerTest {
         Thread t = new Thread(new Runnable() {
             @Override
             public void run() {
-                transaction2.setValue(manager.getThreadSpecificTransaction());
+                try {
+                    manager.getTransaction().getStatus();
+                    transaction2.setValue(manager
+                        .getThreadSpecificTransaction());
+                } catch (SystemException e) {
+                    fail("exception ");
+                }
             }
         });
         t.start();
@@ -81,18 +89,21 @@ public class SimpleTransactionManagerTest {
     }
 
     @Test
-    public void testTransactionLifeCycle() {
+    public void testTransactionLifeCycle() throws Exception {
+        manager.getTransaction().getStatus();
         UserTransaction transaction = manager.getThreadSpecificTransaction();
+        
         assertNotNull(transaction);
         assertEquals(1, callbacks.size());
         callbacks.get(0).transactionFinished();
+        manager.getTransaction().getStatus();
         UserTransaction transaction2 = manager.getThreadSpecificTransaction();
         assertNotNull(transaction2);
         assert (transaction != transaction2);
     }
 
     @Test
-    public void testVerifyResourcesArePassedToFactory() {
+    public void testVerifyResourcesArePassedToFactory() throws Exception {
 
         final ValueHolder<Object[]> actual = new ValueHolder<Object[]>();
         when(factory.create(any(UserTransactionCallback.class), (List) any()))
@@ -100,9 +111,10 @@ public class SimpleTransactionManagerTest {
                 @Override
                 public Object answer(InvocationOnMock aInvocation)
                     throws Throwable {
-                    Object[] value = ((List)aInvocation.getArguments()[1]).toArray();
+                    Object[] value = ((List) aInvocation.getArguments()[1])
+                        .toArray();
                     actual.setValue(value);
-                    return null;
+                    return mock(UserTransaction.class);
                 }
             });
 
@@ -111,9 +123,19 @@ public class SimpleTransactionManagerTest {
         manager.addResource(resource1);
         manager.addResource(resource2);
 
-        UserTransaction transaction = manager.getTransaction();
+        manager.getTransaction().getStatus();
         Object[] expected = new Object[] { resource1, resource2 };
         assertTrue(Arrays.equals(expected, actual.getValue()));
     }
 
+    @Test
+    public void testTwoTransactions() throws Exception {
+        UserTransaction transaction = manager.getTransaction();
+        transaction.begin();
+        transaction.commit();
+
+        transaction.begin();
+        transaction.commit();
+    }
+
 }