|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.unitils.orm.common.OrmModule<org.hibernate.SessionFactory,org.hibernate.Session,org.hibernate.cfg.Configuration,HibernateSessionFactory,OrmConfig,HibernateAnnotationConfigLoader>
org.unitils.orm.hibernate.HibernateModule
public class HibernateModule
Module providing support for unit tests for code that uses Hibernate. It offers an easy way of loading hibernate SessionFactories and having them injected them into the test. It also offers a test to check whether the hibernate mapping is consistent with the structure of the database.
A HibernateSessionFactory
is created when requested and injected into all fields or methods of the test
annotated with HibernateSessionFactory
.
It is highly recommended to write a unit test that invokes HibernateUnitils.assertMappingWithDatabaseConsistent()
,
This is a very useful test that verifies whether the mapping of all your Hibernate mapped objects still corresponds
with the actual structure of the database.
Nested Class Summary | |
---|---|
protected class |
HibernateModule.HibernateTestListener
The TestListener for this module |
Nested classes/interfaces inherited from class org.unitils.orm.common.OrmModule |
---|
OrmModule.OrmTestListener |
Field Summary | |
---|---|
static String |
PROPKEY_CONFIGURATION_CLASS_NAME
|
Fields inherited from class org.unitils.orm.common.OrmModule |
---|
configuredOrmPersistenceUnitCache, ormPersistenceUnitLoader, ormSpringSupport, persistenceUnitConfigLoader |
Constructor Summary | |
---|---|
HibernateModule()
|
Method Summary | |
---|---|
void |
afterInit()
Gives the module the opportunity to performs initialization that can only work after all other modules have been initialized |
void |
assertMappingWithDatabaseConsistent(Object testObject)
Checks if the mapping of the Hibernate managed objects with the database is correct. |
protected HibernateAnnotationConfigLoader |
createOrmConfigLoader()
|
protected OrmPersistenceUnitLoader<org.hibernate.SessionFactory,org.hibernate.cfg.Configuration,OrmConfig> |
createOrmPersistenceUnitLoader()
|
protected org.hibernate.Session |
doGetActivePersistenceContext(Object testObject)
Implementations of this method must return the persistence context object that is associated with the current transaction, if any. |
protected org.hibernate.Session |
doGetPersistenceContext(Object testObject)
Implementations of this method must return a persistence context object, and must be associated with the current transaction active in unitils. |
protected void |
flushOrmPersistenceContext(org.hibernate.Session activeSession)
Flushes all pending update, using the given active persistence context |
Class<? extends org.hibernate.cfg.Configuration> |
getConfigurationObjectClass()
|
protected org.hibernate.dialect.Dialect |
getDatabaseDialect(org.hibernate.cfg.Configuration configuration)
Gets the database dialect from the given Hibernate Configuration
|
protected DataSource |
getDataSource()
|
protected String |
getOrmSpringSupportImplClassName()
|
protected Class<org.hibernate.SessionFactory> |
getPersistenceUnitClass()
|
protected Class<HibernateSessionFactory> |
getPersistenceUnitConfigAnnotationClass()
|
TestListener |
getTestListener()
Creates the test listener for this module. |
void |
init(Properties configuration)
Initializes the module with the given configuration settings. |
Methods inherited from class org.unitils.orm.common.OrmModule |
---|
flushDatabaseUpdates, getActivePersistenceContext, getConfigurationObject, getConfiguredPersistenceUnit, getDatabaseModule, getPersistenceContext, getPersistenceUnit, getPersistenceUnitConfig, initOrmSpringSupport, injectOrmPersistenceUnitIntoTestObject, isPersistenceUnitConfiguredFor, isSpringModuleEnabled |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface org.unitils.database.util.Flushable |
---|
flushDatabaseUpdates |
Field Detail |
---|
public static final String PROPKEY_CONFIGURATION_CLASS_NAME
Constructor Detail |
---|
public HibernateModule()
Method Detail |
---|
public void init(Properties configuration)
Module
init
in interface Module
init
in class OrmModule<org.hibernate.SessionFactory,org.hibernate.Session,org.hibernate.cfg.Configuration,HibernateSessionFactory,OrmConfig,HibernateAnnotationConfigLoader>
configuration
- The Unitils configuration, not nullpublic void afterInit()
Module
afterInit
in interface Module
afterInit
in class OrmModule<org.hibernate.SessionFactory,org.hibernate.Session,org.hibernate.cfg.Configuration,HibernateSessionFactory,OrmConfig,HibernateAnnotationConfigLoader>
protected HibernateAnnotationConfigLoader createOrmConfigLoader()
createOrmConfigLoader
in class OrmModule<org.hibernate.SessionFactory,org.hibernate.Session,org.hibernate.cfg.Configuration,HibernateSessionFactory,OrmConfig,HibernateAnnotationConfigLoader>
ResourceConfigLoader
that scans a test object for a persistence
unit configuration, and returns a specific subtype of OrmConfig
that wraps this configurationprotected Class<HibernateSessionFactory> getPersistenceUnitConfigAnnotationClass()
getPersistenceUnitConfigAnnotationClass
in class OrmModule<org.hibernate.SessionFactory,org.hibernate.Session,org.hibernate.cfg.Configuration,HibernateSessionFactory,OrmConfig,HibernateAnnotationConfigLoader>
protected Class<org.hibernate.SessionFactory> getPersistenceUnitClass()
getPersistenceUnitClass
in class OrmModule<org.hibernate.SessionFactory,org.hibernate.Session,org.hibernate.cfg.Configuration,HibernateSessionFactory,OrmConfig,HibernateAnnotationConfigLoader>
protected OrmPersistenceUnitLoader<org.hibernate.SessionFactory,org.hibernate.cfg.Configuration,OrmConfig> createOrmPersistenceUnitLoader()
createOrmPersistenceUnitLoader
in class OrmModule<org.hibernate.SessionFactory,org.hibernate.Session,org.hibernate.cfg.Configuration,HibernateSessionFactory,OrmConfig,HibernateAnnotationConfigLoader>
OrmPersistenceUnitLoader
that can create a new persistence unit
based on an OrmConfig
objectprotected String getOrmSpringSupportImplClassName()
getOrmSpringSupportImplClassName
in class OrmModule<org.hibernate.SessionFactory,org.hibernate.Session,org.hibernate.cfg.Configuration,HibernateSessionFactory,OrmConfig,HibernateAnnotationConfigLoader>
OrmSpringSupport
that
is used by the ORM module implementationprotected org.hibernate.Session doGetPersistenceContext(Object testObject)
OrmModule
doGetPersistenceContext
in class OrmModule<org.hibernate.SessionFactory,org.hibernate.Session,org.hibernate.cfg.Configuration,HibernateSessionFactory,OrmConfig,HibernateAnnotationConfigLoader>
testObject
- The test instance, not null
protected org.hibernate.Session doGetActivePersistenceContext(Object testObject)
OrmModule
doGetActivePersistenceContext
in class OrmModule<org.hibernate.SessionFactory,org.hibernate.Session,org.hibernate.cfg.Configuration,HibernateSessionFactory,OrmConfig,HibernateAnnotationConfigLoader>
testObject
- The test instance, not null
protected void flushOrmPersistenceContext(org.hibernate.Session activeSession)
OrmModule
flushOrmPersistenceContext
in class OrmModule<org.hibernate.SessionFactory,org.hibernate.Session,org.hibernate.cfg.Configuration,HibernateSessionFactory,OrmConfig,HibernateAnnotationConfigLoader>
activeSession
- Active persistence context, associated with the current transaction, not nullpublic void assertMappingWithDatabaseConsistent(Object testObject)
testObject
- The test instance, not nullpublic Class<? extends org.hibernate.cfg.Configuration> getConfigurationObjectClass()
org.hibernate.cfg.Configuration
that is used for configuring hibernateprotected org.hibernate.dialect.Dialect getDatabaseDialect(org.hibernate.cfg.Configuration configuration)
Configuration
- Parameters:
configuration
- The hibernate config, not null
- Returns:
- the database Dialect, not null
protected DataSource getDataSource()
public TestListener getTestListener()
Module
getTestListener
in interface Module
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |