use of ca.corefacility.bioinformatics.irida.model.project.Project in project irida by phac-nml.
the class ProjectServiceImplTest method testGetProjectsForSample.
@Test
public void testGetProjectsForSample() {
Sample sample = new Sample("my sample");
@SuppressWarnings("unchecked") List<Join<Project, Sample>> projects = Lists.newArrayList(new ProjectSampleJoin(new Project("p1"), sample, true), new ProjectSampleJoin(new Project("p2"), sample, true));
when(psjRepository.getProjectForSample(sample)).thenReturn(projects);
List<Join<Project, Sample>> projectsForSample = projectService.getProjectsForSample(sample);
assertEquals(2, projectsForSample.size());
verify(psjRepository).getProjectForSample(sample);
}
use of ca.corefacility.bioinformatics.irida.model.project.Project in project irida by phac-nml.
the class ProjectServiceImplTest method testCreateProject.
@Test
public void testCreateProject() {
// The currently logged-in user should be added to the project when it's
// created.
Project p = project();
String username = "fbristow";
User u = new User();
u.setUsername(username);
Authentication auth = new UsernamePasswordAuthenticationToken(u, null);
SecurityContextHolder.getContext().setAuthentication(auth);
when(projectRepository.save(p)).thenReturn(p);
when(userRepository.loadUserByUsername(username)).thenReturn(u);
projectService.create(p);
verify(projectRepository).save(p);
verify(userRepository).loadUserByUsername(username);
SecurityContextHolder.getContext().setAuthentication(null);
}
use of ca.corefacility.bioinformatics.irida.model.project.Project in project irida by phac-nml.
the class ProjectServiceImplTest method testAddReferenceFileToProject.
@Test
public void testAddReferenceFileToProject() throws IOException {
Project p = new Project();
Path createTempFile = Files.createTempFile(null, null);
ReferenceFile f = new ReferenceFile(createTempFile);
when(referenceFileRepository.save(f)).thenReturn(f);
projectService.addReferenceFileToProject(p, f);
verify(referenceFileRepository).save(f);
verify(prfjRepository).save(new ProjectReferenceFileJoin(p, f));
}
use of ca.corefacility.bioinformatics.irida.model.project.Project in project irida by phac-nml.
the class SampleServiceImplTest method testMergeSamples.
@Test
public void testMergeSamples() {
// For every sample in toMerge, the service should:
// 1. call SequenceFileRepository to get the sequence files in that
// sample,
// 2. call SequenceFileRepository to add the sequence files to
// mergeInto,
// 3. call SampleRepository to persist the sample as deleted.
final int SIZE = 3;
Sample s = s(1L);
Project project = p(1L);
Sample[] toMerge = new Sample[SIZE];
SequenceFile[] toMerge_sf = new SequenceFile[SIZE];
SequencingObject[] toMerge_so = new SequencingObject[SIZE];
SampleSequencingObjectJoin[] s_so_joins = new SampleSequencingObjectJoin[SIZE];
SampleSequencingObjectJoin[] s_so_original = new SampleSequencingObjectJoin[SIZE];
ProjectSampleJoin[] p_s_joins = new ProjectSampleJoin[SIZE];
List<Sample> mergeSamples = new ArrayList<>();
for (long i = 0; i < SIZE; i++) {
int p = (int) i;
toMerge[p] = s(i + 2);
mergeSamples.add(toMerge[p]);
toMerge_sf[p] = sf(i + 2);
toMerge_so[p] = so(i + 2);
s_so_joins[p] = new SampleSequencingObjectJoin(s, toMerge_so[p]);
p_s_joins[p] = new ProjectSampleJoin(project, toMerge[p], true);
List<Join<Project, Sample>> projectSampleJoins = new ArrayList<>();
projectSampleJoins.add(p_s_joins[p]);
List<SampleSequencingObjectJoin> sampleSeqObjectJoins = new ArrayList<>();
SampleSequencingObjectJoin join = new SampleSequencingObjectJoin(toMerge[p], toMerge_so[p]);
sampleSeqObjectJoins.add(join);
s_so_original[p] = join;
when(ssoRepository.getSequencesForSample(toMerge[p])).thenReturn(null);
when(ssoRepository.getSequencesForSample(toMerge[p])).thenReturn(sampleSeqObjectJoins);
when(ssoRepository.save(s_so_joins[p])).thenReturn(s_so_joins[p]);
when(ssoRepository.readObjectForSample(toMerge[p], toMerge_so[p].getId())).thenReturn(join);
when(psjRepository.getProjectForSample(toMerge[p])).thenReturn(projectSampleJoins);
// for deletion
when(psjRepository.readSampleForProject(project, toMerge[p])).thenReturn(p_s_joins[p]);
}
List<Join<Project, Sample>> joins = new ArrayList<>();
joins.add(new ProjectSampleJoin(project, s, true));
when(psjRepository.getProjectForSample(s)).thenReturn(joins);
Sample saved = sampleService.mergeSamples(project, s, mergeSamples);
verify(psjRepository).getProjectForSample(s);
for (int i = 0; i < SIZE; i++) {
verify(ssoRepository).getSequencesForSample(toMerge[i]);
verify(ssoRepository).save(s_so_joins[i]);
verify(ssoRepository).delete(s_so_original[i]);
verify(sampleRepository).delete(toMerge[i].getId());
verify(psjRepository).getProjectForSample(toMerge[i]);
verify(psjRepository).delete(p_s_joins[i]);
}
assertEquals("The saved sample should be the same as the sample to merge into.", s, saved);
}
use of ca.corefacility.bioinformatics.irida.model.project.Project in project irida by phac-nml.
the class TestDataFactory method constructProject.
/**
* Construct a simple {@link ca.corefacility.bioinformatics.irida.model.Project}.
*
* @return a project with a name and identifier.
*/
public static Project constructProject() {
Project p = new Project();
p.setId(1L);
return p;
}
Aggregations