use of ca.corefacility.bioinformatics.irida.model.project.Project in project irida by phac-nml.
the class RESTProjectSamplesControllerTest method testAddSampleToProject.
@Test
public void testAddSampleToProject() {
MockHttpServletResponse response = new MockHttpServletResponse();
Sample s = TestDataFactory.constructSample();
Project p = TestDataFactory.constructProject();
Join<Project, Sample> r = new ProjectSampleJoin(p, s, true);
when(projectService.read(p.getId())).thenReturn(p);
when(projectService.addSampleToProject(p, s, true)).thenReturn(r);
ModelMap modelMap = controller.addSampleToProject(p.getId(), s, response);
Object o = modelMap.get(RESTGenericController.RESOURCE_NAME);
assertTrue("ModelMap should contan a SampleResource", o instanceof Sample);
verify(projectService, times(1)).read(p.getId());
verify(projectService, times(1)).addSampleToProject(p, s, true);
Link selfLink = s.getLink(Link.REL_SELF);
Link sequenceFilesLink = s.getLink(RESTSampleSequenceFilesController.REL_SAMPLE_SEQUENCE_FILES);
Link projectLink = s.getLink(RESTProjectSamplesController.REL_PROJECT);
String projectLocation = "http://localhost/api/projects/" + p.getId();
String sampleLocation = "http://localhost/api/samples/" + s.getId();
assertNotNull("Sample resource's self link should not be null", selfLink);
assertEquals("Sample resource's sample location should equal [" + sampleLocation + "]", sampleLocation, selfLink.getHref());
assertNotNull("Sequence files link must not be null", sequenceFilesLink);
assertEquals("Sequence files link must be well formed", sampleLocation + "/sequenceFiles", sequenceFilesLink.getHref());
assertNotNull("Project link must not be null", projectLink);
assertEquals("Project link must be well formed", projectLocation, projectLink.getHref());
assertEquals("response should have CREATED status", HttpStatus.CREATED.value(), response.getStatus());
}
use of ca.corefacility.bioinformatics.irida.model.project.Project in project irida by phac-nml.
the class RESTProjectSamplesControllerTest method testGetProjectSample.
@Test
public void testGetProjectSample() throws IOException {
Project p = TestDataFactory.constructProject();
Sample s = TestDataFactory.constructSample();
// mock out the service calls
when(projectService.read(p.getId())).thenReturn(p);
when(sampleService.read(s.getId())).thenReturn(s);
when(sampleService.getSampleForProject(p, s.getId())).thenReturn(new ProjectSampleJoin(p, s, true));
ModelMap modelMap = controller.getProjectSample(p.getId(), s.getId());
verify(sampleService).getSampleForProject(p, s.getId());
Object o = modelMap.get(RESTGenericController.RESOURCE_NAME);
assertTrue(o instanceof Sample);
Sample sr = (Sample) o;
Link selfLink = sr.getLink(Link.REL_SELF);
Link sequenceFilesLink = sr.getLink(RESTSampleSequenceFilesController.REL_SAMPLE_SEQUENCE_FILES);
Link projectLink = sr.getLink(RESTProjectSamplesController.REL_PROJECT);
String projectLocation = "http://localhost/api/projects/" + p.getId();
String sampleLocation = "http://localhost/api/samples/" + s.getId();
assertNotNull(selfLink);
assertEquals(sampleLocation, selfLink.getHref());
assertNotNull(sequenceFilesLink);
assertEquals(sampleLocation + "/sequenceFiles", sequenceFilesLink.getHref());
assertNotNull(projectLink);
assertEquals(projectLocation, projectLink.getHref());
}
use of ca.corefacility.bioinformatics.irida.model.project.Project in project irida by phac-nml.
the class SampleSequenceFilesControllerTest method testAddNewSequenceFilePairToSampleMismatchedRunIDs.
@Test(expected = IllegalArgumentException.class)
public void testAddNewSequenceFilePairToSampleMismatchedRunIDs() throws IOException {
Project p = TestDataFactory.constructProject();
Sample s = TestDataFactory.constructSample();
SequenceFilePair pair = TestDataFactory.constructSequenceFilePair();
SampleSequencingObjectJoin sso = new SampleSequencingObjectJoin(s, pair);
SequenceFileResource resource1 = new SequenceFileResource();
SequenceFileResource resource2 = new SequenceFileResource();
resource1.setMiseqRunId(1L);
resource2.setMiseqRunId(2L);
Path f1 = Files.createTempFile(null, null);
Path f2 = Files.createTempFile(null, null);
MockMultipartFile mmf1 = new MockMultipartFile("filename1", "filename1", "blurgh1", FileCopyUtils.copyToByteArray(f1.toFile()));
MockMultipartFile mmf2 = new MockMultipartFile("filename2", "filename2", "blurgh2", FileCopyUtils.copyToByteArray(f2.toFile()));
MockHttpServletResponse response = new MockHttpServletResponse();
when(sampleService.getSampleForProject(p, s.getId())).thenReturn(new ProjectSampleJoin(p, s, true));
when(sequencingObjectService.createSequencingObjectInSample(any(SequenceFilePair.class), Matchers.eq(s))).thenReturn(sso);
controller.addNewSequenceFilePairToSample(s.getId(), mmf1, resource1, mmf2, resource2, response);
}
use of ca.corefacility.bioinformatics.irida.model.project.Project in project irida by phac-nml.
the class SampleServiceImplTest method p.
private Project p(Long id) {
Project p = new Project();
p.setId(id);
return p;
}
use of ca.corefacility.bioinformatics.irida.model.project.Project in project irida by phac-nml.
the class SampleRemoteServiceImplTest method testGetSamplesForProject.
@Test
public void testGetSamplesForProject() {
String samplesHref = "http://somewhere/projects/5/samples";
Project project = new Project();
project.add(new Link(samplesHref, SampleRemoteServiceImpl.PROJECT_SAMPLES_REL));
RemoteAPI api = new RemoteAPI();
project.setRemoteStatus(new RemoteStatus("http://nowhere", api));
Sample remoteSample = new Sample();
remoteSample.setRemoteStatus(new RemoteStatus("http://nowhere", api));
List<Sample> samples = Lists.newArrayList(remoteSample);
when(sampleRemoteRepository.list(samplesHref, api)).thenReturn(samples);
List<Sample> samplesForProject = sampleRemoteService.getSamplesForProject(project);
verify(sampleRemoteRepository).list(samplesHref, api);
assertEquals(samples, samplesForProject);
}
Aggregations