use of ca.corefacility.bioinformatics.irida.model.sample.Sample in project irida by phac-nml.
the class RESTProjectSamplesControllerTest method testUpdateSample.
@Test
public void testUpdateSample() {
Sample s = TestDataFactory.constructSample();
Map<String, Object> updatedFields = ImmutableMap.of("sampleName", (Object) "some new name");
when(sampleService.updateFields(s.getId(), updatedFields)).thenReturn(s);
ModelMap modelMap = controller.updateSample(s.getId(), updatedFields);
verify(sampleService).updateFields(s.getId(), updatedFields);
Object o = modelMap.get(RESTGenericController.RESOURCE_NAME);
assertNotNull("There should be *something* in the response!", o);
assertTrue("Should be a sample in the response.", o instanceof Sample);
Sample resource = (Sample) o;
Map<String, String> links = linksToMap(resource.getLinks());
String self = links.get(Link.REL_SELF);
assertEquals("http://localhost/api/samples/" + s.getId(), self);
String sequenceFiles = links.get(RESTSampleSequenceFilesController.REL_SAMPLE_SEQUENCE_FILES);
assertEquals("http://localhost/api/samples/" + s.getId() + "/sequenceFiles", sequenceFiles);
}
use of ca.corefacility.bioinformatics.irida.model.sample.Sample in project irida by phac-nml.
the class RESTProjectSamplesControllerTest method testRemoveSampleFromProject.
@Test
public void testRemoveSampleFromProject() {
Project p = TestDataFactory.constructProject();
Sample s = TestDataFactory.constructSample();
when(projectService.read(p.getId())).thenReturn(p);
when(sampleService.read(s.getId())).thenReturn(s);
ModelMap modelMap = controller.removeSampleFromProject(p.getId(), s.getId());
// verify that we actually tried to remove the sample from the project.
verify(projectService, times(1)).removeSampleFromProject(p, s);
verify(projectService, times(1)).read(p.getId());
verify(sampleService, times(1)).read(s.getId());
// confirm that the response looks right.
Object o = modelMap.get(RESTGenericController.RESOURCE_NAME);
assertTrue(o instanceof RootResource);
RootResource resource = (RootResource) o;
List<Link> links = resource.getLinks();
// should be two links in the response, one back to the individual
// project, the other to the samples collection
Set<String> rels = Sets.newHashSet(RESTProjectsController.REL_PROJECT, RESTProjectSamplesController.REL_PROJECT_SAMPLES);
for (Link link : links) {
assertTrue(rels.contains(link.getRel()));
assertNotNull(rels.remove(link.getRel()));
}
assertTrue(rels.isEmpty());
}
use of ca.corefacility.bioinformatics.irida.model.sample.Sample in project irida by phac-nml.
the class RESTProjectSamplesControllerTest method testGetProjectSamples.
@Test
public void testGetProjectSamples() {
Project p = TestDataFactory.constructProject();
Sample s = TestDataFactory.constructSample();
Join<Project, Sample> r = new ProjectSampleJoin(p, s, true);
@SuppressWarnings("unchecked") List<Join<Project, Sample>> relationships = Lists.newArrayList(r);
when(sampleService.getSamplesForProject(p)).thenReturn(relationships);
when(projectService.read(p.getId())).thenReturn(p);
ModelMap modelMap = controller.getProjectSamples(p.getId());
verify(sampleService, times(1)).getSamplesForProject(p);
verify(projectService, times(1)).read(p.getId());
Object o = modelMap.get(RESTGenericController.RESOURCE_NAME);
assertTrue(o instanceof ResourceCollection);
@SuppressWarnings("unchecked") ResourceCollection<Sample> samples = (ResourceCollection<Sample>) o;
assertEquals(1, samples.size());
List<Link> resourceLinks = samples.getLinks();
assertEquals(1, resourceLinks.size());
Link self = resourceLinks.iterator().next();
assertEquals("self", self.getRel());
assertEquals("http://localhost/api/projects/" + p.getId() + "/samples", self.getHref());
Sample resource = samples.iterator().next();
assertEquals(s.getSampleName(), resource.getSampleName());
// assertEquals(1, resource.getSequenceFileCount());
List<Link> links = resource.getLinks();
Set<String> rels = Sets.newHashSet(Link.REL_SELF, RESTSampleSequenceFilesController.REL_SAMPLE_SEQUENCE_FILES, RESTSampleSequenceFilesController.REL_SAMPLE_SEQUENCE_FILE_PAIRS, RESTSampleSequenceFilesController.REL_SAMPLE_SEQUENCE_FILE_UNPAIRED, RESTProjectSamplesController.REL_PROJECT, RESTProjectSamplesController.REL_PROJECT_SAMPLE, RESTSampleMetadataController.METADATA_REL);
for (Link link : links) {
assertTrue("rels should contain link [" + link + "]", rels.contains(link.getRel()));
assertNotNull("rels should remove link [" + link + "]", rels.remove(link.getRel()));
}
assertTrue("Rels should be empty after removing expected links", rels.isEmpty());
}
use of ca.corefacility.bioinformatics.irida.model.sample.Sample in project irida by phac-nml.
the class RESTProjectSamplesControllerTest method testAlreadyCopiedSampleToProject.
@Test(expected = EntityExistsException.class)
public void testAlreadyCopiedSampleToProject() {
final Project p = TestDataFactory.constructProject();
final Sample s = TestDataFactory.constructSample();
when(projectService.read(p.getId())).thenReturn(p);
when(sampleService.read(s.getId())).thenReturn(s);
when(projectService.addSampleToProject(p, s, false)).thenThrow(new EntityExistsException("sample already exists!"));
controller.copySampleToProject(p.getId(), Lists.newArrayList(s.getId()), new MockHttpServletResponse());
}
use of ca.corefacility.bioinformatics.irida.model.sample.Sample 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());
}
Aggregations