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;
|
EntityManager entityManager = null;
|
||||||
EntityTransaction txn = null;
|
EntityTransaction txn = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
entityManager = scope.getEntityManagerFactory().createEntityManager();
|
entityManager = scope.getEntityManagerFactory().createEntityManager();
|
||||||
txn = entityManager.getTransaction();
|
txn = entityManager.getTransaction();
|
||||||
|
|
|
@ -7,7 +7,6 @@
|
||||||
package org.hibernate.orm.test.jpa.ejb3configuration;
|
package org.hibernate.orm.test.jpa.ejb3configuration;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import javax.persistence.EntityManager;
|
|
||||||
|
|
||||||
import org.hibernate.jpa.AvailableSettings;
|
import org.hibernate.jpa.AvailableSettings;
|
||||||
import org.hibernate.jpa.test.Wallet;
|
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.Jpa;
|
||||||
import org.hibernate.testing.orm.junit.Setting;
|
import org.hibernate.testing.orm.junit.Setting;
|
||||||
import org.hibernate.test.util.jdbc.PreparedStatementSpyConnectionProvider;
|
import org.hibernate.test.util.jdbc.PreparedStatementSpyConnectionProvider;
|
||||||
|
|
||||||
import org.junit.jupiter.api.BeforeAll;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
@ -32,7 +30,7 @@ import static org.junit.jupiter.api.Assertions.fail;
|
||||||
@RequiresDialectFeature(DialectChecks.SupportsJdbcDriverProxying.class)
|
@RequiresDialectFeature(DialectChecks.SupportsJdbcDriverProxying.class)
|
||||||
@Jpa(
|
@Jpa(
|
||||||
annotatedClasses = { Wallet.class },
|
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 }
|
nonStringValueSettingProviders = { PreparedStatementSpyConnectionProviderSettingValueProvider.class }
|
||||||
)
|
)
|
||||||
public class EnableDiscardPersistenceContextOnCloseTest {
|
public class EnableDiscardPersistenceContextOnCloseTest {
|
||||||
|
@ -59,6 +57,8 @@ public class EnableDiscardPersistenceContextOnCloseTest {
|
||||||
entityManager.close();
|
entityManager.close();
|
||||||
assertEquals( 0, connectionProvider.getAcquiredConnections().size() );
|
assertEquals( 0, connectionProvider.getAcquiredConnections().size() );
|
||||||
assertTrue( entityManager.getTransaction().isActive() );
|
assertTrue( entityManager.getTransaction().isActive() );
|
||||||
|
}
|
||||||
|
finally {
|
||||||
try {
|
try {
|
||||||
entityManager.getTransaction().rollback();
|
entityManager.getTransaction().rollback();
|
||||||
fail( "Should throw IllegalStateException because the Connection is already closed!" );
|
fail( "Should throw IllegalStateException because the Connection is already closed!" );
|
||||||
|
@ -66,12 +66,6 @@ public class EnableDiscardPersistenceContextOnCloseTest {
|
||||||
catch (IllegalStateException expected) {
|
catch (IllegalStateException expected) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
|
||||||
if ( entityManager.getTransaction().isActive() ) {
|
|
||||||
entityManager.getTransaction().rollback();
|
|
||||||
}
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
|
@ -47,18 +47,23 @@ public class FindTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestForIssue( jiraKey = "HHH-9856" )
|
@TestForIssue(jiraKey = "HHH-9856")
|
||||||
public void testNonEntity(EntityManagerFactoryScope scope) {
|
public void testNonEntity(EntityManagerFactoryScope scope) {
|
||||||
scope.inEntityManager(
|
scope.inEntityManager(
|
||||||
entityManager -> {
|
entityManager -> {
|
||||||
entityManager.getTransaction().begin();
|
|
||||||
try {
|
try {
|
||||||
|
entityManager.getTransaction().begin();
|
||||||
entityManager.find( String.class, 1 );
|
entityManager.find( String.class, 1 );
|
||||||
Assertions.fail( "Expecting a failure" );
|
Assertions.fail( "Expecting a failure" );
|
||||||
}
|
}
|
||||||
catch (IllegalArgumentException ignore) {
|
catch (IllegalArgumentException ignore) {
|
||||||
// expected
|
// 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.Comment.class,
|
||||||
AbstractJtaBatchTest.EventLog.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.JPA_TRANSACTION_COMPLIANCE, value = "true"),
|
||||||
@Setting(name = AvailableSettings.STATEMENT_BATCH_SIZE, value = "50") },
|
@Setting(name = AvailableSettings.STATEMENT_BATCH_SIZE, value = "50")
|
||||||
|
},
|
||||||
nonStringValueSettingProviders = {
|
nonStringValueSettingProviders = {
|
||||||
AbstractJtaBatchTest.JtaPlatformNonStringValueSettingProvider.class,
|
AbstractJtaBatchTest.JtaPlatformNonStringValueSettingProvider.class,
|
||||||
AbstractJtaBatchTest.ConnectionNonStringValueSettingProvider.class,
|
AbstractJtaBatchTest.ConnectionNonStringValueSettingProvider.class,
|
||||||
|
@ -86,39 +88,35 @@ public class JtaWithFailingBatchTest extends AbstractJtaBatchTest {
|
||||||
Comment comment = new Comment();
|
Comment comment = new Comment();
|
||||||
comment.setMessage( "Bar" );
|
comment.setMessage( "Bar" );
|
||||||
|
|
||||||
|
em.persist( comment );
|
||||||
|
transactionManager.commit();
|
||||||
|
}
|
||||||
|
catch (Exception expected) {
|
||||||
|
//expected
|
||||||
try {
|
try {
|
||||||
em.persist( comment );
|
|
||||||
transactionManager.commit();
|
|
||||||
}
|
|
||||||
catch (Exception expected) {
|
|
||||||
//expected
|
|
||||||
switch ( transactionManager.getStatus() ) {
|
switch ( transactionManager.getStatus() ) {
|
||||||
case Status.STATUS_ACTIVE:
|
case Status.STATUS_ACTIVE:
|
||||||
case Status.STATUS_MARKED_ROLLBACK:
|
case Status.STATUS_MARKED_ROLLBACK:
|
||||||
transactionManager.rollback();
|
transactionManager.rollback();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch (Exception e) {
|
||||||
assertThat(
|
//ignore e
|
||||||
"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
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import javax.persistence.FlushModeType;
|
import javax.persistence.FlushModeType;
|
||||||
|
import javax.transaction.NotSupportedException;
|
||||||
import javax.transaction.Status;
|
import javax.transaction.Status;
|
||||||
|
import javax.transaction.SystemException;
|
||||||
import javax.transaction.TransactionManager;
|
import javax.transaction.TransactionManager;
|
||||||
|
|
||||||
import org.hibernate.cfg.AvailableSettings;
|
import org.hibernate.cfg.AvailableSettings;
|
||||||
|
@ -93,12 +95,13 @@ public class JtaWithStatementsBatchTest extends AbstractJtaBatchTest {
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
try {
|
try {
|
||||||
if ( transactionManager.getStatus() == Status.STATUS_ACTIVE ) {
|
switch ( transactionManager.getStatus() ) {
|
||||||
transactionManager.rollback();
|
case Status.STATUS_ACTIVE:
|
||||||
|
case Status.STATUS_MARKED_ROLLBACK:
|
||||||
|
transactionManager.rollback();
|
||||||
}
|
}
|
||||||
}
|
}catch (Exception e2){
|
||||||
catch (Exception e2) {
|
//ignore e
|
||||||
// Ignore
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,12 +126,24 @@ public class JtaWithStatementsBatchTest extends AbstractJtaBatchTest {
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
try {
|
try {
|
||||||
if ( transactionManager.getStatus() == Status.STATUS_ACTIVE ) {
|
switch ( transactionManager.getStatus() ) {
|
||||||
transactionManager.rollback();
|
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