|
1 | 1 | package org.cloudcoder.app.loadtester; |
2 | 2 |
|
3 | | -import java.io.IOException; |
4 | | -import java.util.Properties; |
| 3 | +import java.util.Scanner; |
5 | 4 |
|
6 | | -import org.cloudcoder.app.server.persist.JDBCDatabaseConfig; |
7 | | -import org.cloudcoder.app.server.persist.util.DBUtil; |
| 5 | +import org.cloudcoder.app.shared.model.CloudCoderAuthenticationException; |
| 6 | +import org.cloudcoder.app.shared.model.CourseAndCourseRegistration; |
| 7 | +import org.cloudcoder.app.shared.model.CourseRegistrationType; |
| 8 | +import org.cloudcoder.app.shared.model.User; |
8 | 9 |
|
9 | 10 | public class PrepareDatabaseForLoadTesting { |
10 | | - public static void main(String[] args) throws IOException { |
11 | | - final Properties config = DBUtil.getConfigProperties(); |
12 | | - JDBCDatabaseConfig.createFromProperties(config); |
| 11 | + public static void main(String[] args) throws Exception { |
| 12 | + Scanner keyboard = new Scanner(System.in); |
| 13 | + createTestUserAccounts(keyboard); |
| 14 | + } |
| 15 | + |
| 16 | + private static void createTestUserAccounts(Scanner keyboard) |
| 17 | + throws CloudCoderAuthenticationException { |
| 18 | + HostConfig hostConfig = HostConfigDatabase.forName("default"); |
| 19 | + |
| 20 | + Client client = new Client(hostConfig); |
| 21 | + |
| 22 | + // Must be logged in using an instructor account |
| 23 | + System.out.println("Instructor username: "); |
| 24 | + String userName = keyboard.nextLine(); |
| 25 | + System.out.println("Instructor password: "); |
| 26 | + String password = keyboard.nextLine(); |
| 27 | + |
| 28 | + client.login(userName, password); |
| 29 | + |
| 30 | + System.out.println("Course name: "); |
| 31 | + String courseName = keyboard.nextLine(); |
| 32 | + |
| 33 | + // Find the course and make sure user is really an instructor |
| 34 | + CourseAndCourseRegistration theCCR = null; |
| 35 | + |
| 36 | + CourseAndCourseRegistration[] courses = client.getRegisteredCourses(); |
| 37 | + for (CourseAndCourseRegistration ccr : courses) { |
| 38 | + if (ccr.getCourse().getName().equals(courseName)) { |
| 39 | + theCCR = ccr; |
| 40 | + break; |
| 41 | + } |
| 42 | + } |
| 43 | + |
| 44 | + if (theCCR == null) { |
| 45 | + System.out.println("Could not find course " + courseName); |
| 46 | + System.exit(1); |
| 47 | + } |
| 48 | + if (!theCCR.getCourseRegistration().getRegistrationType().isInstructor()) { |
| 49 | + System.out.println("User is not an instructor"); |
| 50 | + System.exit(1); |
| 51 | + } |
13 | 52 |
|
14 | | - //Database.getInstance(). |
| 53 | + for (int n = 1; n <= 10; n++) { |
| 54 | + User user = new User(); |
| 55 | + String testUserName = "user" + n; |
| 56 | + user.setUsername(testUserName); |
| 57 | + user.setFirstname("Test"); |
| 58 | + user.setLastname("User"); |
| 59 | + user.setPasswordHash(testUserName); // set to plaintext when adding/registering a user |
| 60 | + user.setEmail(testUserName + "@unseen.edu"); |
| 61 | + user.setConsent(""); |
| 62 | + user.setWebsite("http://student.unseen.edu/~" + testUserName); |
| 63 | + |
| 64 | + System.out.println("Adding user " + testUserName); |
| 65 | + client.createUser(user, theCCR.getCourse(), CourseRegistrationType.STUDENT, 101); |
| 66 | + } |
15 | 67 | } |
16 | 68 | } |
0 commit comments