Search in sources :

Example 46 with ProjectSampleJoin

use of ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin in project irida by phac-nml.

the class ProjectServiceImplIT method testShareLockedSamplesWithoutOwner.

@Test
@WithMockUser(username = "user1", roles = "USER")
public void testShareLockedSamplesWithoutOwner() {
    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()));
}
Also used : ProjectRole(ca.corefacility.bioinformatics.irida.model.enums.ProjectRole) ProjectSampleJoinRepository(ca.corefacility.bioinformatics.irida.repositories.joins.project.ProjectSampleJoinRepository) ReferenceFileService(ca.corefacility.bioinformatics.irida.service.ReferenceFileService) URISyntaxException(java.net.URISyntaxException) Autowired(org.springframework.beans.factory.annotation.Autowired) ActiveProfiles(org.springframework.test.context.ActiveProfiles) ProjectService(ca.corefacility.bioinformatics.irida.service.ProjectService) TestExecutionListeners(org.springframework.test.context.TestExecutionListeners) SpringJUnit4ClassRunner(org.springframework.test.context.junit4.SpringJUnit4ClassRunner) AnalysisSubmissionService(ca.corefacility.bioinformatics.irida.service.AnalysisSubmissionService) Sort(org.springframework.data.domain.Sort) Path(java.nio.file.Path) AnalysisSubmission(ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission) SequencingObjectService(ca.corefacility.bioinformatics.irida.service.SequencingObjectService) ProjectWithoutOwnerException(ca.corefacility.bioinformatics.irida.exceptions.ProjectWithoutOwnerException) Collection(java.util.Collection) Set(java.util.Set) PageRequest(org.springframework.data.domain.PageRequest) IridaApiServicesConfig(ca.corefacility.bioinformatics.irida.config.services.IridaApiServicesConfig) Page(org.springframework.data.domain.Page) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) List(java.util.List) WithMockUser(org.springframework.security.test.context.support.WithMockUser) RelatedProjectJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.RelatedProjectJoin) User(ca.corefacility.bioinformatics.irida.model.user.User) SampleService(ca.corefacility.bioinformatics.irida.service.sample.SampleService) Revision(org.springframework.data.history.Revision) Revisions(org.springframework.data.history.Revisions) DatabaseTearDown(com.github.springtestdbunit.annotation.DatabaseTearDown) EntityExistsException(ca.corefacility.bioinformatics.irida.exceptions.EntityExistsException) EntityRevisionDeletedException(ca.corefacility.bioinformatics.irida.exceptions.EntityRevisionDeletedException) AnnotationConfigContextLoader(org.springframework.test.context.support.AnnotationConfigContextLoader) RunWith(org.junit.runner.RunWith) EntityNotFoundException(ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException) Join(ca.corefacility.bioinformatics.irida.model.joins.Join) SequencingObject(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) Qualifier(org.springframework.beans.factory.annotation.Qualifier) Direction(org.springframework.data.domain.Sort.Direction) DependencyInjectionTestExecutionListener(org.springframework.test.context.support.DependencyInjectionTestExecutionListener) ReferenceFile(ca.corefacility.bioinformatics.irida.model.project.ReferenceFile) Iterator(java.util.Iterator) WithSecurityContextTestExcecutionListener(org.springframework.security.test.context.support.WithSecurityContextTestExcecutionListener) ProjectSampleJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin) Files(java.nio.file.Files) DatabaseSetup(com.github.springtestdbunit.annotation.DatabaseSetup) IOException(java.io.IOException) Test(org.junit.Test) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) AccessDeniedException(org.springframework.security.access.AccessDeniedException) UserGroup(ca.corefacility.bioinformatics.irida.model.user.group.UserGroup) Project(ca.corefacility.bioinformatics.irida.model.project.Project) ProjectAnalysisSubmissionJoin(ca.corefacility.bioinformatics.irida.model.workflow.submission.ProjectAnalysisSubmissionJoin) UserGroupService(ca.corefacility.bioinformatics.irida.service.user.UserGroupService) DbUnitTestExecutionListener(com.github.springtestdbunit.DbUnitTestExecutionListener) Paths(java.nio.file.Paths) UserService(ca.corefacility.bioinformatics.irida.service.user.UserService) ContextConfiguration(org.springframework.test.context.ContextConfiguration) UnsupportedReferenceFileContentError(ca.corefacility.bioinformatics.irida.exceptions.UnsupportedReferenceFileContentError) IridaApiJdbcDataSourceConfig(ca.corefacility.bioinformatics.irida.config.data.IridaApiJdbcDataSourceConfig) Assert(org.junit.Assert) 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) RelatedProjectJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.RelatedProjectJoin) Join(ca.corefacility.bioinformatics.irida.model.joins.Join) ProjectSampleJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin) ProjectAnalysisSubmissionJoin(ca.corefacility.bioinformatics.irida.model.workflow.submission.ProjectAnalysisSubmissionJoin) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.Test)

Example 47 with ProjectSampleJoin

use of ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin in project irida by phac-nml.

the class ProjectServiceImplTest method testRemoveSampleWithOtherLinksFromProject.

