Search in sources :

Example 51 with Project

use of ca.corefacility.bioinformatics.irida.model.project.Project in project irida by phac-nml.

the class ProjectServiceImplTest method testAddSampleToProjectNoSamplePersistedInvalidSample.

@Test(expected = ConstraintViolationException.class)
public void testAddSampleToProjectNoSamplePersistedInvalidSample() {
    Project p = project();
    Sample s = new Sample();
    s.setSampleName("name");
    Set<ConstraintViolation<Sample>> violations = new HashSet<>();
    violations.add(ConstraintViolationImpl.forBeanValidation(null, null, Sample.class, null, null, null, null, null, null));
    when(validator.validate(s)).thenReturn(violations);
    projectService.addSampleToProject(p, s, true);
    verifyZeroInteractions(sampleRepository, psjRepository);
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) ConstraintViolation(javax.validation.ConstraintViolation) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 52 with Project

use of ca.corefacility.bioinformatics.irida.model.project.Project in project irida by phac-nml.

the class ProjectServiceImplTest method testAddSampleToProjectNoSamplePersisted.

@Test
public void testAddSampleToProjectNoSamplePersisted() {
    Project p = project();
    Sample s = new Sample();
    s.setSampleName("name");
    Set<ConstraintViolation<Sample>> noViolations = new HashSet<>();
    when(validator.validate(s)).thenReturn(noViolations);
    when(sampleRepository.save(s)).thenReturn(s);
    projectService.addSampleToProject(p, s, true);
    verify(sampleRepository).save(s);
    verify(psjRepository).save(new ProjectSampleJoin(p, s, true));
}
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) ConstraintViolation(javax.validation.ConstraintViolation) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 53 with Project

use of ca.corefacility.bioinformatics.irida.model.project.Project in project irida by phac-nml.

the class ProjectServiceImplTest method testUpdateProjectUserJoinIllegalChange.

@Test(expected = ProjectWithoutOwnerException.class)
public void testUpdateProjectUserJoinIllegalChange() throws ProjectWithoutOwnerException {
    Project project = new Project("Project 1");
    User user = new User();
    ProjectRole projectRole = ProjectRole.PROJECT_USER;
    ProjectUserJoin oldJoin = new ProjectUserJoin(project, user, ProjectRole.PROJECT_OWNER);
    @SuppressWarnings("unchecked") List<Join<Project, User>> owners = Lists.newArrayList(new ProjectUserJoin(project, user, ProjectRole.PROJECT_OWNER));
    when(pujRepository.getProjectJoinForUser(project, user)).thenReturn(oldJoin);
    when(pujRepository.getUsersForProjectByRole(project, ProjectRole.PROJECT_OWNER)).thenReturn(owners);
    projectService.updateUserProjectRole(project, user, projectRole);
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) User(ca.corefacility.bioinformatics.irida.model.user.User) ProjectUserJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin) ProjectReferenceFileJoin(ca.corefacility.bioinformatics.irida.model.project.ProjectReferenceFileJoin) RelatedProjectJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.RelatedProjectJoin) Join(ca.corefacility.bioinformatics.irida.model.joins.Join) ProjectUserJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin) ProjectSampleJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin) UserGroupProjectJoin(ca.corefacility.bioinformatics.irida.model.user.group.UserGroupProjectJoin) ProjectRole(ca.corefacility.bioinformatics.irida.model.enums.ProjectRole) Test(org.junit.Test)

Example 54 with Project

use of ca.corefacility.bioinformatics.irida.model.project.Project in project irida by phac-nml.

the class ProjectServiceImplTest method testAddUserToProjectTwice.

@Test(expected = EntityExistsException.class)
public void testAddUserToProjectTwice() {
    User u = new User("test", "test@nowhere.com", "PASSWOD!1", "Test", "User", "1234");
    u.setId(new Long(1111));
    Project p = project();
    ProjectRole r = ProjectRole.PROJECT_USER;
    ProjectUserJoin join = new ProjectUserJoin(p, u, r);
    when(pujRepository.save(join)).thenThrow(new DataIntegrityViolationException("Duplicates."));
    projectService.addUserToProject(p, u, r);
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) User(ca.corefacility.bioinformatics.irida.model.user.User) ProjectUserJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin) ProjectRole(ca.corefacility.bioinformatics.irida.model.enums.ProjectRole) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException) Test(org.junit.Test)

Example 55 with Project

use of ca.corefacility.bioinformatics.irida.model.project.Project in project irida by phac-nml.

the class ProjectServiceImplTest method testRemoveSamplesFromProject.

@Test
public void testRemoveSamplesFromProject() {
    Project project = new Project();
    List<Sample> samples = ImmutableList.of(new Sample("s1"), new Sample("s2"));
    ProjectSampleJoin psj0 = new ProjectSampleJoin(project, samples.get(0), true);
    ProjectSampleJoin psj1 = new ProjectSampleJoin(project, samples.get(1), true);
    when(psjRepository.readSampleForProject(project, samples.get(0))).thenReturn(psj0);
    when(psjRepository.readSampleForProject(project, samples.get(1))).thenReturn(psj1);
    projectService.removeSamplesFromProject(project, samples);
    verify(psjRepository).delete(psj0);
    verify(psjRepository).delete(psj1);
}
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)

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