Index: lams_tool_nb/test/java/org/lamsfoundation/lams/tool/noticeboard/dao/hibernate/TestNoticeboardAttachmentDAO.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_nb/test/java/org/lamsfoundation/lams/tool/noticeboard/dao/hibernate/Attic/TestNoticeboardAttachmentDAO.java,v diff -u -r1.3 -r1.4 --- lams_tool_nb/test/java/org/lamsfoundation/lams/tool/noticeboard/dao/hibernate/TestNoticeboardAttachmentDAO.java 11 Aug 2005 05:41:40 -0000 1.3 +++ lams_tool_nb/test/java/org/lamsfoundation/lams/tool/noticeboard/dao/hibernate/TestNoticeboardAttachmentDAO.java 23 Dec 2005 01:58:44 -0000 1.4 @@ -21,11 +21,10 @@ */ public class TestNoticeboardAttachmentDAO extends NbDataAccessTestCase { - private NoticeboardAttachmentDAO attachmentDao; - private NoticeboardContentDAO contentDao; + /* private NoticeboardAttachmentDAO attachmentDao; + private NoticeboardContentDAO contentDao; private NoticeboardAttachment nbAttachment = null; - private NoticeboardContent nbContent = null; - + private NoticeboardContent nbContent = null; */ public TestNoticeboardAttachmentDAO(String name) @@ -39,38 +38,38 @@ */ protected void setUp() throws Exception { super.setUp(); - attachmentDao = (NoticeboardAttachmentDAO)this.context.getBean("nbAttachmentDAO"); - contentDao = (NoticeboardContentDAO)this.context.getBean("nbContentDAO"); - super.initAllData(); + + initAllData(); initNbAttachmentData(); } /** * @see NbDataAccessTestCase#tearDown() */ protected void tearDown() throws Exception { - super.tearDown(); - super.cleanNbContentData(TEST_NB_ID); + + cleanNbContentData(TEST_NB_ID); } public void testRetrieveAttachment() { - //test retrieveAttachmentByUuid - nbAttachment = attachmentDao.retrieveAttachmentByUuid(TEST_UUID); + + //test retrieveAttachmentByUuid + nbAttachment = attachmentDAO.retrieveAttachmentByUuid(TEST_UUID); assertAttachmentData(nbAttachment); /* test getAttachmentsFromContent which will return a list of attachment ids, which we can use in the next method call to retrieveAttachment which takes in the attachmentId as the parameter. */ - List attachmentIds = attachmentDao.getAttachmentIdsFromContent(contentDao.findNbContentById(TEST_NB_ID)); + List attachmentIds = attachmentDAO.getAttachmentIdsFromContent(noticeboardDAO.findNbContentById(TEST_NB_ID)); //test retrieveAttachment (by attachmentId, which was retrieved from the previous method) - nbAttachment = attachmentDao.retrieveAttachment((Long)attachmentIds.get(0)); + nbAttachment = attachmentDAO.retrieveAttachment((Long)attachmentIds.get(0)); assertAttachmentData(nbAttachment); //test retrieveAttachment (by filename as the parameter - nbAttachment = attachmentDao.retrieveAttachmentByFilename(TEST_FILENAME); + nbAttachment = attachmentDAO.retrieveAttachmentByFilename(TEST_FILENAME); assertAttachmentData(nbAttachment); } @@ -79,37 +78,44 @@ public void testSaveAttachment() { String newFilename = "new filename"; - nbAttachment = attachmentDao.retrieveAttachmentByUuid(TEST_UUID); + nbAttachment = attachmentDAO.retrieveAttachmentByUuid(TEST_UUID); nbAttachment.setFilename(newFilename); - attachmentDao.saveAttachment(nbAttachment); + attachmentDAO.saveAttachment(nbAttachment); - nbAttachment = attachmentDao.retrieveAttachmentByUuid(TEST_UUID); + nbAttachment = attachmentDAO.retrieveAttachmentByUuid(TEST_UUID); assertEquals("Validating the new filename", nbAttachment.getFilename(), newFilename); } - + public void testRemoveAttachment() { - nbAttachment = attachmentDao.retrieveAttachmentByUuid(TEST_UUID); + nbAttachment = attachmentDAO.retrieveAttachmentByUuid(TEST_UUID); + //remove any associations + nbContent = noticeboardDAO.findNbContentById(TEST_NB_ID); + nbContent.getNbAttachments().remove(nbAttachment); - attachmentDao.removeAttachment(nbAttachment); + attachmentDAO.removeAttachment(nbAttachment); - nbAttachment = attachmentDao.retrieveAttachmentByUuid(TEST_UUID); + nbAttachment = attachmentDAO.retrieveAttachmentByUuid(TEST_UUID); assertNull(nbAttachment); } public void testRemoveAttachmentByUuid() { - nbAttachment = attachmentDao.retrieveAttachmentByUuid(TEST_UUID); + nbAttachment = attachmentDAO.retrieveAttachmentByUuid(TEST_UUID); assertNotNull(nbAttachment); - attachmentDao.removeAttachment(TEST_UUID); + // remove any associations + nbContent = noticeboardDAO.findNbContentById(TEST_NB_ID); + nbContent.getNbAttachments().remove(nbAttachment); - nbAttachment = attachmentDao.retrieveAttachmentByUuid(TEST_UUID); + attachmentDAO.removeAttachment(TEST_UUID); + + nbAttachment = attachmentDAO.retrieveAttachmentByUuid(TEST_UUID); assertNull(nbAttachment); - } + } Index: lams_tool_nb/test/java/org/lamsfoundation/lams/tool/noticeboard/dao/hibernate/TestNoticeboardContentDAO.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_nb/test/java/org/lamsfoundation/lams/tool/noticeboard/dao/hibernate/Attic/TestNoticeboardContentDAO.java,v diff -u -r1.5 -r1.6 --- lams_tool_nb/test/java/org/lamsfoundation/lams/tool/noticeboard/dao/hibernate/TestNoticeboardContentDAO.java 11 Aug 2005 05:41:40 -0000 1.5 +++ lams_tool_nb/test/java/org/lamsfoundation/lams/tool/noticeboard/dao/hibernate/TestNoticeboardContentDAO.java 23 Dec 2005 01:58:44 -0000 1.6 @@ -37,8 +37,6 @@ */ public class TestNoticeboardContentDAO extends NbDataAccessTestCase { - private NoticeboardContentDAO noticeboardDAO; - private NoticeboardSessionDAO nbSessionDAO; private boolean cleanContentData = true; public TestNoticeboardContentDAO(String name) @@ -51,28 +49,26 @@ */ protected void setUp() throws Exception { super.setUp(); + //set up default noticeboard content for each test - noticeboardDAO = (NoticeboardContentDAO) this.context.getBean("nbContentDAO"); - nbSessionDAO = (NoticeboardSessionDAO) this.context.getBean("nbSessionDAO"); - super.initAllData(); + initAllData(); } /** * @see NbDataAccessTestCase#tearDown() */ protected void tearDown() throws Exception - { - super.tearDown(); + { //remove noticeboard content after each test - if(cleanContentData) + if(cleanContentData) { - super.cleanNbContentData(TEST_NB_ID); + cleanNbContentData(TEST_NB_ID); } } public void testfindNbContentByID() { - nbContent = noticeboardDAO.findNbContentById(TEST_NB_ID); + nbContent = noticeboardDAO.findNbContentById(TEST_NB_ID); assertContentEqualsTestData(nbContent); @@ -82,13 +78,30 @@ Long nonExistentId = new Long(88777); assertNbContentIsNull(nonExistentId); + +// NoticeboardContent nb = new NoticeboardContent(new Long(3600), +// TEST_TITLE, +// TEST_CONTENT, +// TEST_ONLINE_INSTRUCTIONS, +// TEST_OFFLINE_INSTRUCTIONS, +// TEST_DEFINE_LATER, +// TEST_CONTENT_IN_USE, +// TEST_FORCE_OFFLINE, +// TEST_CREATOR_USER_ID, +// TEST_DATE_CREATED, +// TEST_DATE_UPDATED); +// +// noticeboardDAO.saveNbContent(nb); + + // noticeboardDAO.removeNoticeboard(new Long(3600)); + // noticeboardDAO.removeNoticeboard(noticeboardDAO.findNbContentById(new Long(3600))); + + } - - + public void testremoveNoticeboard() { - cleanContentData = false; - + cleanContentData = false; nbContent = noticeboardDAO.findNbContentById(TEST_NB_ID); @@ -97,84 +110,87 @@ assertNbSessionIsNull(TEST_SESSION_ID); //check if child table is deleted assertNbContentIsNull(TEST_NB_ID); } - - public void testremoveNoticeboardById() - { - cleanContentData = false; - + + public void testremoveNoticeboardById() + { + cleanContentData = false; + - noticeboardDAO.removeNoticeboard(TEST_NB_ID); - - assertNbSessionIsNull(TEST_SESSION_ID); - assertNbContentIsNull(TEST_NB_ID); - } - - - public void testgetNbContentBySession() - { - nbContent = noticeboardDAO.getNbContentBySession(TEST_SESSION_ID); - - assertContentEqualsTestData(nbContent); - } - - public void testsaveNbContent() - { - /** - * an object already created when setUp() is called, so dont need to save another instance - * TODO: change this, actually test the save method - */ - - - nbContent = noticeboardDAO.findNbContentById(getTestNoticeboardId()); - - assertContentEqualsTestData(nbContent); - - } - - public void testupdateNbContent() - { - // Update the noticeboard to have a new value for its content field - String newContent = "New updated content"; - - nbContent = noticeboardDAO.findNbContentById(getTestNoticeboardId()); - nbContent.setContent(newContent); - - noticeboardDAO.updateNbContent(nbContent); - - //Check whether the value has been updated - - nbContent = noticeboardDAO.findNbContentById(getTestNoticeboardId()); - - assertEquals(nbContent.getContent(), newContent); - - } - - public void testremoveNbSessions() - { - - nbContent = noticeboardDAO.findNbContentById(getTestNoticeboardId()); - - - noticeboardDAO.removeNbSessions(nbContent); - nbContent.getNbSessions().clear(); //Have to remove/empty the collection before deleting it. - //otherwise exception will occur - noticeboardDAO.updateNbContent(nbContent); - NoticeboardContent nb = noticeboardDAO.findNbContentById(getTestNoticeboardId()); - assertNotNull(nb); - assertNbSessionIsNull(TEST_SESSION_ID); - } + noticeboardDAO.removeNoticeboard(TEST_NB_ID); + + assertNbSessionIsNull(TEST_SESSION_ID); + assertNbContentIsNull(TEST_NB_ID); + } - - public void testAddSession() - { - Long newSessionId = new Long(87); - NoticeboardSession newSession = new NoticeboardSession(newSessionId); - - noticeboardDAO.addNbSession(TEST_NB_ID, newSession); - - NoticeboardSession retrievedSession = nbSessionDAO.findNbSessionById(newSessionId); - - assertEquals(retrievedSession.getNbContent().getNbContentId(), TEST_NB_ID); - - } + public void testgetNbContentBySession() + { + nbContent = noticeboardDAO.getNbContentBySession(TEST_SESSION_ID); + + assertContentEqualsTestData(nbContent); + } + + + public void testsaveNbContent() + { + /** + * an object already created when setUp() is called, so dont need to save another instance + * TODO: change this, actually test the save method + */ + + nbContent = noticeboardDAO.findNbContentById(getTestNoticeboardId()); + + assertContentEqualsTestData(nbContent); + + } + + public void testupdateNbContent() + { + // Update the noticeboard to have a new value for its content field + String newContent = "New updated content"; + + nbContent = noticeboardDAO.findNbContentById(getTestNoticeboardId()); + nbContent.setContent(newContent); + + noticeboardDAO.updateNbContent(nbContent); + + //Check whether the value has been updated + + nbContent = noticeboardDAO.findNbContentById(getTestNoticeboardId()); + + assertEquals(nbContent.getContent(), newContent); + + } + + public void testremoveNbSessions() + { + + nbContent = noticeboardDAO.findNbContentById(getTestNoticeboardId()); + + + noticeboardDAO.removeNbSessions(nbContent); + nbContent.getNbSessions().clear(); //Have to remove/empty the collection before deleting it. + //otherwise exception will occur + noticeboardDAO.updateNbContent(nbContent); + NoticeboardContent nb = noticeboardDAO.findNbContentById(getTestNoticeboardId()); + assertNotNull(nb); + assertNbSessionIsNull(TEST_SESSION_ID); + } + + public void testAddSession() + { + Long newSessionId = new Long(87); + NoticeboardSession newSession = new NoticeboardSession(newSessionId); + + noticeboardDAO.addNbSession(TEST_NB_ID, newSession); + + NoticeboardSession retrievedSession = nbSessionDAO.findNbSessionById(newSessionId); + + assertEquals(retrievedSession.getNbContent().getNbContentId(), TEST_NB_ID); + + } + + + + + } Index: lams_tool_nb/test/java/org/lamsfoundation/lams/tool/noticeboard/dao/hibernate/TestNoticeboardSessionDAO.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_nb/test/java/org/lamsfoundation/lams/tool/noticeboard/dao/hibernate/Attic/TestNoticeboardSessionDAO.java,v diff -u -r1.5 -r1.6 --- lams_tool_nb/test/java/org/lamsfoundation/lams/tool/noticeboard/dao/hibernate/TestNoticeboardSessionDAO.java 21 Jul 2005 04:38:22 -0000 1.5 +++ lams_tool_nb/test/java/org/lamsfoundation/lams/tool/noticeboard/dao/hibernate/TestNoticeboardSessionDAO.java 23 Dec 2005 01:58:44 -0000 1.6 @@ -40,9 +40,7 @@ */ public class TestNoticeboardSessionDAO extends NbDataAccessTestCase { - private NoticeboardSessionDAO nbSessionDAO; - private NoticeboardContentDAO nbContentDAO; - private NoticeboardUserDAO nbUserDAO; + private NoticeboardSession nbSession = null; private NoticeboardContent nbContent = null; @@ -60,33 +58,29 @@ */ protected void setUp() throws Exception { super.setUp(); - - nbContentDAO = (NoticeboardContentDAO) this.context.getBean("nbContentDAO"); - nbSessionDAO = (NoticeboardSessionDAO) this.context.getBean("nbSessionDAO"); - nbUserDAO = (NoticeboardUserDAO) this.context.getBean("nbUserDAO"); - super.initAllData(); + initAllData(); } /** * @see NbDataAccessTestCase#tearDown() */ protected void tearDown() throws Exception { - super.tearDown(); + if(cleanContentData) { super.cleanNbContentData(TEST_NB_ID); } } - public void testgetNbSessionByUID() + /* public void testgetNbSessionByUID() { nbSession = nbSessionDAO.getNbSessionByUID(new Long(1)); //default test data which is always in db assertEquals(nbSession.getNbSessionId(), DEFAULT_SESSION_ID); assertEquals(nbSession.getSessionStatus(), DEFAULT_SESSION_STATUS); - } + } */ public void testfindNbSessionById() { @@ -99,7 +93,7 @@ public void testsaveNbSession() { - NoticeboardContent nbContentToReference = nbContentDAO.findNbContentById(TEST_NB_ID); + NoticeboardContent nbContentToReference = noticeboardDAO.findNbContentById(TEST_NB_ID); Long newSessionId = new Long(2222); Date newDateCreated = new Date(System.currentTimeMillis()); @@ -109,7 +103,7 @@ NoticeboardSession.NOT_ATTEMPTED); nbContentToReference.getNbSessions().add(newSessionObject); - nbContentDAO.updateNbContent(nbContentToReference); + noticeboardDAO.updateNbContent(nbContentToReference); nbSessionDAO.saveNbSession(newSessionObject); @@ -135,7 +129,7 @@ assertEquals(updatedSession.getSessionStatus(), NoticeboardSession.COMPLETED); } - public void testremoveNbSessionByUID() + /* public void testremoveNbSessionByUID() { NoticeboardSession existingSession = nbSessionDAO.findNbSessionById(TEST_SESSION_ID); Long uid = existingSession.getUid(); @@ -145,10 +139,10 @@ nbSessionDAO.removeNbSessionByUID(uid); referencedContent.getNbSessions().remove(existingSession); - nbContentDAO.updateNbContent(referencedContent); + noticeboardDAO.updateNbContent(referencedContent); assertSessionObjectIsNull(TEST_SESSION_ID); - } + } */ public void testremoveNbSessionById() @@ -159,7 +153,7 @@ nbSessionDAO.removeNbSession(TEST_SESSION_ID); - nbContentDAO.updateNbContent(nbContent); + noticeboardDAO.updateNbContent(nbContent); assertSessionObjectIsNull(TEST_SESSION_ID); @@ -173,7 +167,7 @@ nbSessionDAO.removeNbSession(nbSession); - nbContentDAO.updateNbContent(nbContent); + noticeboardDAO.updateNbContent(nbContent); assertSessionObjectIsNull(TEST_SESSION_ID); } Index: lams_tool_nb/test/java/org/lamsfoundation/lams/tool/noticeboard/dao/hibernate/TestNoticeboardUserDAO.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_nb/test/java/org/lamsfoundation/lams/tool/noticeboard/dao/hibernate/Attic/TestNoticeboardUserDAO.java,v diff -u -r1.3 -r1.4 --- lams_tool_nb/test/java/org/lamsfoundation/lams/tool/noticeboard/dao/hibernate/TestNoticeboardUserDAO.java 26 Aug 2005 02:47:51 -0000 1.3 +++ lams_tool_nb/test/java/org/lamsfoundation/lams/tool/noticeboard/dao/hibernate/TestNoticeboardUserDAO.java 23 Dec 2005 01:58:44 -0000 1.4 @@ -34,15 +34,11 @@ */ public class TestNoticeboardUserDAO extends NbDataAccessTestCase { - private NoticeboardUserDAO nbUserDAO; - private NoticeboardSessionDAO nbSessionDAO; - private NoticeboardUser nbUser; private NoticeboardSession nbSession; private NoticeboardContent content; - private NoticeboardContentDAO nbContentDao; - + private boolean cleanContentData = true; public TestNoticeboardUserDAO(String name) @@ -55,19 +51,16 @@ */ protected void setUp() throws Exception { super.setUp(); - nbSessionDAO = (NoticeboardSessionDAO) this.context.getBean("nbSessionDAO"); - nbUserDAO = (NoticeboardUserDAO) this.context.getBean("nbUserDAO"); - nbContentDao = (NoticeboardContentDAO) this.context.getBean("nbContentDAO"); - super.initAllData(); + + initAllData(); } protected void tearDown() throws Exception { - - super.tearDown(); + if(cleanContentData) { - super.cleanNbContentData(TEST_NB_ID); + cleanNbContentData(TEST_NB_ID); } } @@ -83,7 +76,6 @@ assertUserObjectIsNull(nonExistentUserId); } - public void testSaveNbUser() { NoticeboardSession sessionToReference = nbSessionDAO.findNbSessionById(TEST_SESSION_ID); @@ -104,9 +96,6 @@ assertEquals(nbUser.getUserId(), newUserId); assertEquals(nbUser.getNbSession().getNbSessionId(),TEST_SESSION_ID); } - - - public void testUpdateNbUser() { nbUser = nbUserDAO.getNbUserByID(TEST_USER_ID); @@ -154,11 +143,11 @@ { Long newSessionId = new Long(3456); - NoticeboardContent content = nbContentDao.findNbContentById(TEST_NB_ID); + NoticeboardContent content = noticeboardDAO.findNbContentById(TEST_NB_ID); NoticeboardSession newSession = new NoticeboardSession(newSessionId, content); content.getNbSessions().add(newSession); - nbContentDao.updateNbContent(content); + noticeboardDAO.updateNbContent(content); nbSessionDAO.saveNbSession(newSession); //add the test user to a new session @@ -185,6 +174,10 @@ assertEquals(retrievedUser.getNbSession().getNbSessionId(), newSessionId); } + + + + }