Skip to content

Commit

Permalink
Improve test setup; add assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
pzdr7 committed May 19, 2024
1 parent 0f80bf6 commit 4f5e7e0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package de.tum.in.www1.artemis.hestia;

import static org.assertj.core.api.Assertions.assertThat;

import java.time.ZonedDateTime;

import org.junit.jupiter.api.AfterEach;
Expand All @@ -12,6 +14,7 @@
import de.tum.in.www1.artemis.course.CourseUtilService;
import de.tum.in.www1.artemis.domain.Course;
import de.tum.in.www1.artemis.domain.ProgrammingExercise;
import de.tum.in.www1.artemis.domain.hestia.ProgrammingExerciseGitDiffEntry;
import de.tum.in.www1.artemis.domain.hestia.ProgrammingExerciseGitDiffReport;
import de.tum.in.www1.artemis.exercise.programming.ProgrammingExerciseFactory;
import de.tum.in.www1.artemis.localvcci.AbstractLocalCILocalVCIntegrationTest;
Expand Down Expand Up @@ -143,9 +146,15 @@ void getGitDiffReportForCommitsWithRenamedFile() throws Exception {
var studentLogin = TEST_PREFIX + "student1";
var submission = hestiaUtilTestService.setupSubmission(FILE_NAME, fileContent, exercise, participationRepo, studentLogin);
// Simulate a renaming by deleting the file and creating a new one with the same content. Git will track this as long as the content is similar enough.
var submission2 = hestiaUtilTestService.deleteFileAndSetupSubmission(FILE_NAME, FILE_NAME + "-renamed", fileContent, exercise, participationRepo, studentLogin);
request.get("/api/programming-exercises/" + exercise.getId() + "/commits/" + submission.getCommitHash() + "/diff-report/" + submission2.getCommitHash()
var submission2 = hestiaUtilTestService.deleteFileAndSetupSubmission(FILE_NAME, FILE_NAME2, fileContent, exercise, participationRepo, studentLogin);
var report = request.get("/api/programming-exercises/" + exercise.getId() + "/commits/" + submission.getCommitHash() + "/diff-report/" + submission2.getCommitHash()
+ "?participationId=" + submission.getParticipation().getId(), HttpStatus.OK, ProgrammingExerciseGitDiffReport.class);
var entries = report.getEntries();
assertThat(entries.size()).isEqualTo(1);
ProgrammingExerciseGitDiffEntry entry = entries.iterator().next();
assertThat(entry.getPreviousFilePath()).isEqualTo(FILE_NAME);
assertThat(entry.getFilePath()).isEqualTo(FILE_NAME2);
assertThat(entry.isEmpty()).isTrue();
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ public ProgrammingSubmission deleteFileAndSetupSubmission(String oldFileName, St
LocalRepository participationRepo, String login) throws Exception {
Path oldFilePath = Path.of(participationRepo.localRepoFile + "/" + oldFileName);
Files.delete(oldFilePath);
// Ensure JGit realizes the file has been removed
participationRepo.localGit.rm().addFilepattern(oldFileName).call();
return setupSubmission(newFileName, content, exercise, participationRepo, login);
}

Expand Down

0 comments on commit 4f5e7e0

Please sign in to comment.