use of ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin in project irida by phac-nml.
the class ProjectServiceImplIT method testShareSamplesWithOwner.
@Test
@WithMockUser(username = "user1", roles = "USER")
public void testShareSamplesWithOwner() {
Project source = projectService.read(2L);
Project destination = projectService.read(10L);
Sample sample1 = sampleService.read(1L);
Set<Sample> samples = Sets.newHashSet(sample1);
List<ProjectSampleJoin> copiedSamples = projectService.shareSamples(source, destination, samples, true);
assertEquals(samples.size(), copiedSamples.size());
copiedSamples.forEach(j -> {
assertTrue("Project should be owner for sample", j.isOwner());
});
assertNotNull("Samples should still exist in source project", projectSampleJoinRepository.readSampleForProject(source, sample1));
assertNotNull("Sample should exist in destination project", projectSampleJoinRepository.readSampleForProject(destination, sample1));
}
use of ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin in project irida by phac-nml.
the class ProjectServiceImplIT method testShareSamplesWithoutOwner.
@Test
@WithMockUser(username = "user1", roles = "USER")
public void testShareSamplesWithoutOwner() {
Project source = projectService.read(2L);
Project destination = projectService.read(10L);
List<Join<Project, Sample>> samplesForProject = sampleService.getSamplesForProject(source);
Set<Sample> samples = samplesForProject.stream().map(j -> j.getObject()).collect(Collectors.toSet());
List<ProjectSampleJoin> copiedSamples = projectService.shareSamples(source, destination, samples, false);
assertEquals(samples.size(), copiedSamples.size());
copiedSamples.forEach(j -> {
assertFalse("Project shouldn't be owner for sample", j.isOwner());
});
assertEquals("Samples should still exist in source project", Sets.newHashSet(1L, 2L), projectSampleJoinRepository.getSamplesForProject(source).stream().map(j -> j.getObject().getId()).collect(Collectors.toSet()));
assertEquals("Samples should exist in destination project", Sets.newHashSet(1L, 2L), projectSampleJoinRepository.getSamplesForProject(destination).stream().map(j -> j.getObject().getId()).collect(Collectors.toSet()));
}
use of ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin in project irida by phac-nml.
the class ProjectServiceImplIT method testMoveSamplesWithoutOwner.
@Test
@WithMockUser(username = "user1", roles = "USER")
public void testMoveSamplesWithoutOwner() {
Project source = projectService.read(2L);
Project destination = projectService.read(10L);
List<Join<Project, Sample>> samplesForProject = sampleService.getSamplesForProject(source);
Set<Sample> samples = samplesForProject.stream().map(j -> j.getObject()).collect(Collectors.toSet());
List<ProjectSampleJoin> movedSamples = projectService.moveSamples(source, destination, samples, false);
assertEquals(samples.size(), movedSamples.size());
movedSamples.forEach(j -> {
assertFalse("Project shouldn't be owner for sample", j.isOwner());
});
assertEquals("Samples should not exist in source project", Long.valueOf(0L), projectSampleJoinRepository.countSamplesForProject(source));
assertEquals("Samples should exist in destination project", Sets.newHashSet(1L, 2L), projectSampleJoinRepository.getSamplesForProject(destination).stream().map(j -> j.getObject().getId()).collect(Collectors.toSet()));
}
use of ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin in project irida by phac-nml.
the class SampleServiceImplIT method testGetSamplesForProjectWithName.
@Test
@WithMockUser(username = "fbristow", roles = "ADMIN")
public void testGetSamplesForProjectWithName() {
int pageSize = 2;
Project project = projectService.read(1L);
Page<ProjectSampleJoin> pageSamplesForProject = sampleService.getSamplesForProjectWithName(project, "", 0, pageSize, Direction.ASC, "createdDate");
assertEquals(pageSize, pageSamplesForProject.getNumberOfElements());
assertEquals(3, pageSamplesForProject.getTotalElements());
pageSamplesForProject = sampleService.getSamplesForProjectWithName(project, "2", 0, pageSize, Direction.ASC, "createdDate");
assertEquals(1, pageSamplesForProject.getTotalElements());
}
use of ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin in project irida by phac-nml.
the class ProjectSamplesControllerTest method testMoveSampleToProject.
@SuppressWarnings("unchecked")
@Test
public void testMoveSampleToProject() {
Long projectId = 1L;
List<Long> sampleIds = ImmutableList.of(2L, 3L);
Long newProjectId = 4L;
boolean removeFromOriginal = true;
Project oldProject = new Project("oldProject");
Project newProject = new Project("newProject");
Sample s2 = new Sample("s2");
Sample s3 = new Sample("s3");
ArrayList<Sample> sampleList = Lists.newArrayList(s2, s3);
boolean owner = true;
ArrayList<ProjectSampleJoin> joins = Lists.newArrayList(new ProjectSampleJoin(newProject, s2, owner), new ProjectSampleJoin(newProject, s3, owner));
when(projectService.read(projectId)).thenReturn(oldProject);
when(projectService.read(newProjectId)).thenReturn(newProject);
when(sampleService.readMultiple(any(Iterable.class))).thenReturn(sampleList);
when(projectService.moveSamples(oldProject, newProject, sampleList, owner)).thenReturn(joins);
Map<String, Object> result = controller.shareSampleToProject(projectId, sampleIds, newProjectId, removeFromOriginal, true, Locale.US);
assertTrue(result.containsKey("result"));
assertTrue(result.containsKey("message"));
verify(projectService).read(projectId);
verify(projectService).read(newProjectId);
verify(projectService).moveSamples(oldProject, newProject, sampleList, owner);
}
Aggregations