import java.util.Arrays;
import java.util.List;
+import javax.transaction.SystemException;
import javax.transaction.UserTransaction;
import org.junit.After;
@Test
public void testTransactionsAreThreadSpecific() throws Exception {
+ manager.getTransaction().getStatus();
UserTransaction transaction = manager.getThreadSpecificTransaction();
assertNotNull(transaction);
assertSame(transaction, manager.getThreadSpecificTransaction());
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();
}
@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()))
@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);
}
});
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();
+ }
+
}