diff --git a/src/test/java/de/tum/in/www1/artemis/lecture/LectureFactory.java b/src/test/java/de/tum/in/www1/artemis/lecture/LectureFactory.java index b61e4a6e5c6d..53d5a635f715 100644 --- a/src/test/java/de/tum/in/www1/artemis/lecture/LectureFactory.java +++ b/src/test/java/de/tum/in/www1/artemis/lecture/LectureFactory.java @@ -23,6 +23,14 @@ */ public class LectureFactory { + /** + * Generates a Lecture for the given Course. + * + * @param startDate The start date of the Lecture + * @param endDate The end date of the Lecture + * @param course The Course the Lecture belongs to + * @return The generated Lecture + */ public static Lecture generateLecture(ZonedDateTime startDate, ZonedDateTime endDate, Course course) { Lecture lecture = new Lecture(); lecture.setVisibleDate(startDate); @@ -35,14 +43,14 @@ public static Lecture generateLecture(ZonedDateTime startDate, ZonedDateTime end } /** - * Create a dummy attachment unit for testing. Includes a dummy attachment with optional placeholder image file on disk + * Generates an AttachmentUnit with an Attachment. The Attachment can be created with or without a link to an image file. * - * @param withFile Whether to include a placeholder image file on disk - * @return AttachmentUnit that was created + * @param withFile True, if the Attachment should link to a file + * @return The generated AttachmentUnit */ public static AttachmentUnit generateAttachmentUnit(boolean withFile) { ZonedDateTime started = ZonedDateTime.now().minusDays(5); - Attachment attachmentOfAttachmentUnit = withFile ? LectureFactory.generateAttachmentWithFile(started) : LectureFactory.generateAttachment(started); + Attachment attachmentOfAttachmentUnit = withFile ? generateAttachmentWithFile(started) : generateAttachment(started); AttachmentUnit attachmentUnit = new AttachmentUnit(); attachmentUnit.setDescription("Lorem Ipsum"); attachmentOfAttachmentUnit.setAttachmentUnit(attachmentUnit); @@ -51,10 +59,10 @@ public static AttachmentUnit generateAttachmentUnit(boolean withFile) { } /** - * Create a dummy attachment for testing + * Generates an Attachment with AttachmentType FILE. * - * @param date The optional upload and release date to set on the attachment - * @return Attachment that was created + * @param date The optional upload and release date of the Attachment + * @return The generated Attachment */ public static Attachment generateAttachment(ZonedDateTime date) { Attachment attachment = new Attachment(); @@ -69,10 +77,10 @@ public static Attachment generateAttachment(ZonedDateTime date) { } /** - * Create a dummy attachment for testing with a placeholder image file on disk + * Generates an Attachment with AttachmentType FILE and a link to an image file. * - * @param startDate The release date to set on the attachment - * @return Attachment that was created with its link set to a testing file on disk + * @param startDate The optional upload and release date of the Attachment + * @return The generated Attachment */ public static Attachment generateAttachmentWithFile(ZonedDateTime startDate) { Attachment attachment = generateAttachment(startDate); diff --git a/src/test/java/de/tum/in/www1/artemis/lecture/LectureUtilService.java b/src/test/java/de/tum/in/www1/artemis/lecture/LectureUtilService.java index ee470c9559c7..f7c5984843d3 100644 --- a/src/test/java/de/tum/in/www1/artemis/lecture/LectureUtilService.java +++ b/src/test/java/de/tum/in/www1/artemis/lecture/LectureUtilService.java @@ -74,6 +74,12 @@ public class LectureUtilService { @Autowired private LectureUnitCompletionRepository lectureUnitCompletionRepository; + /** + * Creates and saves a Course with a Lecture. The Lecture is only saved optionally. The Lecture is empty as it does not contain any LectureUnits. + * + * @param saveLecture True, if the Lecture should be saved + * @return The created Lecture + */ public Lecture createCourseWithLecture(boolean saveLecture) { Course course = CourseFactory.generateCourse(null, pastTimestamp, futureFutureTimestamp, new HashSet<>(), "tumuser", "tutor", "editor", "instructor"); @@ -87,6 +93,13 @@ public Lecture createCourseWithLecture(boolean saveLecture) { return lecture; } + /** + * Creates and saves a Lecture for the given Course. The Lecture is empty as it does not contain any LectureUnits. + * + * @param course The Course the Lecture belongs to + * @param visibleDate The visible date of the Lecture + * @return The created Lecture + */ public Lecture createLecture(Course course, ZonedDateTime visibleDate) { Lecture lecture = new Lecture(); lecture.setDescription("Test Lecture"); @@ -96,6 +109,16 @@ public Lecture createLecture(Course course, ZonedDateTime visibleDate) { return lecture; } + /** + * Creates and saves two Courses with Exercises of each type and two Lectures. For each Lecture, a LectureUnit of each type is added. + * + * @param userPrefix The prefix of the Course's user groups + * @param withParticipations True, if 5 participations by student1 should be added for the Course's Exercises + * @param withFiles True, if the LectureUnit of type AttachmentUnit should contain an Attachment with a link to an image file + * @param numberOfTutorParticipations The number of tutor participations to add to the ModelingExercise ("withParticipations" must be true for this to have an effect) + * @return A List of the created Courses + * @throws IOException If a file cannot be loaded from resources + */ public List createCoursesWithExercisesAndLecturesAndLectureUnits(String userPrefix, boolean withParticipations, boolean withFiles, int numberOfTutorParticipations) throws IOException { List courses = courseUtilService.createCoursesWithExercisesAndLectures(userPrefix, withParticipations, withFiles, numberOfTutorParticipations); @@ -113,6 +136,13 @@ public List createCoursesWithExercisesAndLecturesAndLectureUnits(String }).toList(); } + /** + * Adds the given Competencies to all LectureUnits of the given Lecture and saves the updated LectureUnits. + * + * @param lecture The Lecture whose LectureUnits should be updated + * @param competencies The Competencies to add to the LectureUnits + * @return The Lecture with updated LectureUnits + */ public Lecture addCompetencyToLectureUnits(Lecture lecture, Set competencies) { Lecture l = lectureRepo.findByIdWithLectureUnitsAndCompetenciesElseThrow(lecture.getId()); l.getLectureUnits().forEach(lectureUnit -> { @@ -122,6 +152,13 @@ public Lecture addCompetencyToLectureUnits(Lecture lecture, Set comp return l; } + /** + * Adds the given LectureUnits to the given Lecture and saves the updated Lecture. + * + * @param lecture The Lecture to add the LectureUnits to + * @param lectureUnits The LectureUnits to add to the Lecture + * @return The updated Lecture + */ public Lecture addLectureUnitsToLecture(Lecture lecture, List lectureUnits) { Lecture l = lectureRepo.findByIdWithLectureUnits(lecture.getId()).orElseThrow(); for (LectureUnit lectureUnit : lectureUnits) { @@ -130,18 +167,36 @@ public Lecture addLectureUnitsToLecture(Lecture lecture, List lectu return lectureRepo.save(l); } + /** + * Creates and saves a Channel for the given Lecture. + * + * @param lecture The Lecture the Channel belongs to + * @return The created Channel + */ public Channel addLectureChannel(Lecture lecture) { Channel channel = ConversationFactory.generateCourseWideChannel(lecture.getCourse()); channel.setLecture(lecture); return conversationRepository.save(channel); } + /** + * Creates and saves an ExerciseUnit for the given Exercise. + * + * @param exercise The Exercise the ExerciseUnit belongs to + * @return The created ExerciseUnit + */ public ExerciseUnit createExerciseUnit(Exercise exercise) { ExerciseUnit exerciseUnit = new ExerciseUnit(); exerciseUnit.setExercise(exercise); return exerciseUnitRepository.save(exerciseUnit); } + /** + * Creates and saves an AttachmentUnit with an Attachment. The Attachment can be created with or without a link to an image file. + * + * @param withFile True, if the Attachment should link to a file + * @return The created AttachmentUnit + */ public AttachmentUnit createAttachmentUnit(Boolean withFile) { ZonedDateTime started = ZonedDateTime.now().minusDays(5); Attachment attachmentOfAttachmentUnit = withFile ? LectureFactory.generateAttachmentWithFile(started) : LectureFactory.generateAttachment(started); @@ -154,6 +209,12 @@ public AttachmentUnit createAttachmentUnit(Boolean withFile) { return attachmentUnitRepository.save(attachmentUnit); } + /** + * Creates and saves an AttachmentUnit with an Attachment. Also creates and saves the given number of Slides for the AttachmentUnit. The Slides link to image files. + * + * @param numberOfSlides The number of Slides to create + * @return The created AttachmentUnit + */ public AttachmentUnit createAttachmentUnitWithSlides(int numberOfSlides) { ZonedDateTime started = ZonedDateTime.now().minusDays(5); Attachment attachmentOfAttachmentUnit = LectureFactory.generateAttachment(started); @@ -180,6 +241,11 @@ public AttachmentUnit createAttachmentUnitWithSlides(int numberOfSlides) { return attachmentUnitRepository.save(attachmentUnit); } + /** + * Creates and saves a TextUnit. + * + * @return The created TextUnit + */ public TextUnit createTextUnit() { TextUnit textUnit = new TextUnit(); textUnit.setName("Name Lorem Ipsum"); @@ -187,6 +253,11 @@ public TextUnit createTextUnit() { return textUnitRepository.save(textUnit); } + /** + * Creates and saves a VideoUnit. + * + * @return The created VideoUnit + */ public VideoUnit createVideoUnit() { VideoUnit videoUnit = new VideoUnit(); videoUnit.setDescription("Lorem Ipsum"); @@ -194,6 +265,11 @@ public VideoUnit createVideoUnit() { return videoUnitRepository.save(videoUnit); } + /** + * Creates and saves an OnlineUnit. + * + * @return The created OnlineUnit + */ public OnlineUnit createOnlineUnit() { OnlineUnit onlineUnit = new OnlineUnit(); onlineUnit.setDescription("Lorem Ipsum"); @@ -202,11 +278,11 @@ public OnlineUnit createOnlineUnit() { } /** - * Creates lecture unit completion entry for the user and the specified lecture unit + * Creates and saves a LectureUnitCompletion entry for the given LectureUnit and User. * - * @param lectureUnit the lecture unit that should be completed by the user - * @param user the user that has completed the lecture unit - * @return the updated lecture unit + * @param lectureUnit The LectureUnit that has been completed + * @param user The User that completed the LectureUnit + * @return The completed LectureUnit */ public LectureUnit completeLectureUnitForUser(LectureUnit lectureUnit, User user) { var lectureUnitCompletion = new LectureUnitCompletion();