Index: lams_common/test/java/org/lamsfoundation/lams/selenium/AbstractSeleniumTestCase.java =================================================================== diff -u -rc31ac132c415a51a03bacad1f24c08db90da0514 -re3c917a58dd420e2e96f0a45bd85fb80806c92ed --- lams_common/test/java/org/lamsfoundation/lams/selenium/AbstractSeleniumTestCase.java (.../AbstractSeleniumTestCase.java) (revision c31ac132c415a51a03bacad1f24c08db90da0514) +++ lams_common/test/java/org/lamsfoundation/lams/selenium/AbstractSeleniumTestCase.java (.../AbstractSeleniumTestCase.java) (revision e3c917a58dd420e2e96f0a45bd85fb80806c92ed) @@ -49,552 +49,574 @@ public abstract class AbstractSeleniumTestCase extends SeleneseTestCase { - protected ToolDAO toolDAO; - protected ActivityDAO activityDAO; - protected UserManagementService userManagementService; - protected LessonDAO lessonDAO; - protected LearningDesignDAO learningDesignDAO; + protected ToolDAO toolDAO; + protected ActivityDAO activityDAO; + protected UserManagementService userManagementService; + protected LessonDAO lessonDAO; + protected LearningDesignDAO learningDesignDAO; - private static final String[] contextConfigLocation = new String[] { - "org/lamsfoundation/lams/localCommonContext.xml", - "org/lamsfoundation/lams/lesson/lessonApplicationContext.xml", - "org/lamsfoundation/lams/toolApplicationContext.xml", - }; - - // name of the learning design. we receive it from the subclass initially. - // but then it might be changed if LD with the same name already exists - private String learningDesignName; + private static final String[] contextConfigLocation = new String[] { + "org/lamsfoundation/lams/localCommonContext.xml", + "org/lamsfoundation/lams/lesson/lessonApplicationContext.xml", + "org/lamsfoundation/lams/toolApplicationContext.xml", }; - public void setUp() throws Exception { - ApplicationContext context = new ClassPathXmlApplicationContext(contextConfigLocation); - toolDAO = (ToolDAO) context.getBean("toolDAO"); - activityDAO = (ActivityDAO) context.getBean("activityDAO"); - userManagementService = (UserManagementService) context.getBean("userManagementService"); - lessonDAO = (LessonDAO) context.getBean("lessonDAO"); - learningDesignDAO = (LearningDesignDAO) context.getBean("learningDesignDAO"); - learningDesignName = getLearningDesignName(); - - HttpCommandProcessor proc = new HttpCommandProcessor( - TestFrameworkConstants.SERVER_HOST, - TestFrameworkConstants.SERVER_PORT, - TestFrameworkConstants.BROWSER, - TestFrameworkConstants.WEB_APP_HOST - + TestFrameworkConstants.WEB_APP_DIR); - selenium = new DefaultSeleniumFlex(proc); - selenium.start(); - //do not reduce this parameter as Selenium might start working wrong - selenium.setSpeed("400"); - } + // name of the learning design. we receive it from the subclass initially. + // but then it might be changed if LD with the same name already exists + private String learningDesignName; - public void tearDown() throws Exception { - try { - super.tearDown(); - } finally { - if (selenium != null) { - selenium.stop(); - selenium = null; - } - } + public void setUp() throws Exception { + ApplicationContext context = new ClassPathXmlApplicationContext(contextConfigLocation); + toolDAO = (ToolDAO) context.getBean("toolDAO"); + activityDAO = (ActivityDAO) context.getBean("activityDAO"); + userManagementService = (UserManagementService) context.getBean("userManagementService"); + lessonDAO = (LessonDAO) context.getBean("lessonDAO"); + learningDesignDAO = (LearningDesignDAO) context.getBean("learningDesignDAO"); + learningDesignName = getLearningDesignName(); + + HttpCommandProcessor proc = new HttpCommandProcessor(TestFrameworkConstants.SERVER_HOST, + TestFrameworkConstants.SERVER_PORT, TestFrameworkConstants.BROWSER, TestFrameworkConstants.WEB_APP_HOST + + TestFrameworkConstants.WEB_APP_DIR); + selenium = new DefaultSeleniumFlex(proc); + selenium.start(); + //do not reduce this parameter as Selenium might start working wrong + selenium.setSpeed("400"); + } + + public void tearDown() throws Exception { + try { + super.tearDown(); + } finally { + if (selenium != null) { + selenium.stop(); + selenium = null; + } } - - /** - * Our main test class. Currently it tests authoring, learning and - * monitoring sequentially one-by-one. Also it relies on the fact that you - * store new LD in authoring (otherwise you should reimplement this method). - * - * @throws Exception - */ - public void testEntireTool() throws Exception { - loginToLams(); - - //Authoring part - Map contentDetails = setUpAuthoring(); - authoringTest(); - storeLearningDesign(contentDetails); - - createNewLesson(); - - //Learning part - learningTest(); - - //Monitoring part - openToolMonitor(); - monitoringTest(); - closeToolMonitor(); - } - - /** - * Returns tool's signature. This method should be overridden by all subclasses. - * - * @return tool's signature - */ - protected abstract String getToolSignature(); - - /** - * Returns the name of learning design as it should be saved. - * Should be overridden by all subclasses. - * - * @return name of learning design - */ - protected abstract String getLearningDesignName(); - - /** - * Tests tool authoring. - * Should be overridden by all subclasses. - */ - protected abstract void authoringTest() throws Exception; - - /** - * Tests tool learning. Always should begin with setUpLearning() and end up with tearDownLearning() methods. - * Should be overridden by all subclasses. - */ - protected abstract void learningTest() throws Exception; - - /** - * Tests tool monitoring. - * Should be overridden by all subclasses. - */ - protected abstract void monitoringTest() throws Exception; + } - /** - * Opens up all authoring windows. Should be done before testing tool's - * authoring. - * - * @return Map containing contentFolderID and toolContentID - * @throws Exception - */ - protected Map setUpAuthoring() throws Exception { - // open authoring canvas - selenium.click("//div[@id='header-my-courses']//div[@class='tab-middle-highlight']/a"); - selenium.waitForPopUp("aWindow", "10000"); + /** + * Our main test class. Currently it tests authoring, learning and + * monitoring sequentially one-by-one. Also it relies on the fact that you + * store new LD in authoring (otherwise you should reimplement this method). + * + * @throws Exception + */ + public void testEntireTool() throws Exception { + loginToLams(); - Integer userID = userManagementService.getUserByLogin(TestFrameworkConstants.USER_LOGIN).getUserId(); - String createUniqueContentFolderUrl = TestFrameworkConstants.WEB_APP_DIR - + "authoring/author.do?method=createUniqueContentFolder&userID=" - + userID; - final String createUniqueContentFolderId = "createUniqueContentFolderId"; - selenium.openWindow(createUniqueContentFolderUrl, createUniqueContentFolderId); - selenium.waitForPopUp(createUniqueContentFolderId, "10000"); - selenium.selectWindow(createUniqueContentFolderId); - String wddxPacket = selenium.getEval("this.browserbot.getDocument().getElementsByTagName('body')[0].innerHTML"); - final String contentFolderID = this.extractFolderIDFromWDDXPacket(wddxPacket); - selenium.close(); - selenium.selectWindow(null); + //Authoring part + Map contentDetails = setUpAuthoring(); + authoringTest(); + storeLearningDesign(contentDetails); - Tool tool = toolDAO.getToolBySignature(getToolSignature()); - String getToolContentUrl = TestFrameworkConstants.WEB_APP_DIR - + "authoring/author.do?method=getToolContentID&toolID=" - + tool.getToolId(); - final String getToolContentId = "getToolContentId"; - selenium.openWindow(getToolContentUrl, getToolContentId); - selenium.waitForPopUp(getToolContentId, "10000"); - selenium.selectWindow(getToolContentId); - wddxPacket = selenium.getEval("this.browserbot.getDocument().getElementsByTagName('body')[0].innerHTML"); - final String toolContentID = this.extractToolContentIDFromWDDXPacket(wddxPacket); - selenium.close(); - selenium.selectWindow(null); + createNewLesson(); - String openToolUrl = TestFrameworkConstants.WEB_APP_DIR + tool.getAuthorUrl() + "?mode=author" - + "&toolContentID=" + toolContentID + "&contentFolderID=" - + contentFolderID; - final String openToolId = "openToolId"; - selenium.openWindow(openToolUrl.toString(), openToolId); - selenium.waitForPopUp(openToolId, "10000"); - selenium.selectWindow(openToolId); + //Learning part + learningTest(); - return new HashMap() {{ - put("contentFolderID", contentFolderID); - put("toolContentID", toolContentID); - }}; - } + //Monitoring part + openToolMonitor(); + monitoringTest(); + closeToolMonitor(); + } - /** - * Stores learning design. Uses getLearningDesignName() as a new design name. - */ - protected void storeLearningDesign(Map contentDetails) { - //closes tool authoring screen - selenium.click("//span[@class='okIcon']"); - selenium.waitForPageToLoad("10000"); - selenium.close(); - - //closes Flash authoring screen - selenium.selectWindow("aWindow"); - selenium.close(); - selenium.selectWindow(null); - - final String storeLearningDesignUrl = TestFrameworkConstants.WEB_APP_DIR + "servlet/authoring/storeLearningDesignDetails"; - String designDetails = constructWddxDesign(contentDetails); - //callback function is aimed to let Selenium wait till StoreLDServlet finishes its work - selenium.runScript("$.post(\"" + storeLearningDesignUrl + "\", " + - "\"" + designDetails + "\", " + - "function(data){ return data; }" + - ");"); - selenium.selectWindow(null); - } - - /** - * Beware this method might work wrong (due to the CloudWizard's hidden/visible root element) - * - * @throws Exception - */ - protected void createNewLesson() throws Exception { - Long lastCreatedLessonId = getLastCreatedLessonId(true); - DefaultSeleniumFlex flexSelenium = (DefaultSeleniumFlex) selenium; - - User user = userManagementService.getUserByLogin(TestFrameworkConstants.USER_LOGIN); - Workspace workspace = (Workspace) activityDAO.find(Workspace.class, user.getWorkspace().getWorkspaceId()); - Integer workspaceFolderID = workspace.getDefaultFolder().getWorkspaceFolderId(); - List titles = learningDesignDAO.getLearningDesignTitlesByWorkspaceFolder(workspaceFolderID); - assertTrue("There is no stored learning design", titles.size() > 0); - //TODO receive sorted titles list from the server because if LD was imported it's not sorted alphabetically - Collections.sort(titles, String.CASE_INSENSITIVE_ORDER); - int count = 1; - for (String title : titles) { - if (title.equals(learningDesignName)) { - break; - } - count++; - } - assertTrue("There isn't learning design with name " + learningDesignName,count <= titles.size()); - - flexSelenium.click("link=Add Lesson"); - Thread.sleep(6000); - // flexObjId is now setted to "cloudWizard" by default, change this if - // you want to use another one - // flexSelenium.flexSetFlexObjID("cloudWizard"); - waitForFlexExists("workspaceTree", 20, flexSelenium); - assertTrue(flexSelenium.getFlexEnabled("startButton").equals("true")); + /** + * Returns tool's signature. This method should be overridden by all + * subclasses. + * + * @return tool's signature + */ + protected abstract String getToolSignature(); - flexSelenium.flexSelectIndex("workspaceTree", String.valueOf(count)); -// flexSelenium.flexType("resourceName_txi", "bueno"); - flexSelenium.flexClick("startButton"); - Thread.sleep(5000); - assertTrue("Assertion failed. Lesson has *not* been created", lastCreatedLessonId < getLastCreatedLessonId(true)); + /** + * Returns the name of learning design as it should be saved. Should be + * overridden by all subclasses. + * + * @return name of learning design + */ + protected abstract String getLearningDesignName(); - //TODO fix CloudWizard or define offset checking for lesson's LD name - Long lessonId = getLastCreatedLessonId(false); - String lessonTitle = lessonDAO.getLesson(lessonId).getLearningDesign().getTitle(); - assertTrue("Tests aborted due to the problem with CloudWizard's root element problem. Please, restart tests", learningDesignName.equals(lessonTitle)); - } - - /** - * Prepares learning environment. Should be invoked each time learning is going to be tested. - * @throws InterruptedException - */ - protected void setUpLearning() throws InterruptedException { - selenium.runScript("openLearner(" + getLastCreatedLessonId(false) + ")"); - selenium.waitForPopUp("lWindow", "30000"); - selenium.selectWindow("lWindow"); - waitForElementPresent("contentFrame"); - selenium.selectFrame("contentFrame"); - } - - /** - * Shuts up learning environment. Should be invoked each time learning testing is done. - */ - protected void tearDownLearning() { - selenium.close(); - selenium.selectWindow(null); - } + /** + * Tests tool authoring. Should be overridden by all subclasses. + */ + protected abstract void authoringTest() throws Exception; - /** - * Launches Lams monitor, followed by tool's monitor popup. - */ - protected void openToolMonitor() { - Long lastCreatedLessonId = getLastCreatedLessonId(false); - LearningDesign learningDesign = lessonDAO.getLesson(lastCreatedLessonId).getLearningDesign(); - String contentFolderID = learningDesign.getContentFolderID(); - Activity activity = learningDesign.getFirstActivity(); - // doing this to prevent CGILib initialization exception - ToolActivity toolActivity = (ToolActivity) activityDAO.getActivityByActivityId(activity.getActivityId()); - - selenium.runScript("openMonitorLesson(" + lastCreatedLessonId + ")"); - selenium.waitForPopUp("mWindow", "15000"); + /** + * Tests tool learning. Always should begin with setUpLearning() and end up + * with tearDownLearning() methods. Should be overridden by all subclasses. + */ + protected abstract void learningTest() throws Exception; - // openning tool monitor popup - Tool tool = toolDAO.getToolBySignature(getToolSignature()); - String monitorUrl = TestFrameworkConstants.WEB_APP_DIR + tool.getMonitorUrl() - + "?toolContentID=" + toolActivity.getToolContentId() - + "&contentFolderID=" + contentFolderID; - final String monitorId = "monitorId"; - selenium.openWindow(monitorUrl, monitorId); - selenium.waitForPopUp(monitorId, "50000"); - selenium.selectWindow(monitorId); - } + /** + * Tests tool monitoring. Should be overridden by all subclasses. + */ + protected abstract void monitoringTest() throws Exception; - /** - * Closes Lams monitor. (Optional activity) - */ - protected void closeToolMonitor() { - selenium.close(); - selenium.selectWindow(null); + /** + * Opens up all authoring windows. Should be done before testing tool's + * authoring. + * + * @return Map containing contentFolderID and toolContentID + * @throws Exception + */ + protected Map setUpAuthoring() throws Exception { + // open authoring canvas + selenium.click("//div[@id='header-my-courses']//div[@class='tab-middle-highlight']/a"); + selenium.waitForPopUp("aWindow", "10000"); + + Integer userID = userManagementService.getUserByLogin(TestFrameworkConstants.USER_LOGIN).getUserId(); + String createUniqueContentFolderUrl = TestFrameworkConstants.WEB_APP_DIR + + "authoring/author.do?method=createUniqueContentFolder&userID=" + userID; + final String createUniqueContentFolderId = "createUniqueContentFolderId"; + selenium.openWindow(createUniqueContentFolderUrl, createUniqueContentFolderId); + selenium.waitForPopUp(createUniqueContentFolderId, "10000"); + selenium.selectWindow(createUniqueContentFolderId); + String wddxPacket = selenium.getEval("this.browserbot.getDocument().getElementsByTagName('body')[0].innerHTML"); + final String contentFolderID = this.extractFolderIDFromWDDXPacket(wddxPacket); + selenium.close(); + selenium.selectWindow(null); + + Tool tool = toolDAO.getToolBySignature(getToolSignature()); + String getToolContentUrl = TestFrameworkConstants.WEB_APP_DIR + + "authoring/author.do?method=getToolContentID&toolID=" + tool.getToolId(); + final String getToolContentId = "getToolContentId"; + selenium.openWindow(getToolContentUrl, getToolContentId); + selenium.waitForPopUp(getToolContentId, "10000"); + selenium.selectWindow(getToolContentId); + wddxPacket = selenium.getEval("this.browserbot.getDocument().getElementsByTagName('body')[0].innerHTML"); + final String toolContentID = this.extractToolContentIDFromWDDXPacket(wddxPacket); + selenium.close(); + selenium.selectWindow(null); + + String openToolUrl = TestFrameworkConstants.WEB_APP_DIR + tool.getAuthorUrl() + "?mode=author" + + "&toolContentID=" + toolContentID + "&contentFolderID=" + contentFolderID; + final String openToolId = "openToolId"; + selenium.openWindow(openToolUrl.toString(), openToolId); + selenium.waitForPopUp(openToolId, "10000"); + selenium.selectWindow(openToolId); + + return new HashMap() { + { + put("contentFolderID", contentFolderID); + put("toolContentID", toolContentID); + } + }; + } + + /** + * Stores learning design. Uses getLearningDesignName() as a new design + * name. + */ + protected void storeLearningDesign(Map contentDetails) { + //closes tool authoring screen + selenium.click("//span[@class='okIcon']"); + selenium.waitForPageToLoad("10000"); + selenium.close(); + + //closes Flash authoring screen + selenium.selectWindow("aWindow"); + selenium.close(); + selenium.selectWindow(null); + + final String storeLearningDesignUrl = TestFrameworkConstants.WEB_APP_DIR + + "servlet/authoring/storeLearningDesignDetails"; + String designDetails = constructWddxDesign(contentDetails); + //callback function is aimed to let Selenium wait till StoreLDServlet finishes its work + selenium.runScript("$.post(\"" + storeLearningDesignUrl + "\", " + "\"" + designDetails + "\", " + + "function(data){ return data; }" + ");"); + selenium.selectWindow(null); + } + + /** + * Beware this method might work wrong (due to the CloudWizard's + * hidden/visible root element) + * + * @throws Exception + */ + protected void createNewLesson() throws Exception { + Long lastCreatedLessonId = getLastCreatedLessonId(true); + DefaultSeleniumFlex flexSelenium = (DefaultSeleniumFlex) selenium; + + User user = userManagementService.getUserByLogin(TestFrameworkConstants.USER_LOGIN); + Workspace workspace = (Workspace) activityDAO.find(Workspace.class, user.getWorkspace().getWorkspaceId()); + Integer workspaceFolderID = workspace.getDefaultFolder().getWorkspaceFolderId(); + List titles = learningDesignDAO.getLearningDesignTitlesByWorkspaceFolder(workspaceFolderID); + assertTrue("There is no stored learning design", titles.size() > 0); + //TODO receive sorted titles list from the server because if LD was imported it's not sorted alphabetically + Collections.sort(titles, String.CASE_INSENSITIVE_ORDER); + int count = 1; + for (String title : titles) { + if (title.equals(learningDesignName)) { + break; + } + count++; } - - - /** */ - protected void loginToLams() throws Exception { - selenium.open(TestFrameworkConstants.WEB_APP_DIR); - selenium.type("j_username", TestFrameworkConstants.USER_LOGIN); - selenium.type("j_password", TestFrameworkConstants.USER_PASSWORD); - selenium.click("link=Login"); - selenium.waitForPageToLoad("10000"); - Thread.sleep(3000); - } + assertTrue("There isn't learning design with name " + learningDesignName, count <= titles.size()); - // ***************************************************************************** - // methods for testing Flex - // ***************************************************************************** + flexSelenium.click("link=Add Lesson"); + Thread.sleep(6000); + // flexObjId is now setted to "cloudWizard" by default, change this if + // you want to use another one + // flexSelenium.flexSetFlexObjID("cloudWizard"); + waitForFlexExists("workspaceTree", 20, flexSelenium); + assertTrue(flexSelenium.getFlexEnabled("startButton").equals("true")); - /** - * Waits till element will be presented on a page. - * - * @param locator - an element locator - * @throws InterruptedException - */ - protected void waitForElementPresent(String locator) throws InterruptedException { - for (int second = 0;; second++) { - if (second >= 30) { - fail("Timeout while waiting for element with locator " + locator); - } - try { - if (selenium.isElementPresent(locator)) { - break; - } - } catch (Exception e) { - } - Thread.sleep(1000); + flexSelenium.flexSelectIndex("workspaceTree", String.valueOf(count)); + // flexSelenium.flexType("resourceName_txi", "bueno"); + flexSelenium.flexClick("startButton"); + Thread.sleep(5000); + assertTrue("Assertion failed. Lesson has *not* been created", + lastCreatedLessonId < getLastCreatedLessonId(true)); + + //TODO fix CloudWizard or define offset checking for lesson's LD name + Long lessonId = getLastCreatedLessonId(false); + String lessonTitle = lessonDAO.getLesson(lessonId).getLearningDesign().getTitle(); + assertTrue("Tests aborted due to the problem with CloudWizard's root element problem. Please, restart tests", + learningDesignName.equals(lessonTitle)); + } + + /** + * Prepares learning environment. Should be invoked each time learning is + * going to be tested. + * + * @throws InterruptedException + */ + protected void setUpLearning() throws InterruptedException { + selenium.runScript("openLearner(" + getLastCreatedLessonId(false) + ")"); + selenium.waitForPopUp("lWindow", "30000"); + selenium.selectWindow("lWindow"); + waitForElementPresent("contentFrame"); + selenium.selectFrame("contentFrame"); + } + + /** + * Shuts up learning environment. Should be invoked each time learning + * testing is done. + */ + protected void tearDownLearning() { + selenium.close(); + selenium.selectWindow(null); + } + + /** + * Launches Lams monitor, followed by tool's monitor popup. + */ + protected void openToolMonitor() { + Long lastCreatedLessonId = getLastCreatedLessonId(false); + LearningDesign learningDesign = lessonDAO.getLesson(lastCreatedLessonId).getLearningDesign(); + String contentFolderID = learningDesign.getContentFolderID(); + Activity activity = learningDesign.getFirstActivity(); + // doing this to prevent CGILib initialization exception + ToolActivity toolActivity = (ToolActivity) activityDAO.getActivityByActivityId(activity.getActivityId()); + + selenium.runScript("openMonitorLesson(" + lastCreatedLessonId + ")"); + selenium.waitForPopUp("mWindow", "15000"); + + // openning tool monitor popup + Tool tool = toolDAO.getToolBySignature(getToolSignature()); + String monitorUrl = TestFrameworkConstants.WEB_APP_DIR + tool.getMonitorUrl() + "?toolContentID=" + + toolActivity.getToolContentId() + "&contentFolderID=" + contentFolderID; + final String monitorId = "monitorId"; + selenium.openWindow(monitorUrl, monitorId); + selenium.waitForPopUp(monitorId, "50000"); + selenium.selectWindow(monitorId); + } + + /** + * Closes Lams monitor. (Optional activity) + */ + protected void closeToolMonitor() { + selenium.close(); + selenium.selectWindow(null); + } + + /** */ + protected void loginToLams() throws Exception { + selenium.open(TestFrameworkConstants.WEB_APP_DIR); + selenium.type("j_username", TestFrameworkConstants.USER_LOGIN); + selenium.type("j_password", TestFrameworkConstants.USER_PASSWORD); + selenium.click("link=Login"); + selenium.waitForPageToLoad("10000"); + Thread.sleep(3000); + } + + // ***************************************************************************** + // methods for testing Flex + // ***************************************************************************** + + /** + * Waits till element will be presented on a page. + * + * @param locator + * - an element locator + * @throws InterruptedException + */ + protected void waitForElementPresent(String locator) throws InterruptedException { + for (int second = 0;; second++) { + if (second >= 30) { + fail("Timeout while waiting for element with locator " + locator); + } + try { + if (selenium.isElementPresent(locator)) { + break; } + } catch (Exception e) { + } + Thread.sleep(1000); } - + } + public String getText() { - return selenium.getEval("this.page().bodyText()"); + return selenium.getEval("this.page().bodyText()"); } - - protected void waitForFlexExists(String objectID, int timeout, DefaultSeleniumFlex selenium) throws Exception { - while (timeout > 0 && !selenium.getFlexExists(objectID).contains("true")) { - Thread.sleep(1000); - timeout--; - } - if (timeout == 0) { - throw new Exception("waitForFlexExists flex object:" + objectID + " Timed Out"); - } + + protected void waitForFlexExists(String objectID, int timeout, DefaultSeleniumFlex selenium) throws Exception { + while (timeout > 0 && !selenium.getFlexExists(objectID).contains("true")) { + Thread.sleep(1000); + timeout--; } + if (timeout == 0) { + throw new Exception("waitForFlexExists flex object:" + objectID + " Timed Out"); + } + } - protected void waitForFlexVisible(String objectID, int timeout, - DefaultSeleniumFlex selenium) throws Exception { - while (timeout > 0 && !selenium.getFlexVisible(objectID).equals("true")) { - Thread.sleep(1000); - timeout--; - } - if (timeout == 0) { - throw new Exception("waitForFlexVisible flex object:" + objectID - + " Timed Out"); - } + protected void waitForFlexVisible(String objectID, int timeout, DefaultSeleniumFlex selenium) throws Exception { + while (timeout > 0 && !selenium.getFlexVisible(objectID).equals("true")) { + Thread.sleep(1000); + timeout--; } + if (timeout == 0) { + throw new Exception("waitForFlexVisible flex object:" + objectID + " Timed Out"); + } + } - + // ***************************************************************************** + // auxiliary methods + // ***************************************************************************** - // ***************************************************************************** - // auxiliary methods - // ***************************************************************************** - - /** - * Returns lessonId of the last created lesson. - * - * @return id - */ - private Long getLastCreatedLessonId(boolean returnNegative) { - Integer userID = userManagementService.getUserByLogin(TestFrameworkConstants.USER_LOGIN).getUserId(); - List lessonsCreatedByUser = lessonDAO.getLessonsCreatedByUser(userID); - List lessonsWithLDName = new ArrayList(); - for (Lesson lesson : lessonsCreatedByUser) { - if (lesson.getLessonName().equals(learningDesignName)){ - lessonsWithLDName.add(lesson); - } - } - if (lessonsWithLDName.size() == 0) { - if (returnNegative) { - return new Long(-1); - } else { - fail("Lesson creation failed."); - } - } - - Lesson lastCreatedLesson = lessonsCreatedByUser.iterator().next(); - for (Lesson lesson : lessonsWithLDName) { - if (lesson.getCreateDateTime().after(lastCreatedLesson.getCreateDateTime()) ){ - lastCreatedLesson = lesson; - } - } - return lastCreatedLesson.getLessonId(); + /** + * Returns lessonId of the last created lesson. + * + * @return id + */ + private Long getLastCreatedLessonId(boolean returnNegative) { + Integer userID = userManagementService.getUserByLogin(TestFrameworkConstants.USER_LOGIN).getUserId(); + List lessonsCreatedByUser = lessonDAO.getLessonsCreatedByUser(userID); + List lessonsWithLDName = new ArrayList(); + for (Lesson lesson : lessonsCreatedByUser) { + if (lesson.getLessonName().equals(learningDesignName)) { + lessonsWithLDName.add(lesson); + } } + if (lessonsWithLDName.size() == 0) { + if (returnNegative) { + return new Long(-1); + } else { + fail("Lesson creation failed."); + } + } - /** - * Given a WDDX packet in our normal format, gets the content folder from within - * the <var - * name='messageValue'><string>num</string></var> - * - * @param wddxPacket - * @return id - */ - private String extractFolderIDFromWDDXPacket(String wddxPacket) { - wddxPacket = wddxPacket.toLowerCase(); - int indexMessageValue = wddxPacket.indexOf(""); - assertTrue(" string not found", indexMessageValue > 0); - int endIndexMessageValue = wddxPacket.indexOf("", indexMessageValue); - return wddxPacket.substring(indexMessageValue - + "".length(), endIndexMessageValue); + Lesson lastCreatedLesson = lessonsCreatedByUser.iterator().next(); + for (Lesson lesson : lessonsWithLDName) { + if (lesson.getCreateDateTime().after(lastCreatedLesson.getCreateDateTime())) { + lastCreatedLesson = lesson; + } } + return lastCreatedLesson.getLessonId(); + } - /** - * Given a WDDX packet in our normal format, gets the tool content id from within - * the <var - * name='messageValue'><number>num</number></var> - * - * @param wddxPacket - * @return id - */ - private String extractToolContentIDFromWDDXPacket(String wddxPacket) { - wddxPacket = wddxPacket.toLowerCase(); - int indexMessageValue = wddxPacket.indexOf(""); - assertTrue(" string not found", indexMessageValue > 0); - int endIndexMessageValue = wddxPacket.indexOf(".0", indexMessageValue); - String idString = wddxPacket.substring(indexMessageValue - + "".length(), - endIndexMessageValue); - try { - Long.parseLong(idString); - return idString; - } catch (NumberFormatException e) { - fail("Unable to get toolContentID from WDDX packet. Format exception. String was " - + idString); - } - return null; + /** + * Given a WDDX packet in our normal format, gets the content folder from + * within the <var + * name='messageValue'><string>num</string></var> + * + * @param wddxPacket + * @return id + */ + private String extractFolderIDFromWDDXPacket(String wddxPacket) { + wddxPacket = wddxPacket.toLowerCase(); + int indexMessageValue = wddxPacket.indexOf(""); + assertTrue(" string not found", indexMessageValue > 0); + int endIndexMessageValue = wddxPacket.indexOf("", indexMessageValue); + return wddxPacket.substring(indexMessageValue + "".length(), + endIndexMessageValue); + } + + /** + * Given a WDDX packet in our normal format, gets the tool content id from + * within the <var + * name='messageValue'><number>num</number></var> + * + * @param wddxPacket + * @return id + */ + private String extractToolContentIDFromWDDXPacket(String wddxPacket) { + wddxPacket = wddxPacket.toLowerCase(); + int indexMessageValue = wddxPacket.indexOf(""); + assertTrue(" string not found", indexMessageValue > 0); + int endIndexMessageValue = wddxPacket.indexOf(".0", indexMessageValue); + String idString = wddxPacket.substring(indexMessageValue + "".length(), + endIndexMessageValue); + try { + Long.parseLong(idString); + return idString; + } catch (NumberFormatException e) { + fail("Unable to get toolContentID from WDDX packet. Format exception. String was " + idString); } + return null; + } - /** - * Constructs wddx packet(the same as Flash creates) which contains LD details. - * - * @return - */ - private String constructWddxDesign(Map contentDetails) { - User user = userManagementService.getUserByLogin(TestFrameworkConstants.USER_LOGIN); - Tool tool = toolDAO.getToolBySignature(getToolSignature()); - - //checks if another LD with the same name exists. If so then trying to create unique one. - Workspace workspace = (Workspace) activityDAO.find(Workspace.class, user.getWorkspace().getWorkspaceId()); - Integer workspaceFolderID = workspace.getDefaultFolder().getWorkspaceFolderId(); - List existingTitles = learningDesignDAO.getLearningDesignTitlesByWorkspaceFolder(workspaceFolderID); - if (existingTitles.contains(learningDesignName)) { - int i = 2; - String tempLearningDesignName; - do { - tempLearningDesignName = learningDesignName + "(" + i++ + ")"; - } while (existingTitles.contains(tempLearningDesignName)); - learningDesignName = tempLearningDesignName; + /** + * Constructs wddx packet(the same as Flash creates) which contains LD + * details. + * + * @return + */ + private String constructWddxDesign(Map contentDetails) { + User user = userManagementService.getUserByLogin(TestFrameworkConstants.USER_LOGIN); + Tool tool = toolDAO.getToolBySignature(getToolSignature()); + + //checks if another LD with the same name exists. If so then trying to create unique one. + Workspace workspace = (Workspace) activityDAO.find(Workspace.class, user.getWorkspace().getWorkspaceId()); + Integer workspaceFolderID = workspace.getDefaultFolder().getWorkspaceFolderId(); + List existingTitles = learningDesignDAO.getLearningDesignTitlesByWorkspaceFolder(workspaceFolderID); + if (existingTitles.contains(learningDesignName)) { + int i = 2; + String tempLearningDesignName; + do { + tempLearningDesignName = learningDesignName + "(" + i++ + ")"; + } while (existingTitles.contains(tempLearningDesignName)); + learningDesignName = tempLearningDesignName; + } + + // searching for the template activity + ToolActivity templateActivity = null; + for (Object activityObject : activityDAO.getAllActivities()) { + if (activityObject instanceof ToolActivity) { + ToolActivity activity = (ToolActivity) activityObject; + if ((activity.getLearningDesign() == null) && activity.getTool().getToolId().equals(tool.getToolId())) { + templateActivity = activity; + break; } - - // searching for the template activity - ToolActivity templateActivity = null; - for (Object activityObject : activityDAO.getAllActivities()) { - if (activityObject instanceof ToolActivity) { - ToolActivity activity = (ToolActivity) activityObject; - if ((activity.getLearningDesign() == null) - && activity.getTool().getToolId().equals(tool.getToolId())) { - templateActivity = activity; - } - } - } - - String design = - "" + - "
" + - "" + - "" + - "" + - "" + - "" + - "" + - "" + - "" + - "" + - "" + - "string_null_value" + - "string_null_value" + - "" + tool.getToolId() + "" + - "" + contentDetails.get("toolContentID") + "" + - "" + tool.getToolSignature() + "" + - "" + tool.getToolDisplayName() + "" + - "" + tool.getHelpUrl() + "" + - "" + tool.getAuthorUrl() + "" + - "" + - "" + templateActivity.getGroupingSupportType() + "" + - "2009-6-12T1:24:50+3:0" + - "" + - "" + - "" + - "-111111" + - "-111111" + - "" + templateActivity.getLibraryActivityUiImage() + "" + - "124" + - "132" + - "" + templateActivity.getHelpText() + "" + - "" + templateActivity.getDescription() + "" + - "" + templateActivity.getTitle() + "" + - "" + templateActivity.getLearningLibrary().getLearningLibraryId() + "" + - //works with activityUIID=1 but may be we should generate unique one. - "1" + - "" + templateActivity.getActivityCategoryID() + "" + - "" + templateActivity.getActivityId() + "" + - "" + templateActivity.getActivityTypeId() + "" + - "" + - "" + - "" + - "" + contentDetails.get("contentFolderID") + "" + - "2009-6-24T22:45:24+3:0" + - "" + workspaceFolderID + "" + - "1" + - "0" + - "" + - "" + - "" + user.getUserId() + "" + - "" + learningDesignName + "" + - "-111111" + - "1" + - "" + - "" + - ""; - return design; + } } - // /** - // * Given a WDDX packet in our normal format, return the map object in the - // messageValue parameter. This should - // * contain any returned ids. - // * - // * @param wddxPacket - // * @return Map - // */ - // protected String extractIdMapFromWDDXPacket(String wddxPacket) { - // - // Object obj = null; - // try { - // obj = WDDXProcessor.deserialize(wddxPacket); - // } catch (WddxDeserializationException e1) { - // fail("WddxDeserializationException " + e1.getMessage()); - // e1.printStackTrace(); - // } - // // WDDXProcessor.convertToBoolean(table, key) - // - // Map map = (Map) obj; - // Object uniqueContentFolderObj = map.get("createUniqueContentFolder"); - // assertNotNull("createUniqueContentFolder object found", - // uniqueContentFolderObj); - // if (!String.class.isInstance(uniqueContentFolderObj)) { - // fail("createUniqueContentFolder is not a String - try extractIdFromWDDXPacket(packet)"); - // } - // - // return (String) uniqueContentFolderObj; - // } + String design = "" + "
" + "" + "" + + "" + + "" + + "" + + "" + "" + + "" + "" + "" + + "string_null_value" + + "string_null_value" + "" + + tool.getToolId() + + "" + + "" + + contentDetails.get("toolContentID") + + "" + + "" + + tool.getToolSignature() + + "" + + "" + + tool.getToolDisplayName() + + "" + + "" + + tool.getHelpUrl() + + "" + + "" + + tool.getAuthorUrl() + + "" + + "" + + "" + + templateActivity.getGroupingSupportType() + + "" + + "2009-6-12T1:24:50+3:0" + + "" + + "" + + "" + + "-111111" + + "-111111" + + "" + + templateActivity.getLibraryActivityUiImage() + + "" + + "124" + + "132" + + "" + + templateActivity.getHelpText() + + "" + + "" + + templateActivity.getDescription() + + "" + + "" + + templateActivity.getTitle() + + "" + + "" + + templateActivity.getLearningLibrary().getLearningLibraryId() + + "" + + + //works with activityUIID=1 but may be we should generate unique one. + "1" + + "" + + templateActivity.getActivityCategoryID() + + "" + + "" + + templateActivity.getActivityId() + + "" + + "" + + templateActivity.getActivityTypeId() + + "" + + "" + + "" + + "" + + "" + + contentDetails.get("contentFolderID") + + "" + + "2009-6-24T22:45:24+3:0" + + "" + + workspaceFolderID + + "" + + "1" + + "0" + + "" + + "" + + "" + + user.getUserId() + + "" + + "" + + learningDesignName + + "" + + "-111111" + + "1" + "" + "" + ""; + return design; + } + // /** + // * Given a WDDX packet in our normal format, return the map object in the + // messageValue parameter. This should + // * contain any returned ids. + // * + // * @param wddxPacket + // * @return Map + // */ + // protected String extractIdMapFromWDDXPacket(String wddxPacket) { + // + // Object obj = null; + // try { + // obj = WDDXProcessor.deserialize(wddxPacket); + // } catch (WddxDeserializationException e1) { + // fail("WddxDeserializationException " + e1.getMessage()); + // e1.printStackTrace(); + // } + // // WDDXProcessor.convertToBoolean(table, key) + // + // Map map = (Map) obj; + // Object uniqueContentFolderObj = map.get("createUniqueContentFolder"); + // assertNotNull("createUniqueContentFolder object found", + // uniqueContentFolderObj); + // if (!String.class.isInstance(uniqueContentFolderObj)) { + // fail("createUniqueContentFolder is not a String - try extractIdFromWDDXPacket(packet)"); + // } + // + // return (String) uniqueContentFolderObj; + // } + }