Merge branch 'peerSpringDataTests' into develop
This commit is contained in:
commit
63329efe8a
226
src/test/java/se/su/dsv/scipro/springdata/TestPeerReview.java
Normal file
226
src/test/java/se/su/dsv/scipro/springdata/TestPeerReview.java
Normal file
|
@ -0,0 +1,226 @@
|
|||
package se.su.dsv.scipro.springdata;
|
||||
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.annotation.Rollback;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import se.su.dsv.scipro.data.dataobjects.Employee;
|
||||
import se.su.dsv.scipro.data.dataobjects.Project;
|
||||
import se.su.dsv.scipro.data.dataobjects.ProjectClass;
|
||||
import se.su.dsv.scipro.data.dataobjects.ProjectFollower;
|
||||
import se.su.dsv.scipro.data.dataobjects.Student;
|
||||
import se.su.dsv.scipro.data.dataobjects.User;
|
||||
import se.su.dsv.scipro.data.enums.ProjectStatus;
|
||||
import se.su.dsv.scipro.data.enums.ProjectTeamMemberRoles;
|
||||
import se.su.dsv.scipro.peer.data.dataobjects.PeerRequest;
|
||||
import se.su.dsv.scipro.peer.data.dataobjects.PeerReview;
|
||||
import se.su.dsv.scipro.peer.enums.RequestStatus;
|
||||
import se.su.dsv.scipro.springdata.services.PeerRequestService;
|
||||
import se.su.dsv.scipro.springdata.services.PeerReviewService;
|
||||
import se.su.dsv.scipro.springdata.services.ProjectClassService;
|
||||
import se.su.dsv.scipro.springdata.services.ProjectFollowerService;
|
||||
import se.su.dsv.scipro.springdata.services.ProjectService;
|
||||
import se.su.dsv.scipro.springdata.services.RoleService;
|
||||
import se.su.dsv.scipro.springdata.services.UserService;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(inheritLocations = false, locations = {
|
||||
"classpath:test-applicationContext.xml"
|
||||
})
|
||||
public class TestPeerReview {
|
||||
|
||||
@Autowired
|
||||
private ProjectService projectService;
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
@Autowired
|
||||
private ProjectClassService projectClassService;
|
||||
@Autowired
|
||||
private RoleService roleService;
|
||||
@Autowired
|
||||
private PeerReviewService peerReviewService;
|
||||
@Autowired
|
||||
private PeerRequestService peerRequestService;
|
||||
|
||||
private Project reviewerProject, requesterProject;
|
||||
private User employeeUser, reviewer, requester;
|
||||
private Student reviewerRole, requesterRole;
|
||||
private Employee headSupervisor;
|
||||
private ProjectClass bachelor;
|
||||
private ProjectClass master;
|
||||
private PeerReview review1, review2, review3;
|
||||
private PeerRequest request1, request2, request3, awaitingRequest;
|
||||
|
||||
@Before
|
||||
public void startTransaction() throws Exception {
|
||||
|
||||
bachelor = new ProjectClass(ProjectClass.BACHELOR, "Bachelor", "Bachelor degree thesis project");
|
||||
bachelor = projectClassService.save(bachelor);
|
||||
|
||||
master = new ProjectClass(ProjectClass.MASTER, "Master", "Master degree thesis project");
|
||||
master = projectClassService.save(master);
|
||||
|
||||
employeeUser = new User();
|
||||
employeeUser = userService.save(employeeUser);
|
||||
|
||||
reviewer = new User();
|
||||
reviewer = userService.save(reviewer);
|
||||
requester = new User();
|
||||
requester = userService.save(requester);
|
||||
|
||||
reviewerRole = new Student();
|
||||
reviewerRole.setUser(reviewer);
|
||||
reviewerRole = (Student) roleService.save(reviewerRole);
|
||||
requesterRole = new Student();
|
||||
requesterRole.setUser(requester);
|
||||
requesterRole = (Student) roleService.save(requesterRole);
|
||||
|
||||
headSupervisor = new Employee();
|
||||
headSupervisor.setUser(employeeUser);
|
||||
headSupervisor = (Employee) roleService.save(headSupervisor);
|
||||
|
||||
reviewerProject = new Project();
|
||||
reviewerProject.setProjectClass(bachelor);
|
||||
reviewerProject.setTitle("Project 1");
|
||||
reviewerProject.setHeadSupervisor(headSupervisor);
|
||||
reviewerProject.addProjectParticipant(reviewerRole);
|
||||
reviewerProject.setProjectStatus(ProjectStatus.ACTIVE);
|
||||
reviewerProject = projectService.save(reviewerProject);
|
||||
|
||||
requesterProject = new Project();
|
||||
requesterProject.setProjectClass(master);
|
||||
requesterProject.setTitle("Project 2");
|
||||
requesterProject.setHeadSupervisor(headSupervisor);
|
||||
requesterProject.addProjectParticipant(requesterRole);
|
||||
requesterProject.setProjectStatus(ProjectStatus.ACTIVE);
|
||||
requesterProject = projectService.save(requesterProject);
|
||||
|
||||
request1 = new PeerRequest();
|
||||
request1.setComment("Request 1");
|
||||
request1.setRequester(requesterRole);
|
||||
request1.setProject(requesterProject);
|
||||
request1 = peerRequestService.save(request1);
|
||||
|
||||
review1 = new PeerReview();
|
||||
review1.setReviewer(reviewerRole);
|
||||
review1.setProject(reviewerProject);
|
||||
review1.setComment("Overall ok!");
|
||||
review1.setPeerRequest(request1);
|
||||
request1.setStatus(RequestStatus.FINISHED);
|
||||
request1 = peerRequestService.save(request1);
|
||||
review1.setSubmitted(true);
|
||||
review1 = peerReviewService.save(review1);
|
||||
|
||||
request2 = new PeerRequest();
|
||||
request2.setComment("Request 2");
|
||||
request2.setRequester(requesterRole);
|
||||
request2.setProject(requesterProject);
|
||||
request2 = peerRequestService.save(request2);
|
||||
|
||||
review2 = new PeerReview();
|
||||
review2.setReviewer(reviewerRole);
|
||||
review2.setProject(reviewerProject);
|
||||
review2.setComment("Overall ok!");
|
||||
review2.setPeerRequest(request2);
|
||||
request2.setStatus(RequestStatus.FINISHED);
|
||||
request2 = peerRequestService.save(request2);
|
||||
review2.setSubmitted(true);
|
||||
review2 = peerReviewService.save(review2);
|
||||
|
||||
request3 = new PeerRequest();
|
||||
request3.setComment("Request 3");
|
||||
request3.setRequester(requesterRole);
|
||||
request3.setProject(requesterProject);
|
||||
request3 = peerRequestService.save(request3);
|
||||
|
||||
review3 = new PeerReview();
|
||||
review3.setReviewer(reviewerRole);
|
||||
review3.setProject(reviewerProject);
|
||||
review3.setComment("Overall ok!");
|
||||
review3.setPeerRequest(request2);
|
||||
request3.setStatus(RequestStatus.TAKEN);
|
||||
request3 = peerRequestService.save(request3);
|
||||
review3.setSubmitted(false);
|
||||
review3 = peerReviewService.save(review3);
|
||||
|
||||
awaitingRequest = new PeerRequest();
|
||||
awaitingRequest.setComment("Awaiting request");
|
||||
awaitingRequest.setRequester(requesterRole);
|
||||
awaitingRequest.setProject(requesterProject);
|
||||
awaitingRequest.setStatus(RequestStatus.WAITING);
|
||||
awaitingRequest = peerRequestService.save(awaitingRequest);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@Transactional
|
||||
@Rollback
|
||||
public void testFindCompletedReviewsByAuthorAndProject() {
|
||||
List<PeerReview> completedReviews = peerReviewService.findCompletedReviews(reviewerRole, reviewerProject);
|
||||
Assert.assertEquals(2, completedReviews.size());
|
||||
Assert.assertEquals(Arrays.asList(new PeerReview[]{review1,review2}), completedReviews);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Transactional
|
||||
@Rollback
|
||||
public void testFindInProgressReviewsByAuthorAndProject() {
|
||||
List<PeerReview> inProgressReviews = peerReviewService.findInProgressReviews(reviewerRole, reviewerProject);
|
||||
Assert.assertEquals(1, inProgressReviews.size());
|
||||
Assert.assertEquals(Arrays.asList(new PeerReview[]{review3}), inProgressReviews);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Transactional
|
||||
@Rollback
|
||||
public void testFindReceivedCompletedReviewsByProject() {
|
||||
List<PeerReview> receivedCompleted = peerReviewService.findReceivedCompletedReviews(requesterProject);
|
||||
Assert.assertEquals(2, receivedCompleted.size());
|
||||
Assert.assertEquals(Arrays.asList(new PeerReview[]{review1,review2}), receivedCompleted);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Transactional
|
||||
@Rollback
|
||||
public void testFindReceivedInProgressReviewsByProject() {
|
||||
List<PeerReview> receivedInProgress = peerReviewService.findReceivedInProgressReviews(requesterProject);
|
||||
Assert.assertEquals(1, receivedInProgress.size());
|
||||
Assert.assertEquals(Arrays.asList(new PeerReview[]{review3}), receivedInProgress);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Transactional
|
||||
@Rollback
|
||||
public void testCountAbortedReviewsByAuthorAndProject(){
|
||||
Long abortedCount = peerReviewService.countAbortedReviews(reviewerProject, reviewerRole);
|
||||
Long l = new Long(0);
|
||||
Assert.assertEquals(l, abortedCount);
|
||||
|
||||
review3.setAborted(true);
|
||||
abortedCount = peerReviewService.countAbortedReviews(reviewerProject, reviewerRole);
|
||||
Long l2 = new Long(1);
|
||||
Assert.assertEquals(l2, abortedCount);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@Transactional
|
||||
@Rollback
|
||||
public void testFindAwaitingRequestsByProject(){
|
||||
List<PeerRequest> awaitingRequests = peerRequestService.findAwaitingRequests(requesterProject);
|
||||
Assert.assertEquals(1, awaitingRequests.size());
|
||||
Assert.assertEquals(Arrays.asList(new PeerRequest[]{awaitingRequest}), awaitingRequests);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user