Search in sources :

Example 1 with UserRoleSetProjectEvent

use of ca.corefacility.bioinformatics.irida.model.event.UserRoleSetProjectEvent 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 2 with UserRoleSetProjectEvent

use of ca.corefacility.bioinformatics.irida.model.event.UserRoleSetProjectEvent 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 3 with UserRoleSetProjectEvent

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

the class ProjectEventHandler method handleUserRoleSetProjectEvent.

/**
 * Create a {@link UserRoleSetProjectEvent}. The method must have returned a
 * {@link ProjectUserJoin}
 *
 * @param event
 *            The {@link MethodEvent} that this event is being launched from
 */
private ProjectEvent handleUserRoleSetProjectEvent(MethodEvent event) {
    Object returnValue = event.getReturnValue();
    if (!(returnValue instanceof ProjectUserJoin)) {
        throw new IllegalArgumentException("Method annotated with @LaunchesProjectEvent(UserRoleSetProjectEvent.class) method must return ProjectUserJoin");
    }
    ProjectUserJoin join = (ProjectUserJoin) returnValue;
    return eventRepository.save(new UserRoleSetProjectEvent(join));
}
Also used : UserRoleSetProjectEvent(ca.corefacility.bioinformatics.irida.model.event.UserRoleSetProjectEvent) ProjectUserJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin)

Example 4 with UserRoleSetProjectEvent

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

the class ProjectEventsControllerTest method testGetRecentEventsForUser.

@Test
public void testGetRecentEventsForUser() {
    ExtendedModelMap model = new ExtendedModelMap();
    ProjectEvent event = new UserRoleSetProjectEvent();
    Page<ProjectEvent> page = new PageImpl<>(Lists.newArrayList(event));
    User user = new User();
    Principal principal = () -> "username";
    when(userService.getUserByUsername(principal.getName())).thenReturn(user);
    when(eventService.getEventsForUser(eq(user), any(Pageable.class))).thenReturn(page);
    String recentEventsForProject = controller.getRecentEventsForUser(model, principal, 10);
    assertEquals(ProjectEventsController.EVENTS_VIEW, recentEventsForProject);
    assertTrue(model.containsAttribute("events"));
    @SuppressWarnings("unchecked") List<Map<String, Object>> events = (List<Map<String, Object>>) model.get("events");
    assertEquals(1, events.size());
    Map<String, Object> next = events.iterator().next();
    assertTrue(next.containsKey("name"));
    assertTrue(next.containsKey("event"));
    assertEquals(ProjectEventsController.FRAGMENT_NAMES.get(event.getClass()), next.get("name"));
    assertEquals(event, next.get("event"));
}
Also used : PageImpl(org.springframework.data.domain.PageImpl) ExtendedModelMap(org.springframework.ui.ExtendedModelMap) UserRoleSetProjectEvent(ca.corefacility.bioinformatics.irida.model.event.UserRoleSetProjectEvent) User(ca.corefacility.bioinformatics.irida.model.user.User) Pageable(org.springframework.data.domain.Pageable) List(java.util.List) Map(java.util.Map) ExtendedModelMap(org.springframework.ui.ExtendedModelMap) Principal(java.security.Principal) UserRoleSetProjectEvent(ca.corefacility.bioinformatics.irida.model.event.UserRoleSetProjectEvent) ProjectEvent(ca.corefacility.bioinformatics.irida.model.event.ProjectEvent) Test(org.junit.Test)

Example 5 with UserRoleSetProjectEvent

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

the class ProjectEventsControllerTest method testGetAllEvents.

@Test
public void testGetAllEvents() {
    ExtendedModelMap model = new ExtendedModelMap();
    ProjectEvent event = new UserRoleSetProjectEvent();
    Page<ProjectEvent> page = new PageImpl<>(Lists.newArrayList(event));
    int size = 10;
    when(eventService.list(0, size, Direction.DESC, "createdDate")).thenReturn(page);
    String recentEventsForProject = controller.getAllRecentEvents(model, 10);
    assertEquals(ProjectEventsController.EVENTS_VIEW, recentEventsForProject);
    assertTrue(model.containsAttribute("events"));
    @SuppressWarnings("unchecked") List<Map<String, Object>> events = (List<Map<String, Object>>) model.get("events");
    assertEquals(1, events.size());
    Map<String, Object> next = events.iterator().next();
    assertTrue(next.containsKey("name"));
    assertTrue(next.containsKey("event"));
    assertEquals(ProjectEventsController.FRAGMENT_NAMES.get(event.getClass()), next.get("name"));
    assertEquals(event, next.get("event"));
}
Also used : PageImpl(org.springframework.data.domain.PageImpl) ExtendedModelMap(org.springframework.ui.ExtendedModelMap) UserRoleSetProjectEvent(ca.corefacility.bioinformatics.irida.model.event.UserRoleSetProjectEvent) List(java.util.List) Map(java.util.Map) ExtendedModelMap(org.springframework.ui.ExtendedModelMap) UserRoleSetProjectEvent(ca.corefacility.bioinformatics.irida.model.event.UserRoleSetProjectEvent) ProjectEvent(ca.corefacility.bioinformatics.irida.model.event.ProjectEvent) Test(org.junit.Test)

Aggregations

UserRoleSetProjectEvent (ca.corefacility.bioinformatics.irida.model.event.UserRoleSetProjectEvent)9 ProjectEvent (ca.corefacility.bioinformatics.irida.model.event.ProjectEvent)8 Test (org.junit.Test)8 Project (ca.corefacility.bioinformatics.irida.model.project.Project)6 User (ca.corefacility.bioinformatics.irida.model.user.User)6 ProjectUserJoin (ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin)4 List (java.util.List)4 SampleAddedProjectEvent (ca.corefacility.bioinformatics.irida.model.event.SampleAddedProjectEvent)3 UserRemovedProjectEvent (ca.corefacility.bioinformatics.irida.model.event.UserRemovedProjectEvent)3 Map (java.util.Map)3 PageImpl (org.springframework.data.domain.PageImpl)3 ExtendedModelMap (org.springframework.ui.ExtendedModelMap)3 Date (java.util.Date)2 PageRequest (org.springframework.data.domain.PageRequest)2 Pageable (org.springframework.data.domain.Pageable)2 WithMockUser (org.springframework.security.test.context.support.WithMockUser)2 DataAddedToSampleProjectEvent (ca.corefacility.bioinformatics.irida.model.event.DataAddedToSampleProjectEvent)1 Principal (java.security.Principal)1