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: Refactor atlas tests #9352

Merged
merged 61 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 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
591feae
add AbstractAtlasIntegrationTest
MaximilianAnzinger Sep 21, 2024
31ec22b
add arch test to ensure abstract integration test inheritance
MaximilianAnzinger Sep 21, 2024
f861722
Merge branch 'develop' into chore/restructure-tests
MaximilianAnzinger Sep 23, 2024
c889957
add integration test to prevent autowire in integrationt test impleme…
MaximilianAnzinger Sep 27, 2024
a4d4947
Merge branch 'develop' into chore/restructure-tests
MaximilianAnzinger Sep 28, 2024
d3ad9a2
Merge branch 'chore/restructure-tests' into chore/refactor-atlas-tests
MaximilianAnzinger Sep 28, 2024
3f77991
Merge branch 'develop' into chore/restructure-tests
MaximilianAnzinger Sep 28, 2024
74556c5
Merge branch 'chore/restructure-tests' into chore/refactor-atlas-tests
MaximilianAnzinger Sep 28, 2024
b5a7d6c
merge develop
MaximilianAnzinger Sep 28, 2024
ccebd40
fix import
MaximilianAnzinger Sep 28, 2024
b35ee1f
remove useless empty line
MaximilianAnzinger Sep 28, 2024
9f0ae88
Merge branch 'develop' into chore/refactor-atlas-tests
MaximilianAnzinger Sep 28, 2024
f8df0fd
Merge branch 'develop' into chore/refactor-atlas-tests
MaximilianAnzinger Sep 29, 2024
2bd438d
Merge branch 'develop' into chore/refactor-atlas-tests
MaximilianAnzinger Sep 29, 2024
62a76c6
Merge branch 'develop' into chore/refactor-atlas-tests
MaximilianAnzinger Oct 1, 2024
28b9ce4
use test repos
MaximilianAnzinger Oct 1, 2024
4963195
Merge branch 'develop' into chore/refactor-atlas-tests
MaximilianAnzinger Oct 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
package de.tum.cit.aet.artemis.atlas;

import org.springframework.beans.factory.annotation.Autowired;

import de.tum.cit.aet.artemis.assessment.repository.GradingCriterionRepository;
import de.tum.cit.aet.artemis.assessment.util.StudentScoreUtilService;
import de.tum.cit.aet.artemis.atlas.competency.util.CompetencyProgressUtilService;
import de.tum.cit.aet.artemis.atlas.competency.util.CompetencyUtilService;
import de.tum.cit.aet.artemis.atlas.competency.util.PrerequisiteUtilService;
import de.tum.cit.aet.artemis.atlas.competency.util.StandardizedCompetencyUtilService;
import de.tum.cit.aet.artemis.atlas.learningpath.util.LearningPathUtilService;
import de.tum.cit.aet.artemis.atlas.repository.CompetencyJolRepository;
import de.tum.cit.aet.artemis.atlas.repository.CompetencyRelationRepository;
import de.tum.cit.aet.artemis.atlas.repository.CompetencyRepository;
import de.tum.cit.aet.artemis.atlas.repository.CourseCompetencyRepository;
import de.tum.cit.aet.artemis.atlas.repository.KnowledgeAreaRepository;
import de.tum.cit.aet.artemis.atlas.repository.PrerequisiteRepository;
import de.tum.cit.aet.artemis.atlas.repository.ScienceSettingRepository;
import de.tum.cit.aet.artemis.atlas.repository.SourceRepository;
import de.tum.cit.aet.artemis.atlas.repository.StandardizedCompetencyRepository;
import de.tum.cit.aet.artemis.atlas.service.competency.CompetencyProgressService;
import de.tum.cit.aet.artemis.atlas.test_repository.CompetencyProgressTestRepository;
import de.tum.cit.aet.artemis.atlas.test_repository.LearningPathTestRepository;
import de.tum.cit.aet.artemis.atlas.test_repository.ScienceEventTestRepository;
import de.tum.cit.aet.artemis.core.service.feature.FeatureToggleService;
import de.tum.cit.aet.artemis.core.util.PageableSearchUtilService;
import de.tum.cit.aet.artemis.exercise.participation.util.ParticipationUtilService;
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.SubmissionTestRepository;
import de.tum.cit.aet.artemis.lecture.repository.AttachmentUnitRepository;
import de.tum.cit.aet.artemis.lecture.repository.ExerciseUnitRepository;
import de.tum.cit.aet.artemis.lecture.repository.LectureRepository;
import de.tum.cit.aet.artemis.lecture.repository.LectureUnitRepository;
import de.tum.cit.aet.artemis.lecture.repository.TextUnitRepository;
import de.tum.cit.aet.artemis.lecture.service.LectureUnitService;
import de.tum.cit.aet.artemis.lecture.util.LectureUtilService;
import de.tum.cit.aet.artemis.programming.repository.ProgrammingExerciseBuildConfigRepository;
import de.tum.cit.aet.artemis.programming.test_repository.ProgrammingExerciseTestRepository;
import de.tum.cit.aet.artemis.shared.base.AbstractSpringIntegrationIndependentTest;
import de.tum.cit.aet.artemis.text.util.TextExerciseUtilService;

