Skip to content

Commit

Permalink
HHH-9927 add testcase for calling EntityManager.joinTransaction() wit…
Browse files Browse the repository at this point in the history
…h no active JTA transaction to verify that a TransactionRequiredException is thrown
  • Loading branch information
scottmarlow authored and sebersole committed Jul 23, 2015
1 parent eaf562b commit 289e59a
Showing 1 changed file with 17 additions and 0 deletions.
Expand Up @@ -8,6 +8,7 @@

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;
Expand All @@ -29,6 +30,7 @@

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}
Expand Down Expand Up @@ -178,6 +180,21 @@ public void run() {
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[] {
Expand Down

0 comments on commit 289e59a

Please sign in to comment.