HHH-9927 add testcase for calling EntityManager.joinTransaction() with no active JTA transaction to verify that a TransactionRequiredException is thrown
This commit is contained in:
parent
eaf562b129
commit
289e59a2c0
|
@ -8,6 +8,7 @@ package org.hibernate.jpa.test.transaction;
|
|||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.PersistenceException;
|
||||
import javax.persistence.TransactionRequiredException;
|
||||
import javax.transaction.Status;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
|
@ -29,6 +30,7 @@ import org.hibernate.testing.junit4.ExtraAssertions;
|
|||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
/**
|
||||
* Largely a copy of {@link org.hibernate.test.jpa.txn.JtaTransactionJoiningTest}
|
||||
|
@ -178,6 +180,21 @@ public class TransactionJoiningTest extends BaseEntityManagerFunctionalTestCase
|
|||
em.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTransactionRequiredException() throws Exception {
|
||||
|
||||
assertFalse("setup problem", JtaStatusHelper.isActive(TestingJtaPlatformImpl.INSTANCE.getTransactionManager()));
|
||||
|
||||
EntityManager entityManager = entityManagerFactory().createEntityManager();
|
||||
try {
|
||||
entityManager.joinTransaction();
|
||||
fail( "Expected joinTransaction() to fail since there is no active JTA transaction" );
|
||||
}
|
||||
catch (TransactionRequiredException expected) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class[] getAnnotatedClasses() {
|
||||
return new Class[] {
|
||||
|
|
Loading…
Reference in New Issue