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());
}
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));
}
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));
}
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"));
}
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"));
}
Aggregations