New testing `@Jpa` annotation

This commit is contained in:
Steve Ebersole 2020-12-08 10:35:18 -06:00 committed by Andrea Boriero
parent d810970489
commit 33358df72b
60 changed files with 1067 additions and 84 deletions

View File

@ -435,7 +435,7 @@ public final class ReflectHelper {
}
}
private static boolean isStaticField(Field field) {
public static boolean isStaticField(Field field) {
return field != null && ( field.getModifiers() & Modifier.STATIC ) == Modifier.STATIC;
}

View File

@ -30,6 +30,7 @@ import org.hibernate.testing.orm.junit.ServiceRegistry;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryProducer;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.hibernate.testing.orm.junit.Setting;
import org.junit.jupiter.api.Test;
@ -44,7 +45,7 @@ import org.junit.jupiter.api.Test;
)
@ServiceRegistry(
settings = {
@ServiceRegistry.Setting(name = AvailableSettings.HBM2DDL_DATABASE_ACTION, value = "create-drop")
@Setting(name = AvailableSettings.HBM2DDL_DATABASE_ACTION, value = "create-drop")
}
)
@SessionFactory

View File

@ -11,13 +11,14 @@ import org.hibernate.cfg.AvailableSettings;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.orm.junit.ServiceRegistry;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.hibernate.testing.orm.junit.Setting;
import org.junit.jupiter.api.Test;
/**
* @author Gail Badner
*/
@ServiceRegistry(settings = {
@ServiceRegistry.Setting(name = AvailableSettings.IMPLICIT_NAMING_STRATEGY, value = "org.hibernate.orm.test.annotations.collectionelement.MyImprovedNamingStrategy")
@Setting(name = AvailableSettings.IMPLICIT_NAMING_STRATEGY, value = "org.hibernate.orm.test.annotations.collectionelement.MyImprovedNamingStrategy")
})
public class CustomImprovedNamingCollectionElementTest extends ImprovedNamingCollectionElementTest {

View File

@ -24,6 +24,7 @@ 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.hibernate.test.annotations.Country;
import org.junit.jupiter.api.Test;
@ -53,7 +54,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
)
@SessionFactory
@ServiceRegistry(settings = {
@ServiceRegistry.Setting(name = AvailableSettings.IMPLICIT_NAMING_STRATEGY, value = "legacy-hbm")
@Setting(name = AvailableSettings.IMPLICIT_NAMING_STRATEGY, value = "legacy-hbm")
})
public class DefaultNamingCollectionElementTest {

View File

@ -11,6 +11,7 @@ import org.hibernate.cfg.AvailableSettings;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.orm.junit.ServiceRegistry;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.hibernate.testing.orm.junit.Setting;
import org.junit.jupiter.api.Test;
/**
@ -20,7 +21,7 @@ import org.junit.jupiter.api.Test;
* @author Gail Badner
*/
@ServiceRegistry(settings = {
@ServiceRegistry.Setting(name = AvailableSettings.IMPLICIT_NAMING_STRATEGY, value = "default")
@Setting(name = AvailableSettings.IMPLICIT_NAMING_STRATEGY, value = "default")
})
public class ImprovedNamingCollectionElementTest extends DefaultNamingCollectionElementTest {

View File

@ -16,6 +16,7 @@ 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.hibernate.testing.orm.junit.SkipForDialect;
import org.junit.jupiter.api.Test;
@ -37,7 +38,7 @@ import static org.junit.jupiter.api.Assertions.assertFalse;
}
)
@SessionFactory
@ServiceRegistry(settings = @ServiceRegistry.Setting(name = Environment.AUTO_CLOSE_SESSION, value = "true"))
@ServiceRegistry(settings = @Setting(name = Environment.AUTO_CLOSE_SESSION, value = "true"))
public class GenericsTest {
@SkipForDialect(dialectClass = AbstractHANADialect.class, matchSubTypes = true, reason = "known bug in HANA: rs.next() returns false for org.hibernate.id.enhanced.SequenceStructure$1.getNextValue() for this test")

View File

@ -14,6 +14,7 @@ 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.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@ -26,7 +27,7 @@ import static org.hamcrest.MatcherAssert.assertThat;
* @author Steve Ebersole
*/
@TestForIssue(jiraKey = "HHH-1663")
@ServiceRegistry( settings = @ServiceRegistry.Setting( name = AvailableSettings.USE_SECOND_LEVEL_CACHE, value = "false" ) )
@ServiceRegistry( settings = @Setting( name = AvailableSettings.USE_SECOND_LEVEL_CACHE, value = "false" ) )
@DomainModel( xmlMappings = "org/hibernate/orm/test/any/hbm/Person.hbm.xml" )
@SessionFactory
public class AnyTypeTest {

View File

@ -42,6 +42,7 @@ import org.hibernate.usertype.UserType;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.DomainModelScope;
import org.hibernate.testing.orm.junit.ServiceRegistry;
import org.hibernate.testing.orm.junit.Setting;
import org.junit.jupiter.api.Test;
import static org.hamcrest.CoreMatchers.is;
@ -55,7 +56,7 @@ import static org.hamcrest.Matchers.instanceOf;
* @author Steve Ebersole
*/
@ServiceRegistry(
settings = @ServiceRegistry.Setting( name = AvailableSettings.HBM2DDL_AUTO, value = "create-drop" )
settings = @Setting( name = AvailableSettings.HBM2DDL_AUTO, value = "create-drop" )
)
@DomainModel( annotatedClasses = CustomTypeResolutionTests.Person.class )
public class CustomTypeResolutionTests {

View File

@ -23,6 +23,7 @@ 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.AfterEach;
import org.junit.jupiter.api.Test;
@ -41,7 +42,7 @@ import static org.junit.Assert.assertTrue;
)
@SessionFactory(generateStatistics = true)
@ServiceRegistry(settings = {
@ServiceRegistry.Setting(name = AvailableSettings.IMPLICIT_NAMING_STRATEGY, value = "jpa")
@Setting(name = AvailableSettings.IMPLICIT_NAMING_STRATEGY, value = "jpa")
})
public class EmbeddedCheckQueryExecutedTest {

View File

@ -25,6 +25,7 @@ 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.hamcrest.CoreMatchers.is;
@ -42,8 +43,8 @@ import static org.junit.Assert.assertTrue;
)
@SessionFactory
@ServiceRegistry(settings = {
@ServiceRegistry.Setting(name = AvailableSettings.IMPLICIT_NAMING_STRATEGY, value = "jpa"),
@ServiceRegistry.Setting(name = AvailableSettings.GENERATE_STATISTICS, value = "true")
@Setting(name = AvailableSettings.IMPLICIT_NAMING_STRATEGY, value = "jpa"),
@Setting(name = AvailableSettings.GENERATE_STATISTICS, value = "true")
})
public class EmbeddedCircularFetchTests {
// todo (6.0 : this (along with the `org.hibernate.orm.test.sql.exec.onetoone.bidirectional` package)

View File

@ -28,6 +28,7 @@ import org.hibernate.testing.orm.junit.FailureExpected;
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.hibernate.test.util.SchemaUtil;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
@ -59,7 +60,7 @@ import static org.junit.Assert.assertTrue;
)
@SessionFactory
@ServiceRegistry(settings = {
@ServiceRegistry.Setting(name = AvailableSettings.IMPLICIT_NAMING_STRATEGY, value = "jpa")
@Setting(name = AvailableSettings.IMPLICIT_NAMING_STRATEGY, value = "jpa")
})
public class EmbeddedTest {

View File

@ -19,6 +19,7 @@ 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.hibernate.test.util.SchemaUtil;
import org.junit.jupiter.api.Test;
@ -41,7 +42,7 @@ import static org.junit.Assert.fail;
}
)
@ServiceRegistry(settings = {
@ServiceRegistry.Setting(name = AvailableSettings.IMPLICIT_NAMING_STRATEGY, value = "legacy-jpa")
@Setting(name = AvailableSettings.IMPLICIT_NAMING_STRATEGY, value = "legacy-jpa")
})
@SessionFactory
public class AssociationOverrideTest {

View File

@ -10,17 +10,13 @@ import org.hibernate.boot.MetadataSources;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.metamodel.mapping.AttributeMapping;
import org.hibernate.metamodel.mapping.BasicEntityIdentifierMapping;
import org.hibernate.metamodel.mapping.CompositeIdentifierMapping;
import org.hibernate.metamodel.mapping.EntityIdentifierMapping;
import org.hibernate.metamodel.mapping.internal.NonAggregatedIdentifierMappingImpl;
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.tool.schema.Action;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.ServiceRegistry;
import org.hibernate.testing.orm.junit.ServiceRegistryScope;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.Setting;
import org.junit.jupiter.api.Test;
import static org.hamcrest.CoreMatchers.instanceOf;
@ -32,7 +28,7 @@ import static org.hamcrest.MatcherAssert.assertThat;
* @author Steve Ebersole
*/
@ServiceRegistry(
settings = @ServiceRegistry.Setting( name = AvailableSettings.HBM2DDL_AUTO, value = "create-drop" )
settings = @Setting( name = AvailableSettings.HBM2DDL_AUTO, value = "create-drop" )
)
public class DynamicCompositeIdBasicTests {
@Test

View File

@ -18,6 +18,7 @@ import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.testing.orm.junit.ServiceRegistry;
import org.hibernate.testing.orm.junit.ServiceRegistryScope;
import org.hibernate.testing.orm.junit.Setting;
import org.junit.jupiter.api.Test;
import static org.hamcrest.CoreMatchers.instanceOf;
@ -33,7 +34,7 @@ import static org.hibernate.testing.transaction.TransactionUtil2.inTransaction;
* @author Steve Ebersole
*/
@ServiceRegistry(
settings = @ServiceRegistry.Setting( name = AvailableSettings.HBM2DDL_AUTO, value = "create-drop" )
settings = @Setting( name = AvailableSettings.HBM2DDL_AUTO, value = "create-drop" )
)
public class DynamicCompositeIdManyToOneTests {
@Test

View File

@ -16,6 +16,7 @@ import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.testing.orm.junit.ServiceRegistry;
import org.hibernate.testing.orm.junit.ServiceRegistryScope;
import org.hibernate.testing.orm.junit.Setting;
import org.junit.jupiter.api.Test;
import static org.hamcrest.CoreMatchers.instanceOf;
@ -27,7 +28,7 @@ import static org.hamcrest.MatcherAssert.assertThat;
* @author Steve Ebersole
*/
@ServiceRegistry(
settings = @ServiceRegistry.Setting( name = AvailableSettings.HBM2DDL_AUTO, value = "create-drop" )
settings = @Setting( name = AvailableSettings.HBM2DDL_AUTO, value = "create-drop" )
)
public class SimpleDynamicHbmTests {
@Test

View File

@ -35,6 +35,7 @@ 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.BeforeEach;
import org.junit.jupiter.api.Test;
@ -54,7 +55,7 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
@SessionFactory(statementInspectorClass = SQLStatementInspector.class)
@ServiceRegistry(
settings = {
@ServiceRegistry.Setting(
@Setting(
name = AvailableSettings.MERGE_ENTITY_COPY_OBSERVER, value = "allow"
)
}

View File

@ -16,6 +16,7 @@ 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.AfterEach;
import org.junit.jupiter.api.Test;
@ -49,7 +50,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
)
@SessionFactory
@ServiceRegistry(
settings = @ServiceRegistry.Setting(name = Environment.CHECK_NULLABILITY, value = "true")
settings = @Setting(name = Environment.CHECK_NULLABILITY, value = "true")
)
public class CascadeManagedAndTransientTest {

View File

@ -12,6 +12,7 @@ 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.AfterEach;
import org.junit.jupiter.api.Test;
@ -44,7 +45,7 @@ import org.junit.jupiter.api.Test;
)
@SessionFactory
@ServiceRegistry(
settings = @ServiceRegistry.Setting(name = Environment.CHECK_NULLABILITY, value = "true")
settings = @Setting(name = Environment.CHECK_NULLABILITY, value = "true")
)
public class CascadeMergeToChildBeforeParentTest {

View File

@ -11,6 +11,7 @@ import org.hibernate.cfg.Environment;
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.Setting;
/**
* @author Gail Badner
@ -23,9 +24,9 @@ import org.hibernate.testing.orm.junit.SessionFactory;
@SessionFactory
@ServiceRegistry(
settings = {
@ServiceRegistry.Setting(name = Environment.GENERATE_STATISTICS, value = "true"),
@ServiceRegistry.Setting(name = Environment.STATEMENT_BATCH_SIZE, value = "0"),
@ServiceRegistry.Setting(name = Environment.CHECK_NULLABILITY, value = "false")
@Setting(name = Environment.GENERATE_STATISTICS, value = "true"),
@Setting(name = Environment.STATEMENT_BATCH_SIZE, value = "0"),
@Setting(name = Environment.CHECK_NULLABILITY, value = "false")
}
)
public class MultiPathCircleCascadeCheckNullFalseDelayedInsertTest extends AbstractMultiPathCircleCascadeTest {

View File

@ -11,6 +11,7 @@ import org.hibernate.cfg.Environment;
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.Setting;
/**
* @author Gail Badner
@ -23,9 +24,9 @@ import org.hibernate.testing.orm.junit.SessionFactory;
@SessionFactory
@ServiceRegistry(
settings = {
@ServiceRegistry.Setting(name = Environment.GENERATE_STATISTICS, value = "true"),
@ServiceRegistry.Setting(name = Environment.STATEMENT_BATCH_SIZE, value = "0"),
@ServiceRegistry.Setting(name = Environment.CHECK_NULLABILITY, value = "true")
@Setting(name = Environment.GENERATE_STATISTICS, value = "true"),
@Setting(name = Environment.STATEMENT_BATCH_SIZE, value = "0"),
@Setting(name = Environment.CHECK_NULLABILITY, value = "true")
}
)
public class MultiPathCircleCascadeCheckNullTrueDelayedInsertTest extends AbstractMultiPathCircleCascadeTest {

View File

@ -11,6 +11,7 @@ import org.hibernate.cfg.Environment;
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.Setting;
/**
* @author Gail Badner
@ -23,9 +24,9 @@ import org.hibernate.testing.orm.junit.SessionFactory;
@SessionFactory
@ServiceRegistry(
settings = {
@ServiceRegistry.Setting(name = Environment.GENERATE_STATISTICS, value = "true"),
@ServiceRegistry.Setting(name = Environment.STATEMENT_BATCH_SIZE, value = "0"),
@ServiceRegistry.Setting(name = Environment.CHECK_NULLABILITY, value = "false")
@Setting(name = Environment.GENERATE_STATISTICS, value = "true"),
@Setting(name = Environment.STATEMENT_BATCH_SIZE, value = "0"),
@Setting(name = Environment.CHECK_NULLABILITY, value = "false")
}
)
public class MultiPathCircleCascadeCheckNullibilityFalseTest extends AbstractMultiPathCircleCascadeTest {

View File

@ -11,6 +11,7 @@ import org.hibernate.cfg.Environment;
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.Setting;
/**
* @author Gail Badner
@ -23,9 +24,9 @@ import org.hibernate.testing.orm.junit.SessionFactory;
@SessionFactory
@ServiceRegistry(
settings = {
@ServiceRegistry.Setting(name = Environment.GENERATE_STATISTICS, value = "true"),
@ServiceRegistry.Setting(name = Environment.STATEMENT_BATCH_SIZE, value = "0"),
@ServiceRegistry.Setting(name = Environment.CHECK_NULLABILITY, value = "true")
@Setting(name = Environment.GENERATE_STATISTICS, value = "true"),
@Setting(name = Environment.STATEMENT_BATCH_SIZE, value = "0"),
@Setting(name = Environment.CHECK_NULLABILITY, value = "true")
}
)
public class MultiPathCircleCascadeCheckNullibilityTrueTest extends AbstractMultiPathCircleCascadeTest {

View File

@ -11,6 +11,7 @@ import org.hibernate.cfg.Environment;
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.Setting;
/**
* @author Gail Badner
@ -23,8 +24,8 @@ import org.hibernate.testing.orm.junit.SessionFactory;
@SessionFactory
@ServiceRegistry(
settings = {
@ServiceRegistry.Setting(name = Environment.GENERATE_STATISTICS, value = "true"),
@ServiceRegistry.Setting(name = Environment.STATEMENT_BATCH_SIZE, value = "0"),
@Setting(name = Environment.GENERATE_STATISTICS, value = "true"),
@Setting(name = Environment.STATEMENT_BATCH_SIZE, value = "0"),
}
)
public class MultiPathCircleCascadeDelayedInsertTest extends AbstractMultiPathCircleCascadeTest {

View File

@ -11,6 +11,7 @@ import org.hibernate.cfg.Environment;
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.Setting;
/**
* The test case uses the following model:
@ -42,8 +43,8 @@ import org.hibernate.testing.orm.junit.SessionFactory;
@SessionFactory
@ServiceRegistry(
settings = {
@ServiceRegistry.Setting(name = Environment.GENERATE_STATISTICS, value = "true"),
@ServiceRegistry.Setting(name = Environment.STATEMENT_BATCH_SIZE, value = "0"),
@Setting(name = Environment.GENERATE_STATISTICS, value = "true"),
@Setting(name = Environment.STATEMENT_BATCH_SIZE, value = "0"),
}
)
public class MultiPathCircleCascadeTest extends AbstractMultiPathCircleCascadeTest {

View File

@ -22,6 +22,7 @@ import org.hibernate.testing.orm.junit.FailureExpected;
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.junit.jupiter.api.Assertions.assertEquals;
@ -38,10 +39,10 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
@SessionFactory(generateStatistics = true)
@ServiceRegistry(
settings = {
@ServiceRegistry.Setting(
@Setting(
name = AvailableSettings.USE_SECOND_LEVEL_CACHE, value = "true"
),
@ServiceRegistry.Setting(
@Setting(
name = AvailableSettings.USE_QUERY_CACHE, value = "true"
)
}

View File

@ -34,6 +34,7 @@ import org.hibernate.testing.orm.junit.ServiceRegistry;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryProducer;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.hibernate.testing.orm.junit.Setting;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@ -52,7 +53,7 @@ import static org.hamcrest.MatcherAssert.assertThat;
@SessionFactory
@ServiceRegistry(
settings = {
@ServiceRegistry.Setting(name = AvailableSettings.HBM2DDL_DATABASE_ACTION, value = "create-drop")
@Setting(name = AvailableSettings.HBM2DDL_DATABASE_ACTION, value = "create-drop")
}
)
public class EagerToOneWithJoinFetchModeTests implements SessionFactoryProducer {

View File

@ -27,6 +27,7 @@ import org.hibernate.testing.orm.junit.ServiceRegistry;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryProducer;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.hibernate.testing.orm.junit.Setting;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@ -35,7 +36,6 @@ import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hibernate.testing.hamcrest.CollectionMatchers.hasSize;
/**
* @author Nathan Xu
@ -49,7 +49,7 @@ import static org.hibernate.testing.hamcrest.CollectionMatchers.hasSize;
@SessionFactory
@ServiceRegistry(
settings = {
@ServiceRegistry.Setting(name = AvailableSettings.HBM2DDL_DATABASE_ACTION, value = "create-drop")
@Setting(name = AvailableSettings.HBM2DDL_DATABASE_ACTION, value = "create-drop")
}
)
public class EagerToOneWithSelectFetchModeTests implements SessionFactoryProducer {

View File

@ -28,6 +28,7 @@ import org.hibernate.testing.orm.junit.ServiceRegistry;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryProducer;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.hibernate.testing.orm.junit.Setting;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@ -36,7 +37,6 @@ import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hibernate.testing.hamcrest.CollectionMatchers.hasSize;
/**
* @author Nathan Xu
@ -50,7 +50,7 @@ import static org.hibernate.testing.hamcrest.CollectionMatchers.hasSize;
@SessionFactory
@ServiceRegistry(
settings = {
@ServiceRegistry.Setting(name = AvailableSettings.HBM2DDL_DATABASE_ACTION, value = "create-drop")
@Setting(name = AvailableSettings.HBM2DDL_DATABASE_ACTION, value = "create-drop")
}
)
public class LazyToOneWithJoinFetchModeTests implements SessionFactoryProducer {

View File

@ -28,6 +28,7 @@ import org.hibernate.testing.orm.junit.ServiceRegistry;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryProducer;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.hibernate.testing.orm.junit.Setting;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@ -50,7 +51,7 @@ import static org.hibernate.testing.hamcrest.CollectionMatchers.hasSize;
@SessionFactory
@ServiceRegistry(
settings = {
@ServiceRegistry.Setting(name = AvailableSettings.HBM2DDL_DATABASE_ACTION, value = "create-drop")
@Setting(name = AvailableSettings.HBM2DDL_DATABASE_ACTION, value = "create-drop")
}
)
public class LazyToOneWithSelectFetchModeTests implements SessionFactoryProducer {

View File

@ -32,6 +32,7 @@ import org.hibernate.testing.orm.junit.FailureExpected;
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.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@ -53,7 +54,7 @@ import static org.junit.Assert.assertThat;
@SessionFactory
@ServiceRegistry(
settings = {
@ServiceRegistry.Setting( name = AvailableSettings.GENERATE_STATISTICS, value = "true" )
@Setting( name = AvailableSettings.GENERATE_STATISTICS, value = "true" )
}
)
@TestForIssue(jiraKey = "HHH-7119")

View File

@ -27,6 +27,7 @@ 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.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@ -44,7 +45,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
}
)
@SessionFactory
@ServiceRegistry(settings = @ServiceRegistry.Setting(name = AvailableSettings.FORCE_DISCRIMINATOR_IN_SELECTS_BY_DEFAULT, value = "true"))
@ServiceRegistry(settings = @Setting(name = AvailableSettings.FORCE_DISCRIMINATOR_IN_SELECTS_BY_DEFAULT, value = "true"))
public class SingleTableRelationsTest {
@BeforeEach

View File

@ -24,6 +24,7 @@ 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.junit.jupiter.api.Assertions.assertEquals;
@ -45,7 +46,7 @@ import static org.junit.jupiter.api.Assertions.fail;
@SessionFactory
@ServiceRegistry(
settings =
@ServiceRegistry.Setting(
@Setting(
name = AvailableSettings.IGNORE_EXPLICIT_DISCRIMINATOR_COLUMNS_FOR_JOINED_SUBCLASS,
value = "true"))
public class JoinedSubclassWithIgnoredExplicitDiscriminatorTest {

View File

@ -22,6 +22,7 @@ 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.junit.jupiter.api.Assertions.assertEquals;
@ -42,7 +43,7 @@ import static org.junit.jupiter.api.Assertions.fail;
@SessionFactory
@ServiceRegistry(
settings =
@ServiceRegistry.Setting(
@Setting(
name = AvailableSettings.IMPLICIT_DISCRIMINATOR_COLUMNS_FOR_JOINED_SUBCLASS,
value = "true"))
public class JoinedSubclassWithImplicitDiscriminatorTest {

View File

@ -19,6 +19,7 @@ import org.hibernate.testing.orm.junit.ServiceRegistry;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryProducer;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.hibernate.testing.orm.junit.Setting;
import org.junit.jupiter.api.Test;
import static org.hamcrest.CoreMatchers.is;
@ -36,7 +37,7 @@ import static org.junit.Assert.assertThat;
)
@ServiceRegistry(
settings = {
@ServiceRegistry.Setting(name = AvailableSettings.HBM2DDL_DATABASE_ACTION, value = "create-drop")
@Setting(name = AvailableSettings.HBM2DDL_DATABASE_ACTION, value = "create-drop")
}
)
@SessionFactory

View File

@ -15,6 +15,7 @@ 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.BeforeEach;
import org.junit.jupiter.api.Test;
@ -35,19 +36,19 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
@SessionFactory
@ServiceRegistry(
settings = {
@ServiceRegistry.Setting(
@Setting(
name = Environment.ENABLE_LAZY_LOAD_NO_TRANS, value = "true"
),
@ServiceRegistry.Setting(
@Setting(
name = AvailableSettings.JTA_PLATFORM, value = "org.hibernate.testing.jta.TestingJtaPlatformImpl"
),
@ServiceRegistry.Setting(
@Setting(
name = AvailableSettings.CONNECTION_PROVIDER, value = "org.hibernate.testing.jta.JtaAwareConnectionProviderImpl"
),
@ServiceRegistry.Setting(
@Setting(
name = "javax.persistence.transactionType", value = "JTA"
),
@ServiceRegistry.Setting(
@Setting(
name = AvailableSettings.JTA_PLATFORM, value = "Atomikos"
)
}

View File

@ -15,6 +15,7 @@ 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.BeforeEach;
import org.junit.jupiter.api.Test;
@ -35,16 +36,16 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
@SessionFactory
@ServiceRegistry(
settings = {
@ServiceRegistry.Setting(
@Setting(
name = Environment.ENABLE_LAZY_LOAD_NO_TRANS, value = "true"
),
@ServiceRegistry.Setting(
@Setting(
name = AvailableSettings.JTA_PLATFORM, value = "org.hibernate.testing.jta.TestingJtaPlatformImpl"
),
@ServiceRegistry.Setting(
@Setting(
name = AvailableSettings.CONNECTION_PROVIDER, value = "org.hibernate.testing.jta.JtaAwareConnectionProviderImpl"
),
@ServiceRegistry.Setting(
@Setting(
name = "javax.persistence.transactionType", value = "jta"
)
}

View File

@ -14,6 +14,7 @@ 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.junit.jupiter.api.Assertions.assertNotNull;
@ -30,7 +31,7 @@ import static org.junit.jupiter.api.Assertions.fail;
}
)
@SessionFactory
@ServiceRegistry(settings = @ServiceRegistry.Setting(name = Environment.ENABLE_LAZY_LOAD_NO_TRANS, value = "true"))
@ServiceRegistry(settings = @Setting(name = Environment.ENABLE_LAZY_LOAD_NO_TRANS, value = "true"))
public class LazyLoadingNotFoundTest {
@Test

View File

@ -27,6 +27,7 @@ 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.BeforeEach;
import org.junit.jupiter.api.Test;
@ -51,8 +52,8 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
@SessionFactory
@ServiceRegistry(
settings = {
@ServiceRegistry.Setting(name = Environment.ENABLE_LAZY_LOAD_NO_TRANS, value = "true"),
@ServiceRegistry.Setting(name = Environment.USE_SECOND_LEVEL_CACHE, value = "false"),
@Setting(name = Environment.ENABLE_LAZY_LOAD_NO_TRANS, value = "true"),
@Setting(name = Environment.USE_SECOND_LEVEL_CACHE, value = "false"),
}
)
public class LazyLoadingTest {

View File

@ -9,6 +9,7 @@ package org.hibernate.orm.test.lazyload;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.testing.orm.junit.ServiceRegistry;
import org.hibernate.testing.orm.junit.Setting;
import static org.junit.jupiter.api.Assertions.assertEquals;
@ -17,7 +18,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
* @author Vlad Mihalcea
*/
@ServiceRegistry(
settings = @ServiceRegistry.Setting(name = AvailableSettings.JPA_PROXY_COMPLIANCE, value = "true")
settings = @Setting(name = AvailableSettings.JPA_PROXY_COMPLIANCE, value = "true")
)
public class ManyToOneLazyLoadingByIdJpaComplianceTest extends ManyToOneLazyLoadingByIdTest {

View File

@ -36,6 +36,7 @@ import org.hibernate.testing.orm.junit.ServiceRegistry;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryProducer;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.hibernate.testing.orm.junit.Setting;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
@ -56,9 +57,9 @@ import static org.junit.Assert.assertTrue;
@SuppressWarnings("WeakerAccess")
@ServiceRegistry(
settings = {
@ServiceRegistry.Setting( name = AvailableSettings.USE_SECOND_LEVEL_CACHE, value = "true" ),
@ServiceRegistry.Setting( name = AvailableSettings.GENERATE_STATISTICS, value = "true" ),
@ServiceRegistry.Setting( name = AvailableSettings.HBM2DDL_DATABASE_ACTION, value = "create-drop" )
@Setting( name = AvailableSettings.USE_SECOND_LEVEL_CACHE, value = "true" ),
@Setting( name = AvailableSettings.GENERATE_STATISTICS, value = "true" ),
@Setting( name = AvailableSettings.HBM2DDL_DATABASE_ACTION, value = "create-drop" )
}
)
@DomainModel(

View File

@ -28,6 +28,7 @@ import org.hibernate.testing.orm.junit.ServiceRegistry;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryProducer;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.hibernate.testing.orm.junit.Setting;
import org.junit.Assert;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
@ -52,8 +53,8 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
@SessionFactory
@ServiceRegistry(
settings = {
@ServiceRegistry.Setting( name = AvailableSettings.GENERATE_STATISTICS, value = "true" ),
@ServiceRegistry.Setting( name = AvailableSettings.HBM2DDL_DATABASE_ACTION, value = "create-drop" )
@Setting( name = AvailableSettings.GENERATE_STATISTICS, value = "true" ),
@Setting( name = AvailableSettings.HBM2DDL_DATABASE_ACTION, value = "create-drop" )
}
)
public class OneToManyBidirectionalTest implements SessionFactoryProducer {

View File

@ -13,6 +13,7 @@ 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.orm.test.query.sqm.BaseSqmUnitTest.interpretSelect;
@ -25,7 +26,7 @@ import static org.hibernate.orm.test.query.sqm.BaseSqmUnitTest.interpretSelect;
standardModels = StandardDomainModel.GAMBIT
)
@ServiceRegistry(
settings = @ServiceRegistry.Setting(
settings = @Setting(
name = AvailableSettings.HBM2DDL_AUTO,
value = "create-drop"
)

View File

@ -20,6 +20,7 @@ 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.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
@ -39,7 +40,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
*/
@ServiceRegistry(
settings = {
@ServiceRegistry.Setting( name = AvailableSettings.USE_QUERY_CACHE, value = "true" )
@Setting( name = AvailableSettings.USE_QUERY_CACHE, value = "true" )
}
)
@DomainModel( annotatedClasses = { TestEntity.class, AggregateEntity.class } )

View File

@ -23,6 +23,7 @@ import org.hibernate.testing.orm.domain.gambit.EntityOfBasics;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.ServiceRegistry;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.hibernate.testing.orm.junit.Setting;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@ -49,7 +50,7 @@ import static org.hamcrest.Matchers.notNullValue;
)
@ServiceRegistry(
settings = {
@ServiceRegistry.Setting(
@Setting(
name = AvailableSettings.JDBC_TIME_ZONE,
value = "UTC"
)

View File

@ -42,6 +42,7 @@ 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.hamcrest.CoreMatchers.equalTo;
@ -59,7 +60,7 @@ import static org.hamcrest.MatcherAssert.assertThat;
annotatedClasses = SimpleEntity.class
)
@ServiceRegistry(
settings = @ServiceRegistry.Setting(
settings = @Setting(
name = AvailableSettings.HBM2DDL_AUTO,
value = "create-drop"
)

View File

@ -23,8 +23,6 @@ import javax.persistence.Table;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.internal.util.collections.CollectionHelper;
import org.hibernate.orm.test.metamodel.mapping.SmokeTests.OtherEntity;
import org.hibernate.orm.test.metamodel.mapping.SmokeTests.SimpleEntity;
import org.hibernate.query.Query;
import org.hibernate.query.spi.QueryImplementor;
import org.hibernate.stat.spi.StatisticsImplementor;
@ -34,6 +32,7 @@ import org.hibernate.testing.orm.junit.FailureExpected;
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.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@ -59,8 +58,8 @@ import static org.hamcrest.MatcherAssert.assertThat;
)
@ServiceRegistry(
settings = {
@ServiceRegistry.Setting(name = AvailableSettings.POOL_SIZE, value = "15"),
@ServiceRegistry.Setting(name = AvailableSettings.USE_SECOND_LEVEL_CACHE, value = "false")
@Setting(name = AvailableSettings.POOL_SIZE, value = "15"),
@Setting(name = AvailableSettings.USE_SECOND_LEVEL_CACHE, value = "false")
}
)
@SessionFactory(exportSchema = true)

View File

@ -20,6 +20,11 @@ public abstract class AbstractDomainModelDescriptor implements DomainModelDescri
this.annotatedClasses = annotatedClasses;
}
@Override
public Class[] getAnnotatedClasses() {
return annotatedClasses;
}
@Override
public void applyDomainModel(MetadataSources sources) {
for ( Class annotatedClass : annotatedClasses ) {

View File

@ -23,6 +23,8 @@ import org.hibernate.dialect.Dialect;
*/
public interface DomainModelDescriptor {
Class[] getAnnotatedClasses();
/**
* Apply the model classes to the given MetadataSources
*/

View File

@ -0,0 +1,156 @@
/*
* 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.testing.orm.jpa;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Properties;
import javax.persistence.SharedCacheMode;
import javax.persistence.ValidationMode;
import javax.persistence.spi.ClassTransformer;
import javax.persistence.spi.PersistenceUnitInfo;
import javax.persistence.spi.PersistenceUnitTransactionType;
import javax.sql.DataSource;
import org.hibernate.jpa.HibernatePersistenceProvider;
/**
* @author Steve Ebersole
*/
public class PersistenceUnitInfoImpl implements PersistenceUnitInfo {
private final String name;
private final Properties properties = new Properties();
private PersistenceUnitTransactionType transactionType;
private SharedCacheMode cacheMode;
private ValidationMode validationMode;
private List<String> mappingFiles;
private List<String> managedClassNames;
private boolean excludeUnlistedClasses;
public PersistenceUnitInfoImpl(String name) {
this.name = name;
}
@Override
public String getPersistenceUnitName() {
return name;
}
@Override
public Properties getProperties() {
return properties;
}
@Override
public String getPersistenceProviderClassName() {
return HibernatePersistenceProvider.class.getName();
}
@Override
public PersistenceUnitTransactionType getTransactionType() {
return transactionType;
}
public void setTransactionType(PersistenceUnitTransactionType transactionType) {
this.transactionType = transactionType;
}
@Override
public SharedCacheMode getSharedCacheMode() {
return cacheMode;
}
public void setCacheMode(SharedCacheMode cacheMode) {
this.cacheMode = cacheMode;
}
@Override
public ValidationMode getValidationMode() {
return validationMode;
}
public void setValidationMode(ValidationMode validationMode) {
this.validationMode = validationMode;
}
@Override
public List<String> getMappingFileNames() {
return mappingFiles == null ? Collections.emptyList() : mappingFiles;
}
public void applyMappingFiles(String... mappingFiles) {
if ( this.mappingFiles == null ) {
this.mappingFiles = new ArrayList<>();
}
Collections.addAll( this.mappingFiles, mappingFiles );
}
@Override
public List<String> getManagedClassNames() {
return managedClassNames == null ? Collections.emptyList() : managedClassNames;
}
public void applyManagedClassNames(String... managedClassNames) {
if ( this.managedClassNames == null ) {
this.managedClassNames = new ArrayList<>();
}
Collections.addAll( this.managedClassNames, managedClassNames );
}
@Override
public boolean excludeUnlistedClasses() {
return excludeUnlistedClasses;
}
public void setExcludeUnlistedClasses(boolean excludeUnlistedClasses) {
this.excludeUnlistedClasses = excludeUnlistedClasses;
}
@Override
public String getPersistenceXMLSchemaVersion() {
return null;
}
@Override
public DataSource getJtaDataSource() {
return null;
}
@Override
public DataSource getNonJtaDataSource() {
return null;
}
@Override
public List<URL> getJarFileUrls() {
return null;
}
@Override
public URL getPersistenceUnitRootUrl() {
return null;
}
@Override
public ClassLoader getClassLoader() {
return null;
}
@Override
public void addTransformer(ClassTransformer transformer) {
}
@Override
public ClassLoader getNewTempClassLoader() {
return null;
}
}

View File

@ -0,0 +1,467 @@
/*
* 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.testing.orm.junit;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.Function;
import javax.persistence.EntityManager;
import javax.persistence.spi.PersistenceUnitInfo;
import org.hibernate.SessionFactoryObserver;
import org.hibernate.Transaction;
import org.hibernate.boot.registry.StandardServiceRegistry;
import org.hibernate.boot.spi.MetadataImplementor;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.internal.util.ReflectHelper;
import org.hibernate.jpa.boot.internal.PersistenceUnitInfoDescriptor;
import org.hibernate.jpa.boot.spi.Bootstrap;
import org.hibernate.jpa.boot.spi.EntityManagerFactoryBuilder;
import org.hibernate.resource.jdbc.spi.StatementInspector;
import org.hibernate.tool.schema.Action;
import org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator;
import org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.ActionGrouping;
import org.hibernate.testing.orm.domain.DomainModelDescriptor;
import org.hibernate.testing.orm.domain.StandardDomainModel;
import org.hibernate.testing.orm.jpa.PersistenceUnitInfoImpl;
import org.junit.jupiter.api.extension.AfterAllCallback;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.api.extension.TestExecutionExceptionHandler;
import org.junit.jupiter.api.extension.TestInstancePostProcessor;
import org.junit.platform.commons.support.AnnotationSupport;
import org.jboss.logging.Logger;
/**
* hibernate-testing implementation of a few JUnit5 contracts to support SessionFactory-based testing,
* including argument injection (or see {@link SessionFactoryScopeAware})
*
* @see SessionFactoryScope
* @see DomainModelExtension
*
* @author Steve Ebersole
*/
public class EntityManagerFactoryExtension
implements TestInstancePostProcessor, AfterAllCallback, TestExecutionExceptionHandler {
private static final Logger log = Logger.getLogger( EntityManagerFactoryExtension.class );
private static final String EMF_KEY = EntityManagerFactoryScope .class.getName();
private static ExtensionContext.Store locateExtensionStore(Object testInstance, ExtensionContext context) {
return JUnitHelper.locateExtensionStore( EntityManagerFactoryExtension.class, context, testInstance );
}
@SuppressWarnings("WeakerAccess")
public static EntityManagerFactoryScope findEntityManagerFactoryScope(Object testInstance, ExtensionContext context) {
final ExtensionContext.Store store = locateExtensionStore( testInstance, context );
final EntityManagerFactoryScope existing = (EntityManagerFactoryScope ) store.get( EMF_KEY );
if ( existing != null ) {
return existing;
}
if ( !context.getElement().isPresent() ) {
throw new RuntimeException( "Unable to determine how to handle given ExtensionContext : " + context.getDisplayName() );
}
final Optional<Jpa> emfAnnWrapper = AnnotationSupport.findAnnotation(
context.getElement().get(),
Jpa.class
);
final Jpa emfAnn = emfAnnWrapper.orElseThrow( () -> new RuntimeException( "Could not locate @EntityManagerFactory" ) );
final PersistenceUnitInfoImpl pui = new PersistenceUnitInfoImpl( emfAnn.persistenceUnitName() );
pui.setTransactionType( emfAnn.transactionType() );
pui.setCacheMode( emfAnn.sharedCacheMode() );
pui.setValidationMode( emfAnn.validationMode() );
pui.setExcludeUnlistedClasses( emfAnn.excludeUnlistedClasses() );
final Setting[] properties = emfAnn.properties();
for ( int i = 0; i < properties.length; i++ ) {
final Setting property = properties[ i ];
pui.getProperties().setProperty( property.name(), property.value() );
}
pui.getProperties().setProperty( AvailableSettings.GENERATE_STATISTICS, Boolean.toString( emfAnn.generateStatistics() ) );
if ( emfAnn.exportSchema() ) {
pui.getProperties().setProperty( AvailableSettings.HBM2DDL_DATABASE_ACTION, Action.CREATE_DROP.getExternalHbm2ddlName() );
}
if ( emfAnn.annotatedPackageNames().length > 0 ) {
pui.applyManagedClassNames( emfAnn.annotatedPackageNames() );
}
if ( emfAnn.annotatedClassNames().length > 0 ) {
pui.applyManagedClassNames( emfAnn.annotatedClassNames() );
}
if ( emfAnn.annotatedClasses().length > 0 ) {
for ( int i = 0; i < emfAnn.annotatedClasses().length; i++ ) {
pui.applyManagedClassNames( emfAnn.annotatedClasses()[i].getName() );
}
}
if ( emfAnn.xmlMappings().length > 0 ) {
pui.applyMappingFiles( emfAnn.xmlMappings() );
}
if ( emfAnn.standardModels().length > 0 ) {
for ( int i = 0; i < emfAnn.standardModels().length; i++ ) {
final StandardDomainModel standardDomainModel = emfAnn.standardModels()[ i ];
for ( int i1 = 0; i1 < standardDomainModel.getDescriptor().getAnnotatedClasses().length; i1++ ) {
final Class<?> annotatedClass = standardDomainModel.getDescriptor().getAnnotatedClasses()[ i1 ];
pui.applyManagedClassNames( annotatedClass.getName() );
}
}
}
if ( emfAnn.modelDescriptorClasses().length > 0 ) {
for ( int i = 0; i < emfAnn.modelDescriptorClasses().length; i++ ) {
final Class<? extends DomainModelDescriptor> modelDescriptorClass = emfAnn.modelDescriptorClasses()[ i ];
final DomainModelDescriptor domainModelDescriptor = instantiateDomainModelDescriptor( modelDescriptorClass );
for ( int i1 = 0; i1 < domainModelDescriptor.getAnnotatedClasses().length; i1++ ) {
final Class<?> annotatedClass = domainModelDescriptor.getAnnotatedClasses()[ i1 ];
pui.applyManagedClassNames( annotatedClass.getName() );
}
}
}
final Map<String,String> integrationSettings = new HashMap<>();
for ( int i = 0; i < emfAnn.integrationSettings().length; i++ ) {
final Setting setting = emfAnn.integrationSettings()[ i ];
integrationSettings.put( setting.name(), setting.value() );
}
final EntityManagerFactoryScopeImpl scope = new EntityManagerFactoryScopeImpl( pui, integrationSettings );
locateExtensionStore( testInstance, context ).put( EMF_KEY, scope );
return scope;
}
private static DomainModelDescriptor instantiateDomainModelDescriptor(Class<? extends DomainModelDescriptor> modelDescriptorClass) {
// first, see if it has a static singleton reference and use that if so
try {
final Field[] declaredFields = modelDescriptorClass.getDeclaredFields();
for ( int i = 0; i < declaredFields.length; i++ ) {
final Field field = declaredFields[ i ];
if ( ReflectHelper.isStaticField( field ) ) {
final Object value = field.get( null );
if ( value instanceof DomainModelDescriptor ) {
return (DomainModelDescriptor) value;
}
}
}
}
catch (IllegalAccessException e) {
throw new RuntimeException( "Problem accessing DomainModelDescriptor fields : " + modelDescriptorClass.getName(), e );
}
// no singleton field, try to instantiate it via reflection
try {
return modelDescriptorClass.getConstructor( null ).newInstance( null );
}
catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
throw new RuntimeException( "Problem instantiation DomainModelDescriptor : " + modelDescriptorClass.getName(), e );
}
}
private static void prepareSchemaExport(
SessionFactoryImplementor sessionFactory,
MetadataImplementor model) {
final Map<String, Object> baseProperties = sessionFactory.getProperties();
final ActionGrouping actions = ActionGrouping.interpret( baseProperties );
// if there are explicit setting for auto schema tooling then skip the annotation
if ( actions.getDatabaseAction() != Action.NONE || actions.getScriptAction() != Action.NONE ) {
// the properties contained explicit settings for auto schema tooling - skip the annotation
return;
}
final HashMap settings = new HashMap<>( baseProperties );
//noinspection unchecked
settings.put( AvailableSettings.HBM2DDL_DATABASE_ACTION, Action.CREATE_DROP );
final StandardServiceRegistry serviceRegistry = model.getMetadataBuildingOptions().getServiceRegistry();
SchemaManagementToolCoordinator.process(
model,
serviceRegistry,
settings,
action -> sessionFactory.addObserver(
new SessionFactoryObserver() {
@Override
public void sessionFactoryClosing(org.hibernate.SessionFactory factory) {
action.perform( serviceRegistry );
}
}
)
);
}
@Override
public void postProcessTestInstance(Object testInstance, ExtensionContext context) {
log.tracef( "#postProcessTestInstance(%s, %s)", testInstance, context.getDisplayName() );
findEntityManagerFactoryScope( testInstance, context );
}
@Override
public void afterAll(ExtensionContext context) {
log.tracef( "#afterAll(%s)", context.getDisplayName() );
final Object testInstance = context.getRequiredTestInstance();
if ( testInstance instanceof SessionFactoryScopeAware ) {
( (SessionFactoryScopeAware) testInstance ).injectSessionFactoryScope( null );
}
final EntityManagerFactoryScopeImpl removed = (EntityManagerFactoryScopeImpl) locateExtensionStore( testInstance, context ).remove( EMF_KEY );
if ( removed != null ) {
removed.close();
}
}
@Override
public void handleTestExecutionException(ExtensionContext context, Throwable throwable) throws Throwable {
log.tracef( "#handleTestExecutionException(%s, %s)", context.getDisplayName(), throwable );
try {
final Object testInstance = context.getRequiredTestInstance();
final ExtensionContext.Store store = locateExtensionStore( testInstance, context );
final EntityManagerFactoryScopeImpl scope = (EntityManagerFactoryScopeImpl) store.get( EMF_KEY );
scope.releaseEntityManagerFactory();
}
catch (Exception ignore) {
}
throw throwable;
}
private static class EntityManagerFactoryScopeImpl implements EntityManagerFactoryScope, ExtensionContext.Store.CloseableResource {
private final PersistenceUnitInfo persistenceUnitInfo;
private final Map<String,String> integrationSettings;
private javax.persistence.EntityManagerFactory emf;
private boolean active = true;
private EntityManagerFactoryScopeImpl(
PersistenceUnitInfo persistenceUnitInfo,
Map<String,String> integrationSettings) {
this.persistenceUnitInfo = persistenceUnitInfo;
this.integrationSettings = integrationSettings;
this.emf = createEntityManagerFactory();
}
@Override
public javax.persistence.EntityManagerFactory getEntityManagerFactory() {
if ( emf == null ) {
emf = createEntityManagerFactory();
}
return emf;
}
@Override
public StatementInspector getStatementInspector() {
return getEntityManagerFactory().unwrap( SessionFactoryImplementor.class ).getSessionFactoryOptions().getStatementInspector();
}
@Override
public void close() {
if ( ! active ) {
return;
}
log.debug( "Closing SessionFactoryScope" );
active = false;
releaseEntityManagerFactory();
}
public void releaseEntityManagerFactory() {
if ( emf != null ) {
log.debug( "Releasing SessionFactory" );
try {
emf.close();
}
catch (Exception e) {
log.warn( "Error closing EMF", e );
}
finally {
emf = null;
}
}
}
private javax.persistence.EntityManagerFactory createEntityManagerFactory() {
if ( ! active ) {
throw new IllegalStateException( "EntityManagerFactoryScope is no longer active" );
}
log.debug( "Creating EntityManagerFactory" );
final EntityManagerFactoryBuilder emfBuilder = Bootstrap.getEntityManagerFactoryBuilder(
new PersistenceUnitInfoDescriptor( persistenceUnitInfo ),
integrationSettings
);
return emfBuilder.build();
}
@Override
public void inEntityManager(Consumer<EntityManager> action) {
log.trace( "#inEntityManager(Consumer)" );
try (SessionImplementor session = getEntityManagerFactory().createEntityManager().unwrap( SessionImplementor.class ) ) {
log.trace( "EntityManager opened, calling action" );
action.accept( session );
}
finally {
log.trace( "EntityManager close - auto-close block" );
}
}
@Override
public <T> T fromEntityManager(Function<EntityManager, T> action) {
log.trace( "#fromEntityManager(Function)" );
try (SessionImplementor session = getEntityManagerFactory().createEntityManager().unwrap( SessionImplementor.class ) ) {
log.trace( "EntityManager opened, calling action" );
return action.apply( session );
}
finally {
log.trace( "EntityManager close - auto-close block" );
}
}
@Override
public void inTransaction(Consumer<EntityManager> action) {
log.trace( "#inTransaction(Consumer)" );
try (SessionImplementor session = getEntityManagerFactory().createEntityManager().unwrap( SessionImplementor.class ) ) {
log.trace( "EntityManager opened, calling action" );
inTransaction( session, action );
}
finally {
log.trace( "EntityManager close - auto-close block" );
}
}
@Override
public <T> T fromTransaction(Function<EntityManager, T> action) {
log.trace( "#fromTransaction(Function)" );
try (SessionImplementor session = getEntityManagerFactory().createEntityManager().unwrap( SessionImplementor.class ) ) {
log.trace( "EntityManager opened, calling action" );
return fromTransaction( session, action );
}
finally {
log.trace( "EntityManager close - auto-close block" );
}
}
@Override
public void inTransaction(EntityManager entityManager, Consumer<EntityManager> action) {
log.trace( "inTransaction(EntityManager,Consumer)" );
final SessionImplementor session = entityManager.unwrap( SessionImplementor.class );
final Transaction txn = session.beginTransaction();
log.trace( "Started transaction" );
try {
log.trace( "Calling action in txn" );
action.accept( session );
log.trace( "Called action - in txn" );
if ( !txn.getRollbackOnly() ) {
log.trace( "Committing transaction" );
txn.commit();
log.trace( "Committed transaction" );
}
else {
try {
log.trace( "Rollback transaction marked for rollback only" );
txn.rollback();
}
catch (Exception e) {
log.error( "Rollback failure", e );
}
}
}
catch (Exception e) {
log.tracef(
"Error calling action: %s (%s) - rolling back",
e.getClass().getName(),
e.getMessage()
);
try {
txn.rollback();
}
catch (Exception ignore) {
log.trace( "Was unable to roll back transaction" );
// really nothing else we can do here - the attempt to
// rollback already failed and there is nothing else
// to clean up.
}
throw e;
}
}
@Override
public <T> T fromTransaction(EntityManager entityManager, Function<EntityManager,T> action) {
log.trace( "fromTransaction(EntityManager,Function)" );
final SessionImplementor session = entityManager.unwrap( SessionImplementor.class );
final Transaction txn = session.beginTransaction();
log.trace( "Started transaction" );
try {
log.trace( "Calling action in txn" );
final T result = action.apply( session );
log.trace( "Called action - in txn" );
log.trace( "Committing transaction" );
txn.commit();
log.trace( "Committed transaction" );
return result;
}
catch (Exception e) {
log.tracef(
"Error calling action: %s (%s) - rolling back",
e.getClass().getName(),
e.getMessage()
);
try {
txn.rollback();
}
catch (Exception ignore) {
log.trace( "Was unable to roll back transaction" );
// really nothing else we can do here - the attempt to
// rollback already failed and there is nothing else
// to clean up.
}
throw e;
}
}
}
}

View File

@ -0,0 +1,49 @@
/*
* 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.testing.orm.junit;
import javax.persistence.EntityManagerFactory;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.api.extension.ParameterContext;
import org.junit.jupiter.api.extension.ParameterResolutionException;
import org.junit.jupiter.api.extension.ParameterResolver;
import static org.hibernate.testing.orm.junit.EntityManagerFactoryExtension.findEntityManagerFactoryScope;
/**
* @author Steve Ebersole
*/
public class EntityManagerFactoryParameterResolver implements ParameterResolver {
@Override
public boolean supportsParameter(
ParameterContext parameterContext,
ExtensionContext extensionContext) throws ParameterResolutionException {
return JUnitHelper.supportsParameterInjection(
parameterContext,
EntityManagerFactory.class,
EntityManagerFactoryScope.class
);
}
@Override
public Object resolveParameter(
ParameterContext parameterContext,
ExtensionContext extensionContext) throws ParameterResolutionException {
final EntityManagerFactoryScope scope = findEntityManagerFactoryScope(
extensionContext.getRequiredTestInstance(),
extensionContext
);
if ( EntityManagerFactoryScope.class.isAssignableFrom( parameterContext.getParameter().getType() ) ) {
return scope;
}
assert EntityManagerFactory.class.isAssignableFrom( parameterContext.getParameter().getType() );
return scope.getEntityManagerFactory();
}
}

View File

@ -0,0 +1,32 @@
/*
* 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.testing.orm.junit;
import java.util.Map;
import javax.persistence.EntityManagerFactory;
import org.hibernate.jpa.boot.spi.PersistenceUnitDescriptor;
/**
* Contract for something that can build a SessionFactory.
*
* Used by SessionFactoryScopeExtension to create the
* SessionFactoryScope.
*
* Generally speaking, a test class would implement SessionFactoryScopeContainer
* and return the SessionFactoryProducer to be used for those tests.
* The SessionFactoryProducer is then used to build the SessionFactoryScope
* which is injected back into the SessionFactoryScopeContainer
*
* @see EntityManagerFactoryExtension
* @see EntityManagerFactoryScope
*
* @author Steve Ebersole
*/
public interface EntityManagerFactoryProducer {
EntityManagerFactory produceEntityManagerFactory(PersistenceUnitDescriptor persistenceUnitDescriptor, Map<String,String> integrationSettings);
}

View File

@ -0,0 +1,30 @@
/*
* 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.testing.orm.junit;
import java.util.function.Consumer;
import java.util.function.Function;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import org.hibernate.resource.jdbc.spi.StatementInspector;
/**
* @author Steve Ebersole
*/
public interface EntityManagerFactoryScope {
EntityManagerFactory getEntityManagerFactory();
StatementInspector getStatementInspector();
void inEntityManager(Consumer<EntityManager> action);
void inTransaction(Consumer<EntityManager> action);
void inTransaction(EntityManager entityManager, Consumer<EntityManager> action);
<T> T fromEntityManager(Function<EntityManager, T> action);
<T> T fromTransaction(Function<EntityManager, T> action);
<T> T fromTransaction(EntityManager entityManager, Function<EntityManager, T> action);
}

View File

@ -0,0 +1,70 @@
/*
* 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.testing.orm.junit;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import javax.persistence.SharedCacheMode;
import javax.persistence.ValidationMode;
import javax.persistence.spi.PersistenceUnitTransactionType;
import org.hibernate.testing.orm.domain.DomainModelDescriptor;
import org.hibernate.testing.orm.domain.StandardDomainModel;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.extension.ExtendWith;
/**
* @author Steve Ebersole
*/
@Inherited
@Target( ElementType.TYPE )
@Retention( RetentionPolicy.RUNTIME )
@TestInstance( TestInstance.Lifecycle.PER_CLASS )
@ExtendWith( EntityManagerFactoryExtension.class )
@ExtendWith( EntityManagerFactoryParameterResolver.class )
@ExtendWith( FailureExpectedExtension.class )
public @interface Jpa {
/**
* Used to mimic container integration
*/
Setting[] integrationSettings() default {};
String persistenceUnitName() default "test-pu";
// todo : multiple persistence units?
/**
* Persistence unit properties
*/
Setting[] properties() default {};
boolean generateStatistics() default false;
boolean exportSchema() default true;
PersistenceUnitTransactionType transactionType() default PersistenceUnitTransactionType.RESOURCE_LOCAL;
SharedCacheMode sharedCacheMode() default SharedCacheMode.UNSPECIFIED;
ValidationMode validationMode() default ValidationMode.NONE;
boolean excludeUnlistedClasses() default false;
StandardDomainModel[] standardModels() default {};
Class<? extends DomainModelDescriptor>[] modelDescriptorClasses() default {};
Class[] annotatedClasses() default {};
String[] annotatedClassNames() default {};
String[] annotatedPackageNames() default {};
String[] xmlMappings() default {};
}

View File

@ -88,8 +88,4 @@ public @interface ServiceRegistry {
Class<? extends org.hibernate.service.Service> impl();
}
@interface Setting {
String name();
String value();
}
}

View File

@ -112,7 +112,7 @@ public class ServiceRegistryExtension
private static void configureServices(ServiceRegistry serviceRegistryAnn, StandardServiceRegistryBuilder ssrb) {
try {
for ( ServiceRegistry.Setting setting : serviceRegistryAnn.settings() ) {
for ( Setting setting : serviceRegistryAnn.settings() ) {
ssrb.applySetting( setting.name(), setting.value() );
}

View File

@ -0,0 +1,22 @@
/*
* 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.testing.orm.junit;
/**
* A setting for use in other annotations to define settings for various things.
*/
public @interface Setting {
/**
* The setting name. Often a constant from {@link org.hibernate.cfg.AvailableSettings}
*/
String name();
/**
* The setting value
*/
String value();
}

View File

@ -0,0 +1,39 @@
/*
* 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.testing.annotations;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity( name = "AnEntity" )
@Table( name = "a_tbl" )
public class AnEntity {
@Id
private Integer id;
private String name;
public AnEntity() {
}
public AnEntity(Integer id, String name) {
this.id = id;
this.name = name;
}
public Integer getId() {
return id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}

View File

@ -0,0 +1,44 @@
/*
* 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.testing.annotations;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.testing.orm.junit.Jpa;
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
import org.hibernate.testing.orm.junit.Setting;
import org.junit.jupiter.api.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.notNullValue;
@Jpa(
annotatedClasses = {
AnEntity.class
},
properties = {
@Setting( name = AvailableSettings.JPA_JDBC_URL, value = "jdbc:h2:mem:test_db" ),
@Setting( name = AvailableSettings.JPA_JDBC_USER, value = "tester" )
}
// works with either
// integrationSettings = {
// @Setting( name = AvailableSettings.JPA_JDBC_URL, value = "jdbc:h2:mem:test_db" ),
// @Setting( name = AvailableSettings.JPA_JDBC_USER, value = "tester" )
// }
)
public class BasicEntityManagerFactoryScopeTests {
@Test
public void testBasicUsage(EntityManagerFactoryScope scope) {
assertThat( scope, notNullValue() );
assertThat( scope.getEntityManagerFactory(), notNullValue() );
// check we can use the EMF to create EMs
scope.inTransaction(
(session) -> session.createQuery( "select a from AnEntity a" ).getResultList()
);
}
}

View File

@ -0,0 +1,35 @@
/*
* 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.testing.annotations;
import org.hibernate.cfg.AvailableSettings;
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.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.notNullValue;
@ServiceRegistry( settings = @Setting( name = AvailableSettings.URL, value = "jdbc:h2:mem:test_db" ) )
@DomainModel( annotatedClasses = AnEntity.class )
@SessionFactory
public class BasicSessionFactoryScopeTests {
@Test
public void testBasicUsage(SessionFactoryScope scope) {
assertThat( scope, notNullValue() );
assertThat( scope.getSessionFactory(), notNullValue() );
// check we can use the SF to create Sessions
scope.inTransaction(
(session) -> session.createQuery( "from AnEntity" ).list()
);
}
}