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()));
}
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());
}
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);
}
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)));
}
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);
}
Aggregations