Search in sources :

Example 61 with UserImpl

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

the class UserServiceTest method shouldNotFindUserByNameOrEmailWhenBothAreEmpty.

@Test
public void shouldNotFindUserByNameOrEmailWhenBothAreEmpty() throws Exception {
    final UserImpl testUser = copySubject();
    when(userManager.getByName(testUser.getName())).thenReturn(testUser);
    final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).when().get(SECURE_PATH + "/user/find");
    assertEquals(response.getStatusCode(), 400);
    assertEquals(unwrapError(response), "Missed user's email or name");
}
Also used : Response(com.jayway.restassured.response.Response) UserImpl(org.eclipse.che.api.user.server.model.impl.UserImpl) Test(org.testng.annotations.Test)

Example 62 with UserImpl

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

the class UserServiceTest method shouldBeAbleToFindUserByName.

@Test
public void shouldBeAbleToFindUserByName() throws Exception {
    final UserImpl testUser = copySubject();
    when(userManager.getByName(testUser.getName())).thenReturn(testUser);
    final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).when().get(SECURE_PATH + "/user/find?name=" + testUser.getName());
    assertEquals(response.getStatusCode(), 200);
    final UserDto fetchedUser = unwrapDto(response, UserDto.class);
    assertEquals(fetchedUser.getId(), testUser.getId());
    assertEquals(fetchedUser.getName(), testUser.getName());
    assertEquals(fetchedUser.getEmail(), testUser.getEmail());
}
Also used : Response(com.jayway.restassured.response.Response) UserDto(org.eclipse.che.api.user.shared.dto.UserDto) UserImpl(org.eclipse.che.api.user.server.model.impl.UserImpl) Test(org.testng.annotations.Test)

Example 63 with UserImpl

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

the class UserServiceTest method shouldNotUpdatePasswordIfPasswordContainsOnlyDigits.

@Test
public void shouldNotUpdatePasswordIfPasswordContainsOnlyDigits() 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=1234567890").when().post(SECURE_PATH + "/user/password");
    assertEquals(response.getStatusCode(), 400);
    assertEquals(unwrapError(response), "Password should contain letters and digits");
}
Also used : Response(com.jayway.restassured.response.Response) UserImpl(org.eclipse.che.api.user.server.model.impl.UserImpl) Test(org.testng.annotations.Test)

Example 64 with UserImpl

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

the class UserServiceTest method shouldNotFindUserByNameOrEmailWhenBothSpecified.

@Test
public void shouldNotFindUserByNameOrEmailWhenBothSpecified() throws Exception {
    final UserImpl testUser = copySubject();
    when(userManager.getByName(testUser.getName())).thenReturn(testUser);
    final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).when().get(SECURE_PATH + "/user/find?" + "name=" + testUser.getName() + "&email=" + testUser.getEmail());
    assertEquals(response.getStatusCode(), 400);
    assertEquals(unwrapError(response), "Expected either user's email or name, while both values received");
}
Also used : Response(com.jayway.restassured.response.Response) UserImpl(org.eclipse.che.api.user.server.model.impl.UserImpl) Test(org.testng.annotations.Test)

Example 65 with UserImpl

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

the class PostgreSqlTckModule method configure.

