Search in sources :

Example 51 with Join

use of ca.corefacility.bioinformatics.irida.model.joins.Join in project irida by phac-nml.

the class ProjectServiceImplIT method testRemoveSampleFromProject.

@Test
@WithMockUser(username = "admin", roles = "ADMIN")
public void testRemoveSampleFromProject() {
    Sample s = sampleService.read(1L);
    Project p2 = projectService.read(2L);
    Project p3 = projectService.read(3L);
    projectService.removeSampleFromProject(p2, s);
    projectService.removeSampleFromProject(p3, s);
    Collection<Join<Project, Sample>> samples = sampleService.getSamplesForProject(p3);
    assertTrue("No samples should be assigned to project.", samples.isEmpty());
    assertFalse("sample should be deleted because it was detached", sampleService.exists(s.getId()));
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) RelatedProjectJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.RelatedProjectJoin) Join(ca.corefacility.bioinformatics.irida.model.joins.Join) ProjectSampleJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin) ProjectAnalysisSubmissionJoin(ca.corefacility.bioinformatics.irida.model.workflow.submission.ProjectAnalysisSubmissionJoin) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.Test)

Example 52 with Join

use of ca.corefacility.bioinformatics.irida.model.joins.Join in project irida by phac-nml.

the class ReferenceFileServiceImplIT method testDeleteReferenceFile.

@Test
@WithMockUser(username = "fbristow", roles = "USER")
public void testDeleteReferenceFile() {
    Project p = projectService.read(1L);
    List<Join<Project, ReferenceFile>> prs = referenceFileService.getReferenceFilesForProject(p);
    assertEquals("Wrong number of reference files for project.", 1, prs.size());
    ReferenceFile rf = prs.iterator().next().getObject();
    assertEquals("Wrong reference file attached to project.", Long.valueOf(1), rf.getId());
    referenceFileService.delete(rf.getId());
    p = projectService.read(1L);
    prs = referenceFileService.getReferenceFilesForProject(p);
    assertEquals("No more reference files should be in the project.", 0, prs.size());
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) ReferenceFile(ca.corefacility.bioinformatics.irida.model.project.ReferenceFile) Join(ca.corefacility.bioinformatics.irida.model.joins.Join) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.Test)

Example 53 with Join

use of ca.corefacility.bioinformatics.irida.model.joins.Join in project irida by phac-nml.

the class ProjectServiceImplTest method testUpdateProjectUserJoin.

@Test
public void testUpdateProjectUserJoin() throws ProjectWithoutOwnerException {
    Project project = new Project("Project 1");
    User user = new User();
    User user2 = new User();
    ProjectRole projectRole = ProjectRole.PROJECT_USER;
    ProjectUserJoin oldJoin = new ProjectUserJoin(project, user, ProjectRole.PROJECT_OWNER);
    @SuppressWarnings("unchecked") List<Join<Project, User>> owners = Lists.newArrayList(new ProjectUserJoin(project, user, ProjectRole.PROJECT_OWNER), new ProjectUserJoin(project, user2, ProjectRole.PROJECT_OWNER));
    when(pujRepository.getProjectJoinForUser(project, user)).thenReturn(oldJoin);
    when(pujRepository.save(oldJoin)).thenReturn(oldJoin);
    when(pujRepository.getUsersForProjectByRole(project, ProjectRole.PROJECT_OWNER)).thenReturn(owners);
    Join<Project, User> updateUserProjectRole = projectService.updateUserProjectRole(project, user, projectRole);
    assertNotNull(updateUserProjectRole);
    ProjectUserJoin newJoin = (ProjectUserJoin) updateUserProjectRole;
    assertEquals(projectRole, newJoin.getProjectRole());
    verify(pujRepository).getProjectJoinForUser(project, user);
    verify(pujRepository).getUsersForProjectByRole(project, ProjectRole.PROJECT_OWNER);
    verify(pujRepository).save(oldJoin);
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) User(ca.corefacility.bioinformatics.irida.model.user.User) ProjectUserJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin) ProjectReferenceFileJoin(ca.corefacility.bioinformatics.irida.model.project.ProjectReferenceFileJoin) RelatedProjectJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.RelatedProjectJoin) Join(ca.corefacility.bioinformatics.irida.model.joins.Join) ProjectUserJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin) ProjectSampleJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin) UserGroupProjectJoin(ca.corefacility.bioinformatics.irida.model.user.group.UserGroupProjectJoin) ProjectRole(ca.corefacility.bioinformatics.irida.model.enums.ProjectRole) Test(org.junit.Test)

Example 54 with Join

use of ca.corefacility.bioinformatics.irida.model.joins.Join in project irida by phac-nml.

the class ProjectServiceImplTest method testGetProjectsForUser.

