use of org.eclipse.che.account.spi.AccountImpl in project che by eclipse.
the class WorkspaceManagerTest method setUp.
@BeforeMethod
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
workspaceManager = new WorkspaceManager(workspaceDao, runtimes, eventService, accountManager, false, false, snapshotDao, sharedPool);
when(accountManager.getByName(NAMESPACE)).thenReturn(new AccountImpl("accountId", NAMESPACE, "test"));
when(accountManager.getByName(NAMESPACE_2)).thenReturn(new AccountImpl("accountId2", NAMESPACE_2, "test"));
when(workspaceDao.create(any(WorkspaceImpl.class))).thenAnswer(invocation -> invocation.getArguments()[0]);
when(workspaceDao.update(any(WorkspaceImpl.class))).thenAnswer(invocation -> invocation.getArguments()[0]);
EnvironmentContext.setCurrent(new EnvironmentContext() {
@Override
public Subject getSubject() {
return new SubjectImpl(NAMESPACE, USER_ID, "token", false);
}
});
}
use of org.eclipse.che.account.spi.AccountImpl in project che by eclipse.
the class DefaultWorkspaceValidatorTest method shouldFailValidationIfAttributeNameStartsWithWordCodenvy.
@Test(expectedExceptions = BadRequestException.class, expectedExceptionsMessageRegExp = "Attribute name '.*' is not valid")
public void shouldFailValidationIfAttributeNameStartsWithWordCodenvy() throws Exception {
final AccountImpl account = new AccountImpl("accountId", "namespace", "test");
final WorkspaceImpl workspace = new WorkspaceImpl("id", account, createConfig());
workspace.getAttributes().put("codenvy_key", "value1");
wsValidator.validateWorkspace(workspace);
}
use of org.eclipse.che.account.spi.AccountImpl 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());
}
use of org.eclipse.che.account.spi.AccountImpl in project che by eclipse.
the class WorkspaceManagerTest method createAndMockWorkspace.
private WorkspaceImpl createAndMockWorkspace(WorkspaceConfig cfg, String namespace) throws NotFoundException, ServerException {
WorkspaceImpl workspace = WorkspaceImpl.builder().generateId().setConfig(cfg).setAccount(new AccountImpl("id", namespace, "type")).setStatus(WorkspaceStatus.STOPPED).build();
when(workspaceDao.get(workspace.getId())).thenReturn(workspace);
when(workspaceDao.get(workspace.getConfig().getName(), workspace.getNamespace())).thenReturn(workspace);
when(workspaceDao.get(workspace.getConfig().getName(), NAMESPACE)).thenReturn(workspace);
when(workspaceDao.getByNamespace(workspace.getNamespace())).thenReturn(singletonList(workspace));
when(workspaceDao.getByNamespace(NAMESPACE)).thenReturn(singletonList(workspace));
when(workspaceDao.getWorkspaces(USER_ID)).thenReturn(singletonList(workspace));
return workspace;
}
use of org.eclipse.che.account.spi.AccountImpl in project che by eclipse.
the class WorkspaceDaoTest method createEntities.
@BeforeMethod
public void createEntities() throws TckRepositoryException {
accounts = new AccountImpl[COUNT_OF_ACCOUNTS];
for (int i = 0; i < COUNT_OF_ACCOUNTS; i++) {
accounts[i] = new AccountImpl("accountId" + i, "accountName" + i, "test");
}
workspaces = new WorkspaceImpl[COUNT_OF_WORKSPACES];
for (int i = 0; i < COUNT_OF_WORKSPACES; i++) {
// 2 workspaces share 1 namespace
workspaces[i] = createWorkspace("workspace-" + i, accounts[i / 2], "name-" + i);
}
accountRepo.createAll(Arrays.asList(accounts));
workspaceRepo.createAll(Stream.of(workspaces).map(WorkspaceImpl::new).collect(toList()));
}
Aggregations