use of ca.corefacility.bioinformatics.irida.model.event.UserRemovedProjectEvent 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.UserRemovedProjectEvent in project irida by phac-nml.
the class ProjectEventServiceImplIT method testRemoveUser.
@WithMockUser(username = "tom", password = "password1", roles = "ADMIN")
@Test
public void testRemoveUser() throws ProjectWithoutOwnerException {
Project project = projectService.read(1L);
User user = userService.read(1L);
projectService.removeUserFromProject(project, user);
Page<ProjectEvent> eventsForProject = projectEventService.getEventsForProject(project, new PageRequest(0, 10));
assertEquals(1, eventsForProject.getTotalElements());
ProjectEvent event = eventsForProject.iterator().next();
assertTrue(event instanceof UserRemovedProjectEvent);
UserRemovedProjectEvent userEvent = (UserRemovedProjectEvent) event;
assertEquals(project, userEvent.getProject());
assertEquals(user, userEvent.getUser());
}
use of ca.corefacility.bioinformatics.irida.model.event.UserRemovedProjectEvent in project irida by phac-nml.
the class ProjectEventHandler method handleUserRemovedEvent.
/**
* Create a {@link UserRemovedProjectEvent}. The method arguments must
* contain a {@link Project} and {@link User}
*
* @param event
* The {@link MethodEvent} that this event is being launched from
*/
private ProjectEvent handleUserRemovedEvent(MethodEvent event) {
Object[] args = event.getArgs();
User user = null;
Project project = null;
for (Object arg : args) {
if (arg instanceof Project) {
project = (Project) arg;
} else if (arg instanceof User) {
user = (User) arg;
}
}
if (user == null || project == null) {
throw new IllegalArgumentException("Project or user cannot be found on method annotated with @LaunchesProjectEvent(UserRemovedProjectEvent.class)");
}
return eventRepository.save(new UserRemovedProjectEvent(project, user));
}
use of ca.corefacility.bioinformatics.irida.model.event.UserRemovedProjectEvent in project irida by phac-nml.
the class ProjectEventHandler method handleUserGroupRemovedEvent.
/**
* Create a {@link UserRemovedProjectEvent}. The method arguments must
* contain a {@link Project} and {@link User}
*
* @param event
* The {@link MethodEvent} that this event is being launched from
*/
private ProjectEvent handleUserGroupRemovedEvent(MethodEvent event) {
final Optional<Object> user = Arrays.stream(event.getArgs()).filter(e -> e instanceof UserGroup).findAny();
final Optional<Object> project = Arrays.stream(event.getArgs()).filter(e -> e instanceof Project).findAny();
if (!user.isPresent() || !project.isPresent()) {
throw new IllegalArgumentException("Project or user group cannot be found on method annotated with @LaunchesProjectEvent(UserGroupRemovedProjectEvent.class)");
}
return eventRepository.save(new UserGroupRemovedProjectEvent((Project) project.get(), (UserGroup) user.get()));
}
Aggregations