Search in sources :

Example 6 with RelatedProjectJoin

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");
}
Also used : PageImpl(org.springframework.data.domain.PageImpl) User(ca.corefacility.bioinformatics.irida.model.user.User) Project(ca.corefacility.bioinformatics.irida.model.project.Project) RelatedProjectJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.RelatedProjectJoin) List(java.util.List) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) ExtendedModelMap(org.springframework.ui.ExtendedModelMap) Principal(java.security.Principal) Test(org.junit.Test)

Example 7 with RelatedProjectJoin

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;
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) User(ca.corefacility.bioinformatics.irida.model.user.User) RelatedProjectJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.RelatedProjectJoin)

Example 8 with RelatedProjectJoin

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());
    }
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) RelatedProjectJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.RelatedProjectJoin) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.Test)

Example 9 with RelatedProjectJoin

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());
    }
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) RelatedProjectJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.RelatedProjectJoin) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.Test)

Example 10 with RelatedProjectJoin

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);
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) RelatedProjectJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.RelatedProjectJoin) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.Test)

Aggregations

RelatedProjectJoin (ca.corefacility.bioinformatics.irida.model.joins.impl.RelatedProjectJoin)16 Project (ca.corefacility.bioinformatics.irida.model.project.Project)14 Test (org.junit.Test)10 User (ca.corefacility.bioinformatics.irida.model.user.User)4 ImmutableMap (com.google.common.collect.ImmutableMap)3 Principal (java.security.Principal)3 Map (java.util.Map)3 WithMockUser (org.springframework.security.test.context.support.WithMockUser)3 ExtendedModelMap (org.springframework.ui.ExtendedModelMap)3 List (java.util.List)2 PageImpl (org.springframework.data.domain.PageImpl)2 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Sort (org.springframework.data.domain.Sort)1 Transactional (org.springframework.transaction.annotation.Transactional)1