Search in sources :

Example 46 with Project

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

the class ProjectEventEmailScheduedTaskImplTest method testEmailUserTasks.

@SuppressWarnings("unchecked")
@Test
public void testEmailUserTasks() {
    Date priorDateFromCronString = ProjectEventEmailScheduledTaskImpl.getPriorDateFromCronString(task.getScheduledCronString());
    User tom = new User("tom", null, null, null, null, null);
    Project p = new Project("testproject");
    List<User> users = Lists.newArrayList(tom);
    ProjectUserJoin join = new ProjectUserJoin(p, tom, ProjectRole.PROJECT_OWNER);
    join.setEmailSubscription(true);
    List<ProjectEvent> events = Lists.newArrayList(new UserRoleSetProjectEvent(join));
    when(userService.getUsersWithEmailSubscriptions()).thenReturn(users);
    when(eventService.getEventsForUserAfterDate(eq(tom), any(Date.class))).thenReturn(events);
    when(projectService.getProjectsForUser(tom)).thenReturn(Lists.newArrayList(join));
    Date now = new Date();
    task.emailUserTasks();
    verify(userService).getUsersWithEmailSubscriptions();
    ArgumentCaptor<Date> dateCaptor = ArgumentCaptor.forClass(Date.class);
    verify(eventService).getEventsForUserAfterDate(eq(tom), dateCaptor.capture());
    verify(emailController).sendSubscriptionUpdateEmail(tom, events);
    Date testedDate = dateCaptor.getValue();
    assertTrue("date should be before current time", now.after(testedDate));
    assertTrue("date should be equal to or before scheduled time", priorDateFromCronString.before(testedDate) || priorDateFromCronString.equals(testedDate));
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) User(ca.corefacility.bioinformatics.irida.model.user.User) UserRoleSetProjectEvent(ca.corefacility.bioinformatics.irida.model.event.UserRoleSetProjectEvent) ProjectUserJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin) Date(java.util.Date) UserRoleSetProjectEvent(ca.corefacility.bioinformatics.irida.model.event.UserRoleSetProjectEvent) ProjectEvent(ca.corefacility.bioinformatics.irida.model.event.ProjectEvent) Test(org.junit.Test)

Example 47 with Project

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

the class ProjectEventServiceImplTest method testGetEventsForProject.

@Test
public void testGetEventsForProject() {
    Project project = new Project("a project");
    PageRequest pageable = new PageRequest(0, 1);
    service.getEventsForProject(project, pageable);
    verify(repository).getEventsForProject(project, pageable);
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) PageRequest(org.springframework.data.domain.PageRequest) Test(org.junit.Test)

Example 48 with Project

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

the class ProjectServiceImplTest method testUserHasProjectRole.

@SuppressWarnings("unchecked")
@Test
public void testUserHasProjectRole() {
    Project p = project();
    User u = new User();
    List<ProjectUserJoin> joins = new ArrayList<>();
    joins.add(new ProjectUserJoin(p, u, ProjectRole.PROJECT_OWNER));
    Page<ProjectUserJoin> page = new PageImpl<>(joins);
    when(pujRepository.findAll(any(Specification.class), any(PageRequest.class))).thenReturn(page);
    assertTrue("User has ownership of project.", projectService.userHasProjectRole(u, p, ProjectRole.PROJECT_OWNER));
}
Also used : PageImpl(org.springframework.data.domain.PageImpl) Project(ca.corefacility.bioinformatics.irida.model.project.Project) PageRequest(org.springframework.data.domain.PageRequest) User(ca.corefacility.bioinformatics.irida.model.user.User) ProjectUserJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin) ArrayList(java.util.ArrayList) Specification(org.springframework.data.jpa.domain.Specification) Test(org.junit.Test)

Example 49 with Project

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

the class ProjectServiceImplTest method testAddSampleWithSameSequencerId.

@Test(expected = EntityExistsException.class)
public void testAddSampleWithSameSequencerId() {
    Project p = project();
    Sample s = new Sample();
    Sample otherSample = new Sample("name");
    s.setSampleName("name");
    when(sampleRepository.getSampleBySampleName(p, s.getSampleName())).thenReturn(otherSample);
    projectService.addSampleToProject(p, s, true);
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) Test(org.junit.Test)

Example 50 with Project

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

the class ProjectServiceImplTest method testUpdateProjectUserJoinNotExists.

@Test(expected = EntityNotFoundException.class)
public void testUpdateProjectUserJoinNotExists() throws ProjectWithoutOwnerException {
    Project project = new Project("Project 1");
    User user = new User();
    ProjectRole projectRole = ProjectRole.PROJECT_USER;
    when(pujRepository.getProjectJoinForUser(project, user)).thenReturn(null);
    projectService.updateUserProjectRole(project, user, projectRole);
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) User(ca.corefacility.bioinformatics.irida.model.user.User) ProjectRole(ca.corefacility.bioinformatics.irida.model.enums.ProjectRole) 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