Search in sources :

Example 1 with BeforeUserRemovedEvent

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);
}
Also used : ServerException(org.eclipse.che.api.core.ServerException) UserImpl(org.eclipse.che.api.user.server.model.impl.UserImpl) BeforeUserRemovedEvent(org.eclipse.che.api.user.server.event.BeforeUserRemovedEvent) Test(org.testng.annotations.Test)

Example 2 with BeforeUserRemovedEvent

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);
}
Also used : EntityManager(javax.persistence.EntityManager) UserImpl(org.eclipse.che.api.user.server.model.impl.UserImpl) BeforeUserRemovedEvent(org.eclipse.che.api.user.server.event.BeforeUserRemovedEvent) Transactional(com.google.inject.persist.Transactional)

Example 3 with BeforeUserRemovedEvent

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);
}
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) UserImpl(org.eclipse.che.api.user.server.model.impl.UserImpl) BeforeUserRemovedEvent(org.eclipse.che.api.user.server.event.BeforeUserRemovedEvent) Test(org.testng.annotations.Test)

Aggregations

BeforeUserRemovedEvent (org.eclipse.che.api.user.server.event.BeforeUserRemovedEvent)3 UserImpl (org.eclipse.che.api.user.server.model.impl.UserImpl)3 ServerException (org.eclipse.che.api.core.ServerException)2 Test (org.testng.annotations.Test)2 Transactional (com.google.inject.persist.Transactional)1 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 EntityManager (javax.persistence.EntityManager)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