Search in sources :

Example 6 with UserRoleSetProjectEvent

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"));
}
Also used : PageImpl(org.springframework.data.domain.PageImpl) ExtendedModelMap(org.springframework.ui.ExtendedModelMap) UserRoleSetProjectEvent(ca.corefacility.bioinformatics.irida.model.event.UserRoleSetProjectEvent) Project(ca.corefacility.bioinformatics.irida.model.project.Project) Pageable(org.springframework.data.domain.Pageable) 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)

Example 7 with UserRoleSetProjectEvent

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());
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) PageRequest(org.springframework.data.domain.PageRequest) WithMockUser(org.springframework.security.test.context.support.WithMockUser) User(ca.corefacility.bioinformatics.irida.model.user.User) UserRoleSetProjectEvent(ca.corefacility.bioinformatics.irida.model.event.UserRoleSetProjectEvent) UserRoleSetProjectEvent(ca.corefacility.bioinformatics.irida.model.event.UserRoleSetProjectEvent) UserRemovedProjectEvent(ca.corefacility.bioinformatics.irida.model.event.UserRemovedProjectEvent) ProjectEvent(ca.corefacility.bioinformatics.irida.model.event.ProjectEvent) SampleAddedProjectEvent(ca.corefacility.bioinformatics.irida.model.event.SampleAddedProjectEvent) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.Test)

Example 8 with UserRoleSetProjectEvent

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());
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) PageRequest(org.springframework.data.domain.PageRequest) WithMockUser(org.springframework.security.test.context.support.WithMockUser) User(ca.corefacility.bioinformatics.irida.model.user.User) UserRoleSetProjectEvent(ca.corefacility.bioinformatics.irida.model.event.UserRoleSetProjectEvent) UserRoleSetProjectEvent(ca.corefacility.bioinformatics.irida.model.event.UserRoleSetProjectEvent) UserRemovedProjectEvent(ca.corefacility.bioinformatics.irida.model.event.UserRemovedProjectEvent) ProjectEvent(ca.corefacility.bioinformatics.irida.model.event.ProjectEvent) SampleAddedProjectEvent(ca.corefacility.bioinformatics.irida.model.event.SampleAddedProjectEvent) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.Test)

Example 9 with UserRoleSetProjectEvent

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));
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) UserRoleSetProjectEvent(ca.corefacility.bioinformatics.irida.model.event.UserRoleSetProjectEvent) User(ca.corefacility.bioinformatics.irida.model.user.User) ProjectUserJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin) UserRoleSetProjectEvent(ca.corefacility.bioinformatics.irida.model.event.UserRoleSetProjectEvent) UserRemovedProjectEvent(ca.corefacility.bioinformatics.irida.model.event.UserRemovedProjectEvent) DataAddedToSampleProjectEvent(ca.corefacility.bioinformatics.irida.model.event.DataAddedToSampleProjectEvent) ProjectEvent(ca.corefacility.bioinformatics.irida.model.event.ProjectEvent) SampleAddedProjectEvent(ca.corefacility.bioinformatics.irida.model.event.SampleAddedProjectEvent) 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