diff --git a/src/main/java/de/tum/cit/aet/artemis/atlas/dto/metrics/CompetencyInformationDTO.java b/src/main/java/de/tum/cit/aet/artemis/atlas/dto/metrics/CompetencyInformationDTO.java index 02e0fc7edeb2..f361bc402718 100644 --- a/src/main/java/de/tum/cit/aet/artemis/atlas/dto/metrics/CompetencyInformationDTO.java +++ b/src/main/java/de/tum/cit/aet/artemis/atlas/dto/metrics/CompetencyInformationDTO.java @@ -4,6 +4,7 @@ import com.fasterxml.jackson.annotation.JsonInclude; +import de.tum.cit.aet.artemis.atlas.domain.competency.Competency; import de.tum.cit.aet.artemis.atlas.domain.competency.CompetencyTaxonomy; /** @@ -19,4 +20,15 @@ */ @JsonInclude(JsonInclude.Include.NON_EMPTY) public record CompetencyInformationDTO(long id, String title, String description, CompetencyTaxonomy taxonomy, ZonedDateTime softDueDate, boolean optional, int masteryThreshold) { + + /** + * Creates a CompetencyInformationDTO from a Competency. + * + * @param competency the Competency to create the DTO from + * @return the created DTO + */ + public static CompetencyInformationDTO of(C competency) { + return new CompetencyInformationDTO(competency.getId(), competency.getTitle(), competency.getDescription(), competency.getTaxonomy(), competency.getSoftDueDate(), + competency.isOptional(), competency.getMasteryThreshold()); + } } diff --git a/src/main/java/de/tum/cit/aet/artemis/atlas/dto/metrics/LectureUnitInformationDTO.java b/src/main/java/de/tum/cit/aet/artemis/atlas/dto/metrics/LectureUnitInformationDTO.java index 3a5d9cc8bcb4..8f4016a5f346 100644 --- a/src/main/java/de/tum/cit/aet/artemis/atlas/dto/metrics/LectureUnitInformationDTO.java +++ b/src/main/java/de/tum/cit/aet/artemis/atlas/dto/metrics/LectureUnitInformationDTO.java @@ -18,4 +18,15 @@ */ @JsonInclude(JsonInclude.Include.NON_EMPTY) public record LectureUnitInformationDTO(long id, long lectureId, String lectureTitle, String name, ZonedDateTime releaseDate, Class type) { + + /** + * Creates a LectureUnitInformationDTO from a LectureUnit. + * + * @param lectureUnit the LectureUnit to create the DTO from + * @return the created DTO + */ + public static LectureUnitInformationDTO of(L lectureUnit) { + return new LectureUnitInformationDTO(lectureUnit.getId(), lectureUnit.getLecture().getId(), lectureUnit.getLecture().getTitle(), lectureUnit.getName(), + lectureUnit.getReleaseDate(), lectureUnit.getClass()); + } } diff --git a/src/test/java/de/tum/cit/aet/artemis/assessment/service/CourseScoreCalculationServiceTest.java b/src/test/java/de/tum/cit/aet/artemis/assessment/service/CourseScoreCalculationServiceTest.java index 89d594d99982..f6c323c8e798 100644 --- a/src/test/java/de/tum/cit/aet/artemis/assessment/service/CourseScoreCalculationServiceTest.java +++ b/src/test/java/de/tum/cit/aet/artemis/assessment/service/CourseScoreCalculationServiceTest.java @@ -35,7 +35,6 @@ import de.tum.cit.aet.artemis.exercise.domain.IncludedInOverallScore; import de.tum.cit.aet.artemis.exercise.domain.participation.StudentParticipation; import de.tum.cit.aet.artemis.exercise.participation.util.ParticipationUtilService; -import de.tum.cit.aet.artemis.exercise.repository.ExerciseRepository; import de.tum.cit.aet.artemis.exercise.test_repository.StudentParticipationTestRepository; import de.tum.cit.aet.artemis.plagiarism.domain.PlagiarismVerdict; import de.tum.cit.aet.artemis.quiz.domain.QuizExercise; @@ -45,9 +44,6 @@ class CourseScoreCalculationServiceTest extends AbstractSpringIntegrationIndepen private static final String TEST_PREFIX = "cscservicetest"; - @Autowired - private ExerciseRepository exerciseRepository; - @Autowired private StudentParticipationTestRepository studentParticipationRepository; diff --git a/src/test/java/de/tum/cit/aet/artemis/assessment/util/StudentScoreUtilService.java b/src/test/java/de/tum/cit/aet/artemis/assessment/util/StudentScoreUtilService.java index 409c18fdc45d..a2e9aeee3da1 100644 --- a/src/test/java/de/tum/cit/aet/artemis/assessment/util/StudentScoreUtilService.java +++ b/src/test/java/de/tum/cit/aet/artemis/assessment/util/StudentScoreUtilService.java @@ -34,6 +34,23 @@ public void createStudentScore(Exercise exercise, User user, double score) { studentScoreRepository.save(studentScore); } + /** + * Creates rated and normal score (which are set equal) for given exercise and user. + * + * @param exercise the exercise to link the student score to + * @param user the user that is linked to the score + * @param score the score and rated score that the specified user has reached for the given exercise + */ + public void createRatedStudentScore(Exercise exercise, User user, double score) { + final var studentScore = new StudentScore(); + studentScore.setExercise(exercise); + studentScore.setUser(user); + studentScore.setLastScore(score); + studentScore.setLastPoints(exercise.getMaxPoints() * score / 100); + studentScore.setLastRatedScore(score); + studentScoreRepository.save(studentScore); + } + /** * Creates student score for given exercise and user. * diff --git a/src/test/java/de/tum/cit/aet/artemis/atlas/competency/util/CompetencyUtilService.java b/src/test/java/de/tum/cit/aet/artemis/atlas/competency/util/CompetencyUtilService.java index 411228bd332a..bca2072b19d0 100644 --- a/src/test/java/de/tum/cit/aet/artemis/atlas/competency/util/CompetencyUtilService.java +++ b/src/test/java/de/tum/cit/aet/artemis/atlas/competency/util/CompetencyUtilService.java @@ -18,7 +18,7 @@ import de.tum.cit.aet.artemis.core.domain.Course; import de.tum.cit.aet.artemis.core.domain.User; import de.tum.cit.aet.artemis.exercise.domain.Exercise; -import de.tum.cit.aet.artemis.exercise.repository.ExerciseRepository; +import de.tum.cit.aet.artemis.exercise.repository.ExerciseTestRepository; import de.tum.cit.aet.artemis.lecture.domain.LectureUnit; import de.tum.cit.aet.artemis.lecture.repository.LectureUnitRepository; @@ -35,7 +35,7 @@ public class CompetencyUtilService { private LectureUnitRepository lectureUnitRepository; @Autowired - private ExerciseRepository exerciseRepository; + private ExerciseTestRepository exerciseRepository; @Autowired private CompetencyRelationRepository competencyRelationRepository; diff --git a/src/test/java/de/tum/cit/aet/artemis/atlas/service/LearningPathServiceTest.java b/src/test/java/de/tum/cit/aet/artemis/atlas/service/LearningPathServiceTest.java index 6717bbd6b508..65143ebdf769 100644 --- a/src/test/java/de/tum/cit/aet/artemis/atlas/service/LearningPathServiceTest.java +++ b/src/test/java/de/tum/cit/aet/artemis/atlas/service/LearningPathServiceTest.java @@ -41,7 +41,6 @@ import de.tum.cit.aet.artemis.core.util.CourseUtilService; import de.tum.cit.aet.artemis.exercise.domain.DifficultyLevel; import de.tum.cit.aet.artemis.exercise.domain.Exercise; -import de.tum.cit.aet.artemis.exercise.repository.ExerciseRepository; import de.tum.cit.aet.artemis.lecture.domain.Lecture; import de.tum.cit.aet.artemis.lecture.domain.LectureUnit; import de.tum.cit.aet.artemis.lecture.repository.LectureUnitRepository; @@ -80,9 +79,6 @@ class LearningPathServiceTest extends AbstractSpringIntegrationIndependentTest { @Autowired private CompetencyProgressUtilService competencyProgressUtilService; - @Autowired - private ExerciseRepository exerciseRepository; - @Autowired private StudentScoreUtilService studentScoreUtilService; diff --git a/src/test/java/de/tum/cit/aet/artemis/communication/notification/GroupNotificationServiceTest.java b/src/test/java/de/tum/cit/aet/artemis/communication/notification/GroupNotificationServiceTest.java index 88dbd05d6ccb..4ccf0116d463 100644 --- a/src/test/java/de/tum/cit/aet/artemis/communication/notification/GroupNotificationServiceTest.java +++ b/src/test/java/de/tum/cit/aet/artemis/communication/notification/GroupNotificationServiceTest.java @@ -61,7 +61,6 @@ import de.tum.cit.aet.artemis.exam.repository.ExamRepository; import de.tum.cit.aet.artemis.exam.util.ExamUtilService; import de.tum.cit.aet.artemis.exercise.domain.Exercise; -import de.tum.cit.aet.artemis.exercise.repository.ExerciseRepository; import de.tum.cit.aet.artemis.lecture.domain.Attachment; import de.tum.cit.aet.artemis.lecture.domain.Lecture; import de.tum.cit.aet.artemis.programming.domain.ProgrammingExercise; @@ -82,9 +81,6 @@ class GroupNotificationServiceTest extends AbstractSpringIntegrationIndependentT @Autowired private NotificationSettingRepository notificationSettingRepository; - @Autowired - private ExerciseRepository exerciseRepository; - @Autowired private ExamRepository examRepository; diff --git a/src/test/java/de/tum/cit/aet/artemis/communication/notification/NotificationScheduleServiceTest.java b/src/test/java/de/tum/cit/aet/artemis/communication/notification/NotificationScheduleServiceTest.java index f3dc650315c9..21b6a8abdaed 100644 --- a/src/test/java/de/tum/cit/aet/artemis/communication/notification/NotificationScheduleServiceTest.java +++ b/src/test/java/de/tum/cit/aet/artemis/communication/notification/NotificationScheduleServiceTest.java @@ -32,7 +32,6 @@ import de.tum.cit.aet.artemis.core.util.CourseUtilService; import de.tum.cit.aet.artemis.exercise.domain.Exercise; import de.tum.cit.aet.artemis.exercise.participation.util.ParticipationUtilService; -import de.tum.cit.aet.artemis.exercise.repository.ExerciseRepository; import de.tum.cit.aet.artemis.shared.base.AbstractSpringIntegrationLocalCILocalVCTest; import de.tum.cit.aet.artemis.text.domain.TextSubmission; import de.tum.cit.aet.artemis.text.util.TextExerciseFactory; @@ -44,9 +43,6 @@ class NotificationScheduleServiceTest extends AbstractSpringIntegrationLocalCILo @Autowired private InstanceMessageReceiveService instanceMessageReceiveService; - @Autowired - private ExerciseRepository exerciseRepository; - @Autowired private NotificationRepository notificationRepository; diff --git a/src/test/java/de/tum/cit/aet/artemis/communication/notification/SingleUserNotificationServiceTest.java b/src/test/java/de/tum/cit/aet/artemis/communication/notification/SingleUserNotificationServiceTest.java index 9faaf7d03bc3..9a3f7db09aff 100644 --- a/src/test/java/de/tum/cit/aet/artemis/communication/notification/SingleUserNotificationServiceTest.java +++ b/src/test/java/de/tum/cit/aet/artemis/communication/notification/SingleUserNotificationServiceTest.java @@ -90,7 +90,6 @@ import de.tum.cit.aet.artemis.core.util.CourseUtilService; import de.tum.cit.aet.artemis.exercise.domain.Exercise; import de.tum.cit.aet.artemis.exercise.participation.util.ParticipationUtilService; -import de.tum.cit.aet.artemis.exercise.repository.ExerciseRepository; import de.tum.cit.aet.artemis.fileupload.domain.FileUploadExercise; import de.tum.cit.aet.artemis.fileupload.util.FileUploadExerciseUtilService; import de.tum.cit.aet.artemis.lecture.domain.Lecture; @@ -118,9 +117,6 @@ class SingleUserNotificationServiceTest extends AbstractSpringIntegrationIndepen @Autowired private NotificationSettingRepository notificationSettingRepository; - @Autowired - private ExerciseRepository exerciseRepository; - @Autowired private ResultTestRepository resultRepository; diff --git a/src/test/java/de/tum/cit/aet/artemis/communication/service/EmailSummaryServiceTest.java b/src/test/java/de/tum/cit/aet/artemis/communication/service/EmailSummaryServiceTest.java index 3e83e09a225c..4a42a5a826a5 100644 --- a/src/test/java/de/tum/cit/aet/artemis/communication/service/EmailSummaryServiceTest.java +++ b/src/test/java/de/tum/cit/aet/artemis/communication/service/EmailSummaryServiceTest.java @@ -29,7 +29,6 @@ import de.tum.cit.aet.artemis.core.util.CourseUtilService; import de.tum.cit.aet.artemis.exercise.domain.DifficultyLevel; import de.tum.cit.aet.artemis.exercise.domain.Exercise; -import de.tum.cit.aet.artemis.exercise.repository.ExerciseRepository; import de.tum.cit.aet.artemis.shared.base.AbstractSpringIntegrationIndependentTest; import de.tum.cit.aet.artemis.text.util.TextExerciseFactory; @@ -40,9 +39,6 @@ class EmailSummaryServiceTest extends AbstractSpringIntegrationIndependentTest { @Autowired private EmailSummaryService weeklyEmailSummaryService; - @Autowired - private ExerciseRepository exerciseRepository; - @Autowired private NotificationSettingRepository notificationSettingRepository; diff --git a/src/test/java/de/tum/cit/aet/artemis/communication/util/ConversationUtilService.java b/src/test/java/de/tum/cit/aet/artemis/communication/util/ConversationUtilService.java index 46a2adbe005e..1d581ffc7c66 100644 --- a/src/test/java/de/tum/cit/aet/artemis/communication/util/ConversationUtilService.java +++ b/src/test/java/de/tum/cit/aet/artemis/communication/util/ConversationUtilService.java @@ -37,7 +37,7 @@ import de.tum.cit.aet.artemis.core.user.util.UserUtilService; import de.tum.cit.aet.artemis.core.util.CourseFactory; import de.tum.cit.aet.artemis.core.util.CourseUtilService; -import de.tum.cit.aet.artemis.exercise.repository.ExerciseRepository; +import de.tum.cit.aet.artemis.exercise.repository.ExerciseTestRepository; import de.tum.cit.aet.artemis.exercise.util.ExerciseUtilService; import de.tum.cit.aet.artemis.lecture.domain.Lecture; import de.tum.cit.aet.artemis.lecture.repository.LectureRepository; @@ -64,7 +64,7 @@ public class ConversationUtilService { private CourseTestRepository courseRepo; @Autowired - private ExerciseRepository exerciseRepo; + private ExerciseTestRepository exerciseRepo; @Autowired private LectureRepository lectureRepo; diff --git a/src/test/java/de/tum/cit/aet/artemis/connectors/Lti13ServiceTest.java b/src/test/java/de/tum/cit/aet/artemis/connectors/Lti13ServiceTest.java index b1c21105fbb9..5fc135207c5f 100644 --- a/src/test/java/de/tum/cit/aet/artemis/connectors/Lti13ServiceTest.java +++ b/src/test/java/de/tum/cit/aet/artemis/connectors/Lti13ServiceTest.java @@ -55,7 +55,7 @@ import de.tum.cit.aet.artemis.core.test_repository.UserTestRepository; import de.tum.cit.aet.artemis.exercise.domain.Exercise; import de.tum.cit.aet.artemis.exercise.domain.participation.StudentParticipation; -import de.tum.cit.aet.artemis.exercise.repository.ExerciseRepository; +import de.tum.cit.aet.artemis.exercise.repository.ExerciseTestRepository; import de.tum.cit.aet.artemis.lti.config.Lti13TokenRetriever; import de.tum.cit.aet.artemis.lti.domain.LtiPlatformConfiguration; import de.tum.cit.aet.artemis.lti.domain.LtiResourceLaunch; @@ -78,7 +78,7 @@ class Lti13ServiceTest { private UserTestRepository userRepository; @Mock - private ExerciseRepository exerciseRepository; + private ExerciseTestRepository exerciseRepository; @Mock private CourseTestRepository courseRepository; diff --git a/src/test/java/de/tum/cit/aet/artemis/core/MetricsIntegrationTest.java b/src/test/java/de/tum/cit/aet/artemis/core/MetricsIntegrationTest.java index aa126be537b7..2b1b73492764 100644 --- a/src/test/java/de/tum/cit/aet/artemis/core/MetricsIntegrationTest.java +++ b/src/test/java/de/tum/cit/aet/artemis/core/MetricsIntegrationTest.java @@ -1,20 +1,20 @@ package de.tum.cit.aet.artemis.core; +import static de.tum.cit.aet.artemis.core.config.Constants.MIN_SCORE_GREEN; import static de.tum.cit.aet.artemis.core.util.TimeUtil.toRelativeTime; import static org.assertj.core.api.Assertions.assertThat; -import static org.awaitility.Awaitility.await; import java.time.Instant; import java.util.Comparator; import java.util.HashSet; +import java.util.List; +import java.util.Map; import java.util.Optional; import java.util.Set; -import java.util.function.Function; import java.util.stream.Collectors; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -22,15 +22,25 @@ import org.springframework.security.test.context.support.WithMockUser; import org.springframework.test.util.ReflectionTestUtils; -import de.tum.cit.aet.artemis.assessment.domain.Result; +import de.tum.cit.aet.artemis.assessment.domain.ParticipantScore; +import de.tum.cit.aet.artemis.assessment.repository.StudentScoreRepository; import de.tum.cit.aet.artemis.assessment.service.ParticipantScoreScheduleService; +import de.tum.cit.aet.artemis.assessment.util.StudentScoreUtilService; +import de.tum.cit.aet.artemis.atlas.competency.util.CompetencyUtilService; +import de.tum.cit.aet.artemis.atlas.dto.metrics.CompetencyInformationDTO; +import de.tum.cit.aet.artemis.atlas.dto.metrics.LectureUnitInformationDTO; import de.tum.cit.aet.artemis.atlas.dto.metrics.ResourceTimestampDTO; import de.tum.cit.aet.artemis.atlas.dto.metrics.StudentMetricsDTO; +import de.tum.cit.aet.artemis.atlas.repository.CompetencyRepository; import de.tum.cit.aet.artemis.core.domain.Course; import de.tum.cit.aet.artemis.exercise.domain.Exercise; import de.tum.cit.aet.artemis.exercise.domain.Submission; import de.tum.cit.aet.artemis.exercise.dto.ExerciseInformationDTO; import de.tum.cit.aet.artemis.exercise.repository.ExerciseMetricsRepository; +import de.tum.cit.aet.artemis.exercise.repository.ExerciseTestRepository; +import de.tum.cit.aet.artemis.lecture.repository.LectureUnitRepository; +import de.tum.cit.aet.artemis.lecture.service.LectureUnitService; +import de.tum.cit.aet.artemis.lecture.util.LectureUtilService; import de.tum.cit.aet.artemis.shared.base.AbstractSpringIntegrationIndependentTest; class MetricsIntegrationTest extends AbstractSpringIntegrationIndependentTest { @@ -40,14 +50,40 @@ class MetricsIntegrationTest extends AbstractSpringIntegrationIndependentTest { @Autowired private ExerciseMetricsRepository exerciseMetricsRepository; + @Autowired + private CompetencyRepository competencyRepository; + + @Autowired + private ExerciseTestRepository exerciseTestRepository; + + @Autowired + private LectureUnitRepository lectureUnitRepository; + + @Autowired + private StudentScoreRepository studentScoreRepository; + + @Autowired + protected StudentScoreUtilService studentScoreUtilService; + + @Autowired + protected LectureUtilService lectureUtilService; + + @Autowired + protected CompetencyUtilService competencyUtilService; + + @Autowired + protected LectureUnitService lectureUnitService; + private Course course; private Course courseWithTestRuns; + private long userID; + private static final String STUDENT_OF_COURSE = TEST_PREFIX + "student1"; @BeforeEach - void setupTestScenario() { + void setupTestScenario() throws Exception { // Prevents the ParticipantScoreScheduleService from scheduling tasks related to prior results ReflectionTestUtils.setField(participantScoreScheduleService, "lastScheduledRun", Optional.of(Instant.now())); ParticipantScoreScheduleService.DEFAULT_WAITING_TIME_FOR_SCHEDULED_TASKS = 100; @@ -59,6 +95,7 @@ void setupTestScenario() { courseWithTestRuns = courseUtilService.createCourseWithAllExerciseTypesAndParticipationsAndSubmissionsAndResultsAndTestRunsAndTwoUsers(TEST_PREFIX, true); userUtilService.createAndSaveUser(TEST_PREFIX + "user1337"); + userID = userUtilService.getUserByLogin(TEST_PREFIX + "student1").getId(); } @AfterEach @@ -94,25 +131,56 @@ void shouldReturnExerciseInformation() throws Exception { assertThat(exerciseInformation).allSatisfy((id, dto) -> assertThat(id).isEqualTo(dto.id())); } - @Disabled // TODO: reduce jacoco missing by one after enabled @Test @WithMockUser(username = STUDENT_OF_COURSE, roles = "USER") - void shouldReturnAverageScores() throws Exception { - // Wait for the scheduler to execute its task - participantScoreScheduleService.executeScheduledTasks(); - await().until(() -> participantScoreScheduleService.isIdle()); + void shouldReturnCategories() throws Exception { + final var result = request.get("/api/metrics/course/" + course.getId() + "/student", HttpStatus.OK, StudentMetricsDTO.class); + assertThat(result).isNotNull(); + assertThat(result.exerciseMetrics()).isNotNull(); + final var categories = result.exerciseMetrics().categories(); + + final var expectedCategories = exerciseTestRepository.findAllWithCategoriesByCourseId(course.getId()).stream() + .collect(Collectors.toMap(Exercise::getId, Exercise::getCategories)); + + assertThat(categories).isEqualTo(expectedCategories); + } + @Test + @WithMockUser(username = STUDENT_OF_COURSE, roles = "USER") + void shouldReturnAverageScores() throws Exception { + final var exercises = exerciseTestRepository.findAllExercisesByCourseIdWithEagerParticipation(course.getId()); + exercises.forEach(exercise -> studentScoreUtilService.createRatedStudentScore(exercise, userUtilService.getUserByLogin(STUDENT_OF_COURSE), 5)); final var result = request.get("/api/metrics/course/" + course.getId() + "/student", HttpStatus.OK, StudentMetricsDTO.class); assertThat(result).isNotNull(); assertThat(result.exerciseMetrics()).isNotNull(); final var averageScores = result.exerciseMetrics().averageScore(); + final var expectedAverageScores = exercises.stream().collect(Collectors.toMap(Exercise::getId, + exercise -> exercise.getStudentParticipations().stream().flatMap(participation -> participation.getStudents().stream()).mapToDouble( + student -> studentScoreRepository.findByExercise_IdAndUser_Id(exercise.getId(), student.getId()).map(ParticipantScore::getLastRatedScore).orElse(0.0)) + .average().orElse(0.0))); + + assertThat(averageScores).isEqualTo(expectedAverageScores); + } + + @Test + @WithMockUser(username = STUDENT_OF_COURSE, roles = "USER") + void shouldReturnScore() throws Exception { final var exercises = exerciseRepository.findAllExercisesByCourseId(course.getId()); - final var expectedMap = exercises.stream().map(Exercise::getId).collect( - Collectors.toMap(Function.identity(), id -> resultRepository.findAllByParticipationExerciseId(id).stream().mapToDouble(Result::getScore).average().orElse(0))); + exercises.forEach(exercise -> studentScoreUtilService.createRatedStudentScore(exercise, userUtilService.getUserByLogin(STUDENT_OF_COURSE), 0.5)); - assertThat(averageScores).isEqualTo(expectedMap); + final var result = request.get("/api/metrics/course/" + course.getId() + "/student", HttpStatus.OK, StudentMetricsDTO.class); + assertThat(result).isNotNull(); + assertThat(result.exerciseMetrics()).isNotNull(); + final var score = result.exerciseMetrics().score(); + + var expectedScores = exercises.stream() + .map(exercise -> studentScoreRepository.findByExercise_IdAndUser_Id(exercise.getId(), userID) + .map(studentScore -> Map.entry(exercise.getId(), studentScore.getLastRatedScore()))) + .filter(Optional::isPresent).map(Optional::get).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); + + assertThat(score).isEqualTo(expectedScores); } @Test @@ -196,5 +264,72 @@ void shouldFindLatestSubmissionDatesByUser() throws Exception { Set result = exerciseMetricsRepository.findLatestSubmissionDatesForUser(exerciseIds, userID); assertThat(result).isEqualTo(expectedSet); } + + @Test + @WithMockUser(username = STUDENT_OF_COURSE, roles = "USER") + void shouldReturnCompleted() throws Exception { + final var exercises = exerciseRepository.findAllExercisesByCourseId(course.getId()); + exercises.forEach(exercise -> studentScoreUtilService.createRatedStudentScore(exercise, userUtilService.getUserByLogin(STUDENT_OF_COURSE), MIN_SCORE_GREEN)); + + final var result = request.get("/api/metrics/course/" + course.getId() + "/student", HttpStatus.OK, StudentMetricsDTO.class); + assertThat(result).isNotNull(); + assertThat(result.exerciseMetrics()).isNotNull(); + final var completed = result.exerciseMetrics().completed(); + + final var expectedCompleted = exercises.stream().map(Exercise::getId).filter( + id -> studentScoreRepository.findByExercise_IdAndUser_Id(id, userID).map(studentScore -> studentScore.getLastRatedScore() >= MIN_SCORE_GREEN).orElse(false)) + .collect(Collectors.toSet()); + + assertThat(completed).isEqualTo(expectedCompleted); + } + } + + @Nested + class CompetencyMetrics { + + @Test + @WithMockUser(username = STUDENT_OF_COURSE, roles = "USER") + void shouldReturnCompetencyInformation() throws Exception { + course.setCompetencies(Set.of(competencyUtilService.createCompetency(course))); + + final var result = request.get("/api/metrics/course/" + course.getId() + "/student", HttpStatus.OK, StudentMetricsDTO.class); + assertThat(result).isNotNull(); + assertThat(result.competencyMetrics()).isNotNull(); + + final var competencyInformation = result.competencyMetrics().competencyInformation(); + + final var competencies = competencyRepository.findAllForCourseWithExercisesAndLectureUnitsAndLecturesAndAttachments(course.getId()); + final var expectedDTOs = competencies.stream().map(CompetencyInformationDTO::of).collect(Collectors.toSet()); + + assertThat(competencyInformation.values()).containsExactlyInAnyOrderElementsOf(expectedDTOs); + assertThat(competencyInformation).allSatisfy((id, dto) -> assertThat(id).isEqualTo(dto.id())); + } + } + + @Nested + class LectureMetrics { + + @Test + @WithMockUser(username = STUDENT_OF_COURSE, roles = "USER") + void shouldReturnLectureUnitInformation() throws Exception { + + final var lectureUnit = lectureUtilService.createTextUnit(); + lectureUnitService.linkLectureUnitsToCompetency(competencyUtilService.createCompetency(course), Set.of(lectureUnit), Set.of()); + + final var testLecture = lectureUtilService.createLecture(course, null); + lectureUtilService.addLectureUnitsToLecture(testLecture, List.of(lectureUnit)); + course.addLectures(testLecture); + + final var result = request.get("/api/metrics/course/" + course.getId() + "/student", HttpStatus.OK, StudentMetricsDTO.class); + assertThat(result).isNotNull(); + assertThat(result.lectureUnitStudentMetricsDTO()).isNotNull(); + final var lectureUnitInformation = result.lectureUnitStudentMetricsDTO().lectureUnitInformation(); + + final var lectureUnits = lectureUnitRepository.findAllById(Set.of(lectureUnit.getId())); + final var expectedDTOs = lectureUnits.stream().map(LectureUnitInformationDTO::of).collect(Collectors.toSet()); + + assertThat(lectureUnitInformation.values()).containsExactlyInAnyOrderElementsOf(expectedDTOs); + assertThat(lectureUnitInformation).allSatisfy((id, dto) -> assertThat(id).isEqualTo(dto.id())); + } } } diff --git a/src/test/java/de/tum/cit/aet/artemis/core/config/MetricsBeanTest.java b/src/test/java/de/tum/cit/aet/artemis/core/config/MetricsBeanTest.java index 969dcba1d7f8..f2f97b9ffe74 100644 --- a/src/test/java/de/tum/cit/aet/artemis/core/config/MetricsBeanTest.java +++ b/src/test/java/de/tum/cit/aet/artemis/core/config/MetricsBeanTest.java @@ -24,7 +24,6 @@ import de.tum.cit.aet.artemis.exercise.domain.ExerciseType; import de.tum.cit.aet.artemis.exercise.participation.util.ParticipationFactory; import de.tum.cit.aet.artemis.exercise.participation.util.ParticipationUtilService; -import de.tum.cit.aet.artemis.exercise.repository.ExerciseRepository; import de.tum.cit.aet.artemis.exercise.test_repository.SubmissionTestRepository; import de.tum.cit.aet.artemis.exercise.util.ExerciseUtilService; import de.tum.cit.aet.artemis.quiz.domain.QuizExercise; @@ -70,9 +69,6 @@ class MetricsBeanTest extends AbstractSpringIntegrationIndependentTest { @Autowired private UserTestRepository userRepository; - @Autowired - private ExerciseRepository exerciseRepository; - @Autowired private ExamUserRepository examUserRepository; diff --git a/src/test/java/de/tum/cit/aet/artemis/core/service/AssessmentServiceTest.java b/src/test/java/de/tum/cit/aet/artemis/core/service/AssessmentServiceTest.java index 673f3c13f07c..07be65439250 100644 --- a/src/test/java/de/tum/cit/aet/artemis/core/service/AssessmentServiceTest.java +++ b/src/test/java/de/tum/cit/aet/artemis/core/service/AssessmentServiceTest.java @@ -30,7 +30,6 @@ import de.tum.cit.aet.artemis.exercise.domain.participation.Participation; import de.tum.cit.aet.artemis.exercise.domain.participation.StudentParticipation; import de.tum.cit.aet.artemis.exercise.participation.util.ParticipationUtilService; -import de.tum.cit.aet.artemis.exercise.repository.ExerciseRepository; import de.tum.cit.aet.artemis.exercise.test_repository.ParticipationTestRepository; import de.tum.cit.aet.artemis.exercise.util.ExerciseUtilService; import de.tum.cit.aet.artemis.fileupload.domain.FileUploadExercise; @@ -49,9 +48,6 @@ class AssessmentServiceTest extends AbstractSpringIntegrationIndependentTest { private static final String TEST_PREFIX = "assessmentservice"; - @Autowired - private ExerciseRepository exerciseRepository; - @Autowired private ResultTestRepository resultRepository; diff --git a/src/test/java/de/tum/cit/aet/artemis/core/service/CourseExamExportServiceTest.java b/src/test/java/de/tum/cit/aet/artemis/core/service/CourseExamExportServiceTest.java index 719f1b47a0d9..77915abba5d3 100644 --- a/src/test/java/de/tum/cit/aet/artemis/core/service/CourseExamExportServiceTest.java +++ b/src/test/java/de/tum/cit/aet/artemis/core/service/CourseExamExportServiceTest.java @@ -20,7 +20,6 @@ import de.tum.cit.aet.artemis.core.user.util.UserUtilService; import de.tum.cit.aet.artemis.core.util.CourseUtilService; import de.tum.cit.aet.artemis.exam.repository.ExamRepository; -import de.tum.cit.aet.artemis.exercise.repository.ExerciseRepository; import de.tum.cit.aet.artemis.shared.base.AbstractSpringIntegrationIndependentTest; class CourseExamExportServiceTest extends AbstractSpringIntegrationIndependentTest { @@ -39,9 +38,6 @@ class CourseExamExportServiceTest extends AbstractSpringIntegrationIndependentTe @Autowired private UserUtilService userUtilService; - @Autowired - private ExerciseRepository exerciseRepository; - @Autowired private UserTestRepository userRepository; diff --git a/src/test/java/de/tum/cit/aet/artemis/core/service/CourseServiceTest.java b/src/test/java/de/tum/cit/aet/artemis/core/service/CourseServiceTest.java index b6483580a761..65e9c93d3cec 100644 --- a/src/test/java/de/tum/cit/aet/artemis/core/service/CourseServiceTest.java +++ b/src/test/java/de/tum/cit/aet/artemis/core/service/CourseServiceTest.java @@ -29,7 +29,6 @@ import de.tum.cit.aet.artemis.core.user.util.UserUtilService; import de.tum.cit.aet.artemis.core.util.CourseUtilService; import de.tum.cit.aet.artemis.exercise.domain.participation.StudentParticipation; -import de.tum.cit.aet.artemis.exercise.repository.ExerciseRepository; import de.tum.cit.aet.artemis.exercise.test_repository.StudentParticipationTestRepository; import de.tum.cit.aet.artemis.exercise.test_repository.SubmissionTestRepository; import de.tum.cit.aet.artemis.shared.base.AbstractSpringIntegrationLocalCILocalVCTest; @@ -52,9 +51,6 @@ class CourseServiceTest extends AbstractSpringIntegrationLocalCILocalVCTest { @Autowired private StudentParticipationTestRepository studentParticipationRepo; - @Autowired - private ExerciseRepository exerciseRepo; - @Autowired private UserUtilService userUtilService; @@ -79,7 +75,7 @@ void testGetActiveStudents(long weeks) { var course = courseUtilService.addEmptyCourse(); var exercise = TextExerciseFactory.generateTextExercise(date, date, date, course); course.addExercises(exercise); - exercise = exerciseRepo.save(exercise); + exercise = exerciseRepository.save(exercise); var student1 = userUtilService.getUserByLogin(TEST_PREFIX + "student1"); var participation1 = new StudentParticipation(); @@ -140,7 +136,7 @@ void testGetActiveStudents_UTCConversion() { var course = courseUtilService.addEmptyCourse(); var exercise = TextExerciseFactory.generateTextExercise(date, date, date, course); course.addExercises(exercise); - exercise = exerciseRepo.save(exercise); + exercise = exerciseRepository.save(exercise); var student1 = userUtilService.getUserByLogin(TEST_PREFIX + "student1"); var participation1 = new StudentParticipation(); diff --git a/src/test/java/de/tum/cit/aet/artemis/core/service/DataExportCreationServiceTest.java b/src/test/java/de/tum/cit/aet/artemis/core/service/DataExportCreationServiceTest.java index d4f16c93604a..73382100b910 100644 --- a/src/test/java/de/tum/cit/aet/artemis/core/service/DataExportCreationServiceTest.java +++ b/src/test/java/de/tum/cit/aet/artemis/core/service/DataExportCreationServiceTest.java @@ -67,7 +67,6 @@ import de.tum.cit.aet.artemis.exam.util.ExamUtilService; import de.tum.cit.aet.artemis.exercise.domain.Exercise; import de.tum.cit.aet.artemis.exercise.participation.util.ParticipationUtilService; -import de.tum.cit.aet.artemis.exercise.repository.ExerciseRepository; import de.tum.cit.aet.artemis.exercise.util.ExerciseUtilService; import de.tum.cit.aet.artemis.fileupload.util.ZipFileTestUtilService; import de.tum.cit.aet.artemis.modeling.domain.ModelingExercise; @@ -118,9 +117,6 @@ class DataExportCreationServiceTest extends AbstractSpringIntegrationJenkinsGitl @Autowired private StudentExamTestRepository studentExamRepository; - @Autowired - private ExerciseRepository exerciseRepository; - @Autowired private DataExportTestRepository dataExportRepository; diff --git a/src/test/java/de/tum/cit/aet/artemis/core/service/TitleCacheEvictionServiceTest.java b/src/test/java/de/tum/cit/aet/artemis/core/service/TitleCacheEvictionServiceTest.java index f9991fa36fc4..30f880543785 100644 --- a/src/test/java/de/tum/cit/aet/artemis/core/service/TitleCacheEvictionServiceTest.java +++ b/src/test/java/de/tum/cit/aet/artemis/core/service/TitleCacheEvictionServiceTest.java @@ -15,7 +15,6 @@ import de.tum.cit.aet.artemis.core.util.Tuple; import de.tum.cit.aet.artemis.exam.repository.ExamRepository; import de.tum.cit.aet.artemis.exam.util.ExamUtilService; -import de.tum.cit.aet.artemis.exercise.repository.ExerciseRepository; import de.tum.cit.aet.artemis.lecture.repository.LectureRepository; import de.tum.cit.aet.artemis.lecture.util.LectureUtilService; import de.tum.cit.aet.artemis.modeling.domain.DiagramType; @@ -39,9 +38,6 @@ class TitleCacheEvictionServiceTest extends AbstractSpringIntegrationIndependent @Autowired private CacheManager cacheManager; - @Autowired - private ExerciseRepository exerciseRepository; - @Autowired private LectureRepository lectureRepository; diff --git a/src/test/java/de/tum/cit/aet/artemis/core/util/CourseTestService.java b/src/test/java/de/tum/cit/aet/artemis/core/util/CourseTestService.java index c3c68e44b5e5..3b8ce269954b 100644 --- a/src/test/java/de/tum/cit/aet/artemis/core/util/CourseTestService.java +++ b/src/test/java/de/tum/cit/aet/artemis/core/util/CourseTestService.java @@ -126,7 +126,7 @@ import de.tum.cit.aet.artemis.exercise.domain.participation.StudentParticipation; import de.tum.cit.aet.artemis.exercise.participation.util.ParticipationFactory; import de.tum.cit.aet.artemis.exercise.participation.util.ParticipationUtilService; -import de.tum.cit.aet.artemis.exercise.repository.ExerciseRepository; +import de.tum.cit.aet.artemis.exercise.repository.ExerciseTestRepository; import de.tum.cit.aet.artemis.exercise.service.ParticipationService; import de.tum.cit.aet.artemis.exercise.team.TeamUtilService; import de.tum.cit.aet.artemis.exercise.test_repository.ParticipationTestRepository; @@ -175,7 +175,7 @@ public class CourseTestService { private CourseTestRepository courseRepo; @Autowired - private ExerciseRepository exerciseRepo; + private ExerciseTestRepository exerciseRepo; @Autowired private LectureRepository lectureRepo; diff --git a/src/test/java/de/tum/cit/aet/artemis/core/util/CourseUtilService.java b/src/test/java/de/tum/cit/aet/artemis/core/util/CourseUtilService.java index 02d8d55a6231..93e7856af38e 100644 --- a/src/test/java/de/tum/cit/aet/artemis/core/util/CourseUtilService.java +++ b/src/test/java/de/tum/cit/aet/artemis/core/util/CourseUtilService.java @@ -49,7 +49,7 @@ import de.tum.cit.aet.artemis.exercise.domain.participation.StudentParticipation; import de.tum.cit.aet.artemis.exercise.participation.util.ParticipationFactory; import de.tum.cit.aet.artemis.exercise.participation.util.ParticipationUtilService; -import de.tum.cit.aet.artemis.exercise.repository.ExerciseRepository; +import de.tum.cit.aet.artemis.exercise.repository.ExerciseTestRepository; import de.tum.cit.aet.artemis.exercise.test_repository.StudentParticipationTestRepository; import de.tum.cit.aet.artemis.exercise.test_repository.SubmissionTestRepository; import de.tum.cit.aet.artemis.exercise.util.ExerciseUtilService; @@ -110,7 +110,7 @@ public class CourseUtilService { private AttachmentRepository attachmentRepo; @Autowired - private ExerciseRepository exerciseRepo; + private ExerciseTestRepository exerciseRepository; @Autowired private TutorParticipationTestRepository tutorParticipationRepo; @@ -390,12 +390,12 @@ public List createCoursesWithExercisesAndLectures(String userPrefix, boo attachmentRepo.save(attachment1); attachmentRepo.save(attachment2); - modelingExercise = exerciseRepo.save(modelingExercise); - textExercise = exerciseRepo.save(textExercise); - exerciseRepo.save(fileUploadExercise); + modelingExercise = exerciseRepository.save(modelingExercise); + textExercise = exerciseRepository.save(textExercise); + exerciseRepository.save(fileUploadExercise); programmingExercise.setBuildConfig(programmingExerciseBuildConfigRepository.save(programmingExercise.getBuildConfig())); - exerciseRepo.save(programmingExercise); - exerciseRepo.save(quizExercise); + exerciseRepository.save(programmingExercise); + exerciseRepository.save(quizExercise); if (withParticipations) { @@ -521,12 +521,12 @@ public Course createCourseWithAllExerciseTypesAndParticipationsAndSubmissionsAnd // Save course and exercises to database Course courseSaved = courseRepo.save(course); - modelingExercise = exerciseRepo.save(modelingExercise); - textExercise = exerciseRepo.save(textExercise); - fileUploadExercise = exerciseRepo.save(fileUploadExercise); + modelingExercise = exerciseRepository.save(modelingExercise); + textExercise = exerciseRepository.save(textExercise); + fileUploadExercise = exerciseRepository.save(fileUploadExercise); programmingExercise.setBuildConfig(programmingExerciseBuildConfigRepository.save(programmingExercise.getBuildConfig())); - programmingExercise = exerciseRepo.save(programmingExercise); - quizExercise = exerciseRepo.save(quizExercise); + programmingExercise = exerciseRepository.save(programmingExercise); + quizExercise = exerciseRepository.save(quizExercise); // Get user and setup participations User user = (userRepo.findOneByLogin(userPrefix + "student1")).orElseThrow(); @@ -630,11 +630,11 @@ public Course createCourseWithAllExerciseTypesAndParticipationsAndSubmissionsAnd programmingSubmission = submissionRepository.save(programmingSubmission); // Save exercises - exerciseRepo.save(modelingExercise); - exerciseRepo.save(textExercise); - exerciseRepo.save(fileUploadExercise); - exerciseRepo.save(programmingExercise); - exerciseRepo.save(quizExercise); + exerciseRepository.save(modelingExercise); + exerciseRepository.save(textExercise); + exerciseRepository.save(fileUploadExercise); + exerciseRepository.save(programmingExercise); + exerciseRepository.save(quizExercise); // Connect participations with submissions participationModeling.setSubmissions(Set.of(modelingSubmission)); @@ -687,12 +687,12 @@ public Course createCourseWithAllExerciseTypesAndParticipationsAndSubmissionsAnd // Save course and exercises to database Course courseSaved = courseRepo.save(course); - modelingExercise = exerciseRepo.save(modelingExercise); - textExercise = exerciseRepo.save(textExercise); - fileUploadExercise = exerciseRepo.save(fileUploadExercise); + modelingExercise = exerciseRepository.save(modelingExercise); + textExercise = exerciseRepository.save(textExercise); + fileUploadExercise = exerciseRepository.save(fileUploadExercise); programmingExercise.setBuildConfig(programmingExerciseBuildConfigRepository.save(programmingExercise.getBuildConfig())); - programmingExercise = exerciseRepo.save(programmingExercise); - quizExercise = exerciseRepo.save(quizExercise); + programmingExercise = exerciseRepository.save(programmingExercise); + quizExercise = exerciseRepository.save(quizExercise); // Get user and setup participations User user = (userRepo.findOneByLogin(userPrefix + "student1")).orElseThrow(); @@ -811,11 +811,11 @@ public Course createCourseWithAllExerciseTypesAndParticipationsAndSubmissionsAnd programmingSubmission = submissionRepository.save(programmingSubmission); // Save exercises - exerciseRepo.save(modelingExercise); - exerciseRepo.save(textExercise); - exerciseRepo.save(fileUploadExercise); - exerciseRepo.save(programmingExercise); - exerciseRepo.save(quizExercise); + exerciseRepository.save(modelingExercise); + exerciseRepository.save(textExercise); + exerciseRepository.save(fileUploadExercise); + exerciseRepository.save(programmingExercise); + exerciseRepository.save(quizExercise); // Connect participations with submissions participationModeling.setSubmissions(Set.of(modelingSubmission)); @@ -898,7 +898,7 @@ else if ("Text".equals(title)) { textExercise.setTitle("Text"); course.addExercises(textExercise); courseRepo.save(course); - exerciseRepo.save(textExercise); + exerciseRepository.save(textExercise); } else if (title.startsWith("ClassDiagram")) { ModelingExercise modelingExercise = ModelingExerciseFactory.generateModelingExercise(PAST_TIMESTAMP, FUTURE_TIMESTAMP, FUTURE_FUTURE_TIMESTAMP, @@ -906,7 +906,7 @@ else if (title.startsWith("ClassDiagram")) { modelingExercise.setTitle(title); course.addExercises(modelingExercise); courseRepo.save(course); - exerciseRepo.save(modelingExercise); + exerciseRepository.save(modelingExercise); } return course; @@ -927,8 +927,8 @@ public Course addCourseWithModelingAndTextExercise() { textExercise.setTitle("Text"); course.addExercises(textExercise); course = courseRepo.save(course); - exerciseRepo.save(modelingExercise); - exerciseRepo.save(textExercise); + exerciseRepository.save(modelingExercise); + exerciseRepository.save(textExercise); return course; } @@ -954,9 +954,9 @@ public Course addCourseWithModelingAndTextAndFileUploadExercise() { course.addExercises(fileUploadExercise); course = courseRepo.save(course); - exerciseRepo.save(modelingExercise); - exerciseRepo.save(textExercise); - exerciseRepo.save(fileUploadExercise); + exerciseRepository.save(modelingExercise); + exerciseRepository.save(textExercise); + exerciseRepository.save(fileUploadExercise); return course; } @@ -1056,7 +1056,7 @@ public Course addCourseWithExercisesAndSubmissions(String courseShortName, Strin ModelingExercise modelingExercise = ModelingExerciseFactory.generateModelingExercise(releaseDate, dueDate, assessmentDueDate, DiagramType.ClassDiagram, course); modelingExercise.setTitle("Modeling" + i); modelingExercise.setCourse(course); - modelingExercise = exerciseRepo.save(modelingExercise); + modelingExercise = exerciseRepository.save(modelingExercise); course.addExercises(modelingExercise); for (int j = 1; j <= numberOfSubmissionPerExercise; j++) { StudentParticipation participation = participationUtilService.createAndSaveParticipationForExercise(modelingExercise, userPrefix + "student" + j); @@ -1079,7 +1079,7 @@ else if ((i % 3) == 1) { TextExercise textExercise = TextExerciseFactory.generateTextExercise(releaseDate, dueDate, assessmentDueDate, course); textExercise.setTitle("Text" + i); textExercise.setCourse(course); - textExercise = exerciseRepo.save(textExercise); + textExercise = exerciseRepository.save(textExercise); course.addExercises(textExercise); for (int j = 1; j <= numberOfSubmissionPerExercise; j++) { TextSubmission submission = ParticipationFactory.generateTextSubmission("submissionText", Language.ENGLISH, true); @@ -1097,7 +1097,7 @@ else if ((i % 3) == 1) { FileUploadExercise fileUploadExercise = FileUploadExerciseFactory.generateFileUploadExercise(releaseDate, dueDate, assessmentDueDate, "png,pdf", course); fileUploadExercise.setTitle("FileUpload" + i); fileUploadExercise.setCourse(course); - fileUploadExercise = exerciseRepo.save(fileUploadExercise); + fileUploadExercise = exerciseRepository.save(fileUploadExercise); course.addExercises(fileUploadExercise); for (int j = 1; j <= numberOfSubmissionPerExercise; j++) { FileUploadSubmission submission = ParticipationFactory.generateFileUploadSubmissionWithFile(true, null); @@ -1175,7 +1175,7 @@ public Course createCourseWithExamExercisesAndSubmissions(String userPrefix) thr // Create a file upload exercise with a dummy submission file var exerciseGroup1 = exerciseGroupRepository.save(new ExerciseGroup()); var fileUploadExercise = FileUploadExerciseFactory.generateFileUploadExerciseForExam(".png", exerciseGroup1); - fileUploadExercise = exerciseRepo.save(fileUploadExercise); + fileUploadExercise = exerciseRepository.save(fileUploadExercise); fileUploadExerciseUtilService.createFileUploadSubmissionWithFile(userPrefix, fileUploadExercise, "uploaded-file.png"); exerciseGroup1.addExercise(fileUploadExercise); exerciseGroup1 = exerciseGroupRepository.save(exerciseGroup1); @@ -1183,7 +1183,7 @@ public Course createCourseWithExamExercisesAndSubmissions(String userPrefix) thr // Create a text exercise with a dummy submission file var exerciseGroup2 = exerciseGroupRepository.save(new ExerciseGroup()); var textExercise = TextExerciseFactory.generateTextExerciseForExam(exerciseGroup2); - textExercise = exerciseRepo.save(textExercise); + textExercise = exerciseRepository.save(textExercise); var textSubmission = ParticipationFactory.generateTextSubmission("example text", Language.ENGLISH, true); textExerciseUtilService.saveTextSubmission(textExercise, textSubmission, userPrefix + "student1"); exerciseGroup2.addExercise(textExercise); @@ -1192,7 +1192,7 @@ public Course createCourseWithExamExercisesAndSubmissions(String userPrefix) thr // Create a modeling exercise with a dummy submission file var exerciseGroup3 = exerciseGroupRepository.save(new ExerciseGroup()); var modelingExercise = ModelingExerciseFactory.generateModelingExerciseForExam(DiagramType.ClassDiagram, exerciseGroup2); - modelingExercise = exerciseRepo.save(modelingExercise); + modelingExercise = exerciseRepository.save(modelingExercise); String emptyActivityModel = TestResourceUtils.loadFileFromResources("test-data/model-submission/empty-activity-diagram.json"); var modelingSubmission = ParticipationFactory.generateModelingSubmission(emptyActivityModel, true); participationUtilService.addSubmission(modelingExercise, modelingSubmission, userPrefix + "student1"); diff --git a/src/test/java/de/tum/cit/aet/artemis/exam/ExamStartTest.java b/src/test/java/de/tum/cit/aet/artemis/exam/ExamStartTest.java index 60aad76d09b3..399cb4306f6d 100644 --- a/src/test/java/de/tum/cit/aet/artemis/exam/ExamStartTest.java +++ b/src/test/java/de/tum/cit/aet/artemis/exam/ExamStartTest.java @@ -42,7 +42,6 @@ import de.tum.cit.aet.artemis.exercise.domain.Exercise; import de.tum.cit.aet.artemis.exercise.domain.participation.Participation; import de.tum.cit.aet.artemis.exercise.participation.util.ParticipationUtilService; -import de.tum.cit.aet.artemis.exercise.repository.ExerciseRepository; import de.tum.cit.aet.artemis.exercise.test_repository.ParticipationTestRepository; import de.tum.cit.aet.artemis.modeling.domain.DiagramType; import de.tum.cit.aet.artemis.modeling.domain.ModelingExercise; @@ -65,9 +64,6 @@ class ExamStartTest extends AbstractSpringIntegrationLocalCILocalVCTest { private static final String TEST_PREFIX = "examstarttest"; - @Autowired - private ExerciseRepository exerciseRepo; - @Autowired private ExamRepository examRepository; @@ -153,7 +149,7 @@ void testStartExercisesWithTextExercise() throws Exception { TextExercise textExercise = TextExerciseFactory.generateTextExerciseForExam(exerciseGroup); exerciseGroup.addExercise(textExercise); exerciseGroupRepository.save(exerciseGroup); - textExercise = exerciseRepo.save(textExercise); + textExercise = exerciseRepository.save(textExercise); createStudentExams(textExercise); @@ -176,7 +172,7 @@ void testStartExercisesWithModelingExercise() throws Exception { ModelingExercise modelingExercise = ModelingExerciseFactory.generateModelingExerciseForExam(DiagramType.ClassDiagram, exam.getExerciseGroups().getFirst()); exam.getExerciseGroups().getFirst().addExercise(modelingExercise); exerciseGroupRepository.save(exam.getExerciseGroups().getFirst()); - modelingExercise = exerciseRepo.save(modelingExercise); + modelingExercise = exerciseRepository.save(modelingExercise); createStudentExams(modelingExercise); @@ -271,7 +267,7 @@ private void createStudentExams(Exercise exercise) { private ProgrammingExercise createProgrammingExercise() { ProgrammingExercise programmingExercise = ProgrammingExerciseFactory.generateProgrammingExerciseForExam(exam.getExerciseGroups().getFirst()); programmingExercise.setBuildConfig(programmingExerciseBuildConfigRepository.save(programmingExercise.getBuildConfig())); - programmingExercise = exerciseRepo.save(programmingExercise); + programmingExercise = exerciseRepository.save(programmingExercise); programmingExercise = programmingExerciseUtilService.addTemplateParticipationForProgrammingExercise(programmingExercise); exam.getExerciseGroups().getFirst().addExercise(programmingExercise); exerciseGroupRepository.save(exam.getExerciseGroups().getFirst()); diff --git a/src/test/java/de/tum/cit/aet/artemis/exam/ExerciseGroupIntegrationJenkinsGitlabTest.java b/src/test/java/de/tum/cit/aet/artemis/exam/ExerciseGroupIntegrationJenkinsGitlabTest.java index 108eef0bb76f..cca6fc1591e2 100644 --- a/src/test/java/de/tum/cit/aet/artemis/exam/ExerciseGroupIntegrationJenkinsGitlabTest.java +++ b/src/test/java/de/tum/cit/aet/artemis/exam/ExerciseGroupIntegrationJenkinsGitlabTest.java @@ -29,7 +29,6 @@ import de.tum.cit.aet.artemis.exam.util.ExamFactory; import de.tum.cit.aet.artemis.exam.util.ExamUtilService; import de.tum.cit.aet.artemis.exercise.domain.Exercise; -import de.tum.cit.aet.artemis.exercise.repository.ExerciseRepository; import de.tum.cit.aet.artemis.programming.domain.ProgrammingExercise; import de.tum.cit.aet.artemis.programming.domain.ProgrammingLanguage; import de.tum.cit.aet.artemis.programming.repository.ProgrammingExerciseBuildConfigRepository; @@ -47,9 +46,6 @@ class ExerciseGroupIntegrationJenkinsGitlabTest extends AbstractSpringIntegratio @Autowired private TextExerciseRepository textExerciseRepository; - @Autowired - private ExerciseRepository exerciseRepository; - @Autowired private ProgrammingExerciseBuildConfigRepository programmingExerciseBuildConfigRepository; diff --git a/src/test/java/de/tum/cit/aet/artemis/exam/service/ExamServiceTest.java b/src/test/java/de/tum/cit/aet/artemis/exam/service/ExamServiceTest.java index 140deeae34c1..860576490fb0 100644 --- a/src/test/java/de/tum/cit/aet/artemis/exam/service/ExamServiceTest.java +++ b/src/test/java/de/tum/cit/aet/artemis/exam/service/ExamServiceTest.java @@ -28,7 +28,6 @@ import de.tum.cit.aet.artemis.exam.util.ExamUtilService; import de.tum.cit.aet.artemis.exercise.domain.IncludedInOverallScore; import de.tum.cit.aet.artemis.exercise.domain.participation.StudentParticipation; -import de.tum.cit.aet.artemis.exercise.repository.ExerciseRepository; import de.tum.cit.aet.artemis.exercise.test_repository.StudentParticipationTestRepository; import de.tum.cit.aet.artemis.quiz.domain.QuizExercise; import de.tum.cit.aet.artemis.shared.base.AbstractSpringIntegrationIndependentTest; @@ -47,9 +46,6 @@ class ExamServiceTest extends AbstractSpringIntegrationIndependentTest { @Autowired private StudentParticipationTestRepository studentParticipationRepository; - @Autowired - private ExerciseRepository exerciseRepository; - @Autowired private CourseUtilService courseUtilService; diff --git a/src/test/java/de/tum/cit/aet/artemis/exam/util/ExamUtilService.java b/src/test/java/de/tum/cit/aet/artemis/exam/util/ExamUtilService.java index ba1fe0c84b8f..0d6c8a6899c1 100644 --- a/src/test/java/de/tum/cit/aet/artemis/exam/util/ExamUtilService.java +++ b/src/test/java/de/tum/cit/aet/artemis/exam/util/ExamUtilService.java @@ -44,7 +44,7 @@ import de.tum.cit.aet.artemis.exercise.domain.participation.StudentParticipation; import de.tum.cit.aet.artemis.exercise.participation.util.ParticipationFactory; import de.tum.cit.aet.artemis.exercise.participation.util.ParticipationUtilService; -import de.tum.cit.aet.artemis.exercise.repository.ExerciseRepository; +import de.tum.cit.aet.artemis.exercise.repository.ExerciseTestRepository; import de.tum.cit.aet.artemis.exercise.test_repository.StudentParticipationTestRepository; import de.tum.cit.aet.artemis.exercise.test_repository.SubmissionTestRepository; import de.tum.cit.aet.artemis.fileupload.domain.FileUploadExercise; @@ -94,7 +94,7 @@ public class ExamUtilService { private ExamRepository examRepository; @Autowired - private ExerciseRepository exerciseRepo; + private ExerciseTestRepository exerciseRepo; @Autowired private ProgrammingExerciseBuildConfigRepository programmingExerciseBuildConfigRepository; diff --git a/src/test/java/de/tum/cit/aet/artemis/exercise/participation/util/ParticipationUtilService.java b/src/test/java/de/tum/cit/aet/artemis/exercise/participation/util/ParticipationUtilService.java index 13f049125c0a..ff3ab5f260e6 100644 --- a/src/test/java/de/tum/cit/aet/artemis/exercise/participation/util/ParticipationUtilService.java +++ b/src/test/java/de/tum/cit/aet/artemis/exercise/participation/util/ParticipationUtilService.java @@ -47,7 +47,7 @@ import de.tum.cit.aet.artemis.exercise.domain.participation.Participant; import de.tum.cit.aet.artemis.exercise.domain.participation.Participation; import de.tum.cit.aet.artemis.exercise.domain.participation.StudentParticipation; -import de.tum.cit.aet.artemis.exercise.repository.ExerciseRepository; +import de.tum.cit.aet.artemis.exercise.repository.ExerciseTestRepository; import de.tum.cit.aet.artemis.exercise.repository.TeamRepository; import de.tum.cit.aet.artemis.exercise.service.ParticipationService; import de.tum.cit.aet.artemis.exercise.test_repository.StudentParticipationTestRepository; @@ -91,7 +91,7 @@ public class ParticipationUtilService { private ParticipationVcsAccessTokenService participationVCSAccessTokenService; @Autowired - private ExerciseRepository exerciseRepo; + private ExerciseTestRepository exerciseRepository; @Autowired private SubmissionTestRepository submissionRepository; @@ -177,14 +177,14 @@ public Result addProgrammingParticipationWithResultForExercise(ProgrammingExerci * @return The created Result */ public Result createParticipationSubmissionAndResult(long exerciseId, Participant participant, Double points, Double bonusPoints, long scoreAwarded, boolean rated) { - Exercise exercise = exerciseRepo.findById(exerciseId).orElseThrow(); + Exercise exercise = exerciseRepository.findById(exerciseId).orElseThrow(); if (!exercise.getMaxPoints().equals(points)) { exercise.setMaxPoints(points); } if (!exercise.getBonusPoints().equals(bonusPoints)) { exercise.setBonusPoints(bonusPoints); } - exercise = exerciseRepo.saveAndFlush(exercise); + exercise = exerciseRepository.saveAndFlush(exercise); StudentParticipation studentParticipation = participationService.startExercise(exercise, participant, false); return createSubmissionAndResult(studentParticipation, scoreAwarded, rated); } diff --git a/src/test/java/de/tum/cit/aet/artemis/exercise/repository/ExerciseTestRepository.java b/src/test/java/de/tum/cit/aet/artemis/exercise/repository/ExerciseTestRepository.java new file mode 100644 index 000000000000..03332b2f6fc5 --- /dev/null +++ b/src/test/java/de/tum/cit/aet/artemis/exercise/repository/ExerciseTestRepository.java @@ -0,0 +1,31 @@ +package de.tum.cit.aet.artemis.exercise.repository; + +import java.util.List; +import java.util.Set; + +import org.springframework.context.annotation.Primary; +import org.springframework.data.jpa.repository.EntityGraph; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; +import org.springframework.stereotype.Repository; + +import de.tum.cit.aet.artemis.exercise.domain.Exercise; + +/** + * Spring Data JPA repository for the Exercise entity for Tests. + */ +@Primary +@Repository +public interface ExerciseTestRepository extends ExerciseRepository { + + @EntityGraph(attributePaths = { "studentParticipations", "studentParticipations.student", "studentParticipations.submissions" }) + @Query(""" + SELECT e + FROM Exercise e + WHERE e.course.id = :courseId + """) + Set findAllExercisesByCourseIdWithEagerParticipation(@Param("courseId") Long courseId); + + @EntityGraph(attributePaths = "categories") + List findAllWithCategoriesByCourseId(Long courseId); +} diff --git a/src/test/java/de/tum/cit/aet/artemis/exercise/service/PresentationPointsCalculationServiceTest.java b/src/test/java/de/tum/cit/aet/artemis/exercise/service/PresentationPointsCalculationServiceTest.java index 0592824c6ad7..56aded0df2ae 100644 --- a/src/test/java/de/tum/cit/aet/artemis/exercise/service/PresentationPointsCalculationServiceTest.java +++ b/src/test/java/de/tum/cit/aet/artemis/exercise/service/PresentationPointsCalculationServiceTest.java @@ -17,7 +17,6 @@ import de.tum.cit.aet.artemis.exercise.domain.IncludedInOverallScore; import de.tum.cit.aet.artemis.exercise.domain.participation.StudentParticipation; import de.tum.cit.aet.artemis.exercise.participation.util.ParticipationUtilService; -import de.tum.cit.aet.artemis.exercise.repository.ExerciseRepository; import de.tum.cit.aet.artemis.exercise.test_repository.StudentParticipationTestRepository; import de.tum.cit.aet.artemis.programming.domain.ProgrammingExercise; import de.tum.cit.aet.artemis.programming.util.ProgrammingExerciseUtilService; @@ -27,9 +26,6 @@ class PresentationPointsCalculationServiceTest extends AbstractSpringIntegration private static final String TEST_PREFIX = "ppcservicetest"; - @Autowired - private ExerciseRepository exerciseRepository; - @Autowired private StudentParticipationTestRepository studentParticipationRepository; diff --git a/src/test/java/de/tum/cit/aet/artemis/exercise/service/TeamWebsocketServiceTest.java b/src/test/java/de/tum/cit/aet/artemis/exercise/service/TeamWebsocketServiceTest.java index b73dc55fe396..0e9bca57e218 100644 --- a/src/test/java/de/tum/cit/aet/artemis/exercise/service/TeamWebsocketServiceTest.java +++ b/src/test/java/de/tum/cit/aet/artemis/exercise/service/TeamWebsocketServiceTest.java @@ -24,7 +24,6 @@ import de.tum.cit.aet.artemis.exercise.domain.Team; import de.tum.cit.aet.artemis.exercise.dto.TeamAssignmentPayload; import de.tum.cit.aet.artemis.exercise.dto.TeamImportStrategyType; -import de.tum.cit.aet.artemis.exercise.repository.ExerciseRepository; import de.tum.cit.aet.artemis.exercise.repository.TeamRepository; import de.tum.cit.aet.artemis.exercise.team.TeamUtilService; import de.tum.cit.aet.artemis.modeling.domain.ModelingExercise; @@ -38,9 +37,6 @@ class TeamWebsocketServiceTest extends AbstractSpringIntegrationIndependentTest @Autowired private UserTestRepository userRepo; - @Autowired - private ExerciseRepository exerciseRepo; - @Autowired private TeamRepository teamRepository; @@ -77,11 +73,11 @@ void init() { for (Exercise exercise : course.getExercises()) { if (exercise instanceof ModelingExercise) { exercise.setMode(ExerciseMode.TEAM); - modelingExercise = (ModelingExercise) exerciseRepo.save(exercise); + modelingExercise = (ModelingExercise) exerciseRepository.save(exercise); } if (exercise instanceof TextExercise) { exercise.setMode(ExerciseMode.TEAM); - textExercise = (TextExercise) exerciseRepo.save(exercise); + textExercise = (TextExercise) exerciseRepository.save(exercise); } } assertThat(modelingExercise).isNotNull(); diff --git a/src/test/java/de/tum/cit/aet/artemis/exercise/util/ExerciseUtilService.java b/src/test/java/de/tum/cit/aet/artemis/exercise/util/ExerciseUtilService.java index fa04fd24ca0d..db92da355b2f 100644 --- a/src/test/java/de/tum/cit/aet/artemis/exercise/util/ExerciseUtilService.java +++ b/src/test/java/de/tum/cit/aet/artemis/exercise/util/ExerciseUtilService.java @@ -38,7 +38,7 @@ import de.tum.cit.aet.artemis.exercise.domain.participation.StudentParticipation; import de.tum.cit.aet.artemis.exercise.participation.util.ParticipationFactory; import de.tum.cit.aet.artemis.exercise.participation.util.ParticipationUtilService; -import de.tum.cit.aet.artemis.exercise.repository.ExerciseRepository; +import de.tum.cit.aet.artemis.exercise.repository.ExerciseTestRepository; import de.tum.cit.aet.artemis.exercise.test_repository.StudentParticipationTestRepository; import de.tum.cit.aet.artemis.exercise.test_repository.SubmissionTestRepository; import de.tum.cit.aet.artemis.fileupload.domain.FileUploadExercise; @@ -65,7 +65,7 @@ public class ExerciseUtilService { @Autowired - private ExerciseRepository exerciseRepo; + private ExerciseTestRepository exerciseTestRepository; @Autowired private StudentParticipationTestRepository studentParticipationRepo; @@ -122,7 +122,7 @@ public Exercise addMaxScoreAndBonusPointsToExercise(Exercise exercise) { exercise.setIncludedInOverallScore(IncludedInOverallScore.INCLUDED_COMPLETELY); exercise.setMaxPoints(100.0); exercise.setBonusPoints(10.0); - return exerciseRepo.save(exercise); + return exerciseTestRepository.save(exercise); } /** @@ -222,7 +222,7 @@ public Course addCourseWithOneExerciseAndSubmissions(String userPrefix, String e switch (exerciseType) { case "modeling" -> { course = modelingExerciseUtilService.addCourseWithOneModelingExercise(); - exercise = exerciseRepo.findAllExercisesByCourseId(course.getId()).iterator().next(); + exercise = exerciseTestRepository.findAllExercisesByCourseId(course.getId()).iterator().next(); for (int j = 1; j <= numberOfSubmissions; j++) { StudentParticipation participation = participationUtilService.createAndSaveParticipationForExercise(exercise, userPrefix + "student" + j); assertThat(modelForModelingExercise).isNotEmpty(); @@ -235,7 +235,7 @@ public Course addCourseWithOneExerciseAndSubmissions(String userPrefix, String e } case "programming" -> { course = programmingExerciseUtilService.addCourseWithOneProgrammingExercise(); - exercise = exerciseRepo.findAllExercisesByCourseId(course.getId()).iterator().next(); + exercise = exerciseTestRepository.findAllExercisesByCourseId(course.getId()).iterator().next(); for (int j = 1; j <= numberOfSubmissions; j++) { ProgrammingSubmission submission = new ProgrammingSubmission(); programmingExerciseUtilService.addProgrammingSubmission((ProgrammingExercise) exercise, submission, userPrefix + "student" + j); @@ -244,7 +244,7 @@ public Course addCourseWithOneExerciseAndSubmissions(String userPrefix, String e } case "text" -> { course = textExerciseUtilService.addCourseWithOneFinishedTextExercise(); - exercise = exerciseRepo.findAllExercisesByCourseId(course.getId()).iterator().next(); + exercise = exerciseTestRepository.findAllExercisesByCourseId(course.getId()).iterator().next(); for (int j = 1; j <= numberOfSubmissions; j++) { TextSubmission textSubmission = ParticipationFactory.generateTextSubmission("Text" + j + j, null, true); textExerciseUtilService.saveTextSubmission((TextExercise) exercise, textSubmission, userPrefix + "student" + j); @@ -253,7 +253,7 @@ public Course addCourseWithOneExerciseAndSubmissions(String userPrefix, String e } case "file-upload" -> { course = fileUploadExerciseUtilService.addCourseWithFileUploadExercise(); - exercise = exerciseRepo.findAllExercisesByCourseId(course.getId()).iterator().next(); + exercise = exerciseTestRepository.findAllExercisesByCourseId(course.getId()).iterator().next(); for (int j = 1; j <= numberOfSubmissions; j++) { FileUploadSubmission submission = ParticipationFactory.generateFileUploadSubmissionWithFile(true, "path/to/file.pdf"); fileUploadExerciseUtilService.saveFileUploadSubmission((FileUploadExercise) exercise, submission, userPrefix + "student" + j); @@ -313,12 +313,13 @@ public void addAssessmentToExercise(Exercise exercise, User assessor) { * @param newDueDate The new due date of the exercise. */ public void updateExerciseDueDate(long exerciseId, ZonedDateTime newDueDate) { - Exercise exercise = exerciseRepo.findById(exerciseId).orElseThrow(() -> new IllegalArgumentException("Exercise with given ID " + exerciseId + " could not be found")); + Exercise exercise = exerciseTestRepository.findById(exerciseId) + .orElseThrow(() -> new IllegalArgumentException("Exercise with given ID " + exerciseId + " could not be found")); exercise.setDueDate(newDueDate); if (exercise instanceof ProgrammingExercise) { ((ProgrammingExercise) exercise).setBuildAndTestStudentSubmissionsAfterDueDate(newDueDate); } - exerciseRepo.save(exercise); + exerciseTestRepository.save(exercise); } /** @@ -328,9 +329,10 @@ public void updateExerciseDueDate(long exerciseId, ZonedDateTime newDueDate) { * @param newDueDate The new assessment due date of the exercise. */ public void updateAssessmentDueDate(long exerciseId, ZonedDateTime newDueDate) { - Exercise exercise = exerciseRepo.findById(exerciseId).orElseThrow(() -> new IllegalArgumentException("Exercise with given ID " + exerciseId + " could not be found")); + Exercise exercise = exerciseTestRepository.findById(exerciseId) + .orElseThrow(() -> new IllegalArgumentException("Exercise with given ID " + exerciseId + " could not be found")); exercise.setAssessmentDueDate(newDueDate); - exerciseRepo.save(exercise); + exerciseTestRepository.save(exercise); } /** diff --git a/src/test/java/de/tum/cit/aet/artemis/fileupload/util/FileUploadExerciseUtilService.java b/src/test/java/de/tum/cit/aet/artemis/fileupload/util/FileUploadExerciseUtilService.java index 4b6084891726..c85b0c3df488 100644 --- a/src/test/java/de/tum/cit/aet/artemis/fileupload/util/FileUploadExerciseUtilService.java +++ b/src/test/java/de/tum/cit/aet/artemis/fileupload/util/FileUploadExerciseUtilService.java @@ -26,7 +26,7 @@ import de.tum.cit.aet.artemis.exercise.domain.participation.StudentParticipation; import de.tum.cit.aet.artemis.exercise.participation.util.ParticipationFactory; import de.tum.cit.aet.artemis.exercise.participation.util.ParticipationUtilService; -import de.tum.cit.aet.artemis.exercise.repository.ExerciseRepository; +import de.tum.cit.aet.artemis.exercise.repository.ExerciseTestRepository; import de.tum.cit.aet.artemis.exercise.test_repository.StudentParticipationTestRepository; import de.tum.cit.aet.artemis.exercise.test_repository.SubmissionTestRepository; import de.tum.cit.aet.artemis.fileupload.domain.FileUploadExercise; @@ -45,9 +45,6 @@ public class FileUploadExerciseUtilService { private static final ZonedDateTime FUTURE_FUTURE_TIMESTAMP = ZonedDateTime.now().plusDays(2); - @Autowired - private ExerciseRepository exerciseRepo; - @Autowired private CourseTestRepository courseRepo; @@ -72,6 +69,9 @@ public class FileUploadExerciseUtilService { @Autowired private UserUtilService userUtilService; + @Autowired + private ExerciseTestRepository exerciseRepository; + /** * Creates and saves a new Course and an Exam with one mandatory FileUploadExercise. * @@ -82,7 +82,7 @@ public class FileUploadExerciseUtilService { public FileUploadExercise addCourseExamExerciseGroupWithOneFileUploadExercise(boolean startDateBeforeCurrentTime) { ExerciseGroup exerciseGroup = examUtilService.addExerciseGroupWithExamAndCourse(true, startDateBeforeCurrentTime); FileUploadExercise fileUploadExercise = FileUploadExerciseFactory.generateFileUploadExerciseForExam("pdf", exerciseGroup); - return exerciseRepo.save(fileUploadExercise); + return exerciseRepository.save(fileUploadExercise); } /** @@ -118,10 +118,10 @@ public List createFileUploadExercisesWithCourse() { public Course addCourseWithThreeFileUploadExercise() { var fileUploadExercises = createFileUploadExercisesWithCourse(); assertThat(fileUploadExercises).as("created three exercises").hasSize(3); - exerciseRepo.saveAll(fileUploadExercises); + exerciseRepository.saveAll(fileUploadExercises); long courseId = fileUploadExercises.getFirst().getCourseViaExerciseGroupOrCourseMember().getId(); Course course = courseRepo.findByIdWithEagerExercisesElseThrow(courseId); - List exercises = exerciseRepo.findAllExercisesByCourseId(courseId).stream().toList(); + List exercises = exerciseRepository.findAllExercisesByCourseId(courseId).stream().toList(); assertThat(exercises).as("three exercises got stored").hasSize(3); assertThat(course.getExercises()).as("course contains the exercises").containsExactlyInAnyOrder(exercises.toArray(new Exercise[] {})); return course; @@ -152,7 +152,7 @@ public Course addCourseWithFourFileUploadExercise() { fileUploadExercises.add(finishedFileUploadExercise); fileUploadExercises.add(assessedFileUploadExercise); fileUploadExercises.add(noDueDateFileUploadExercise); - exerciseRepo.saveAll(fileUploadExercises); + exerciseRepository.saveAll(fileUploadExercises); return courseRepo.findByIdWithEagerExercisesElseThrow(course.getId()); } @@ -168,7 +168,7 @@ public Course addCourseWithFileUploadExercise() { assessedFileUploadExercise.setTitle("assessed"); course.addExercises(assessedFileUploadExercise); courseRepo.save(course); - exerciseRepo.save(assessedFileUploadExercise); + exerciseRepository.save(assessedFileUploadExercise); return course; } diff --git a/src/test/java/de/tum/cit/aet/artemis/lti/service/LtiDeepLinkingServiceTest.java b/src/test/java/de/tum/cit/aet/artemis/lti/service/LtiDeepLinkingServiceTest.java index de205dc54fb1..9c597bbc1cbd 100644 --- a/src/test/java/de/tum/cit/aet/artemis/lti/service/LtiDeepLinkingServiceTest.java +++ b/src/test/java/de/tum/cit/aet/artemis/lti/service/LtiDeepLinkingServiceTest.java @@ -35,7 +35,7 @@ import de.tum.cit.aet.artemis.core.domain.Course; import de.tum.cit.aet.artemis.core.exception.BadRequestAlertException; import de.tum.cit.aet.artemis.exercise.domain.Exercise; -import de.tum.cit.aet.artemis.exercise.repository.ExerciseRepository; +import de.tum.cit.aet.artemis.exercise.repository.ExerciseTestRepository; import de.tum.cit.aet.artemis.lti.config.Lti13TokenRetriever; import de.tum.cit.aet.artemis.lti.domain.OnlineCourseConfiguration; import de.tum.cit.aet.artemis.text.domain.TextExercise; @@ -44,7 +44,7 @@ class LtiDeepLinkingServiceTest { @Mock - private ExerciseRepository exerciseRepository; + private ExerciseTestRepository exerciseRepository; @Mock private Lti13TokenRetriever tokenRetriever; diff --git a/src/test/java/de/tum/cit/aet/artemis/modeling/util/ModelingExerciseUtilService.java b/src/test/java/de/tum/cit/aet/artemis/modeling/util/ModelingExerciseUtilService.java index 8b8c4c18be85..2fe018ff8f5f 100644 --- a/src/test/java/de/tum/cit/aet/artemis/modeling/util/ModelingExerciseUtilService.java +++ b/src/test/java/de/tum/cit/aet/artemis/modeling/util/ModelingExerciseUtilService.java @@ -36,7 +36,7 @@ import de.tum.cit.aet.artemis.exercise.domain.participation.StudentParticipation; import de.tum.cit.aet.artemis.exercise.participation.util.ParticipationFactory; import de.tum.cit.aet.artemis.exercise.participation.util.ParticipationUtilService; -import de.tum.cit.aet.artemis.exercise.repository.ExerciseRepository; +import de.tum.cit.aet.artemis.exercise.repository.ExerciseTestRepository; import de.tum.cit.aet.artemis.exercise.test_repository.StudentParticipationTestRepository; import de.tum.cit.aet.artemis.modeling.domain.DiagramType; import de.tum.cit.aet.artemis.modeling.domain.ModelingExercise; @@ -62,9 +62,6 @@ public class ModelingExerciseUtilService { @Autowired private CourseTestRepository courseRepo; - @Autowired - private ExerciseRepository exerciseRepo; - @Autowired private ModelingExerciseRepository modelingExerciseRepository; @@ -98,6 +95,9 @@ public class ModelingExerciseUtilService { @Autowired private ModelingSubmissionService modelSubmissionService; + @Autowired + private ExerciseTestRepository exerciseRepository; + /** * Creates and saves a Course with a ModelingExercise. The ModelingExercise's DiagramType is set to ClassDiagram. * @@ -112,7 +112,7 @@ public Course addCourseWithOneModelingExercise(String title) { course.addExercises(modelingExercise); course.setMaxComplaintTimeDays(14); course = courseRepo.save(course); - modelingExercise = exerciseRepo.save(modelingExercise); + modelingExercise = exerciseRepository.save(modelingExercise); assertThat(course.getExercises()).as("course contains the exercise").containsExactlyInAnyOrder(modelingExercise); assertThat(modelingExercise.getPresentationScoreEnabled()).as("presentation score is enabled").isTrue(); return course; @@ -219,17 +219,17 @@ public Course addCourseWithDifferentModelingExercises() { course.addExercises(finishedExercise); course = courseRepo.save(course); - exerciseRepo.save(classExercise); - exerciseRepo.save(activityExercise); - exerciseRepo.save(objectExercise); - exerciseRepo.save(useCaseExercise); - exerciseRepo.save(communicationExercise); - exerciseRepo.save(componentExercise); - exerciseRepo.save(deploymentExercise); - exerciseRepo.save(petriNetExercise); - exerciseRepo.save(syntaxTreeExercise); - exerciseRepo.save(flowchartExercise); - exerciseRepo.save(finishedExercise); + exerciseRepository.save(classExercise); + exerciseRepository.save(activityExercise); + exerciseRepository.save(objectExercise); + exerciseRepository.save(useCaseExercise); + exerciseRepository.save(communicationExercise); + exerciseRepository.save(componentExercise); + exerciseRepository.save(deploymentExercise); + exerciseRepository.save(petriNetExercise); + exerciseRepository.save(syntaxTreeExercise); + exerciseRepository.save(flowchartExercise); + exerciseRepository.save(finishedExercise); Course storedCourse = courseRepo.findByIdWithExercisesAndExerciseDetailsAndLecturesElseThrow(course.getId()); Set exercises = storedCourse.getExercises(); assertThat(exercises).as("eleven exercises got stored").hasSize(11); diff --git a/src/test/java/de/tum/cit/aet/artemis/plagiarism/ContinuousPlagiarismControlServiceTest.java b/src/test/java/de/tum/cit/aet/artemis/plagiarism/ContinuousPlagiarismControlServiceTest.java index bba2832d362d..1986d792856d 100644 --- a/src/test/java/de/tum/cit/aet/artemis/plagiarism/ContinuousPlagiarismControlServiceTest.java +++ b/src/test/java/de/tum/cit/aet/artemis/plagiarism/ContinuousPlagiarismControlServiceTest.java @@ -25,7 +25,7 @@ import de.tum.cit.aet.artemis.core.domain.User; import de.tum.cit.aet.artemis.exercise.domain.Exercise; import de.tum.cit.aet.artemis.exercise.domain.participation.StudentParticipation; -import de.tum.cit.aet.artemis.exercise.repository.ExerciseRepository; +import de.tum.cit.aet.artemis.exercise.repository.ExerciseTestRepository; import de.tum.cit.aet.artemis.fileupload.domain.FileUploadExercise; import de.tum.cit.aet.artemis.modeling.domain.ModelingExercise; import de.tum.cit.aet.artemis.plagiarism.domain.PlagiarismCase; @@ -51,7 +51,7 @@ class ContinuousPlagiarismControlServiceTest { - private final ExerciseRepository exerciseRepository = mock(); + private final ExerciseTestRepository exerciseRepository = mock(); private final PlagiarismDetectionService plagiarismChecksService = mock(); diff --git a/src/test/java/de/tum/cit/aet/artemis/plagiarism/PlagiarismUtilService.java b/src/test/java/de/tum/cit/aet/artemis/plagiarism/PlagiarismUtilService.java index 67208a1bfabe..d08bda49304e 100644 --- a/src/test/java/de/tum/cit/aet/artemis/plagiarism/PlagiarismUtilService.java +++ b/src/test/java/de/tum/cit/aet/artemis/plagiarism/PlagiarismUtilService.java @@ -21,7 +21,7 @@ import de.tum.cit.aet.artemis.exercise.domain.participation.StudentParticipation; import de.tum.cit.aet.artemis.exercise.participation.util.ParticipationFactory; import de.tum.cit.aet.artemis.exercise.participation.util.ParticipationUtilService; -import de.tum.cit.aet.artemis.exercise.repository.ExerciseRepository; +import de.tum.cit.aet.artemis.exercise.repository.ExerciseTestRepository; import de.tum.cit.aet.artemis.exercise.team.TeamUtilService; import de.tum.cit.aet.artemis.exercise.test_repository.StudentParticipationTestRepository; import de.tum.cit.aet.artemis.exercise.test_repository.SubmissionTestRepository; @@ -47,7 +47,7 @@ public class PlagiarismUtilService { private CourseTestRepository courseRepo; @Autowired - private ExerciseRepository exerciseRepo; + private ExerciseTestRepository exerciseRepository; @Autowired private StudentParticipationTestRepository studentParticipationRepo; @@ -76,7 +76,7 @@ private TextExercise createTextExercise(String userPrefix, int studentsAmount, E exercise.setMode(mode); course.addExercises(exercise); courseRepo.save(course); - return exerciseRepo.save(exercise); + return exerciseRepository.save(exercise); } private ModelingExercise createModelingExercise(String userPrefix, int studentsAmount, ExerciseMode mode) { @@ -85,7 +85,7 @@ private ModelingExercise createModelingExercise(String userPrefix, int studentsA exercise.setMode(mode); course.addExercises(exercise); courseRepo.save(course); - return exerciseRepo.save(exercise); + return exerciseRepository.save(exercise); } private StudentParticipation saveParticipationAndAddSubmission(StudentParticipation participation, Submission submission) { @@ -115,7 +115,7 @@ public long createTextExerciseAndSimilarSubmissions(String userPrefix, String si saveParticipationAndAddSubmission(participation, submission); exercise.addParticipation(participation); } - exerciseRepo.save(exercise); + exerciseRepository.save(exercise); return exercise.getId(); } @@ -137,7 +137,7 @@ public long createTeamTextExerciseAndSimilarSubmissions(String userPrefix, Strin saveParticipationAndAddSubmission(participation, submission); exercise.addParticipation(participation); } - exerciseRepo.save(exercise); + exerciseRepository.save(exercise); return exercise.getId(); } @@ -159,7 +159,7 @@ public long createModelingExerciseAndSimilarSubmissionsToTheCourse(String userPr saveParticipationAndAddSubmission(participation, submission); exercise.addParticipation(participation); } - exerciseRepo.save(exercise); + exerciseRepository.save(exercise); return exercise.getId(); } @@ -181,7 +181,7 @@ public long createTeamModelingExerciseAndSimilarSubmissionsToTheCourse(String us saveParticipationAndAddSubmission(participation, submission); exercise.addParticipation(participation); } - exerciseRepo.save(exercise); + exerciseRepository.save(exercise); return exercise.getId(); } diff --git a/src/test/java/de/tum/cit/aet/artemis/programming/ProgrammingExerciseGradingServiceTest.java b/src/test/java/de/tum/cit/aet/artemis/programming/ProgrammingExerciseGradingServiceTest.java index 3b7b0bad36c8..b38a7248ae5f 100644 --- a/src/test/java/de/tum/cit/aet/artemis/programming/ProgrammingExerciseGradingServiceTest.java +++ b/src/test/java/de/tum/cit/aet/artemis/programming/ProgrammingExerciseGradingServiceTest.java @@ -47,7 +47,6 @@ import de.tum.cit.aet.artemis.exercise.domain.participation.Participation; import de.tum.cit.aet.artemis.exercise.domain.participation.StudentParticipation; import de.tum.cit.aet.artemis.exercise.participation.util.ParticipationUtilService; -import de.tum.cit.aet.artemis.exercise.repository.ExerciseRepository; import de.tum.cit.aet.artemis.exercise.test_repository.StudentParticipationTestRepository; import de.tum.cit.aet.artemis.exercise.util.ExerciseUtilService; import de.tum.cit.aet.artemis.programming.domain.ProgrammingExercise; @@ -84,9 +83,6 @@ abstract class ProgrammingExerciseGradingServiceTest extends AbstractSpringInteg @Autowired private ProgrammingExerciseTestCaseTestRepository testCaseRepository; - @Autowired - private ExerciseRepository exerciseRepository; - @Autowired private StudentParticipationTestRepository studentParticipationRepository; diff --git a/src/test/java/de/tum/cit/aet/artemis/quiz/util/QuizExerciseUtilService.java b/src/test/java/de/tum/cit/aet/artemis/quiz/util/QuizExerciseUtilService.java index 261ac6f912b0..2c378bb69fe9 100644 --- a/src/test/java/de/tum/cit/aet/artemis/quiz/util/QuizExerciseUtilService.java +++ b/src/test/java/de/tum/cit/aet/artemis/quiz/util/QuizExerciseUtilService.java @@ -31,7 +31,7 @@ import de.tum.cit.aet.artemis.exercise.domain.TeamAssignmentConfig; import de.tum.cit.aet.artemis.exercise.domain.participation.StudentParticipation; import de.tum.cit.aet.artemis.exercise.participation.util.ParticipationUtilService; -import de.tum.cit.aet.artemis.exercise.repository.ExerciseRepository; +import de.tum.cit.aet.artemis.exercise.repository.ExerciseTestRepository; import de.tum.cit.aet.artemis.exercise.repository.TeamRepository; import de.tum.cit.aet.artemis.exercise.test_repository.StudentParticipationTestRepository; import de.tum.cit.aet.artemis.quiz.domain.DragAndDropMapping; @@ -70,7 +70,7 @@ public class QuizExerciseUtilService { private CourseTestRepository courseRepo; @Autowired - private ExerciseRepository exerciseRepo; + private ExerciseTestRepository exerciseRepository; @Autowired private QuizSubmissionTestRepository quizSubmissionRepository; @@ -137,7 +137,7 @@ public Course addCourseWithOneQuizExercise(String title) { assertThat(quizExercise.isValid()).isTrue(); course.addExercises(quizExercise); course = courseRepo.save(course); - quizExercise = exerciseRepo.save(quizExercise); + quizExercise = exerciseRepository.save(quizExercise); assertThat(courseRepo.findWithEagerExercisesById(course.getId()).getExercises()).as("course contains the exercise").contains(quizExercise); return course; } diff --git a/src/test/java/de/tum/cit/aet/artemis/shared/base/AbstractArtemisIntegrationTest.java b/src/test/java/de/tum/cit/aet/artemis/shared/base/AbstractArtemisIntegrationTest.java index 57706d00e482..4157341a3deb 100644 --- a/src/test/java/de/tum/cit/aet/artemis/shared/base/AbstractArtemisIntegrationTest.java +++ b/src/test/java/de/tum/cit/aet/artemis/shared/base/AbstractArtemisIntegrationTest.java @@ -51,7 +51,7 @@ import de.tum.cit.aet.artemis.core.util.RequestUtilService; import de.tum.cit.aet.artemis.core.util.ThrowingProducer; import de.tum.cit.aet.artemis.exam.service.ExamAccessService; -import de.tum.cit.aet.artemis.exercise.repository.ExerciseRepository; +import de.tum.cit.aet.artemis.exercise.repository.ExerciseTestRepository; import de.tum.cit.aet.artemis.exercise.util.ExerciseUtilService; import de.tum.cit.aet.artemis.lti.service.Lti13Service; import de.tum.cit.aet.artemis.modeling.service.ModelingSubmissionService; @@ -186,7 +186,7 @@ public abstract class AbstractArtemisIntegrationTest implements MockDelegate { protected UserTestRepository userTestRepository; @Autowired - protected ExerciseRepository exerciseRepository; + protected ExerciseTestRepository exerciseRepository; @Autowired protected ResultTestRepository resultRepository; diff --git a/src/test/java/de/tum/cit/aet/artemis/text/util/TextExerciseUtilService.java b/src/test/java/de/tum/cit/aet/artemis/text/util/TextExerciseUtilService.java index fb1effac7c64..f52f9e7de82d 100644 --- a/src/test/java/de/tum/cit/aet/artemis/text/util/TextExerciseUtilService.java +++ b/src/test/java/de/tum/cit/aet/artemis/text/util/TextExerciseUtilService.java @@ -34,7 +34,7 @@ import de.tum.cit.aet.artemis.exercise.domain.participation.StudentParticipation; import de.tum.cit.aet.artemis.exercise.participation.util.ParticipationFactory; import de.tum.cit.aet.artemis.exercise.participation.util.ParticipationUtilService; -import de.tum.cit.aet.artemis.exercise.repository.ExerciseRepository; +import de.tum.cit.aet.artemis.exercise.repository.ExerciseTestRepository; import de.tum.cit.aet.artemis.exercise.test_repository.ParticipationTestRepository; import de.tum.cit.aet.artemis.exercise.test_repository.StudentParticipationTestRepository; import de.tum.cit.aet.artemis.exercise.test_repository.SubmissionTestRepository; @@ -62,7 +62,7 @@ public class TextExerciseUtilService { private static final ZonedDateTime futureFutureTimestamp = ZonedDateTime.now().plusDays(2); @Autowired - private ExerciseRepository exerciseRepo; + private ExerciseTestRepository exerciseRepository; @Autowired private CourseTestRepository courseRepo; @@ -194,7 +194,7 @@ public TextExercise createIndividualTextExercise(Course course, ZonedDateTime re TextExercise textExercise = TextExerciseFactory.generateTextExercise(releaseDate, dueDate, assessmentDueDate, course); textExercise.setMaxPoints(10.0); textExercise.setBonusPoints(0.0); - return exerciseRepo.save(textExercise); + return exerciseRepository.save(textExercise); } /** @@ -211,7 +211,7 @@ public TextExercise createTeamTextExercise(Course course, ZonedDateTime releaseD teamTextExercise.setMaxPoints(10.0); teamTextExercise.setBonusPoints(0.0); teamTextExercise.setMode(ExerciseMode.TEAM); - return exerciseRepo.save(teamTextExercise); + return exerciseRepository.save(teamTextExercise); } /** @@ -226,7 +226,7 @@ public Course addCourseWithOneReleasedTextExercise(String title) { textExercise.setTitle(title); course.addExercises(textExercise); course = courseRepo.save(course); - textExercise = exerciseRepo.save(textExercise); + textExercise = exerciseRepository.save(textExercise); assertThat(courseRepo.findWithEagerExercisesById(course.getId()).getExercises()).as("course contains the exercise").contains(textExercise); assertThat(textExercise.getPresentationScoreEnabled()).as("presentation score is enabled").isTrue(); @@ -268,7 +268,7 @@ public TextExercise addCourseExamExerciseGroupWithOneTextExercise(String title) if (title != null) { textExercise.setTitle(title); } - return exerciseRepo.save(textExercise); + return exerciseRepository.save(textExercise); } /** @@ -288,7 +288,7 @@ public TextExercise addCourseExamExerciseGroupWithOneTextExercise() { public TextExercise addCourseExamWithReviewDatesExerciseGroupWithOneTextExercise() { ExerciseGroup exerciseGroup = examUtilService.addExerciseGroupWithExamWithReviewDatesAndCourse(true); TextExercise textExercise = TextExerciseFactory.generateTextExerciseForExam(exerciseGroup); - return exerciseRepo.save(textExercise); + return exerciseRepository.save(textExercise); } /** @@ -493,7 +493,7 @@ public Course addCourseWithOneFinishedTextExercise() { finishedTextExercise.setTitle("Finished"); course.addExercises(finishedTextExercise); course = courseRepo.save(course); - exerciseRepo.save(finishedTextExercise); + exerciseRepository.save(finishedTextExercise); return course; }