Index: lams_common/src/java/org/lamsfoundation/lams/lesson/dto/LearnerProgressDTO.java =================================================================== diff -u -rb87bb85e1a8722d63f64814929381d590ca7e633 -r6e59ce4878d3f44cf14542a284c749258f2a9039 --- lams_common/src/java/org/lamsfoundation/lams/lesson/dto/LearnerProgressDTO.java (.../LearnerProgressDTO.java) (revision b87bb85e1a8722d63f64814929381d590ca7e633) +++ lams_common/src/java/org/lamsfoundation/lams/lesson/dto/LearnerProgressDTO.java (.../LearnerProgressDTO.java) (revision 6e59ce4878d3f44cf14542a284c749258f2a9039) @@ -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 =================================================================== diff -u -r466cdc6a3d942a86899c33499fe7495d010280a5 -r6e59ce4878d3f44cf14542a284c749258f2a9039 --- lams_common/test/java/org/lamsfoundation/lams/AbstractLamsStrutsTestCase.java (.../AbstractLamsStrutsTestCase.java) (revision 466cdc6a3d942a86899c33499fe7495d010280a5) +++ lams_common/test/java/org/lamsfoundation/lams/AbstractLamsStrutsTestCase.java (.../AbstractLamsStrutsTestCase.java) (revision 6e59ce4878d3f44cf14542a284c749258f2a9039) @@ -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); + } + } }