Search in sources :

Example 6 with ProjectEvent

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));
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) User(ca.corefacility.bioinformatics.irida.model.user.User) UserRemovedProjectEvent(ca.corefacility.bioinformatics.irida.model.event.UserRemovedProjectEvent) 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)

Example 7 with ProjectEvent

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);
}
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) 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)

Example 8 with ProjectEvent

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"));
}
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 9 with ProjectEvent

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

Example 10 with ProjectEvent

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

Aggregations

ProjectEvent (ca.corefacility.bioinformatics.irida.model.event.ProjectEvent)30 UserRoleSetProjectEvent (ca.corefacility.bioinformatics.irida.model.event.UserRoleSetProjectEvent)29 SampleAddedProjectEvent (ca.corefacility.bioinformatics.irida.model.event.SampleAddedProjectEvent)23 UserRemovedProjectEvent (ca.corefacility.bioinformatics.irida.model.event.UserRemovedProjectEvent)23 Test (org.junit.Test)23 Project (ca.corefacility.bioinformatics.irida.model.project.Project)21 User (ca.corefacility.bioinformatics.irida.model.user.User)16 DataAddedToSampleProjectEvent (ca.corefacility.bioinformatics.irida.model.event.DataAddedToSampleProjectEvent)13 PageRequest (org.springframework.data.domain.PageRequest)10 WithMockUser (org.springframework.security.test.context.support.WithMockUser)10 Sample (ca.corefacility.bioinformatics.irida.model.sample.Sample)8 Map (java.util.Map)8 Date (java.util.Date)7 List (java.util.List)7 UserGroupRemovedProjectEvent (ca.corefacility.bioinformatics.irida.model.enums.UserGroupRemovedProjectEvent)5 SampleRemovedProjectEvent (ca.corefacility.bioinformatics.irida.model.event.SampleRemovedProjectEvent)5 UserGroupRoleSetProjectEvent (ca.corefacility.bioinformatics.irida.model.event.UserGroupRoleSetProjectEvent)5 ProjectSampleJoin (ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin)5 ProjectUserJoin (ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin)5 SampleSequencingObjectJoin (ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin)4