87: Integration test in progress
This commit is contained in:
parent
185785582a
commit
195e7f3bfb
156
core/src/test/java/se/su/dsv/scipro/project/split/SplitOrRestartProjectServiceIntegrationTest.java
156
core/src/test/java/se/su/dsv/scipro/project/split/SplitOrRestartProjectServiceIntegrationTest.java
@ -1,16 +1,28 @@
|
||||
package se.su.dsv.scipro.project.split;
|
||||
|
||||
import jakarta.inject.Inject;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import se.su.dsv.scipro.file.FileUpload;
|
||||
import se.su.dsv.scipro.project.Project;
|
||||
import se.su.dsv.scipro.project.ProjectStatus;
|
||||
import se.su.dsv.scipro.reviewing.ReviewerAssignmentService;
|
||||
import se.su.dsv.scipro.reviewing.RoughDraftApproval;
|
||||
import se.su.dsv.scipro.reviewing.RoughDraftApprovalService;
|
||||
import se.su.dsv.scipro.security.auth.roles.Roles;
|
||||
import se.su.dsv.scipro.system.DegreeType;
|
||||
import se.su.dsv.scipro.system.ProjectType;
|
||||
import se.su.dsv.scipro.system.ResearchArea;
|
||||
import se.su.dsv.scipro.system.User;
|
||||
import se.su.dsv.scipro.test.IntegrationTest;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.time.LocalDate;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static se.su.dsv.scipro.project.split.SplitOrRestartProjectService.SplittableStatus;
|
||||
@ -20,6 +32,13 @@ public class SplitOrRestartProjectServiceIntegrationTest extends IntegrationTest
|
||||
@Inject
|
||||
private SplitOrRestartProjectService sorpService;
|
||||
|
||||
@Inject
|
||||
private RoughDraftApprovalService rdaService;
|
||||
|
||||
@Inject
|
||||
private ReviewerAssignmentService raService;
|
||||
|
||||
private ResearchArea researchArea;
|
||||
private Project parentProject;
|
||||
private User supervisor;
|
||||
private User reviwer;
|
||||
@ -28,15 +47,13 @@ public class SplitOrRestartProjectServiceIntegrationTest extends IntegrationTest
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
ProjectType bachelor = createProjectType();
|
||||
this.parentProject = createProject(bachelor, ProjectStatus.ACTIVE);
|
||||
/*
|
||||
user = createUser();
|
||||
Unit unit = new Unit();
|
||||
unit.setTitle("DSV IT");
|
||||
user.setUnit(save(unit));
|
||||
ProjectType bachelor = save (new ProjectType(DegreeType.BACHELOR, "Bachelor", "Bachelor"));
|
||||
|
||||
*/
|
||||
researchArea = new ResearchArea();
|
||||
researchArea.setTitle("Computer Science");
|
||||
researchArea = save(researchArea);
|
||||
|
||||
parentProject = createProject(bachelor, ProjectStatus.ACTIVE);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -58,31 +75,128 @@ public class SplitOrRestartProjectServiceIntegrationTest extends IntegrationTest
|
||||
assertTrue(status == SplittableStatus.NOT_ACTIVE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void project_must_have_two_participants() {
|
||||
SplittableStatusRecord record = sorpService.getSplittableStatus(parentProject.getId());
|
||||
SplittableStatus status = record.splittableStatus();
|
||||
|
||||
|
||||
private ProjectType createProjectType() {
|
||||
ProjectType projectType = new ProjectType(DegreeType.BACHELOR, "Bachelor", "Bachelor");
|
||||
save(projectType);
|
||||
return projectType;
|
||||
assertTrue(status == SplittableStatus.NOT_TWO_PARTICIPANTS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void project_phase_two_started() {
|
||||
setUpBeforePhaseTwo();
|
||||
|
||||
SplittableStatusRecord record = sorpService.getSplittableStatus(parentProject.getId());
|
||||
SplittableStatus status = record.splittableStatus();
|
||||
|
||||
assertTrue(status == SplittableStatus.PHASE_TWO_STARTED);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void split_on_failed_phase_two() {
|
||||
setUpBeforePhaseTwo();
|
||||
|
||||
Optional<RoughDraftApproval> optional = this.rdaService.findBy(parentProject);
|
||||
optional.ifPresent(rda -> rda.reject("Fail", Optional.empty()));
|
||||
|
||||
SplittableStatusRecord record = sorpService.getSplittableStatus(parentProject.getId());
|
||||
SplittableStatus status = record.splittableStatus();
|
||||
|
||||
assertTrue(status == SplittableStatus.OK);
|
||||
|
||||
sorpService.splitProject(parentProject.getId());
|
||||
List<Project> childProjects = sorpService.getChildProjects(parentProject.getId());
|
||||
|
||||
assertTrue(parentProject.getProjectStatus() == ProjectStatus.INACTIVE);
|
||||
assertTrue(childProjects.size() == 2);
|
||||
childProjects.forEach(project -> {
|
||||
assertTrue(project.getProjectParticipants().size() == 1);
|
||||
assertTrue(project.getHeadSupervisor().equals(supervisor));
|
||||
assertTrue(project.getProjectStatus() == ProjectStatus.ACTIVE);
|
||||
});
|
||||
}
|
||||
|
||||
/*
|
||||
PHASE_TWO_STARTED,
|
||||
FINAL_SEMINAR_PHASE_STARTED,
|
||||
OK,
|
||||
*/
|
||||
|
||||
private Project createProject(ProjectType projectType, ProjectStatus active) {
|
||||
User headSupervisor = save(
|
||||
User.builder().firstName("John").lastName("Doe").emailAddress("john@example.com").build()
|
||||
);
|
||||
supervisor = createEmployee("Eric", "Employee", "eric@example.com", false);
|
||||
|
||||
Project project = new Project();
|
||||
project.setTitle("Some title");
|
||||
project.setProjectType(projectType);
|
||||
project.setProjectStatus(active);
|
||||
project.setHeadSupervisor(headSupervisor);
|
||||
project.setHeadSupervisor(supervisor);
|
||||
project.setStartDate(LocalDate.now());
|
||||
|
||||
author1 = createUser("Adam", "Student", "adam.student@example.com");
|
||||
project.addProjectParticipant(author1);
|
||||
|
||||
project = save(project);
|
||||
System.out.println(project);
|
||||
return project;
|
||||
}
|
||||
|
||||
private User createUser() {
|
||||
User user = User.builder().firstName("Bob").lastName("Sponge").emailAddress("bob@example.com").build();
|
||||
private User createEmployee(String firstName, String lastName, String email, boolean isReviewer) {
|
||||
User employee = createUser(firstName, lastName, email);
|
||||
|
||||
Set<ResearchArea> researchAreas = new HashSet<>();
|
||||
researchAreas.add(researchArea);
|
||||
employee.setResearchAreas(researchAreas);
|
||||
|
||||
if (isReviewer) {
|
||||
employee.addRole(Roles.REVIEWER);
|
||||
}
|
||||
|
||||
save(employee);
|
||||
return employee;
|
||||
}
|
||||
|
||||
private User createUser(String firstName, String lastName, String email) {
|
||||
User user = User.builder().firstName(firstName).lastName(lastName).emailAddress(email).build();
|
||||
return save(user);
|
||||
}
|
||||
|
||||
private void setUpBeforePhaseTwo() {
|
||||
author2 = createUser("Bertil", "Student", "bertil.student@example.com");
|
||||
parentProject.addProjectParticipant(author2);
|
||||
save(parentProject);
|
||||
|
||||
rdaService.requestApproval(parentProject, dummyFile(), "comment");
|
||||
|
||||
reviwer = createEmployee("Lisa", "Employee", "lisa.employee@example.com", true);
|
||||
ReviewerAssignmentService.ReviewerAssignment reviewerAssignment = raService.assignReviewer(parentProject, reviwer);
|
||||
}
|
||||
|
||||
private FileUpload dummyFile() {
|
||||
return new FileUpload() {
|
||||
@Override
|
||||
public String getFileName() {
|
||||
return "dummy.tmp";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getContentType() {
|
||||
return "text/plain";
|
||||
}
|
||||
|
||||
@Override
|
||||
public User getUploader() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getSize() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T handleData(Function<InputStream, T> handler) {
|
||||
return handler.apply(InputStream.nullInputStream());
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user