Index: lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/persistence/Message.java =================================================================== diff -u -rbb86b2d50b113e03e7ead098db991c1ae922d99c -r640a9d5aeeb4b9794b93c5a764a9a20d4298b3d6 --- lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/persistence/Message.java (.../Message.java) (revision bb86b2d50b113e03e7ead098db991c1ae922d99c) +++ lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/persistence/Message.java (.../Message.java) (revision 640a9d5aeeb4b9794b93c5a764a9a20d4298b3d6) @@ -130,6 +130,8 @@ .append(this.uid,genericEntity.uid) .append(this.subject,genericEntity.subject) .append(this.body,genericEntity.body) + .append(this.replyNumber,genericEntity.replyNumber) + .append(this.lastReplyDate,genericEntity.lastReplyDate) .append(this.created,genericEntity.created) .append(this.updated,genericEntity.updated) .append(this.createdBy,genericEntity.createdBy) Index: lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/service/ForumService.java =================================================================== diff -u -rd3558795f19f456d9caed6ac5dafdb0a71cb0029 -r640a9d5aeeb4b9794b93c5a764a9a20d4298b3d6 --- lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/service/ForumService.java (.../ForumService.java) (revision d3558795f19f456d9caed6ac5dafdb0a71cb0029) +++ lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/service/ForumService.java (.../ForumService.java) (revision 640a9d5aeeb4b9794b93c5a764a9a20d4298b3d6) @@ -134,8 +134,7 @@ //if this message is root message, then actually, it will update itself lastReplayDate MessageSeq msgSeq = messageSeqDao.getByTopicId(message.getUid()); Message root = msgSeq.getRootMessage(); - //update last reply date for root message - root.setLastReplyDate(new Date()); + //update reply date messageDao.saveOrUpdate(root); return message; Index: lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/service/IForumService.java =================================================================== diff -u -r80eff1f58f1205ddc908f3eca5ea8706a0c444d2 -r640a9d5aeeb4b9794b93c5a764a9a20d4298b3d6 --- lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/service/IForumService.java (.../IForumService.java) (revision 80eff1f58f1205ddc908f3eca5ea8706a0c444d2) +++ lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/service/IForumService.java (.../IForumService.java) (revision 640a9d5aeeb4b9794b93c5a764a9a20d4298b3d6) @@ -5,7 +5,6 @@ import org.apache.struts.upload.FormFile; import org.lamsfoundation.lams.tool.forum.persistence.Attachment; import org.lamsfoundation.lams.tool.forum.persistence.Forum; -import org.lamsfoundation.lams.tool.forum.persistence.ForumReport; import org.lamsfoundation.lams.tool.forum.persistence.ForumToolSession; import org.lamsfoundation.lams.tool.forum.persistence.ForumUser; import org.lamsfoundation.lams.tool.forum.persistence.Message; Index: lams_tool_forum/test/java/org/lamsfoundation/lams/tool/forum/test/TestUtils.java =================================================================== diff -u --- lams_tool_forum/test/java/org/lamsfoundation/lams/tool/forum/test/TestUtils.java (revision 0) +++ lams_tool_forum/test/java/org/lamsfoundation/lams/tool/forum/test/TestUtils.java (revision 640a9d5aeeb4b9794b93c5a764a9a20d4298b3d6) @@ -0,0 +1,69 @@ +/* + *Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org) + * + *This program is free software; you can redistribute it and/or modify + *it under the terms of the GNU General Public License as published by + *the Free Software Foundation; either version 2 of the License, or + *(at your option) any later version. + * + *This program is distributed in the hope that it will be useful, + *but WITHOUT ANY WARRANTY; without even the implied warranty of + *MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + *GNU General Public License for more details. + * + *You should have received a copy of the GNU General Public License + *along with this program; if not, write to the Free Software + *Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + *USA + * + *http://www.gnu.org/licenses/gpl.txt + */ +package org.lamsfoundation.lams.tool.forum.test; + +import org.lamsfoundation.lams.tool.forum.persistence.Forum; +import org.lamsfoundation.lams.tool.forum.persistence.ForumToolSession; +import org.lamsfoundation.lams.tool.forum.persistence.ForumUser; +import org.lamsfoundation.lams.tool.forum.persistence.Message; +public class TestUtils { + + public static Forum getForumA(){ + Forum forum = new Forum(); + forum.setContentId(new Long(1)); + forum.setCreatedBy(getUserA()); + + return forum; + + } + public static ForumUser getUserA(){ + ForumUser user = new ForumUser(); + user.setFirstName("UserA"); + user.setUserId(new Long(1)); + + return user; + } + public static ForumToolSession getSessionA(){ + ForumToolSession session = new ForumToolSession(); + session.setSessionId(new Long(1)); + session.setStatus(1); + return session; + } + public static ForumToolSession getSessionB(){ + ForumToolSession session = new ForumToolSession(); + session.setSessionId(new Long(2)); + session.setStatus(2); + return session; + } + public static Message getMessageA() { + Message msg = new Message(); + msg.setBody("bodyA"); + msg.setSubject("subjectA"); + return msg; + } + public static Message getMessageB() { + Message msg = new Message(); + msg.setBody("bodyB"); + msg.setSubject("subjectB"); + return msg; + } + +} Index: lams_tool_forum/test/java/org/lamsfoundation/lams/tool/forum/test/service/ForumServiceTest.java =================================================================== diff -u -rd3558795f19f456d9caed6ac5dafdb0a71cb0029 -r640a9d5aeeb4b9794b93c5a764a9a20d4298b3d6 --- lams_tool_forum/test/java/org/lamsfoundation/lams/tool/forum/test/service/ForumServiceTest.java (.../ForumServiceTest.java) (revision d3558795f19f456d9caed6ac5dafdb0a71cb0029) +++ lams_tool_forum/test/java/org/lamsfoundation/lams/tool/forum/test/service/ForumServiceTest.java (.../ForumServiceTest.java) (revision 640a9d5aeeb4b9794b93c5a764a9a20d4298b3d6) @@ -20,38 +20,129 @@ */ package org.lamsfoundation.lams.tool.forum.test.service; +import java.util.List; + +import org.lamsfoundation.lams.tool.ToolContentManager; +import org.lamsfoundation.lams.tool.ToolSessionManager; +import org.lamsfoundation.lams.tool.exception.DataMissingException; +import org.lamsfoundation.lams.tool.exception.ToolException; import org.lamsfoundation.lams.tool.forum.persistence.Forum; +import org.lamsfoundation.lams.tool.forum.persistence.ForumToolSession; import org.lamsfoundation.lams.tool.forum.persistence.ForumUser; +import org.lamsfoundation.lams.tool.forum.persistence.Message; import org.lamsfoundation.lams.tool.forum.service.IForumService; import org.lamsfoundation.lams.tool.forum.test.BaseTest; +import org.lamsfoundation.lams.tool.forum.test.TestUtils; public class ForumServiceTest extends BaseTest{ private IForumService forumService; + private ToolContentManager contentManager; + private ToolSessionManager sessionManager; public ForumServiceTest(String name) { super(name); } public void setUp()throws Exception{ super.setUp(); forumService = (IForumService)context.getBean("forumService"); - + contentManager = (ToolContentManager) forumService; + sessionManager = (ToolSessionManager) forumService; } public void testUpdateForum(){ - ForumUser user = new ForumUser(); - user.setFirstName("Steve"); - user.setUserId(new Long(1)); + Forum forum = TestUtils.getForumA(); + ForumUser user = forum.getCreatedBy(); - Forum forum = new Forum(); - - forum.setContentId(new Long(1)); - forum.setCreatedBy(user); - forumService.updateForum(forum); - + //get back Forum tForum = forumService.getForum(new Long(1)); - assertEquals(tForum.getContentId(),new Long(1)); assertEquals(tForum.getCreatedBy(),user); } - + public void testCreateRootTopic(){ + Message msg = TestUtils.getMessageA(); + forumService.createRootTopic(new Long(1),new Long(1),msg); + Message tMsg = forumService.getMessage(msg.getUid()); + assertFalse(tMsg.getUpdated().equals(msg.getUpdated())); + tMsg.setUpdated(msg.getUpdated()); + assertEquals(tMsg,msg); + } + public void testUpdateTopic(){ + + Message msg = TestUtils.getMessageA(); + Message tMsg = forumService.updateTopic(msg); + //update date will be different + assertFalse(tMsg.getUpdated().equals(msg.getUpdated())); + tMsg.setUpdated(msg.getUpdated()); + assertEquals(tMsg,msg); + + //remove test data + forumService.deleteTopic(msg.getUid()); + } + public void testReplyTopic(){ + Message parent = TestUtils.getMessageA(); + forumService.updateTopic(parent); + + Message msg = TestUtils.getMessageB(); + ForumToolSession session = TestUtils.getSessionA(); + forumService.updateSession(session); + Message tMsg = forumService.replyTopic(parent.getUid(),session.getUid(),msg); + + //update date will be different + assertFalse(tMsg.getUpdated().equals(msg.getUpdated())); + tMsg.setUpdated(msg.getUpdated()); + assertEquals(tMsg,msg); + +// remove test data + forumService.deleteTopic(parent.getUid()); + } + public void testDeleteTopic(){ + Message parent = TestUtils.getMessageA(); + forumService.updateTopic(parent); + + Message msg = TestUtils.getMessageB(); + ForumToolSession session = TestUtils.getSessionA(); + forumService.updateSession(session); + forumService.replyTopic(parent.getUid(),session.getUid(),msg); + + //delete parent and its children. + forumService.deleteTopic(parent.getUid()); + + assertNull(forumService.getMessage(parent.getUid())); + assertNull(forumService.getMessage(msg.getUid())); + + } + public void testGetTopicThread(){ + Message parent = TestUtils.getMessageA(); + ForumToolSession sessionA = TestUtils.getSessionA(); + forumService.updateSession(sessionA); + parent.setToolSession(sessionA); + forumService.updateTopic(parent); + + Message msg = TestUtils.getMessageB(); + forumService.replyTopic(parent.getUid(),sessionA.getUid(),msg); + + List list = forumService.getRootTopics(sessionA.getUid()); + + assertEquals(list.size(),1); + assertEquals(list.get(0),parent); + + //delete parent and its children. + forumService.deleteTopic(parent.getUid()); + + } + public void testUpdateSession() throws DataMissingException, ToolException{ + ForumToolSession sessionA = TestUtils.getSessionA(); + forumService.updateSession(sessionA); + ForumToolSession session = TestUtils.getSessionA(); + assertEquals(session,sessionA); + + //remove test data. + sessionManager.removeToolSession(sessionA.getSessionId()); + } + public void testCreateUser(){ + ForumUser userA = TestUtils.getUserA(); + forumService.createUser(userA); + ForumUser user = TestUtils.getUserA(); + assertEquals(userA,user); + } }