use of org.eclipse.che.account.spi.AccountImpl in project che by eclipse.
the class WorkspaceDaoTest method shouldUpdateWorkspace.
@Test(dependsOnMethods = "shouldGetWorkspaceById")
public void shouldUpdateWorkspace() throws Exception {
final WorkspaceImpl workspace = new WorkspaceImpl(workspaces[0], workspaces[0].getAccount());
// Remove an existing project configuration from workspace
workspace.getConfig().getProjects().remove(1);
// Add new project to the workspace configuration
final SourceStorageImpl source3 = new SourceStorageImpl();
source3.setType("type3");
source3.setLocation("location3");
source3.setParameters(new HashMap<>(ImmutableMap.of("param1", "value1", "param2", "value2", "param3", "value3")));
final ProjectConfigImpl newProjectCfg = new ProjectConfigImpl();
newProjectCfg.setPath("/path3");
newProjectCfg.setType("type3");
newProjectCfg.setName("project3");
newProjectCfg.setDescription("description3");
newProjectCfg.getMixins().addAll(asList("mixin3", "mixin4"));
newProjectCfg.setSource(source3);
newProjectCfg.getAttributes().put("new-key", asList("1", "2"));
workspace.getConfig().getProjects().add(newProjectCfg);
// Update an existing project configuration
final ProjectConfigImpl projectCfg = workspace.getConfig().getProjects().get(0);
projectCfg.getAttributes().clear();
projectCfg.getSource().setLocation("new-location");
projectCfg.getSource().setType("new-type");
projectCfg.getSource().getParameters().put("new-param", "new-param-value");
projectCfg.getMixins().add("new-mixin");
projectCfg.setPath("/new-path");
projectCfg.setDescription("new project description");
// Remove an existing command
workspace.getConfig().getCommands().remove(1);
// Add a new command
final CommandImpl newCmd = new CommandImpl();
newCmd.setName("name3");
newCmd.setType("type3");
newCmd.setCommandLine("cmd3");
newCmd.getAttributes().putAll(ImmutableMap.of("attr1", "value1", "attr2", "value2", "attr3", "value3"));
workspace.getConfig().getCommands().add(newCmd);
// Update an existing command
final CommandImpl command = workspace.getConfig().getCommands().get(0);
command.setName("new-name");
command.setType("new-type");
command.setCommandLine("new-command-line");
command.getAttributes().clear();
// Add a new environment
final EnvironmentRecipeImpl newRecipe = new EnvironmentRecipeImpl();
newRecipe.setLocation("new-location");
newRecipe.setType("new-type");
newRecipe.setContentType("new-content-type");
newRecipe.setContent("new-content");
final ExtendedMachineImpl newMachine = new ExtendedMachineImpl();
final ServerConf2Impl serverConf1 = new ServerConf2Impl("2265", "http", singletonMap("prop1", "val"));
final ServerConf2Impl serverConf2 = new ServerConf2Impl("2266", "ftp", singletonMap("prop1", "val"));
newMachine.setServers(ImmutableMap.of("ref1", serverConf1, "ref2", serverConf2));
newMachine.setAgents(ImmutableList.of("agent5", "agent4"));
newMachine.setAttributes(singletonMap("att1", "val"));
final EnvironmentImpl newEnv = new EnvironmentImpl();
newEnv.setMachines(ImmutableMap.of("new-machine", newMachine));
newEnv.setRecipe(newRecipe);
workspace.getConfig().getEnvironments().put("new-env", newEnv);
// Update an existing environment
final EnvironmentImpl defaultEnv = workspace.getConfig().getEnvironments().get(workspace.getConfig().getDefaultEnv());
// Remove an existing machine config
final List<String> machineNames = new ArrayList<>(defaultEnv.getMachines().keySet());
// Update an existing machine
final ExtendedMachineImpl existingMachine = defaultEnv.getMachines().get(machineNames.get(1));
existingMachine.setAgents(asList("new-agent1", "new-agent2"));
existingMachine.setAttributes(ImmutableMap.of("attr1", "value1", "attr2", "value2", "attr3", "value3"));
existingMachine.getServers().clear();
existingMachine.getServers().put("new-ref", new ServerConf2Impl("new-port", "new-protocol", ImmutableMap.of("prop1", "value")));
defaultEnv.getMachines().remove(machineNames.get(0));
defaultEnv.getRecipe().setContent("updated-content");
defaultEnv.getRecipe().setContentType("updated-content-type");
defaultEnv.getRecipe().setLocation("updated-location");
defaultEnv.getRecipe().setType("updated-type");
// Remove an existing environment
final Optional<String> nonDefaultEnv = workspace.getConfig().getEnvironments().keySet().stream().filter(key -> !key.equals(workspace.getConfig().getDefaultEnv())).findAny();
assertTrue(nonDefaultEnv.isPresent());
workspace.getConfig().getEnvironments().remove(nonDefaultEnv.get());
// Update workspace configuration
final WorkspaceConfigImpl wCfg = workspace.getConfig();
wCfg.setDefaultEnv("new-env");
wCfg.setName("new-name");
wCfg.setDescription("This is a new description");
// Update workspace object
workspace.setAccount(new AccountImpl("accId", "new-namespace", "test"));
workspace.getAttributes().clear();
workspaceDao.update(workspace);
assertEquals(workspaceDao.get(workspace.getId()), new WorkspaceImpl(workspace, workspace.getAccount()));
}
use of org.eclipse.che.account.spi.AccountImpl in project che by eclipse.
the class DefaultWorkspaceValidatorTest method shouldFailValidationIfAttributeNameIsNull.
@Test(expectedExceptions = BadRequestException.class, expectedExceptionsMessageRegExp = "Attribute name 'null' is not valid")
public void shouldFailValidationIfAttributeNameIsNull() throws Exception {
final AccountImpl account = new AccountImpl("accountId", "namespace", "test");
final WorkspaceImpl workspace = new WorkspaceImpl("id", account, createConfig());
workspace.getAttributes().put(null, "value1");
wsValidator.validateWorkspace(workspace);
}
use of org.eclipse.che.account.spi.AccountImpl in project che by eclipse.
the class DefaultWorkspaceValidatorTest method shouldFailValidationIfAttributeNameIsEmpty.
@Test(expectedExceptions = BadRequestException.class, expectedExceptionsMessageRegExp = "Attribute name '' is not valid")
public void shouldFailValidationIfAttributeNameIsEmpty() throws Exception {
final AccountImpl account = new AccountImpl("accountId", "namespace", "test");
final WorkspaceImpl workspace = new WorkspaceImpl("id", account, createConfig());
workspace.getAttributes().put("", "value1");
wsValidator.validateWorkspace(workspace);
}
use of org.eclipse.che.account.spi.AccountImpl in project che by eclipse.
the class JpaTckModule method configure.
@Override
protected void configure() {
install(new JpaPersistModule("main"));
bind(DBInitializer.class).asEagerSingleton();
bind(SchemaInitializer.class).toInstance(new FlywaySchemaInitializer(H2TestHelper.inMemoryDefault(), "che-schema"));
bind(TckResourcesCleaner.class).to(H2JpaCleaner.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 TestWorkspacesTckRepository());
bind(new TypeLiteral<TckRepository<AccountImpl>>() {
}).toInstance(new JpaTckRepository<>(AccountImpl.class));
bind(RecipeDao.class).to(JpaRecipeDao.class);
bind(SnapshotDao.class).to(JpaSnapshotDao.class);
}
use of org.eclipse.che.account.spi.AccountImpl in project che by eclipse.
the class SnapshotDaoTest method createSnapshots.
@BeforeMethod
private void createSnapshots() throws TckRepositoryException {
// one account for all the workspaces
final AccountImpl account = new AccountImpl("account1", "name", "type");
// workspaces
workspaces = new TestWorkspace[SNAPSHOTS_SIZE / 3];
for (int i = 0; i < workspaces.length; i++) {
workspaces[i] = new TestWorkspace("workspace-" + i, account.getId());
}
// snapshots
snapshots = new SnapshotImpl[SNAPSHOTS_SIZE];
for (int i = 0; i < SNAPSHOTS_SIZE; i++) {
snapshots[i] = createSnapshot("snapshot-" + i, // 3 snapshot share the same workspace id
workspaces[i / 3].getId(), // 2 snapshots share the same env name
"environment-" + i / 2, "machine-" + i);
}
accountRepo.createAll(singletonList(account));
workspaceRepo.createAll(asList(workspaces));
snaphotRepo.createAll(asList(snapshots));
}
Aggregations