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

View File

@ -4,7 +4,7 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. * 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>. * 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.Retention;
import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy;
@ -14,33 +14,33 @@ import javax.persistence.Entity;
import javax.persistence.GeneratedValue; import javax.persistence.GeneratedValue;
import javax.persistence.Id; import javax.persistence.Id;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.Generated;
import org.hibernate.annotations.NaturalId; import org.hibernate.annotations.NaturalId;
import org.hibernate.annotations.ValueGenerationType; 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.AnnotationValueGeneration;
import org.hibernate.tuple.GenerationTiming; import org.hibernate.tuple.GenerationTiming;
import org.hibernate.tuple.ValueGenerator; import org.hibernate.tuple.ValueGenerator;
import org.hibernate.testing.TestForIssue; import org.hibernate.testing.TestForIssue;
import org.junit.Assert; import org.hibernate.testing.orm.junit.DialectFeatureChecks;
import org.junit.Test; import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
import org.hibernate.testing.orm.junit.Jpa;
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA; 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 * @author Vlad Mihalcea
*/ */
@TestForIssue( jiraKey = "HHH-11096" ) @TestForIssue( jiraKey = "HHH-11096" )
public class DatabaseCreationTimestampNullableColumnTest extends BaseEntityManagerFunctionalTestCase { @RequiresDialectFeature( feature = DialectFeatureChecks.UsesStandardCurrentTimestampFunction.class )
@Jpa(
@Override annotatedClasses = {
protected Class<?>[] getAnnotatedClasses() { DatabaseCreationTimestampNullableColumnTest.Person.class
return new Class<?>[]{
Person.class
};
} }
)
public class DatabaseCreationTimestampNullableColumnTest {
@Entity(name = "Person") @Entity(name = "Person")
public class Person { public class Person {
@ -119,14 +119,16 @@ public class DatabaseCreationTimestampNullableColumnTest extends BaseEntityManag
} }
@Test @Test
public void generatesCurrentTimestamp() { public void generatesCurrentTimestamp(EntityManagerFactoryScope scope) {
doInJPA(this::entityManagerFactory, entityManager -> { scope.inTransaction(
entityManager -> {
Person person = new Person(); Person person = new Person();
person.setName("John Doe"); person.setName("John Doe");
entityManager.persist(person); entityManager.persist(person);
entityManager.flush(); 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.type.YesNoType;
import org.hibernate.testing.TestForIssue; import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase; import org.hibernate.testing.orm.junit.DomainModel;
import org.junit.Test; 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.jupiter.api.Assertions.assertTrue;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.fail;
import static org.junit.Assert.fail;
/** /**
* @author Vlad Mihalcea * @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 String TEST_STRING = "test_string";
private static final char[] TEST_CHAR_ARRAY = TEST_STRING.toCharArray(); private static final char[] TEST_CHAR_ARRAY = TEST_STRING.toCharArray();
@ -80,30 +85,30 @@ public class StoredProcedureParameterTypeTest extends BaseNonConfigCoreFunctiona
@Test @Test
@TestForIssue( jiraKey = "HHH-12661" ) @TestForIssue( jiraKey = "HHH-12661" )
public void testNumericBooleanTypeInParameter() { public void testNumericBooleanTypeInParameter(SessionFactoryScope scope) {
doInHibernate( this::sessionFactory, session -> { scope.inTransaction(
session.createStoredProcedureQuery( "test" ) session -> session.createStoredProcedureQuery( "test" )
.registerStoredProcedureParameter( 1, NumericBooleanType.class, ParameterMode.IN ) .registerStoredProcedureParameter( 1, NumericBooleanType.class, ParameterMode.IN )
.registerStoredProcedureParameter( 2, String.class, ParameterMode.OUT ) .registerStoredProcedureParameter( 2, String.class, ParameterMode.OUT )
.setParameter( 1, false ); .setParameter( 1, false )
} ); );
} }
@Test @Test
@TestForIssue( jiraKey = "HHH-12661" ) @TestForIssue( jiraKey = "HHH-12661" )
public void testYesNoTypeInParameter() { public void testYesNoTypeInParameter(SessionFactoryScope scope) {
doInHibernate( this::sessionFactory, session -> { scope.inTransaction(
session.createStoredProcedureQuery( "test" ) session -> session.createStoredProcedureQuery( "test" )
.registerStoredProcedureParameter( 1, YesNoType.class, ParameterMode.IN ) .registerStoredProcedureParameter( 1, YesNoType.class, ParameterMode.IN )
.registerStoredProcedureParameter( 2, String.class, ParameterMode.OUT ) .registerStoredProcedureParameter( 2, String.class, ParameterMode.OUT )
.setParameter( 1, false ); .setParameter( 1, false )
} ); );
} }
@Test @Test
@TestForIssue( jiraKey = "HHH-12661" ) @TestForIssue( jiraKey = "HHH-12661" )
public void testStringTypeInParameter() { public void testStringTypeInParameter(SessionFactoryScope scope) {
inTransaction( scope.inTransaction(
session -> session.createStoredProcedureQuery("test") session -> session.createStoredProcedureQuery("test")
.registerStoredProcedureParameter( 1, StringType.class, ParameterMode.IN) .registerStoredProcedureParameter( 1, StringType.class, ParameterMode.IN)
.setParameter(1, TEST_STRING) .setParameter(1, TEST_STRING)
@ -112,8 +117,8 @@ public class StoredProcedureParameterTypeTest extends BaseNonConfigCoreFunctiona
@Test @Test
@TestForIssue( jiraKey = "HHH-12661" ) @TestForIssue( jiraKey = "HHH-12661" )
public void testMaterializedClobTypeInParameter() { public void testMaterializedClobTypeInParameter(SessionFactoryScope scope) {
inTransaction( scope.inTransaction(
session -> session.createStoredProcedureQuery("test") session -> session.createStoredProcedureQuery("test")
.registerStoredProcedureParameter( 1, MaterializedClobType.class, ParameterMode.IN) .registerStoredProcedureParameter( 1, MaterializedClobType.class, ParameterMode.IN)
.setParameter(1, TEST_STRING) .setParameter(1, TEST_STRING)
@ -122,8 +127,8 @@ public class StoredProcedureParameterTypeTest extends BaseNonConfigCoreFunctiona
@Test @Test
@TestForIssue( jiraKey = "HHH-12661" ) @TestForIssue( jiraKey = "HHH-12661" )
public void testTextTypeInParameter() { public void testTextTypeInParameter(SessionFactoryScope scope) {
inTransaction( scope.inTransaction(
session -> session.createStoredProcedureQuery("test") session -> session.createStoredProcedureQuery("test")
.registerStoredProcedureParameter( 1, TextType.class, ParameterMode.IN) .registerStoredProcedureParameter( 1, TextType.class, ParameterMode.IN)
.setParameter(1, TEST_STRING) .setParameter(1, TEST_STRING)
@ -132,8 +137,8 @@ public class StoredProcedureParameterTypeTest extends BaseNonConfigCoreFunctiona
@Test @Test
@TestForIssue( jiraKey = "HHH-12661" ) @TestForIssue( jiraKey = "HHH-12661" )
public void testCharacterTypeInParameter() { public void testCharacterTypeInParameter(SessionFactoryScope scope) {
inTransaction( scope.inTransaction(
session -> session.createStoredProcedureQuery("test") session -> session.createStoredProcedureQuery("test")
.registerStoredProcedureParameter( 1, CharacterType.class, ParameterMode.IN) .registerStoredProcedureParameter( 1, CharacterType.class, ParameterMode.IN)
.setParameter(1, 'a') .setParameter(1, 'a')
@ -142,8 +147,8 @@ public class StoredProcedureParameterTypeTest extends BaseNonConfigCoreFunctiona
@Test @Test
@TestForIssue( jiraKey = "HHH-12661" ) @TestForIssue( jiraKey = "HHH-12661" )
public void testTrueFalseTypeInParameter() { public void testTrueFalseTypeInParameter(SessionFactoryScope scope) {
inTransaction( scope.inTransaction(
session -> session.createStoredProcedureQuery("test") session -> session.createStoredProcedureQuery("test")
.registerStoredProcedureParameter( 1, TrueFalseType.class, ParameterMode.IN) .registerStoredProcedureParameter( 1, TrueFalseType.class, ParameterMode.IN)
.setParameter(1, false) .setParameter(1, false)
@ -152,8 +157,8 @@ public class StoredProcedureParameterTypeTest extends BaseNonConfigCoreFunctiona
@Test @Test
@TestForIssue( jiraKey = "HHH-12661" ) @TestForIssue( jiraKey = "HHH-12661" )
public void testBooleanTypeInParameter() { public void testBooleanTypeInParameter(SessionFactoryScope scope) {
inTransaction( scope.inTransaction(
session -> session.createStoredProcedureQuery("test") session -> session.createStoredProcedureQuery("test")
.registerStoredProcedureParameter( 1, BooleanType.class, ParameterMode.IN) .registerStoredProcedureParameter( 1, BooleanType.class, ParameterMode.IN)
.setParameter(1, false) .setParameter(1, false)
@ -162,8 +167,8 @@ public class StoredProcedureParameterTypeTest extends BaseNonConfigCoreFunctiona
@Test @Test
@TestForIssue( jiraKey = "HHH-12661" ) @TestForIssue( jiraKey = "HHH-12661" )
public void testByteTypeInParameter() { public void testByteTypeInParameter(SessionFactoryScope scope) {
inTransaction( scope.inTransaction(
session -> session.createStoredProcedureQuery("test") session -> session.createStoredProcedureQuery("test")
.registerStoredProcedureParameter( 1, ByteType.class, ParameterMode.IN) .registerStoredProcedureParameter( 1, ByteType.class, ParameterMode.IN)
.setParameter(1, (byte) 'a') .setParameter(1, (byte) 'a')
@ -172,8 +177,8 @@ public class StoredProcedureParameterTypeTest extends BaseNonConfigCoreFunctiona
@Test @Test
@TestForIssue( jiraKey = "HHH-12661" ) @TestForIssue( jiraKey = "HHH-12661" )
public void testShortTypeInParameter() { public void testShortTypeInParameter(SessionFactoryScope scope) {
inTransaction( scope.inTransaction(
session -> session.createStoredProcedureQuery("test") session -> session.createStoredProcedureQuery("test")
.registerStoredProcedureParameter( 1, ShortType.class, ParameterMode.IN) .registerStoredProcedureParameter( 1, ShortType.class, ParameterMode.IN)
.setParameter(1, (short) 2) .setParameter(1, (short) 2)
@ -182,8 +187,8 @@ public class StoredProcedureParameterTypeTest extends BaseNonConfigCoreFunctiona
@Test @Test
@TestForIssue( jiraKey = "HHH-12661" ) @TestForIssue( jiraKey = "HHH-12661" )
public void testIntegerTypeInParameter() { public void testIntegerTypeInParameter(SessionFactoryScope scope) {
inTransaction( scope.inTransaction(
session -> session.createStoredProcedureQuery("test") session -> session.createStoredProcedureQuery("test")
.registerStoredProcedureParameter( 1, IntegerType.class, ParameterMode.IN) .registerStoredProcedureParameter( 1, IntegerType.class, ParameterMode.IN)
.setParameter(1, 2) .setParameter(1, 2)
@ -192,8 +197,8 @@ public class StoredProcedureParameterTypeTest extends BaseNonConfigCoreFunctiona
@Test @Test
@TestForIssue( jiraKey = "HHH-12661" ) @TestForIssue( jiraKey = "HHH-12661" )
public void testLongTypeInParameter() { public void testLongTypeInParameter(SessionFactoryScope scope) {
inTransaction( scope.inTransaction(
session -> session.createStoredProcedureQuery("test") session -> session.createStoredProcedureQuery("test")
.registerStoredProcedureParameter( 1, LongType.class, ParameterMode.IN) .registerStoredProcedureParameter( 1, LongType.class, ParameterMode.IN)
.setParameter(1, 2L) .setParameter(1, 2L)
@ -201,8 +206,8 @@ public class StoredProcedureParameterTypeTest extends BaseNonConfigCoreFunctiona
} }
@Test @Test
public void testFloatTypeInParameter() { public void testFloatTypeInParameter(SessionFactoryScope scope) {
inTransaction( scope.inTransaction(
session -> session.createStoredProcedureQuery("test") session -> session.createStoredProcedureQuery("test")
.registerStoredProcedureParameter( 1, FloatType.class, ParameterMode.IN) .registerStoredProcedureParameter( 1, FloatType.class, ParameterMode.IN)
.setParameter(1, 2.0F) .setParameter(1, 2.0F)
@ -211,8 +216,8 @@ public class StoredProcedureParameterTypeTest extends BaseNonConfigCoreFunctiona
@Test @Test
@TestForIssue( jiraKey = "HHH-12661" ) @TestForIssue( jiraKey = "HHH-12661" )
public void testDoubleTypeInParameter() { public void testDoubleTypeInParameter(SessionFactoryScope scope) {
inTransaction( scope.inTransaction(
session -> session.createStoredProcedureQuery("test") session -> session.createStoredProcedureQuery("test")
.registerStoredProcedureParameter( 1, DoubleType.class, ParameterMode.IN) .registerStoredProcedureParameter( 1, DoubleType.class, ParameterMode.IN)
.setParameter(1, 2.0D) .setParameter(1, 2.0D)
@ -221,8 +226,8 @@ public class StoredProcedureParameterTypeTest extends BaseNonConfigCoreFunctiona
@Test @Test
@TestForIssue( jiraKey = "HHH-12661" ) @TestForIssue( jiraKey = "HHH-12661" )
public void testBigIntegerTypeInParameter() { public void testBigIntegerTypeInParameter(SessionFactoryScope scope) {
inTransaction( scope.inTransaction(
session -> session.createStoredProcedureQuery("test") session -> session.createStoredProcedureQuery("test")
.registerStoredProcedureParameter( 1, BigIntegerType.class, ParameterMode.IN) .registerStoredProcedureParameter( 1, BigIntegerType.class, ParameterMode.IN)
.setParameter( 1, BigInteger.ONE) .setParameter( 1, BigInteger.ONE)
@ -231,8 +236,8 @@ public class StoredProcedureParameterTypeTest extends BaseNonConfigCoreFunctiona
@Test @Test
@TestForIssue( jiraKey = "HHH-12661" ) @TestForIssue( jiraKey = "HHH-12661" )
public void testBigDecimalTypeInParameter() { public void testBigDecimalTypeInParameter(SessionFactoryScope scope) {
inTransaction( scope.inTransaction(
session -> session.createStoredProcedureQuery("test") session -> session.createStoredProcedureQuery("test")
.registerStoredProcedureParameter( 1, BigDecimalType.class, ParameterMode.IN) .registerStoredProcedureParameter( 1, BigDecimalType.class, ParameterMode.IN)
.setParameter( 1, BigDecimal.ONE) .setParameter( 1, BigDecimal.ONE)
@ -241,8 +246,8 @@ public class StoredProcedureParameterTypeTest extends BaseNonConfigCoreFunctiona
@Test @Test
@TestForIssue( jiraKey = "HHH-12661" ) @TestForIssue( jiraKey = "HHH-12661" )
public void testTimestampTypeDateInParameter() { public void testTimestampTypeDateInParameter(SessionFactoryScope scope) {
inTransaction( scope.inTransaction(
session -> session.createStoredProcedureQuery("test") session -> session.createStoredProcedureQuery("test")
.registerStoredProcedureParameter( 1, TimestampType.class, ParameterMode.IN) .registerStoredProcedureParameter( 1, TimestampType.class, ParameterMode.IN)
.setParameter(1, new Date()) .setParameter(1, new Date())
@ -251,8 +256,8 @@ public class StoredProcedureParameterTypeTest extends BaseNonConfigCoreFunctiona
@Test @Test
@TestForIssue( jiraKey = "HHH-12661" ) @TestForIssue( jiraKey = "HHH-12661" )
public void testTimestampTypeTimestampInParameter() { public void testTimestampTypeTimestampInParameter(SessionFactoryScope scope) {
inTransaction( scope.inTransaction(
session -> session.createStoredProcedureQuery("test") session -> session.createStoredProcedureQuery("test")
.registerStoredProcedureParameter(1, TimestampType.class, ParameterMode.IN) .registerStoredProcedureParameter(1, TimestampType.class, ParameterMode.IN)
.setParameter( 1, Timestamp.valueOf( LocalDateTime.now())) .setParameter( 1, Timestamp.valueOf( LocalDateTime.now()))
@ -261,8 +266,8 @@ public class StoredProcedureParameterTypeTest extends BaseNonConfigCoreFunctiona
@Test @Test
@TestForIssue( jiraKey = "HHH-12661" ) @TestForIssue( jiraKey = "HHH-12661" )
public void testTimeTypeInParameter() { public void testTimeTypeInParameter(SessionFactoryScope scope) {
inTransaction( scope.inTransaction(
session -> session.createStoredProcedureQuery("test") session -> session.createStoredProcedureQuery("test")
.registerStoredProcedureParameter( 1, TimeType.class, ParameterMode.IN) .registerStoredProcedureParameter( 1, TimeType.class, ParameterMode.IN)
.setParameter( 1, Time.valueOf( LocalTime.now())) .setParameter( 1, Time.valueOf( LocalTime.now()))
@ -271,8 +276,8 @@ public class StoredProcedureParameterTypeTest extends BaseNonConfigCoreFunctiona
@Test @Test
@TestForIssue( jiraKey = "HHH-12661" ) @TestForIssue( jiraKey = "HHH-12661" )
public void testDateTypeInParameter() { public void testDateTypeInParameter(SessionFactoryScope scope) {
inTransaction( scope.inTransaction(
session -> session.createStoredProcedureQuery("test") session -> session.createStoredProcedureQuery("test")
.registerStoredProcedureParameter( 1, DateType.class, ParameterMode.IN) .registerStoredProcedureParameter( 1, DateType.class, ParameterMode.IN)
.setParameter(1, java.sql.Date.valueOf( LocalDate.now())) .setParameter(1, java.sql.Date.valueOf( LocalDate.now()))
@ -281,8 +286,8 @@ public class StoredProcedureParameterTypeTest extends BaseNonConfigCoreFunctiona
@Test @Test
@TestForIssue( jiraKey = "HHH-12661" ) @TestForIssue( jiraKey = "HHH-12661" )
public void testCalendarTypeCalendarInParameter() { public void testCalendarTypeCalendarInParameter(SessionFactoryScope scope) {
inTransaction( scope.inTransaction(
session -> session.createStoredProcedureQuery("test") session -> session.createStoredProcedureQuery("test")
.registerStoredProcedureParameter( 1, CalendarType.class, ParameterMode.IN) .registerStoredProcedureParameter( 1, CalendarType.class, ParameterMode.IN)
.setParameter( 1, Calendar.getInstance()) .setParameter( 1, Calendar.getInstance())
@ -291,8 +296,8 @@ public class StoredProcedureParameterTypeTest extends BaseNonConfigCoreFunctiona
@Test @Test
@TestForIssue( jiraKey = "HHH-12661" ) @TestForIssue( jiraKey = "HHH-12661" )
public void testCurrencyTypeInParameter() { public void testCurrencyTypeInParameter(SessionFactoryScope scope) {
inTransaction( scope.inTransaction(
session -> session.createStoredProcedureQuery("test") session -> session.createStoredProcedureQuery("test")
.registerStoredProcedureParameter( 1, CurrencyType.class, ParameterMode.IN) .registerStoredProcedureParameter( 1, CurrencyType.class, ParameterMode.IN)
.setParameter( 1, Currency.getAvailableCurrencies().iterator().next()) .setParameter( 1, Currency.getAvailableCurrencies().iterator().next())
@ -301,8 +306,8 @@ public class StoredProcedureParameterTypeTest extends BaseNonConfigCoreFunctiona
@Test @Test
@TestForIssue( jiraKey = "HHH-12661" ) @TestForIssue( jiraKey = "HHH-12661" )
public void testLocaleTypeInParameter() { public void testLocaleTypeInParameter(SessionFactoryScope scope) {
inTransaction( scope.inTransaction(
session -> session.createStoredProcedureQuery("test") session -> session.createStoredProcedureQuery("test")
.registerStoredProcedureParameter( 1, LocaleType.class, ParameterMode.IN) .registerStoredProcedureParameter( 1, LocaleType.class, ParameterMode.IN)
.setParameter( 1, Locale.ENGLISH) .setParameter( 1, Locale.ENGLISH)
@ -311,8 +316,8 @@ public class StoredProcedureParameterTypeTest extends BaseNonConfigCoreFunctiona
@Test @Test
@TestForIssue( jiraKey = "HHH-12661" ) @TestForIssue( jiraKey = "HHH-12661" )
public void testTimeZoneTypeInParameter() { public void testTimeZoneTypeInParameter(SessionFactoryScope scope) {
inTransaction( scope.inTransaction(
session -> session.createStoredProcedureQuery("test") session -> session.createStoredProcedureQuery("test")
.registerStoredProcedureParameter( 1, TimeZoneType.class, ParameterMode.IN) .registerStoredProcedureParameter( 1, TimeZoneType.class, ParameterMode.IN)
.setParameter( 1, TimeZone.getTimeZone( ZoneId.systemDefault())) .setParameter( 1, TimeZone.getTimeZone( ZoneId.systemDefault()))
@ -321,9 +326,9 @@ public class StoredProcedureParameterTypeTest extends BaseNonConfigCoreFunctiona
@Test @Test
@TestForIssue( jiraKey = "HHH-12661" ) @TestForIssue( jiraKey = "HHH-12661" )
public void testUrlTypeInParameter() throws MalformedURLException { public void testUrlTypeInParameter(SessionFactoryScope scope) throws MalformedURLException {
final URL url = new URL( "http://example.com"); final URL url = new URL( "http://example.com");
inTransaction( scope.inTransaction(
session -> session.createStoredProcedureQuery("test") session -> session.createStoredProcedureQuery("test")
.registerStoredProcedureParameter( 1, UrlType.class, ParameterMode.IN) .registerStoredProcedureParameter( 1, UrlType.class, ParameterMode.IN)
.setParameter(1, url) .setParameter(1, url)
@ -332,8 +337,8 @@ public class StoredProcedureParameterTypeTest extends BaseNonConfigCoreFunctiona
@Test @Test
@TestForIssue( jiraKey = "HHH-12661" ) @TestForIssue( jiraKey = "HHH-12661" )
public void testClassTypeInParameter() { public void testClassTypeInParameter(SessionFactoryScope scope) {
inTransaction( scope.inTransaction(
session -> session.createStoredProcedureQuery("test") session -> session.createStoredProcedureQuery("test")
.registerStoredProcedureParameter( 1, ClassType.class, ParameterMode.IN) .registerStoredProcedureParameter( 1, ClassType.class, ParameterMode.IN)
.setParameter(1, Class.class) .setParameter(1, Class.class)
@ -342,9 +347,9 @@ public class StoredProcedureParameterTypeTest extends BaseNonConfigCoreFunctiona
@Test @Test
@TestForIssue( jiraKey = "HHH-12661" ) @TestForIssue( jiraKey = "HHH-12661" )
public void testBlobTypeInParameter() throws SQLException { public void testBlobTypeInParameter(SessionFactoryScope scope) throws SQLException {
final Blob blob = new SerialBlob( TEST_BYTE_ARRAY); final Blob blob = new SerialBlob( TEST_BYTE_ARRAY);
inTransaction( scope.inTransaction(
session -> session.createStoredProcedureQuery("test") session -> session.createStoredProcedureQuery("test")
.registerStoredProcedureParameter( 1, BlobType.class, ParameterMode.IN) .registerStoredProcedureParameter( 1, BlobType.class, ParameterMode.IN)
.setParameter(1, blob) .setParameter(1, blob)
@ -353,9 +358,9 @@ public class StoredProcedureParameterTypeTest extends BaseNonConfigCoreFunctiona
@Test @Test
@TestForIssue( jiraKey = "HHH-12661" ) @TestForIssue( jiraKey = "HHH-12661" )
public void testClobTypeInParameter() throws SQLException { public void testClobTypeInParameter(SessionFactoryScope scope) throws SQLException {
final Clob clob = new SerialClob( TEST_CHAR_ARRAY); final Clob clob = new SerialClob( TEST_CHAR_ARRAY);
inTransaction( scope.inTransaction(
session -> session.createStoredProcedureQuery("test") session -> session.createStoredProcedureQuery("test")
.registerStoredProcedureParameter( 1, ClobType.class, ParameterMode.IN) .registerStoredProcedureParameter( 1, ClobType.class, ParameterMode.IN)
.setParameter(1, clob) .setParameter(1, clob)
@ -364,8 +369,8 @@ public class StoredProcedureParameterTypeTest extends BaseNonConfigCoreFunctiona
@Test @Test
@TestForIssue( jiraKey = "HHH-12661" ) @TestForIssue( jiraKey = "HHH-12661" )
public void testBinaryTypeInParameter() { public void testBinaryTypeInParameter(SessionFactoryScope scope) {
inTransaction( scope.inTransaction(
session -> session.createStoredProcedureQuery("test") session -> session.createStoredProcedureQuery("test")
.registerStoredProcedureParameter( 1, BinaryType.class, ParameterMode.IN) .registerStoredProcedureParameter( 1, BinaryType.class, ParameterMode.IN)
.setParameter(1, TEST_BYTE_ARRAY) .setParameter(1, TEST_BYTE_ARRAY)
@ -374,8 +379,8 @@ public class StoredProcedureParameterTypeTest extends BaseNonConfigCoreFunctiona
@Test @Test
@TestForIssue( jiraKey = "HHH-12661" ) @TestForIssue( jiraKey = "HHH-12661" )
public void testCharArrayTypeInParameter() { public void testCharArrayTypeInParameter(SessionFactoryScope scope) {
inTransaction( scope.inTransaction(
session -> session.createStoredProcedureQuery("test") session -> session.createStoredProcedureQuery("test")
.registerStoredProcedureParameter( 1, CharArrayType.class, ParameterMode.IN) .registerStoredProcedureParameter( 1, CharArrayType.class, ParameterMode.IN)
.setParameter(1, TEST_CHAR_ARRAY) .setParameter(1, TEST_CHAR_ARRAY)
@ -384,8 +389,8 @@ public class StoredProcedureParameterTypeTest extends BaseNonConfigCoreFunctiona
@Test @Test
@TestForIssue( jiraKey = "HHH-12661" ) @TestForIssue( jiraKey = "HHH-12661" )
public void testUUIDBinaryTypeInParameter() { public void testUUIDBinaryTypeInParameter(SessionFactoryScope scope) {
inTransaction( scope.inTransaction(
session -> session.createStoredProcedureQuery("test") session -> session.createStoredProcedureQuery("test")
.registerStoredProcedureParameter( 1, UUIDBinaryType.class, ParameterMode.IN) .registerStoredProcedureParameter( 1, UUIDBinaryType.class, ParameterMode.IN)
.setParameter( 1, UUID.randomUUID()) .setParameter( 1, UUID.randomUUID())
@ -394,8 +399,8 @@ public class StoredProcedureParameterTypeTest extends BaseNonConfigCoreFunctiona
@Test @Test
@TestForIssue(jiraKey = "HHH-12905") @TestForIssue(jiraKey = "HHH-12905")
public void testStringTypeInParameterIsNull() { public void testStringTypeInParameterIsNull(SessionFactoryScope scope) {
inTransaction( scope.inTransaction(
session -> { session -> {
ProcedureCall procedureCall = session.createStoredProcedureCall( "test" ); ProcedureCall procedureCall = session.createStoredProcedureCall( "test" );
procedureCall.registerParameter( 1, StringType.class, ParameterMode.IN ).enablePassingNulls( true ); procedureCall.registerParameter( 1, StringType.class, ParameterMode.IN ).enablePassingNulls( true );
@ -406,8 +411,8 @@ public class StoredProcedureParameterTypeTest extends BaseNonConfigCoreFunctiona
@Test @Test
@TestForIssue(jiraKey = "HHH-12905") @TestForIssue(jiraKey = "HHH-12905")
public void testStringTypeInParameterIsNullWithoutEnablePassingNulls() { public void testStringTypeInParameterIsNullWithoutEnablePassingNulls(SessionFactoryScope scope) {
inTransaction( scope.inTransaction(
session -> { session -> {
try { try {
ProcedureCall procedureCall = session.createStoredProcedureCall( "test" ); 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();
}
}