Index: lams_tool_nb/test/java/org/lamsfoundation/lams/tool/noticeboard/service/TestNoticeboardServicePOJO.java =================================================================== diff -u -r7bcfa73cac3014829779e4dc4b029573421e21ab -r14e4648edfb90ace995634a421388ed3e82a2931 --- lams_tool_nb/test/java/org/lamsfoundation/lams/tool/noticeboard/service/TestNoticeboardServicePOJO.java (.../TestNoticeboardServicePOJO.java) (revision 7bcfa73cac3014829779e4dc4b029573421e21ab) +++ lams_tool_nb/test/java/org/lamsfoundation/lams/tool/noticeboard/service/TestNoticeboardServicePOJO.java (.../TestNoticeboardServicePOJO.java) (revision 14e4648edfb90ace995634a421388ed3e82a2931) @@ -79,16 +79,7 @@ * Methods for access to NoticeboardContent objects * ============================================================================== */ - public void testRetrieveNoticeboardByUID() - { - nbContent = nbService.retrieveNoticeboard(TEST_NB_ID); - Long uid = nbContent.getUid(); - - NoticeboardContent testObject = nbService.retrieveNoticeboardByUID(uid); - assertContentEqualsTestData(testObject); - } - public void testRetrieveNoticeboard() { nbContent = nbService.retrieveNoticeboard(TEST_NB_ID); @@ -186,15 +177,6 @@ assertEqualsForSessionContent(nbSession); } - public void testRetrieveNoticeboardSessionByUID() - { - nbSession = nbService.retrieveNoticeboardSession(TEST_SESSION_ID); - Long uid = nbSession.getUid(); - - NoticeboardSession testSession = nbService.retrieveNoticeboardSessionByUID(uid); - - assertEqualsForSessionContent(testSession); - } public void testSaveNoticeboardSession() { @@ -210,11 +192,10 @@ nbContent, created, NoticeboardSession.NOT_ATTEMPTED); - - nbService.saveNoticeboardSession(nbSession); + nbService.addSession(testContentId, nbSession); - NoticeboardSession retrievedSession = nbService.retrieveNoticeboardSession(testSessionId); + NoticeboardSession retrievedSession = nbService.retrieveNoticeboardSession(testSessionId); assertEquals(retrievedSession.getNbContent().getNbContentId(), testContentId); assertEquals(retrievedSession.getSessionStartDate(), created); @@ -258,17 +239,6 @@ } - public void testRemoveSessionByUID() - { - nbSession = nbService.retrieveNoticeboardSession(TEST_SESSION_ID); - Long uid = nbSession.getUid(); - - nbService.removeSessionByUID(uid); - - assertSessionObjectIsNull(TEST_SESSION_ID); - - } - public void testRemoveNoticeboardUsersFromSession() { nbSession = nbService.retrieveNoticeboardSession(TEST_SESSION_ID); @@ -291,12 +261,6 @@ assertEqualsForNbUser(nbUser); } - public void testRetrieveNoticeboardUserByUID() - { - nbUser = nbService.retrieveNoticeboardUserByUID(new Long(1)); - - assertEqualsForDefaultNbUser(nbUser); - } public void testSaveNoticeboardUser() { @@ -343,6 +307,29 @@ assertUserObjectIsNull(TEST_USER_ID); } + + public void testAddSession() + { + Long toolSessionId = new Long(99); + NoticeboardSession newSession = new NoticeboardSession(toolSessionId); + nbService.addSession(TEST_NB_ID, newSession); + + NoticeboardSession session = nbService.retrieveNoticeboardSession(toolSessionId); + assertEquals(session.getNbContent().getNbContentId(), TEST_NB_ID); + + } + + public void testAddUser() + { + Long userId = new Long(88); + NoticeboardUser newUser = new NoticeboardUser(userId); + nbService.addUser(TEST_SESSION_ID, newUser); + + NoticeboardUser user = nbService.retrieveNoticeboardUser(userId); + assertEquals(user.getNbSession().getNbSessionId(), TEST_SESSION_ID); + } + + } \ No newline at end of file Index: lams_tool_nb/test/java/org/lamsfoundation/lams/tool/noticeboard/service/TestToolContentManager.java =================================================================== diff -u -r7bcfa73cac3014829779e4dc4b029573421e21ab -r14e4648edfb90ace995634a421388ed3e82a2931 --- lams_tool_nb/test/java/org/lamsfoundation/lams/tool/noticeboard/service/TestToolContentManager.java (.../TestToolContentManager.java) (revision 7bcfa73cac3014829779e4dc4b029573421e21ab) +++ lams_tool_nb/test/java/org/lamsfoundation/lams/tool/noticeboard/service/TestToolContentManager.java (.../TestToolContentManager.java) (revision 14e4648edfb90ace995634a421388ed3e82a2931) @@ -28,9 +28,12 @@ import org.lamsfoundation.lams.tool.noticeboard.NbDataAccessTestCase; import org.lamsfoundation.lams.tool.ToolContentManager; import org.lamsfoundation.lams.tool.noticeboard.service.INoticeboardService; +import org.lamsfoundation.lams.tool.exception.ToolException; +import org.lamsfoundation.lams.tool.exception.DataMissingException; +import org.lamsfoundation.lams.tool.exception.SessionDataExistsException; +import org.lamsfoundation.lams.tool.noticeboard.NoticeboardConstants; - /** * @author mtruong * @@ -55,6 +58,8 @@ { super.setUp(); //setup some data + this.nbContent = null; + this.nbSession = null; nbContentManager = (ToolContentManager)this.context.getBean("nbService"); nbService = (INoticeboardService)this.context.getBean("nbService"); this.initNbContentData(); @@ -77,8 +82,10 @@ super.cleanNbContentData(TEST_COPYNB_ID); } } - - public void testcopyToolContent() + /* + * Normal Use case + */ + public void testcopyToolContent() throws ToolException { //ensure that the copied data is deleted after use cleanCopyContent = true; @@ -91,33 +98,268 @@ assertEquals(nbContent.getNbContentId(), TEST_COPYNB_ID); assertContentEqualsTestData(nbContent); + } + + /* + * Error case: toContentId not supplied + */ + + public void testCopyToolContentWithToContentIdNull() throws ToolException + { + cleanCopyContent = true; + try + { + nbContentManager.copyToolContent(TEST_NB_ID, null); + fail("A ToolException should have been raised as toContentId is missing"); + } + catch(ToolException e) + { + assertTrue(true); + } } - public void testsetAsDefineLater() + /* + * Alternative case: the fromContentId supplied is null, default content is used. + */ + public void testCopyToolContentWithFromContentIdNull() throws ToolException { - nbContentManager.setAsDefineLater(TEST_NB_ID); + cleanCopyContent = true; + try + { + nbContentManager.copyToolContent(null, TEST_COPYNB_ID); + + nbContent = nbService.retrieveNoticeboard(TEST_COPYNB_ID); + assertEquals(nbContent.getNbContentId(), TEST_COPYNB_ID); + assertContentEqualsDefaultData(nbContent); + + + } + catch(ToolException e) + { + assertFalse(false); //an exception should not have been thrown since default content is there + } + } + + /* + * Alternative case: the fromContentId supplied does not exist in the db, default content is used. + */ + public void testCopyToolContentWithInvalidFromContentId() throws ToolException + { + cleanCopyContent = true; + try + { + nbContentManager.copyToolContent(new Long(76), TEST_COPYNB_ID); + + nbContent = nbService.retrieveNoticeboard(TEST_COPYNB_ID); + assertEquals(nbContent.getNbContentId(), TEST_COPYNB_ID); + assertContentEqualsDefaultData(nbContent); + } + catch(ToolException e) + { + assertFalse(true); //an exception should not have been thrown since default content is there + } + } + + /* + * Error case: Default content is missing, throws DataMissingException + */ + public void testCopyToolContentWithDefaultContentMissing() throws ToolException + { + // cleanCopyContent = true; + + //remove the default content so it will trigger the exception + nbService.removeNoticeboard(NoticeboardConstants.DEFAULT_CONTENT_ID); + + try + { + nbContentManager.copyToolContent(null, TEST_COPYNB_ID); + fail("A ToolException should have been raised as the fromContentId is missing" + + " and default content is missing."); + + } + catch(ToolException e) + { + assertTrue(true); //an exception should not have been thrown since default content is there + } + + this.restoreDefaultContent(); + } + + /* + * Normal case: + */ + + public void testSetAsDefineLater() throws ToolException, DataMissingException + { + nbContentManager.setAsDefineLater(TEST_NB_ID); nbContent = nbService.retrieveNoticeboard(TEST_NB_ID); assertTrue(nbContent.isDefineLater()); } - public void testsetAsRunOffline() + /* + * Error case: supplied parameter toolContentId is null, ToolException is thrown + */ + public void testSetAsDefineLaterWithIdNull() throws ToolException, DataMissingException { + try + { + nbContentManager.setAsDefineLater(null); + fail("A ToolException should have been raised as the toolContentId is null"); + } + catch(ToolException e) + { + assertTrue(true); + } + } + + /* + * Error case: The tool content is missing for the supplied toolContentId, throws DataMissingException + */ + public void testSetAsDefineLaterWithInvalidId() throws ToolException, DataMissingException + { + try + { + Long idWithNoContent = new Long(8767); + nbContentManager.setAsDefineLater(idWithNoContent); + fail("A ToolException should have been raised as the tool content is missing for the supplied toolContentId: "+idWithNoContent); + } + catch(DataMissingException e) + { + assertTrue(true); + } + } + + /* + * Normal case for: setAsRunOffline(Long toolContentId) + */ + + public void testsetAsRunOffline() throws DataMissingException, ToolException + { nbContentManager.setAsRunOffline(TEST_NB_ID); nbContent = nbService.retrieveNoticeboard(TEST_NB_ID); assertTrue(nbContent.isForceOffline()); } - public void testremoveToolContent() + /* + * Error case: supplied parameter toolContentId is null, ToolException is thrown + */ + public void testSetAsRunOfflineWithIdNull() throws ToolException, DataMissingException { - cleanContentData = false; - nbContentManager.removeToolContent(TEST_NB_ID); - - nbContent = nbService.retrieveNoticeboard(TEST_NB_ID); - assertNull(nbContent); + try + { + nbContentManager.setAsRunOffline(null); + fail("A ToolException should have been raised as the toolContentId is null"); + } + catch(ToolException e) + { + assertTrue(true); + } + } + /* + * Error case: The tool content is missing for the supplied toolContentId, throws DataMissingException + */ + public void testSetAsRunOfflineWithInvalidId() throws ToolException, DataMissingException + { + try + { + Long idWithNoContent = new Long(8767); + nbContentManager.setAsRunOffline(idWithNoContent); + fail("A ToolException should have been raised as the tool content is missing for the supplied toolContentId: "+idWithNoContent); + } + catch(DataMissingException e) + { + assertTrue(true); + } } + /* + * Normal case: + * @author mtruong + */ + public void testRemoveToolContent() throws ToolException, SessionDataExistsException + { + cleanContentData = false; + + nbContentManager.removeToolContent(TEST_NB_ID, true); + nbContent = nbService.retrieveNoticeboard(TEST_NB_ID); + assertNull(nbContent); + } + + /* + * Error case: toolContentId is null, throws ToolException + */ + public void testRemoveToolContentWithIdNull() throws ToolException, SessionDataExistsException + { + cleanContentData = true; + try + { + nbContentManager.removeToolContent(null, true); + fail("An exception should be raised as the supplied toolContentId is null"); + } + catch (ToolException e) + { + assertTrue(true); + } + } + + /* + * Error case: toolContentId is invalid (no content is defined for that id), throws DataMissingException + */ + public void testRemoveToolContentWithInvalidId() throws ToolException, SessionDataExistsException + { + cleanContentData = true; + try + { + Long nonExistentId = new Long(89879); + nbContentManager.removeToolContent(nonExistentId, true); + fail("An exception should be raised as the supplied toolContentId does not have content data"); + } + catch (DataMissingException e) + { + assertTrue(true); + } + } + + /* + * Exception case: session data exists, and removeSessionData flag is set to false, throws SessionDataExistsException + */ + + public void testRemoveToolContentWithFlagSetToFalseAndSessionDataExists() throws ToolException, SessionDataExistsException + { + cleanContentData = true; + try + { + nbContentManager.removeToolContent(TEST_NB_ID, false); + fail("An exception should be raised as session data exists, but removeSessionData is false. Cannot Continue to remove tool content"); + } + catch(SessionDataExistsException e) + { + assertTrue(true); + } + } + + /* + * Alternative case: the flag removeSessionData=false, but no session data exists, return without throwing exception + */ + public void testRemoveToolContentWithFlagSetToFalseAndNoSessionData() throws ToolException, SessionDataExistsException + { + cleanContentData = false; + + //remove session data + nbContent = nbService.retrieveNoticeboard(TEST_NB_ID); + nbContent.getNbSessions().clear(); + nbService.updateNoticeboard(nbContent); + + nbContentManager.removeToolContent(TEST_NB_ID, false); + + nbContent = nbService.retrieveNoticeboard(TEST_NB_ID); + assertNull(nbContent); + + } + + } Index: lams_tool_nb/test/java/org/lamsfoundation/lams/tool/noticeboard/service/TestToolSessionManager.java =================================================================== diff -u --- lams_tool_nb/test/java/org/lamsfoundation/lams/tool/noticeboard/service/TestToolSessionManager.java (revision 0) +++ lams_tool_nb/test/java/org/lamsfoundation/lams/tool/noticeboard/service/TestToolSessionManager.java (revision 14e4648edfb90ace995634a421388ed3e82a2931) @@ -0,0 +1,229 @@ +/* + *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 + */ + + +/* + * Created on Jul 8, 2005 + * + * TODO To change the template for this generated file go to + * Window - Preferences - Java - Code Style - Code Templates + */ +package org.lamsfoundation.lams.tool.noticeboard.service; +import org.lamsfoundation.lams.tool.noticeboard.NbDataAccessTestCase; +import org.lamsfoundation.lams.tool.ToolSessionManager; +import org.lamsfoundation.lams.tool.noticeboard.service.INoticeboardService; +import org.lamsfoundation.lams.tool.exception.ToolException; +import org.lamsfoundation.lams.tool.exception.DataMissingException; +import org.lamsfoundation.lams.tool.exception.SessionDataExistsException; + +import org.lamsfoundation.lams.tool.noticeboard.NoticeboardConstants; + +/** + * @author mtruong + * + */ +public class TestToolSessionManager extends NbDataAccessTestCase { + + private ToolSessionManager nbSessionManager = null; + private INoticeboardService nbService = null; + private boolean cleanContentData = true; + private static final Long NEW_SESSION_ID = new Long(3400); + + public TestToolSessionManager(String name) + { + super(name); + } + + protected void setUp() throws Exception + { + super.setUp(); + //setup some data + this.nbContent = null; + this.nbSession = null; + nbSessionManager = (ToolSessionManager)this.context.getBean("nbService"); + nbService = (INoticeboardService)this.context.getBean("nbService"); + this.initNbContentData(); + this.initNbSessionContent(); + } + + protected void tearDown() throws Exception + { + super.tearDown(); + + //delete data + if(cleanContentData) + { + super.cleanNbContentData(TEST_NB_ID); + } + + + } + + /* Normal case: with valid toolSessionId and toolContentId */ + + public void testCreateToolSession() throws ToolException + { + try + { + nbSessionManager.createToolSession(NEW_SESSION_ID, TEST_NB_ID); + + nbSession = nbService.retrieveNoticeboardSession(NEW_SESSION_ID); + + assertEquals(nbSession.getNbSessionId(), NEW_SESSION_ID); + assertEquals(nbSession.getNbContent().getNbContentId(), TEST_NB_ID); + + } + catch (ToolException e) + { + fail("An exception should not have been thrown"); + assertTrue(false); + } + + } + + /* + * Error case: the supplied toolSessionId is null + */ + public void testCreateToolSessionWithNullSessionId() throws ToolException + { + try + { + nbSessionManager.createToolSession(null, TEST_NB_ID); + fail("An exception should be raised as the toolSessionId is null"); + } + catch(ToolException e) + { + assertTrue(true); + } + } + + /* + * Error case: the supplied toolContentId is null + */ + public void testCreateToolSessionWithNullContentId() throws ToolException + { + try + { + nbSessionManager.createToolSession(NEW_SESSION_ID, null); + fail("An exception should be raised as the toolContentId is null"); + } + catch(ToolException e) + { + assertTrue(true); + } + } + + /* + * Alternative case: the supplied toolSessionId is invalid (has no content) + */ + + public void testCreateToolSessionWithInvalidContentId() throws ToolException + { + Long invalidId = new Long(8968); + try + { + nbSessionManager.createToolSession(NEW_SESSION_ID, invalidId); + + nbSession = nbService.retrieveNoticeboardSession(NEW_SESSION_ID); + + assertEquals("validating session id:", nbSession.getNbSessionId(), NEW_SESSION_ID); + assertEquals("Validating content Id:", nbSession.getNbContent().getNbContentId(), DEFAULT_CONTENT_ID); + assertContentEqualsDefaultData(nbSession.getNbContent()); + } + catch (ToolException e) + { + fail("An exception should not have been thrown"); + assertTrue(false); + } + } + /* + * Error case: the default content is missing, throws ToolException + */ + + public void testCreateToolSessionDefaultContentMissing() throws ToolException + { + nbService.removeNoticeboard(DEFAULT_CONTENT_ID); + + try + { + nbSessionManager.createToolSession(NEW_SESSION_ID, null); + fail("An exception should be raised since the toolContentId" + + "is null and the defaultContent is missing"); + } + catch (ToolException e) + { + assertTrue(true); + } + + this.restoreDefaultContent(); + } + + /* + * Normal case: + */ + public void testRemoveToolSession() throws ToolException, DataMissingException + { + try + { + nbSessionManager.removeToolSession(TEST_SESSION_ID); + + nbSession = nbService.retrieveNoticeboardSession(TEST_SESSION_ID); + assertNull(nbSession); + } + catch(DataMissingException e) + { + fail("An exception should not have been thrown"); + assertTrue(false); + } + catch(ToolException e) + { + fail("An exception should not have been thrown"); + assertTrue(false); + } + } + + public void testRemoveToolSessionWithSessionIdNull() throws ToolException, DataMissingException + { + try + { + nbSessionManager.removeToolSession(null); + fail("An exception should have been raised as the session id is null"); + } + catch(ToolException e) + { + assertTrue(true); + } + } + + public void testRemoveToolSessionWithInvalidId() throws ToolException, DataMissingException//no session data + { + try + { + Long invalidId = new Long(878); + nbSessionManager.removeToolSession(invalidId); + fail("An exception should have been raised as there is no corresponding session data"); + } + catch(DataMissingException e) + { + assertTrue(true); + } + } +}