From 3f6739c18b8ff08f559b118f9457f7881c90a26d Mon Sep 17 00:00:00 2001 From: lara Date: Sat, 14 Oct 2023 13:46:50 +0200 Subject: [PATCH 1/4] add javadoc to QuizExerciseFactory --- .../quizexercise/QuizExerciseFactory.java | 190 ++++++++++++++---- .../quizexercise/QuizExerciseUtilService.java | 58 +++++- 2 files changed, 204 insertions(+), 44 deletions(-) diff --git a/src/test/java/de/tum/in/www1/artemis/exercise/quizexercise/QuizExerciseFactory.java b/src/test/java/de/tum/in/www1/artemis/exercise/quizexercise/QuizExerciseFactory.java index 2b6fe03b6a68..e4d5d9ed357f 100644 --- a/src/test/java/de/tum/in/www1/artemis/exercise/quizexercise/QuizExerciseFactory.java +++ b/src/test/java/de/tum/in/www1/artemis/exercise/quizexercise/QuizExerciseFactory.java @@ -28,6 +28,16 @@ */ public class QuizExerciseFactory { + /** + * Creates a quiz exercise with given dates and adds it to the course. + * The quiz consist of one multiple choice, one drag and drop, and one short answer question. + * + * @param course The course the quiz should be added to. + * @param releaseDate The release date of the quiz. + * @param dueDate The due date of the quiz. + * @param quizMode The quiz mode used. + * @return The newly created quiz. + */ @NotNull public static QuizExercise createQuiz(Course course, ZonedDateTime releaseDate, ZonedDateTime dueDate, QuizMode quizMode) { QuizExercise quizExercise = generateQuizExercise(releaseDate, dueDate, quizMode, course); @@ -36,6 +46,13 @@ public static QuizExercise createQuiz(Course course, ZonedDateTime releaseDate, return quizExercise; } + /** + * Creates a quiz exercise for an exam with given dates and adds it to the course. + * The quiz consist of one multiple choice, one drag and drop, and one short answer question. + * + * @param exerciseGroup Exercise group of an exam to which the quiz should be added. + * @return The newly created quiz. + */ @NotNull public static QuizExercise createQuizForExam(ExerciseGroup exerciseGroup) { QuizExercise quizExercise = generateQuizExerciseForExam(exerciseGroup); @@ -45,9 +62,10 @@ public static QuizExercise createQuizForExam(ExerciseGroup exerciseGroup) { } /** - * initializes a quiz with all different types of questions + * Initializes a quiz exercise with different types of questions. + * After initialization, the quiz consists of one multiple choice, one drag and drop, and one short answer question. * - * @param quizExercise to be initialized + * @param quizExercise The quiz to be initialized. */ public static void initializeQuizExercise(QuizExercise quizExercise) { quizExercise.addQuestions(createMultipleChoiceQuestion()); @@ -57,6 +75,12 @@ public static void initializeQuizExercise(QuizExercise quizExercise) { quizExercise.setGradingInstructions(null); } + /** + * Creates a short answer question with score 2 and 2 different spot-solution mappings. + * The scoring type of the question is proportional without penalty. + * + * @return The newly created short answer question. + */ @NotNull public static ShortAnswerQuestion createShortAnswerQuestion() { ShortAnswerQuestion sa = (ShortAnswerQuestion) new ShortAnswerQuestion().title("SA").score(2).text("This is a long answer text"); @@ -106,6 +130,12 @@ public static ShortAnswerQuestion createShortAnswerQuestion() { return sa; } + /** + * Creates a drag and drop question with score 3 and 3 different location-drag item mappings. + * The scoring type of the question is proportional with penalty. + * + * @return The newly created drag and drop question. + */ @NotNull public static DragAndDropQuestion createDragAndDropQuestion() { DragAndDropQuestion dnd = (DragAndDropQuestion) new DragAndDropQuestion().title("DnD").score(3).text("Q2"); @@ -160,10 +190,21 @@ public static DragAndDropQuestion createDragAndDropQuestion() { return dnd; } + /** + * Generates a temporary id using ThreadLocalRandom for a quiz exercise. + * + * @return The generated temporary id. + */ public static Long generateTempId() { return ThreadLocalRandom.current().nextLong(Long.MAX_VALUE); } + /** + * Creates a multiple choice question with score 4 and 2 different answer options. One answer is correct and the other one incorrect. + * The scoring type of the question is all or nothing. + * + * @return The newly created multiple choice question. + */ @NotNull public static MultipleChoiceQuestion createMultipleChoiceQuestion() { MultipleChoiceQuestion mc = (MultipleChoiceQuestion) new MultipleChoiceQuestion().title("MC").score(4).text("Q1"); @@ -176,6 +217,13 @@ public static MultipleChoiceQuestion createMultipleChoiceQuestion() { return mc; } + /** + * Generates a quiz batch for the given quiz using the given start time. + * + * @param quizExercise The quiz to which a batch should be added. + * @param startTime The start time of the batch. + * @return The newly created quiz batch. + */ public static QuizBatch generateQuizBatch(QuizExercise quizExercise, ZonedDateTime startTime) { var quizBatch = new QuizBatch(); quizBatch.setQuizExercise(quizExercise); @@ -183,10 +231,29 @@ public static QuizBatch generateQuizBatch(QuizExercise quizExercise, ZonedDateTi return quizBatch; } + /** + * Generates a quiz exercise without an assessment due date and adds it to the given course. + * + * @param releaseDate The release date of the quiz. + * @param dueDate The due date of the quiz. + * @param quizMode The quiz mode of the quiz. + * @param course The course to which the quiz should be added to. + * @return The newly created quiz exercise. + */ public static QuizExercise generateQuizExercise(ZonedDateTime releaseDate, ZonedDateTime dueDate, QuizMode quizMode, Course course) { return generateQuizExercise(releaseDate, dueDate, null, quizMode, course); } + /** + * Generates a quiz exercise using the passed dates and adds it to the given course. + * + * @param releaseDate The release date of the quiz. + * @param dueDate The due date of the quiz. + * @param assessmentDueDate The assessment due date of the quiz. + * @param quizMode The quiz mode of the quiz. + * @param course The course to which the quiz should be added to. + * @return The newly created quiz exercise. + */ public static QuizExercise generateQuizExercise(ZonedDateTime releaseDate, ZonedDateTime dueDate, ZonedDateTime assessmentDueDate, QuizMode quizMode, Course course) { QuizExercise quizExercise = (QuizExercise) ExerciseFactory.populateExercise(new QuizExercise(), releaseDate, dueDate, assessmentDueDate, course); quizExercise.setTitle("new quiz"); @@ -206,11 +273,12 @@ public static QuizExercise generateQuizExercise(ZonedDateTime releaseDate, Zoned } /** - * Generates a submitted answer for a given question. + * Generates a submitted answer for the given quiz question of any type. + * The correctness of the answer depends on the passed correct value. * - * @param question given question, the answer is for - * @param correct boolean whether the answer should be correct or not - * @return created SubmittedAnswer + * @param question The quiz question to which a submitted answer should be added. + * @param correct True, if the answer should be correct. + * @return The newly generated submitted answer. */ public static SubmittedAnswer generateSubmittedAnswerFor(QuizQuestion question, boolean correct) { if (question instanceof MultipleChoiceQuestion) { @@ -283,6 +351,12 @@ else if (question instanceof ShortAnswerQuestion) { return null; } + /** + * Generates a quiz exercise for an exam with the duration of 10 seconds and randomized question order. + * + * @param exerciseGroup The exam exercise group to which the quiz should be added. + * @return The newly created exam quiz exercise. + */ public static QuizExercise generateQuizExerciseForExam(ExerciseGroup exerciseGroup) { var quizExercise = (QuizExercise) ExerciseFactory.populateExerciseForExam(new QuizExercise(), exerciseGroup); @@ -293,28 +367,30 @@ public static QuizExercise generateQuizExerciseForExam(ExerciseGroup exerciseGro quizExercise.setAllowedNumberOfAttempts(1); quizExercise.setDuration(10); quizExercise.setQuizPointStatistic(new QuizPointStatistic()); - for (var question : quizExercise.getQuizQuestions()) { - if (question instanceof DragAndDropQuestion) { - question.setQuizQuestionStatistic(new DragAndDropQuestionStatistic()); - } - else if (question instanceof MultipleChoiceQuestion) { - question.setQuizQuestionStatistic(new MultipleChoiceQuestionStatistic()); - } - else { - question.setQuizQuestionStatistic(new ShortAnswerQuestionStatistic()); - } - } quizExercise.setRandomizeQuestionOrder(true); return quizExercise; } + /** + * Generates quiz exercise for an exam with the duration of 10 seconds and randomized question order. + * + * @param exerciseGroup The exam exercise group to which the quiz exercise should be added. + * @param title The title which is used to set the quiz title together with a 3 character random UUID suffix. + * @return The newly generated quiz exercise. + */ public static QuizExercise generateQuizExerciseForExam(ExerciseGroup exerciseGroup, String title) { var quizExercise = generateQuizExerciseForExam(exerciseGroup); quizExercise.setTitle(title + UUID.randomUUID().toString().substring(0, 3)); return quizExercise; } + /** + * Initializes a quiz exercise with all different types of questions. + * After initialization, the quiz consists of one multiple choice, one drag and drop, one short answer, and single choice question. + * + * @param quizExercise The quiz to be initialized. + */ public static void initializeQuizExerciseWithAllQuestionTypes(QuizExercise quizExercise) { quizExercise.addQuestions(createMultipleChoiceQuestionWithAllTypesOfAnswerOptions()); quizExercise.addQuestions(createDragAndDropQuestionWithAllTypesOfMappings()); @@ -322,12 +398,24 @@ public static void initializeQuizExerciseWithAllQuestionTypes(QuizExercise quizE quizExercise.addQuestions(createSingleChoiceQuestion()); } + /** + * Creates a short answer question with "This [-spot0] a [-spot 2] answer text" text. + * + * @return The newly created short answer question. + */ private static ShortAnswerQuestion createShortAnswerQuestionWithRealisticText() { var shortAnswerQuestion = createShortAnswerQuestion(); shortAnswerQuestion.setText("This [-spot0] a [-spot 2] answer text"); return shortAnswerQuestion; } + /** + * Creates a drag and drop question with score 5 and 3 different location-drag item mappings. + * Fourth drag item is invalid and fifth one has a picture file. + * The scoring type of the question is proportional with penalty. + * + * @return The newly created drag and drop question. + */ public static DragAndDropQuestion createDragAndDropQuestionWithAllTypesOfMappings() { DragAndDropQuestion dnd = (DragAndDropQuestion) new DragAndDropQuestion().title("DnD").score(3).text("Q2"); dnd.setScoringType(ScoringType.PROPORTIONAL_WITH_PENALTY); @@ -401,6 +489,13 @@ public static DragAndDropQuestion createDragAndDropQuestionWithAllTypesOfMapping return dnd; } + /** + * Creates a multiple choice question with score 4 and 5 different answer options. 2 answers are correct and the other 3 incorrect. + * One answer option is invalid. + * The scoring type of the question is all or nothing. + * + * @return The newly created multiple choice question. + */ @NotNull public static MultipleChoiceQuestion createMultipleChoiceQuestionWithAllTypesOfAnswerOptions() { MultipleChoiceQuestion mc = (MultipleChoiceQuestion) new MultipleChoiceQuestion().title("MC").score(4).text("Q1"); @@ -413,6 +508,12 @@ public static MultipleChoiceQuestion createMultipleChoiceQuestionWithAllTypesOfA return mc; } + /** + * Creates a single choice question with 2 answer options. + * The scoring type of the question is all or nothing. + * + * @return The newly created single choice question. + */ @NotNull public static MultipleChoiceQuestion createSingleChoiceQuestion() { var singleChoiceQuestion = createMultipleChoiceQuestion(); @@ -421,12 +522,15 @@ public static MultipleChoiceQuestion createSingleChoiceQuestion() { } /** - * Generate submissions for a student for an exercise. Results depend on the studentID. + * Generates a submission for the given quiz exercise. The quiz should have at least 3 questions! + * A submitted answer is added to each of the first 3 questions. + * The result of each answer depends on the given student id. * - * @param quizExercise QuizExercise the submissions are for (we assume 3 questions here) - * @param studentID ID of the student - * @param submitted Boolean if it is submitted or not - * @param submissionDate Submission date + * @param quizExercise The quiz to which the submission should be added. + * @param studentID The id of the student participating in the quiz. + * @param submitted True, if the submission should be submitted. + * @param submissionDate The submission date. + * @return The newly created quiz submission. */ public static QuizSubmission generateSubmissionForThreeQuestions(QuizExercise quizExercise, int studentID, boolean submitted, ZonedDateTime submissionDate) { QuizSubmission quizSubmission = new QuizSubmission(); @@ -442,6 +546,13 @@ public static QuizSubmission generateSubmissionForThreeQuestions(QuizExercise qu return quizSubmission; } + /** + * Generates a submitted answer for the given quiz question of any type. + * The answer is only partially correct. + * + * @param question The quiz question to which a submitted answer should be added. + * @return The newly generated submitted answer. + */ public static SubmittedAnswer generateSubmittedAnswerForQuizWithCorrectAndFalseAnswers(QuizQuestion question) { if (question instanceof MultipleChoiceQuestion) { var submittedAnswer = new MultipleChoiceSubmittedAnswer(); @@ -505,12 +616,13 @@ else if (question instanceof ShortAnswerQuestion) { } /** - * Generate a submission with all or none options of a MultipleChoiceQuestion selected, if there is one in the exercise + * Generate a submission with all or none options of a multiple choice questions selected. + * For other question typed, incorrect submitted answers are added. * - * @param quizExercise Exercise the submission is for - * @param submitted Boolean whether it is submitted or not - * @param submissionDate Submission date - * @param selectEverything Boolean whether every answer option should be selected or none + * @param quizExercise The quiz to which the submission should be added. + * @param submitted True, if the submission is submitted. + * @param submissionDate The submission date. + * @param selectEverything True, if every answer option should be selected. Otherwise, none are selected. */ public static QuizSubmission generateSpecialSubmissionWithResult(QuizExercise quizExercise, boolean submitted, ZonedDateTime submissionDate, boolean selectEverything) { QuizSubmission quizSubmission = new QuizSubmission(); @@ -537,6 +649,14 @@ public static QuizSubmission generateSpecialSubmissionWithResult(QuizExercise qu return quizSubmission; } + /** + * Creates a titled quiz exercise with all types of questions for an exam. + * The quiz includes one multiple choice, one drag and drop, one short answer, and single choice question. + * + * @param exerciseGroup The exam exercise group to which the quiz exercise should be added. + * @param title The title which is used to set the quiz title together with a 3 character random UUID suffix. + * @return The newly created exam quiz exercise. + */ @NotNull public static QuizExercise createQuizWithAllQuestionTypesForExam(ExerciseGroup exerciseGroup, String title) { QuizExercise quizExercise = QuizExerciseFactory.generateQuizExerciseForExam(exerciseGroup, title); @@ -545,11 +665,11 @@ public static QuizExercise createQuizWithAllQuestionTypesForExam(ExerciseGroup e } /** - * creates a quiz submissions and adds submitted answer to it + * Creates a quiz submissions and adds a submitted answer to it. * - * @param quizQuestion the quiz question we want to add the submission to - * @param correct should the generated answer be correct or not - * @return the created quiz submission + * @param quizQuestion The quiz question to which a submission should be added. + * @param correct True if, the generated answer should be correct. + * @return The created quiz submission. */ public static QuizSubmission generateQuizSubmissionWithSubmittedAnswer(QuizQuestion quizQuestion, boolean correct) { QuizSubmission quizSubmission = ParticipationFactory.generateQuizSubmission(true); @@ -559,18 +679,18 @@ public static QuizSubmission generateQuizSubmissionWithSubmittedAnswer(QuizQuest } /** - * sets the quiz question id associated to the quiz submission answer to null + * Sets the quiz question id associated to the quiz submission answer to null. * - * @param quizSubmission quiz submission with answer + * @param quizSubmission The quiz submission with answer. */ public static void setQuizQuestionToNull(QuizSubmission quizSubmission) { quizSubmission.getSubmittedAnswers().forEach(answer -> answer.setQuizQuestion(null)); } /** - * sets the quiz question id associated to the quiz submission answer to null + * Sets the quiz question id associated to the quiz submission answer to null. * - * @param quizSubmission quiz submission with answer + * @param quizSubmission The quiz submission with answer. */ public static void setQuizQuestionsIdToNull(QuizSubmission quizSubmission) { quizSubmission.getSubmittedAnswers().forEach(answer -> answer.getQuizQuestion().setId(null)); diff --git a/src/test/java/de/tum/in/www1/artemis/exercise/quizexercise/QuizExerciseUtilService.java b/src/test/java/de/tum/in/www1/artemis/exercise/quizexercise/QuizExerciseUtilService.java index 909215386516..6d0399269333 100644 --- a/src/test/java/de/tum/in/www1/artemis/exercise/quizexercise/QuizExerciseUtilService.java +++ b/src/test/java/de/tum/in/www1/artemis/exercise/quizexercise/QuizExerciseUtilService.java @@ -88,11 +88,18 @@ public class QuizExerciseUtilService { @Autowired private QuizScheduleService quizScheduleService; + // TODO public Course addCourseWithOneQuizExercise() { return addCourseWithOneQuizExercise("Title"); } + /** + * Creates and saves a course with one quiz exercise with the given title. + * + * @param title The title of the quiz exercise. + * @return The newly created course with the quiz. + */ public Course addCourseWithOneQuizExercise(String title) { Course course = CourseFactory.generateCourse(null, pastTimestamp, futureTimestamp, new HashSet<>(), "tumuser", "tutor", "editor", "instructor"); QuizExercise quizExercise = QuizExerciseFactory.createQuiz(course, futureTimestamp, futureFutureTimestamp, QuizMode.SYNCHRONIZED); @@ -107,8 +114,16 @@ public Course addCourseWithOneQuizExercise(String title) { return course; } - public QuizSubmission saveQuizSubmission(QuizExercise exercise, QuizSubmission submission, String login) { - StudentParticipation participation = participationUtilService.createAndSaveParticipationForExercise(exercise, login); + /** + * Adds a student participation to the given quiz submission. The submission is then saved in the reposiotry. + * + * @param quizExercise The quiz to which + * @param submission + * @param login + * @return + */ + public QuizSubmission saveQuizSubmission(QuizExercise quizExercise, QuizSubmission submission, String login) { + StudentParticipation participation = participationUtilService.createAndSaveParticipationForExercise(quizExercise, login); participation.addSubmission(submission); submission.setParticipation(participation); submission = quizSubmissionRepository.save(submission); @@ -183,7 +198,7 @@ public QuizExercise createAndSaveTeamQuiz(ZonedDateTime releaseDate, ZonedDateTi } /** - * sets up a team quiz exercise. + * Sets up a team quiz exercise. * * @param quiz quiz exercise that should be a team exercise. * @param minTeamSize minimum number of members the team is allowed to have @@ -222,10 +237,10 @@ public QuizExercise createAndSaveExamQuiz(ZonedDateTime startDate, ZonedDateTime } /** - * renames the quiz with the passed title, the quiz gets saved in the repository. + * Renames and saves the quiz exercise using the passed title. * - * @param quizExercise quiz to be renamed - * @param newTitle new name of the quiz + * @param quizExercise The quiz to be renamed. + * @param newTitle The new name of the quiz. */ public void renameAndSaveQuiz(QuizExercise quizExercise, String newTitle) { quizExercise.setTitle(newTitle); @@ -233,16 +248,24 @@ public void renameAndSaveQuiz(QuizExercise quizExercise, String newTitle) { } /** - * sets the quiz exercise of quiz batch and saves the batch into the repository + * Sets the quiz exercise of the quiz batch and saves the batch into the repository. * - * @param batch quiz batch that should get saved - * @param quizExercise quiz exercise to be added to the batch + * @param batch The quiz batch that should be saved. + * @param quizExercise The quiz exercise to be added to the batch. */ public void setQuizBatchExerciseAndSave(QuizBatch batch, QuizExercise quizExercise) { batch.setQuizExercise(quizExercise); quizBatchRepository.save(batch); } + /** + * + * @param course + * @param login + * @param dueDateInTheFuture + * @return + * @throws IOException + */ public QuizSubmission addQuizExerciseToCourseWithParticipationAndSubmissionForUser(Course course, String login, boolean dueDateInTheFuture) throws IOException { QuizExercise quizExercise; if (dueDateInTheFuture) { @@ -351,12 +374,29 @@ public QuizSubmission addQuizExerciseToCourseWithParticipationAndSubmissionForUs return quizSubmission; } + /** + * Generates and saves a quiz exercise using the passed dates and adds it to the given course. + * + * @param releaseDate The release date of the quiz. + * @param dueDate The due date of the quiz. + * @param assessmentDueDate The assessment due date of the quiz. + * @param quizMode The quiz mode of the quiz. + * @param course The course to which the quiz should be added to. + * @return The newly created quiz exercise. + */ public QuizExercise createAndSaveQuizWithAllQuestionTypes(Course course, ZonedDateTime releaseDate, ZonedDateTime dueDate, ZonedDateTime assessmentDueDate, QuizMode quizMode) { QuizExercise quizExercise = QuizExerciseFactory.generateQuizExercise(releaseDate, dueDate, assessmentDueDate, quizMode, course); QuizExerciseFactory.initializeQuizExerciseWithAllQuestionTypes(quizExercise); return quizExerciseRepository.save(quizExercise); } + /** + * Joins the given quiz batch as the user with the passed username. + * + * @param quizExercise The quiz of the batch which should be joined. + * @param batch The quiz batch which should be joined. + * @param username The username of the user joining the batch. + */ public void joinQuizBatch(QuizExercise quizExercise, QuizBatch batch, String username) { var user = new User(); user.setLogin(username); From 2f0cfbc9d1bb5d5bc6fab8fc29db345e431b8aea Mon Sep 17 00:00:00 2001 From: lara Date: Wed, 18 Oct 2023 16:23:09 +0200 Subject: [PATCH 2/4] add javadoc to QuizExerciseUtilService --- .../quizexercise/QuizExerciseFactory.java | 42 ++++---- .../quizexercise/QuizExerciseUtilService.java | 99 ++++++++++--------- 2 files changed, 75 insertions(+), 66 deletions(-) diff --git a/src/test/java/de/tum/in/www1/artemis/exercise/quizexercise/QuizExerciseFactory.java b/src/test/java/de/tum/in/www1/artemis/exercise/quizexercise/QuizExerciseFactory.java index e4d5d9ed357f..8795fc4a8978 100644 --- a/src/test/java/de/tum/in/www1/artemis/exercise/quizexercise/QuizExerciseFactory.java +++ b/src/test/java/de/tum/in/www1/artemis/exercise/quizexercise/QuizExerciseFactory.java @@ -35,8 +35,8 @@ public class QuizExerciseFactory { * @param course The course the quiz should be added to. * @param releaseDate The release date of the quiz. * @param dueDate The due date of the quiz. - * @param quizMode The quiz mode used. - * @return The newly created quiz. + * @param quizMode The quiz mode used. SYNCHRONIZED, BATCHED, or INDIVIDUAL. + * @return The created quiz. */ @NotNull public static QuizExercise createQuiz(Course course, ZonedDateTime releaseDate, ZonedDateTime dueDate, QuizMode quizMode) { @@ -51,7 +51,7 @@ public static QuizExercise createQuiz(Course course, ZonedDateTime releaseDate, * The quiz consist of one multiple choice, one drag and drop, and one short answer question. * * @param exerciseGroup Exercise group of an exam to which the quiz should be added. - * @return The newly created quiz. + * @return The created quiz. */ @NotNull public static QuizExercise createQuizForExam(ExerciseGroup exerciseGroup) { @@ -79,7 +79,7 @@ public static void initializeQuizExercise(QuizExercise quizExercise) { * Creates a short answer question with score 2 and 2 different spot-solution mappings. * The scoring type of the question is proportional without penalty. * - * @return The newly created short answer question. + * @return The created short answer question. */ @NotNull public static ShortAnswerQuestion createShortAnswerQuestion() { @@ -134,7 +134,7 @@ public static ShortAnswerQuestion createShortAnswerQuestion() { * Creates a drag and drop question with score 3 and 3 different location-drag item mappings. * The scoring type of the question is proportional with penalty. * - * @return The newly created drag and drop question. + * @return The created drag and drop question. */ @NotNull public static DragAndDropQuestion createDragAndDropQuestion() { @@ -203,7 +203,7 @@ public static Long generateTempId() { * Creates a multiple choice question with score 4 and 2 different answer options. One answer is correct and the other one incorrect. * The scoring type of the question is all or nothing. * - * @return The newly created multiple choice question. + * @return The created multiple choice question. */ @NotNull public static MultipleChoiceQuestion createMultipleChoiceQuestion() { @@ -222,7 +222,7 @@ public static MultipleChoiceQuestion createMultipleChoiceQuestion() { * * @param quizExercise The quiz to which a batch should be added. * @param startTime The start time of the batch. - * @return The newly created quiz batch. + * @return The created quiz batch. */ public static QuizBatch generateQuizBatch(QuizExercise quizExercise, ZonedDateTime startTime) { var quizBatch = new QuizBatch(); @@ -236,9 +236,9 @@ public static QuizBatch generateQuizBatch(QuizExercise quizExercise, ZonedDateTi * * @param releaseDate The release date of the quiz. * @param dueDate The due date of the quiz. - * @param quizMode The quiz mode of the quiz. + * @param quizMode The quiz mode of the quiz. SYNCHRONIZED, BATCHED, or INDIVIDUAL. * @param course The course to which the quiz should be added to. - * @return The newly created quiz exercise. + * @return The created quiz exercise. */ public static QuizExercise generateQuizExercise(ZonedDateTime releaseDate, ZonedDateTime dueDate, QuizMode quizMode, Course course) { return generateQuizExercise(releaseDate, dueDate, null, quizMode, course); @@ -250,9 +250,9 @@ public static QuizExercise generateQuizExercise(ZonedDateTime releaseDate, Zoned * @param releaseDate The release date of the quiz. * @param dueDate The due date of the quiz. * @param assessmentDueDate The assessment due date of the quiz. - * @param quizMode The quiz mode of the quiz. + * @param quizMode The quiz mode of the quiz. SYNCHRONIZED, BATCHED, or INDIVIDUAL. * @param course The course to which the quiz should be added to. - * @return The newly created quiz exercise. + * @return The created quiz exercise. */ public static QuizExercise generateQuizExercise(ZonedDateTime releaseDate, ZonedDateTime dueDate, ZonedDateTime assessmentDueDate, QuizMode quizMode, Course course) { QuizExercise quizExercise = (QuizExercise) ExerciseFactory.populateExercise(new QuizExercise(), releaseDate, dueDate, assessmentDueDate, course); @@ -278,7 +278,7 @@ public static QuizExercise generateQuizExercise(ZonedDateTime releaseDate, Zoned * * @param question The quiz question to which a submitted answer should be added. * @param correct True, if the answer should be correct. - * @return The newly generated submitted answer. + * @return The generated submitted answer. */ public static SubmittedAnswer generateSubmittedAnswerFor(QuizQuestion question, boolean correct) { if (question instanceof MultipleChoiceQuestion) { @@ -355,7 +355,7 @@ else if (question instanceof ShortAnswerQuestion) { * Generates a quiz exercise for an exam with the duration of 10 seconds and randomized question order. * * @param exerciseGroup The exam exercise group to which the quiz should be added. - * @return The newly created exam quiz exercise. + * @return The created exam quiz exercise. */ public static QuizExercise generateQuizExerciseForExam(ExerciseGroup exerciseGroup) { var quizExercise = (QuizExercise) ExerciseFactory.populateExerciseForExam(new QuizExercise(), exerciseGroup); @@ -377,7 +377,7 @@ public static QuizExercise generateQuizExerciseForExam(ExerciseGroup exerciseGro * * @param exerciseGroup The exam exercise group to which the quiz exercise should be added. * @param title The title which is used to set the quiz title together with a 3 character random UUID suffix. - * @return The newly generated quiz exercise. + * @return The generated quiz exercise. */ public static QuizExercise generateQuizExerciseForExam(ExerciseGroup exerciseGroup, String title) { var quizExercise = generateQuizExerciseForExam(exerciseGroup); @@ -401,7 +401,7 @@ public static void initializeQuizExerciseWithAllQuestionTypes(QuizExercise quizE /** * Creates a short answer question with "This [-spot0] a [-spot 2] answer text" text. * - * @return The newly created short answer question. + * @return The created short answer question. */ private static ShortAnswerQuestion createShortAnswerQuestionWithRealisticText() { var shortAnswerQuestion = createShortAnswerQuestion(); @@ -414,7 +414,7 @@ private static ShortAnswerQuestion createShortAnswerQuestionWithRealisticText() * Fourth drag item is invalid and fifth one has a picture file. * The scoring type of the question is proportional with penalty. * - * @return The newly created drag and drop question. + * @return The created drag and drop question. */ public static DragAndDropQuestion createDragAndDropQuestionWithAllTypesOfMappings() { DragAndDropQuestion dnd = (DragAndDropQuestion) new DragAndDropQuestion().title("DnD").score(3).text("Q2"); @@ -494,7 +494,7 @@ public static DragAndDropQuestion createDragAndDropQuestionWithAllTypesOfMapping * One answer option is invalid. * The scoring type of the question is all or nothing. * - * @return The newly created multiple choice question. + * @return The created multiple choice question. */ @NotNull public static MultipleChoiceQuestion createMultipleChoiceQuestionWithAllTypesOfAnswerOptions() { @@ -512,7 +512,7 @@ public static MultipleChoiceQuestion createMultipleChoiceQuestionWithAllTypesOfA * Creates a single choice question with 2 answer options. * The scoring type of the question is all or nothing. * - * @return The newly created single choice question. + * @return The created single choice question. */ @NotNull public static MultipleChoiceQuestion createSingleChoiceQuestion() { @@ -530,7 +530,7 @@ public static MultipleChoiceQuestion createSingleChoiceQuestion() { * @param studentID The id of the student participating in the quiz. * @param submitted True, if the submission should be submitted. * @param submissionDate The submission date. - * @return The newly created quiz submission. + * @return The created quiz submission. */ public static QuizSubmission generateSubmissionForThreeQuestions(QuizExercise quizExercise, int studentID, boolean submitted, ZonedDateTime submissionDate) { QuizSubmission quizSubmission = new QuizSubmission(); @@ -551,7 +551,7 @@ public static QuizSubmission generateSubmissionForThreeQuestions(QuizExercise qu * The answer is only partially correct. * * @param question The quiz question to which a submitted answer should be added. - * @return The newly generated submitted answer. + * @return The generated submitted answer. */ public static SubmittedAnswer generateSubmittedAnswerForQuizWithCorrectAndFalseAnswers(QuizQuestion question) { if (question instanceof MultipleChoiceQuestion) { @@ -655,7 +655,7 @@ public static QuizSubmission generateSpecialSubmissionWithResult(QuizExercise qu * * @param exerciseGroup The exam exercise group to which the quiz exercise should be added. * @param title The title which is used to set the quiz title together with a 3 character random UUID suffix. - * @return The newly created exam quiz exercise. + * @return The created exam quiz exercise. */ @NotNull public static QuizExercise createQuizWithAllQuestionTypesForExam(ExerciseGroup exerciseGroup, String title) { diff --git a/src/test/java/de/tum/in/www1/artemis/exercise/quizexercise/QuizExerciseUtilService.java b/src/test/java/de/tum/in/www1/artemis/exercise/quizexercise/QuizExerciseUtilService.java index 80a9b9dcaba9..3dccf0dca22b 100644 --- a/src/test/java/de/tum/in/www1/artemis/exercise/quizexercise/QuizExerciseUtilService.java +++ b/src/test/java/de/tum/in/www1/artemis/exercise/quizexercise/QuizExerciseUtilService.java @@ -88,14 +88,20 @@ public class QuizExerciseUtilService { @Autowired private QuizScheduleService quizScheduleService; - // TODO + /** + * Creates and saves a course with one quiz exercise with the title "Title". + * The quiz is synchronized and has a duration of 120 seconds. + * + * @return The created course with the quiz. + */ public Course addCourseWithOneQuizExercise() { return addCourseWithOneQuizExercise("Title"); } /** * Creates and saves a course with one quiz exercise with the given title. + * The quiz is synchronized and has a duration of 120 seconds. * * @param title The title of the quiz exercise. * @return The newly created course with the quiz. @@ -115,41 +121,40 @@ public Course addCourseWithOneQuizExercise(String title) { } /** - * Adds a student participation to the given quiz submission. The submission is then saved in the reposiotry. + * Creates and adds a student participation to the given quiz submission. The submission is then saved in the repository. * - * @param quizExercise The quiz to which - * @param submission - * @param login - * @return + * @param quizExercise The quiz for which a student participation should be created. + * @param submission The submission which should be saved + * @param login The login of the user participating in the quiz. + * @return The saved submission. */ public QuizSubmission saveQuizSubmission(QuizExercise quizExercise, QuizSubmission submission, String login) { StudentParticipation participation = participationUtilService.createAndSaveParticipationForExercise(quizExercise, login); participation.addSubmission(submission); submission.setParticipation(participation); - submission = quizSubmissionRepository.save(submission); - return submission; + return quizSubmissionRepository.save(submission); } /** - * important quiz fields are emptied, so it can be imported, + * Sets quiz exercise dates and course to null so quiz can be imported. The quiz batches are set to an empty set. * - * @param quizExercise to be emptied + * @param quizExercise The quiz of which fields should be set to null. */ public void emptyOutQuizExercise(QuizExercise quizExercise) { quizExercise.setReleaseDate(null); - quizExercise.setCourse(null); quizExercise.setDueDate(null); quizExercise.setAssessmentDueDate(null); + quizExercise.setCourse(null); quizExercise.setQuizBatches(new HashSet<>()); } /** - * Creates a new quiz that gets saved in the QuizExercise repository. + * Creates and saves a new quiz exercise. * - * @param releaseDate release date of the quiz, is also used to set the start date of the course - * @param dueDate due date of the quiz, is also used to set the end date of the course - * @param quizMode SYNCHRONIZED, BATCHED or INDIVIDUAL - * @return quiz that was created + * @param releaseDate The release date of the quiz, also used to set the start date of the course. + * @param dueDate The due date of the quiz, also used to set the end date of the course. + * @param quizMode The mode of the quiz. SYNCHRONIZED, BATCHED or INDIVIDUAL. + * @return The created quiz exercise. */ public QuizExercise createAndSaveQuiz(ZonedDateTime releaseDate, ZonedDateTime dueDate, QuizMode quizMode) { QuizExercise quizExercise = createQuiz(releaseDate, dueDate, quizMode); @@ -159,12 +164,12 @@ public QuizExercise createAndSaveQuiz(ZonedDateTime releaseDate, ZonedDateTime d } /** - * Creates a new quiz + * Creates and saves a course. A new quiz exercise is created and added to the course. * - * @param releaseDate release date of the quiz, is also used to set the start date of the course - * @param dueDate due date of the quiz, is also used to set the end date of the course - * @param quizMode SYNCHRONIZED, BATCHED or INDIVIDUAL - * @return quiz that was created + * @param releaseDate The release date of the quiz, also used to set the start date of the course. + * @param dueDate The due date of the quiz, also used to set the end date of the course. + * @param quizMode The mode of the quiz. SYNCHRONIZED, BATCHED, or INDIVIDUAL. + * @return The created quiz exercise. */ public QuizExercise createQuiz(ZonedDateTime releaseDate, ZonedDateTime dueDate, QuizMode quizMode) { Course course = courseUtilService.createAndSaveCourse(null, releaseDate == null ? null : releaseDate.minusDays(1), dueDate == null ? null : dueDate.plusDays(1), Set.of()); @@ -176,14 +181,14 @@ public QuizExercise createQuiz(ZonedDateTime releaseDate, ZonedDateTime dueDate, } /** - * Creates a team quiz exercise with a team and saves it into the repository. + * Creates and saves a team quiz exercise. * - * @param releaseDate release date of the quiz - * @param dueDate due date of the quiz - * @param quizMode SYNCHRONIZED, BATCHED or INDIVIDUAL - * @param minTeamSize minimum number of members the team is allowed to have - * @param maxTeamSize maximum number of members the team is allowed to have - * @return exercise created + * @param releaseDate The release date of the quiz. + * @param dueDate The due date of the quiz. + * @param quizMode The mode of the quiz. SYNCHRONIZED, BATCHED or INDIVIDUAL + * @param minTeamSize The minimum number of members the team is allowed to have. + * @param maxTeamSize The maximum number of members the team is allowed to have. + * @return The created quiz exercise. */ public QuizExercise createAndSaveTeamQuiz(ZonedDateTime releaseDate, ZonedDateTime dueDate, QuizMode quizMode, int minTeamSize, int maxTeamSize) { QuizExercise quizExercise = createQuiz(releaseDate, dueDate, quizMode); @@ -198,11 +203,11 @@ public QuizExercise createAndSaveTeamQuiz(ZonedDateTime releaseDate, ZonedDateTi } /** - * Sets up a team quiz exercise. + * Sets up a team quiz exercise by creating the team assignment config with the passed values and setting it to the quiz. * - * @param quiz quiz exercise that should be a team exercise. - * @param minTeamSize minimum number of members the team is allowed to have - * @param maxTeamSize maximum number of members the team is allowed to have + * @param quiz The quiz which should be a team exercise. + * @param minTeamSize The minimum number of members the team is allowed to have. + * @param maxTeamSize The maximum number of members the team is allowed to have. */ public void setupTeamQuizExercise(QuizExercise quiz, int minTeamSize, int maxTeamSize) { var teamAssignmentConfig = new TeamAssignmentConfig(); @@ -214,11 +219,11 @@ public void setupTeamQuizExercise(QuizExercise quiz, int minTeamSize, int maxTea } /** - * Creates a new exam quiz that gets saved in the QuizExercise repository. + * Creates and saves a course and exam with a new exam quiz which also gets saved, * - * @param startDate start date of the exam, is also used to set the end date of the course the exam is in - * @param endDate end date of the exam, is also used to set the end date of the course the exam is in - * @return exam quiz that was created + * @param startDate The start date of the exam, also used to set the start date of the course the exam is in. + * @param endDate The end date of the exam, also used to set the end date of the course the exam is in. + * @return The created exam quiz exercise. */ @NotNull public QuizExercise createAndSaveExamQuiz(ZonedDateTime startDate, ZonedDateTime endDate) { @@ -259,12 +264,16 @@ public void setQuizBatchExerciseAndSave(QuizBatch batch, QuizExercise quizExerci } /** + * Creates and saves a quiz with a multiple, single choice, short, and drag and drop question. + * An actual file is used as the background and a data item of the drag and drop question. + * The quiz takes 120 seconds and is synchronized. + * A participation and submission are also created for the user with the given login. An answer is submitted for each question. * - * @param course - * @param login - * @param dueDateInTheFuture - * @return - * @throws IOException + * @param course The course of the quiz. + * @param login The login of the user participating in the quiz. + * @param dueDateInTheFuture True, if the due date of the quiz is in the future. + * @return The created quiz submission. + * @throws IOException If the background or data item file cannot be accessed. */ public QuizSubmission addQuizExerciseToCourseWithParticipationAndSubmissionForUser(Course course, String login, boolean dueDateInTheFuture) throws IOException { QuizExercise quizExercise; @@ -276,8 +285,7 @@ public QuizSubmission addQuizExerciseToCourseWithParticipationAndSubmissionForUs } quizExercise.setTitle("quiz"); quizExercise.setDuration(120); - assertThat(quizExercise.getQuizQuestions()).isNotEmpty(); - assertThat(quizExercise.isValid()).isTrue(); + course.addExercises(quizExercise); StudentParticipation studentParticipation = new StudentParticipation(); studentParticipation.setExercise(quizExercise); @@ -375,7 +383,8 @@ public QuizSubmission addQuizExerciseToCourseWithParticipationAndSubmissionForUs } /** - * Generates and saves a quiz exercise using the passed dates and adds it to the given course. + * Creates and saves a quiz exercise with all question types using the passed dates and adds it to the given course. + * After initialization, the quiz consists of one multiple choice, one drag and drop, one short answer, and single choice question. * * @param releaseDate The release date of the quiz. * @param dueDate The due date of the quiz. @@ -391,7 +400,7 @@ public QuizExercise createAndSaveQuizWithAllQuestionTypes(Course course, ZonedDa } /** - * Joins the given quiz batch as the user with the passed username. + * Joins the given quiz batch as the user with the given username. * * @param quizExercise The quiz of the batch which should be joined. * @param batch The quiz batch which should be joined. From 041de15f28bfc339934cc51a382353fd2116fad2 Mon Sep 17 00:00:00 2001 From: lara Date: Wed, 18 Oct 2023 17:29:17 +0200 Subject: [PATCH 3/4] small improvements --- .../artemis/exam/QuizPoolIntegrationTest.java | 45 +++++------ .../quizexercise/QuizExerciseFactory.java | 81 +++++++++++++++++-- .../quizexercise/QuizExerciseUtilService.java | 41 +--------- 3 files changed, 96 insertions(+), 71 deletions(-) diff --git a/src/test/java/de/tum/in/www1/artemis/exam/QuizPoolIntegrationTest.java b/src/test/java/de/tum/in/www1/artemis/exam/QuizPoolIntegrationTest.java index 9616695f0892..77cfc534b8f8 100644 --- a/src/test/java/de/tum/in/www1/artemis/exam/QuizPoolIntegrationTest.java +++ b/src/test/java/de/tum/in/www1/artemis/exam/QuizPoolIntegrationTest.java @@ -17,14 +17,8 @@ import de.tum.in.www1.artemis.domain.Course; import de.tum.in.www1.artemis.domain.User; import de.tum.in.www1.artemis.domain.exam.Exam; -import de.tum.in.www1.artemis.domain.quiz.DragAndDropQuestion; -import de.tum.in.www1.artemis.domain.quiz.MultipleChoiceQuestion; -import de.tum.in.www1.artemis.domain.quiz.QuizGroup; -import de.tum.in.www1.artemis.domain.quiz.QuizPool; -import de.tum.in.www1.artemis.domain.quiz.QuizQuestion; -import de.tum.in.www1.artemis.domain.quiz.ShortAnswerQuestion; +import de.tum.in.www1.artemis.domain.quiz.*; import de.tum.in.www1.artemis.exercise.quizexercise.QuizExerciseFactory; -import de.tum.in.www1.artemis.exercise.quizexercise.QuizExerciseUtilService; import de.tum.in.www1.artemis.service.QuizPoolService; import de.tum.in.www1.artemis.user.UserUtilService; import de.tum.in.www1.artemis.util.RequestUtilService; @@ -42,9 +36,6 @@ class QuizPoolIntegrationTest extends AbstractSpringIntegrationBambooBitbucketJi @Autowired private ExamUtilService examUtilService; - @Autowired - private QuizExerciseUtilService quizExerciseUtilService; - @Autowired private UserUtilService userUtilService; @@ -91,10 +82,10 @@ void testCreateQuizPoolSuccessful() throws Exception { void testUpdateQuizPoolSuccessful() throws Exception { QuizPool quizPool = createQuizPool(); - QuizGroup quizGroup3 = quizExerciseUtilService.createQuizGroup("Exception Handling"); - QuizQuestion saQuizQuestion1 = quizExerciseUtilService.createShortAnswerQuestionWithTitleAndGroup("SA 1", quizGroup2); - QuizQuestion saQuizQuestion2 = quizExerciseUtilService.createShortAnswerQuestionWithTitleAndGroup("SA 2", quizGroup3); - QuizQuestion saQuizQuestion3 = quizExerciseUtilService.createShortAnswerQuestionWithTitleAndGroup("SA 3", null); + QuizGroup quizGroup3 = QuizExerciseFactory.createQuizGroup("Exception Handling"); + QuizQuestion saQuizQuestion1 = QuizExerciseFactory.createShortAnswerQuestionWithTitleAndGroup("SA 1", quizGroup2); + QuizQuestion saQuizQuestion2 = QuizExerciseFactory.createShortAnswerQuestionWithTitleAndGroup("SA 2", quizGroup3); + QuizQuestion saQuizQuestion3 = QuizExerciseFactory.createShortAnswerQuestionWithTitleAndGroup("SA 3", null); quizPool.setQuizGroups(List.of(quizPool.getQuizGroups().get(0), quizPool.getQuizGroups().get(2), quizGroup3)); quizPool.setQuizQuestions(List.of(quizPool.getQuizQuestions().get(0), quizPool.getQuizQuestions().get(1), quizPool.getQuizQuestions().get(2), saQuizQuestion1, saQuizQuestion2, saQuizQuestion3)); @@ -165,11 +156,11 @@ void testUpdateQuizPoolNotFoundExam() throws Exception { @Test @WithMockUser(username = TEST_PREFIX + "instructor1", roles = "INSTRUCTOR") void testGetQuizPoolSuccessful() throws Exception { - QuizGroup quizGroup0 = quizExerciseUtilService.createQuizGroup("Encapsulation"); - QuizGroup quizGroup1 = quizExerciseUtilService.createQuizGroup("Inheritance"); - QuizQuestion mcQuizQuestion = quizExerciseUtilService.createMultipleChoiceQuestionWithTitleAndGroup("MC", quizGroup0); - QuizQuestion dndQuizQuestion = quizExerciseUtilService.createDragAndDropQuestionWithTitleAndGroup("DND", quizGroup1); - QuizQuestion saQuizQuestion = quizExerciseUtilService.createShortAnswerQuestionWithTitleAndGroup("SA", null); + QuizGroup quizGroup0 = QuizExerciseFactory.createQuizGroup("Encapsulation"); + QuizGroup quizGroup1 = QuizExerciseFactory.createQuizGroup("Inheritance"); + QuizQuestion mcQuizQuestion = QuizExerciseFactory.createMultipleChoiceQuestionWithTitleAndGroup("MC", quizGroup0); + QuizQuestion dndQuizQuestion = QuizExerciseFactory.createDragAndDropQuestionWithTitleAndGroup("DND", quizGroup1); + QuizQuestion saQuizQuestion = QuizExerciseFactory.createShortAnswerQuestionWithTitleAndGroup("SA", null); quizPool.setQuizGroups(List.of(quizGroup0, quizGroup1)); quizPool.setQuizQuestions(List.of(mcQuizQuestion, dndQuizQuestion, saQuizQuestion)); QuizPool savedQuizPool = quizPoolService.update(exam.getId(), quizPool); @@ -190,14 +181,14 @@ void testGetQuizPoolNotFoundExam() throws Exception { } private QuizPool createQuizPool() throws Exception { - quizGroup0 = quizExerciseUtilService.createQuizGroup("Encapsulation"); - quizGroup1 = quizExerciseUtilService.createQuizGroup("Inheritance"); - quizGroup2 = quizExerciseUtilService.createQuizGroup("Polymorphism"); - QuizQuestion mcQuizQuestion0 = quizExerciseUtilService.createMultipleChoiceQuestionWithTitleAndGroup("MC 0", quizGroup0); - QuizQuestion mcQuizQuestion1 = quizExerciseUtilService.createMultipleChoiceQuestionWithTitleAndGroup("MC 1", quizGroup0); - QuizQuestion dndQuizQuestion0 = quizExerciseUtilService.createDragAndDropQuestionWithTitleAndGroup("DND 0", quizGroup1); - QuizQuestion dndQuizQuestion1 = quizExerciseUtilService.createDragAndDropQuestionWithTitleAndGroup("DND 1", quizGroup2); - QuizQuestion saQuizQuestion0 = quizExerciseUtilService.createShortAnswerQuestionWithTitleAndGroup("SA 0", null); + quizGroup0 = QuizExerciseFactory.createQuizGroup("Encapsulation"); + quizGroup1 = QuizExerciseFactory.createQuizGroup("Inheritance"); + quizGroup2 = QuizExerciseFactory.createQuizGroup("Polymorphism"); + QuizQuestion mcQuizQuestion0 = QuizExerciseFactory.createMultipleChoiceQuestionWithTitleAndGroup("MC 0", quizGroup0); + QuizQuestion mcQuizQuestion1 = QuizExerciseFactory.createMultipleChoiceQuestionWithTitleAndGroup("MC 1", quizGroup0); + QuizQuestion dndQuizQuestion0 = QuizExerciseFactory.createDragAndDropQuestionWithTitleAndGroup("DND 0", quizGroup1); + QuizQuestion dndQuizQuestion1 = QuizExerciseFactory.createDragAndDropQuestionWithTitleAndGroup("DND 1", quizGroup2); + QuizQuestion saQuizQuestion0 = QuizExerciseFactory.createShortAnswerQuestionWithTitleAndGroup("SA 0", null); quizPool.setQuizGroups(List.of(quizGroup0, quizGroup1, quizGroup2)); quizPool.setQuizQuestions(List.of(mcQuizQuestion0, mcQuizQuestion1, dndQuizQuestion0, dndQuizQuestion1, saQuizQuestion0)); diff --git a/src/test/java/de/tum/in/www1/artemis/exercise/quizexercise/QuizExerciseFactory.java b/src/test/java/de/tum/in/www1/artemis/exercise/quizexercise/QuizExerciseFactory.java index 8795fc4a8978..c3b369bd640b 100644 --- a/src/test/java/de/tum/in/www1/artemis/exercise/quizexercise/QuizExerciseFactory.java +++ b/src/test/java/de/tum/in/www1/artemis/exercise/quizexercise/QuizExerciseFactory.java @@ -29,7 +29,7 @@ public class QuizExerciseFactory { /** - * Creates a quiz exercise with given dates and adds it to the course. + * Creates a quiz exercise with the given dates and adds it to the course. * The quiz consist of one multiple choice, one drag and drop, and one short answer question. * * @param course The course the quiz should be added to. @@ -47,7 +47,7 @@ public static QuizExercise createQuiz(Course course, ZonedDateTime releaseDate, } /** - * Creates a quiz exercise for an exam with given dates and adds it to the course. + * Creates a quiz exercise for an exam with the given dates and adds it to the course. * The quiz consist of one multiple choice, one drag and drop, and one short answer question. * * @param exerciseGroup Exercise group of an exam to which the quiz should be added. @@ -191,7 +191,7 @@ public static DragAndDropQuestion createDragAndDropQuestion() { } /** - * Generates a temporary id using ThreadLocalRandom for a quiz exercise. + * Generates a temporary id for a quiz exercise using ThreadLocalRandom. * * @return The generated temporary id. */ @@ -218,7 +218,7 @@ public static MultipleChoiceQuestion createMultipleChoiceQuestion() { } /** - * Generates a quiz batch for the given quiz using the given start time. + * Generates a quiz batch for a quiz exercise using the given start time. * * @param quizExercise The quiz to which a batch should be added. * @param startTime The start time of the batch. @@ -621,7 +621,7 @@ else if (question instanceof ShortAnswerQuestion) { * * @param quizExercise The quiz to which the submission should be added. * @param submitted True, if the submission is submitted. - * @param submissionDate The submission date. + * @param submissionDate The date the submission is submitted. * @param selectEverything True, if every answer option should be selected. Otherwise, none are selected. */ public static QuizSubmission generateSpecialSubmissionWithResult(QuizExercise quizExercise, boolean submitted, ZonedDateTime submissionDate, boolean selectEverything) { @@ -679,7 +679,7 @@ public static QuizSubmission generateQuizSubmissionWithSubmittedAnswer(QuizQuest } /** - * Sets the quiz question id associated to the quiz submission answer to null. + * Sets quiz questions associated to quiz submission answers to null. * * @param quizSubmission The quiz submission with answer. */ @@ -688,11 +688,78 @@ public static void setQuizQuestionToNull(QuizSubmission quizSubmission) { } /** - * Sets the quiz question id associated to the quiz submission answer to null. + * Sets quiz question ids associated to quiz submission answers to null. * * @param quizSubmission The quiz submission with answer. */ public static void setQuizQuestionsIdToNull(QuizSubmission quizSubmission) { quizSubmission.getSubmittedAnswers().forEach(answer -> answer.getQuizQuestion().setId(null)); } + + /** + * Creates a quiz group with the given name. + * + * @param name The name of the quiz group. + * @return The created quiz group. + */ + @NotNull + public static QuizGroup createQuizGroup(String name) { + QuizGroup quizGroup = new QuizGroup(); + quizGroup.setName(name); + return quizGroup; + } + + /** + * Creates a multiple choice question with the given title and quiz group. + * + * @param title The title of the quiz question. + * @param quizGroup The group of the quiz question. + * @return The created multiple choice question. + */ + @NotNull + public static MultipleChoiceQuestion createMultipleChoiceQuestionWithTitleAndGroup(String title, QuizGroup quizGroup) { + MultipleChoiceQuestion quizQuestion = QuizExerciseFactory.createMultipleChoiceQuestion(); + setQuizQuestionsTitleAndGroup(quizQuestion, title, quizGroup); + return quizQuestion; + } + + /** + * Creates a drag and drop question with the given title and quiz group. + * + * @param title The title of the quiz question. + * @param quizGroup The group of the quiz question. + * @return The created drag and drop question. + */ + @NotNull + public static DragAndDropQuestion createDragAndDropQuestionWithTitleAndGroup(String title, QuizGroup quizGroup) { + DragAndDropQuestion quizQuestion = QuizExerciseFactory.createDragAndDropQuestion(); + setQuizQuestionsTitleAndGroup(quizQuestion, title, quizGroup); + return quizQuestion; + } + + /** + * Creates a short answer question with the given title and quiz group. + * + * @param title The title of the quiz question. + * @param quizGroup The group of the quiz question. + * @return The created short answer question. + */ + @NotNull + public static ShortAnswerQuestion createShortAnswerQuestionWithTitleAndGroup(String title, QuizGroup quizGroup) { + ShortAnswerQuestion quizQuestion = QuizExerciseFactory.createShortAnswerQuestion(); + setQuizQuestionsTitleAndGroup(quizQuestion, title, quizGroup); + return quizQuestion; + } + + /** + * Sets the title and group of the quiz question. + * + * @param quizQuestion The quiz question to be updated. + * @param title The new title of the quiz question. + * @param quizGroup The new group of the quiz question. + */ + private static void setQuizQuestionsTitleAndGroup(QuizQuestion quizQuestion, String title, QuizGroup quizGroup) { + quizQuestion.setTitle(title); + quizQuestion.setQuizGroup(quizGroup); + } } diff --git a/src/test/java/de/tum/in/www1/artemis/exercise/quizexercise/QuizExerciseUtilService.java b/src/test/java/de/tum/in/www1/artemis/exercise/quizexercise/QuizExerciseUtilService.java index 3dccf0dca22b..efcf027c38e8 100644 --- a/src/test/java/de/tum/in/www1/artemis/exercise/quizexercise/QuizExerciseUtilService.java +++ b/src/test/java/de/tum/in/www1/artemis/exercise/quizexercise/QuizExerciseUtilService.java @@ -136,7 +136,7 @@ public QuizSubmission saveQuizSubmission(QuizExercise quizExercise, QuizSubmissi } /** - * Sets quiz exercise dates and course to null so quiz can be imported. The quiz batches are set to an empty set. + * Sets quiz exercise dates and course to null so the quiz can be imported. The quiz batches are set to an empty set. * * @param quizExercise The quiz of which fields should be set to null. */ @@ -219,7 +219,7 @@ public void setupTeamQuizExercise(QuizExercise quiz, int minTeamSize, int maxTea } /** - * Creates and saves a course and exam with a new exam quiz which also gets saved, + * Creates and saves a course and an exam. An exam quiz exercise is created and saved. * * @param startDate The start date of the exam, also used to set the start date of the course the exam is in. * @param endDate The end date of the exam, also used to set the end date of the course the exam is in. @@ -255,7 +255,7 @@ public void renameAndSaveQuiz(QuizExercise quizExercise, String newTitle) { /** * Sets the quiz exercise of the quiz batch and saves the batch into the repository. * - * @param batch The quiz batch that should be saved. + * @param batch The quiz batch which should be saved. * @param quizExercise The quiz exercise to be added to the batch. */ public void setQuizBatchExerciseAndSave(QuizBatch batch, QuizExercise quizExercise) { @@ -265,7 +265,7 @@ public void setQuizBatchExerciseAndSave(QuizBatch batch, QuizExercise quizExerci /** * Creates and saves a quiz with a multiple, single choice, short, and drag and drop question. - * An actual file is used as the background and a data item of the drag and drop question. + * An actual picture file is used as the background and a data item of the drag and drop question. * The quiz takes 120 seconds and is synchronized. * A participation and submission are also created for the user with the given login. An answer is submitted for each question. * @@ -411,37 +411,4 @@ public void joinQuizBatch(QuizExercise quizExercise, QuizBatch batch, String use user.setLogin(username); quizScheduleService.joinQuizBatch(quizExercise, batch, user); } - - @NotNull - public QuizGroup createQuizGroup(String name) { - QuizGroup quizGroup = new QuizGroup(); - quizGroup.setName(name); - return quizGroup; - } - - @NotNull - public MultipleChoiceQuestion createMultipleChoiceQuestionWithTitleAndGroup(String title, QuizGroup quizGroup) { - MultipleChoiceQuestion quizQuestion = QuizExerciseFactory.createMultipleChoiceQuestion(); - setQuizQuestionsTitleAndGroup(quizQuestion, title, quizGroup); - return quizQuestion; - } - - @NotNull - public DragAndDropQuestion createDragAndDropQuestionWithTitleAndGroup(String title, QuizGroup quizGroup) { - DragAndDropQuestion quizQuestion = QuizExerciseFactory.createDragAndDropQuestion(); - setQuizQuestionsTitleAndGroup(quizQuestion, title, quizGroup); - return quizQuestion; - } - - @NotNull - public ShortAnswerQuestion createShortAnswerQuestionWithTitleAndGroup(String title, QuizGroup quizGroup) { - ShortAnswerQuestion quizQuestion = QuizExerciseFactory.createShortAnswerQuestion(); - setQuizQuestionsTitleAndGroup(quizQuestion, title, quizGroup); - return quizQuestion; - } - - private void setQuizQuestionsTitleAndGroup(Q quizQuestion, String title, QuizGroup quizGroup) { - quizQuestion.setTitle(title); - quizQuestion.setQuizGroup(quizGroup); - } } From 71f53c060f44d3a0bc48a6c99d028bffab9b16a1 Mon Sep 17 00:00:00 2001 From: lara Date: Wed, 25 Oct 2023 19:35:03 +0200 Subject: [PATCH 4/4] implement Dominik's suggestions 2 --- .../quizexercise/QuizExerciseFactory.java | 24 ++++++++++--------- .../quizexercise/QuizExerciseUtilService.java | 6 ++--- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/test/java/de/tum/in/www1/artemis/exercise/quizexercise/QuizExerciseFactory.java b/src/test/java/de/tum/in/www1/artemis/exercise/quizexercise/QuizExerciseFactory.java index c3b369bd640b..d4f44c8e53bc 100644 --- a/src/test/java/de/tum/in/www1/artemis/exercise/quizexercise/QuizExerciseFactory.java +++ b/src/test/java/de/tum/in/www1/artemis/exercise/quizexercise/QuizExerciseFactory.java @@ -41,7 +41,7 @@ public class QuizExerciseFactory { @NotNull public static QuizExercise createQuiz(Course course, ZonedDateTime releaseDate, ZonedDateTime dueDate, QuizMode quizMode) { QuizExercise quizExercise = generateQuizExercise(releaseDate, dueDate, quizMode, course); - initializeQuizExercise(quizExercise); + addQuestionsToQuizExercise(quizExercise); return quizExercise; } @@ -56,18 +56,19 @@ public static QuizExercise createQuiz(Course course, ZonedDateTime releaseDate, @NotNull public static QuizExercise createQuizForExam(ExerciseGroup exerciseGroup) { QuizExercise quizExercise = generateQuizExerciseForExam(exerciseGroup); - initializeQuizExercise(quizExercise); + addQuestionsToQuizExercise(quizExercise); return quizExercise; } /** - * Initializes a quiz exercise with different types of questions. - * After initialization, the quiz consists of one multiple choice, one drag and drop, and one short answer question. + * Adds different types of questions to the given quiz. + * One multiple choice, one drag and drop, and one short answer question is added to the quiz. + * The grading instructions are set to null. * - * @param quizExercise The quiz to be initialized. + * @param quizExercise The quiz to which questions should be added. */ - public static void initializeQuizExercise(QuizExercise quizExercise) { + public static void addQuestionsToQuizExercise(QuizExercise quizExercise) { quizExercise.addQuestions(createMultipleChoiceQuestion()); quizExercise.addQuestions(createDragAndDropQuestion()); quizExercise.addQuestions(createShortAnswerQuestion()); @@ -386,12 +387,13 @@ public static QuizExercise generateQuizExerciseForExam(ExerciseGroup exerciseGro } /** - * Initializes a quiz exercise with all different types of questions. - * After initialization, the quiz consists of one multiple choice, one drag and drop, one short answer, and single choice question. + * Adds different types of questions to the given quiz. + * One multiple choice, one drag and drop, one short answer, and one single choice question is added to the quiz. + * The grading instructions are set to null. * - * @param quizExercise The quiz to be initialized. + * @param quizExercise The quiz to which questions should be added. */ - public static void initializeQuizExerciseWithAllQuestionTypes(QuizExercise quizExercise) { + public static void addAllQuestionTypesToQuizExercise(QuizExercise quizExercise) { quizExercise.addQuestions(createMultipleChoiceQuestionWithAllTypesOfAnswerOptions()); quizExercise.addQuestions(createDragAndDropQuestionWithAllTypesOfMappings()); quizExercise.addQuestions(createShortAnswerQuestionWithRealisticText()); @@ -660,7 +662,7 @@ public static QuizSubmission generateSpecialSubmissionWithResult(QuizExercise qu @NotNull public static QuizExercise createQuizWithAllQuestionTypesForExam(ExerciseGroup exerciseGroup, String title) { QuizExercise quizExercise = QuizExerciseFactory.generateQuizExerciseForExam(exerciseGroup, title); - initializeQuizExerciseWithAllQuestionTypes(quizExercise); + addAllQuestionTypesToQuizExercise(quizExercise); return quizExercise; } diff --git a/src/test/java/de/tum/in/www1/artemis/exercise/quizexercise/QuizExerciseUtilService.java b/src/test/java/de/tum/in/www1/artemis/exercise/quizexercise/QuizExerciseUtilService.java index efcf027c38e8..ba378033e3ed 100644 --- a/src/test/java/de/tum/in/www1/artemis/exercise/quizexercise/QuizExerciseUtilService.java +++ b/src/test/java/de/tum/in/www1/artemis/exercise/quizexercise/QuizExerciseUtilService.java @@ -175,7 +175,7 @@ public QuizExercise createQuiz(ZonedDateTime releaseDate, ZonedDateTime dueDate, Course course = courseUtilService.createAndSaveCourse(null, releaseDate == null ? null : releaseDate.minusDays(1), dueDate == null ? null : dueDate.plusDays(1), Set.of()); QuizExercise quizExercise = QuizExerciseFactory.generateQuizExercise(releaseDate, dueDate, quizMode, course); - QuizExerciseFactory.initializeQuizExercise(quizExercise); + QuizExerciseFactory.addQuestionsToQuizExercise(quizExercise); return quizExercise; } @@ -234,7 +234,7 @@ public QuizExercise createAndSaveExamQuiz(ZonedDateTime startDate, ZonedDateTime examRepository.save(exam); QuizExercise quizExercise = QuizExerciseFactory.generateQuizExerciseForExam(exerciseGroup); - QuizExerciseFactory.initializeQuizExercise(quizExercise); + QuizExerciseFactory.addQuestionsToQuizExercise(quizExercise); quizExerciseRepository.save(quizExercise); @@ -395,7 +395,7 @@ public QuizSubmission addQuizExerciseToCourseWithParticipationAndSubmissionForUs */ public QuizExercise createAndSaveQuizWithAllQuestionTypes(Course course, ZonedDateTime releaseDate, ZonedDateTime dueDate, ZonedDateTime assessmentDueDate, QuizMode quizMode) { QuizExercise quizExercise = QuizExerciseFactory.generateQuizExercise(releaseDate, dueDate, assessmentDueDate, quizMode, course); - QuizExerciseFactory.initializeQuizExerciseWithAllQuestionTypes(quizExercise); + QuizExerciseFactory.addAllQuestionTypesToQuizExercise(quizExercise); return quizExerciseRepository.save(quizExercise); }