2984 Tests for submitting plagiarism analysis

This commit is contained in:
Andreas Svanberg 2023-05-22 14:01:05 +02:00
parent dbf3b1b9ab
commit 4b419ef643

@ -0,0 +1,104 @@
package se.su.dsv.scipro.grading;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.util.file.File;
import org.apache.wicket.util.tester.FormTester;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
import se.su.dsv.scipro.SciProTest;
import se.su.dsv.scipro.file.FileReference;
import se.su.dsv.scipro.finalthesis.FinalThesis;
import se.su.dsv.scipro.finalthesis.RejectFinalThesisPanelTest;
import se.su.dsv.scipro.project.Project;
import se.su.dsv.scipro.system.ProjectType;
import java.net.URISyntaxException;
import java.time.LocalDate;
import java.time.LocalTime;
import java.time.Month;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.Date;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
public class UploadTextMatchingPanelTest extends SciProTest {
public static final ZonedDateTime FINAL_THESIS_APPROVED = ZonedDateTime.of(
LocalDate.of(2023, Month.MAY, 18),
LocalTime.NOON,
ZoneId.systemDefault());
private Project project;
@BeforeEach
public void setUp() {
ProjectType bachelor = new ProjectType(ProjectType.BACHELOR, "Bachelor", "Bachelor");
project = Project.builder()
.title("Project title")
.projectType(bachelor)
.startDate(LocalDate.of(2023, Month.JANUARY, 17))
.build();
}
@Test
public void renders() {
startPanel();
tester.assertComponent("panel", UploadTextMatchingPanel.class);
}
@Test
void shows_form_when_final_thesis_is_approved_but_not_analysis_submitted() {
FinalThesis finalThesis = newFinalThesisWithoutPlagiarismAnalysis();
when(finalThesisService.findByProject(project)).thenReturn(finalThesis);
startPanel();
tester.assertVisible(path("panel", "form"));
tester.assertComponent(path("panel", "form"), Form.class);
}
@Test
public void saves_submitted_plagiarism_analysis() throws URISyntaxException {
String analysis = "No plagiarism detected";
File file = new File(RejectFinalThesisPanelTest.class.getResource("thesis.pdf").toURI());
FileReference textMatchingDocument = new FileReference();
FinalThesis finalThesis = newFinalThesisWithoutPlagiarismAnalysis();
when(finalThesisService.findByProject(project)).thenReturn(finalThesis);
when(fileDescriptionService.storeFile(any())).thenReturn(textMatchingDocument);
startPanel();
FormTester formTester = tester.newFormTester(path("panel", "form"));
formTester.setValue("comment", analysis);
formTester.setFile("textMatchingDocument", file, "application/pdf");
formTester.submit();
ArgumentCaptor<FinalThesis> captor = ArgumentCaptor.forClass(FinalThesis.class);
verify(finalThesisService).save(captor.capture());
assertEquals(analysis, captor.getValue().getTextMatchingAnalysis());
assertEquals(textMatchingDocument, captor.getValue().getTextMatchingDocument());
}
private void startPanel() {
tester.startComponentInPage(new UploadTextMatchingPanel("panel", () -> project));
}
private FinalThesis newFinalThesisWithoutPlagiarismAnalysis() {
FinalThesis finalThesis = new FinalThesis();
finalThesis.setProject(project);
finalThesis.setStatus(FinalThesis.Status.APPROVED);
finalThesis.setDateApproved(Date.from(FINAL_THESIS_APPROVED.toInstant()));
finalThesis.setTextMatchingAnalysis(null);
finalThesis.setTextMatchingDocument(null);
return finalThesis;
}
}