@Test
public void testGetProjectsForUser() {
    final User u = new User();
    final Project p1 = new Project("p1");
    final Project p2 = new Project("p2");
    final UserGroup ug = new UserGroup("group");
    final ProjectUserJoin puj = new ProjectUserJoin(p1, u, ProjectRole.PROJECT_OWNER);
    final UserGroupProjectJoin ugpj = new UserGroupProjectJoin(p2, ug, ProjectRole.PROJECT_OWNER);
    when(pujRepository.getProjectsForUser(u)).thenReturn(ImmutableList.of(puj));
    when(ugpjRepository.findProjectsByUser(u)).thenReturn(ImmutableList.of(ugpj));
    final List<Join<Project, User>> projects = projectService.getProjectsForUser(u);
    assertEquals("User should be in 2 projects.", 2, projects.size());
    assertTrue("Should have found user project join.", projects.stream().anyMatch(p -> p.getSubject().equals(p1)));
    assertTrue("Should have found group project join.", projects.stream().anyMatch(p -> p.getSubject().equals(p2)));
}
Also used : ProjectRole(ca.corefacility.bioinformatics.irida.model.enums.ProjectRole) ProjectSampleJoinRepository(ca.corefacility.bioinformatics.irida.repositories.joins.project.ProjectSampleJoinRepository) ConstraintViolationImpl(org.hibernate.validator.internal.engine.ConstraintViolationImpl) ProjectReferenceFileJoin(ca.corefacility.bioinformatics.irida.model.project.ProjectReferenceFileJoin) ProjectService(ca.corefacility.bioinformatics.irida.service.ProjectService) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException) SecurityContextHolder(org.springframework.security.core.context.SecurityContextHolder) Path(java.nio.file.Path) ConstraintViolation(javax.validation.ConstraintViolation) ReferenceFileRepository(ca.corefacility.bioinformatics.irida.repositories.referencefile.ReferenceFileRepository) UserRepository(ca.corefacility.bioinformatics.irida.repositories.user.UserRepository) ProjectWithoutOwnerException(ca.corefacility.bioinformatics.irida.exceptions.ProjectWithoutOwnerException) SequencingObjectRepository(ca.corefacility.bioinformatics.irida.repositories.sequencefile.SequencingObjectRepository) Set(java.util.Set) Validator(javax.validation.Validator) PageRequest(org.springframework.data.domain.PageRequest) Page(org.springframework.data.domain.Page) SampleSequencingObjectJoinRepository(ca.corefacility.bioinformatics.irida.repositories.joins.sample.SampleSequencingObjectJoinRepository) Matchers.any(org.mockito.Matchers.any) ProjectUserJoinRepository(ca.corefacility.bioinformatics.irida.repositories.joins.project.ProjectUserJoinRepository) List(java.util.List) Specification(org.springframework.data.jpa.domain.Specification) Assert.assertFalse(org.junit.Assert.assertFalse) RelatedProjectJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.RelatedProjectJoin) User(ca.corefacility.bioinformatics.irida.model.user.User) ProjectAnalysisSubmissionJoinRepository(ca.corefacility.bioinformatics.irida.repositories.analysis.submission.ProjectAnalysisSubmissionJoinRepository) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) Authentication(org.springframework.security.core.Authentication) PageImpl(org.springframework.data.domain.PageImpl) Mockito.mock(org.mockito.Mockito.mock) ProjectServiceImpl(ca.corefacility.bioinformatics.irida.service.impl.ProjectServiceImpl) EntityExistsException(ca.corefacility.bioinformatics.irida.exceptions.EntityExistsException) EntityNotFoundException(ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException) SampleRepository(ca.corefacility.bioinformatics.irida.repositories.sample.SampleRepository) Join(ca.corefacility.bioinformatics.irida.model.joins.Join) Mockito.verifyZeroInteractions(org.mockito.Mockito.verifyZeroInteractions) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) UserGroupProjectJoinRepository(ca.corefacility.bioinformatics.irida.repositories.joins.project.UserGroupProjectJoinRepository) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) ProjectReferenceFileJoinRepository(ca.corefacility.bioinformatics.irida.repositories.joins.project.ProjectReferenceFileJoinRepository) ProjectUserJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin) RelatedProjectRepository(ca.corefacility.bioinformatics.irida.repositories.joins.project.RelatedProjectRepository) ProjectRepository(ca.corefacility.bioinformatics.irida.repositories.ProjectRepository) Before(org.junit.Before) ReferenceFile(ca.corefacility.bioinformatics.irida.model.project.ReferenceFile) ProjectSampleJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin) Files(java.nio.file.Files) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) Test(org.junit.Test) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) Mockito.when(org.mockito.Mockito.when) UserGroup(ca.corefacility.bioinformatics.irida.model.user.group.UserGroup) Project(ca.corefacility.bioinformatics.irida.model.project.Project) Mockito.verify(org.mockito.Mockito.verify) ConstraintViolationException(javax.validation.ConstraintViolationException) UserGroupProjectJoin(ca.corefacility.bioinformatics.irida.model.user.group.UserGroupProjectJoin) Assert.assertEquals(org.junit.Assert.assertEquals) Project(ca.corefacility.bioinformatics.irida.model.project.Project) User(ca.corefacility.bioinformatics.irida.model.user.User) ProjectUserJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin) UserGroupProjectJoin(ca.corefacility.bioinformatics.irida.model.user.group.UserGroupProjectJoin) ProjectReferenceFileJoin(ca.corefacility.bioinformatics.irida.model.project.ProjectReferenceFileJoin) RelatedProjectJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.RelatedProjectJoin) Join(ca.corefacility.bioinformatics.irida.model.joins.Join) ProjectUserJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin) ProjectSampleJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin) UserGroupProjectJoin(ca.corefacility.bioinformatics.irida.model.user.group.UserGroupProjectJoin) UserGroup(ca.corefacility.bioinformatics.irida.model.user.group.UserGroup) Test(org.junit.Test)

