use of ca.corefacility.bioinformatics.irida.model.joins.impl.RelatedProjectJoin in project irida by phac-nml.
the class ProjectSettingsAssociatedProjectsControllerTest method testGetPotentialAssociatedProjectsAsUser.
@SuppressWarnings("unchecked")
@Test
public void testGetPotentialAssociatedProjectsAsUser() {
Long projectId = 1L;
Principal principal = () -> USER_NAME;
int page = 1;
int count = 10;
String sortedBy = "id";
String sortDir = "asc";
String projectName = "";
Project p1 = new Project("p1");
when(projectService.read(projectId)).thenReturn(p1);
User user = new User();
user.setSystemRole(Role.ROLE_USER);
when(userService.getUserByUsername(USER_NAME)).thenReturn(user);
Project p2 = new Project("p2");
p2.setId(2L);
Project p3 = new Project("p3");
p3.setId(3L);
List<RelatedProjectJoin> relatedJoins = Lists.newArrayList(new RelatedProjectJoin(p1, p2));
when(projectService.getRelatedProjects(p1)).thenReturn(relatedJoins);
Page<Project> projectPage = new PageImpl<>(Lists.newArrayList(p2, p3));
when(projectService.getUnassociatedProjects(p1, projectName, page, count, Direction.ASC, "id")).thenReturn(projectPage);
Map<String, Object> potentialAssociatedProjects = controller.getPotentialAssociatedProjects(projectId, principal, page, count, sortedBy, sortDir, projectName);
assertTrue(potentialAssociatedProjects.containsKey("associated"));
List<Map<String, String>> associated = (List<Map<String, String>>) potentialAssociatedProjects.get("associated");
assertEquals(2, associated.size());
for (Map<String, String> pmap : associated) {
if (pmap.get("id").equals("2")) {
assertTrue(pmap.containsKey("associated"));
}
}
verify(projectService).read(projectId);
verify(projectService).getRelatedProjects(p1);
verify(projectService).getUnassociatedProjects(p1, "", page, count, Direction.ASC, "id");
}
use of ca.corefacility.bioinformatics.irida.model.joins.impl.RelatedProjectJoin in project irida by phac-nml.
the class ProjectsControllerTest method getRelatedProjectJoin.
private List<RelatedProjectJoin> getRelatedProjectJoin(List<Join<Project, User>> projects) {
List<RelatedProjectJoin> join = new ArrayList<>();
Project objectProject = getProject();
for (Join<Project, User> j : projects) {
Project p = j.getSubject();
join.add(new RelatedProjectJoin(objectProject, p));
}
// Add a couple that do not have authorization
for (int i = 10; i < 15; i++) {
Project p = new Project("project" + i);
p.setId(1L + i);
join.add(new RelatedProjectJoin(objectProject, p));
}
return join;
}
use of ca.corefacility.bioinformatics.irida.model.joins.impl.RelatedProjectJoin in project irida by phac-nml.
the class ProjectServiceImplIT method testGetRelatedProjects.
@Test
@WithMockUser(username = "user2", password = "password1", roles = "USER")
public void testGetRelatedProjects() {
Project p6 = projectService.read(6L);
List<RelatedProjectJoin> relatedProjects = projectService.getRelatedProjects(p6);
assertFalse(relatedProjects.isEmpty());
for (RelatedProjectJoin rp : relatedProjects) {
assertEquals(p6, rp.getSubject());
assertNotEquals(p6, rp.getObject());
}
}
use of ca.corefacility.bioinformatics.irida.model.joins.impl.RelatedProjectJoin in project irida by phac-nml.
the class ProjectServiceImplIT method testGetProjectsRelatedTo.
@Test
@WithMockUser(username = "user2", password = "password1", roles = "USER")
public void testGetProjectsRelatedTo() {
Project p8 = projectService.read(8L);
List<RelatedProjectJoin> relatedProjects = projectService.getReverseRelatedProjects(p8);
assertFalse(relatedProjects.isEmpty());
for (RelatedProjectJoin rp : relatedProjects) {
assertEquals(p8, rp.getObject());
assertNotEquals(p8, rp.getSubject());
}
}
use of ca.corefacility.bioinformatics.irida.model.joins.impl.RelatedProjectJoin in project irida by phac-nml.
the class ProjectServiceImplIT method testAddRelatedProject.
@Test
@WithMockUser(username = "user2", password = "password1", roles = "USER")
public void testAddRelatedProject() {
Project p6 = projectService.read(6L);
Project p7 = projectService.read(7L);
RelatedProjectJoin rp = projectService.addRelatedProject(p6, p7);
assertNotNull(rp);
assertEquals(rp.getSubject(), p6);
assertEquals(rp.getObject(), p7);
}
Aggregations