added new test methods for availability and author-project ideas datatable to make sure you only see ideas of capable supervisors
This commit is contained in:
parent
0a52473b4f
commit
1eb7523484
src
main/java/se/su/dsv/scipro
project/panels
springdata
test/java/se/su/dsv/scipro/springdata
@ -74,7 +74,7 @@ public class ProjectIdeaOverviewPanel extends Panel {
|
||||
|
||||
@Override
|
||||
public Iterator<SupervisorIdea> getIterator() {
|
||||
return ideaService.findByStatusAndParams(IdeaStatus.WAITING, params, new PageRequest(getTable().getCurrentPage(), getTable().getRowsPerPage(), getSort())).iterator();
|
||||
return ideaService.findByStatusAndCapabilities(IdeaStatus.WAITING, params, new PageRequest(getTable().getCurrentPage(), getTable().getRowsPerPage(), getSort())).iterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -197,6 +197,11 @@ public class SupervisorIdeaServiceImpl extends AbstractQueryService<SupervisorId
|
||||
|
||||
@Override
|
||||
public Page<SupervisorIdea> findByStatusAndParams(IdeaStatus status, FilterParams params, Pageable pageable) {
|
||||
return supervisorIdeaRepo.findAll(byStatus(status).and(levelFilter(params.getLevels())), pageable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<SupervisorIdea> findByStatusAndCapabilities(IdeaStatus status, FilterParams params, Pageable pageable) {
|
||||
return supervisorIdeaRepo.findAll(byStatus(status).and(capabilityFilter(params.getLevels())), pageable);
|
||||
}
|
||||
|
||||
@ -223,17 +228,20 @@ public class SupervisorIdeaServiceImpl extends AbstractQueryService<SupervisorId
|
||||
|
||||
private BooleanBuilder capabilityFilter(Collection<ProjectClass> levels){
|
||||
BooleanBuilder e = new BooleanBuilder();
|
||||
if(levels!=null && !levels.isEmpty()){
|
||||
for (ProjectClass level : levels) {
|
||||
List<Employee> list = supervisorService.getSupervisorsWithinLimits(level);
|
||||
e.or(byLevel(level).and(inSupervisorList(list)));
|
||||
}
|
||||
return e;
|
||||
}
|
||||
else {
|
||||
e.and(QSupervisorIdea.supervisorIdea.projectClass.isNull());
|
||||
return e;
|
||||
}
|
||||
if (levels != null && !levels.isEmpty()) {
|
||||
for (ProjectClass level : levels) {
|
||||
List<Employee> list = supervisorService
|
||||
.getSupervisorsWithinLimits(level);
|
||||
if (list.isEmpty()) { // If no capable supervisors exist, make
|
||||
// sure no ideas is returned.
|
||||
return e.and(QSupervisorIdea.supervisorIdea.projectClass.isNull());
|
||||
} else
|
||||
e.or(byLevel(level).and(inSupervisorList(list)));
|
||||
}
|
||||
return e;
|
||||
} else {
|
||||
return e.and(QSupervisorIdea.supervisorIdea.projectClass.isNull());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -21,6 +21,7 @@ public interface SupervisorIdeaService extends GenericService<SupervisorIdea, Lo
|
||||
Page<SupervisorIdea> findAll(FilterParams params, Pageable pageable);
|
||||
Page<SupervisorIdea> findByStatus(IdeaStatus status, Pageable pageable);
|
||||
Page<SupervisorIdea> findByStatusAndParams(IdeaStatus status, FilterParams params, Pageable pageable);
|
||||
Page<SupervisorIdea> findByStatusAndCapabilities(IdeaStatus status, FilterParams params, Pageable pageable);
|
||||
List<SupervisorIdea> findByStatusAndAuthor(IdeaStatus status, Student author);
|
||||
List<SupervisorIdea> findIdeas(IdeaStatus status, Student author, boolean confirmed);
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package se.su.dsv.scipro.springdata;
|
||||
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@ -11,8 +12,11 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.UserDao;
|
||||
import se.su.dsv.scipro.data.dataobjects.Employee;
|
||||
import se.su.dsv.scipro.data.dataobjects.ProjectClass;
|
||||
import se.su.dsv.scipro.data.dataobjects.User;
|
||||
import se.su.dsv.scipro.match.dao.interfaces.KeywordTypeDao;
|
||||
import se.su.dsv.scipro.match.dataobject.Availability;
|
||||
import se.su.dsv.scipro.springdata.services.ProjectClassService;
|
||||
import se.su.dsv.scipro.springdata.services.SupervisorService;
|
||||
|
||||
import java.util.*;
|
||||
@ -28,6 +32,8 @@ public class TestSupervisor {
|
||||
|
||||
@Autowired
|
||||
private SupervisorService supervisorService;
|
||||
@Autowired
|
||||
private ProjectClassService projectClassService;
|
||||
|
||||
@Autowired
|
||||
private UserDao userDao;
|
||||
@ -45,6 +51,27 @@ public class TestSupervisor {
|
||||
return supervisorService.save(employee);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Transactional
|
||||
@Rollback
|
||||
public void testSupervisorAvailabilities() {
|
||||
ProjectClass bachelor = new ProjectClass(ProjectClass.BACHELOR, "Bachelor", "Bachelor degree thesis project");
|
||||
bachelor = projectClassService.save(bachelor);
|
||||
ProjectClass master = new ProjectClass(ProjectClass.MASTER, "Master", "Master degree thesis project");
|
||||
master = projectClassService.save(master);
|
||||
|
||||
Employee employee1 = getEmployee("Head", "Supervisor", "supervisor@scipro.se");
|
||||
employee1.getCapabilities().setMaxProjects(bachelor, 1);
|
||||
employee1.getCapabilities().setMaxProjects(master, 2);
|
||||
|
||||
Availability availability = supervisorService.getAvailability(employee1, bachelor);
|
||||
Availability availability2 = supervisorService.getAvailability(employee1, master);
|
||||
Assert.assertEquals(new Availability(employee1, 0L, 1, bachelor), availability);
|
||||
Assert.assertEquals(new Availability(employee1, 0L, 2, master), availability2);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test for getting supervisors in sorted order based on last name in ascending order.
|
||||
*/
|
||||
|
@ -67,7 +67,7 @@ public class TestSupervisorIdea {
|
||||
private User authorUser1, authorUser2, supervisorUser, supervisorUser2, unconfirmedUser;
|
||||
private Student author1, author2, unconfirmedAuthor;
|
||||
private Employee supervisor, supervisor2;
|
||||
private SupervisorIdea waitingBachelorIdea, waitingMasterIdea, takenBachelorIdea, completedMasterIdea;
|
||||
private SupervisorIdea waitingBachelorIdea, waitingMasterIdea, takenBachelorIdea, completedMasterIdea, waitingBachelor2, waitingMaster2, waitingBachelor3;
|
||||
private ApplicationPeriod bachelorPeriod, masterPeriod;
|
||||
private Keyword keyword1, keyword2;
|
||||
|
||||
@ -106,6 +106,9 @@ public class TestSupervisorIdea {
|
||||
waitingMasterIdea = newIdea(master, masterPeriod, supervisor, IdeaStatus.WAITING);
|
||||
takenBachelorIdea = newIdea(bachelor, bachelorPeriod, supervisor, IdeaStatus.TAKEN);
|
||||
completedMasterIdea = newIdea(master, masterPeriod, supervisor, IdeaStatus.COMPLETED);
|
||||
waitingBachelor2 = newIdea(bachelor, bachelorPeriod, supervisor2, IdeaStatus.WAITING);
|
||||
waitingBachelor3 = newIdea(bachelor, bachelorPeriod, supervisor2, IdeaStatus.WAITING);
|
||||
waitingMaster2 = newIdea(master, masterPeriod, supervisor2, IdeaStatus.WAITING);
|
||||
}
|
||||
|
||||
|
||||
@ -115,7 +118,7 @@ public class TestSupervisorIdea {
|
||||
public void testFindIdeasByStatus() {
|
||||
Page<SupervisorIdea> waitingIdeaPage = ideaService.findByStatus(IdeaStatus.WAITING, new PageRequest(0, 10));
|
||||
List<SupervisorIdea> waitingIdeasList = waitingIdeaPage.getContent();
|
||||
Assert.assertEquals(Arrays.asList(new SupervisorIdea[]{waitingBachelorIdea, waitingMasterIdea}), waitingIdeasList);
|
||||
Assert.assertEquals(Arrays.asList(new SupervisorIdea[]{waitingBachelorIdea, waitingMasterIdea, waitingBachelor2, waitingBachelor3, waitingMaster2}), waitingIdeasList);
|
||||
|
||||
Page<SupervisorIdea> takenIdeaPage = ideaService.findByStatus(IdeaStatus.TAKEN, new PageRequest(0, 10));
|
||||
List<SupervisorIdea> takenIdeasList = takenIdeaPage.getContent();
|
||||
@ -138,14 +141,14 @@ public class TestSupervisorIdea {
|
||||
|
||||
Page<SupervisorIdea> waitingBachelors = ideaService.findByStatusAndParams(IdeaStatus.WAITING, params, new PageRequest(0, 10));
|
||||
List<SupervisorIdea> waitingIdeasList = waitingBachelors.getContent();
|
||||
Assert.assertEquals(Arrays.asList(new SupervisorIdea[]{waitingBachelorIdea}), waitingIdeasList);
|
||||
Assert.assertEquals(Arrays.asList(new SupervisorIdea[]{waitingBachelorIdea, waitingBachelor2, waitingBachelor3}), waitingIdeasList);
|
||||
|
||||
levelSet.add(master);
|
||||
params.setLevels(levelSet);
|
||||
|
||||
Page<SupervisorIdea> waitingBachelorAndMasters = ideaService.findByStatusAndParams(IdeaStatus.WAITING, params, new PageRequest(0, 10));
|
||||
List<SupervisorIdea> waitingIdeas = waitingBachelorAndMasters.getContent();
|
||||
Assert.assertEquals(Arrays.asList(new SupervisorIdea[]{waitingBachelorIdea, waitingMasterIdea}), waitingIdeas);
|
||||
Assert.assertEquals(Arrays.asList(new SupervisorIdea[]{waitingBachelorIdea, waitingMasterIdea, waitingBachelor2, waitingBachelor3, waitingMaster2}), waitingIdeas);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -185,10 +188,10 @@ public class TestSupervisorIdea {
|
||||
@Transactional
|
||||
@Rollback
|
||||
public void testSaveSupervisorCreatedIdea() {
|
||||
Assert.assertEquals(new Long(2), ideaService.countByStatus(IdeaStatus.WAITING));
|
||||
Assert.assertEquals(new Long(5), ideaService.countByStatus(IdeaStatus.WAITING));
|
||||
IModel<SupervisorIdea> model = newIdeaModel(bachelor);
|
||||
ideaService.saveSupervisorCreatedIdea(model, supervisor, new TreeSet<Student>());
|
||||
Assert.assertEquals(new Long(3), ideaService.countByStatus(IdeaStatus.WAITING));
|
||||
Assert.assertEquals(new Long(6), ideaService.countByStatus(IdeaStatus.WAITING));
|
||||
|
||||
}
|
||||
|
||||
@ -214,17 +217,17 @@ public class TestSupervisorIdea {
|
||||
public void testDeleteWaitingIdea() {
|
||||
Iterable<SupervisorIdea> ideas = ideaService.findAll();
|
||||
List<SupervisorIdea> ideaList = constructList(ideas);
|
||||
Assert.assertEquals(4, ideaList.size());
|
||||
Assert.assertEquals(7, ideaList.size());
|
||||
|
||||
ideaService.deleteWaitingIdea(Model.of(takenBachelorIdea)); //Should not be deleted.
|
||||
ideas = ideaService.findAll();
|
||||
ideaList = constructList(ideas);
|
||||
Assert.assertEquals(4, ideaList.size());
|
||||
Assert.assertEquals(7, ideaList.size());
|
||||
|
||||
ideaService.deleteWaitingIdea(Model.of(waitingBachelorIdea)); //Should be deleted.
|
||||
ideas = ideaService.findAll();
|
||||
ideaList = constructList(ideas);
|
||||
Assert.assertEquals(3, ideaList.size());
|
||||
Assert.assertEquals(6, ideaList.size());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -278,6 +281,44 @@ public class TestSupervisorIdea {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@Transactional
|
||||
@Rollback
|
||||
public void testShowOnlyWaitingIdeasBySupervisorsWithinLimits() {
|
||||
Set<ProjectClass> levels = new HashSet<ProjectClass>();
|
||||
levels.add(bachelor);
|
||||
levels.add(master);
|
||||
FilterParams params = new FilterParams();
|
||||
params.setLevels(levels);
|
||||
|
||||
supervisor.getCapabilities().setMaxProjects(bachelor, 1);
|
||||
supervisor.getCapabilities().setMaxProjects(master, 1);
|
||||
|
||||
supervisor2.getCapabilities().setMaxProjects(bachelor, 1);
|
||||
supervisor2.getCapabilities().setMaxProjects(master, 1);
|
||||
|
||||
Page<SupervisorIdea> ideaPage = ideaService.findByStatusAndCapabilities(IdeaStatus.WAITING, params, new PageRequest(0, 10));
|
||||
List<SupervisorIdea> ideas = ideaPage.getContent();
|
||||
Assert.assertEquals(Arrays.asList(new SupervisorIdea[]{waitingMasterIdea, waitingBachelor2, waitingBachelor3, waitingMaster2}), ideas);
|
||||
|
||||
supervisor.getCapabilities().setMaxProjects(bachelor, 5);
|
||||
ideaPage = ideaService.findByStatusAndCapabilities(IdeaStatus.WAITING, params, new PageRequest(0, 10));
|
||||
ideas = ideaPage.getContent();
|
||||
Assert.assertEquals(Arrays.asList(new SupervisorIdea[]{waitingBachelorIdea, waitingMasterIdea, waitingBachelor2, waitingBachelor3, waitingMaster2}), ideas);
|
||||
|
||||
waitingBachelor2.setIdeaStatus(IdeaStatus.TAKEN);
|
||||
|
||||
ideaPage = ideaService.findByStatusAndCapabilities(IdeaStatus.WAITING, params, new PageRequest(0, 10));
|
||||
ideas = ideaPage.getContent();
|
||||
Assert.assertEquals(Arrays.asList(new SupervisorIdea[]{waitingBachelorIdea, waitingMasterIdea, waitingMaster2}), ideas);
|
||||
|
||||
supervisor2.getCapabilities().setMaxProjects(master, 0);
|
||||
|
||||
ideaPage = ideaService.findByStatusAndCapabilities(IdeaStatus.WAITING, params, new PageRequest(0, 10));
|
||||
ideas = ideaPage.getContent();
|
||||
Assert.assertEquals(Arrays.asList(new SupervisorIdea[]{waitingBachelorIdea, waitingMasterIdea}), ideas);
|
||||
}
|
||||
|
||||
// HELPER METHODS
|
||||
private SupervisorIdea newIdea(ProjectClass pc, ApplicationPeriod ap, Employee supervisor, IdeaStatus ideaStatus) {
|
||||
SupervisorIdea idea = new SupervisorIdea();
|
||||
|
Loading…
x
Reference in New Issue
Block a user