HHH-14503 - Migration of tests from jpa/test to orm/test/jpa
This commit is contained in:
parent
e2225d8814
commit
a7f242af03
|
@ -138,6 +138,7 @@ public class ForeignGeneratorResourceLocalTest {
|
|||
|
||||
EntityManager entityManager = null;
|
||||
EntityTransaction txn = null;
|
||||
|
||||
try {
|
||||
entityManager = scope.getEntityManagerFactory().createEntityManager();
|
||||
txn = entityManager.getTransaction();
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
package org.hibernate.orm.test.jpa.ejb3configuration;
|
||||
|
||||
import java.util.Map;
|
||||
import javax.persistence.EntityManager;
|
||||
|
||||
import org.hibernate.jpa.AvailableSettings;
|
||||
import org.hibernate.jpa.test.Wallet;
|
||||
|
@ -18,7 +17,6 @@ import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
|
|||
import org.hibernate.testing.orm.junit.Jpa;
|
||||
import org.hibernate.testing.orm.junit.Setting;
|
||||
import org.hibernate.test.util.jdbc.PreparedStatementSpyConnectionProvider;
|
||||
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
|
@ -32,7 +30,7 @@ import static org.junit.jupiter.api.Assertions.fail;
|
|||
@RequiresDialectFeature(DialectChecks.SupportsJdbcDriverProxying.class)
|
||||
@Jpa(
|
||||
annotatedClasses = { Wallet.class },
|
||||
integrationSettings = { @Setting( name = AvailableSettings.DISCARD_PC_ON_CLOSE, value = "true") },
|
||||
integrationSettings = { @Setting(name = AvailableSettings.DISCARD_PC_ON_CLOSE, value = "true") },
|
||||
nonStringValueSettingProviders = { PreparedStatementSpyConnectionProviderSettingValueProvider.class }
|
||||
)
|
||||
public class EnableDiscardPersistenceContextOnCloseTest {
|
||||
|
@ -59,6 +57,8 @@ public class EnableDiscardPersistenceContextOnCloseTest {
|
|||
entityManager.close();
|
||||
assertEquals( 0, connectionProvider.getAcquiredConnections().size() );
|
||||
assertTrue( entityManager.getTransaction().isActive() );
|
||||
}
|
||||
finally {
|
||||
try {
|
||||
entityManager.getTransaction().rollback();
|
||||
fail( "Should throw IllegalStateException because the Connection is already closed!" );
|
||||
|
@ -66,12 +66,6 @@ public class EnableDiscardPersistenceContextOnCloseTest {
|
|||
catch (IllegalStateException expected) {
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
if ( entityManager.getTransaction().isActive() ) {
|
||||
entityManager.getTransaction().rollback();
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
|
||||
}
|
||||
);
|
||||
|
|
|
@ -47,18 +47,23 @@ public class FindTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue( jiraKey = "HHH-9856" )
|
||||
@TestForIssue(jiraKey = "HHH-9856")
|
||||
public void testNonEntity(EntityManagerFactoryScope scope) {
|
||||
scope.inEntityManager(
|
||||
entityManager -> {
|
||||
entityManager.getTransaction().begin();
|
||||
try {
|
||||
entityManager.getTransaction().begin();
|
||||
entityManager.find( String.class, 1 );
|
||||
Assertions.fail( "Expecting a failure" );
|
||||
}
|
||||
catch (IllegalArgumentException ignore) {
|
||||
// expected
|
||||
}
|
||||
finally {
|
||||
if ( entityManager.getTransaction().isActive() ) {
|
||||
entityManager.getTransaction().rollback();
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
|
@ -49,9 +49,11 @@ import static org.junit.jupiter.api.Assertions.assertFalse;
|
|||
AbstractJtaBatchTest.Comment.class,
|
||||
AbstractJtaBatchTest.EventLog.class
|
||||
},
|
||||
integrationSettings = { @Setting(name = AvailableSettings.JPA_TRANSACTION_TYPE, value = "JTA"),
|
||||
integrationSettings = {
|
||||
@Setting(name = AvailableSettings.JPA_TRANSACTION_TYPE, value = "JTA"),
|
||||
@Setting(name = AvailableSettings.JPA_TRANSACTION_COMPLIANCE, value = "true"),
|
||||
@Setting(name = AvailableSettings.STATEMENT_BATCH_SIZE, value = "50") },
|
||||
@Setting(name = AvailableSettings.STATEMENT_BATCH_SIZE, value = "50")
|
||||
},
|
||||
nonStringValueSettingProviders = {
|
||||
AbstractJtaBatchTest.JtaPlatformNonStringValueSettingProvider.class,
|
||||
AbstractJtaBatchTest.ConnectionNonStringValueSettingProvider.class,
|
||||
|
@ -86,39 +88,35 @@ public class JtaWithFailingBatchTest extends AbstractJtaBatchTest {
|
|||
Comment comment = new Comment();
|
||||
comment.setMessage( "Bar" );
|
||||
|
||||
em.persist( comment );
|
||||
transactionManager.commit();
|
||||
}
|
||||
catch (Exception expected) {
|
||||
//expected
|
||||
try {
|
||||
em.persist( comment );
|
||||
transactionManager.commit();
|
||||
}
|
||||
catch (Exception expected) {
|
||||
//expected
|
||||
switch ( transactionManager.getStatus() ) {
|
||||
case Status.STATUS_ACTIVE:
|
||||
case Status.STATUS_MARKED_ROLLBACK:
|
||||
transactionManager.rollback();
|
||||
}
|
||||
}
|
||||
|
||||
assertThat(
|
||||
"AbstractBatchImpl#releaseStatements() has not been callled",
|
||||
testBatch.calledReleaseStatements,
|
||||
is( true )
|
||||
);
|
||||
assertAllStatementsAreClosed( testBatch.createdStatements );
|
||||
assertStatementsListIsCleared();
|
||||
}
|
||||
catch (Exception e) {
|
||||
try {
|
||||
if (transactionManager.getStatus() == Status.STATUS_ACTIVE) {
|
||||
transactionManager.rollback();
|
||||
}
|
||||
}
|
||||
catch (Exception e2) {
|
||||
// Ignore
|
||||
catch (Exception e) {
|
||||
//ignore e
|
||||
}
|
||||
}
|
||||
|
||||
assertFalse( triggerable.wasTriggered(), "HHH000352: Unable to release batch statement... has been thrown" );
|
||||
assertThat(
|
||||
"AbstractBatchImpl#releaseStatements() has not been callled",
|
||||
testBatch.calledReleaseStatements,
|
||||
is( true )
|
||||
);
|
||||
assertAllStatementsAreClosed( testBatch.createdStatements );
|
||||
assertStatementsListIsCleared();
|
||||
|
||||
assertFalse(
|
||||
triggerable.wasTriggered(),
|
||||
"HHH000352: Unable to release batch statement... has been thrown"
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
|
@ -10,7 +10,9 @@ import java.sql.PreparedStatement;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javax.persistence.FlushModeType;
|
||||
import javax.transaction.NotSupportedException;
|
||||
import javax.transaction.Status;
|
||||
import javax.transaction.SystemException;
|
||||
import javax.transaction.TransactionManager;
|
||||
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
|
@ -93,12 +95,13 @@ public class JtaWithStatementsBatchTest extends AbstractJtaBatchTest {
|
|||
}
|
||||
catch (Exception e) {
|
||||
try {
|
||||
if ( transactionManager.getStatus() == Status.STATUS_ACTIVE ) {
|
||||
transactionManager.rollback();
|
||||
switch ( transactionManager.getStatus() ) {
|
||||
case Status.STATUS_ACTIVE:
|
||||
case Status.STATUS_MARKED_ROLLBACK:
|
||||
transactionManager.rollback();
|
||||
}
|
||||
}
|
||||
catch (Exception e2) {
|
||||
// Ignore
|
||||
}catch (Exception e2){
|
||||
//ignore e
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -123,12 +126,24 @@ public class JtaWithStatementsBatchTest extends AbstractJtaBatchTest {
|
|||
}
|
||||
catch (Exception e) {
|
||||
try {
|
||||
if ( transactionManager.getStatus() == Status.STATUS_ACTIVE ) {
|
||||
transactionManager.rollback();
|
||||
switch ( transactionManager.getStatus() ) {
|
||||
case Status.STATUS_ACTIVE:
|
||||
case Status.STATUS_MARKED_ROLLBACK:
|
||||
transactionManager.rollback();
|
||||
}
|
||||
}catch (Exception e2){
|
||||
//ignore e
|
||||
}
|
||||
catch (Exception e2) {
|
||||
// Ignore
|
||||
}
|
||||
finally {
|
||||
try {
|
||||
switch ( transactionManager.getStatus() ) {
|
||||
case Status.STATUS_ACTIVE:
|
||||
case Status.STATUS_MARKED_ROLLBACK:
|
||||
transactionManager.rollback();
|
||||
}
|
||||
}catch (Exception e){
|
||||
//ignore e
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue