Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Development: Adjust server tests to restructuring into modules #9314

Merged
merged 48 commits into from
Sep 28, 2024
Merged
Show file tree
Hide file tree
Changes from 47 commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
83ecf2d
Enable all architecture tests
MaximilianAnzinger Sep 13, 2024
8b43b93
Move architecture tests and object method tests into shared test package
MaximilianAnzinger Sep 13, 2024
adfb778
Restructure integration tests into modules
ole-ve Sep 13, 2024
51a468f
Restructure service tests into modules
ole-ve Sep 13, 2024
ceee431
Merge remote-tracking branch 'origin/develop' into chore/restructure-…
ole-ve Sep 13, 2024
81ff31e
Apply spotless
ole-ve Sep 13, 2024
71bdeec
Fix enforceNothing arch test
ole-ve Sep 13, 2024
52778fb
Fix correctServiceAnnotation arch test
ole-ve Sep 13, 2024
fefb027
Add architecture test to check for test only queries in prod code
MaximilianAnzinger Sep 14, 2024
c563417
Move test repositories to test_repository subdirectory
ole-ve Sep 14, 2024
4ed0b10
Merge remote-tracking branch 'origin/develop' into chore/restructure-…
ole-ve Sep 14, 2024
eb34cd8
Move exercise methods to test repository
MaximilianAnzinger Sep 17, 2024
b5fb222
Merge branch 'develop' into chore/restructure-tests
MaximilianAnzinger Sep 17, 2024
c896c8b
Create ResultTestRepository and improve test repository inheritance
MaximilianAnzinger Sep 19, 2024
ac1887b
Create TutorParticipationTestRepository
MaximilianAnzinger Sep 19, 2024
c468aa2
Create atlas test repositories
MaximilianAnzinger Sep 19, 2024
6db26fe
move test repos into test modules
MaximilianAnzinger Sep 20, 2024
fc4587e
Fix tutorial group repositories
JohannesStoehr Sep 20, 2024
799ac5a
create more test repositories
MaximilianAnzinger Sep 20, 2024
ebc8c8b
Fix text and quiz exercises
JohannesStoehr Sep 20, 2024
681ad06
Merge remote-tracking branch 'origin/chore/restructure-tests' into ch…
JohannesStoehr Sep 20, 2024
f7b9633
Fix check for method references
JohannesStoehr Sep 20, 2024
5d3792f
create more test repositories
MaximilianAnzinger Sep 20, 2024
9fec368
create more test repos
MaximilianAnzinger Sep 20, 2024
573fa81
Fix check for method references and remove unused methods
JohannesStoehr Sep 20, 2024
5f8e55c
add remaining test repos
MaximilianAnzinger Sep 20, 2024
73fc3c1
add more arch tests
MaximilianAnzinger Sep 20, 2024
6786cfe
User group of user in DatabaseQueryCountTest not saved
ole-ve Sep 20, 2024
8699f6a
Replace all usages of prod repo with test repo (if exists)
ole-ve Sep 20, 2024
93c5066
Annotate all test repositories with @Primary to override prod reposit…
ole-ve Sep 20, 2024
72624ee
Add archTest to enforce @Primary annotation on test repositories
ole-ve Sep 20, 2024
f917f45
Remove ToDo
ole-ve Sep 20, 2024
ab4eb7f
Merge remote-tracking branch 'origin/develop' into chore/restructure-…
ole-ve Sep 20, 2024
c267f28
Fix unintentional change
ole-ve Sep 20, 2024
232d809
Fix unintentional change
ole-ve Sep 20, 2024
1dbb3d7
Use ProgrammingExerciseTestRepository instead of ProgrammingExerciseR…
ole-ve Sep 20, 2024
3245271
Add archTest to check that test repositories are used instead of prod…
ole-ve Sep 20, 2024
dde0954
Fix unintentional change
ole-ve Sep 20, 2024
4e68bb7
Disable testCreateAnswerInExamChannel
ole-ve Sep 20, 2024
67105d4
Remove validated todo: https://docs.hazelcast.com/imdg/4.2/configurat…
ole-ve Sep 20, 2024
87c8996
Move JhiMetricsIntegrationTest to core module
ole-ve Sep 20, 2024
d065dc8
move tests from competency package into atlas module
MaximilianAnzinger Sep 21, 2024
520bcc5
fix atlas structure
MaximilianAnzinger Sep 21, 2024
c96f537
move online course tests to lti
MaximilianAnzinger Sep 21, 2024
f861722
Merge branch 'develop' into chore/restructure-tests
MaximilianAnzinger Sep 23, 2024
a4d4947
Merge branch 'develop' into chore/restructure-tests
MaximilianAnzinger Sep 28, 2024
3f77991
Merge branch 'develop' into chore/restructure-tests
MaximilianAnzinger Sep 28, 2024
b2b58e7
Merge remote-tracking branch 'origin/develop' into chore/restructure-…
ole-ve Sep 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Original file line number Diff line number Diff line change
Expand Up @@ -209,15 +209,6 @@ SELECT COUNT(c)
@Modifying
void deleteByResult_Id(long resultId);