public abstract class AbstractAtlasIntegrationTest extends AbstractSpringIntegrationIndependentTest {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick (assertive)

Add JavaDoc comment to the class definition

Consider adding a JavaDoc comment to the AbstractAtlasIntegrationTest class to describe its purpose and usage. This will enhance code readability and help other developers understand the intent of this abstract test class.


// Repositories
@Autowired
protected CompetencyRepository competencyRepository;

@Autowired
protected CourseCompetencyRepository courseCompetencyRepository;

@Autowired
protected CompetencyRelationRepository competencyRelationRepository;

@Autowired
protected CompetencyProgressTestRepository competencyProgressRepository;

@Autowired
protected KnowledgeAreaRepository knowledgeAreaRepository;

@Autowired
protected StandardizedCompetencyRepository standardizedCompetencyRepository;

@Autowired
protected SourceRepository sourceRepository;

@Autowired
protected LearningPathTestRepository learningPathRepository;

@Autowired
protected ScienceSettingRepository scienceSettingRepository;

@Autowired
protected ScienceEventTestRepository scienceEventRepository;

@Autowired
protected PrerequisiteRepository prerequisiteRepository;

@Autowired
protected CompetencyJolRepository competencyJolRepository;

// External Repositories
@Autowired
protected LectureRepository lectureRepository;

@Autowired
protected LectureUnitRepository lectureUnitRepository;

@Autowired
protected GradingCriterionRepository gradingCriterionRepository;

@Autowired
protected TextUnitRepository textUnitRepository;

@Autowired
protected AttachmentUnitRepository attachmentUnitRepository;

@Autowired
protected ExerciseUnitRepository exerciseUnitRepository;

@Autowired
protected SubmissionTestRepository submissionRepository;

@Autowired
protected ProgrammingExerciseTestRepository programmingExerciseRepository;

@Autowired
protected ProgrammingExerciseBuildConfigRepository programmingExerciseBuildConfigRepository;

// Services

@Autowired
protected CompetencyProgressService competencyProgressService;

@Autowired
protected FeatureToggleService featureToggleService;

// External Services
@Autowired
protected LectureUnitService lectureUnitService;

@Autowired
protected ParticipationService participationService;

// Util Services
@Autowired
protected CompetencyProgressUtilService competencyProgressUtilService;

@Autowired
protected CompetencyUtilService competencyUtilService;

@Autowired
protected PrerequisiteUtilService prerequisiteUtilService;

@Autowired
protected StandardizedCompetencyUtilService standardizedCompetencyUtilService;

@Autowired
protected LearningPathUtilService learningPathUtilService;

// External Util Services
@Autowired
protected PageableSearchUtilService pageableSearchUtilService;

@Autowired
protected TextExerciseUtilService textExerciseUtilService;

@Autowired
protected LectureUtilService lectureUtilService;

@Autowired
protected StudentScoreUtilService studentScoreUtilService;

@Autowired
protected ParticipationUtilService participationUtilService;

@Autowired
protected TeamUtilService teamUtilService;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package de.tum.cit.aet.artemis.atlas.architecture;

import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.classes;
import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.noMembers;

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;

import de.tum.cit.aet.artemis.atlas.AbstractAtlasIntegrationTest;
import de.tum.cit.aet.artemis.shared.architecture.AbstractArchitectureTest;

class TestArchitectureTest extends AbstractArchitectureTest {

@Test
void integrationTestsShouldExtendAbstractAtlasIntegrationTest() {
classes().that().resideInAPackage(ARTEMIS_PACKAGE + ".atlas").and().haveSimpleNameEndingWith("IntegrationTest").should().beAssignableTo(AbstractAtlasIntegrationTest.class)
.because("All integration tests should extend AbstractAtlasIntegrationTest").check(testClasses);
}
MaximilianAnzinger marked this conversation as resolved.
Show resolved Hide resolved
MaximilianAnzinger marked this conversation as resolved.
Show resolved Hide resolved

@Test
void integrationTestsShouldNotAutowireMembers() {
noMembers().that().areAnnotatedWith(Autowired.class).should().beDeclaredInClassesThat().areAssignableTo(AbstractAtlasIntegrationTest.class).andShould()
.notBeDeclaredIn(AbstractAtlasIntegrationTest.class)
.because("Integration tests should not autowire members in any class that inherits from AbstractAtlasIntegrationTest").check(testClasses);
}
MaximilianAnzinger marked this conversation as resolved.
Show resolved Hide resolved
MaximilianAnzinger marked this conversation as resolved.
Show resolved Hide resolved
}
MaximilianAnzinger marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,16 @@
import java.util.function.Function;
import java.util.stream.Collectors;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;

import de.tum.cit.aet.artemis.atlas.competency.util.CompetencyProgressUtilService;
import de.tum.cit.aet.artemis.atlas.competency.util.PrerequisiteUtilService;
import de.tum.cit.aet.artemis.atlas.competency.util.StandardizedCompetencyUtilService;
import de.tum.cit.aet.artemis.atlas.AbstractAtlasIntegrationTest;
import de.tum.cit.aet.artemis.atlas.domain.competency.CompetencyRelation;
import de.tum.cit.aet.artemis.atlas.domain.competency.CompetencyTaxonomy;
import de.tum.cit.aet.artemis.atlas.domain.competency.CourseCompetency;
import de.tum.cit.aet.artemis.atlas.domain.competency.Prerequisite;
import de.tum.cit.aet.artemis.atlas.domain.competency.RelationType;
import de.tum.cit.aet.artemis.atlas.dto.CompetencyImportResponseDTO;
import de.tum.cit.aet.artemis.atlas.dto.CompetencyWithTailRelationDTO;
import de.tum.cit.aet.artemis.atlas.repository.CompetencyRelationRepository;
import de.tum.cit.aet.artemis.atlas.repository.CourseCompetencyRepository;
import de.tum.cit.aet.artemis.atlas.repository.PrerequisiteRepository;
import de.tum.cit.aet.artemis.core.domain.Course;
import de.tum.cit.aet.artemis.core.domain.DomainObject;
import de.tum.cit.aet.artemis.core.domain.User;
Expand All @@ -39,53 +33,10 @@
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.domain.TextUnit;
import de.tum.cit.aet.artemis.lecture.repository.AttachmentUnitRepository;
import de.tum.cit.aet.artemis.lecture.repository.ExerciseUnitRepository;
import de.tum.cit.aet.artemis.lecture.repository.LectureRepository;
import de.tum.cit.aet.artemis.lecture.repository.LectureUnitRepository;
import de.tum.cit.aet.artemis.lecture.repository.TextUnitRepository;
import de.tum.cit.aet.artemis.lecture.util.LectureUtilService;
import de.tum.cit.aet.artemis.shared.base.AbstractSpringIntegrationLocalCILocalVCTest;
import de.tum.cit.aet.artemis.text.domain.TextExercise;
import de.tum.cit.aet.artemis.text.util.TextExerciseFactory;

abstract class AbstractCompetencyPrerequisiteIntegrationTest extends AbstractSpringIntegrationLocalCILocalVCTest {

@Autowired
protected LectureRepository lectureRepository;

@Autowired
protected TextUnitRepository textUnitRepository;

@Autowired
protected AttachmentUnitRepository attachmentUnitRepository;

@Autowired
protected ExerciseUnitRepository exerciseUnitRepository;

@Autowired
protected CompetencyRelationRepository competencyRelationRepository;

@Autowired
protected PrerequisiteRepository prerequisiteRepository;

@Autowired
protected LectureUnitRepository lectureUnitRepository;

@Autowired
protected PrerequisiteUtilService prerequisiteUtilService;

@Autowired
protected CompetencyProgressUtilService competencyProgressUtilService;

@Autowired
protected LectureUtilService lectureUtilService;

@Autowired
protected StandardizedCompetencyUtilService standardizedCompetencyUtilService;

@Autowired
protected CourseCompetencyRepository courseCompetencyRepository;
abstract class AbstractCompetencyPrerequisiteIntegrationTest extends AbstractAtlasIntegrationTest {
MaximilianAnzinger marked this conversation as resolved.
Show resolved Hide resolved

protected Course course;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.EnumSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.security.test.context.support.WithMockUser;

import de.tum.cit.aet.artemis.atlas.competency.util.CompetencyUtilService;
import de.tum.cit.aet.artemis.atlas.domain.competency.Competency;
import de.tum.cit.aet.artemis.atlas.domain.competency.CourseCompetency;
import de.tum.cit.aet.artemis.atlas.dto.CompetencyImportResponseDTO;
Expand All @@ -24,9 +22,6 @@ class CompetencyIntegrationTest extends AbstractCompetencyPrerequisiteIntegratio

private static final String TEST_PREFIX = "competencyintegrationtest";

@Autowired
private CompetencyUtilService competencyUtilService;

@BeforeEach
void setupTestScenario() {
super.setupTestScenario(TEST_PREFIX, competencyUtilService::createCompetency);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,19 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.security.test.context.support.WithMockUser;

import de.tum.cit.aet.artemis.atlas.competency.util.CompetencyProgressUtilService;
import de.tum.cit.aet.artemis.atlas.competency.util.CompetencyUtilService;
import de.tum.cit.aet.artemis.atlas.AbstractAtlasIntegrationTest;
import de.tum.cit.aet.artemis.atlas.domain.competency.Competency;
import de.tum.cit.aet.artemis.atlas.domain.competency.CompetencyProgress;
import de.tum.cit.aet.artemis.atlas.dto.CompetencyJolPairDTO;
import de.tum.cit.aet.artemis.atlas.repository.CompetencyJolRepository;
import de.tum.cit.aet.artemis.core.domain.User;
import de.tum.cit.aet.artemis.shared.base.AbstractSpringIntegrationIndependentTest;

class CompetencyJolIntegrationTest extends AbstractSpringIntegrationIndependentTest {
class CompetencyJolIntegrationTest extends AbstractAtlasIntegrationTest {

private static final String TEST_PREFIX = "competencyjolintegrationtest";

@Autowired
private CompetencyUtilService competencyUtilService;

@Autowired
private CompetencyProgressUtilService competencyProgressUtilService;

@Autowired
private CompetencyJolRepository competencyJOLRepository;

private final Competency[] competency = new Competency[3];

private CompetencyProgress competencyProgress;
Expand Down Expand Up @@ -63,7 +50,7 @@ void setup() {

@AfterEach
void tearDown() {
competencyJOLRepository.deleteAll();
competencyJolRepository.deleteAll();
}

@Nested
Expand Down Expand Up @@ -100,7 +87,7 @@ void shouldReturnForbiddenForStudentNotInCourse() throws Exception {
void shouldCreateJOL() throws Exception {
short jolValue = 3;
sendRequest(competency[0].getId(), jolValue, HttpStatus.OK);
final var jol = competencyJOLRepository.findLatestByCompetencyIdAndUserId(competency[0].getId(), student.getId());
final var jol = competencyJolRepository.findLatestByCompetencyIdAndUserId(competency[0].getId(), student.getId());
assertThat(jol).isPresent();
assertThat(jol.get().getValue()).isEqualTo(jolValue);
assertThat(jol.get().getCompetencyConfidence()).isEqualTo(competencyProgress.getConfidence());
Expand All @@ -113,7 +100,7 @@ void shouldUpdateJOL() throws Exception {
competencyUtilService.createJol(competency[0], student, (short) 123, ZonedDateTime.now().minusDays(1), 0.0, 0.0);
short jolValue = 3;
sendRequest(competency[0].getId(), jolValue, HttpStatus.OK);
final var jol = competencyJOLRepository.findLatestByCompetencyIdAndUserId(competency[0].getId(), student.getId());
final var jol = competencyJolRepository.findLatestByCompetencyIdAndUserId(competency[0].getId(), student.getId());
assertThat(jol).isPresent();
assertThat(jol.get().getValue()).isEqualTo(jolValue);
assertThat(jol.get().getCompetencyConfidence()).isEqualTo(competencyProgress.getConfidence());
Expand Down
Loading
Loading