Skip to content

Commit

Permalink
Merge pull request #485 from JoyOfCodingPDX/issue-479/dont-submit-dot…
Browse files Browse the repository at this point in the history
…-gradle

Add a test that validates that .gradle files are not submitted. This fixes #479.
  • Loading branch information
DavidWhitlock authored Nov 21, 2024
2 parents 249f282 + 1cc0dcb commit ad75744
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
package edu.pdx.cs.joy.grader;

import edu.pdx.cs.joy.grader.gradebook.Assignment;
import edu.pdx.cs.joy.grader.gradebook.Grade;
import edu.pdx.cs.joy.grader.gradebook.GradeBook;
import edu.pdx.cs.joy.grader.gradebook.Student;
import jakarta.mail.MessagingException;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;

public class SubmitAndroidProjectIT extends SubmitIT {
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
import static org.hamcrest.Matchers.equalTo;

public class SubmitAndroidProjectIT extends SubmitIT {

@BeforeEach
@Override
Expand All @@ -32,6 +44,8 @@ public void createFilesToSubmit() throws IOException {
this.filesToSubmit.add(createEmptyFile(wrapperDir, fileName));
}

File dotGradleDir = createDirectories(".gradle");
this.filesToSubmit.add(createEmptyFile(dotGradleDir, "config.properties"));
}

@Override
Expand All @@ -45,4 +59,37 @@ protected Submit getSubmitProgram() {
return new SubmitAndroidProject(() -> submitTime);
}
}

@Test
void dotGradleFilesAreNotSubmitted() throws MessagingException, IOException {
submitter().submitFiles();

GradeBook gradeBook = new GradeBook("SubmitIT");
gradeBook.addStudent(new Student(studentLoginId));
gradeBook.addAssignment(new Assignment(projectName, 3.5));

GraderEmailAccount account = new GraderEmailAccount(emailServerHost, imapsPort, graderEmail, imapPassword, true, m -> { });
FetchAndProcessGraderEmail.fetchAndProcessGraderEmails("projects", account, this.tempDirectory, gradeBook);

Grade grade = gradeBook.getStudent(studentLoginId).get().getGrade(projectName);
assertThat(grade, is(notNullValue()));
assertThat(grade.getScore(), equalTo(Grade.NO_GRADE));
assertThat(grade.getSubmissionTimes().size(), equalTo(1));

File zipFile = findNewestZipFileInTempDirectory();
assertThat(zipFile, is(notNullValue()));
List<String> entryNames = getZipFileEntryNames(zipFile);
assertThat(entryNames, not(empty()));

assertThat(entryNames, not(hasItem(".gradle")));
assertThat(entryNames, not(hasItem(".gradle/config.properties")));
}

@Override
protected Collection<File> getExpectedFilesToSubmit() {
Collection<File> allFiles = super.getExpectedFilesToSubmit();
return allFiles.stream()
.filter(file -> !file.getPath().contains(".gradle"))
.toList();
}
}
16 changes: 10 additions & 6 deletions grader/src/it/java/edu/pdx/cs/joy/grader/SubmitIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ public class SubmitIT extends EmailSenderIntegrationTestCase {
private final String studentName = studentFirstName + " " + studentLastName;
protected final Collection<File> filesToSubmit = new ArrayList<>();
protected final String studentLoginId = "student";
private final String projectName = "Project";
private final String graderEmail = TA_EMAIL.getAddress();
protected final String projectName = "Project";
protected final String graderEmail = TA_EMAIL.getAddress();

@BeforeEach
public void createFilesToSubmit() throws IOException {
Expand Down Expand Up @@ -145,13 +145,17 @@ private void assertZipFileContainsFilesInProjectDirectories() throws IOException
List<String> entryNames = getZipFileEntryNames(zipFile);
assertThat(entryNames, not(empty()));

filesToSubmit.forEach(file -> {
getExpectedFilesToSubmit().forEach(file -> {
String filePath = file.getPath().substring(this.tempDirectory.getPath().length() + 1);
assertThat(entryNames, hasItem(filePath));
});
}

private List<String> getZipFileEntryNames(File zipFile) throws IOException {
protected Collection<File> getExpectedFilesToSubmit() {
return filesToSubmit;
}

protected List<String> getZipFileEntryNames(File zipFile) throws IOException {
List<String> entryNames = new ArrayList<>();
FileInputStream stream = new FileInputStream(zipFile);
try (
Expand All @@ -166,7 +170,7 @@ private List<String> getZipFileEntryNames(File zipFile) throws IOException {
return entryNames;
}

private File findNewestZipFileInTempDirectory() {
protected File findNewestZipFileInTempDirectory() {
File[] zipFiles = this.tempDirectory.listFiles((dir, name) -> name.endsWith(".zip"));
if (zipFiles == null) {
return null;
Expand Down Expand Up @@ -201,7 +205,7 @@ public ProjectSubmitter setSendReceipt(boolean sendReceipt) {
return this;
}

private void submitFiles() throws IOException, MessagingException {
protected void submitFiles() throws IOException, MessagingException {
Student student = new Student(studentLoginId);
student.setEmail(studentEmail);
student.setFirstName(studentFirstName);
Expand Down

0 comments on commit ad75744

Please sign in to comment.