Search in sources :

Example 6 with UserImpl

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

the class UserManagerTest method shouldGetAllUsers.

@Test
public void shouldGetAllUsers() throws Exception {
    final Page users = new Page(Arrays.asList(new UserImpl("identifier1", "test1@email.com", "testName1", "password", Collections.singletonList("alias1")), new UserImpl("identifier2", "test2@email.com", "testName2", "password", Collections.singletonList("alias2")), new UserImpl("identifier3", "test3@email.com", "testName3", "password", Collections.singletonList("alias3"))), 0, 30, 3);
    when(userDao.getAll(30, 0)).thenReturn(users);
    assertEquals(manager.getAll(30, 0), users);
    verify(userDao).getAll(30, 0);
}
Also used : UserImpl(org.eclipse.che.api.user.server.model.impl.UserImpl) Page(org.eclipse.che.api.core.Page) Test(org.testng.annotations.Test)

Example 7 with UserImpl

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

the class UserManagerTest method shouldTryToRollbackWhenEntityCreationFailed.

@Test(dataProvider = "rollback")
public void shouldTryToRollbackWhenEntityCreationFailed(Callable preAction) throws Exception {
    preAction.call();
    // Creating new user
    try {
        manager.create(new UserImpl(null, "test@email.com", "testName", null, null), false);
        fail("Had to throw Exception");
    } catch (Exception x) {
    // defined by userDao mock
    }
    // Capturing identifier
    final ArgumentCaptor<UserImpl> captor = ArgumentCaptor.forClass(UserImpl.class);
    verify(userDao).create(captor.capture());
    final String userId = captor.getValue().getId();
    // Verifying rollback
    verify(userDao).remove(userId);
    verify(preferencesDao).remove(userId);
    verify(profileDao).remove(userId);
}
Also used : UserImpl(org.eclipse.che.api.user.server.model.impl.UserImpl) Matchers.anyString(org.mockito.Matchers.anyString) ConflictException(org.eclipse.che.api.core.ConflictException) ServerException(org.eclipse.che.api.core.ServerException) Test(org.testng.annotations.Test)

Example 8 with UserImpl

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

the class UserManagerTest method shouldGetUserByEmail.

@Test
public void shouldGetUserByEmail() throws Exception {
    final User user = new UserImpl("identifier", "test@email.com", "testName", "password", Collections.singletonList("alias"));
    when(manager.getByEmail(user.getEmail())).thenReturn(user);
    assertEquals(manager.getByEmail(user.getEmail()), user);
}
Also used : User(org.eclipse.che.api.core.model.user.User) UserImpl(org.eclipse.che.api.user.server.model.impl.UserImpl) Test(org.testng.annotations.Test)

Example 9 with UserImpl

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

the class UserServiceTest method shouldUpdatePassword.

@Test
public void shouldUpdatePassword() throws Exception {
    final UserImpl testUser = copySubject();
    when(userManager.getById(testUser.getId())).thenReturn(testUser);
    final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).contentType("application/x-www-form-urlencoded").body("password=password12345").when().post(SECURE_PATH + "/user/password");
    verify(userManager).update(userCaptor.capture());
    final User fetchedUser = userCaptor.getValue();
    assertEquals(fetchedUser.getPassword(), "password12345");
}
Also used : Response(com.jayway.restassured.response.Response) User(org.eclipse.che.api.core.model.user.User) UserImpl(org.eclipse.che.api.user.server.model.impl.UserImpl) Test(org.testng.annotations.Test)

Example 10 with UserImpl

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

the class UserServiceTest method shouldNotUpdatePasswordIfPasswordContainsLessThan8Chars.

@Test
public void shouldNotUpdatePasswordIfPasswordContainsLessThan8Chars() throws Exception {
    final UserImpl testUser = copySubject();
    when(userManager.getById(testUser.getId())).thenReturn(testUser);
    final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).contentType("application/x-www-form-urlencoded").body("password=0xf").when().post(SECURE_PATH + "/user/password");
    assertEquals(response.getStatusCode(), 400);
    assertEquals(unwrapError(response), "Password should contain at least 8 characters");
}
Also used : Response(com.jayway.restassured.response.Response) 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