Index: lams_tool_sbmt/build.properties =================================================================== diff -u -r218109b0df4286a49f8426d903457f30760d7109 -rcd4c4671fd22ddbc11b5ffded95c721f52242c28 --- lams_tool_sbmt/build.properties (.../build.properties) (revision 218109b0df4286a49f8426d903457f30760d7109) +++ lams_tool_sbmt/build.properties (.../build.properties) (revision cd4c4671fd22ddbc11b5ffded95c721f52242c28) @@ -11,11 +11,5 @@ sbmt.package=org.lamsfoundation.lams.tool.sbmt sbmt.path=org/lamsfoundation/lams/tool/sbmt -#JBoss root. Open comment if using another folder -#jboss.home=D:/jboss-4.0.2/ - #Repository directory -contentrepository.location = D:/repository - -# Open comment if use different folder -#j2eelibs=D:/eclipseplugins/myeclipse/eclipse/plugins/com.genuitec.eclipse.j2eedt.core_3.8.4/data/libraryset/1.4 \ No newline at end of file +contentrepository.location = /tmp/repository \ No newline at end of file Index: lams_tool_sbmt/build.xml =================================================================== diff -u -r5d368a095452538907dc13aba254b6a7557953b6 -rcd4c4671fd22ddbc11b5ffded95c721f52242c28 --- lams_tool_sbmt/build.xml (.../build.xml) (revision 5d368a095452538907dc13aba254b6a7557953b6) +++ lams_tool_sbmt/build.xml (.../build.xml) (revision cd4c4671fd22ddbc11b5ffded95c721f52242c28) @@ -318,6 +318,20 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file Index: lams_tool_sbmt/db/sql/insert_test_data.sql =================================================================== diff -u --- lams_tool_sbmt/db/sql/insert_test_data.sql (revision 0) +++ lams_tool_sbmt/db/sql/insert_test_data.sql (revision cd4c4671fd22ddbc11b5ffded95c721f52242c28) @@ -0,0 +1,5 @@ +INSERT INTO tl_lasbmt11_content (content_id,title,instruction,define_later,run_offline,content_in_use,lock_on_finished) values(2,"Test Submission","Submit your a file",0,0,0,0); +INSERT INTO tl_lasbmt11_session (session_id,content_id,status) values(3,2,1); +INSERT INTO tl_lasbmt11_report (report_id, comments, marks, date_marks_released) VALUES (1, 'Not much effort', 1, '2005-09-08 16:04:56'); +INSERT INTO tl_lasbmt11_session_learners (learner_id, user_id, finished, session_id) VALUES (1, 1, 1, 3); +INSERT INTO tl_lasbmt11_submission_details (submission_id, filePath, fileDescription, date_of_submission, uuid, version_id, session_id, learner_id) VALUES (1, 'myfile.txt', 'My Submission', '2005-09-08 16:04:27', 3, 1, 3, 1); Index: lams_tool_sbmt/src/java/org/lamsfoundation/lams/tool/sbmt/submitFilesApplicationContext.xml =================================================================== diff -u -rdf6ad7b34421631085b2ad7a68fa779c550e6a24 -rcd4c4671fd22ddbc11b5ffded95c721f52242c28 --- lams_tool_sbmt/src/java/org/lamsfoundation/lams/tool/sbmt/submitFilesApplicationContext.xml (.../submitFilesApplicationContext.xml) (revision df6ad7b34421631085b2ad7a68fa779c550e6a24) +++ lams_tool_sbmt/src/java/org/lamsfoundation/lams/tool/sbmt/submitFilesApplicationContext.xml (.../submitFilesApplicationContext.xml) (revision cd4c4671fd22ddbc11b5ffded95c721f52242c28) @@ -6,17 +6,9 @@ - - - com.mysql.jdbc.Driver - jdbc:mysql://localhost/lams?zeroDateTimeBehavior=convertToNull&characterEncoding=utf8 - lams - lamsdemo - - - + org/lamsfoundation/lams/tool/sbmt/SubmitFilesContent.hbm.xml @@ -38,12 +30,6 @@ - - - - - - Index: lams_tool_sbmt/test/java/org/lamsfoundation/lams/tool/sbmt/SbmtBaseTestCase.java =================================================================== diff -u --- lams_tool_sbmt/test/java/org/lamsfoundation/lams/tool/sbmt/SbmtBaseTestCase.java (revision 0) +++ lams_tool_sbmt/test/java/org/lamsfoundation/lams/tool/sbmt/SbmtBaseTestCase.java (revision cd4c4671fd22ddbc11b5ffded95c721f52242c28) @@ -0,0 +1,91 @@ +/* + *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.sbmt; + +import javax.sql.DataSource; + +import org.lamsfoundation.lams.test.AbstractLamsTestCase; + +/** + * Base test case containing all the needed application context + * files for submission tool testing + */ +public class SbmtBaseTestCase extends AbstractLamsTestCase { + + /* Content ids and session ids from the test data (see insert_test_data.sql) */ + public static final Long TEST_CONTENT_ID=new Long(2); + public static final String TEST_CONTENT_TITLE="Test Submission"; + public static final String TEST_CONTENT_INSTRUCTIONS="Submit your a file"; + public static final Long TEST_SESSION_ID=new Long(3); + public static final Long TEST_REPORT_ID=new Long(1); + public static final String TEST_REPORT_COMMENT="Not much effort"; + public static final Long TEST_SUBMISSION_ID=new Long(1); + public static final String TEST_FILE_NAME="myfile.txt"; + + public static final String CONTENT_TABLE = "tl_lasbmt11_content"; + public static final String SESSION_TABLE = "tl_lasbmt11_session"; + + public SbmtBaseTestCase(String name){ + super(name); + } + + /** + *(non-Javadoc) + * @see org.lamsfoundation.lams.AbstractLamsTestCase#getContextConfigLocation() + */ + protected String[] getContextConfigLocation() { + return new String[] {"org/lamsfoundation/lams/localApplicationContext.xml", + "org/lamsfoundation/lams/tool/sbmt/submitFilesApplicationContext.xml", + "org/lamsfoundation/lams/contentrepository/applicationContext.xml", + "org/lamsfoundation/lams/lesson/lessonApplicationContext.xml", + "org/lamsfoundation/lams/learning/learningApplicationContext.xml", + "org/lamsfoundation/lams/tool/toolApplicationContext.xml"}; + } + + + /** + * (non-Javadoc) + * @see org.lamsfoundation.lams.AbstractLamsTestCase#getHibernateSessionFactoryName() + */ + protected String getHibernateSessionFactoryName() { + return "sbmtSessionFactory"; + } + + public void setUp()throws Exception{ + super.setUp(); + } + + /** Gets the datasource for the tool database */ + protected DataSource getDataSource() { + DataSource toolDataSource = (DataSource) this.context.getBean("toolDataSource");; + assertNotNull(toolDataSource); + return toolDataSource; + } + + protected long getMaxContentId() { + return getMaxId(CONTENT_TABLE,"content_id",getDataSource()); + } + + protected long getMaxSessionId() { + return getMaxId(SESSION_TABLE,"session_id",getDataSource()); +} +} + \ No newline at end of file Fisheye: Tag b9ef7102d5de177b2caeaa920e9cfce8996267ed refers to a dead (removed) revision in file `lams_tool_sbmt/test/java/org/lamsfoundation/lams/tool/sbmt/dao/TestSubmissionDetailsDAO.java'. Fisheye: No comparison available. Pass `N' to diff? Index: lams_tool_sbmt/test/java/org/lamsfoundation/lams/tool/sbmt/dao/TestSubmitFilesContentDAO.java =================================================================== diff -u -rcbd58f7123483d3575b76d4a19afb6c75b61b3da -rcd4c4671fd22ddbc11b5ffded95c721f52242c28 --- lams_tool_sbmt/test/java/org/lamsfoundation/lams/tool/sbmt/dao/TestSubmitFilesContentDAO.java (.../TestSubmitFilesContentDAO.java) (revision cbd58f7123483d3575b76d4a19afb6c75b61b3da) +++ lams_tool_sbmt/test/java/org/lamsfoundation/lams/tool/sbmt/dao/TestSubmitFilesContentDAO.java (.../TestSubmitFilesContentDAO.java) (revision cd4c4671fd22ddbc11b5ffded95c721f52242c28) @@ -1,53 +1,61 @@ -package org.lamsfoundation.lams.tool.sbmt.dao; - -import org.lamsfoundation.lams.test.AbstractLamsTestCase; -import org.lamsfoundation.lams.tool.sbmt.SubmitFilesContent; -import org.lamsfoundation.lams.tool.sbmt.dao.ISubmitFilesContentDAO; /* - * Created on May 30, 2005 + *Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org) * - * TODO To change the template for this generated file go to - * Window - Preferences - Java - Code Style - Code Templates + *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.sbmt.dao; + +import org.lamsfoundation.lams.tool.sbmt.SbmtBaseTestCase; +import org.lamsfoundation.lams.tool.sbmt.SubmitFilesContent; + /** * @author Manpreet Minhas */ -public class TestSubmitFilesContentDAO extends AbstractLamsTestCase { +public class TestSubmitFilesContentDAO extends SbmtBaseTestCase { protected SubmitFilesContent submitFilesContent; protected ISubmitFilesContentDAO submitFilesContentDAO; public TestSubmitFilesContentDAO(String name){ super(name); } - /** - * (non-Javadoc) - * @see org.lamsfoundation.lams.AbstractLamsTestCase#getContextConfigLocation() - */ - protected String[] getContextConfigLocation() { - return new String[] {"org/lamsfoundation/lams/tool/sbmt/submitFilesApplicationContext.xml"}; - } - /** - * (non-Javadoc) - * @see org.lamsfoundation.lams.AbstractLamsTestCase#getHibernateSessionFactoryName() - */ - protected String getHibernateSessionFactoryName() { - return "sbmtSessionFactory"; - } public void setUp()throws Exception{ super.setUp(); submitFilesContentDAO = (ISubmitFilesContentDAO)context.getBean("submitFilesContentDAO"); } - public void testAddSubmitFilesContent(){ - submitFilesContent = new SubmitFilesContent(new Long(1),"Trial Content","Trial Instructions"); + + public void testAddSubmitFilesContent() throws Exception { + long newId = getMaxContentId() + 1; + String title = "Trial Content"; + String instructions = "Trial Instructions"; + submitFilesContent = new SubmitFilesContent(new Long(newId),title,instructions); submitFilesContentDAO.insert(submitFilesContent); - assertNotNull(submitFilesContent.getContentID()); + Long contentId = submitFilesContent.getContentID(); + assertNotNull(contentId); + assertEquals(contentId.longValue(), newId); } - public void testGetContentByID(){ - submitFilesContent = submitFilesContentDAO.getContentByID(new Long(1)); - assertEquals(submitFilesContent.getTitle(), new String("Trial Content")); + + public void testAddGetContentByID() throws Exception { + submitFilesContent = submitFilesContentDAO.getContentByID(TEST_CONTENT_ID); + assertEquals(submitFilesContent.getTitle(), TEST_CONTENT_TITLE); + assertEquals(submitFilesContent.getInstruction(), TEST_CONTENT_INSTRUCTIONS); } } Index: lams_tool_sbmt/test/java/org/lamsfoundation/lams/tool/sbmt/dao/TestSubmitFilesReportDAO.java =================================================================== diff -u -rcbd58f7123483d3575b76d4a19afb6c75b61b3da -rcd4c4671fd22ddbc11b5ffded95c721f52242c28 --- lams_tool_sbmt/test/java/org/lamsfoundation/lams/tool/sbmt/dao/TestSubmitFilesReportDAO.java (.../TestSubmitFilesReportDAO.java) (revision cbd58f7123483d3575b76d4a19afb6c75b61b3da) +++ lams_tool_sbmt/test/java/org/lamsfoundation/lams/tool/sbmt/dao/TestSubmitFilesReportDAO.java (.../TestSubmitFilesReportDAO.java) (revision cd4c4671fd22ddbc11b5ffded95c721f52242c28) @@ -1,21 +1,37 @@ /* - * Created on May 30, 2005 + *Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org) * - * TODO To change the template for this generated file go to - * Window - Preferences - Java - Code Style - Code Templates + *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.sbmt.dao; -import org.lamsfoundation.lams.test.AbstractLamsTestCase; +import org.lamsfoundation.lams.tool.sbmt.SbmtBaseTestCase; +import org.lamsfoundation.lams.tool.sbmt.SubmissionDetails; import org.lamsfoundation.lams.tool.sbmt.SubmitFilesContent; import org.lamsfoundation.lams.tool.sbmt.SubmitFilesReport; +import org.lamsfoundation.lams.tool.sbmt.SubmitFilesSession; import org.lamsfoundation.lams.tool.sbmt.dao.hibernate.SubmitFilesContentDAO; import org.lamsfoundation.lams.tool.sbmt.dao.hibernate.SubmitFilesReportDAO; /** * @author Manpreet Minhas */ -public class TestSubmitFilesReportDAO extends AbstractLamsTestCase { +public class TestSubmitFilesReportDAO extends SbmtBaseTestCase { protected SubmitFilesReport submitFilesReport; protected SubmitFilesContent submitFilesContent; @@ -27,32 +43,30 @@ super(name); } - /** - * (non-Javadoc) - * @see org.lamsfoundation.lams.AbstractLamsTestCase#getContextConfigLocation() - */ - protected String[] getContextConfigLocation() { - return new String[] {"org/lamsfoundation/lams/tool/sbmt/submitFilesApplicationContext.xml"}; - } - - /** - * (non-Javadoc) - * @see org.lamsfoundation.lams.AbstractLamsTestCase#getHibernateSessionFactoryName() - */ - protected String getHibernateSessionFactoryName() { - return "sbmtSessionFactory"; - } public void setUp()throws Exception{ super.setUp(); submitFilesReportDAO = (SubmitFilesReportDAO)context.getBean("submitFilesReportDAO"); submitFilesContentDAO = (SubmitFilesContentDAO)context.getBean("submitFilesContentDAO"); submissionDetailsDAO = (ISubmissionDetailsDAO)context.getBean("submissionDetailsDAO"); } + + public void testGetReportByID() { + SubmitFilesReport report = submitFilesReportDAO.getReportByID(TEST_REPORT_ID); + assertNotNull("report",report); + assertEquals(report.getComments(),TEST_REPORT_COMMENT); + } public void testAddSubmitFilesReport(){ - submitFilesContent = submitFilesContentDAO.getContentByID(new Long(1)); - - submitFilesReport = submissionDetailsDAO.getSubmissionDetailsByID(new Long(1)).getReport(); - submitFilesReportDAO.insert(submitFilesReport); - assertNotNull(submitFilesReport.getReportID()); + + SubmissionDetails details = submissionDetailsDAO.getSubmissionDetailsByID(TEST_SUBMISSION_ID); + assertNotNull("details", details); + + submitFilesReport = details.getReport(); + assertNotNull("submitFilesReport", submitFilesReport); + + SubmitFilesReport clone = (SubmitFilesReport) submitFilesReport.clone(); + submitFilesReportDAO.insert(clone); + assertNotNull(clone.getReportID()); + assertNotSame("Clone has a different id", clone.getReportID(), submitFilesReport.getReportID()); + } } Index: lams_tool_sbmt/test/java/org/lamsfoundation/lams/tool/sbmt/dao/TestSubmitFilesSession.java =================================================================== diff -u -rcbd58f7123483d3575b76d4a19afb6c75b61b3da -rcd4c4671fd22ddbc11b5ffded95c721f52242c28 --- lams_tool_sbmt/test/java/org/lamsfoundation/lams/tool/sbmt/dao/TestSubmitFilesSession.java (.../TestSubmitFilesSession.java) (revision cbd58f7123483d3575b76d4a19afb6c75b61b3da) +++ lams_tool_sbmt/test/java/org/lamsfoundation/lams/tool/sbmt/dao/TestSubmitFilesSession.java (.../TestSubmitFilesSession.java) (revision cd4c4671fd22ddbc11b5ffded95c721f52242c28) @@ -1,12 +1,26 @@ /* - * Created on May 30, 2005 + *Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org) * - * TODO To change the template for this generated file go to - * Window - Preferences - Java - Code Style - Code Templates + *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.sbmt.dao; -import org.lamsfoundation.lams.test.AbstractLamsTestCase; +import org.lamsfoundation.lams.tool.sbmt.SbmtBaseTestCase; import org.lamsfoundation.lams.tool.sbmt.SubmitFilesContent; import org.lamsfoundation.lams.tool.sbmt.SubmitFilesSession; import org.lamsfoundation.lams.tool.sbmt.dao.hibernate.SubmitFilesContentDAO; @@ -15,7 +29,7 @@ /** * @author Manpreet Minhas */ -public class TestSubmitFilesSession extends AbstractLamsTestCase { +public class TestSubmitFilesSession extends SbmtBaseTestCase { protected SubmitFilesSession submitFilesSession; protected SubmitFilesContent submitFilesContent; @@ -27,22 +41,6 @@ super(name); } - /** - * (non-Javadoc) - * @see org.lamsfoundation.lams.AbstractLamsTestCase#getContextConfigLocation() - */ - protected String[] getContextConfigLocation() { - return new String[] {"org/lamsfoundation/lams/tool/sbmt/submitFilesApplicationContext.xml"}; - } - - /** - * (non-Jsavadoc) - * @see org.lamsfoundation.lams.AbstractLamsTestCase#getHibernateSessionFactoryName() - */ - protected String getHibernateSessionFactoryName() { - return "sbmtSessionFactory"; - } - public void setUp() throws Exception{ super.setUp(); submitFilesSessionDAO = (SubmitFilesSessionDAO)context.getBean("submitFilesSessionDAO"); Index: lams_tool_sbmt/test/java/org/lamsfoundation/lams/tool/sbmt/service/TestSubmitFilesService.java =================================================================== diff -u -rcbd58f7123483d3575b76d4a19afb6c75b61b3da -rcd4c4671fd22ddbc11b5ffded95c721f52242c28 --- lams_tool_sbmt/test/java/org/lamsfoundation/lams/tool/sbmt/service/TestSubmitFilesService.java (.../TestSubmitFilesService.java) (revision cbd58f7123483d3575b76d4a19afb6c75b61b3da) +++ lams_tool_sbmt/test/java/org/lamsfoundation/lams/tool/sbmt/service/TestSubmitFilesService.java (.../TestSubmitFilesService.java) (revision cd4c4671fd22ddbc11b5ffded95c721f52242c28) @@ -1,23 +1,51 @@ /* - * Created on May 20, 2005 + *Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org) * - * TODO To change the template for this generated file go to - * Window - Preferences - Java - Code Style - Code Templates + *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.sbmt.service; -import org.lamsfoundation.lams.test.AbstractLamsTestCase; +import org.lamsfoundation.lams.tool.ToolContentManager; +import org.lamsfoundation.lams.tool.ToolSessionManager; +import org.lamsfoundation.lams.tool.exception.SessionDataExistsException; +import org.lamsfoundation.lams.tool.exception.ToolException; +import org.lamsfoundation.lams.tool.sbmt.SbmtBaseTestCase; import org.lamsfoundation.lams.tool.sbmt.SubmitFilesContent; +import org.lamsfoundation.lams.tool.sbmt.SubmitFilesSession; import org.lamsfoundation.lams.tool.sbmt.dao.ISubmissionDetailsDAO; import org.lamsfoundation.lams.tool.sbmt.dao.ISubmitFilesContentDAO; +import org.lamsfoundation.lams.tool.sbmt.dao.ISubmitFilesSessionDAO; +import org.springframework.orm.hibernate.HibernateObjectRetrievalFailureException; /** - * @author Manpreet Minhas + * Note: this test sets up tool content ids and tool session ids that + * are invalid with respect to the core tables. + * + * @author Manpreet Minhas, Fiona Malikoff */ -public class TestSubmitFilesService extends AbstractLamsTestCase { +public class TestSubmitFilesService extends SbmtBaseTestCase { protected ISubmitFilesService submitFilesService; - protected ISubmitFilesContentDAO submitFilesContentDAO; + protected ToolContentManager submitFilesToolContentManager; + protected ToolSessionManager submitFilesToolSessionManager; + + protected ISubmitFilesSessionDAO submitFilesSessionDAO = null; + protected ISubmitFilesContentDAO submitFilesContentDAO = null; protected ISubmissionDetailsDAO submissionDetailsDAO; protected SubmitFilesContent submitFilesContent; @@ -26,32 +54,15 @@ super(name); } - /** - *(non-Javadoc) - * @see org.lamsfoundation.lams.AbstractLamsTestCase#getContextConfigLocation() - */ - protected String[] getContextConfigLocation() { - return new String[] {"org/lamsfoundation/lams/applicationContext.xml", - "org/lamsfoundation/lams/workspace/workspaceApplicationContext.xml", - "org/lamsfoundation/lams/authoring/authoringApplicationContext.xml", - "org/lamsfoundation/lams/tool/sbmt/submitFilesApplicationContext.xml"}; - } - - /** - * (non-Javadoc) - * @see org.lamsfoundation.lams.AbstractLamsTestCase#getHibernateSessionFactoryName() - */ - protected String getHibernateSessionFactoryName() { - return "sbmtSessionFactory"; - } - public void setUp()throws Exception{ super.setUp(); submitFilesService = (ISubmitFilesService)context.getBean("submitFilesService"); + submitFilesToolContentManager = (ToolContentManager) submitFilesService; + submitFilesToolSessionManager = (ToolSessionManager) submitFilesService; + + submitFilesSessionDAO = (ISubmitFilesSessionDAO)context.getBean("submitFilesSessionDAO"); submitFilesContentDAO = (ISubmitFilesContentDAO)context.getBean("submitFilesContentDAO"); - submissionDetailsDAO = (ISubmissionDetailsDAO)context.getBean("submissionDetailsDAO"); } - /*public void testAddSubmitFilesContent(){ submitFilesService.addSubmitFilesContent(new Long(1),"Trial Title Submit Files", "Trial Instructions Submit Files"); assertNotNull(submitFilesContentDAO.getContentByID(new Long(1))); @@ -65,17 +76,130 @@ submitFilesService.uploadFile(new Long(1),filePath,"Trial Content File Description", new Long(1)); submitFilesService.uploadFile(new Long(1),filePath,"Trial Content File Description", new Long(2)); assertNotNull(submissionDetailsDAO.getSubmissionDetailsByID(new Long(1))); + }*/ + + public void testCopyContent(){ + Long id = copyTestContent(); } - public void testRemoveToolContent(){ - submitFilesService.removeToolContent(new Long(1)); + + private Long copyTestContent() { + + Long newContentId = new Long(getMaxContentId() + 1); + try { + submitFilesToolContentManager.copyToolContent(TEST_CONTENT_ID, newContentId); + } catch (ToolException e) { + e.printStackTrace(); + fail("Tool exception thrown copying the content"); + } + return newContentId; + } + + public void testCreateSession() { + createSession(copyTestContent()); + } + + private SubmitFilesSession createSession(Long toolContentId) { + Long toolSessionId = new Long(getMaxSessionId()+1); + + try { + submitFilesToolSessionManager.createToolSession(toolSessionId,toolContentId); + } catch (ToolException e) { + e.printStackTrace(); + fail("Tool exception thrown while creating session"); + } + SubmitFilesSession submitFilesSession = submitFilesSessionDAO.getSessionByID(toolSessionId); + assertNotNull("submitFilesSession", submitFilesSession); + assertEquals(toolSessionId, submitFilesSession.getSessionID()); + return submitFilesSession; + } + + /** Tests removing content where session data exists */ + public void testRemoveToolContentSessionDataExists(){ + + Long toolContentId = copyTestContent(); + SubmitFilesSession submitFilesSession = createSession(toolContentId); + Long sessionContentId = submitFilesSession.getSessionID(); + + // Remove without removing the session data - should fail. + try { + submitFilesToolContentManager.removeToolContent(toolContentId, false); + fail("Expected SessionDataExistsException to be thrown, toolSessionId = " + +sessionContentId); + } catch (SessionDataExistsException e) { + assertTrue("SessionDataExistsException thrown as expected", true); + } catch (ToolException e) { + e.printStackTrace(); + fail("Tool exception thrown deleting the content toolContentId="+toolContentId); + } + + // Records should still exist try{ - submitFilesContentDAO.getContentByID(new Long(1)); - fail("Exception should be raised because this object has already been deleted"); + SubmitFilesContent content = submitFilesContentDAO.getContentByID(toolContentId); + assertNotNull("Tool content data", content); }catch(HibernateObjectRetrievalFailureException he){ - assertTrue(true); + fail("Tool content has been marked as deleted - should not have been deleted"); } + + try{ + SubmitFilesSession session = submitFilesSessionDAO.getSessionByID(sessionContentId); + assertNotNull("Tool session data", session); + }catch(HibernateObjectRetrievalFailureException he){ + fail("Tool session has been marked as deleted - should not have been deleted"); + } + + // This time remove the session data too! + try { + submitFilesToolContentManager.removeToolContent(toolContentId, true); + } catch (SessionDataExistsException e) { + e.printStackTrace(); + fail("SessionDataExistsException thrown deleting the content toolContentId="+toolContentId); + } catch (ToolException e) { + e.printStackTrace(); + fail("Tool exception thrown deleting the content toolContentId="+toolContentId); + } + + try{ + submitFilesContentDAO.getContentByID(toolContentId); + fail("Exception should be raised because content object has already been deleted"); + }catch(HibernateObjectRetrievalFailureException he){ + assertTrue("Tool Content has been deleted as expected", true); + } + + try{ + submitFilesSessionDAO.getSessionByID(sessionContentId); + fail("Exception should be raised because session object has already been deleted"); + }catch(HibernateObjectRetrievalFailureException he){ + assertTrue("Tool session has been deleted as expected", true); + } + } - public void testGenerateReport(){ + + /** Tests removing content where session data does not exist */ + public void testRemoveToolContentNoSessionData(){ + + Long toolContentId = copyTestContent(); + + // Remove without removing the session data - should work. + try { + submitFilesToolContentManager.removeToolContent(toolContentId, true); + } catch (SessionDataExistsException e) { + e.printStackTrace(); + fail("SessionDataExistsException thrown deleting the content toolContentId="+toolContentId); + } catch (ToolException e) { + e.printStackTrace(); + fail("Tool exception thrown deleting the content toolContentId="+toolContentId); + } + + try{ + submitFilesContentDAO.getContentByID(toolContentId); + fail("Exception should be raised because content object has already been deleted"); + }catch(HibernateObjectRetrievalFailureException he){ + assertTrue("Tool Content has been deleted as expected", true); + } + + } + + /* public void testGenerateReport(){ Hashtable table = submitFilesService.generateReport(new Long(1)); assertEquals(table.size(),3); }*/ Index: lams_tool_sbmt/test/java/org/lamsfoundation/lams/tool/sbmt/web/SbmtBaseTestAction.java =================================================================== diff -u --- lams_tool_sbmt/test/java/org/lamsfoundation/lams/tool/sbmt/web/SbmtBaseTestAction.java (revision 0) +++ lams_tool_sbmt/test/java/org/lamsfoundation/lams/tool/sbmt/web/SbmtBaseTestAction.java (revision cd4c4671fd22ddbc11b5ffded95c721f52242c28) @@ -0,0 +1,49 @@ +/**************************************************************** + * 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.sbmt.web; + +import org.springframework.web.context.ContextLoader; +import org.springframework.web.context.support.XmlWebApplicationContext; + +import servletunit.struts.MockStrutsTestCase; + +public class SbmtBaseTestAction extends MockStrutsTestCase { + + public SbmtBaseTestAction(String name){ + super(name); + } + public void setUp()throws Exception{ + super.setUp(); + ContextLoader ctxLoader = new ContextLoader(); + context.setInitParameter(ContextLoader.CONTEXT_CLASS_PARAM, + XmlWebApplicationContext.class.getName()); + context.setInitParameter(ContextLoader.CONFIG_LOCATION_PARAM, + "org/lamsfoundation/lams/localApplicationContext.xml,"+ + "org/lamsfoundation/lams/tool/sbmt/submitFilesApplicationContext.xml,"+ + "org/lamsfoundation/lams/contentrepository/applicationContext.xml,"+ + "org/lamsfoundation/lams/lesson/lessonApplicationContext.xml,"+ + "org/lamsfoundation/lams/learning/learningApplicationContext.xml,"+ + "org/lamsfoundation/lams/tool/toolApplicationContext.xml,"); + ctxLoader.initWebApplicationContext(context); + } +} Index: lams_tool_sbmt/test/java/org/lamsfoundation/lams/tool/sbmt/web/TestAuthoringAction.java =================================================================== diff -u -reb8df38a09efc89ecb2524cb7cf70ad9f3ec69d8 -rcd4c4671fd22ddbc11b5ffded95c721f52242c28 --- lams_tool_sbmt/test/java/org/lamsfoundation/lams/tool/sbmt/web/TestAuthoringAction.java (.../TestAuthoringAction.java) (revision eb8df38a09efc89ecb2524cb7cf70ad9f3ec69d8) +++ lams_tool_sbmt/test/java/org/lamsfoundation/lams/tool/sbmt/web/TestAuthoringAction.java (.../TestAuthoringAction.java) (revision cd4c4671fd22ddbc11b5ffded95c721f52242c28) @@ -28,9 +28,13 @@ import servletunit.struts.MockStrutsTestCase; /** + * This test is invalid. The url and parameter names are wrong, + * the matching content doesn't exist in the database. + * FM Sept 05 + * * @author Manpreet Minhas */ -public class TestAuthoringAction extends MockStrutsTestCase { +public class TestAuthoringAction extends SbmtBaseTestAction { public TestAuthoringAction(String name){ super(name); Index: lams_tool_sbmt/test/java/org/lamsfoundation/lams/tool/sbmt/web/TestLearnerAction.java =================================================================== diff -u -reb8df38a09efc89ecb2524cb7cf70ad9f3ec69d8 -rcd4c4671fd22ddbc11b5ffded95c721f52242c28 --- lams_tool_sbmt/test/java/org/lamsfoundation/lams/tool/sbmt/web/TestLearnerAction.java (.../TestLearnerAction.java) (revision eb8df38a09efc89ecb2524cb7cf70ad9f3ec69d8) +++ lams_tool_sbmt/test/java/org/lamsfoundation/lams/tool/sbmt/web/TestLearnerAction.java (.../TestLearnerAction.java) (revision cd4c4671fd22ddbc11b5ffded95c721f52242c28) @@ -1,40 +1,45 @@ -/* - * Created on May 24, 2005 - * - * TODO To change the template for this generated file go to - * Window - Preferences - Java - Code Style - Code Templates +/**************************************************************** + * 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.sbmt.web; import java.io.File; -import org.springframework.web.context.ContextLoader; -import org.springframework.web.context.support.XmlWebApplicationContext; - -import servletunit.struts.MockStrutsTestCase; - /** + * This test is invalid. You can't assign a string to the + * filePath parameter - its of type org.apache.struts.upload.FormFile! + * FM Sept 05 + * * @author Manpreet Minhas */ -public class TestLearnerAction extends MockStrutsTestCase { +public class TestLearnerAction extends SbmtBaseTestAction { public TestLearnerAction(String name){ super(name); } - public void setUp() throws Exception{ - super.setUp(); - ContextLoader ctxLoader = new ContextLoader(); - context.setInitParameter(ContextLoader.CONTEXT_CLASS_PARAM, - XmlWebApplicationContext.class.getName()); - context.setInitParameter(ContextLoader.CONFIG_LOCATION_PARAM, - "/org/lamsfoundation/lams/tool/sbmt/submitFilesApplicationContext.xml"); - ctxLoader.initWebApplicationContext(context); - } - public void testUploadFile(){ setConfigFile("/WEB-INF/struts/struts-config.xml"); - setRequestPathInfo("/tool/sbmt/learner"); + setRequestPathInfo("/learner"); addRequestParameter("method","uploadFile"); addRequestParameter("contentID","1"); Index: lams_tool_sbmt/test/java/org/lamsfoundation/lams/tool/sbmt/web/TestMonitoringAction.java =================================================================== diff -u -reb8df38a09efc89ecb2524cb7cf70ad9f3ec69d8 -rcd4c4671fd22ddbc11b5ffded95c721f52242c28 --- lams_tool_sbmt/test/java/org/lamsfoundation/lams/tool/sbmt/web/TestMonitoringAction.java (.../TestMonitoringAction.java) (revision eb8df38a09efc89ecb2524cb7cf70ad9f3ec69d8) +++ lams_tool_sbmt/test/java/org/lamsfoundation/lams/tool/sbmt/web/TestMonitoringAction.java (.../TestMonitoringAction.java) (revision cd4c4671fd22ddbc11b5ffded95c721f52242c28) @@ -22,31 +22,20 @@ */ package org.lamsfoundation.lams.tool.sbmt.web; -import org.springframework.web.context.ContextLoader; -import org.springframework.web.context.support.XmlWebApplicationContext; - import servletunit.struts.MockStrutsTestCase; /** + * None of these tests are valid - the getStatus method + * doesn't exist and markFiles should be markFile and take + * different parameters. FM Sept 05 + * * @author Manpreet Minhas */ public class TestMonitoringAction extends MockStrutsTestCase { public TestMonitoringAction(String name){ super(name); } - public void setUp()throws Exception{ - super.setUp(); - ContextLoader ctxLoader = new ContextLoader(); - context.setInitParameter(ContextLoader.CONTEXT_CLASS_PARAM, - XmlWebApplicationContext.class.getName()); - context.setInitParameter(ContextLoader.CONFIG_LOCATION_PARAM, - "org/lamsfoundation/lams/applicationContext.xml," + - " org/lamsfoundation/lams/workspace/workspaceApplicationContext.xml," + - " org/lamsfoundation/lams/authoring/authoringApplicationContext.xml," + - " org/lamsfoundation/lams/tool/sbmt/submitFilesApplicationContext.xml"); - ctxLoader.initWebApplicationContext(context); - } public void testGetStatus(){ setConfigFile("/WEB-INF/struts/struts-config.xml"); setRequestPathInfo("/monitoring");