@Override
protected void configure() {
    final String dbUrl = System.getProperty("jdbc.url");
    final String dbUser = System.getProperty("jdbc.user");
    final String dbPassword = System.getProperty("jdbc.password");
    waitConnectionIsEstablished(dbUrl, dbUser, dbPassword);
    // jpa
    install(new PersistTestModuleBuilder().setDriver(Driver.class).setUrl(dbUrl).setUser(dbUser).setPassword(dbPassword).setExceptionHandler(PostgreSqlExceptionHandler.class).addEntityClasses(AccountImpl.class, UserImpl.class, ProfileImpl.class, PreferenceEntity.class, WorkspaceImpl.class, WorkspaceConfigImpl.class, ProjectConfigImpl.class, EnvironmentImpl.class, EnvironmentRecipeImpl.class, ExtendedMachineImpl.class, SourceStorageImpl.class, ServerConf2Impl.class, StackImpl.class, CommandImpl.class, SnapshotImpl.class, RecipeImpl.class, SshPairImpl.class).addEntityClass("org.eclipse.che.api.workspace.server.model.impl.ProjectConfigImpl$Attribute").build());
    bind(TckResourcesCleaner.class).to(JpaCleaner.class);
    // db initialization
    bind(DBInitializer.class).asEagerSingleton();
    final PGSimpleDataSource dataSource = new PGSimpleDataSource();
    dataSource.setUser(dbUser);
    dataSource.setPassword(dbPassword);
    dataSource.setUrl(dbUrl);
    bind(SchemaInitializer.class).toInstance(new FlywaySchemaInitializer(dataSource, "che-schema"));
    // account
    bind(AccountDao.class).to(JpaAccountDao.class);
    bind(new TypeLiteral<TckRepository<AccountImpl>>() {
    }).toInstance(new JpaTckRepository<>(AccountImpl.class));
    // user
    bind(UserDao.class).to(JpaUserDao.class);
    bind(ProfileDao.class).to(JpaProfileDao.class);
    bind(PreferenceDao.class).to(JpaPreferenceDao.class);
    bind(new TypeLiteral<TckRepository<UserImpl>>() {
    }).to(UserRepo.class);
    bind(new TypeLiteral<TckRepository<Pair<String, Map<String, String>>>>() {
    }).to(PreferencesRepo.class);
    bind(new TypeLiteral<TckRepository<ProfileImpl>>() {
    }).toInstance(new JpaTckRepository<>(ProfileImpl.class));
    bind(PasswordEncryptor.class).to(SHA512PasswordEncryptor.class);
    // machine
    bind(RecipeDao.class).to(JpaRecipeDao.class);
    bind(SnapshotDao.class).to(JpaSnapshotDao.class);
    bind(new TypeLiteral<TckRepository<RecipeImpl>>() {
    }).toInstance(new JpaTckRepository<>(RecipeImpl.class));
    bind(new TypeLiteral<TckRepository<SnapshotImpl>>() {
    }).toInstance(new JpaTckRepository<>(SnapshotImpl.class));
    bind(new TypeLiteral<TckRepository<Workspace>>() {
    }).toInstance(new WorkspaceRepoForSnapshots());
    // ssh
    bind(SshDao.class).to(JpaSshDao.class);
    bind(new TypeLiteral<TckRepository<SshPairImpl>>() {
    }).toInstance(new JpaTckRepository<>(SshPairImpl.class));
    // workspace
    bind(WorkspaceDao.class).to(JpaWorkspaceDao.class);
    bind(StackDao.class).to(JpaStackDao.class);
    bind(new TypeLiteral<TckRepository<WorkspaceImpl>>() {
    }).toInstance(new WorkspaceRepository());
    bind(new TypeLiteral<TckRepository<StackImpl>>() {
    }).toInstance(new StackRepository());
}
Also used : TckResourcesCleaner(org.eclipse.che.commons.test.tck.TckResourcesCleaner) WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) StackImpl(org.eclipse.che.api.workspace.server.model.impl.stack.StackImpl) SshPairImpl(org.eclipse.che.api.ssh.server.model.impl.SshPairImpl) PreferenceEntity(org.eclipse.che.api.user.server.jpa.PreferenceEntity) AccountImpl(org.eclipse.che.account.spi.AccountImpl) EnvironmentImpl(org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl) SchemaInitializer(org.eclipse.che.core.db.schema.SchemaInitializer) FlywaySchemaInitializer(org.eclipse.che.core.db.schema.impl.flyway.FlywaySchemaInitializer) FlywaySchemaInitializer(org.eclipse.che.core.db.schema.impl.flyway.FlywaySchemaInitializer) JpaProfileDao(org.eclipse.che.api.user.server.jpa.JpaProfileDao) ProfileDao(org.eclipse.che.api.user.server.spi.ProfileDao) JpaSnapshotDao(org.eclipse.che.api.machine.server.jpa.JpaSnapshotDao) SnapshotDao(org.eclipse.che.api.machine.server.spi.SnapshotDao) ServerConf2Impl(org.eclipse.che.api.workspace.server.model.impl.ServerConf2Impl) TypeLiteral(com.google.inject.TypeLiteral) UserDao(org.eclipse.che.api.user.server.spi.UserDao) JpaUserDao(org.eclipse.che.api.user.server.jpa.JpaUserDao) DBInitializer(org.eclipse.che.core.db.DBInitializer) JpaRecipeDao(org.eclipse.che.api.machine.server.jpa.JpaRecipeDao) RecipeDao(org.eclipse.che.api.machine.server.spi.RecipeDao) ExtendedMachineImpl(org.eclipse.che.api.workspace.server.model.impl.ExtendedMachineImpl) UserImpl(org.eclipse.che.api.user.server.model.impl.UserImpl) WorkspaceConfigImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl) PGSimpleDataSource(org.postgresql.ds.PGSimpleDataSource) EnvironmentRecipeImpl(org.eclipse.che.api.workspace.server.model.impl.EnvironmentRecipeImpl) Pair(org.eclipse.che.commons.lang.Pair) CommandImpl(org.eclipse.che.api.machine.server.model.impl.CommandImpl) SnapshotImpl(org.eclipse.che.api.machine.server.model.impl.SnapshotImpl) PasswordEncryptor(org.eclipse.che.security.PasswordEncryptor) SHA512PasswordEncryptor(org.eclipse.che.security.SHA512PasswordEncryptor) AccountDao(org.eclipse.che.account.spi.AccountDao) JpaAccountDao(org.eclipse.che.account.spi.jpa.JpaAccountDao) JpaPreferenceDao(org.eclipse.che.api.user.server.jpa.JpaPreferenceDao) PreferenceDao(org.eclipse.che.api.user.server.spi.PreferenceDao) SshDao(org.eclipse.che.api.ssh.server.spi.SshDao) JpaSshDao(org.eclipse.che.api.ssh.server.jpa.JpaSshDao) SourceStorageImpl(org.eclipse.che.api.workspace.server.model.impl.SourceStorageImpl) PersistTestModuleBuilder(org.eclipse.che.commons.test.db.PersistTestModuleBuilder) ProfileImpl(org.eclipse.che.api.user.server.model.impl.ProfileImpl) JpaStackDao(org.eclipse.che.api.workspace.server.jpa.JpaStackDao) StackDao(org.eclipse.che.api.workspace.server.spi.StackDao) RecipeImpl(org.eclipse.che.api.machine.server.recipe.RecipeImpl) EnvironmentRecipeImpl(org.eclipse.che.api.workspace.server.model.impl.EnvironmentRecipeImpl) JpaWorkspaceDao(org.eclipse.che.api.workspace.server.jpa.JpaWorkspaceDao) WorkspaceDao(org.eclipse.che.api.workspace.server.spi.WorkspaceDao) ProjectConfigImpl(org.eclipse.che.api.workspace.server.model.impl.ProjectConfigImpl) Workspace(org.eclipse.che.api.core.model.workspace.Workspace)

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