use of ca.corefacility.bioinformatics.irida.model.event.ProjectEvent in project irida by phac-nml.
the class ProjectEventHandlerTest method testDelegateUserRemoved.
@Test
public void testDelegateUserRemoved() {
Class<? extends ProjectEvent> clazz = UserRemovedProjectEvent.class;
Project project = new Project();
User user = new User();
Object[] args = { project, user };
MethodEvent methodEvent = new MethodEvent(clazz, null, args);
when(eventRepository.save(any(ProjectEvent.class))).thenReturn(new UserRemovedProjectEvent(project, user));
handler.delegate(methodEvent);
ArgumentCaptor<ProjectEvent> captor = ArgumentCaptor.forClass(ProjectEvent.class);
verify(eventRepository).save(captor.capture());
ProjectEvent event = captor.getValue();
assertTrue(event instanceof UserRemovedProjectEvent);
verify(projectRepository).save(any(Project.class));
}
use of ca.corefacility.bioinformatics.irida.model.event.ProjectEvent in project irida by phac-nml.
the class ProjectEventHandlerTest method testOtherEvent.
@Test
public void testOtherEvent() {
Class<? extends ProjectEvent> clazz = ProjectEvent.class;
Project project = new Project();
User user = new User();
Object[] args = { project, user };
MethodEvent methodEvent = new MethodEvent(clazz, null, args);
handler.delegate(methodEvent);
verifyZeroInteractions(eventRepository);
}
use of ca.corefacility.bioinformatics.irida.model.event.ProjectEvent 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.ProjectEvent 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"));
}
use of ca.corefacility.bioinformatics.irida.model.event.ProjectEvent in project irida by phac-nml.
the class ProjectEventsControllerTest method testGetRecentEventsForProject.
@Test
public void testGetRecentEventsForProject() {
Long projectId = 1L;
Project project = new Project();
ExtendedModelMap model = new ExtendedModelMap();
ProjectEvent event = new UserRoleSetProjectEvent();
Page<ProjectEvent> page = new PageImpl<>(Lists.newArrayList(event));
when(projectService.read(projectId)).thenReturn(project);
when(eventService.getEventsForProject(eq(project), any(Pageable.class))).thenReturn(page);
String recentEventsForProject = controller.getRecentEventsForProject(projectId, 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