Search in sources :

Example 66 with Project

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());
}
Also used : ProjectSampleJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin) Project(ca.corefacility.bioinformatics.irida.model.project.Project) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) ModelMap(org.springframework.ui.ModelMap) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Link(org.springframework.hateoas.Link) Test(org.junit.Test)

Example 67 with Project

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());
}
Also used : ProjectSampleJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin) Project(ca.corefacility.bioinformatics.irida.model.project.Project) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) ModelMap(org.springframework.ui.ModelMap) Link(org.springframework.hateoas.Link) Test(org.junit.Test)

Example 68 with Project

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);
}
Also used : Path(java.nio.file.Path) MockMultipartFile(org.springframework.mock.web.MockMultipartFile) ProjectSampleJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin) Project(ca.corefacility.bioinformatics.irida.model.project.Project) SequenceFilePair(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFilePair) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) SampleSequencingObjectJoin(ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin) SequenceFileResource(ca.corefacility.bioinformatics.irida.web.assembler.resource.sequencefile.SequenceFileResource) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 69 with Project

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;
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project)

Example 70 with Project

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);
}
Also used : RemoteAPI(ca.corefacility.bioinformatics.irida.model.RemoteAPI) Project(ca.corefacility.bioinformatics.irida.model.project.Project) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) RemoteStatus(ca.corefacility.bioinformatics.irida.model.remote.RemoteStatus) Link(org.springframework.hateoas.Link) Test(org.junit.Test)

Aggregations

Project (ca.corefacility.bioinformatics.irida.model.project.Project)331 Test (org.junit.Test)190 Sample (ca.corefacility.bioinformatics.irida.model.sample.Sample)120 User (ca.corefacility.bioinformatics.irida.model.user.User)88 WithMockUser (org.springframework.security.test.context.support.WithMockUser)80 ProjectSampleJoin (ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin)71 Join (ca.corefacility.bioinformatics.irida.model.joins.Join)62 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)51 RelatedProjectJoin (ca.corefacility.bioinformatics.irida.model.joins.impl.RelatedProjectJoin)37 ArrayList (java.util.ArrayList)34 ProjectUserJoin (ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin)30 SampleSequencingObjectJoin (ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin)30 AnalysisSubmission (ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission)27 ProjectRole (ca.corefacility.bioinformatics.irida.model.enums.ProjectRole)25 ReferenceFile (ca.corefacility.bioinformatics.irida.model.project.ReferenceFile)23 ProjectEvent (ca.corefacility.bioinformatics.irida.model.event.ProjectEvent)22 ProjectAnalysisSubmissionJoin (ca.corefacility.bioinformatics.irida.model.workflow.submission.ProjectAnalysisSubmissionJoin)22 List (java.util.List)22 UserRoleSetProjectEvent (ca.corefacility.bioinformatics.irida.model.event.UserRoleSetProjectEvent)21 ImmutableMap (com.google.common.collect.ImmutableMap)21