Index: lams_common/src/java/org/lamsfoundation/lams/lesson/dto/LearnerProgressDTO.java =================================================================== RCS file: /usr/local/cvsroot/lams_common/src/java/org/lamsfoundation/lams/lesson/dto/LearnerProgressDTO.java,v diff -u -r1.1 -r1.2 --- lams_common/src/java/org/lamsfoundation/lams/lesson/dto/LearnerProgressDTO.java 13 Mar 2005 22:48:25 -0000 1.1 +++ lams_common/src/java/org/lamsfoundation/lams/lesson/dto/LearnerProgressDTO.java 14 Mar 2005 22:52:29 -0000 1.2 @@ -98,6 +98,14 @@ } /** + * @return Returns the attemptedActivities. + */ + public Long[] getAttemptedActivities() + { + return attemptedActivities; + } + + /** * @return Returns the completedActivities. */ public Long[] getCompletedActivities() Index: lams_common/test/java/org/lamsfoundation/lams/AbstractLamsStrutsTestCase.java =================================================================== RCS file: /usr/local/cvsroot/lams_common/test/java/org/lamsfoundation/lams/Attic/AbstractLamsStrutsTestCase.java,v diff -u -r1.1 -r1.2 --- lams_common/test/java/org/lamsfoundation/lams/AbstractLamsStrutsTestCase.java 8 Mar 2005 07:10:27 -0000 1.1 +++ lams_common/test/java/org/lamsfoundation/lams/AbstractLamsStrutsTestCase.java 14 Mar 2005 22:52:29 -0000 1.2 @@ -27,18 +27,31 @@ import junit.framework.TestCase; +import net.sf.hibernate.HibernateException; +import net.sf.hibernate.Session; +import net.sf.hibernate.SessionFactory; + +import org.springframework.orm.hibernate.SessionFactoryUtils; +import org.springframework.orm.hibernate.SessionHolder; +import org.springframework.transaction.support.TransactionSynchronizationManager; import org.springframework.web.context.ContextLoader; +import org.springframework.web.context.WebApplicationContext; +import org.springframework.web.context.support.WebApplicationContextUtils; import org.springframework.web.context.support.XmlWebApplicationContext; import servletunit.HttpServletRequestSimulator; import servletunit.struts.MockStrutsTestCase; /** + * The abstract test case that initialize the Spring context using context + * loader. It also use a session holder to simulate the + * OpenSessionInViewFilter. Without this session holder, we can + * not run integration testing with lazy loading hibernate object configured. * * @author Jacky Fang * @since 2005-3-8 - * @version + * @version 1.0 * */ public abstract class AbstractLamsStrutsTestCase extends MockStrutsTestCase @@ -47,6 +60,7 @@ private final String CONFIG_LOCATIONS; protected HttpServletRequestSimulator httpRequest; protected HttpSession httpSession ; + protected WebApplicationContext wac; /** * @param arg0 @@ -59,6 +73,9 @@ } /** + * Set up spring context and hibernate session holder into mock servlet + * context. + * * @see TestCase#setUp() */ protected void setUp() throws Exception @@ -71,15 +88,44 @@ CONFIG_LOCATIONS); ctxLoader.initWebApplicationContext(context); + wac = WebApplicationContextUtils.getRequiredWebApplicationContext(context); + initializeHibernateSession(); httpRequest = (HttpServletRequestSimulator)getRequest(); httpSession = getSession(); } - /* + /** * @see MockStrutsTestCase#tearDown() */ protected void tearDown() throws Exception { super.tearDown(); } + + /** + * @throws HibernateException + */ + protected void initializeHibernateSession() throws HibernateException + { + //hold the hibernate session + SessionFactory sessionFactory = (SessionFactory) this.wac.getBean("coreSessionFactory"); + Session s = sessionFactory.openSession(); + TransactionSynchronizationManager.bindResource(sessionFactory, new SessionHolder(s)); + } + + /** + * @throws HibernateException + */ + protected void finalizeHibernateSession() throws HibernateException + { + //clean the hibernate session + SessionFactory sessionFactory = (SessionFactory)this.wac .getBean("coreSessionFactory"); + SessionHolder holder = (SessionHolder)TransactionSynchronizationManager.getResource(sessionFactory); + if (holder != null) { + Session s = holder.getSession(); + s.flush(); + TransactionSynchronizationManager.unbindResource(sessionFactory); + SessionFactoryUtils.closeSessionIfNecessary(s, sessionFactory); + } + } }