Index: lams_learning/test/java/org/lamsfoundation/lams/learning/export/service/TestExportPortfolioService.java =================================================================== diff -u -r7f80ba8587932005ce6285ea17c4f91f94b6e02c -r226c997fa0f489fe21248582359d3849bf93d2e2 --- lams_learning/test/java/org/lamsfoundation/lams/learning/export/service/TestExportPortfolioService.java (.../TestExportPortfolioService.java) (revision 7f80ba8587932005ce6285ea17c4f91f94b6e02c) +++ lams_learning/test/java/org/lamsfoundation/lams/learning/export/service/TestExportPortfolioService.java (.../TestExportPortfolioService.java) (revision 226c997fa0f489fe21248582359d3849bf93d2e2) @@ -1,8 +1,6 @@ /* * Created on Aug 30, 2005 * - * TODO To change the template for this generated file go to - * Window - Preferences - Java - Code Style - Code Templates */ package org.lamsfoundation.lams.learning.export.service; @@ -30,8 +28,6 @@ /** * @author mtruong * - * TODO To change the template for this generated type comment go to - * Window - Preferences - Java - Code Style - Code Templates */ public class TestExportPortfolioService extends AbstractLamsTestCase { @@ -90,19 +86,11 @@ protected String[] getContextConfigLocation() { - return new String[] { "classpath:/org/lamsfoundation/lams/applicationContext.xml", + return new String[] { "classpath:/org/lamsfoundation/lams/localApplicationContext.xml", "classpath:/org/lamsfoundation/lams/lesson/lessonApplicationContext.xml", "classpath:/org/lamsfoundation/lams/tool/toolApplicationContext.xml", "classpath:/org/lamsfoundation/lams/learning/learningApplicationContext.xml", "classpath:*/applicationContext.xml"}; - -/* return new String[] { "/org/lamsfoundation/lams/lesson/lessonApplicationContext.xml", - "/org/lamsfoundation/lams/tool/toolApplicationContext.xml", - "/org/lamsfoundation/lams/learningdesign/learningDesignApplicationContext.xml", - "/org/lamsfoundation/lams/tool/survey/dataAccessContext.xml", - "/org/lamsfoundation/lams/tool/survey/surveyApplicationContext.xml", - "applicationContext.xml", - "/WEB-INF/spring/learningApplicationContext.xml"}; */ } protected String getHibernateSessionFactoryName() @@ -125,10 +113,7 @@ testLesson_fromCommon = lessonDao.getLesson(TEST_LESSON_ID_fromCommon); testUser_fromCommon = usermanageService.getUserById(TEST_USER_ID_fromCommon); - - - - } + } /* * @see TestCase#tearDown() @@ -138,61 +123,101 @@ super.tearDown(); } - /* + + /** + * Tests the export service method getOrderedActivityList(LearningDesign), used + * when the student is conducting the export. The ordered list of activities + * returned by this method, is compared with the correct ordered list that + * should be returned. + */ public void testGetOrderedListByLearningDesign() { - log.info("==================Inside testGetOrderedList(LearningDesign)=================="); - Long id = testLesson_fromCommon.getLearningDesign().getFirstActivity().getActivityId(); - Vector sortedActivityList = exportService.getOrderedActivityList(testLesson_fromCommon.getLearningDesign()); + Long id = testLesson.getLearningDesign().getFirstActivity().getActivityId(); + Vector sortedActivityList = exportService.getOrderedActivityList(testLesson.getLearningDesign()); + Vector correctOrderedList = getTestOrderedActivityIdList(); Iterator i = sortedActivityList.iterator(); + Iterator j = correctOrderedList.iterator(); - while(i.hasNext()) + while(i.hasNext() && j.hasNext()) { Activity a = (Activity)i.next(); - log.info("Activity Id: " + a.getActivityId()); - } + Long testId = (Long)j.next(); + // ensure that the activityId from the test ordered list and the ordered list returned from the method is the same + assertEquals(testId, a.getActivityId()); + } - } - public void testGetOrderedListByLearnerProgress() + /** + * Tests the export service method getOrderedActivityList(learnerProgressId), used when + * a student is conducting the export. The ordered list of completed activities returned + * by this method is compared with the correct ordered list that should be returned. + * @return + */ + public void testGetOrderedListByLearnerProgressId() { - log.info("==================Inside testGetOrderedList(LearnerProgress)=================="); - testProgress=learnerProgressDao.getLearnerProgressByLearner(testUser_fromCommon,testLesson_fromCommon); - assertEquals(testProgress.getLearnerProgressId(),new Long(6)); - Vector sortedActivityList = exportService.getOrderedActivityList(testProgress); - assertTrue(sortedActivityList.size()!=0); - Iterator i = sortedActivityList.iterator(); + testProgress=learnerProgressDao.getLearnerProgressByLearner(testUser,testLesson); - while(i.hasNext()) - { - Activity a = (Activity)i.next(); - log.info("Activity Id: " + a.getActivityId()); - } - - - } - */ - public void testGetOrderedListByLearningDesign2() - { - log.info("==================Inside testGetOrderedList(LearningDesign)=================="); - Long id = testLesson.getLearningDesign().getFirstActivity().getActivityId(); - Vector sortedActivityList = exportService.getOrderedActivityList(testLesson.getLearningDesign()); - Vector testActivityIdList = getTestOrderedActivityIdList(); + Vector sortedActivityList = exportService.getOrderedActivityList(testProgress.getLearnerProgressId()); + Vector testActivityIdList = getTestOrderedCompletedActivityIdList(); Iterator i = sortedActivityList.iterator(); Iterator j = testActivityIdList.iterator(); - while(i.hasNext() && j.hasNext()) { Activity a = (Activity)i.next(); Long testId = (Long)j.next(); assertEquals(testId, a.getActivityId()); - log.info("Activity Id: " + a.getActivityId()); + } + } + + /** + * Helper method which creates the ordered activity list, based on the test data + * inserted by export_test_data.sql script. This list is used as a comparison + * between the ordered list obtained by calling getOrderedActivityList(LearningDesign) + * See export_test_data.sql for the list of activities. + * + * @return the ordered list of activities in the learning design + */ + private Vector getTestOrderedActivityIdList() + { + Vector orderedIdList = new Vector(); + orderedIdList.add(TEST_ACTIVITY_ID1_NB); + orderedIdList.add(TEST_ACTIVITY_ID2_NB); + orderedIdList.add(TEST_ACTIVITY_ID3_SURVEY); + orderedIdList.add(TEST_ACTIVITY_ID4_NB); + orderedIdList.add(TEST_ACTIVITY_ID5_NB); + //orderedIdList.add(TEST_ACTIVITY_ID6_OPTIONAL); //not added because its not a toolactivity, only child activities are added + orderedIdList.add(TEST_ACTIVITY_ID7_OPT_NB); + orderedIdList.add(TEST_ACTIVITY_ID8_OPT_SURVEY); + orderedIdList.add(TEST_ACTIVITY_ID9_NB); + return orderedIdList; + } + + /** + * Helper method which creates the ordered list of completed activities by the learner, + * based on the test data inserted by export_test_data.sql script. This list is used as a comparison + * between the ordered list obtained by calling getOrderedActivityList(learnerProgressId) + * See export_test_data.sql for the list of completed activities. + * + * @return the ordered list of completed activities by the test learner + */ + private Vector getTestOrderedCompletedActivityIdList() + { + Vector orderedIdList = new Vector(); + orderedIdList.add(TEST_ACTIVITY_ID1_NB); + orderedIdList.add(TEST_ACTIVITY_ID2_NB); + orderedIdList.add(TEST_ACTIVITY_ID3_SURVEY); + orderedIdList.add(TEST_ACTIVITY_ID4_NB); + orderedIdList.add(TEST_ACTIVITY_ID5_NB); + //orderedIdList.add(TEST_ACTIVITY_ID6_OPTIONAL); //not added because its not a toolactivity, only child activities are added + orderedIdList.add(TEST_ACTIVITY_ID7_OPT_NB); - + return orderedIdList; } + /* + //method is not used as it doesnt work. get the lazy initialisation error public void testGetOrderedListByLearnerProgress2() { log.info("==================Inside testGetOrderedList(LearnerProgress)=================="); @@ -211,9 +236,10 @@ } - } + } */ - /* public void testSetupPortfoliosFromCommonByTeacher() throws LamsToolServiceException + /* + public void testSetupPortfoliosFromCommonByTeacher() throws LamsToolServiceException { log.info("==================Inside testSetupPortfolios by teacher=================="); Long id = testLesson_fromCommon.getLearningDesign().getFirstActivity().getActivityId(); @@ -234,7 +260,7 @@ log.info("Activity exportURL: " + individualPortfolio.getExportUrl()); } } - + public void testSetupPortfoliosFromCommonByLearner() throws LamsToolServiceException { log.info("==================Inside testSetupPortfolios By Learner=================="); @@ -259,44 +285,8 @@ } */ - //see insert_test_data.sql for list of activities - private Vector getTestOrderedActivityIdList() - { - Vector orderedIdList = new Vector(); - orderedIdList.add(TEST_ACTIVITY_ID1_NB); - orderedIdList.add(TEST_ACTIVITY_ID2_NB); - orderedIdList.add(TEST_ACTIVITY_ID3_SURVEY); - orderedIdList.add(TEST_ACTIVITY_ID4_NB); - orderedIdList.add(TEST_ACTIVITY_ID5_NB); - //orderedIdList.add(TEST_ACTIVITY_ID6_OPTIONAL); //not added because its not a toolactivity, only child activities are added - orderedIdList.add(TEST_ACTIVITY_ID7_OPT_NB); - orderedIdList.add(TEST_ACTIVITY_ID8_OPT_SURVEY); - orderedIdList.add(TEST_ACTIVITY_ID9_NB); - return orderedIdList; - } - - private Vector getTestOrderedCompletedActivityIdList() - { - Vector orderedIdList = new Vector(); - orderedIdList.add(TEST_ACTIVITY_ID1_NB); - orderedIdList.add(TEST_ACTIVITY_ID2_NB); - orderedIdList.add(TEST_ACTIVITY_ID3_SURVEY); - orderedIdList.add(TEST_ACTIVITY_ID4_NB); - orderedIdList.add(TEST_ACTIVITY_ID5_NB); - //orderedIdList.add(TEST_ACTIVITY_ID6_OPTIONAL); //not added because its not a toolactivity, only child activities are added - orderedIdList.add(TEST_ACTIVITY_ID7_OPT_NB); - - return orderedIdList; - } - - public void testCreateTempDirectory() - { - String directoryName = "TestCreateDir"; - - boolean created = exportService.createTempDirectory(directoryName); - assertTrue(created); - } - + + /* public void testZipPortfolio() { String directoryName = "C:\\TestDir"; @@ -308,6 +298,14 @@ String zipFileNameReturned = exportService.zipPortfolio(zipFileName, directoryName); assertNotNull(zipFileNameReturned); assertEquals(zipFileNameReturned, zipFileName); + } */ + + /* public void testConnectToUrl() + { + //Set up the portfolio, then try to connect to the tool + String exportUrl = "http://localhost:8080/lams/tool/lanb11/portfolioExport?mode=teacher&toolContentId=358&directoryName=/JunitTest"; + String mainFileName = exportService.connectToToolViaExportURL(exportUrl); + // System.out.println(mainFileName); } - +*/ }