use of ca.corefacility.bioinformatics.irida.model.event.UserRoleSetProjectEvent 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"));
}
use of ca.corefacility.bioinformatics.irida.model.event.UserRoleSetProjectEvent in project irida by phac-nml.
the class ProjectEventServiceImplIT method testAddProjectUser.
@WithMockUser(username = "tom", password = "password1", roles = "ADMIN")
@Test
public void testAddProjectUser() {
Project project = projectService.read(1L);
User user = userService.read(2L);
projectService.addUserToProject(project, user, ProjectRole.PROJECT_USER);
Page<ProjectEvent> eventsForProject = projectEventService.getEventsForProject(project, new PageRequest(0, 10));
assertEquals(1, eventsForProject.getTotalElements());
ProjectEvent event = eventsForProject.iterator().next();
assertTrue(event instanceof UserRoleSetProjectEvent);
UserRoleSetProjectEvent userEvent = (UserRoleSetProjectEvent) event;
assertEquals(project, userEvent.getProject());
assertEquals(user, userEvent.getUser());
}
use of ca.corefacility.bioinformatics.irida.model.event.UserRoleSetProjectEvent in project irida by phac-nml.
the class ProjectEventServiceImplIT method testUpdateProjectUser.
@WithMockUser(username = "tom", password = "password1", roles = "ADMIN")
@Test
public void testUpdateProjectUser() throws ProjectWithoutOwnerException {
Project project = projectService.read(1L);
User user = userService.read(1L);
projectService.updateUserProjectRole(project, user, ProjectRole.PROJECT_USER);
Page<ProjectEvent> eventsForProject = projectEventService.getEventsForProject(project, new PageRequest(0, 10));
assertEquals(1, eventsForProject.getTotalElements());
ProjectEvent event = eventsForProject.iterator().next();
assertTrue(event instanceof UserRoleSetProjectEvent);
UserRoleSetProjectEvent userEvent = (UserRoleSetProjectEvent) event;
assertEquals(project, userEvent.getProject());
assertEquals(user, userEvent.getUser());
}
use of ca.corefacility.bioinformatics.irida.model.event.UserRoleSetProjectEvent in project irida by phac-nml.
the class ProjectEventHandlerTest method testDelegateUserRole.
@Test
public void testDelegateUserRole() {
Class<? extends ProjectEvent> clazz = UserRoleSetProjectEvent.class;
Project project = new Project();
User user = new User();
ProjectUserJoin returnValue = new ProjectUserJoin(project, user, ProjectRole.PROJECT_USER);
Object[] args = { project, user, ProjectRole.PROJECT_USER };
MethodEvent methodEvent = new MethodEvent(clazz, returnValue, args);
when(eventRepository.save(any(ProjectEvent.class))).thenReturn(new UserRoleSetProjectEvent(returnValue));
handler.delegate(methodEvent);
ArgumentCaptor<ProjectEvent> captor = ArgumentCaptor.forClass(ProjectEvent.class);
verify(eventRepository).save(captor.capture());
ProjectEvent event = captor.getValue();
assertTrue(event instanceof UserRoleSetProjectEvent);
verify(projectRepository).save(any(Project.class));
}
Aggregations