Created
July 25, 2012 17:00
-
-
Save doubledouble/3177263 to your computer and use it in GitHub Desktop.
This file contains 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
package com.iteye.common.test; | |
import junit.framework.TestCase; | |
import org.hibernate.FlushMode; | |
import org.hibernate.Session; | |
import org.hibernate.SessionFactory; | |
import org.springframework.context.ApplicationContext; | |
import org.springframework.context.support.ClassPathXmlApplicationContext; | |
import org.springframework.orm.hibernate3.SessionFactoryUtils; | |
import org.springframework.orm.hibernate3.SessionHolder; | |
import org.springframework.transaction.support.TransactionSynchronizationManager; | |
public abstract class AbstractTestBean extends TestCase { | |
protected ApplicationContext applicationContext; | |
private SessionFactory sessionFactory; | |
private Session session; | |
protected void setUp() throws Exception { | |
String configFile = "spring/*.xml"; | |
applicationContext = new ClassPathXmlApplicationContext(configFile); | |
sessionFactory = (SessionFactory) applicationContext.getBean("sessionFactory"); | |
session = SessionFactoryUtils.getSession(sessionFactory, true); | |
session.setFlushMode(FlushMode.NEVER); | |
TransactionSynchronizationManager.bindResource(sessionFactory, new SessionHolder(session)); | |
} | |
protected void tearDown() throws Exception { | |
TransactionSynchronizationManager.unbindResource(sessionFactory); | |
SessionFactoryUtils.releaseSession(session, sessionFactory); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment