Search in sources :

Example 26 with User

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

the class ProjectEventEmailScheduedTaskImplTest method testEmailUserPartialSubscriptoinTasks.

@SuppressWarnings("unchecked")
@Test
public void testEmailUserPartialSubscriptoinTasks() {
    User tom = new User("tom", null, null, null, null, null);
    Project p = new Project("testproject");
    Project p2 = new Project("testproject2");
    List<User> users = Lists.newArrayList(tom);
    ProjectUserJoin join = new ProjectUserJoin(p, tom, ProjectRole.PROJECT_OWNER);
    join.setEmailSubscription(true);
    ProjectUserJoin notSubscribed = new ProjectUserJoin(p2, tom, ProjectRole.PROJECT_OWNER);
    List<ProjectEvent> events = Lists.newArrayList(new UserRoleSetProjectEvent(join), new UserRoleSetProjectEvent(notSubscribed));
    when(userService.getUsersWithEmailSubscriptions()).thenReturn(users);
    when(eventService.getEventsForUserAfterDate(eq(tom), any(Date.class))).thenReturn(events);
    when(projectService.getProjectsForUser(tom)).thenReturn(Lists.newArrayList(join, notSubscribed));
    task.emailUserTasks();
    verify(userService).getUsersWithEmailSubscriptions();
    verify(eventService).getEventsForUserAfterDate(eq(tom), any(Date.class));
    @SuppressWarnings("rawtypes") ArgumentCaptor<List> eventCaptor = ArgumentCaptor.forClass(List.class);
    verify(emailController).sendSubscriptionUpdateEmail(eq(tom), eventCaptor.capture());
    List<ProjectEvent> sentEvents = eventCaptor.getValue();
    assertEquals("should send 1 event", 1, sentEvents.size());
    ProjectEvent sentEvent = sentEvents.iterator().next();
    assertEquals("should have sent from subscribed project", p, sentEvent.getProject());
}
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) List(java.util.List) 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 27 with User

use of ca.corefacility.bioinformatics.irida.model.user.User 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 28 with User

use of ca.corefacility.bioinformatics.irida.model.user.User 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 29 with User

use of ca.corefacility.bioinformatics.irida.model.user.User 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)

Example 30 with User

use of ca.corefacility.bioinformatics.irida.model.user.User 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)

Aggregations

User (ca.corefacility.bioinformatics.irida.model.user.User)252 Test (org.junit.Test)153 Project (ca.corefacility.bioinformatics.irida.model.project.Project)84 WithMockUser (org.springframework.security.test.context.support.WithMockUser)57 Authentication (org.springframework.security.core.Authentication)45 Join (ca.corefacility.bioinformatics.irida.model.joins.Join)34 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)27 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)27 PageRequest (org.springframework.data.domain.PageRequest)26 UserGroup (ca.corefacility.bioinformatics.irida.model.user.group.UserGroup)25 ProjectRole (ca.corefacility.bioinformatics.irida.model.enums.ProjectRole)24 ProjectUserJoin (ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin)24 AnalysisSubmission (ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission)19 Principal (java.security.Principal)19 ProjectSampleJoin (ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin)18 RelatedProjectJoin (ca.corefacility.bioinformatics.irida.model.joins.impl.RelatedProjectJoin)18 List (java.util.List)18 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)17 EntityNotFoundException (ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException)16 ArrayList (java.util.ArrayList)16