use of org.eclipse.che.api.user.server.event.BeforeUserRemovedEvent in project che by eclipse.
the class UserDaoTest method shouldNotRemoveUserWhenSubscriberThrowsExceptionOnUserRemoving.
@Test(dependsOnMethods = "shouldGetUserById")
public void shouldNotRemoveUserWhenSubscriberThrowsExceptionOnUserRemoving() throws Exception {
final UserImpl user = users[0];
CascadeEventSubscriber<BeforeUserRemovedEvent> subscriber = mockCascadeEventSubscriber();
doThrow(new ServerException("error")).when(subscriber).onCascadeEvent(any());
eventService.subscribe(subscriber, BeforeUserRemovedEvent.class);
try {
userDao.remove(user.getId());
fail("UserDao#remove had to throw server exception");
} catch (ServerException ignored) {
}
assertEqualsNoPassword(userDao.getById(user.getId()), user);
eventService.unsubscribe(subscriber, BeforeUserRemovedEvent.class);
}
use of org.eclipse.che.api.user.server.event.BeforeUserRemovedEvent in project che by eclipse.
the class JpaUserDao method doRemove.
@Transactional(rollbackOn = { RuntimeException.class, ServerException.class })
protected Optional<UserImpl> doRemove(String id) throws ServerException {
final EntityManager manager = managerProvider.get();
final UserImpl user = manager.find(UserImpl.class, id);
if (user == null) {
return Optional.empty();
}
eventService.publish(new BeforeUserRemovedEvent(user)).propagateException();
manager.remove(user);
manager.flush();
return Optional.of(user);
}
use of org.eclipse.che.api.user.server.event.BeforeUserRemovedEvent in project che by eclipse.
the class UserDaoTest method shouldFireBeforeUserRemovedEventOnRemoveExistedUser.
@Test
public void shouldFireBeforeUserRemovedEventOnRemoveExistedUser() throws Exception {
final UserImpl user = users[0];
final BeforeUserRemovedEvent[] firedEvent = { null };
EventSubscriber<BeforeUserRemovedEvent> beforeUserRemovedSubscriber = event -> firedEvent[0] = event;
eventService.subscribe(beforeUserRemovedSubscriber, BeforeUserRemovedEvent.class);
userDao.remove(user.getId());
assertNotNull(firedEvent[0]);
assertEquals(firedEvent[0].getUser().getId(), user.getId());
eventService.unsubscribe(beforeUserRemovedSubscriber, BeforeUserRemovedEvent.class);
}
Aggregations