/**
* Given a user id, retrieve all complaints related to assessments made by that assessor
*
* @param assessorId - the id of the assessor
* @return a list of complaints
*/
@EntityGraph(type = LOAD, attributePaths = { "result.participation", "result.submission", "result.assessor" })
List<Complaint> getAllByResult_Assessor_Id(Long assessorId);

/**
* Given an exercise id, retrieve all complaints related to that exercise
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import static de.tum.cit.aet.artemis.core.config.Constants.PROFILE_CORE;

import java.util.List;
import java.util.Optional;
import java.util.Set;

import org.springframework.context.annotation.Profile;
Expand All @@ -25,8 +24,6 @@
@Repository
public interface ComplaintResponseRepository extends ArtemisJpaRepository<ComplaintResponse, Long> {

Optional<ComplaintResponse> findByComplaint_Id(Long complaintId);

/**
* This magic method counts the number of complaints responses by complaint type associated to a course id
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ public interface ExampleSubmissionRepository extends ArtemisJpaRepository<Exampl
""")
Optional<ExampleSubmission> findByIdWithResultsAndFeedback(@Param("exampleSubmissionId") long exampleSubmissionId);

Optional<ExampleSubmission> findBySubmissionId(long submissionId);

@EntityGraph(type = LOAD, attributePaths = { "submission", "submission.results" })
Optional<ExampleSubmission> findWithResultsBySubmissionId(long submissionId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
import java.util.Optional;
import java.util.Set;

import jakarta.validation.constraints.NotNull;

import org.springframework.context.annotation.Profile;
import org.springframework.data.jpa.repository.EntityGraph;
import org.springframework.data.jpa.repository.Modifying;
Expand Down Expand Up @@ -46,11 +44,6 @@ public interface ParticipantScoreRepository extends ArtemisJpaRepository<Partici
""")
List<ParticipantScore> findAllOutdated();

@NotNull
@Override
@EntityGraph(type = LOAD, attributePaths = { "exercise", "lastResult", "lastRatedResult" })
List<ParticipantScore> findAll();

@EntityGraph(type = LOAD, attributePaths = { "exercise", "lastResult", "lastRatedResult" })
List<ParticipantScore> findAllByExercise(Exercise exercise);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,23 +147,6 @@ default Optional<Result> findFirstWithSubmissionAndFeedbacksAndTestCasesByPartic
@EntityGraph(type = LOAD, attributePaths = "submission")
Optional<Result> findResultWithSubmissionsById(long resultId);

/**
* Finds the first result by participation ID, including its submissions, ordered by completion date in descending order.
* This method avoids in-memory paging by retrieving the first result directly from the database.
*
* @param participationId the ID of the participation to find the result for
* @return an {@code Optional} containing the first {@code Result} with submissions, ordered by completion date in descending order,
* or an empty {@code Optional} if no result is found
*/
default Optional<Result> findFirstWithSubmissionsByParticipationIdOrderByCompletionDateDesc(long participationId) {
var resultOptional = findFirstByParticipationIdOrderByCompletionDateDesc(participationId);
if (resultOptional.isEmpty()) {
return Optional.empty();
}
var id = resultOptional.get().getId();
return findResultWithSubmissionsById(id);
}

