Move some tests from test.annotations to orm.test.annotations

Signed-off-by: Jan Schatteman <jschatte@redhat.com>
This commit is contained in:
Jan Schatteman 2021-08-09 17:25:26 +02:00 committed by Jan Schatteman
parent a9725f4fca
commit bf57f31a8f
6 changed files with 340 additions and 303 deletions

View File

@ -6,34 +6,36 @@
*/
//$Id$
package org.hibernate.test.annotations;
package org.hibernate.orm.test.annotations;
import org.hibernate.SessionFactory;
import org.hibernate.query.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.query.SemanticException;
import org.hibernate.query.sqm.InterpretationException;
import org.junit.Test;
import org.hibernate.test.annotations.Boat;
import org.hibernate.test.annotations.Ferry;
import org.hibernate.test.annotations.Port;
import org.junit.jupiter.api.Test;
import static org.hibernate.testing.junit4.ExtraAssertions.assertTyping;
import static org.hibernate.testing.transaction.TransactionUtil2.inTransaction;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
/**
* @author Emmanuel Bernard
*/
public class ConfigurationTest {
@Test
public void testDeclarativeMix() throws Exception {
public void testDeclarativeMix() {
Configuration cfg = new Configuration();
cfg.configure( "org/hibernate/test/annotations/hibernate.cfg.xml" );
cfg.configure( "org/hibernate/orm/test/annotations/hibernate.cfg.xml" );
cfg.setProperty( Environment.HBM2DDL_AUTO, "create-drop" );
SessionFactory sf = cfg.buildSessionFactory();
assertNotNull( sf );
@ -47,10 +49,11 @@ public class ConfigurationTest {
s.close();
sf.close();
}
@Test
public void testIgnoringHbm() throws Exception {
public void testIgnoringHbm() {
Configuration cfg = new Configuration();
cfg.configure( "org/hibernate/test/annotations/hibernate.cfg.xml" );
cfg.configure( "org/hibernate/orm/test/annotations/hibernate.cfg.xml" );
cfg.setProperty( Environment.HBM2DDL_AUTO, "create-drop" );
cfg.setProperty( Configuration.ARTEFACT_PROCESSING_ORDER, "class" );
@ -65,7 +68,7 @@ public class ConfigurationTest {
fail( "Boat should not be mapped" );
}
catch (IllegalArgumentException expected) {
assertTyping( SemanticException.class, expected.getCause() );
assertEquals( InterpretationException.class, expected.getCause().getClass() );
// expected outcome
// see org.hibernate.test.jpa.compliance.tck2_2.QueryApiTest#testInvalidQueryMarksTxnForRollback
@ -85,9 +88,9 @@ public class ConfigurationTest {
}
@Test
public void testPrecedenceHbm() throws Exception {
public void testPrecedenceHbm() {
Configuration cfg = new Configuration();
cfg.configure( "org/hibernate/test/annotations/hibernate.cfg.xml" );
cfg.configure( "org/hibernate/orm/test/annotations/hibernate.cfg.xml" );
cfg.setProperty( Environment.HBM2DDL_AUTO, "create-drop" );
cfg.addAnnotatedClass( Boat.class );
SessionFactory sf = cfg.buildSessionFactory();
@ -102,17 +105,18 @@ public class ConfigurationTest {
s.clear();
Transaction tx = s.beginTransaction();
boat = (Boat) s.get( Boat.class, boat.getId() );
assertTrue( "Annotation has precedence", 34 != boat.getWeight() );
assertTrue( 34 != boat.getWeight(), "Annotation has precedence" );
s.delete( boat );
//s.getTransaction().commit();
tx.commit();
s.close();
sf.close();
}
@Test
public void testPrecedenceAnnotation() throws Exception {
public void testPrecedenceAnnotation() {
Configuration cfg = new Configuration();
cfg.configure( "org/hibernate/test/annotations/hibernate.cfg.xml" );
cfg.configure( "org/hibernate/orm/test/annotations/hibernate.cfg.xml" );
cfg.setProperty( Environment.HBM2DDL_AUTO, "create-drop" );
cfg.setProperty( Configuration.ARTEFACT_PROCESSING_ORDER, "class, hbm" );
cfg.addAnnotatedClass( Boat.class );
@ -128,16 +132,17 @@ public class ConfigurationTest {
s.clear();
Transaction tx = s.beginTransaction();
boat = (Boat) s.get( Boat.class, boat.getId() );
assertTrue( "Annotation has precedence", 34 == boat.getWeight() );
assertTrue( 34 == boat.getWeight(), "Annotation has precedence" );
s.delete( boat );
tx.commit();
s.close();
sf.close();
}
@Test
public void testHbmWithSubclassExtends() throws Exception {
public void testHbmWithSubclassExtends() {
Configuration cfg = new Configuration();
cfg.configure( "org/hibernate/test/annotations/hibernate.cfg.xml" );
cfg.configure( "org/hibernate/orm/test/annotations/hibernate.cfg.xml" );
cfg.addClass( Ferry.class );
cfg.setProperty( Environment.HBM2DDL_AUTO, "create-drop" );
SessionFactory sf = cfg.buildSessionFactory();
@ -152,10 +157,11 @@ public class ConfigurationTest {
s.close();
sf.close();
}
@Test
public void testAnnReferencesHbm() throws Exception {
public void testAnnReferencesHbm() {
Configuration cfg = new Configuration();
cfg.configure( "org/hibernate/test/annotations/hibernate.cfg.xml" );
cfg.configure( "org/hibernate/orm/test/annotations/hibernate.cfg.xml" );
cfg.addAnnotatedClass( Port.class );
cfg.setProperty( Environment.HBM2DDL_AUTO, "create-drop" );
SessionFactory sf = cfg.buildSessionFactory();

View File

@ -4,7 +4,7 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.test.annotations;
package org.hibernate.orm.test.annotations;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@ -14,33 +14,33 @@ import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.Generated;
import org.hibernate.annotations.NaturalId;
import org.hibernate.annotations.ValueGenerationType;
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
import org.hibernate.dialect.SybaseASEDialect;
import org.hibernate.tuple.AnnotationValueGeneration;
import org.hibernate.tuple.GenerationTiming;
import org.hibernate.tuple.ValueGenerator;
import org.hibernate.testing.TestForIssue;
import org.junit.Assert;
import org.junit.Test;
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
import org.hibernate.testing.orm.junit.DialectFeatureChecks;
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
import org.hibernate.testing.orm.junit.Jpa;
import org.hibernate.testing.orm.junit.RequiresDialectFeature;
import org.hibernate.testing.orm.junit.SkipForDialect;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
/**
* @author Vlad Mihalcea
*/
@TestForIssue( jiraKey = "HHH-11096" )
public class DatabaseCreationTimestampNullableColumnTest extends BaseEntityManagerFunctionalTestCase {
@Override
protected Class<?>[] getAnnotatedClasses() {
return new Class<?>[]{
Person.class
};
@RequiresDialectFeature( feature = DialectFeatureChecks.UsesStandardCurrentTimestampFunction.class )
@Jpa(
annotatedClasses = {
DatabaseCreationTimestampNullableColumnTest.Person.class
}
)
public class DatabaseCreationTimestampNullableColumnTest {
@Entity(name = "Person")
public class Person {
@ -119,14 +119,16 @@ public class DatabaseCreationTimestampNullableColumnTest extends BaseEntityManag
}
@Test
public void generatesCurrentTimestamp() {
doInJPA(this::entityManagerFactory, entityManager -> {
public void generatesCurrentTimestamp(EntityManagerFactoryScope scope) {
scope.inTransaction(
entityManager -> {
Person person = new Person();
person.setName("John Doe");
entityManager.persist(person);
entityManager.flush();
Assert.assertNotNull(person.getCreationDate());
});
Assertions.assertNotNull(person.getCreationDate());
}
);
}
}

View File

@ -0,0 +1,118 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.orm.test.tm;
import javax.persistence.PersistenceException;
import org.hibernate.Transaction;
import org.hibernate.TransactionException;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.orm.test.jdbc.Person;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.ServiceRegistry;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.hibernate.testing.orm.junit.Setting;
import org.junit.jupiter.api.Test;
import static org.hibernate.testing.orm.junit.ExtraAssertions.assertTyping;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotSame;
import static org.junit.jupiter.api.Assertions.fail;
/**
* @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com)
*/
@TestForIssue(jiraKey = "HHH-6780")
@ServiceRegistry(
settings = {
@Setting( name = AvailableSettings.IMPLICIT_NAMING_STRATEGY, value = "legacy-hbm" )
}
)
@DomainModel(
xmlMappings = {"org/hibernate/orm/test/jdbc/Mappings.hbm.xml"}
)
@SessionFactory
public class TransactionTimeoutTest {
@Test
public void testJdbcCoordinatorTransactionTimeoutCheck(SessionFactoryScope scope) {
scope.inSession(
session -> {
try {
Transaction transaction = session.getTransaction();
transaction.setTimeout( 2 );
assertEquals( -1, session.getJdbcCoordinator().determineRemainingTransactionTimeOutPeriod() );
transaction.begin();
assertNotSame( -1, session.getJdbcCoordinator().determineRemainingTransactionTimeOutPeriod() );
transaction.commit();
}
catch (Exception e) {
if ( session.getTransaction().isActive() ) {
session.getTransaction().rollback();
}
throw e;
}
}
);
}
@Test
public void testTransactionTimeoutFailure(SessionFactoryScope scope) {
scope.inSession(
session -> {
try {
Transaction transaction = session.getTransaction();
transaction.setTimeout( 1 );
assertEquals( -1, session.getJdbcCoordinator().determineRemainingTransactionTimeOutPeriod() );
transaction.begin();
Thread.sleep( 1000 );
session.persist( new Person( "Lukasz", "Antoniak" ) );
transaction.commit();
}
catch (TransactionException e) {
// expected
}
catch (PersistenceException e) {
assertTyping( TransactionException.class, e.getCause() );
}
catch (InterruptedException ie) {
fail(ie.getCause());
}
finally {
if ( session.getTransaction().isActive() ) {
session.getTransaction().rollback();
}
}
}
);
}
@Test
public void testTransactionTimeoutSuccess(SessionFactoryScope scope) {
scope.inSession(
session -> {
try {
Transaction transaction = session.getTransaction();
transaction.setTimeout( 60 );
transaction.begin();
session.persist( new Person( "Lukasz", "Antoniak" ) );
transaction.commit();
}
catch (Exception e) {
if ( session.getTransaction().isActive() ) {
session.getTransaction().rollback();
}
throw e;
}
}
);
}
}

View File

@ -62,17 +62,22 @@ import org.hibernate.type.UrlType;
import org.hibernate.type.YesNoType;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
import org.junit.Test;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.NotImplementedYet;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.jupiter.api.Test;
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
/**
* @author Vlad Mihalcea
*/
public class StoredProcedureParameterTypeTest extends BaseNonConfigCoreFunctionalTestCase {
@NotImplementedYet
@DomainModel
@SessionFactory
public class StoredProcedureParameterTypeTest {
private static final String TEST_STRING = "test_string";
private static final char[] TEST_CHAR_ARRAY = TEST_STRING.toCharArray();
@ -80,30 +85,30 @@ public class StoredProcedureParameterTypeTest extends BaseNonConfigCoreFunctiona
@Test
@TestForIssue( jiraKey = "HHH-12661" )
public void testNumericBooleanTypeInParameter() {
doInHibernate( this::sessionFactory, session -> {
session.createStoredProcedureQuery( "test" )
public void testNumericBooleanTypeInParameter(SessionFactoryScope scope) {
scope.inTransaction(
session -> session.createStoredProcedureQuery( "test" )
.registerStoredProcedureParameter( 1, NumericBooleanType.class, ParameterMode.IN )
.registerStoredProcedureParameter( 2, String.class, ParameterMode.OUT )
.setParameter( 1, false );
} );
.setParameter( 1, false )
);
}
@Test
@TestForIssue( jiraKey = "HHH-12661" )
public void testYesNoTypeInParameter() {
doInHibernate( this::sessionFactory, session -> {
session.createStoredProcedureQuery( "test" )
public void testYesNoTypeInParameter(SessionFactoryScope scope) {
scope.inTransaction(
session -> session.createStoredProcedureQuery( "test" )
.registerStoredProcedureParameter( 1, YesNoType.class, ParameterMode.IN )
.registerStoredProcedureParameter( 2, String.class, ParameterMode.OUT )
.setParameter( 1, false );
} );
.setParameter( 1, false )
);
}
@Test
@TestForIssue( jiraKey = "HHH-12661" )
public void testStringTypeInParameter() {
inTransaction(
public void testStringTypeInParameter(SessionFactoryScope scope) {
scope.inTransaction(
session -> session.createStoredProcedureQuery("test")
.registerStoredProcedureParameter( 1, StringType.class, ParameterMode.IN)
.setParameter(1, TEST_STRING)
@ -112,8 +117,8 @@ public class StoredProcedureParameterTypeTest extends BaseNonConfigCoreFunctiona
@Test
@TestForIssue( jiraKey = "HHH-12661" )
public void testMaterializedClobTypeInParameter() {
inTransaction(
public void testMaterializedClobTypeInParameter(SessionFactoryScope scope) {
scope.inTransaction(
session -> session.createStoredProcedureQuery("test")
.registerStoredProcedureParameter( 1, MaterializedClobType.class, ParameterMode.IN)
.setParameter(1, TEST_STRING)
@ -122,8 +127,8 @@ public class StoredProcedureParameterTypeTest extends BaseNonConfigCoreFunctiona
@Test
@TestForIssue( jiraKey = "HHH-12661" )
public void testTextTypeInParameter() {
inTransaction(
public void testTextTypeInParameter(SessionFactoryScope scope) {
scope.inTransaction(
session -> session.createStoredProcedureQuery("test")
.registerStoredProcedureParameter( 1, TextType.class, ParameterMode.IN)
.setParameter(1, TEST_STRING)
@ -132,8 +137,8 @@ public class StoredProcedureParameterTypeTest extends BaseNonConfigCoreFunctiona
@Test
@TestForIssue( jiraKey = "HHH-12661" )
public void testCharacterTypeInParameter() {
inTransaction(
public void testCharacterTypeInParameter(SessionFactoryScope scope) {
scope.inTransaction(
session -> session.createStoredProcedureQuery("test")
.registerStoredProcedureParameter( 1, CharacterType.class, ParameterMode.IN)
.setParameter(1, 'a')
@ -142,8 +147,8 @@ public class StoredProcedureParameterTypeTest extends BaseNonConfigCoreFunctiona
@Test
@TestForIssue( jiraKey = "HHH-12661" )
public void testTrueFalseTypeInParameter() {
inTransaction(
public void testTrueFalseTypeInParameter(SessionFactoryScope scope) {
scope.inTransaction(
session -> session.createStoredProcedureQuery("test")
.registerStoredProcedureParameter( 1, TrueFalseType.class, ParameterMode.IN)
.setParameter(1, false)
@ -152,8 +157,8 @@ public class StoredProcedureParameterTypeTest extends BaseNonConfigCoreFunctiona
@Test
@TestForIssue( jiraKey = "HHH-12661" )
public void testBooleanTypeInParameter() {
inTransaction(
public void testBooleanTypeInParameter(SessionFactoryScope scope) {
scope.inTransaction(
session -> session.createStoredProcedureQuery("test")
.registerStoredProcedureParameter( 1, BooleanType.class, ParameterMode.IN)
.setParameter(1, false)
@ -162,8 +167,8 @@ public class StoredProcedureParameterTypeTest extends BaseNonConfigCoreFunctiona
@Test
@TestForIssue( jiraKey = "HHH-12661" )
public void testByteTypeInParameter() {
inTransaction(
public void testByteTypeInParameter(SessionFactoryScope scope) {
scope.inTransaction(
session -> session.createStoredProcedureQuery("test")
.registerStoredProcedureParameter( 1, ByteType.class, ParameterMode.IN)
.setParameter(1, (byte) 'a')
@ -172,8 +177,8 @@ public class StoredProcedureParameterTypeTest extends BaseNonConfigCoreFunctiona
@Test
@TestForIssue( jiraKey = "HHH-12661" )
public void testShortTypeInParameter() {
inTransaction(
public void testShortTypeInParameter(SessionFactoryScope scope) {
scope.inTransaction(
session -> session.createStoredProcedureQuery("test")
.registerStoredProcedureParameter( 1, ShortType.class, ParameterMode.IN)
.setParameter(1, (short) 2)
@ -182,8 +187,8 @@ public class StoredProcedureParameterTypeTest extends BaseNonConfigCoreFunctiona
@Test
@TestForIssue( jiraKey = "HHH-12661" )
public void testIntegerTypeInParameter() {
inTransaction(
public void testIntegerTypeInParameter(SessionFactoryScope scope) {
scope.inTransaction(
session -> session.createStoredProcedureQuery("test")
.registerStoredProcedureParameter( 1, IntegerType.class, ParameterMode.IN)
.setParameter(1, 2)
@ -192,8 +197,8 @@ public class StoredProcedureParameterTypeTest extends BaseNonConfigCoreFunctiona
@Test
@TestForIssue( jiraKey = "HHH-12661" )
public void testLongTypeInParameter() {
inTransaction(
public void testLongTypeInParameter(SessionFactoryScope scope) {
scope.inTransaction(
session -> session.createStoredProcedureQuery("test")
.registerStoredProcedureParameter( 1, LongType.class, ParameterMode.IN)
.setParameter(1, 2L)
@ -201,8 +206,8 @@ public class StoredProcedureParameterTypeTest extends BaseNonConfigCoreFunctiona
}
@Test
public void testFloatTypeInParameter() {
inTransaction(
public void testFloatTypeInParameter(SessionFactoryScope scope) {
scope.inTransaction(
session -> session.createStoredProcedureQuery("test")
.registerStoredProcedureParameter( 1, FloatType.class, ParameterMode.IN)
.setParameter(1, 2.0F)
@ -211,8 +216,8 @@ public class StoredProcedureParameterTypeTest extends BaseNonConfigCoreFunctiona
@Test
@TestForIssue( jiraKey = "HHH-12661" )
public void testDoubleTypeInParameter() {
inTransaction(
public void testDoubleTypeInParameter(SessionFactoryScope scope) {
scope.inTransaction(
session -> session.createStoredProcedureQuery("test")
.registerStoredProcedureParameter( 1, DoubleType.class, ParameterMode.IN)
.setParameter(1, 2.0D)
@ -221,8 +226,8 @@ public class StoredProcedureParameterTypeTest extends BaseNonConfigCoreFunctiona
@Test
@TestForIssue( jiraKey = "HHH-12661" )
public void testBigIntegerTypeInParameter() {
inTransaction(
public void testBigIntegerTypeInParameter(SessionFactoryScope scope) {
scope.inTransaction(
session -> session.createStoredProcedureQuery("test")
.registerStoredProcedureParameter( 1, BigIntegerType.class, ParameterMode.IN)
.setParameter( 1, BigInteger.ONE)
@ -231,8 +236,8 @@ public class StoredProcedureParameterTypeTest extends BaseNonConfigCoreFunctiona
@Test
@TestForIssue( jiraKey = "HHH-12661" )
public void testBigDecimalTypeInParameter() {
inTransaction(
public void testBigDecimalTypeInParameter(SessionFactoryScope scope) {
scope.inTransaction(
session -> session.createStoredProcedureQuery("test")
.registerStoredProcedureParameter( 1, BigDecimalType.class, ParameterMode.IN)
.setParameter( 1, BigDecimal.ONE)
@ -241,8 +246,8 @@ public class StoredProcedureParameterTypeTest extends BaseNonConfigCoreFunctiona
@Test
@TestForIssue( jiraKey = "HHH-12661" )
public void testTimestampTypeDateInParameter() {
inTransaction(
public void testTimestampTypeDateInParameter(SessionFactoryScope scope) {
scope.inTransaction(
session -> session.createStoredProcedureQuery("test")
.registerStoredProcedureParameter( 1, TimestampType.class, ParameterMode.IN)
.setParameter(1, new Date())
@ -251,8 +256,8 @@ public class StoredProcedureParameterTypeTest extends BaseNonConfigCoreFunctiona
@Test
@TestForIssue( jiraKey = "HHH-12661" )
public void testTimestampTypeTimestampInParameter() {
inTransaction(
public void testTimestampTypeTimestampInParameter(SessionFactoryScope scope) {
scope.inTransaction(
session -> session.createStoredProcedureQuery("test")
.registerStoredProcedureParameter(1, TimestampType.class, ParameterMode.IN)
.setParameter( 1, Timestamp.valueOf( LocalDateTime.now()))
@ -261,8 +266,8 @@ public class StoredProcedureParameterTypeTest extends BaseNonConfigCoreFunctiona
@Test
@TestForIssue( jiraKey = "HHH-12661" )
public void testTimeTypeInParameter() {
inTransaction(
public void testTimeTypeInParameter(SessionFactoryScope scope) {
scope.inTransaction(
session -> session.createStoredProcedureQuery("test")
.registerStoredProcedureParameter( 1, TimeType.class, ParameterMode.IN)
.setParameter( 1, Time.valueOf( LocalTime.now()))
@ -271,8 +276,8 @@ public class StoredProcedureParameterTypeTest extends BaseNonConfigCoreFunctiona
@Test
@TestForIssue( jiraKey = "HHH-12661" )
public void testDateTypeInParameter() {
inTransaction(
public void testDateTypeInParameter(SessionFactoryScope scope) {
scope.inTransaction(
session -> session.createStoredProcedureQuery("test")
.registerStoredProcedureParameter( 1, DateType.class, ParameterMode.IN)
.setParameter(1, java.sql.Date.valueOf( LocalDate.now()))
@ -281,8 +286,8 @@ public class StoredProcedureParameterTypeTest extends BaseNonConfigCoreFunctiona
@Test
@TestForIssue( jiraKey = "HHH-12661" )
public void testCalendarTypeCalendarInParameter() {
inTransaction(
public void testCalendarTypeCalendarInParameter(SessionFactoryScope scope) {
scope.inTransaction(
session -> session.createStoredProcedureQuery("test")
.registerStoredProcedureParameter( 1, CalendarType.class, ParameterMode.IN)
.setParameter( 1, Calendar.getInstance())
@ -291,8 +296,8 @@ public class StoredProcedureParameterTypeTest extends BaseNonConfigCoreFunctiona
@Test
@TestForIssue( jiraKey = "HHH-12661" )
public void testCurrencyTypeInParameter() {
inTransaction(
public void testCurrencyTypeInParameter(SessionFactoryScope scope) {
scope.inTransaction(
session -> session.createStoredProcedureQuery("test")
.registerStoredProcedureParameter( 1, CurrencyType.class, ParameterMode.IN)
.setParameter( 1, Currency.getAvailableCurrencies().iterator().next())
@ -301,8 +306,8 @@ public class StoredProcedureParameterTypeTest extends BaseNonConfigCoreFunctiona
@Test
@TestForIssue( jiraKey = "HHH-12661" )
public void testLocaleTypeInParameter() {
inTransaction(
public void testLocaleTypeInParameter(SessionFactoryScope scope) {
scope.inTransaction(
session -> session.createStoredProcedureQuery("test")
.registerStoredProcedureParameter( 1, LocaleType.class, ParameterMode.IN)
.setParameter( 1, Locale.ENGLISH)
@ -311,8 +316,8 @@ public class StoredProcedureParameterTypeTest extends BaseNonConfigCoreFunctiona
@Test
@TestForIssue( jiraKey = "HHH-12661" )
public void testTimeZoneTypeInParameter() {
inTransaction(
public void testTimeZoneTypeInParameter(SessionFactoryScope scope) {
scope.inTransaction(
session -> session.createStoredProcedureQuery("test")
.registerStoredProcedureParameter( 1, TimeZoneType.class, ParameterMode.IN)
.setParameter( 1, TimeZone.getTimeZone( ZoneId.systemDefault()))
@ -321,9 +326,9 @@ public class StoredProcedureParameterTypeTest extends BaseNonConfigCoreFunctiona
@Test
@TestForIssue( jiraKey = "HHH-12661" )
public void testUrlTypeInParameter() throws MalformedURLException {
public void testUrlTypeInParameter(SessionFactoryScope scope) throws MalformedURLException {
final URL url = new URL( "http://example.com");
inTransaction(
scope.inTransaction(
session -> session.createStoredProcedureQuery("test")
.registerStoredProcedureParameter( 1, UrlType.class, ParameterMode.IN)
.setParameter(1, url)
@ -332,8 +337,8 @@ public class StoredProcedureParameterTypeTest extends BaseNonConfigCoreFunctiona
@Test
@TestForIssue( jiraKey = "HHH-12661" )
public void testClassTypeInParameter() {
inTransaction(
public void testClassTypeInParameter(SessionFactoryScope scope) {
scope.inTransaction(
session -> session.createStoredProcedureQuery("test")
.registerStoredProcedureParameter( 1, ClassType.class, ParameterMode.IN)
.setParameter(1, Class.class)
@ -342,9 +347,9 @@ public class StoredProcedureParameterTypeTest extends BaseNonConfigCoreFunctiona
@Test
@TestForIssue( jiraKey = "HHH-12661" )
public void testBlobTypeInParameter() throws SQLException {
public void testBlobTypeInParameter(SessionFactoryScope scope) throws SQLException {
final Blob blob = new SerialBlob( TEST_BYTE_ARRAY);
inTransaction(
scope.inTransaction(
session -> session.createStoredProcedureQuery("test")
.registerStoredProcedureParameter( 1, BlobType.class, ParameterMode.IN)
.setParameter(1, blob)
@ -353,9 +358,9 @@ public class StoredProcedureParameterTypeTest extends BaseNonConfigCoreFunctiona
@Test
@TestForIssue( jiraKey = "HHH-12661" )
public void testClobTypeInParameter() throws SQLException {
public void testClobTypeInParameter(SessionFactoryScope scope) throws SQLException {
final Clob clob = new SerialClob( TEST_CHAR_ARRAY);
inTransaction(
scope.inTransaction(
session -> session.createStoredProcedureQuery("test")
.registerStoredProcedureParameter( 1, ClobType.class, ParameterMode.IN)
.setParameter(1, clob)
@ -364,8 +369,8 @@ public class StoredProcedureParameterTypeTest extends BaseNonConfigCoreFunctiona
@Test
@TestForIssue( jiraKey = "HHH-12661" )
public void testBinaryTypeInParameter() {
inTransaction(
public void testBinaryTypeInParameter(SessionFactoryScope scope) {
scope.inTransaction(
session -> session.createStoredProcedureQuery("test")
.registerStoredProcedureParameter( 1, BinaryType.class, ParameterMode.IN)
.setParameter(1, TEST_BYTE_ARRAY)
@ -374,8 +379,8 @@ public class StoredProcedureParameterTypeTest extends BaseNonConfigCoreFunctiona
@Test
@TestForIssue( jiraKey = "HHH-12661" )
public void testCharArrayTypeInParameter() {
inTransaction(
public void testCharArrayTypeInParameter(SessionFactoryScope scope) {
scope.inTransaction(
session -> session.createStoredProcedureQuery("test")
.registerStoredProcedureParameter( 1, CharArrayType.class, ParameterMode.IN)
.setParameter(1, TEST_CHAR_ARRAY)
@ -384,8 +389,8 @@ public class StoredProcedureParameterTypeTest extends BaseNonConfigCoreFunctiona
@Test
@TestForIssue( jiraKey = "HHH-12661" )
public void testUUIDBinaryTypeInParameter() {
inTransaction(
public void testUUIDBinaryTypeInParameter(SessionFactoryScope scope) {
scope.inTransaction(
session -> session.createStoredProcedureQuery("test")
.registerStoredProcedureParameter( 1, UUIDBinaryType.class, ParameterMode.IN)
.setParameter( 1, UUID.randomUUID())
@ -394,8 +399,8 @@ public class StoredProcedureParameterTypeTest extends BaseNonConfigCoreFunctiona
@Test
@TestForIssue(jiraKey = "HHH-12905")
public void testStringTypeInParameterIsNull() {
inTransaction(
public void testStringTypeInParameterIsNull(SessionFactoryScope scope) {
scope.inTransaction(
session -> {
ProcedureCall procedureCall = session.createStoredProcedureCall( "test" );
procedureCall.registerParameter( 1, StringType.class, ParameterMode.IN ).enablePassingNulls( true );
@ -406,8 +411,8 @@ public class StoredProcedureParameterTypeTest extends BaseNonConfigCoreFunctiona
@Test
@TestForIssue(jiraKey = "HHH-12905")
public void testStringTypeInParameterIsNullWithoutEnablePassingNulls() {
inTransaction(
public void testStringTypeInParameterIsNullWithoutEnablePassingNulls(SessionFactoryScope scope) {
scope.inTransaction(
session -> {
try {
ProcedureCall procedureCall = session.createStoredProcedureCall( "test" );

View File

@ -1,94 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.test.tm;
import javax.persistence.PersistenceException;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.TransactionException;
import org.hibernate.boot.model.naming.ImplicitNamingStrategyLegacyHbmImpl;
import org.hibernate.cfg.Configuration;
import org.hibernate.dialect.PostgreSQL81Dialect;
import org.hibernate.dialect.PostgreSQLDialect;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.testing.SkipForDialect;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.hibernate.orm.test.jdbc.Person;
import org.junit.Test;
import static org.hibernate.testing.junit4.ExtraAssertions.assertTyping;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotSame;
/**
* @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com)
*/
@TestForIssue(jiraKey = "HHH-6780")
@SkipForDialect( value ={ PostgreSQL81Dialect.class, PostgreSQLDialect.class}, comment = "PostgreSQL jdbc driver doesn't impl timeout method")
public class TransactionTimeoutTest extends BaseCoreFunctionalTestCase {
@Override
public String[] getMappings() {
return new String[] {"jdbc/Mappings.hbm.xml"};
}
@Override
protected void configure(Configuration configuration) {
super.configure( configuration );
configuration.setImplicitNamingStrategy( ImplicitNamingStrategyLegacyHbmImpl.INSTANCE );
}
@Test
public void testJdbcCoordinatorTransactionTimeoutCheck() {
Session session = openSession();
Transaction transaction = session.getTransaction();
transaction.setTimeout( 2 );
assertEquals( -1, ((SessionImplementor)session).getJdbcCoordinator().determineRemainingTransactionTimeOutPeriod() );
transaction.begin();
assertNotSame( -1, ((SessionImplementor)session).getJdbcCoordinator().determineRemainingTransactionTimeOutPeriod() );
transaction.commit();
session.close();
}
@Test
public void testTransactionTimeoutFailure() throws InterruptedException {
Session session = openSession();
try {
Transaction transaction = session.getTransaction();
transaction.setTimeout( 1 );
assertEquals( -1,
( (SessionImplementor) session ).getJdbcCoordinator().determineRemainingTransactionTimeOutPeriod()
);
transaction.begin();
Thread.sleep( 1000 );
session.persist( new Person( "Lukasz", "Antoniak" ) );
transaction.commit();
}
catch (TransactionException e) {
// expected
}
catch (PersistenceException e) {
assertTyping( TransactionException.class, e.getCause() );
}
finally {
session.close();
}
}
@Test
public void testTransactionTimeoutSuccess() {
Session session = openSession();
Transaction transaction = session.getTransaction();
transaction.setTimeout( 60 );
transaction.begin();
session.persist( new Person( "Lukasz", "Antoniak" ) );
transaction.commit();
session.close();
}
}