From 611465be1ab493e800538ac13ab49ac4fcb924ad Mon Sep 17 00:00:00 2001 From: Dominik Remo <47261058+DominikRemo@users.noreply.github.com> Date: Tue, 26 Sep 2023 18:04:51 +0200 Subject: [PATCH 1/5] Empty Commit From 9ccfc5808288a8b5f5e71bce11876118deca5ef6 Mon Sep 17 00:00:00 2001 From: Dominik Remo <47261058+DominikRemo@users.noreply.github.com> Date: Tue, 26 Sep 2023 18:23:43 +0200 Subject: [PATCH 2/5] Add documentation --- .../tum/in/www1/artemis/exam/ExamFactory.java | 14 ++++++++++++- .../in/www1/artemis/exam/ExamUtilService.java | 20 +++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/test/java/de/tum/in/www1/artemis/exam/ExamFactory.java b/src/test/java/de/tum/in/www1/artemis/exam/ExamFactory.java index 35ec60736223..0fe1e923f628 100644 --- a/src/test/java/de/tum/in/www1/artemis/exam/ExamFactory.java +++ b/src/test/java/de/tum/in/www1/artemis/exam/ExamFactory.java @@ -16,7 +16,7 @@ public class ExamFactory { /** - * Generates a real exam with student review dates set + * Generates a real exam with student review dates set [now; now + 60min] * * @param course the associated course * @return the created exam @@ -160,6 +160,12 @@ public static ExerciseGroup generateExerciseGroupWithTitle(boolean mandatory, Ex return exerciseGroup; } + /** + * Creates a StudentExam that is linked to the given exam + * + * @param exam the exam to be linked to the studentExam + * @return the newly created StudentExam + */ public static StudentExam generateStudentExam(Exam exam) { StudentExam studentExam = new StudentExam(); studentExam.setExam(exam); @@ -181,6 +187,12 @@ public static StudentExam generateStudentExamForTestExam(Exam exam) { return studentExam; } + /** + * Creates a StudentExam that is linked to the given exam and is a test run + * + * @param exam the exam to be linked to the studentExam + * @return the newly created StudentExam + */ public static StudentExam generateExamTestRun(Exam exam) { StudentExam studentExam = new StudentExam(); studentExam.setExam(exam); diff --git a/src/test/java/de/tum/in/www1/artemis/exam/ExamUtilService.java b/src/test/java/de/tum/in/www1/artemis/exam/ExamUtilService.java index 1959b08bf8c1..801055aa9895 100644 --- a/src/test/java/de/tum/in/www1/artemis/exam/ExamUtilService.java +++ b/src/test/java/de/tum/in/www1/artemis/exam/ExamUtilService.java @@ -576,6 +576,14 @@ public Exam addExerciseGroupsAndExercisesToExam(Exam exam, boolean withProgrammi return exam; } + /** + * Creates and saves a text, modeling, optional programming and optional quiz exercise and adds them to the exam. + * + * @param initialExam the exam to which the exercises should be added + * @param withProgrammingExercise whether a programming exercise should be added + * @param withQuizExercise whether a quiz exercise should be added + * @return the exam with the added exercises + */ public Exam addTextModelingProgrammingExercisesToExam(Exam initialExam, boolean withProgrammingExercise, boolean withQuizExercise) { ExamFactory.generateExerciseGroup(true, initialExam); // text ExamFactory.generateExerciseGroup(true, initialExam); // modeling @@ -623,6 +631,12 @@ public Exam addTextModelingProgrammingExercisesToExam(Exam initialExam, boolean return exam; } + /** + * Creates and saves an active course with an exam and an exercise group. + * + * @param mandatory true if the exercise group is mandatory + * @return the created exercise group + */ public ExerciseGroup addExerciseGroupWithExamAndCourse(boolean mandatory) { Course course = CourseFactory.generateCourse(null, pastTimestamp, futureFutureTimestamp, new HashSet<>(), "tumuser", "tutor", "editor", "instructor"); Exam exam = ExamFactory.generateExam(course); @@ -649,6 +663,12 @@ public ExerciseGroup addExerciseGroupWithExamAndCourse(boolean mandatory) { return exerciseGroup; } + /** + * Creates and saves an active course with an exam and an exercise group. The exam has a review date [now; now + 60min]. + * + * @param mandatory true if the exercise group is mandatory + * @return the created exercise group + */ public ExerciseGroup addExerciseGroupWithExamWithReviewDatesAndCourse(boolean mandatory) { Course course = CourseFactory.generateCourse(null, pastTimestamp, futureFutureTimestamp, new HashSet<>(), "tumuser", "tutor", "editor", "instructor"); Exam exam = ExamFactory.generateExamWithStudentReviewDates(course); From 46ce6d0ce158c30faa9692b1e5768c5a460e2ba9 Mon Sep 17 00:00:00 2001 From: Dominik Remo <47261058+DominikRemo@users.noreply.github.com> Date: Fri, 6 Oct 2023 10:18:50 +0200 Subject: [PATCH 3/5] Add documentation --- .../tum/in/www1/artemis/exam/ExamFactory.java | 126 +++++++++--------- .../in/www1/artemis/exam/ExamUtilService.java | 102 ++++++++++++-- 2 files changed, 150 insertions(+), 78 deletions(-) diff --git a/src/test/java/de/tum/in/www1/artemis/exam/ExamFactory.java b/src/test/java/de/tum/in/www1/artemis/exam/ExamFactory.java index 0fe1e923f628..5fba65ec6fb0 100644 --- a/src/test/java/de/tum/in/www1/artemis/exam/ExamFactory.java +++ b/src/test/java/de/tum/in/www1/artemis/exam/ExamFactory.java @@ -16,10 +16,10 @@ public class ExamFactory { /** - * Generates a real exam with student review dates set [now; now + 60min] + * Creates an Exam with student review dates set [now; now + 60min] * - * @param course the associated course - * @return the created exam + * @param course The associated course + * @return The newly created Exam */ public static Exam generateExamWithStudentReviewDates(Course course) { Exam exam = generateExamHelper(course, false); @@ -32,50 +32,50 @@ public static Exam generateExamWithStudentReviewDates(Course course) { } /** - * Generates a real exam without student review dates set + * Creates an Exam without student review dates set * - * @param course the associated course - * @return the created exam + * @param course The associated course + * @return The newly created Exam */ public static Exam generateExam(Course course) { return generateExamHelper(course, false); } /** - * Generates a real exam without student review dates set and attaches a channel + * Creates an Exam with a Channel and without student review dates set * - * @param course the associated course - * @param channelName the channel name - * @return the created exam + * @param course The associated course + * @param channelName The channel name + * @return The newly created Exam */ public static Exam generateExam(Course course, String channelName) { return generateExamHelper(course, false, channelName); } /** - * Generates an exam without channel - * - * @param course the associated course - * @param visibleDate the visible date of the exam - * @param startDate the start date of the exam - * @param endDate the end date of the exam - * @param testExam if the exam is a test exam - * @return the created exam + * Creates an Exam without a Channel + * + * @param course The associated course + * @param visibleDate The visible date of the exam + * @param startDate The start date of the exam + * @param endDate The end date of the exam + * @param testExam True, if the exam is a test exam + * @return The newly created Exam */ public static Exam generateExam(Course course, ZonedDateTime visibleDate, ZonedDateTime startDate, ZonedDateTime endDate, boolean testExam) { return generateExam(course, visibleDate, startDate, endDate, testExam, null); } /** - * Generates an exam with channel - * - * @param course the associated course - * @param visibleDate the visible date of the exam - * @param startDate the start date of the exam - * @param endDate the end date of the exam - * @param testExam if the exam is a test exam - * @param channelName the channel name - * @return the created exam + * Creates an Exam with a Channel + * + * @param course The associated course + * @param visibleDate The visible date of the exam + * @param startDate The start date of the exam + * @param endDate The end date of the exam + * @param testExam True, if the exam is a test exam + * @param channelName The channel name + * @return The newly created Exam */ public static Exam generateExam(Course course, ZonedDateTime visibleDate, ZonedDateTime startDate, ZonedDateTime endDate, boolean testExam, String channelName) { Exam exam = new Exam(); @@ -99,32 +99,32 @@ public static Exam generateExam(Course course, ZonedDateTime visibleDate, ZonedD } /** - * Generates a test exam (test exams have no student review dates) + * Creates a test Exam (test exams have no student review dates) * - * @param course the associated course - * @return the created exam + * @param course The associated course + * @return The newly created Exam */ public static Exam generateTestExam(Course course) { return generateExamHelper(course, true); } /** - * Helper method to create an exam without a channel + * Creates an exam without a Channel * - * @param course the associated course - * @param testExam Boolean flag to determine whether it is a test exam - * @return the created Exam + * @param course The associated course + * @param testExam True, if the Exam is a test exam + * @return The newly created Exam */ private static Exam generateExamHelper(Course course, boolean testExam) { return generateExamHelper(course, testExam, null); } /** - * Helper method to create an exam with a channel + * Creates an Exam with a Channel * - * @param course the associated course - * @param testExam Boolean flag to determine whether it is a test exam - * @return the created Exam + * @param course The associated course + * @param testExam True, if the Exam is a test exam + * @return The newly created Exam */ private static Exam generateExamHelper(Course course, boolean testExam, String channelName) { ZonedDateTime currentTime = now(); @@ -132,25 +132,23 @@ private static Exam generateExamHelper(Course course, boolean testExam, String c } /** - * generates an exercise group for an exam + * Creates an ExerciseGroup and adds it to the given exam * - * @param mandatory if the exercise group is mandatory - * @param exam the exam that this exercise group should be added to - * - * @return the newly created exercise + * @param mandatory True, if the exercise group is mandatory + * @param exam The exam that this exercise group should be added to + * @return The newly created ExerciseGroup */ public static ExerciseGroup generateExerciseGroup(boolean mandatory, Exam exam) { return generateExerciseGroupWithTitle(mandatory, exam, "Exercise group title"); } /** - * generates an exercise group for an exam with the given title - * - * @param mandatory if the exercise group is mandatory - * @param exam the exam that this exercise group should be added to - * @param title title of the exercise group + * Creates an ExerciseGroup for an Exam * - * @return the newly created exercise + * @param mandatory True, if the exercise group is mandatory + * @param exam The exam that this exercise group should be added to + * @param title The title of the exercise group + * @return The newly created ExerciseGroup */ public static ExerciseGroup generateExerciseGroupWithTitle(boolean mandatory, Exam exam, String title) { ExerciseGroup exerciseGroup = new ExerciseGroup(); @@ -163,8 +161,8 @@ public static ExerciseGroup generateExerciseGroupWithTitle(boolean mandatory, Ex /** * Creates a StudentExam that is linked to the given exam * - * @param exam the exam to be linked to the studentExam - * @return the newly created StudentExam + * @param exam The exam to be linked to the studentExam + * @return The newly created StudentExam */ public static StudentExam generateStudentExam(Exam exam) { StudentExam studentExam = new StudentExam(); @@ -174,10 +172,10 @@ public static StudentExam generateStudentExam(Exam exam) { } /** - * Helper Method to generate a studentExam for a test exam + * Creates a StudentExam for a test exam * - * @param exam the exam to be linked to the studentExam - * @return a StudentExam for a test exam + * @param exam The exam to be linked to the studentExam + * @return The newly created StudentExam */ public static StudentExam generateStudentExamForTestExam(Exam exam) { StudentExam studentExam = new StudentExam(); @@ -190,8 +188,8 @@ public static StudentExam generateStudentExamForTestExam(Exam exam) { /** * Creates a StudentExam that is linked to the given exam and is a test run * - * @param exam the exam to be linked to the studentExam - * @return the newly created StudentExam + * @param exam The exam to be linked to the studentExam + * @return The newly created StudentExam */ public static StudentExam generateExamTestRun(Exam exam) { StudentExam studentExam = new StudentExam(); @@ -201,11 +199,11 @@ public static StudentExam generateExamTestRun(Exam exam) { } /** - * generates an exam with one exercise group + * Creates an Exam with an ExerciseGroup * - * @param course course of the exam - * @param mandatory if the exercise group is mandatory - * @return newly generated exam + * @param course The associated course + * @param mandatory True, if the exercise group is mandatory + * @return The newly created Exam */ public static Exam generateExamWithExerciseGroup(Course course, boolean mandatory) { Exam exam = generateExam(course); @@ -215,11 +213,11 @@ public static Exam generateExamWithExerciseGroup(Course course, boolean mandator } /** - * creates exam session DTOs + * Creates a Set of ExamSessionDTOs from the given exam sessions * - * @param session1 firts exam session - * @param session2 second exam session - * @return set of exam session DTOs + * @param session1 The first exam session + * @param session2 The second exam session + * @return The created set of ExamSessionDTOs */ public static Set createExpectedExamSessionDTOs(ExamSession session1, ExamSession session2) { var expectedDTOs = new HashSet(); diff --git a/src/test/java/de/tum/in/www1/artemis/exam/ExamUtilService.java b/src/test/java/de/tum/in/www1/artemis/exam/ExamUtilService.java index 801055aa9895..f5717ac8448d 100644 --- a/src/test/java/de/tum/in/www1/artemis/exam/ExamUtilService.java +++ b/src/test/java/de/tum/in/www1/artemis/exam/ExamUtilService.java @@ -102,6 +102,15 @@ public class ExamUtilService { @Autowired private ExamSessionRepository examSessionRepository; + /** + * Creates and saves a course with an exam and an exercise group with all exercise types excluding programming exercises. + * + * @param user The user who should be registered for the exam + * @param visible The visible date of the exam + * @param start The start date of the exam + * @param end The end date of the exam + * @return The newly created course + */ public Course createCourseWithExamAndExerciseGroupAndExercises(User user, ZonedDateTime visible, ZonedDateTime start, ZonedDateTime end) { Course course = courseUtilService.createCourse(); Exam exam = addExamWithUser(course, user, false, visible, start, end); @@ -110,6 +119,13 @@ public Course createCourseWithExamAndExerciseGroupAndExercises(User user, ZonedD return courseRepo.save(course); } + /** + * Creates and saves a course with an exam and an exercise group with all exercise types excluding programming exercises. Sets the visible (now - 1 min), start (now) and end + * (now + 1 min) date with default values. + * + * @param user The user who should be registered for the exam + * @return The newly created course + */ public Course createCourseWithExamAndExerciseGroupAndExercises(User user) { Course course = courseUtilService.createCourse(); Exam exam = addExamWithUser(course, user, false, ZonedDateTime.now().minusMinutes(1), ZonedDateTime.now(), ZonedDateTime.now().plusMinutes(1)); @@ -118,6 +134,14 @@ public Course createCourseWithExamAndExerciseGroupAndExercises(User user) { return courseRepo.save(course); } + /** + * Creates and saves a StudentExam for a test run. + * + * @param exam The exam for which the test run should be created + * @param instructor The user who should be registered for the test run + * @param exerciseGroupsWithExercises The ExerciseGroups with Exercises that should be added to the test run + * @return The newly created StudentExam + */ public StudentExam setupTestRunForExamWithExerciseGroupsForInstructor(Exam exam, User instructor, List exerciseGroupsWithExercises) { List exercises = new ArrayList<>(); exerciseGroupsWithExercises.forEach(exerciseGroup -> exercises.add(exerciseGroup.getExercises().iterator().next())); @@ -125,6 +149,14 @@ public StudentExam setupTestRunForExamWithExerciseGroupsForInstructor(Exam exam, return studentExamRepository.save(testRun); } + /** + * Creates and saves a StudentExam and StudentParticipations for a test run. + * + * @param exam The exam for which the test run should be created + * @param instructor The user who should be registered for the test run + * @param exercises The Exercises that should be added to the test run + * @return The newly created StudentExam + */ public StudentExam generateTestRunForInstructor(Exam exam, User instructor, List exercises) { var testRun = ExamFactory.generateExamTestRun(exam); testRun.setUser(instructor); @@ -157,6 +189,12 @@ else if (exercise instanceof FileUploadExercise fileUploadExercise) { return testRun; } + /** + * Creates and saves an Exam with one mandatory ExerciseGroup with three TextExercises. + * + * @param course The course to which the exam should be added + * @return The newly created Exam + */ public Exam setupSimpleExamWithExerciseGroupExercise(Course course) { var exam = ExamFactory.generateExam(course); exam.setNumberOfExercisesInExam(1); @@ -179,6 +217,15 @@ public Exam setupSimpleExamWithExerciseGroupExercise(Course course) { return examRepository.findWithExerciseGroupsAndExercisesByIdOrElseThrow(exam.getId()); } + /** + * Creates and saves an Exam with three mandatory and two optional ExerciseGroups. Each ExerciseGroup contains three TextExercises. Registers students for the exam given the + * userPrefix and numberOfStudents. + * + * @param userPrefix The prefix of the users + * @param course The course to which the exam should be added + * @param numberOfStudents The number of students that should be registered for the exam + * @return The newly created Exam + */ public Exam setupExamWithExerciseGroupsExercisesRegisteredStudents(String userPrefix, Course course, int numberOfStudents) { Exam exam = ExamFactory.generateExam(course); exam.setNumberOfExercisesInExam(4); @@ -229,18 +276,26 @@ public Exam setupExamWithExerciseGroupsExercisesRegisteredStudents(String userPr return registerUsersForExamAndSaveExam(exam, userPrefix, numberOfStudents); } + /** + * Saves the updated Exam after registering new Users. + * + * @param exam The exam for which the users should be registered + * @param userPrefix The prefix of the users + * @param numberOfStudents The number of students that should be registered for the exam + * @return The updated Exam + */ public Exam registerUsersForExamAndSaveExam(Exam exam, String userPrefix, int numberOfStudents) { return registerUsersForExamAndSaveExam(exam, userPrefix, 1, numberOfStudents); } /** - * registers students for exam and saves the exam in the repository + * Saves and updates the Exam after registering new Users. * - * @param exam exam to which students should be registered to - * @param userPrefix prefix of the users - * @param from index of the first student to be registered - * @param to index of the last student to be registered - * @return exam that was saved in the repository + * @param exam The exam for which the users should be registered + * @param userPrefix The prefix of the users + * @param from The index of the first student to be registered + * @param to The index of the last student to be registered + * @return The updated Exam */ public Exam registerUsersForExamAndSaveExam(Exam exam, String userPrefix, int from, int to) { @@ -255,16 +310,35 @@ public Exam registerUsersForExamAndSaveExam(Exam exam, String userPrefix, int fr return examRepository.save(exam); } + /** + * Creates and saves an Exam without ExerciseGroups and Exercises. + * + * @param course The course to which the exam should be added + * @return The newly created Exam + */ public Exam addExam(Course course) { Exam exam = ExamFactory.generateExam(course); return examRepository.save(exam); } + /** + * Creates and saves a test Exam without ExerciseGroups and Exercises. + * + * @param course The course to which the exam should be added + * @return The newly created Exam + */ public Exam addTestExam(Course course) { Exam exam = ExamFactory.generateTestExam(course); return examRepository.save(exam); } + /** + * Creates and saves a test Exam without Exercises and registers the given user to the exam. + * + * @param course The course to which the exam should be added + * @param user The user who should be registered for the exam + * @return The newly created Exam + */ public Exam addTestExamWithRegisteredUser(Course course, User user) { Exam exam = ExamFactory.generateTestExam(course); exam = examRepository.save(exam); @@ -278,15 +352,15 @@ public Exam addTestExamWithRegisteredUser(Course course, User user) { } /** - * creates and saves an exam with the passed user + * Creates and saves an Exam with a registered User and an optional ExerciseGroup. * - * @param course course of the exam - * @param user registered exam user - * @param exerciseGroup should an (empty) exercise group be added - * @param visibleDate visible date of the exam - * @param startDate start date of the exam - * @param endDate end date of the exam - * @return newly created exam + * @param course The course to which the exam should be added + * @param user The user who should be registered for the exam + * @param exerciseGroup True, if an empty ExerciseGroup should be added to the exam + * @param visibleDate The visible date of the exam + * @param startDate The start date of the exam + * @param endDate The end date of the exam + * @return The newly created Exam */ public Exam addExamWithUser(Course course, User user, boolean exerciseGroup, ZonedDateTime visibleDate, ZonedDateTime startDate, ZonedDateTime endDate) { Exam exam = ExamFactory.generateExam(course); From 52368f3d4bc39127f3269bed8ae709f26152b288 Mon Sep 17 00:00:00 2001 From: Dominik Remo <47261058+DominikRemo@users.noreply.github.com> Date: Fri, 6 Oct 2023 12:38:28 +0200 Subject: [PATCH 4/5] Actually commit and push all changes Next time before setting ready for review --- .../tum/in/www1/artemis/exam/ExamFactory.java | 16 +- .../in/www1/artemis/exam/ExamUtilService.java | 271 ++++++++++++++---- 2 files changed, 217 insertions(+), 70 deletions(-) diff --git a/src/test/java/de/tum/in/www1/artemis/exam/ExamFactory.java b/src/test/java/de/tum/in/www1/artemis/exam/ExamFactory.java index 5fba65ec6fb0..f50f69f62009 100644 --- a/src/test/java/de/tum/in/www1/artemis/exam/ExamFactory.java +++ b/src/test/java/de/tum/in/www1/artemis/exam/ExamFactory.java @@ -56,10 +56,10 @@ public static Exam generateExam(Course course, String channelName) { * Creates an Exam without a Channel * * @param course The associated course - * @param visibleDate The visible date of the exam - * @param startDate The start date of the exam - * @param endDate The end date of the exam - * @param testExam True, if the exam is a test exam + * @param visibleDate The visible date of the Exam + * @param startDate The start date of the Exam + * @param endDate The end date of the Exam + * @param testExam True, if the Exam is a test exam * @return The newly created Exam */ public static Exam generateExam(Course course, ZonedDateTime visibleDate, ZonedDateTime startDate, ZonedDateTime endDate, boolean testExam) { @@ -70,10 +70,10 @@ public static Exam generateExam(Course course, ZonedDateTime visibleDate, ZonedD * Creates an Exam with a Channel * * @param course The associated course - * @param visibleDate The visible date of the exam - * @param startDate The start date of the exam - * @param endDate The end date of the exam - * @param testExam True, if the exam is a test exam + * @param visibleDate The visible date of the Exam + * @param startDate The start date of the Exam + * @param endDate The end date of the Exam + * @param testExam True, if the Exam is a test exam * @param channelName The channel name * @return The newly created Exam */ diff --git a/src/test/java/de/tum/in/www1/artemis/exam/ExamUtilService.java b/src/test/java/de/tum/in/www1/artemis/exam/ExamUtilService.java index f5717ac8448d..14f6bb5123ac 100644 --- a/src/test/java/de/tum/in/www1/artemis/exam/ExamUtilService.java +++ b/src/test/java/de/tum/in/www1/artemis/exam/ExamUtilService.java @@ -105,10 +105,10 @@ public class ExamUtilService { /** * Creates and saves a course with an exam and an exercise group with all exercise types excluding programming exercises. * - * @param user The user who should be registered for the exam - * @param visible The visible date of the exam - * @param start The start date of the exam - * @param end The end date of the exam + * @param user The User who should be registered for the Exam + * @param visible The visible date of the Exam + * @param start The start date of the Exam + * @param end The end date of the Exam * @return The newly created course */ public Course createCourseWithExamAndExerciseGroupAndExercises(User user, ZonedDateTime visible, ZonedDateTime start, ZonedDateTime end) { @@ -123,7 +123,7 @@ public Course createCourseWithExamAndExerciseGroupAndExercises(User user, ZonedD * Creates and saves a course with an exam and an exercise group with all exercise types excluding programming exercises. Sets the visible (now - 1 min), start (now) and end * (now + 1 min) date with default values. * - * @param user The user who should be registered for the exam + * @param user The User who should be registered for the Exam * @return The newly created course */ public Course createCourseWithExamAndExerciseGroupAndExercises(User user) { @@ -138,7 +138,7 @@ public Course createCourseWithExamAndExerciseGroupAndExercises(User user) { * Creates and saves a StudentExam for a test run. * * @param exam The exam for which the test run should be created - * @param instructor The user who should be registered for the test run + * @param instructor The User who should be registered for the test run * @param exerciseGroupsWithExercises The ExerciseGroups with Exercises that should be added to the test run * @return The newly created StudentExam */ @@ -153,7 +153,7 @@ public StudentExam setupTestRunForExamWithExerciseGroupsForInstructor(Exam exam, * Creates and saves a StudentExam and StudentParticipations for a test run. * * @param exam The exam for which the test run should be created - * @param instructor The user who should be registered for the test run + * @param instructor The User who should be registered for the test run * @param exercises The Exercises that should be added to the test run * @return The newly created StudentExam */ @@ -192,7 +192,7 @@ else if (exercise instanceof FileUploadExercise fileUploadExercise) { /** * Creates and saves an Exam with one mandatory ExerciseGroup with three TextExercises. * - * @param course The course to which the exam should be added + * @param course The Course to which the Exam should be added * @return The newly created Exam */ public Exam setupSimpleExamWithExerciseGroupExercise(Course course) { @@ -218,12 +218,12 @@ public Exam setupSimpleExamWithExerciseGroupExercise(Course course) { } /** - * Creates and saves an Exam with three mandatory and two optional ExerciseGroups. Each ExerciseGroup contains three TextExercises. Registers students for the exam given the + * Creates and saves an Exam with three mandatory and two optional ExerciseGroups. Each ExerciseGroup contains three TextExercises. Registers students for the Exam given the * userPrefix and numberOfStudents. * * @param userPrefix The prefix of the users - * @param course The course to which the exam should be added - * @param numberOfStudents The number of students that should be registered for the exam + * @param course The Course to which the Exam should be added + * @param numberOfStudents The number of students that should be registered for the Exam * @return The newly created Exam */ public Exam setupExamWithExerciseGroupsExercisesRegisteredStudents(String userPrefix, Course course, int numberOfStudents) { @@ -277,11 +277,11 @@ public Exam setupExamWithExerciseGroupsExercisesRegisteredStudents(String userPr } /** - * Saves the updated Exam after registering new Users. + * Saves and updates the Exam after registering new Users. * * @param exam The exam for which the users should be registered * @param userPrefix The prefix of the users - * @param numberOfStudents The number of students that should be registered for the exam + * @param numberOfStudents The number of students that should be registered for the Exam * @return The updated Exam */ public Exam registerUsersForExamAndSaveExam(Exam exam, String userPrefix, int numberOfStudents) { @@ -313,7 +313,7 @@ public Exam registerUsersForExamAndSaveExam(Exam exam, String userPrefix, int fr /** * Creates and saves an Exam without ExerciseGroups and Exercises. * - * @param course The course to which the exam should be added + * @param course The Course to which the Exam should be added * @return The newly created Exam */ public Exam addExam(Course course) { @@ -324,7 +324,7 @@ public Exam addExam(Course course) { /** * Creates and saves a test Exam without ExerciseGroups and Exercises. * - * @param course The course to which the exam should be added + * @param course The Course to which the Exam should be added * @return The newly created Exam */ public Exam addTestExam(Course course) { @@ -333,10 +333,10 @@ public Exam addTestExam(Course course) { } /** - * Creates and saves a test Exam without Exercises and registers the given user to the exam. + * Creates and saves a test Exam without Exercises and registers the given user to the Exam. * - * @param course The course to which the exam should be added - * @param user The user who should be registered for the exam + * @param course The Course to which the Exam should be added + * @param user The User who should be registered for the Exam * @return The newly created Exam */ public Exam addTestExamWithRegisteredUser(Course course, User user) { @@ -354,12 +354,12 @@ public Exam addTestExamWithRegisteredUser(Course course, User user) { /** * Creates and saves an Exam with a registered User and an optional ExerciseGroup. * - * @param course The course to which the exam should be added - * @param user The user who should be registered for the exam - * @param exerciseGroup True, if an empty ExerciseGroup should be added to the exam - * @param visibleDate The visible date of the exam - * @param startDate The start date of the exam - * @param endDate The end date of the exam + * @param course The Course to which the Exam should be added + * @param user The User who should be registered for the Exam + * @param exerciseGroup True, if an empty ExerciseGroup should be added to the Exam + * @param visibleDate The visible date of the Exam + * @param startDate The start date of the Exam + * @param endDate The end date of the Exam * @return The newly created Exam */ public Exam addExamWithUser(Course course, User user, boolean exerciseGroup, ZonedDateTime visibleDate, ZonedDateTime startDate, ZonedDateTime endDate) { @@ -382,12 +382,30 @@ public Exam addExamWithUser(Course course, User user, boolean exerciseGroup, Zon return exam; } - public Exam addExam(Course course, User user, ZonedDateTime visibleDate, ZonedDateTime startDate, ZonedDateTime endDate, ZonedDateTime resultsPublicationDate) { + /** + * Creates and saves an Exam with a registered User, with a results publication date and without an ExerciseGroup. + * + * @param course The Course to which the Exam should be added + * @param user The User who should be registered for the Exam + * @param visibleDate The visible date of the Exam + * @param startDate The start date of the Exam + * @param endDate The end date of the Exam + * @param publishResultsDate The results publication date of the Exam + * @return The newly created Exam + */ + public Exam addExam(Course course, User user, ZonedDateTime visibleDate, ZonedDateTime startDate, ZonedDateTime endDate, ZonedDateTime publishResultsDate) { Exam exam = addExamWithUser(course, user, false, visibleDate, startDate, endDate); - exam.setPublishResultsDate(resultsPublicationDate); + exam.setPublishResultsDate(publishResultsDate); return examRepository.save(exam); } + /** + * Creates and saves an Exam with a registered User and an ExerciseGroup. The Exam is visible, starts in 10 minutes, and ends in 60 minutes. + * + * @param course The Course to which the Exam should be added + * @param mandatory True, if the ExerciseGroup should be mandatory + * @return The newly created Exam + */ public Exam addExamWithExerciseGroup(Course course, boolean mandatory) { Exam exam = ExamFactory.generateExam(course); ExamFactory.generateExerciseGroup(mandatory, exam); @@ -395,6 +413,13 @@ public Exam addExamWithExerciseGroup(Course course, boolean mandatory) { return exam; } + /** + * Creates and saves a test Exam with a registered User and an ExerciseGroup. The Exam is visible, starts in 10 minutes, and ends in 80 minutes. + * + * @param course The Course to which the Exam should be added + * @param mandatory True, if the ExerciseGroup should be mandatory + * @return The newly created Exam + */ public Exam addTestExamWithExerciseGroup(Course course, boolean mandatory) { Exam exam = ExamFactory.generateTestExam(course); ExamFactory.generateExerciseGroup(mandatory, exam); @@ -402,6 +427,15 @@ public Exam addTestExamWithExerciseGroup(Course course, boolean mandatory) { return exam; } + /** + * Creates and saves an Exam without ExerciseGroups and Exercises. + * + * @param course The Course to which the Exam should be added + * @param visibleDate The visible date of the Exam + * @param startDate The start date of the Exam + * @param endDate The end date of the Exam + * @return The newly created Exam + */ public Exam addExam(Course course, ZonedDateTime visibleDate, ZonedDateTime startDate, ZonedDateTime endDate) { Exam exam = ExamFactory.generateExam(course); exam.setVisibleDate(visibleDate); @@ -413,24 +447,48 @@ public Exam addExam(Course course, ZonedDateTime visibleDate, ZonedDateTime star return exam; } - public Exam addExam(Course course, ZonedDateTime visibleDate, ZonedDateTime startDate, ZonedDateTime endDate, ZonedDateTime publishResultDate) { + /** + * Creates and saves an Exam without ExerciseGroups and Exercises. + * + * @param course The Course to which the Exam should be added + * @param visibleDate The visible date of the Exam + * @param startDate The start date of the Exam + * @param endDate The end date of the Exam + * @param publishResultsDate The results publication date of the Exam + * @return The newly created Exam + */ + public Exam addExam(Course course, ZonedDateTime visibleDate, ZonedDateTime startDate, ZonedDateTime endDate, ZonedDateTime publishResultsDate) { Exam exam = ExamFactory.generateExam(course); exam.setVisibleDate(visibleDate); exam.setStartDate(startDate); exam.setEndDate(endDate); - exam.setPublishResultsDate(publishResultDate); + exam.setPublishResultsDate(publishResultsDate); exam.setWorkingTime(exam.getDuration()); exam.setGracePeriod(180); exam = examRepository.save(exam); return exam; } + /** + * Creates and saves a Channel for the given Exam. + * + * @param exam The Exam for which the Channel should be created + * @param channelName The channel name + * @return The newly created Channel + */ public Channel addExamChannel(Exam exam, String channelName) { Channel channel = ConversationFactory.generatePublicChannel(exam.getCourse(), channelName, true); channel.setExam(exam); return conversationRepository.save(channel); } + /** + * Creates and saves an Exam and corresponding StudentExam with a registered User. The Exam started 1 hour ago and ends in 1 hour. + * + * @param course The Course to which the Exam should be added + * @param user The User who should be registered for the Exam + * @return The newly created Exam + */ public Exam addActiveExamWithRegisteredUser(Course course, User user) { Exam exam = ExamFactory.generateExam(course); exam.setStartDate(ZonedDateTime.now().minusHours(1)); @@ -453,6 +511,13 @@ public Exam addActiveExamWithRegisteredUser(Course course, User user) { return exam; } + /** + * Creates and saves an Exam with a registered User and without a StudentExam. The Exam started 1 hour ago and ends in 1 hour. + * + * @param course The Course to which the Exam should be added + * @param user The User who should be registered for the Exam + * @return The newly created Exam + */ public Exam addActiveTestExamWithRegisteredUserWithoutStudentExam(Course course, User user) { Exam exam = ExamFactory.generateTestExam(course); exam.setStartDate(ZonedDateTime.now().minusHours(1)); @@ -468,6 +533,12 @@ public Exam addActiveTestExamWithRegisteredUserWithoutStudentExam(Course course, return exam; } + /** + * Creates and saves an Exam with five ExerciseGroups (0: modelling, 1: text, 2: file upload, 3: quiz, 4: empty) + * + * @param course The Course to which the Exam should be added + * @return The newly created Exam + */ public Exam addExamWithModellingAndTextAndFileUploadAndQuizAndEmptyGroup(Course course) { Exam exam = addExam(course); for (int i = 0; i <= 4; i++) { @@ -500,16 +571,36 @@ public Exam addExamWithModellingAndTextAndFileUploadAndQuizAndEmptyGroup(Course return exam; } + /** + * Creates and saves a StudentExam for the given Exam. + * + * @param exam The Exam for which the StudentExam should be created + * @return The newly created StudentExam + */ public StudentExam addStudentExam(Exam exam) { StudentExam studentExam = ExamFactory.generateStudentExam(exam); studentExam = studentExamRepository.save(studentExam); return studentExam; } - public StudentExam addStudentExamWithUser(Exam exam, String user) { - return addStudentExamWithUser(exam, userRepo.findOneByLogin(user).orElseThrow()); + /** + * Creates and saves a StudentExam for the given Exam and the user's login. + * + * @param exam The Exam for which the StudentExam should be created + * @param userLogin The login of the User for which the StudentExam should be created + * @return The newly created StudentExam + */ + public StudentExam addStudentExamWithUser(Exam exam, String userLogin) { + return addStudentExamWithUser(exam, userRepo.findOneByLogin(userLogin).orElseThrow()); } + /** + * Creates and saves a StudentExam for the given Exam and User. + * + * @param exam The Exam for which the StudentExam should be created + * @param user The User for which the StudentExam should be created + * @return The newly created StudentExam + */ public StudentExam addStudentExamWithUser(Exam exam, User user) { StudentExam studentExam = ExamFactory.generateStudentExam(exam); studentExam.setUser(user); @@ -519,15 +610,15 @@ public StudentExam addStudentExamWithUser(Exam exam, User user) { } /** - * Adds an exam session with the given parameters to the given student exam, associates the exam session with the given student exam and saves both entities in the database. + * Creates and saves an ExamSession with the given parameters and adds it to the given student exam. * - * @param studentExam the student exam to which the exam session should be added - * @param sessionToken the session token of the exam session - * @param ipAddress the IP address of the exam session - * @param browserFingerprint the browser fingerprint hash of the exam session - * @param instanceId the instance id of the exam session - * @param userAgent the user agent of the exam session - * @return the exam session that was added to the student exam + * @param studentExam The StudentExam to which the ExamSession should be added + * @param sessionToken The session token of the ExamSession + * @param ipAddress The IP address of the ExamSession + * @param browserFingerprint The browser fingerprint hash of the ExamSession + * @param instanceId The instance id of the ExamSession + * @param userAgent The user agent of the ExamSession + * @return The ExamSession that was added to the student exam */ public ExamSession addExamSessionToStudentExam(StudentExam studentExam, String sessionToken, String ipAddress, String browserFingerprint, String instanceId, String userAgent) { ExamSession examSession = new ExamSession(); @@ -544,17 +635,37 @@ public ExamSession addExamSessionToStudentExam(StudentExam studentExam, String s return examSession; } - public StudentExam addStudentExamForActiveExamWithUser(String user) { + /** + * Creates and saves a StudentExam with a registered User. Also creates and saves an empty course and an Exam that started 1 hour ago and ends in 1 hour. + * + * @param userLogin The login of the User for which the StudentExam should be created + * @return The newly created StudentExam + */ + public StudentExam addStudentExamForActiveExamWithUser(String userLogin) { Course course = courseUtilService.addEmptyCourse(); - User studentUser = userUtilService.getUserByLogin(user); + User studentUser = userUtilService.getUserByLogin(userLogin); Exam exam = addActiveTestExamWithRegisteredUserWithoutStudentExam(course, studentUser); return addStudentExamWithUser(exam, studentUser, 0); } + /** + * Creates and saves a StudentExam with a registered User. + * + * @param exam The Exam for which the StudentExam should be created + * @param userLogin The login of the User for which the StudentExam should be created + * @return The newly created StudentExam + */ public StudentExam addStudentExamForTestExam(Exam exam, String userLogin) { return addStudentExamForTestExam(exam, userUtilService.getUserByLogin(userLogin)); } + /** + * Creates and saves a StudentExam with a registered User. + * + * @param exam The Exam for which the StudentExam should be created + * @param user The User for which the StudentExam should be created + * @return The newly created StudentExam + */ public StudentExam addStudentExamForTestExam(Exam exam, User user) { StudentExam studentExam = ExamFactory.generateStudentExamForTestExam(exam); studentExam.setUser(user); @@ -562,6 +673,14 @@ public StudentExam addStudentExamForTestExam(Exam exam, User user) { return studentExam; } + /** + * Creates and saves a StudentExam with a registered User and additional working time. + * + * @param exam The Exam for which the StudentExam should be created + * @param user The User for which the StudentExam should be created + * @param additionalWorkingTime The additional working time for the StudentExam in seconds + * @return The newly created StudentExam + */ public StudentExam addStudentExamWithUser(Exam exam, User user, int additionalWorkingTime) { StudentExam studentExam = ExamFactory.generateStudentExam(exam); studentExam.setUser(user); @@ -570,10 +689,27 @@ public StudentExam addStudentExamWithUser(Exam exam, User user, int additionalWo return studentExam; } + /** + * Creates and saves ExerciseGroups and Exercises for the given Exam. + * (Groups 0: text, 1: quiz, 2: file upload, 3: modeling, 4: bonus text, 5: not included text, 7 (optional): programming). + * + * @param exam The Exam for which the ExerciseGroups and Exercises should be created + * @param withProgrammingExercise True, if a ProgrammingExercise should be added + * @return The updated Exam + */ public Exam addExerciseGroupsAndExercisesToExam(Exam exam, boolean withProgrammingExercise) { return addExerciseGroupsAndExercisesToExam(exam, withProgrammingExercise, false); } + /** + * Creates and saves ExerciseGroups and Exercises for the given Exam + * (Groups 0: text, 1: quiz, 2: file upload, 3: modeling, 4: bonus text, 5: not included text, 7 (optional): programming). + * + * @param exam The Exam for which the ExerciseGroups and Exercises should be created + * @param withProgrammingExercise True, if a ProgrammingExercise should be added + * @param withAllQuizQuestionTypes True, if all QuizQuestionTypes should be added to the QuizExercise + * @return The updated Exam + */ public Exam addExerciseGroupsAndExercisesToExam(Exam exam, boolean withProgrammingExercise, boolean withAllQuizQuestionTypes) { ExamFactory.generateExerciseGroup(true, exam); // text ExamFactory.generateExerciseGroup(true, exam); // quiz @@ -651,12 +787,13 @@ public Exam addExerciseGroupsAndExercisesToExam(Exam exam, boolean withProgrammi } /** - * Creates and saves a text, modeling, optional programming and optional quiz exercise and adds them to the exam. + * Creates and saves ExerciseGroups and Exercises for the given Exam. + * (Groups 0: text, 1: modeling, 2 (optional): programming, 3 (optional): quiz). * - * @param initialExam the exam to which the exercises should be added - * @param withProgrammingExercise whether a programming exercise should be added - * @param withQuizExercise whether a quiz exercise should be added - * @return the exam with the added exercises + * @param initialExam The Exam for which the ExerciseGroups and Exercises should be created + * @param withProgrammingExercise True, if a ProgrammingExercise should be added + * @param withQuizExercise True, if a QuizExercise should be added + * @return The updated Exam */ public Exam addTextModelingProgrammingExercisesToExam(Exam initialExam, boolean withProgrammingExercise, boolean withQuizExercise) { ExamFactory.generateExerciseGroup(true, initialExam); // text @@ -706,10 +843,10 @@ public Exam addTextModelingProgrammingExercisesToExam(Exam initialExam, boolean } /** - * Creates and saves an active course with an exam and an exercise group. + * Creates and saves an Exam with an ExerciseGroup for a newly created, active course with default group names. * - * @param mandatory true if the exercise group is mandatory - * @return the created exercise group + * @param mandatory True, if the ExerciseGroup should be mandatory + * @return The newly created ExerciseGroup */ public ExerciseGroup addExerciseGroupWithExamAndCourse(boolean mandatory) { Course course = CourseFactory.generateCourse(null, pastTimestamp, futureFutureTimestamp, new HashSet<>(), "tumuser", "tutor", "editor", "instructor"); @@ -738,10 +875,10 @@ public ExerciseGroup addExerciseGroupWithExamAndCourse(boolean mandatory) { } /** - * Creates and saves an active course with an exam and an exercise group. The exam has a review date [now; now + 60min]. + * Creates and saves an Exam with an ExerciseGroup for a newly created, active course. The exam has a review date [now; now + 60min]. * - * @param mandatory true if the exercise group is mandatory - * @return the created exercise group + * @param mandatory True, if the ExerciseGroup should be mandatory + * @return The newly created ExerciseGroup */ public ExerciseGroup addExerciseGroupWithExamWithReviewDatesAndCourse(boolean mandatory) { Course course = CourseFactory.generateCourse(null, pastTimestamp, futureFutureTimestamp, new HashSet<>(), "tumuser", "tutor", "editor", "instructor"); @@ -770,10 +907,10 @@ public ExerciseGroup addExerciseGroupWithExamWithReviewDatesAndCourse(boolean ma } /** - * creates and saves an exam exercise group in a course that is currently active. + * Creates and saves an Exam with an ExerciseGroup for a newly created, active course. * - * @param mandatory if the exerciseGroup is mandatory - * @return exercise group created + * @param mandatory True, if the ExerciseGroup should be mandatory + * @return The newly created ExerciseGroup */ public ExerciseGroup createAndSaveActiveExerciseGroup(boolean mandatory) { Course course = courseUtilService.createAndSaveCourse(1L, pastTimestamp, futureFutureTimestamp, Set.of()); @@ -785,12 +922,12 @@ public ExerciseGroup createAndSaveActiveExerciseGroup(boolean mandatory) { } /** - * sets the visible, start and end date of the exam. The working time gets set accordingly. + * Sets the visible, start and end date of the Exam. The working time gets set accordingly. Does not save the changes to the database. * - * @param exam exam that gets the dates set - * @param visibleDate new visible date of the exam - * @param startDate new start date of the exam - * @param endDate new end date of the exam + * @param exam The Exam that gets the dates set + * @param visibleDate The new visible date of the Exam + * @param startDate The new start date of the Exam + * @param endDate The new end date of the Exam */ public void setVisibleStartAndEndDateOfExam(Exam exam, ZonedDateTime visibleDate, ZonedDateTime startDate, ZonedDateTime endDate) { exam.setVisibleDate(visibleDate); @@ -799,6 +936,16 @@ public void setVisibleStartAndEndDateOfExam(Exam exam, ZonedDateTime visibleDate exam.setWorkingTime(exam.getDuration()); } + /** + * Creates and saves StudentParticipations and Submissions for the given Exam. Expects the exam to have six ExerciseGroups + * (Expected Groups 0: text, 1: quiz, 2: file upload, 3: modeling, 4: any, 5: any, 6: programming). + * + * @param exam The Exam for which the StudentParticipations and Submissions should be created + * @param studentExam The StudentExam for which the StudentParticipations and Submissions should be created + * @param validModel The valid model for the modeling exercise + * @param localRepoPath The local repository path for the programming exercise + * @return The updated StudentExam + */ public StudentExam addExercisesWithParticipationsAndSubmissionsToStudentExam(Exam exam, StudentExam studentExam, String validModel, URI localRepoPath) { var exerciseGroups = exam.getExerciseGroups(); // text exercise @@ -889,10 +1036,10 @@ public StudentExam addExercisesWithParticipationsAndSubmissionsToStudentExam(Exa } /** - * gets the number of programming exercises in the exam + * Gets the number of programming exercises in the Exam * - * @param examId id of the exam to be searched for programming exercises - * @return number of programming exercises in the exams + * @param examId The id of the Exam to be searched for programming exercises + * @return The number of programming exercises in the Exam */ public int getNumberOfProgrammingExercises(Long examId) { Exam exam = examRepository.findWithExerciseGroupsAndExercisesByIdOrElseThrow(examId); From 9d72902de3247c3e20369cdf22d4d2236484e79d Mon Sep 17 00:00:00 2001 From: Dominik Remo <47261058+DominikRemo@users.noreply.github.com> Date: Fri, 13 Oct 2023 07:49:35 +0200 Subject: [PATCH 5/5] Implement feedback by @laadvo --- src/test/java/de/tum/in/www1/artemis/exam/ExamUtilService.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/test/java/de/tum/in/www1/artemis/exam/ExamUtilService.java b/src/test/java/de/tum/in/www1/artemis/exam/ExamUtilService.java index 14f6bb5123ac..fe7229ddd4f2 100644 --- a/src/test/java/de/tum/in/www1/artemis/exam/ExamUtilService.java +++ b/src/test/java/de/tum/in/www1/artemis/exam/ExamUtilService.java @@ -636,7 +636,8 @@ public ExamSession addExamSessionToStudentExam(StudentExam studentExam, String s } /** - * Creates and saves a StudentExam with a registered User. Also creates and saves an empty course and an Exam that started 1 hour ago and ends in 1 hour. + * Creates and saves a StudentExam with a registered User. Creates and saves an empty Course first. Then, given the new Course and User, creates and saves an Exam that + * started 1 hour ago and ends in 1 hour. The Exam is then used to create the StudentExam. * * @param userLogin The login of the User for which the StudentExam should be created * @return The newly created StudentExam