Index: TestHarness4LAMS2/.cvsignore =================================================================== diff -u -r41955af92f3e17f2f11c07d94ae1a5f92b0d998f -r159c15ed2f6cc7c8f273367d199b196effd5f340 --- TestHarness4LAMS2/.cvsignore (.../.cvsignore) (revision 41955af92f3e17f2f11c07d94ae1a5f92b0d998f) +++ TestHarness4LAMS2/.cvsignore (.../.cvsignore) (revision 159c15ed2f6cc7c8f273367d199b196effd5f340) @@ -1 +1,2 @@ build +*.users Index: TestHarness4LAMS2/adminTest1.properties =================================================================== diff -u -r41955af92f3e17f2f11c07d94ae1a5f92b0d998f -r159c15ed2f6cc7c8f273367d199b196effd5f340 --- TestHarness4LAMS2/adminTest1.properties (.../adminTest1.properties) (revision 41955af92f3e17f2f11c07d94ae1a5f92b0d998f) +++ TestHarness4LAMS2/adminTest1.properties (.../adminTest1.properties) (revision 159c15ed2f6cc7c8f273367d199b196effd5f340) @@ -19,13 +19,6 @@ #----------------------------------------------------------------- # CourseId = 1 -#----------------------------------------------------------------- -# If UserCreated is set to true, all the settings regarding user creation will be ignored -# If not specified, the value of the property will be false. -# If CourseId is not set, this value will be always considered false -#----------------------------------------------------------------- -# UserCreated = true - #-------------------------------------------------------------- # sysadmin login info #-------------------------------------------------------------- Index: TestHarness4LAMS2/authorTest1.properties =================================================================== diff -u -r41955af92f3e17f2f11c07d94ae1a5f92b0d998f -r159c15ed2f6cc7c8f273367d199b196effd5f340 --- TestHarness4LAMS2/authorTest1.properties (.../authorTest1.properties) (revision 41955af92f3e17f2f11c07d94ae1a5f92b0d998f) +++ TestHarness4LAMS2/authorTest1.properties (.../authorTest1.properties) (revision 159c15ed2f6cc7c8f273367d199b196effd5f340) @@ -20,7 +20,7 @@ # Set the base name of the author # If it's not specified, "Author" will be used #------------------------------------------------------------------ -# BaseAuthorName = Shaun +# BaseAuthorName = Author #------------------------------------------------------------ # Set delays (in secounds) which are the amount of idle time between calls to the server Index: TestHarness4LAMS2/learnerTest1.properties =================================================================== diff -u -r41955af92f3e17f2f11c07d94ae1a5f92b0d998f -r159c15ed2f6cc7c8f273367d199b196effd5f340 --- TestHarness4LAMS2/learnerTest1.properties (.../learnerTest1.properties) (revision 41955af92f3e17f2f11c07d94ae1a5f92b0d998f) +++ TestHarness4LAMS2/learnerTest1.properties (.../learnerTest1.properties) (revision 159c15ed2f6cc7c8f273367d199b196effd5f340) @@ -27,13 +27,6 @@ # LearnerOffset = 101 #------------------------------------------------------------------ -# UserIdOffSet set the start userId. It should be set when -# UserCreated set to be true in AdminTest while LessonId is not set -# in MonitorTest -#------------------------------------------------------------------ -# UserIdOffset = 84 - -#------------------------------------------------------------------ # Set the base name of the learners # If it's not specified, "Learner" will be used #------------------------------------------------------------------ Index: TestHarness4LAMS2/monitorTest1.properties =================================================================== diff -u -r41955af92f3e17f2f11c07d94ae1a5f92b0d998f -r159c15ed2f6cc7c8f273367d199b196effd5f340 --- TestHarness4LAMS2/monitorTest1.properties (.../monitorTest1.properties) (revision 41955af92f3e17f2f11c07d94ae1a5f92b0d998f) +++ TestHarness4LAMS2/monitorTest1.properties (.../monitorTest1.properties) (revision 159c15ed2f6cc7c8f273367d199b196effd5f340) @@ -29,12 +29,6 @@ #------------------------------------------------------------------ # BaseMonitorName = Ernie -#------------------------------------------------------------------ -# Set the user id of the monitor. -# It should be set if and only if LessonId is not set and UserCreated is true in adminTest -#------------------------------------------------------------------ -# UserId = 100 - #------------------------------------------------------------ # Set delays (in secounds) which are the amount of idle time between calls to the server # Delay is used to emulate the time monitors spent on watching where the learners are stuck ;-) Index: TestHarness4LAMS2/src/org/lamsfoundation/testharness/MockUser.java =================================================================== diff -u -r41955af92f3e17f2f11c07d94ae1a5f92b0d998f -r159c15ed2f6cc7c8f273367d199b196effd5f340 --- TestHarness4LAMS2/src/org/lamsfoundation/testharness/MockUser.java (.../MockUser.java) (revision 41955af92f3e17f2f11c07d94ae1a5f92b0d998f) +++ TestHarness4LAMS2/src/org/lamsfoundation/testharness/MockUser.java (.../MockUser.java) (revision 159c15ed2f6cc7c8f273367d199b196effd5f340) @@ -52,27 +52,23 @@ private static final String INDEX_PAGE_FLAG = "images/loading.gif"; private static final String USERNAME = "j_username"; - private static final String PASSWORD = "j_password"; + private static final String PASSWORD = "j_password";; - private static String indexPage; - protected AbstractTest test; protected String userId; protected String username; protected String password; + protected String role; protected WebConversation wc; - public MockUser(AbstractTest test, String username, String password, String userId) { + public MockUser(AbstractTest test, String username, String password, String role, String userId) { this.test = test; this.username = username; + this.role = role; this.password = password; this.userId = userId; } - public static void setIndexPage(String indexPageURL) { - MockUser.indexPage = indexPageURL; - } - private static String sha1(String plaintext) throws NoSuchAlgorithmException { MessageDigest md = MessageDigest.getInstance("SHA1"); return new String(Hex.encodeHex(md.digest(plaintext.getBytes()))); @@ -103,8 +99,7 @@ public void login() { try { wc = new WebConversation(); - WebResponse resp = (WebResponse) new Call(wc, test, username + " fetch index page", MockUser.indexPage) - .execute(); + WebResponse resp = (WebResponse) new Call(wc, test, username + " fetch index page", "").execute(); if (!MockUser.checkPageContains(resp, MockUser.LOGIN_PAGE_FLAG)) { MockUser.log.debug(resp.getText()); throw new TestHarnessException(username + " didn't get login page when hitting LAMS the first time"); @@ -178,4 +173,16 @@ } return form; } + + public boolean equals(Object o){ + return username.equals(((MockUser) o).username); + } + + public int hashCode(){ + return username.hashCode(); + } + + public String getRole() { + return role; + } } \ No newline at end of file Index: TestHarness4LAMS2/src/org/lamsfoundation/testharness/TestManager.java =================================================================== diff -u -r457bede6fb8b69e25fa9a899ed66a32407bf80e9 -r159c15ed2f6cc7c8f273367d199b196effd5f340 --- TestHarness4LAMS2/src/org/lamsfoundation/testharness/TestManager.java (.../TestManager.java) (revision 457bede6fb8b69e25fa9a899ed66a32407bf80e9) +++ TestHarness4LAMS2/src/org/lamsfoundation/testharness/TestManager.java (.../TestManager.java) (revision 159c15ed2f6cc7c8f273367d199b196effd5f340) @@ -22,13 +22,21 @@ */ package org.lamsfoundation.testharness; +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; import java.io.IOException; import java.io.InputStream; +import java.util.Collection; import java.util.LinkedList; import java.util.List; +import java.util.Map; import java.util.Properties; +import java.util.TreeMap; import java.util.concurrent.CountDownLatch; import org.apache.log4j.Logger; @@ -44,7 +52,7 @@ /** * @author Fei Yang, Marcin Cieslak */ -class TestManager { +public class TestManager { private static final Logger log = Logger.getLogger(TestManager.class); List testSuites = new LinkedList(); @@ -63,6 +71,7 @@ private static final String AUTHOR_PROPERTY_FILE = "AuthorTestPropertyFile"; private static final String MONITOR_PROPERTY_FILE = "MonitorTestPropertyFile"; private static final String LEARNER_PROPERTY_FILE = "LearnerTestPropertyFile"; + private static final String STORED_USERS_FILE = "UsersFile"; // common property keys of all the single tests(admin test, author test, monitor test, learner test) private static final String MIN_DELAY = "MinDelay"; @@ -73,7 +82,6 @@ private static final String CREATE_USER_URL = "CreateUserURL"; private static final String COURSE_NAME = "CourseName"; private static final String COURSE_ID = "CourseId"; - private static final String USER_CREATED = "UserCreated"; private static final String SYSADMIN_USERNAME = "SysadminUsername"; private static final String SYSADMIN_PASSWORD = "SysadminPassword"; @@ -89,7 +97,6 @@ private static final String START_LESSON_URL = "StartLessonURL"; private static final String LESSON_ID = "LessonId"; private static final String LESSON_NAME = "LessonName"; - private static final String USER_ID = "UserId"; private static final String BASE_MONITOR_NAME = "BaseMonitorName"; private static final String GET_LESSON_DETAILS_URL = "GetLessonDetailsURL"; private static final String GET_CA_URL = "GetContributeActivitiesURL"; @@ -106,7 +113,6 @@ private static final String GET_PROGRESS_URL = "GetFlashProgressDataURL"; private static final String LESSON_ENTRY_URL = "LessonEntryURL"; private static final String FILES_TO_UPLOAD = "FilesToUpload"; - private static final String USER_ID_OFFSET = "UserIdOffset"; public TestManager(String name) { this.testPropertyFileName = name; @@ -209,23 +215,21 @@ TestManager.log.info(finishedCount + " test suites finished and " + abortedCount + " aborted"); } - private AdminTest createAdminTest(String adminTestPropertyFileName) { + private AdminTest createAdminTest(String adminTestPropertyFileName, String storedUsersFileName) { String testName = TestManager.extractTestName(adminTestPropertyFileName); TestManager.log.info("Creating admin test " + testName); Properties adminTestProperties = TestManager.loadProperties(adminTestPropertyFileName); Integer courseId = TestManager.getIntegerProperty(adminTestPropertyFileName, adminTestProperties, TestManager.COURSE_ID, true); - Boolean userCreated = new Boolean(TestManager.getStringProperty(adminTestPropertyFileName, adminTestProperties, - TestManager.USER_CREATED, true)); Integer minDelay = TestManager.getIntegerProperty(adminTestPropertyFileName, adminTestProperties, TestManager.MIN_DELAY, true); Integer maxDelay = TestManager.getIntegerProperty(adminTestPropertyFileName, adminTestProperties, TestManager.MAX_DELAY, true); String createCourseURL = TestManager.getStringProperty(adminTestPropertyFileName, adminTestProperties, TestManager.CREATE_COURSE_URL, courseId != null); String createUserURL = TestManager.getStringProperty(adminTestPropertyFileName, adminTestProperties, - TestManager.CREATE_USER_URL, userCreated); + TestManager.CREATE_USER_URL, false); String courseName = TestManager.getStringProperty(adminTestPropertyFileName, adminTestProperties, TestManager.COURSE_NAME, true); String sysadminUsername = TestManager.getStringProperty(adminTestPropertyFileName, adminTestProperties, @@ -234,15 +238,15 @@ TestManager.SYSADMIN_PASSWORD, false); AdminTest test = new AdminTest(testName, minDelay, maxDelay, createCourseURL, createUserURL, - courseId == null ? null : courseId.toString(), userCreated, courseName); + courseId == null ? null : courseId.toString(), courseName, storedUsersFileName); - test.setUsers(new MockAdmin[] { new MockAdmin(test, sysadminUsername, sysadminPassword, null) }); + test.setUsers(new MockAdmin[] { new MockAdmin(test, sysadminUsername, sysadminPassword) }); TestManager.log.info("Finished creating admin test " + testName); return test; } - private AuthorTest createAuthorTest(String authorTestPropertyFileName) { + private AuthorTest createAuthorTest(String authorTestPropertyFileName, Map storedUsers) { String testName = TestManager.extractTestName(authorTestPropertyFileName); TestManager.log.info("Creating author test " + testName); @@ -265,13 +269,14 @@ baseAuthorName = baseAuthorName == null ? MockAuthor.DEFAULT_NAME : baseAuthorName; String username = TestUtil.buildName(testName, baseAuthorName, TestManager.MAX_USERNAME_LENGTH); - test.setUsers(new MockAuthor[] { new MockAuthor(test, username, username, null) }); + String userId = storedUsers.get(username); + test.setUsers(new MockAuthor[] { new MockAuthor(test, username, username, userId) }); TestManager.log.info("Finished creating author test " + testName); return test; } - private LearnerTest createLearnerTest(String learnerTestPropertyFileName) { + private LearnerTest createLearnerTest(String learnerTestPropertyFileName, Map storedUsers) { String testName = TestManager.extractTestName(learnerTestPropertyFileName); TestManager.log.info("Creating learner test:" + testName); @@ -300,22 +305,17 @@ TestManager.LESSON_ENTRY_URL, false); String filesToUpload = TestManager.getStringProperty(learnerTestPropertyFileName, learnerTestProperties, TestManager.FILES_TO_UPLOAD, false); - Integer userIdOffset = TestManager.getIntegerProperty(learnerTestPropertyFileName, learnerTestProperties, - TestManager.USER_ID_OFFSET, true); LearnerTest test = new LearnerTest(testName, minDelay, maxDelay, getLessonURL, getLearningDesignURL, joinLessonURL, getProgressURL, lessonEntryURL, filesToUpload == null ? null : filesToUpload.split(";")); - if (userIdOffset != null) { - userIdOffset--; - } MockLearner[] learners = new MockLearner[numberOfLearners]; for (int i = 0; i < numberOfLearners; i++) { baseLearnerName = baseLearnerName == null ? MockLearner.DEFAULT_NAME : baseLearnerName; String username = TestUtil.buildName(testName, baseLearnerName + (learnerOffset + i), TestManager.MAX_USERNAME_LENGTH); - String userId = userIdOffset == null ? null : (++userIdOffset).toString(); + String userId = storedUsers.get(username); learners[i] = new MockLearner(test, username, username, userId); } test.setUsers(learners); @@ -324,7 +324,7 @@ return test; } - private MonitorTest createMonitorTest(String monitorTestPropertyFileName) { + private MonitorTest createMonitorTest(String monitorTestPropertyFileName, Map storedUsers) { String testName = TestManager.extractTestName(monitorTestPropertyFileName); TestManager.log.info("Creating monitor test " + testName); @@ -353,43 +353,47 @@ TestManager.LESSON_NAME, true); String baseMonitorName = TestManager.getStringProperty(monitorTestPropertyFileName, monitorTestProperties, TestManager.BASE_MONITOR_NAME, true); - Integer userId = TestManager.getIntegerProperty(monitorTestPropertyFileName, monitorTestProperties, - TestManager.USER_ID, true); MonitorTest test = new MonitorTest(testName, minDelay, maxDelay, initLessonURL, createLessonClassURL, startLessonURL, getLessonDetailsURL, getContributeActivitiesURL, getLearningDesignDetailsURL, getAllLearnersProgressURL, lsName, lsId == null ? null : lsId.toString()); baseMonitorName = baseMonitorName == null ? MockMonitor.DEFAULT_NAME : baseMonitorName; String username = TestUtil.buildName(testName, baseMonitorName, TestManager.MAX_USERNAME_LENGTH); - test.setUsers(new MockMonitor[] { new MockMonitor(test, username, username, userId == null ? null : userId - .toString()) }); + String userId = storedUsers.get(username); + test.setUsers(new MockMonitor[] { new MockMonitor(test, username, username, userId) }); TestManager.log.info("Finished creating monitor test " + testName); return test; } private TestSuite createTestSuite(Properties testProperties, int suiteIndex) { TestManager.log.info("Creating test suite " + suiteIndex); + String targetServer = TestManager.getStringProperty(testPropertyFileName, testProperties, TestManager.buildPropertyKey(TestManager.TARGET_SERVER, suiteIndex), true); String contextRoot = TestManager.getStringProperty(testPropertyFileName, testProperties, TestManager.buildPropertyKey(TestManager.CONTEXT_ROOT, suiteIndex), true); + String storedUsersFileName = TestManager.getStringProperty(testPropertyFileName, testProperties, + TestManager.buildPropertyKey(TestManager.STORED_USERS_FILE, suiteIndex), true); + Map storedUsers = TestManager.getStoredUsers(storedUsersFileName); + String adminTestPropertyFileName = TestManager.getStringProperty(testPropertyFileName, testProperties, TestManager.buildPropertyKey(TestManager.ADMIN_PROPERTY_FILE, suiteIndex), true); - AdminTest adminTest = adminTestPropertyFileName == null ? null : createAdminTest(adminTestPropertyFileName); + AdminTest adminTest = adminTestPropertyFileName == null ? null : createAdminTest(adminTestPropertyFileName, + storedUsersFileName); String authorTestPropertyFileName = TestManager.getStringProperty(testPropertyFileName, testProperties, TestManager.buildPropertyKey(TestManager.AUTHOR_PROPERTY_FILE, suiteIndex), true); - AuthorTest authorTest = authorTestPropertyFileName == null ? null - : createAuthorTest(authorTestPropertyFileName); + AuthorTest authorTest = authorTestPropertyFileName == null ? null : createAuthorTest( + authorTestPropertyFileName, storedUsers); String monitorTestPropertyFileName = TestManager.getStringProperty(testPropertyFileName, testProperties, TestManager.buildPropertyKey(TestManager.MONITOR_PROPERTY_FILE, suiteIndex), true); - MonitorTest monitorTest = monitorTestPropertyFileName == null ? null - : createMonitorTest(monitorTestPropertyFileName); + MonitorTest monitorTest = monitorTestPropertyFileName == null ? null : createMonitorTest( + monitorTestPropertyFileName, storedUsers); String learnerTestPropertyFileName = TestManager.getStringProperty(testPropertyFileName, testProperties, TestManager.buildPropertyKey(TestManager.LEARNER_PROPERTY_FILE, suiteIndex), true); - LearnerTest learnerTest = learnerTestPropertyFileName == null ? null - : createLearnerTest(learnerTestPropertyFileName); + LearnerTest learnerTest = learnerTestPropertyFileName == null ? null : createLearnerTest( + learnerTestPropertyFileName, storedUsers); TestSuite suite = new TestSuite(this, suiteIndex, targetServer, contextRoot, adminTest, authorTest, monitorTest, learnerTest); @@ -404,8 +408,6 @@ Properties testProperties = TestManager.loadProperties(testPropertyFileName); TestReporter.setFileName(TestManager.getStringProperty(testPropertyFileName, testProperties, TestManager.REPORT_FILE_NAME, false)); - MockUser.setIndexPage(TestManager.getStringProperty(testPropertyFileName, testProperties, - TestManager.INDEX_PAGE_URL, false)); String fileTemplate = TestManager.getStringProperty(testPropertyFileName, testProperties, TestManager.REPORT_FILE_TEMPLATE, false); TestReporter.setFileTemplate(fileTemplate); @@ -418,4 +420,69 @@ TestManager.log.info("Finished initialization"); } + + private static Map getStoredUsers(String storedUsersFileName) { + Map result = new TreeMap(); + + if (storedUsersFileName != null) { + BufferedReader reader = null; + try { + File file = new File(storedUsersFileName); + if (file.canRead()) { + reader = new BufferedReader(new FileReader(storedUsersFileName)); + String line = null; + do { + line = reader.readLine(); + if (line != null) { + String[] userData = line.split(","); + if ((userData[0] != null) && (userData[1] != null)) { + result.put(userData[0], userData[1]); + } + } + } while (line != null); + } + } catch (Exception e) { + TestManager.log.warn("Error while trying to read users file: " + storedUsersFileName, e); + } finally { + if (reader != null) { + try { + reader.close(); + } catch (IOException e) { + TestManager.log.warn("Error while trying to read users file: " + storedUsersFileName, e); + } + } + } + } + + return result; + } + + public static void storeUsers(String storedUsersFileName, Collection storedUsers) { + if (storedUsersFileName != null) { + BufferedWriter writer = null; + + try { + File file = new File(storedUsersFileName); + file.delete(); + + writer = new BufferedWriter(new FileWriter(file)); + for (MockUser user : storedUsers) { + if (user.getUserId() != null) { + writer.append(user.getUsername() + "," + user.getUserId()); + writer.newLine(); + } + } + } catch (Exception e) { + TestManager.log.warn("Error while trying to write users file: " + storedUsersFileName, e); + } finally { + if (writer != null) { + try { + writer.close(); + } catch (IOException e) { + TestManager.log.warn("Error while trying to write users file: " + storedUsersFileName, e); + } + } + } + } + } } \ No newline at end of file Index: TestHarness4LAMS2/src/org/lamsfoundation/testharness/admin/AdminTest.java =================================================================== diff -u -r41955af92f3e17f2f11c07d94ae1a5f92b0d998f -r159c15ed2f6cc7c8f273367d199b196effd5f340 --- TestHarness4LAMS2/src/org/lamsfoundation/testharness/admin/AdminTest.java (.../AdminTest.java) (revision 41955af92f3e17f2f11c07d94ae1a5f92b0d998f) +++ TestHarness4LAMS2/src/org/lamsfoundation/testharness/admin/AdminTest.java (.../AdminTest.java) (revision 159c15ed2f6cc7c8f273367d199b196effd5f340) @@ -40,19 +40,19 @@ private String createCourseURL; private String createUserURL; - private Boolean userCreated; private String courseName; private String courseId; + private String storedUsersFileName; public AdminTest(String testName, Integer minDelay, Integer maxDelay, String createCourseURL, String createUserURL, - String courseId, Boolean userCreated, String courseName) { + String courseId, String courseName, String storedUsersFileName) { super(testName, minDelay, maxDelay); this.createCourseURL = createCourseURL; this.createUserURL = createUserURL; this.courseName = courseName == null ? TestUtil.buildName(testName, AdminTest.DEFAULT_COURSE_NAME) : TestUtil .buildName(testName, courseName); this.courseId = courseId; - this.userCreated = userCreated; + this.storedUsersFileName = storedUsersFileName; } public final String getCourseId() { @@ -71,10 +71,6 @@ return createUserURL; } - public final Boolean getUserCreated() { - return userCreated; - } - public final void setCourseId(String courseId) { this.courseId = courseId; } @@ -83,10 +79,6 @@ this.courseName = courseName; } - public final void setUserCreated(Boolean userCreated) { - this.userCreated = userCreated; - } - /** * let MockAdmin do what he should do login, create course and then create users * @@ -95,14 +87,11 @@ */ @Override protected void startTest() { - if ((courseId != null) && userCreated) { - return; - } MockAdmin admin = (MockAdmin) users[0]; admin.login(); if (courseId == null) { setCourseId(admin.createCourse(createCourseURL, courseName)); } - admin.createUsers(createUserURL, courseId); + admin.createUsers(createUserURL, courseId, storedUsersFileName); } } \ No newline at end of file Index: TestHarness4LAMS2/src/org/lamsfoundation/testharness/admin/MockAdmin.java =================================================================== diff -u -r41955af92f3e17f2f11c07d94ae1a5f92b0d998f -r159c15ed2f6cc7c8f273367d199b196effd5f340 --- TestHarness4LAMS2/src/org/lamsfoundation/testharness/admin/MockAdmin.java (.../MockAdmin.java) (revision 41955af92f3e17f2f11c07d94ae1a5f92b0d998f) +++ TestHarness4LAMS2/src/org/lamsfoundation/testharness/admin/MockAdmin.java (.../MockAdmin.java) (revision 159c15ed2f6cc7c8f273367d199b196effd5f340) @@ -24,15 +24,19 @@ import java.io.IOException; import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import org.apache.log4j.Logger; import org.lamsfoundation.testharness.AbstractTest; import org.lamsfoundation.testharness.Call; import org.lamsfoundation.testharness.MockUser; import org.lamsfoundation.testharness.TestHarnessException; +import org.lamsfoundation.testharness.TestManager; import org.lamsfoundation.testharness.author.AuthorTest; import org.lamsfoundation.testharness.learner.LearnerTest; import org.lamsfoundation.testharness.monitor.MonitorTest; @@ -53,17 +57,10 @@ * @author Fei Yang */ public class MockAdmin extends MockUser { + public static final String AUTHOR_ROLE = "3"; + public static final String MONITOR_ROLE = "4"; + public static final String LEARNER_ROLE = "5"; - private static class MockUserWithRoles { - MockUser user; - String role; - - public MockUserWithRoles(MockUser user, String roles) { - this.user = user; - this.role = roles; - } - } - private static final Logger log = Logger.getLogger(MockAdmin.class); private static final String COURSE_FORM_FLAG = "OrganisationForm"; private static final String COURSE_NAME = "name"; @@ -77,39 +74,16 @@ private static final String EMAIL = "email"; private static final String COMMON_LAST_NAME = "Testharness"; private static final String ROLES = "roles"; - private static final String AUTHOR_ROLE = "3"; - private static final String MONITOR_ROLE = "4"; - private static final String LEARNER_ROLE = "5"; private static final String USER_ID_START_FLAG = "userId="; private static final char USER_ID_END_FLAG = '&'; private static final String LOGIN_TAKEN_ERROR = "Login is already taken."; + private static final Pattern EXISTING_USER_ID_PATTERN = Pattern.compile(", ID: (\\d+)"); - public MockAdmin(AbstractTest test, String username, String password, String userId) { - super(test, username, password, userId); + public MockAdmin(AbstractTest test, String username, String password) { + super(test, username, password, null, null); } - private static MockUserWithRoles[] getMockUsersWithRoles(AbstractTest[] tests) { - List users = new ArrayList(); - for (AbstractTest test : tests) { - if (test != null) { - MockUser[] mockUsers = test.getUsers(); - String role; - if (test instanceof AuthorTest) { - role = MockAdmin.AUTHOR_ROLE; - } else if (test instanceof MonitorTest) { - role = MockAdmin.MONITOR_ROLE; - } else { - role = MockAdmin.LEARNER_ROLE; - } - for (MockUser mockUser : mockUsers) { - users.add(new MockUserWithRoles(mockUser, role)); - } - } - } - return users.toArray(new MockUserWithRoles[] {}); - } - public String createCourse(String createCourseURL, String courseName) { try { delay(); @@ -151,20 +125,26 @@ } } - public void createUsers(String createUserURL, String courseId) { + public void createUsers(String createUserURL, String courseId, String storedUsersFileName) { try { String url = createUserURL.replace(MockAdmin.COURSE_ID_PATTERN, courseId.toString()); + List mockUsers = new ArrayList(); AuthorTest authorTest = test.getTestSuite().getAuthorTest(); + Collections.addAll(mockUsers, authorTest.getUsers()); MonitorTest monitorTest = test.getTestSuite().getMonitorTest(); + Collections.addAll(mockUsers, monitorTest.getUsers()); LearnerTest learnerTest = test.getTestSuite().getLearnerTest(); - AbstractTest[] tests = new AbstractTest[] { authorTest, monitorTest, learnerTest }; - MockUserWithRoles[] mockUsers = MockAdmin.getMockUsersWithRoles(tests); + Collections.addAll(mockUsers, learnerTest.getUsers()); - for (MockUserWithRoles mockUser : mockUsers) { - delay(); + for (MockUser mockUser : mockUsers) { + String name = mockUser.getUsername(); + if (mockUser.getUserId() != null) { + log.debug("User " + name + " already exists, skipping creation"); + continue; + } + delay(); // create the user - String name = mockUser.user.getUsername(); MockAdmin.log.info(username + " creating user " + name); WebResponse resp = (WebResponse) new Call(wc, test, username + " creating user " + name, url).execute(); if (!MockUser.checkPageContains(resp, MockAdmin.USER_FORM_FLAG)) { @@ -183,14 +163,23 @@ params)).execute(); // add the roles - if (resp.getText().indexOf(MockAdmin.LOGIN_TAKEN_ERROR) != -1) { - log.warn("Login " + name + " already taken."); + String respText = resp.getText(); + if (respText.indexOf(MockAdmin.LOGIN_TAKEN_ERROR) != -1) { + Matcher m = MockAdmin.EXISTING_USER_ID_PATTERN.matcher(respText); + if (m.find()) { + String userId = m.group(1); + mockUser.setUserId(userId); + MockAdmin.log.debug("User " + name + " already exists with ID: " + userId); + } else { + throw new TestHarnessException("User " + name + + " already exists, but could not retrieve his ID"); + } continue; } MockAdmin.log.info(username + " adding roles to user " + name); params = new HashMap(); - params.put(MockAdmin.ROLES, new String[] { mockUser.role }); + params.put(MockAdmin.ROLES, new String[] { mockUser.getRole() }); resp = (WebResponse) new Call(wc, test, username + " submit user rolesform", fillForm(resp, 0, params)) .execute(); WebTable[] tables = resp.getTables(); @@ -220,8 +209,10 @@ throw new TestHarnessException("Failed to get the user id for " + name); } MockAdmin.log.info(username + " created user " + name + " and the id is " + idAsString); - mockUser.user.setUserId(idAsString); + mockUser.setUserId(idAsString); } + + TestManager.storeUsers(storedUsersFileName, mockUsers); } catch (IOException e) { throw new RuntimeException(e); } catch (SAXException e) { Index: TestHarness4LAMS2/src/org/lamsfoundation/testharness/author/MockAuthor.java =================================================================== diff -u -r41955af92f3e17f2f11c07d94ae1a5f92b0d998f -r159c15ed2f6cc7c8f273367d199b196effd5f340 --- TestHarness4LAMS2/src/org/lamsfoundation/testharness/author/MockAuthor.java (.../MockAuthor.java) (revision 41955af92f3e17f2f11c07d94ae1a5f92b0d998f) +++ TestHarness4LAMS2/src/org/lamsfoundation/testharness/author/MockAuthor.java (.../MockAuthor.java) (revision 159c15ed2f6cc7c8f273367d199b196effd5f340) @@ -31,6 +31,7 @@ import org.lamsfoundation.testharness.Call; import org.lamsfoundation.testharness.MockUser; import org.lamsfoundation.testharness.TestHarnessException; +import org.lamsfoundation.testharness.admin.MockAdmin; import org.xml.sax.SAXException; import com.meterware.httpunit.WebResponse; @@ -62,7 +63,7 @@ * @param */ public MockAuthor(AuthorTest test, String username, String password, String userId) { - super(test, username, password, userId); + super(test, username, password, MockAdmin.AUTHOR_ROLE, userId); } public String importLearningDesign(String learningDesignUploadURL, File file) { Index: TestHarness4LAMS2/src/org/lamsfoundation/testharness/learner/MockLearner.java =================================================================== diff -u -r41955af92f3e17f2f11c07d94ae1a5f92b0d998f -r159c15ed2f6cc7c8f273367d199b196effd5f340 --- TestHarness4LAMS2/src/org/lamsfoundation/testharness/learner/MockLearner.java (.../MockLearner.java) (revision 41955af92f3e17f2f11c07d94ae1a5f92b0d998f) +++ TestHarness4LAMS2/src/org/lamsfoundation/testharness/learner/MockLearner.java (.../MockLearner.java) (revision 159c15ed2f6cc7c8f273367d199b196effd5f340) @@ -39,6 +39,7 @@ import org.lamsfoundation.testharness.MockUser; import org.lamsfoundation.testharness.TestHarnessException; import org.lamsfoundation.testharness.TestUtil; +import org.lamsfoundation.testharness.admin.MockAdmin; import org.xml.sax.SAXException; import com.allaire.wddx.WddxDeserializationException; @@ -117,7 +118,7 @@ * MockLearner Constructor */ public MockLearner(LearnerTest test, String username, String password, String userId) { - super(test, username, password, userId); + super(test, username, password, MockAdmin.LEARNER_ROLE, userId); } Index: TestHarness4LAMS2/src/org/lamsfoundation/testharness/monitor/MockMonitor.java =================================================================== diff -u -r41955af92f3e17f2f11c07d94ae1a5f92b0d998f -r159c15ed2f6cc7c8f273367d199b196effd5f340 --- TestHarness4LAMS2/src/org/lamsfoundation/testharness/monitor/MockMonitor.java (.../MockMonitor.java) (revision 41955af92f3e17f2f11c07d94ae1a5f92b0d998f) +++ TestHarness4LAMS2/src/org/lamsfoundation/testharness/monitor/MockMonitor.java (.../MockMonitor.java) (revision 159c15ed2f6cc7c8f273367d199b196effd5f340) @@ -35,6 +35,7 @@ import org.lamsfoundation.testharness.MockUser; import org.lamsfoundation.testharness.TestHarnessException; import org.lamsfoundation.testharness.TestUtil; +import org.lamsfoundation.testharness.admin.MockAdmin; import com.allaire.wddx.WddxDeserializationException; import com.meterware.httpunit.WebResponse; @@ -82,7 +83,7 @@ * @param */ public MockMonitor(MonitorTest test, String username, String password, String userId) { - super(test, username, password, userId); + super(test, username, password, MockAdmin.MONITOR_ROLE, userId); } public void createLessonClass(String createLessonClassURL, String userId) { Index: TestHarness4LAMS2/test.properties =================================================================== diff -u -r1adca864dec2f9accd289755e5878f57837b65da -r159c15ed2f6cc7c8f273367d199b196effd5f340 --- TestHarness4LAMS2/test.properties (.../test.properties) (revision 1adca864dec2f9accd289755e5878f57837b65da) +++ TestHarness4LAMS2/test.properties (.../test.properties) (revision 159c15ed2f6cc7c8f273367d199b196effd5f340) @@ -1,62 +1,57 @@ #----------------------------------------------------------------- # Test report file name. -# Timestamp will be added to the name by the application +# Timestamp will appended to the name . #----------------------------------------------------------------- ReportFileName = report #----------------------------------------------------------------- # Test report file template. -# The file path could be relative or absolute +# The file path can be relative or absolute #----------------------------------------------------------------- ReportFileTemplate = template.html -#----------------------------------------------------------------- -# index page -#----------------------------------------------------------------- -IndexPageURL = /index.jsp - #------------------------------------------------------------------ # This is the master property file. # It organises single tests into test suites. # # Each test suite definition typically involves: # one TargetServer., # one ContextRoot., -# one HttpPort., # one AdminTestPropertyFile., # one AuthorTestPropertyFile., # one MonitorTestPropertyFile., # one LearnerTestPropertyFile., +# one UsersFile., # # To avoid any test, just do not specify the corresponding xxxTestPropertyFile # # # Example : # NumberOfTestSuites=2 # -# TargetServer.1=saturn.melcoe.mq.edu.au -# ContextRoot.1=/lams -# HttpPort.1=8080 +# TargetServer.1=saturn.melcoe.mq.edu.au:8080 +# ContextRoot.1=/lams # AdminTestPropertyFile.1=adminTest1.properties # AuthorTestPropertyFile.1=authorTest1.properties # MonitorTestPropertyFile.1=monitorTest1.properties # LearnerTestPropertyFile.1=learnerTest1.properties +# UsersFile.1=users1.users # -# TargetServer.2=lams.melcoe.mq.edu.au -# ContextRoot.2=/ -# HttpPort.2=1080 +# TargetServer.2=https://lams.melcoe.mq.edu.au +# ContextRoot.2=/ # MonitorTestPropertyFile.2=monitorTest2.properties # LearnerTestPropertyFile.2=learnerTest2.properties +# UsersFile.2=users2.users # -# Note: in the second test suite, there are only 2 tests, in which case -# Either LessonId or UserId must be set in monitorTest2.properties file +# Note: in the second test suite, there are only 2 tests, +# so users must had been already created and stored in users2.users file # #------------------------------------------------------------------- NumberOfTestSuites=1 #--------------------------------------------------------- -# if TargetServer is not specified, localhost will be used. +# If TargetServer is not specified, localhost will be used. # Target server must include protocol and port, if custom. #--------------------------------------------------------- # TargetServer.1=https://shaun.melcoe.mq.edu.au:8443 @@ -66,16 +61,12 @@ #---------------------------------------------------------- # LAMS central web application context root # If not specified, empty context root will be used -# other modules's context roots must be: -# /admin -# /learning -# /monitoring -# Since "admin","learning","monitoring" are hard coded in -# lams-central JSPs as part of relative path #---------------------------------------------------------- ContextRoot.1=/lams AdminTestPropertyFile.1=adminTest1.properties AuthorTestPropertyFile.1=authorTest1.properties MonitorTestPropertyFile.1=monitorTest1.properties -LearnerTestPropertyFile.1=learnerTest1.properties \ No newline at end of file +LearnerTestPropertyFile.1=learnerTest1.properties +# File with existing users, filled automatically when users get created in the first run +UsersFile.1=users1.users \ No newline at end of file Index: lams_admin/src/java/org/lamsfoundation/lams/admin/web/UserSaveAction.java =================================================================== diff -u -ra23376f298830f9cb4d3d18e5dc7ef11b907c173 -r159c15ed2f6cc7c8f273367d199b196effd5f340 --- lams_admin/src/java/org/lamsfoundation/lams/admin/web/UserSaveAction.java (.../UserSaveAction.java) (revision a23376f298830f9cb4d3d18e5dc7ef11b907c173) +++ lams_admin/src/java/org/lamsfoundation/lams/admin/web/UserSaveAction.java (.../UserSaveAction.java) (revision 159c15ed2f6cc7c8f273367d199b196effd5f340) @@ -59,8 +59,7 @@ /** * struts doclets * - * @struts:action path="/usersave" name="UserForm" input=".user" scope="request" - * validate="false" + * @struts:action path="/usersave" name="UserForm" input=".user" scope="request" validate="false" * * @struts:action-forward name="user" path="/user.do?method=edit" * @struts:action-forward name="userlist" path="/usermanage.do" @@ -73,8 +72,8 @@ private static IUserManagementService service; @Override - @SuppressWarnings("unchecked") - public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { + public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) throws Exception { UserSaveAction.service = AdminServiceProxy.getService(getServlet().getServletContext()); @@ -87,14 +86,15 @@ UserSaveAction.log.debug("orgId: " + orgId); Boolean edit = false; Boolean passwordChanged = true; - SupportedLocale locale = (SupportedLocale) UserSaveAction.service.findById(SupportedLocale.class, (Integer) userForm.get("localeId")); - AuthenticationMethod authenticationMethod = (AuthenticationMethod) UserSaveAction.service.findById(AuthenticationMethod.class, (Integer) userForm - .get("authenticationMethodId")); + SupportedLocale locale = (SupportedLocale) UserSaveAction.service.findById(SupportedLocale.class, + (Integer) userForm.get("localeId")); + AuthenticationMethod authenticationMethod = (AuthenticationMethod) UserSaveAction.service.findById( + AuthenticationMethod.class, (Integer) userForm.get("authenticationMethodId")); UserSaveAction.log.debug("locale: " + locale); UserSaveAction.log.debug("authenticationMethod:" + authenticationMethod); if (isCancelled(request)) { - if (orgId == null || orgId == 0) { + if ((orgId == null) || (orgId == 0)) { return mapping.findForward("usersearch"); } request.setAttribute("org", orgId); @@ -108,33 +108,42 @@ } // (dyna)form validation - userForm.set("login", userForm.getString("login").trim()); - if (userForm.get("login") == null || userForm.getString("login").length() == 0) { - errors.add("login", new ActionMessage("error.login.required")); + String login = userForm.getString("login"); + if (login != null) { + login = login.trim(); } - if (UserSaveAction.service.getUserByLogin(userForm.getString("login")) != null) { - if (user != null && StringUtils.equals(user.getLogin(), userForm.getString("login"))) { - // login exists - it's the user's current login - } else { - errors.add("login", new ActionMessage("error.login.unique", "(" + userForm.getString("login") + ")")); + if ((login == null) || (login.length() == 0)) { + errors.add("login", new ActionMessage("error.login.required")); + } else { + userForm.set("login", login); + User existingUser = UserSaveAction.service.getUserByLogin(login); + if (existingUser != null) { + if ((user != null) && StringUtils.equals(user.getLogin(), login)) { + // login exists - it's the user's current login + } else { + errors.add("login", + new ActionMessage("error.login.unique", "(" + login + ", ID: " + existingUser.getUserId() + + ")")); + } } } + if (!StringUtils.equals((String) userForm.get("password"), ((String) userForm.get("password2")))) { errors.add("password", new ActionMessage("error.newpassword.mismatch")); } - if (userForm.get("password") == null || userForm.getString("password").trim().length() == 0) { + if ((userForm.get("password") == null) || (userForm.getString("password").trim().length() == 0)) { passwordChanged = false; if (!edit) { errors.add("password", new ActionMessage("error.password.required")); } } - if (userForm.get("firstName") == null || userForm.getString("firstName").trim().length() == 0) { + if ((userForm.get("firstName") == null) || (userForm.getString("firstName").trim().length() == 0)) { errors.add("firstName", new ActionMessage("error.firstname.required")); } - if (userForm.get("lastName") == null || userForm.getString("lastName").trim().length() == 0) { + if ((userForm.get("lastName") == null) || (userForm.getString("lastName").trim().length() == 0)) { errors.add("lastName", new ActionMessage("error.lastname.required")); } - if (userForm.get("email") == null || userForm.getString("email").trim().length() == 0) { + if ((userForm.get("email") == null) || (userForm.getString("email").trim().length() == 0)) { errors.add("email", new ActionMessage("error.email.required")); } else { Pattern p = Pattern.compile(".+@.+\\.[a-z]+"); @@ -158,10 +167,12 @@ user.setLocale(locale); user.setAuthenticationMethod(authenticationMethod); - Theme cssTheme = (Theme) service.findById(Theme.class, (Long) userForm.get("userCSSTheme")); + Theme cssTheme = (Theme) UserSaveAction.service.findById(Theme.class, + (Long) userForm.get("userCSSTheme")); user.setHtmlTheme(cssTheme); - Theme flashTheme = (Theme) service.findById(Theme.class, (Long) userForm.get("userFlashTheme")); + Theme flashTheme = (Theme) UserSaveAction.service.findById(Theme.class, + (Long) userForm.get("userFlashTheme")); user.setFlashTheme(flashTheme); UserSaveAction.service.save(user); @@ -177,15 +188,17 @@ user.setHtmlTheme(UserSaveAction.service.getDefaultHtmlTheme()); user.setDisabledFlag(false); user.setCreateDate(new Date()); - user.setAuthenticationMethod((AuthenticationMethod) UserSaveAction.service.findByProperty(AuthenticationMethod.class, - "authenticationMethodName", "LAMS-Database").get(0)); + user.setAuthenticationMethod((AuthenticationMethod) UserSaveAction.service.findByProperty( + AuthenticationMethod.class, "authenticationMethodName", "LAMS-Database").get(0)); user.setUserId(null); user.setLocale(locale); - Theme cssTheme = (Theme) service.findById(Theme.class, (Long) userForm.get("userCSSTheme")); + Theme cssTheme = (Theme) UserSaveAction.service.findById(Theme.class, + (Long) userForm.get("userCSSTheme")); user.setHtmlTheme(cssTheme); - Theme flashTheme = (Theme) service.findById(Theme.class, (Long) userForm.get("userFlashTheme")); + Theme flashTheme = (Theme) UserSaveAction.service.findById(Theme.class, + (Long) userForm.get("userFlashTheme")); user.setFlashTheme(flashTheme); UserSaveAction.service.save(user); @@ -199,7 +212,7 @@ } if (errors.isEmpty()) { - if (orgId == null || orgId == 0) { + if ((orgId == null) || (orgId == 0)) { return mapping.findForward("usersearch"); } if (edit) {