From 124e05b5c0c2619457b8134df21f10b3b23226e0 Mon Sep 17 00:00:00 2001 From: Erik Brakkee Date: Thu, 22 Jul 2010 17:30:01 +0000 Subject: [PATCH] --- ...mpleTransactionManagerIntegrationTest.java | 10 ++++++ .../SimpleTransactionManagerTest.java | 34 +++++++++++++++---- 2 files changed, 38 insertions(+), 6 deletions(-) diff --git a/test/enterprise/src/test/java/org/wamblee/test/transactions/SimpleTransactionManagerIntegrationTest.java b/test/enterprise/src/test/java/org/wamblee/test/transactions/SimpleTransactionManagerIntegrationTest.java index 1ad1a2b3..f200de51 100644 --- a/test/enterprise/src/test/java/org/wamblee/test/transactions/SimpleTransactionManagerIntegrationTest.java +++ b/test/enterprise/src/test/java/org/wamblee/test/transactions/SimpleTransactionManagerIntegrationTest.java @@ -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(); + } + } diff --git a/test/enterprise/src/test/java/org/wamblee/test/transactions/SimpleTransactionManagerTest.java b/test/enterprise/src/test/java/org/wamblee/test/transactions/SimpleTransactionManagerTest.java index d0630ad8..1f7afc64 100644 --- a/test/enterprise/src/test/java/org/wamblee/test/transactions/SimpleTransactionManagerTest.java +++ b/test/enterprise/src/test/java/org/wamblee/test/transactions/SimpleTransactionManagerTest.java @@ -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 actual = new ValueHolder(); 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(); + } + } -- 2.31.1