@Test
public void testRemoveSampleWithOtherLinksFromProject() {
    Sample s = new Sample("s1");
    Project p1 = new Project("p1");
    final ProjectSampleJoin j = new ProjectSampleJoin(p1, s, true);
    when(psjRepository.getProjectForSample(s)).thenReturn(ImmutableList.of(j));
    when(psjRepository.readSampleForProject(p1, s)).thenReturn(j);
    projectService.removeSampleFromProject(p1, s);
    verify(psjRepository).delete(j);
    verifyZeroInteractions(sampleRepository);
}
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) Test(org.junit.Test)

Example 48 with ProjectSampleJoin

use of ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin in project irida by phac-nml.

the class ProjectServiceImplTest method testAddSampleToProject.

@Test
public void testAddSampleToProject() {
    Sample s = new Sample();
    s.setSampleName("sample");
    s.setId(new Long(2222));
    Project p = project();
    ProjectSampleJoin join = new ProjectSampleJoin(p, s, true);
    when(psjRepository.save(join)).thenReturn(join);
    Join<Project, Sample> rel = projectService.addSampleToProject(p, s, true);
    verify(psjRepository).save(join);
    verify(sampleRepository).getSampleBySampleName(p, s.getSampleName());
    assertNotNull(rel);
    assertEquals(rel.getSubject(), p);
    assertEquals(rel.getObject(), s);
}
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) Test(org.junit.Test)

Example 49 with ProjectSampleJoin

use of ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin in project irida by phac-nml.

the class SampleServiceImplTest method testGetSampleForProject.

@Test
public void testGetSampleForProject() {
    Project p = new Project();
    p.setId(1111L);
    Sample s = new Sample();
    s.setId(2222L);
    ProjectSampleJoin join = new ProjectSampleJoin(p, s, true);
    when(sampleRepository.findOne(s.getId())).thenReturn(s);
    when(psjRepository.readSampleForProject(p, s)).thenReturn(join);
    sampleService.getSampleForProject(p, s.getId());
    verify(psjRepository).readSampleForProject(p, s);
}
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) Test(org.junit.Test)

Example 50 with ProjectSampleJoin

use of ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin in project irida by phac-nml.

the class SampleServiceImplTest method testRejectSampleMergeDifferentProjects.

@Test
public void testRejectSampleMergeDifferentProjects() {
    Sample s1 = new Sample();
    s1.setId(1L);
    Sample s2 = new Sample();
    s2.setId(2L);
    Project p1 = new Project();
    p1.setId(1L);
    p1.setName("project 1");
    Project p2 = new Project();
    p2.setId(2L);
    p2.setName("project 2");
    List<Join<Project, Sample>> p1_s1 = new ArrayList<>();
    p1_s1.add(new ProjectSampleJoin(p1, s1, true));
    List<Join<Project, Sample>> p2_s2 = new ArrayList<>();
    p2_s2.add(new ProjectSampleJoin(p2, s2, true));
    when(psjRepository.getProjectForSample(s1)).thenReturn(p1_s1);
    when(psjRepository.getProjectForSample(s2)).thenReturn(p2_s2);
    try {
        sampleService.mergeSamples(p1, s1, Lists.newArrayList(s2));
        fail("Samples from different projects were allowed to be merged.");
    } catch (IllegalArgumentException e) {
    } catch (Exception e) {
        e.printStackTrace();
        fail("Failed for an unknown reason; stack trace preceded.");
    }
    verify(psjRepository).getProjectForSample(s1);
    verify(psjRepository).getProjectForSample(s2);
}
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) ArrayList(java.util.ArrayList) Join(ca.corefacility.bioinformatics.irida.model.joins.Join) ProjectSampleJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin) SampleSequencingObjectJoin(ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin) AnalysisAlreadySetException(ca.corefacility.bioinformatics.irida.exceptions.AnalysisAlreadySetException) SequenceFileAnalysisException(ca.corefacility.bioinformatics.irida.exceptions.SequenceFileAnalysisException) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

ProjectSampleJoin (ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin)59 Project (ca.corefacility.bioinformatics.irida.model.project.Project)51 Sample (ca.corefacility.bioinformatics.irida.model.sample.Sample)51 Test (org.junit.Test)43 Join (ca.corefacility.bioinformatics.irida.model.joins.Join)15 SampleSequencingObjectJoin (ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin)15 ArrayList (java.util.ArrayList)11 SequenceFile (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile)8 SingleEndSequenceFile (ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile)8 WithMockUser (org.springframework.security.test.context.support.WithMockUser)8 User (ca.corefacility.bioinformatics.irida.model.user.User)7 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)7 Authentication (org.springframework.security.core.Authentication)7 Transactional (org.springframework.transaction.annotation.Transactional)7 EntityExistsException (ca.corefacility.bioinformatics.irida.exceptions.EntityExistsException)6 SequencingObject (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject)6 AnalysisSubmission (ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission)6 LaunchesProjectEvent (ca.corefacility.bioinformatics.irida.events.annotations.LaunchesProjectEvent)5 EntityNotFoundException (ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException)5 RelatedProjectJoin (ca.corefacility.bioinformatics.irida.model.joins.impl.RelatedProjectJoin)5