Search in sources :

Example 1 with UserRemovedEvent

use of org.eclipse.che.api.user.server.event.UserRemovedEvent in project che by eclipse.

the class UserDaoTest method shouldFireUserRemovedEventOnRemoveExistedUser.

@Test
public void shouldFireUserRemovedEventOnRemoveExistedUser() throws Exception {
    final UserImpl user = users[0];
    final UserRemovedEvent[] firedEvent = { null };
    EventSubscriber<UserRemovedEvent> userRemovedSubscriber = event -> firedEvent[0] = event;
    eventService.subscribe(userRemovedSubscriber, UserRemovedEvent.class);
    userDao.remove(user.getId());
    assertNotNull(firedEvent[0]);
    assertEquals(firedEvent[0].getUserId(), user.getId());
    eventService.unsubscribe(userRemovedSubscriber, UserRemovedEvent.class);
}
Also used : Mockito.doCallRealMethod(org.mockito.Mockito.doCallRealMethod) Arrays(java.util.Arrays) Listeners(org.testng.annotations.Listeners) TckRepository(org.eclipse.che.commons.test.tck.repository.TckRepository) Page(org.eclipse.che.api.core.Page) Constants(org.eclipse.che.api.user.server.Constants) Assert.assertEquals(org.testng.Assert.assertEquals) Test(org.testng.annotations.Test) TckRepositoryException(org.eclipse.che.commons.test.tck.repository.TckRepositoryException) AfterMethod(org.testng.annotations.AfterMethod) AssertJUnit.assertTrue(org.testng.AssertJUnit.assertTrue) CascadeEvent(org.eclipse.che.core.db.cascade.event.CascadeEvent) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) HashSet(java.util.HashSet) Mockito.doThrow(org.mockito.Mockito.doThrow) CascadeEventSubscriber(org.eclipse.che.core.db.cascade.CascadeEventSubscriber) Arrays.asList(java.util.Arrays.asList) User(org.eclipse.che.api.core.model.user.User) ConflictException(org.eclipse.che.api.core.ConflictException) BeforeUserRemovedEvent(org.eclipse.che.api.user.server.event.BeforeUserRemovedEvent) NameGenerator(org.eclipse.che.commons.lang.NameGenerator) EventService(org.eclipse.che.api.core.notification.EventService) EventSubscriber(org.eclipse.che.api.core.notification.EventSubscriber) Assert.fail(org.testng.Assert.fail) BeforeMethod(org.testng.annotations.BeforeMethod) Assert.assertNotNull(org.testng.Assert.assertNotNull) NotFoundException(org.eclipse.che.api.core.NotFoundException) Matchers.any(org.mockito.Matchers.any) PostUserPersistedEvent(org.eclipse.che.api.user.server.event.PostUserPersistedEvent) TckListener(org.eclipse.che.commons.test.tck.TckListener) List(java.util.List) ServerException(org.eclipse.che.api.core.ServerException) UserRemovedEvent(org.eclipse.che.api.user.server.event.UserRemovedEvent) UserDao(org.eclipse.che.api.user.server.spi.UserDao) UserImpl(org.eclipse.che.api.user.server.model.impl.UserImpl) Mockito.mock(org.mockito.Mockito.mock) BeforeUserRemovedEvent(org.eclipse.che.api.user.server.event.BeforeUserRemovedEvent) UserRemovedEvent(org.eclipse.che.api.user.server.event.UserRemovedEvent) UserImpl(org.eclipse.che.api.user.server.model.impl.UserImpl) Test(org.testng.annotations.Test)

Example 2 with UserRemovedEvent

use of org.eclipse.che.api.user.server.event.UserRemovedEvent in project che by eclipse.

the class JpaUserDao method remove.

@Override
public void remove(String id) throws ServerException {
    requireNonNull(id, "Required non-null id");
    try {
        Optional<UserImpl> userOpt = doRemove(id);
        userOpt.ifPresent(user -> eventService.publish(new UserRemovedEvent(user.getId())));
    } catch (RuntimeException x) {
        throw new ServerException(x.getLocalizedMessage(), x);
    }
}
Also used : ServerException(org.eclipse.che.api.core.ServerException) BeforeUserRemovedEvent(org.eclipse.che.api.user.server.event.BeforeUserRemovedEvent) UserRemovedEvent(org.eclipse.che.api.user.server.event.UserRemovedEvent) UserImpl(org.eclipse.che.api.user.server.model.impl.UserImpl)

Aggregations

ServerException (org.eclipse.che.api.core.ServerException)2 BeforeUserRemovedEvent (org.eclipse.che.api.user.server.event.BeforeUserRemovedEvent)2 UserRemovedEvent (org.eclipse.che.api.user.server.event.UserRemovedEvent)2 UserImpl (org.eclipse.che.api.user.server.model.impl.UserImpl)2 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Arrays.asList (java.util.Arrays.asList)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Inject (javax.inject.Inject)1 ConflictException (org.eclipse.che.api.core.ConflictException)1 NotFoundException (org.eclipse.che.api.core.NotFoundException)1 Page (org.eclipse.che.api.core.Page)1 User (org.eclipse.che.api.core.model.user.User)1 EventService (org.eclipse.che.api.core.notification.EventService)1 EventSubscriber (org.eclipse.che.api.core.notification.EventSubscriber)1 Constants (org.eclipse.che.api.user.server.Constants)1 PostUserPersistedEvent (org.eclipse.che.api.user.server.event.PostUserPersistedEvent)1 UserDao (org.eclipse.che.api.user.server.spi.UserDao)1 NameGenerator (org.eclipse.che.commons.lang.NameGenerator)1