Search in sources :

Example 1 with PostUserPersistedEvent

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

the class UserDaoTest method shouldNotCreateUserWhenSubscriberThrowsExceptionOnUserStoring.

@Test(dependsOnMethods = "shouldThrowNotFoundExceptionWhenGettingNonExistingUserById", expectedExceptions = NotFoundException.class)
public void shouldNotCreateUserWhenSubscriberThrowsExceptionOnUserStoring() throws Exception {
    final UserImpl newUser = new UserImpl("user123", "user123@eclipse.org", "user_name", "password", asList("google:user123", "github:user123"));
    CascadeEventSubscriber<PostUserPersistedEvent> subscriber = mockCascadeEventSubscriber();
    doThrow(new ConflictException("error")).when(subscriber).onCascadeEvent(any());
    eventService.subscribe(subscriber, PostUserPersistedEvent.class);
    try {
        userDao.create(newUser);
        fail("UserDao#create had to throw conflict exception");
    } catch (ConflictException ignored) {
    }
    eventService.unsubscribe(subscriber, PostUserPersistedEvent.class);
    userDao.getById(newUser.getId());
}
Also used : PostUserPersistedEvent(org.eclipse.che.api.user.server.event.PostUserPersistedEvent) ConflictException(org.eclipse.che.api.core.ConflictException) UserImpl(org.eclipse.che.api.user.server.model.impl.UserImpl) Test(org.testng.annotations.Test)

Example 2 with PostUserPersistedEvent

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

the class JpaUserDao method doCreate.

@Transactional(rollbackOn = { RuntimeException.class, ApiException.class })
protected void doCreate(UserImpl user) throws ConflictException, ServerException {
    EntityManager manage = managerProvider.get();
    manage.persist(user);
    manage.flush();
    eventService.publish(new PostUserPersistedEvent(new UserImpl(user))).propagateException();
}
Also used : EntityManager(javax.persistence.EntityManager) PostUserPersistedEvent(org.eclipse.che.api.user.server.event.PostUserPersistedEvent) UserImpl(org.eclipse.che.api.user.server.model.impl.UserImpl) Transactional(com.google.inject.persist.Transactional)

Aggregations

PostUserPersistedEvent (org.eclipse.che.api.user.server.event.PostUserPersistedEvent)2 UserImpl (org.eclipse.che.api.user.server.model.impl.UserImpl)2 Transactional (com.google.inject.persist.Transactional)1 EntityManager (javax.persistence.EntityManager)1 ConflictException (org.eclipse.che.api.core.ConflictException)1 Test (org.testng.annotations.Test)1