Example 55 with Join

use of ca.corefacility.bioinformatics.irida.model.joins.Join in project irida by phac-nml.

the class SampleServiceImplTest method testRejectSampleMergeDifferentProjects.

@Test
public void testRejectSampleMergeDifferentProjects() {
    Sample s1 = new Sample();
    s1.setId(1L);
    Sample s2 = new Sample();
    s2.setId(2L);
    Project p1 = new Project();
    p1.setId(1L);
    p1.setName("project 1");
    Project p2 = new Project();
    p2.setId(2L);
    p2.setName("project 2");
    List<Join<Project, Sample>> p1_s1 = new ArrayList<>();
    p1_s1.add(new ProjectSampleJoin(p1, s1, true));
    List<Join<Project, Sample>> p2_s2 = new ArrayList<>();
    p2_s2.add(new ProjectSampleJoin(p2, s2, true));
    when(psjRepository.getProjectForSample(s1)).thenReturn(p1_s1);
    when(psjRepository.getProjectForSample(s2)).thenReturn(p2_s2);
    try {
        sampleService.mergeSamples(p1, s1, Lists.newArrayList(s2));
        fail("Samples from different projects were allowed to be merged.");
    } catch (IllegalArgumentException e) {
    } catch (Exception e) {
        e.printStackTrace();
        fail("Failed for an unknown reason; stack trace preceded.");
    }
    verify(psjRepository).getProjectForSample(s1);
    verify(psjRepository).getProjectForSample(s2);
}
Also used : ProjectSampleJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin) Project(ca.corefacility.bioinformatics.irida.model.project.Project) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) ArrayList(java.util.ArrayList) Join(ca.corefacility.bioinformatics.irida.model.joins.Join) ProjectSampleJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin) SampleSequencingObjectJoin(ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin) AnalysisAlreadySetException(ca.corefacility.bioinformatics.irida.exceptions.AnalysisAlreadySetException) SequenceFileAnalysisException(ca.corefacility.bioinformatics.irida.exceptions.SequenceFileAnalysisException) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

Join (ca.corefacility.bioinformatics.irida.model.joins.Join)65 Project (ca.corefacility.bioinformatics.irida.model.project.Project)60 Test (org.junit.Test)40 Sample (ca.corefacility.bioinformatics.irida.model.sample.Sample)35 User (ca.corefacility.bioinformatics.irida.model.user.User)35 ProjectSampleJoin (ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin)34 RelatedProjectJoin (ca.corefacility.bioinformatics.irida.model.joins.impl.RelatedProjectJoin)26 ProjectUserJoin (ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin)23 ArrayList (java.util.ArrayList)20 WithMockUser (org.springframework.security.test.context.support.WithMockUser)20 ProjectAnalysisSubmissionJoin (ca.corefacility.bioinformatics.irida.model.workflow.submission.ProjectAnalysisSubmissionJoin)16 SampleSequencingObjectJoin (ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin)14 ProjectRole (ca.corefacility.bioinformatics.irida.model.enums.ProjectRole)13 ReferenceFile (ca.corefacility.bioinformatics.irida.model.project.ReferenceFile)13 List (java.util.List)12 Set (java.util.Set)12 SequencingObject (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject)11 Autowired (org.springframework.beans.factory.annotation.Autowired)11 ProjectSampleJoinRepository (ca.corefacility.bioinformatics.irida.repositories.joins.project.ProjectSampleJoinRepository)10 ProjectService (ca.corefacility.bioinformatics.irida.service.ProjectService)10