Index: lams_common/.classpath =================================================================== RCS file: /usr/local/cvsroot/lams_common/.classpath,v diff -u -r1.1 -r1.2 --- lams_common/.classpath 13 Dec 2004 02:58:54 -0000 1.1 +++ lams_common/.classpath 4 Feb 2005 06:13:37 -0000 1.2 @@ -57,12 +57,16 @@ - - + + + + + + Index: lams_common/build.xml =================================================================== RCS file: /usr/local/cvsroot/lams_common/build.xml,v diff -u -r1.14 -r1.15 --- lams_common/build.xml 3 Feb 2005 01:19:26 -0000 1.14 +++ lams_common/build.xml 4 Feb 2005 06:13:37 -0000 1.15 @@ -158,6 +158,7 @@ + @@ -180,6 +181,20 @@ + + + + + + + + + + + + + + @@ -331,6 +346,41 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Index: lams_common/properties.xml =================================================================== RCS file: /usr/local/cvsroot/lams_common/Attic/properties.xml,v diff -u -r1.7 -r1.8 --- lams_common/properties.xml 28 Jan 2005 04:22:16 -0000 1.7 +++ lams_common/properties.xml 4 Feb 2005 06:14:09 -0000 1.8 @@ -17,6 +17,7 @@ + @@ -33,6 +34,7 @@ + @@ -41,6 +43,9 @@ + + + Index: lams_common/test/java/org/lamsfoundation/lams/AbstractLamsCommonTestCase.java =================================================================== RCS file: /usr/local/cvsroot/lams_common/test/java/org/lamsfoundation/lams/Attic/AbstractLamsCommonTestCase.java,v diff -u -r1.2 -r1.3 --- lams_common/test/java/org/lamsfoundation/lams/AbstractLamsCommonTestCase.java 4 Feb 2005 04:21:13 -0000 1.2 +++ lams_common/test/java/org/lamsfoundation/lams/AbstractLamsCommonTestCase.java 4 Feb 2005 06:13:37 -0000 1.3 @@ -11,6 +11,7 @@ import junit.framework.TestCase; +import net.sf.hibernate.HibernateException; import net.sf.hibernate.Session; import net.sf.hibernate.SessionFactory; @@ -45,21 +46,35 @@ { super.setUp(); ac = new ClassPathXmlApplicationContext(getContextConfigLocation()); - //hold the hibernate session - SessionFactory sessionFactory = (SessionFactory) this.ac.getBean("coreSessionFactory"); - Session s = sessionFactory.openSession(); - TransactionSynchronizationManager.bindResource(sessionFactory, new SessionHolder(s)); - + initializeHibernateSession(); } - protected abstract String[] getContextConfigLocation(); + protected abstract String[] getContextConfigLocation(); /** * @see TestCase#tearDown() */ protected void tearDown() throws Exception { super.tearDown(); + finalizeHibernateSession(); + } + + /** + * @throws HibernateException + */ + protected void initializeHibernateSession() throws HibernateException + { + //hold the hibernate session + SessionFactory sessionFactory = (SessionFactory) this.ac.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.ac.getBean("coreSessionFactory"); SessionHolder holder = (SessionHolder)TransactionSynchronizationManager.getResource(sessionFactory); @@ -70,4 +85,15 @@ SessionFactoryUtils.closeSessionIfNecessary(s, sessionFactory); } } + + protected Session getSession() + { + SessionFactory sessionFactory = (SessionFactory)this.ac.getBean("coreSessionFactory"); + SessionHolder holder = (SessionHolder)TransactionSynchronizationManager.getResource(sessionFactory); + if (holder != null) + return holder.getSession(); + else + return null; + + } } Fisheye: Tag 1.2 refers to a dead (removed) revision in file `lams_common/test/java/org/lamsfoundation/lams/BaseTestCase.java'. Fisheye: No comparison available. Pass `N' to diff? Index: lams_common/test/java/org/lamsfoundation/lams/lesson/LessonDataAccessTestCase.java =================================================================== RCS file: /usr/local/cvsroot/lams_common/test/java/org/lamsfoundation/lams/lesson/Attic/LessonDataAccessTestCase.java,v diff -u -r1.3 -r1.4 --- lams_common/test/java/org/lamsfoundation/lams/lesson/LessonDataAccessTestCase.java 4 Feb 2005 04:21:13 -0000 1.3 +++ lams_common/test/java/org/lamsfoundation/lams/lesson/LessonDataAccessTestCase.java 4 Feb 2005 06:13:37 -0000 1.4 @@ -15,6 +15,8 @@ import junit.framework.TestCase; +import net.sf.hibernate.HibernateException; + import org.lamsfoundation.lams.AbstractLamsCommonTestCase; import org.lamsfoundation.lams.learningdesign.Group; import org.lamsfoundation.lams.learningdesign.Grouping; @@ -127,9 +129,10 @@ * * We have to creat lesson class before create group due to the not null * field(grouping_id) in the group object. + * @throws HibernateException * */ - protected void initializeTestLesson() + protected void initializeTestLesson() throws HibernateException { this.initLessonClassData(); lessonClassDao.saveLessonClass(this.testLessonClass); @@ -139,6 +142,8 @@ this.initLessonData(); lessonDao.saveLesson(testLesson); + + super.getSession().flush(); } /** @@ -148,12 +153,21 @@ * groups collection * @param lesson the lesson needs to be removed. */ - protected void cleanUpTestLesson(Lesson lesson) + protected void cleanUpLesson(Lesson lesson) { lesson.getLessonClass().getGroups().clear(); lessonDao.deleteLesson(lesson); } + protected void cleanUpTestLesson() throws HibernateException + { + super.initializeHibernateSession(); + + Lesson lesson = lessonDao.getLesson(this.testLesson.getLessonId()); + this.cleanUpLesson(lesson); + + super.finalizeHibernateSession(); + } /** * Create a lesson class with empty group information. */ Index: lams_common/test/java/org/lamsfoundation/lams/lesson/lessonApplicationContext.xml =================================================================== RCS file: /usr/local/cvsroot/lams_common/test/java/org/lamsfoundation/lams/lesson/Attic/lessonApplicationContext.xml,v diff -u -r1.2 -r1.3 --- lams_common/test/java/org/lamsfoundation/lams/lesson/lessonApplicationContext.xml 3 Feb 2005 06:21:12 -0000 1.2 +++ lams_common/test/java/org/lamsfoundation/lams/lesson/lessonApplicationContext.xml 4 Feb 2005 06:13:37 -0000 1.3 @@ -72,7 +72,7 @@ net.sf.hibernate.dialect.MySQLDialect - true + false 5 20 1800 Index: lams_common/test/java/org/lamsfoundation/lams/lesson/dao/TestCleanUpLesson.java =================================================================== RCS file: /usr/local/cvsroot/lams_common/test/java/org/lamsfoundation/lams/lesson/dao/Attic/TestCleanUpLesson.java,v diff -u -r1.1 -r1.2 --- lams_common/test/java/org/lamsfoundation/lams/lesson/dao/TestCleanUpLesson.java 4 Feb 2005 04:21:13 -0000 1.1 +++ lams_common/test/java/org/lamsfoundation/lams/lesson/dao/TestCleanUpLesson.java 4 Feb 2005 06:13:37 -0000 1.2 @@ -55,7 +55,7 @@ for(Iterator i = lessons.iterator();i.hasNext();) { Lesson curLesson = (Lesson)i.next(); - super.cleanUpTestLesson(curLesson); + super.cleanUpLesson(curLesson); } List cleanedLessons = lessonDao.getAllLessons(); assertEquals("There should be a lesson in the db",0,cleanedLessons.size()); Index: lams_common/test/java/org/lamsfoundation/lams/lesson/dao/TestInitLesson.java =================================================================== RCS file: /usr/local/cvsroot/lams_common/test/java/org/lamsfoundation/lams/lesson/dao/Attic/TestInitLesson.java,v diff -u -r1.2 -r1.3 --- lams_common/test/java/org/lamsfoundation/lams/lesson/dao/TestInitLesson.java 4 Feb 2005 04:21:13 -0000 1.2 +++ lams_common/test/java/org/lamsfoundation/lams/lesson/dao/TestInitLesson.java 4 Feb 2005 06:13:37 -0000 1.3 @@ -9,6 +9,8 @@ package org.lamsfoundation.lams.lesson.dao; +import net.sf.hibernate.HibernateException; + import org.lamsfoundation.lams.lesson.LessonDataAccessTestCase; @@ -46,7 +48,7 @@ super(arg0); } - public void testInitLesson() + public void testInitLesson() throws HibernateException { super.initializeTestLesson(); //checking initialization result of lesson class Index: lams_common/test/java/org/lamsfoundation/lams/lesson/dao/TestLessonDAO.java =================================================================== RCS file: /usr/local/cvsroot/lams_common/test/java/org/lamsfoundation/lams/lesson/dao/Attic/TestLessonDAO.java,v diff -u -r1.1 -r1.2 --- lams_common/test/java/org/lamsfoundation/lams/lesson/dao/TestLessonDAO.java 2 Feb 2005 06:10:04 -0000 1.1 +++ lams_common/test/java/org/lamsfoundation/lams/lesson/dao/TestLessonDAO.java 4 Feb 2005 06:13:37 -0000 1.2 @@ -9,6 +9,9 @@ package org.lamsfoundation.lams.lesson.dao; +import org.lamsfoundation.lams.lesson.Lesson; +import org.lamsfoundation.lams.lesson.LessonDataAccessTestCase; + import junit.framework.TestCase; @@ -17,7 +20,39 @@ * @author Jacky Fang 2/02/2005 * */ -public class TestLessonDAO extends TestCase +public class TestLessonDAO extends LessonDataAccessTestCase { - + + /** + * @param name + */ + public TestLessonDAO(String name) + { + super(name); + } + /** + * @see TestCase#setUp() + */ + protected void setUp() throws Exception + { + super.setUp(); + super.initializeTestLesson(); + } + /** + * @see TestCase#tearDown() + */ + protected void tearDown() throws Exception + { + super.tearDown(); + super.cleanUpTestLesson(); + } + + public void testGetLessonWithEagerlyFetchedProgress() + { + Lesson createdLesson = this.lessonDao.getLessonWithEagerlyFetchedProgress(this.testLesson.getLessonId()); + + super.assertLessonClass(); + super.assertLesson(); + } + }