Optional<Result> findFirstByParticipationIdAndRatedOrderByCompletionDateDesc(long participationId, boolean rated);

/**
Expand All @@ -184,11 +167,6 @@ default Optional<Result> findFirstByParticipationIdAndRatedWithSubmissionOrderBy
return findResultWithSubmissionsById(id);
}

Optional<Result> findDistinctBySubmissionId(long submissionId);

@EntityGraph(type = LOAD, attributePaths = "feedbacks")
Optional<Result> findDistinctWithFeedbackBySubmissionId(long submissionId);

@Query("""
SELECT r
FROM Result r
Expand All @@ -208,8 +186,6 @@ default Optional<Result> findFirstByParticipationIdAndRatedWithSubmissionOrderBy
""")
Optional<Result> findByIdWithEagerFeedbacksAndAssessor(@Param("resultId") long resultId);

Set<Result> findAllByParticipationExerciseId(long exerciseId);

/**
* Load a result from the database by its id together with the associated submission, the list of feedback items, its assessor and assessment note.
*
Expand Down Expand Up @@ -352,9 +328,6 @@ SELECT COUNT(r.id)
""")
List<Long> countNumberOfFinishedAssessmentsByExamIdIgnoreTestRuns(@Param("examId") long examId);

@EntityGraph(type = LOAD, attributePaths = { "feedbacks" })
Set<Result> findAllWithEagerFeedbackByAssessorIsNotNullAndParticipation_ExerciseIdAndCompletionDateIsNotNull(long exerciseId);

@Query("""
SELECT COUNT(DISTINCT p)
FROM Participation p
Expand Down Expand Up @@ -805,10 +778,6 @@ default Optional<Result> findLatestResultWithFeedbacksForParticipation(long part
}
}

default Result findFirstWithFeedbacksByParticipationIdOrderByCompletionDateDescElseThrow(long participationId) {
return getValueElseThrow(findFirstWithFeedbacksTestCasesByParticipationIdOrderByCompletionDateDesc(participationId));
}

default Result findWithBidirectionalSubmissionAndFeedbackAndAssessorAndAssessmentNoteAndTeamStudentsByIdElseThrow(long resultId) {
return getValueElseThrow(findWithBidirectionalSubmissionAndFeedbackAndAssessorAndAssessmentNoteAndTeamStudentsById(resultId), resultId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import org.springframework.transaction.annotation.Transactional;

import de.tum.cit.aet.artemis.assessment.domain.TutorParticipation;
import de.tum.cit.aet.artemis.core.domain.Course;
import de.tum.cit.aet.artemis.core.domain.User;
import de.tum.cit.aet.artemis.core.repository.base.ArtemisJpaRepository;
import de.tum.cit.aet.artemis.exercise.domain.Exercise;
Expand All @@ -24,8 +23,6 @@
@Repository
public interface TutorParticipationRepository extends ArtemisJpaRepository<TutorParticipation, Long> {

List<TutorParticipation> findByAssessedExercise(Exercise assessedExercise);

@EntityGraph(type = LOAD, attributePaths = { "trainedExampleSubmissions", "trainedExampleSubmissions.submission.results" })
TutorParticipation findWithEagerExampleSubmissionAndResultsByAssessedExerciseAndTutor(Exercise assessedExercise, User tutor);

Expand All @@ -34,8 +31,6 @@ public interface TutorParticipationRepository extends ArtemisJpaRepository<Tutor
@EntityGraph(type = LOAD, attributePaths = { "trainedExampleSubmissions", "trainedExampleSubmissions.submission.results" })
List<TutorParticipation> findAllByAssessedExercise_Course_IdAndTutor_Id(long courseId, long tutorId);

List<TutorParticipation> findAllByAssessedExercise_Course(Course course);

@EntityGraph(type = LOAD, attributePaths = { "trainedExampleSubmissions", "trainedExampleSubmissions.submission.results" })
List<TutorParticipation> findAllByAssessedExercise_ExerciseGroup_Exam_IdAndTutor_Id(long examId, long tutorId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@ public interface CompetencyProgressRepository extends ArtemisJpaRepository<Compe
""")
Optional<CompetencyProgress> findByCompetencyIdAndUserId(@Param("competencyId") long competencyId, @Param("userId") long userId);

default CompetencyProgress findByCompetencyIdAndUserIdOrElseThrow(long competencyId, long userId) {
return getValueElseThrow(findByCompetencyIdAndUserId(competencyId, userId));
}

@Query("""
SELECT cp
FROM CompetencyProgress cp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@ default LearningPath findWithEagerUserByIdElseThrow(long learningPathId) {
@EntityGraph(type = LOAD, attributePaths = { "competencies" })
Optional<LearningPath> findWithEagerCompetenciesByCourseIdAndUserId(long courseId, long userId);

default LearningPath findWithEagerCompetenciesByCourseIdAndUserIdElseThrow(long courseId, long userId) {
return getValueElseThrow(findWithEagerCompetenciesByCourseIdAndUserId(courseId, userId));
}

@EntityGraph(type = LOAD, attributePaths = { "course", "competencies" })
Optional<LearningPath> findWithEagerCourseAndCompetenciesById(long learningPathId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import org.springframework.transaction.annotation.Transactional;

import de.tum.cit.aet.artemis.atlas.domain.science.ScienceEvent;
import de.tum.cit.aet.artemis.atlas.domain.science.ScienceEventType;
import de.tum.cit.aet.artemis.core.repository.base.ArtemisJpaRepository;

/**
Expand All @@ -22,8 +21,6 @@
@Repository
public interface ScienceEventRepository extends ArtemisJpaRepository<ScienceEvent, Long> {

Set<ScienceEvent> findAllByType(ScienceEventType type);

@Transactional // ok because of modifying query
@Modifying
@Query("""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.tum.cit.aet.artemis.atlas.web;
package de.tum.cit.aet.artemis.atlas.web.admin;

import static de.tum.cit.aet.artemis.core.config.Constants.PROFILE_CORE;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,6 @@ public interface ConversationParticipantRepository extends ArtemisJpaRepository<

Optional<ConversationParticipant> findConversationParticipantByConversationIdAndUserId(Long conversationId, Long userId);

default ConversationParticipant findConversationParticipantByConversationIdAndUserIdElseThrow(Long conversationId, Long userId) {
return getValueElseThrow(findConversationParticipantByConversationIdAndUserId(conversationId, userId));
}

@Query("""
SELECT DISTINCT conversationParticipant
FROM ConversationParticipant conversationParticipant
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,6 @@ public interface PostRepository extends ArtemisJpaRepository<Post, Long>, JpaSpe

List<Post> findPostsByAuthorId(long authorId);

/**
* find all posts of a user in a course
* currently only used for testing
*
* @param authorId id of the user
* @param courseId id of the course
* @return a list of posts
*/
@Query("""
SELECT p
FROM Post p
WHERE p.author.id =:authorId
AND p.conversation.course.id = :courseId
""")
List<Post> findPostsByAuthorIdAndCourseId(@Param("authorId") long authorId, @Param("courseId") long courseId);

