Search in sources :

Example 36 with UserImpl

use of org.eclipse.che.api.user.server.model.impl.UserImpl 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)

Example 37 with UserImpl

use of org.eclipse.che.api.user.server.model.impl.UserImpl 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 38 with UserImpl

use of org.eclipse.che.api.user.server.model.impl.UserImpl in project che by eclipse.

the class UserDaoTest method shouldGetUserByAlias.

@Test
public void shouldGetUserByAlias() throws Exception {
    final UserImpl user = users[0];
    assertEqualsNoPassword(userDao.getByAlias(user.getAliases().get(0)), user);
}
Also used : UserImpl(org.eclipse.che.api.user.server.model.impl.UserImpl) Test(org.testng.annotations.Test)

Example 39 with UserImpl

use of org.eclipse.che.api.user.server.model.impl.UserImpl in project che by eclipse.

the class UserDaoTest method shouldThrowNotFoundExceptionIfUserWithSuchNameOrEmailDoesNotExist.

@Test(expectedExceptions = NotFoundException.class)
public void shouldThrowNotFoundExceptionIfUserWithSuchNameOrEmailDoesNotExist() throws Exception {
    final UserImpl user = users[0];
    userDao.getByAliasAndPassword(user.getId(), user.getPassword());
}
Also used : UserImpl(org.eclipse.che.api.user.server.model.impl.UserImpl) Test(org.testng.annotations.Test)

Example 40 with UserImpl

use of org.eclipse.che.api.user.server.model.impl.UserImpl in project che by eclipse.

the class UserDaoTest method shouldThrowConflictExceptionWhenCreatingUserWithExistingId.

@Test(expectedExceptions = ConflictException.class)
public void shouldThrowConflictExceptionWhenCreatingUserWithExistingId() throws Exception {
    final UserImpl newUser = new UserImpl(users[0].getId(), "user123@eclipse.org", "user_name", "password", asList("google:user123", "github:user123"));
    userDao.create(newUser);
}
Also used : UserImpl(org.eclipse.che.api.user.server.model.impl.UserImpl) Test(org.testng.annotations.Test)

Aggregations

UserImpl (org.eclipse.che.api.user.server.model.impl.UserImpl)65 Test (org.testng.annotations.Test)45 User (org.eclipse.che.api.core.model.user.User)13 Response (com.jayway.restassured.response.Response)10 BeforeMethod (org.testng.annotations.BeforeMethod)9 ServerException (org.eclipse.che.api.core.ServerException)8 Transactional (com.google.inject.persist.Transactional)6 ConflictException (org.eclipse.che.api.core.ConflictException)5 BeforeUserRemovedEvent (org.eclipse.che.api.user.server.event.BeforeUserRemovedEvent)5 EntityManager (javax.persistence.EntityManager)4 NotFoundException (org.eclipse.che.api.core.NotFoundException)4 Page (org.eclipse.che.api.core.Page)4 PostUserPersistedEvent (org.eclipse.che.api.user.server.event.PostUserPersistedEvent)4 ProfileImpl (org.eclipse.che.api.user.server.model.impl.ProfileImpl)4 UserDao (org.eclipse.che.api.user.server.spi.UserDao)4 ArrayList (java.util.ArrayList)3 Inject (javax.inject.Inject)3 UserRemovedEvent (org.eclipse.che.api.user.server.event.UserRemovedEvent)3 UserDto (org.eclipse.che.api.user.shared.dto.UserDto)3 TckRepository (org.eclipse.che.commons.test.tck.repository.TckRepository)3