Created
August 10, 2011 16:20
-
-
Save hferentschik/1137321 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public abstract class SearchTestCase extends TestCase { | |
... | |
protected void buildConfiguration() { | |
try { | |
setCfg( new Configuration() ); | |
configure( cfg ); | |
if ( recreateSchema() ) { | |
cfg.setProperty( org.hibernate.cfg.Environment.HBM2DDL_AUTO, "create-drop" ); | |
} | |
for ( String aPackage : getAnnotatedPackages() ) { | |
getCfg().addPackage( aPackage ); | |
} | |
for ( Class<?> aClass : getAnnotatedClasses() ) { | |
getCfg().addAnnotatedClass( aClass ); | |
} | |
for ( String xmlFile : getXmlFiles() ) { | |
InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream( xmlFile ); | |
getCfg().addInputStream( is ); | |
} | |
final ServiceRegistry serviceRegistry = new ServiceRegistryBuilder( cfg.getProperties() ).buildServiceRegistry(); | |
EventListenerRegistry registry = serviceRegistry.getService( EventListenerRegistry.class ); | |
registerCustomListeners(registry); | |
setSessions( getCfg().buildSessionFactory( serviceRegistry )); | |
} | |
catch ( HibernateException e ) { | |
e.printStackTrace(); | |
throw e; | |
} | |
catch ( SearchException e ) { | |
e.printStackTrace(); | |
throw e; | |
} | |
catch ( Exception e ) { | |
e.printStackTrace(); | |
throw new RuntimeException( e ); | |
} | |
} | |
protected void registerCustomListeners(EventListenerRegistry registry) { | |
// per default do nothing | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This should do it :