@Transactional // ok because of delete
@Modifying
void deleteAllByConversationId(Long conversationId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,5 @@
@Repository
public interface ReactionRepository extends ArtemisJpaRepository<Reaction, Long> {

List<Reaction> findReactionsByPostId(Long postId);

List<Reaction> findReactionsByUserId(long userId);

List<Reaction> findReactionsByAnswerPostId(Long answerPostId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,6 @@ public interface ChannelRepository extends ArtemisJpaRepository<Channel, Long> {
""")
List<Channel> findChannelsOfUser(@Param("courseId") Long courseId, @Param("userId") Long userId);

@Query("""
SELECT DISTINCT channel
FROM Channel channel
WHERE channel.course.id = :courseId
AND channel.isCourseWide = TRUE
ORDER BY channel.name
""")
List<Channel> findCourseWideChannelsInCourse(@Param("courseId") long courseId);

@Query("""
SELECT DISTINCT channel
FROM Channel channel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ public interface ConversationRepository extends ArtemisJpaRepository<Conversatio
@Modifying
void deleteAllByCourseId(long courseId);

// This is used only for testing purposes
List<Conversation> findAllByCourseId(long courseId);

@EntityGraph(type = LOAD, attributePaths = { "conversationParticipants" })
Optional<Conversation> findWithParticipantsById(long conversationId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import org.springframework.stereotype.Repository;

import de.tum.cit.aet.artemis.communication.domain.conversation.OneToOneChat;
import de.tum.cit.aet.artemis.core.exception.EntityNotFoundException;
import de.tum.cit.aet.artemis.core.repository.base.ArtemisJpaRepository;

@Profile(PROFILE_CORE)
Expand Down Expand Up @@ -73,15 +72,5 @@ AND EXISTS (
// one-to-one chats userA has in that specific course.
Optional<OneToOneChat> findWithParticipantsAndUserGroupsInCourseBetweenUsers(@Param("courseId") Long courseId, @Param("userIdA") Long userIdA, @Param("userIdB") Long userIdB);

@Query("""
SELECT DISTINCT oneToOneChat
FROM OneToOneChat oneToOneChat
LEFT JOIN FETCH oneToOneChat.conversationParticipants p
LEFT JOIN FETCH p.user u
LEFT JOIN FETCH u.groups
WHERE oneToOneChat.id = :oneToOneChatId
""")
Optional<OneToOneChat> findByIdWithConversationParticipantsAndUserGroups(@Param("oneToOneChatId") Long oneToOneChatId) throws EntityNotFoundException;

Integer countByCreatorIdAndCourseId(Long creatorId, Long courseId);
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.tum.cit.aet.artemis.communication.web;
package de.tum.cit.aet.artemis.communication.web.admin;

import static de.tum.cit.aet.artemis.core.config.Constants.PROFILE_CORE;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,6 @@ public HazelcastInstance hazelcastInstance(JHipsterProperties jHipsterProperties
}
config.getMapConfigs().put("default", initializeDefaultMapConfig(jHipsterProperties));
config.getMapConfigs().put("files", initializeFilesMapConfig(jHipsterProperties));
// TODO Ole: investigate if the following * in artemis.*.domain works for database entity caching or if we need to specify all module domain paths here
config.getMapConfigs().put("de.tum.cit.aet.artemis.*.domain.*", initializeDomainMapConfig(jHipsterProperties));

// Configure split brain protection if the cluster was split at some point
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,6 @@ SELECT COUNT(c) > 0
""")
Optional<Course> findWithEagerLearningPathsAndLearningPathCompetencies(@Param("courseId") long courseId);

@EntityGraph(type = LOAD, attributePaths = { "competencies", "prerequisites", "learningPaths", "learningPaths.competencies" })
Optional<Course> findWithEagerLearningPathsAndCompetenciesAndPrerequisitesById(long courseId);

// Note: we load attachments directly because otherwise, they will be loaded in subsequent DB calls due to the EAGER relationship
@EntityGraph(type = LOAD, attributePaths = { "lectures", "lectures.attachments" })
Optional<Course> findWithEagerLecturesById(long courseId);
Expand Down Expand Up @@ -488,11 +485,6 @@ default Course findWithEagerLearningPathsAndLearningPathCompetenciesByIdElseThro
return getValueElseThrow(findWithEagerLearningPathsAndLearningPathCompetencies(courseId), courseId);
}

@NotNull
default Course findWithEagerLearningPathsAndCompetenciesAndPrerequisitesByIdElseThrow(long courseId) {
return getValueElseThrow(findWithEagerLearningPathsAndCompetenciesAndPrerequisitesById(courseId), courseId);
}

Page<Course> findByTitleIgnoreCaseContaining(String partialTitle, Pageable pageable);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,4 @@ public interface DataExportRepository extends ArtemisJpaRepository<DataExport, L
ORDER BY dataExport.createdDate DESC
""")
List<DataExport> findAllDataExportsByUserIdOrderByRequestDateDesc(@Param("userId") long userId);

@Query("""
SELECT dataExport
FROM DataExport dataExport
WHERE dataExport.dataExportState = 2
""")
Set<DataExport> findAllSuccessfullyCreatedDataExports();
}
Loading
Loading