Skip to content

Commit

Permalink
Development: Refactor file upload tests (#9415)
Browse files Browse the repository at this point in the history
  • Loading branch information
MaximilianAnzinger authored Oct 7, 2024
1 parent 2e5ebe5 commit a0f7fd8
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 106 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package de.tum.cit.aet.artemis.fileupload;

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

import de.tum.cit.aet.artemis.assessment.repository.ComplaintRepository;
import de.tum.cit.aet.artemis.assessment.repository.FeedbackRepository;
import de.tum.cit.aet.artemis.assessment.repository.GradingCriterionRepository;
import de.tum.cit.aet.artemis.assessment.util.ComplaintUtilService;
import de.tum.cit.aet.artemis.atlas.competency.util.CompetencyUtilService;
import de.tum.cit.aet.artemis.communication.repository.conversation.ChannelRepository;
import de.tum.cit.aet.artemis.core.util.PageableSearchUtilService;
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.participation.util.ParticipationUtilService;
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;
import de.tum.cit.aet.artemis.fileupload.repository.FileUploadExerciseRepository;
import de.tum.cit.aet.artemis.fileupload.repository.FileUploadSubmissionRepository;
import de.tum.cit.aet.artemis.fileupload.util.FileUploadExerciseUtilService;
import de.tum.cit.aet.artemis.modeling.util.ModelingExerciseUtilService;
import de.tum.cit.aet.artemis.shared.base.AbstractSpringIntegrationIndependentTest;

public class AbstractFileUploadIntegrationTest extends AbstractSpringIntegrationIndependentTest {

// Repositories
@Autowired
protected FileUploadExerciseRepository fileUploadExerciseRepository;

// External Repositories
@Autowired
protected ComplaintRepository complaintRepository;

@Autowired
protected SubmissionTestRepository submissionRepository;

@Autowired
protected ExamRepository examRepository;

@Autowired
protected StudentParticipationTestRepository studentParticipationRepository;

@Autowired
protected FeedbackRepository feedbackRepository;

@Autowired
protected GradingCriterionRepository gradingCriterionRepository;

@Autowired
protected ChannelRepository channelRepository;

@Autowired
protected ParticipationTestRepository participationRepository;

// Services
@Autowired
protected FileUploadSubmissionRepository fileUploadSubmissionRepository;

// Util Services
@Autowired
protected FileUploadExerciseUtilService fileUploadExerciseUtilService;

// External Util Services
@Autowired
protected ParticipationUtilService participationUtilService;

@Autowired
protected ExamUtilService examUtilService;

@Autowired
protected ComplaintUtilService complaintUtilService;

@Autowired
protected PageableSearchUtilService pageableSearchUtilService;

@Autowired
protected CompetencyUtilService competencyUtilService;

@Autowired
protected ModelingExerciseUtilService modelingExerciseUtilService;
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.util.LinkedMultiValueMap;
Expand All @@ -30,65 +29,28 @@
import de.tum.cit.aet.artemis.assessment.domain.FeedbackType;
import de.tum.cit.aet.artemis.assessment.domain.Result;
import de.tum.cit.aet.artemis.assessment.dto.AssessmentUpdateDTO;
import de.tum.cit.aet.artemis.assessment.repository.ComplaintRepository;
import de.tum.cit.aet.artemis.assessment.util.ComplaintUtilService;
import de.tum.cit.aet.artemis.core.config.Constants;
import de.tum.cit.aet.artemis.core.domain.Course;
import de.tum.cit.aet.artemis.exam.domain.Exam;
import de.tum.cit.aet.artemis.exam.domain.ExerciseGroup;
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.domain.IncludedInOverallScore;
import de.tum.cit.aet.artemis.exercise.domain.Submission;
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.ParticipationFactory;
import de.tum.cit.aet.artemis.exercise.participation.util.ParticipationUtilService;
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;
import de.tum.cit.aet.artemis.fileupload.domain.FileUploadSubmission;
import de.tum.cit.aet.artemis.fileupload.dto.FileUploadAssessmentDTO;
import de.tum.cit.aet.artemis.fileupload.repository.FileUploadExerciseRepository;
import de.tum.cit.aet.artemis.fileupload.util.FileUploadExerciseFactory;
import de.tum.cit.aet.artemis.fileupload.util.FileUploadExerciseUtilService;
import de.tum.cit.aet.artemis.programming.dto.ResultDTO;
import de.tum.cit.aet.artemis.shared.base.AbstractSpringIntegrationIndependentTest;

class FileUploadAssessmentIntegrationTest extends AbstractSpringIntegrationIndependentTest {
class FileUploadAssessmentIntegrationTest extends AbstractFileUploadIntegrationTest {

private static final String TEST_PREFIX = "fileuploadassessment";

public static final String API_FILE_UPLOAD_SUBMISSIONS = "/api/file-upload-submissions/";

@Autowired
private ComplaintRepository complaintRepo;

@Autowired
private FileUploadExerciseRepository fileUploadExerciseRepository;

@Autowired
private SubmissionTestRepository submissionRepository;

@Autowired
private ExamRepository examRepository;

@Autowired
private StudentParticipationTestRepository studentParticipationRepository;

@Autowired
private FileUploadExerciseUtilService fileUploadExerciseUtilService;

@Autowired
private ParticipationUtilService participationUtilService;

@Autowired
private ExamUtilService examUtilService;

@Autowired
private ComplaintUtilService complaintUtilService;

private FileUploadExercise afterReleaseFileUploadExercise;

private Course course;
Expand Down Expand Up @@ -206,7 +168,7 @@ void testUpdateFileUploadAssessmentAfterComplaint_studentHidden() throws Excepti
Result fileUploadAssessment = fileUploadSubmission.getLatestResult();
Complaint complaint = new Complaint().result(fileUploadAssessment).complaintText("This is not fair");

complaint = complaintRepo.save(complaint);
complaint = complaintRepository.save(complaint);
complaint.getResult().setParticipation(null); // Break infinite reference chain

ComplaintResponse complaintResponse = complaintUtilService.createInitialEmptyResponse(TEST_PREFIX + "tutor2", complaint);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,76 +25,34 @@
import org.junit.jupiter.params.provider.ArgumentsSource;
import org.junit.jupiter.params.provider.NullSource;
import org.junit.jupiter.params.provider.ValueSource;
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.assessment.domain.Feedback;
import de.tum.cit.aet.artemis.assessment.domain.GradingCriterion;
import de.tum.cit.aet.artemis.assessment.domain.GradingInstruction;
import de.tum.cit.aet.artemis.assessment.domain.Result;
import de.tum.cit.aet.artemis.assessment.repository.FeedbackRepository;
import de.tum.cit.aet.artemis.assessment.repository.GradingCriterionRepository;
import de.tum.cit.aet.artemis.assessment.util.GradingCriterionUtil;
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.communication.domain.conversation.Channel;
import de.tum.cit.aet.artemis.communication.repository.conversation.ChannelRepository;
import de.tum.cit.aet.artemis.core.domain.Course;
import de.tum.cit.aet.artemis.core.dto.CourseForDashboardDTO;
import de.tum.cit.aet.artemis.core.dto.SearchResultPageDTO;
import de.tum.cit.aet.artemis.core.util.PageableSearchUtilService;
import de.tum.cit.aet.artemis.exam.domain.ExerciseGroup;
import de.tum.cit.aet.artemis.exam.util.ExamUtilService;
import de.tum.cit.aet.artemis.exam.util.InvalidExamExerciseDatesArgumentProvider;
import de.tum.cit.aet.artemis.exam.util.InvalidExamExerciseDatesArgumentProvider.InvalidExamExerciseDateConfiguration;
import de.tum.cit.aet.artemis.exercise.domain.Exercise;
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.ParticipationFactory;
import de.tum.cit.aet.artemis.exercise.participation.util.ParticipationUtilService;
import de.tum.cit.aet.artemis.exercise.test_repository.StudentParticipationTestRepository;
import de.tum.cit.aet.artemis.fileupload.domain.FileUploadExercise;
import de.tum.cit.aet.artemis.fileupload.domain.FileUploadSubmission;
import de.tum.cit.aet.artemis.fileupload.repository.FileUploadExerciseRepository;
import de.tum.cit.aet.artemis.fileupload.util.FileUploadExerciseFactory;
import de.tum.cit.aet.artemis.fileupload.util.FileUploadExerciseUtilService;
import de.tum.cit.aet.artemis.shared.base.AbstractSpringIntegrationIndependentTest;

class FileUploadExerciseIntegrationTest extends AbstractSpringIntegrationIndependentTest {
class FileUploadExerciseIntegrationTest extends AbstractFileUploadIntegrationTest {

private static final String TEST_PREFIX = "fileuploaderxercise";

@Autowired
private FeedbackRepository feedbackRepository;

@Autowired
private GradingCriterionRepository gradingCriterionRepository;

@Autowired
private FileUploadExerciseRepository fileUploadExerciseRepository;

@Autowired
private StudentParticipationTestRepository studentParticipationRepository;

@Autowired
private ChannelRepository channelRepository;

@Autowired
private FileUploadExerciseUtilService fileUploadExerciseUtilService;

@Autowired
private ExamUtilService examUtilService;

@Autowired
private ParticipationUtilService participationUtilService;

@Autowired
private PageableSearchUtilService pageableSearchUtilService;

@Autowired
private CompetencyUtilService competencyUtilService;

private FileUploadExercise fileUploadExercise;

private Course course;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.mock.web.MockMultipartFile;
Expand All @@ -38,36 +37,15 @@
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.ParticipationFactory;
import de.tum.cit.aet.artemis.exercise.participation.util.ParticipationUtilService;
import de.tum.cit.aet.artemis.exercise.test_repository.ParticipationTestRepository;
import de.tum.cit.aet.artemis.fileupload.domain.FileUploadExercise;
import de.tum.cit.aet.artemis.fileupload.domain.FileUploadSubmission;
import de.tum.cit.aet.artemis.fileupload.repository.FileUploadSubmissionRepository;
import de.tum.cit.aet.artemis.fileupload.util.FileUploadExerciseUtilService;
import de.tum.cit.aet.artemis.modeling.domain.ModelingExercise;
import de.tum.cit.aet.artemis.modeling.domain.ModelingSubmission;
import de.tum.cit.aet.artemis.modeling.util.ModelingExerciseUtilService;
import de.tum.cit.aet.artemis.shared.base.AbstractSpringIntegrationIndependentTest;

class FileUploadSubmissionIntegrationTest extends AbstractSpringIntegrationIndependentTest {
class FileUploadSubmissionIntegrationTest extends AbstractFileUploadIntegrationTest {

private static final String TEST_PREFIX = "fileuploadsubmission";

@Autowired
private FileUploadSubmissionRepository fileUploadSubmissionRepository;

@Autowired
private ParticipationTestRepository participationRepository;

@Autowired
private FileUploadExerciseUtilService fileUploadExerciseUtilService;

@Autowired
private ParticipationUtilService participationUtilService;

@Autowired
private ModelingExerciseUtilService modelingExerciseUtilService;

private FileUploadExercise releasedFileUploadExercise;

private FileUploadExercise finishedFileUploadExercise;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package de.tum.cit.aet.artemis.fileupload.architecture;

import de.tum.cit.aet.artemis.fileupload.AbstractFileUploadIntegrationTest;
import de.tum.cit.aet.artemis.shared.architecture.module.AbstractModuleTestArchitectureTest;

class FileUploadTestArchitectureTest extends AbstractModuleTestArchitectureTest<AbstractFileUploadIntegrationTest> {

@Override
public String getModulePackage() {
return ARTEMIS_PACKAGE + ".fileupload";
}

@Override
protected Class<AbstractFileUploadIntegrationTest> getAbstractModuleIntegrationTestClass() {
return AbstractFileUploadIntegrationTest.class;
}
}

0 comments on commit a0f7fd8

Please sign in to comment.