Search in sources :

Example 56 with ComponentImpl

use of org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl in project che-server by eclipse-che.

the class PluginComponentToWorkspaceApplierTest method shouldProvisionPluginCommandAttributesDuringChePluginComponentApplying.

@Test
public void shouldProvisionPluginCommandAttributesDuringChePluginComponentApplying() throws Exception {
    // given
    ComponentImpl superPluginComponent = new ComponentImpl();
    superPluginComponent.setAlias("super-plugin");
    superPluginComponent.setId("eclipse/super-plugin/0.0.1");
    superPluginComponent.setType(PLUGIN_COMPONENT_TYPE);
    WorkspaceConfigImpl workspaceConfig = new WorkspaceConfigImpl();
    CommandImpl command = new CommandImpl();
    command.getAttributes().put(COMPONENT_ALIAS_COMMAND_ATTRIBUTE, "super-plugin");
    workspaceConfig.getCommands().add(command);
    // when
    pluginComponentApplier.apply(workspaceConfig, superPluginComponent, null);
    // then
    assertEquals(workspaceConfig.getCommands().get(0).getAttributes().get(PLUGIN_ATTRIBUTE), "eclipse/super-plugin/0.0.1");
}
Also used : CommandImpl(org.eclipse.che.api.workspace.server.model.impl.CommandImpl) WorkspaceConfigImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl) ComponentImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl) Test(org.testng.annotations.Test)

Example 57 with ComponentImpl

use of org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl in project che-server by eclipse-che.

the class DevfileIntegrityValidatorTest method shouldThrowExceptionOnMultipleEditors.

@Test(expectedExceptions = DevfileFormatException.class, expectedExceptionsMessageRegExp = "Multiple editor components found: 'eclipse/che-theia/0.0.3', 'editor-2'")
public void shouldThrowExceptionOnMultipleEditors() throws Exception {
    DevfileImpl broken = new DevfileImpl(initialDevfile);
    ComponentImpl component = new ComponentImpl();
    component.setAlias("editor-2");
    component.setType(EDITOR_COMPONENT_TYPE);
    broken.getComponents().add(component);
    // when
    integrityValidator.validateDevfile(broken);
}
Also used : DevfileImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.DevfileImpl) ComponentImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl) Test(org.testng.annotations.Test)

Example 58 with ComponentImpl

use of org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl in project che-server by eclipse-che.

the class WorkspaceDaoTest method shouldUpdateWorkspaceWithDevfile.

@Test(dependsOnMethods = "shouldGetWorkspaceById")
public void shouldUpdateWorkspaceWithDevfile() throws Exception {
    final WorkspaceImpl workspace = new WorkspaceImpl(workspaces[DEVFILE_WORKSPACE_INDEX], workspaces[DEVFILE_WORKSPACE_INDEX].getAccount());
    // Remove an existing project configuration from workspace
    workspace.getDevfile().getProjects().remove(1);
    final SourceImpl source3 = new SourceImpl("type3", "http://location", "branch3", "point3", "tag3", "commit3", "sparseCheckoutDir3");
    ProjectImpl newProject = new ProjectImpl("project3", source3, "path3");
    workspace.getDevfile().getProjects().add(newProject);
    // Update an existing project configuration
    final ProjectImpl projectCfg = workspace.getDevfile().getProjects().get(0);
    projectCfg.getSource().setLocation("new-location");
    projectCfg.getSource().setType("new-type");
    projectCfg.getSource().setBranch("new-branch");
    projectCfg.getSource().setCommitId("new-commit");
    projectCfg.getSource().setTag("new-tag");
    projectCfg.getSource().setStartPoint("new-point");
    projectCfg.getSource().setSparseCheckoutDir("new-sparse-checkout-dir");
    // Remove an existing command
    workspace.getDevfile().getCommands().remove(1);
    ActionImpl action3 = new ActionImpl("exec3", "component3", "run.sh", "/home/user/3", null, null);
    ActionImpl action4 = new ActionImpl("exec4", "component4", "run.sh", "/home/user/4", null, null);
    // Add a new command
    final org.eclipse.che.api.workspace.server.model.impl.devfile.CommandImpl newCmd = new org.eclipse.che.api.workspace.server.model.impl.devfile.CommandImpl("command-3", singletonList(action3), singletonMap("attr3", "value3"), null);
    workspace.getDevfile().getCommands().add(newCmd);
    // Update an existing command
    final org.eclipse.che.api.workspace.server.model.impl.devfile.CommandImpl command = workspace.getDevfile().getCommands().get(0);
    command.setName("new-name");
    command.setActions(asList(action4));
    command.getAttributes().clear();
    workspace.getDevfile().getComponents().remove(1);
    EntrypointImpl entrypoint3 = new EntrypointImpl("parentName", singletonMap("parent3", "selector3"), "containerName3", asList("command3", "command5"), asList("arg3", "arg5"));
    org.eclipse.che.api.workspace.server.model.impl.devfile.VolumeImpl volume3 = new org.eclipse.che.api.workspace.server.model.impl.devfile.VolumeImpl("name3", "path3");
    EnvImpl env3 = new EnvImpl("name3", "value3");
    EndpointImpl endpoint3 = new EndpointImpl("name3", 3333, singletonMap("key3", "value3"));
    ComponentImpl component3 = workspace.getDevfile().getComponents().get(0);
    new ComponentImpl("kubernetes", "component3", "eclipse/che-theia/0.0.1", ImmutableMap.of("java.home", "/opt/jdk11"), "https://mysite.com/registry/somepath", "/dev.yaml", null, ImmutableMap.of("app.kubernetes.io/component", "webapp"), singletonList(entrypoint3), "image", "1256G", "123G", "2", "1", false, false, singletonList("command"), singletonList("arg"), singletonList(volume3), singletonList(env3), singletonList(endpoint3));
    component3.setSelector(singletonMap("key3", "value3"));
    // 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()));
}
Also used : CommandImpl(org.eclipse.che.api.workspace.server.model.impl.CommandImpl) WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) EntrypointImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.EntrypointImpl) ProjectImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.ProjectImpl) EndpointImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.EndpointImpl) AccountImpl(org.eclipse.che.account.spi.AccountImpl) EnvImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.EnvImpl) ComponentImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl) SourceImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.SourceImpl) ActionImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.ActionImpl) VolumeImpl(org.eclipse.che.api.workspace.server.model.impl.VolumeImpl) Test(org.testng.annotations.Test)

Example 59 with ComponentImpl

use of org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl in project che-server by eclipse-che.

the class DevfileIntegrityValidatorTest method shouldRequireAliasWhenOpenshiftComponentsHaveNoReference.

@Test(expectedExceptions = DevfileFormatException.class, expectedExceptionsMessageRegExp = "There are multiple components 'openshift' of type 'openshift' that cannot be" + " uniquely identified. Please add aliases that would distinguish the components.")
public void shouldRequireAliasWhenOpenshiftComponentsHaveNoReference() throws Exception {
    // given
    DevfileImpl devfile = new DevfileImpl(initialDevfile);
    ComponentImpl k8s1 = new ComponentImpl();
    k8s1.setType(OPENSHIFT_COMPONENT_TYPE);
    ComponentImpl k8s2 = new ComponentImpl();
    k8s2.setType(OPENSHIFT_COMPONENT_TYPE);
    devfile.getComponents().add(k8s1);
    devfile.getComponents().add(k8s2);
    // when
    integrityValidator.validateDevfile(devfile);
// then
// exception is thrown
}
Also used : DevfileImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.DevfileImpl) ComponentImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl) Test(org.testng.annotations.Test)

Example 60 with ComponentImpl

use of org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl in project che-server by eclipse-che.

the class DevfileIntegrityValidatorTest method shouldThrowExceptionOnDuplicateComponentAlias.

@Test(expectedExceptions = DevfileFormatException.class, expectedExceptionsMessageRegExp = "Duplicate component alias found:'mvn-stack'")
public void shouldThrowExceptionOnDuplicateComponentAlias() throws Exception {
    DevfileImpl broken = new DevfileImpl(initialDevfile);
    ComponentImpl component = new ComponentImpl();
    component.setAlias(initialDevfile.getComponents().get(0).getAlias());
    broken.getComponents().add(component);
    // when
    integrityValidator.validateDevfile(broken);
}
Also used : DevfileImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.DevfileImpl) ComponentImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl) Test(org.testng.annotations.Test)

Aggregations

ComponentImpl (org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl)218 Test (org.testng.annotations.Test)184 DevfileImpl (org.eclipse.che.api.workspace.server.model.impl.devfile.DevfileImpl)76 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)56 Container (io.fabric8.kubernetes.api.model.Container)48 MachineConfigImpl (org.eclipse.che.api.workspace.server.model.impl.MachineConfigImpl)44 EndpointImpl (org.eclipse.che.api.workspace.server.model.impl.devfile.EndpointImpl)42 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)38 WorkspaceConfigImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl)36 CommandImpl (org.eclipse.che.api.workspace.server.model.impl.CommandImpl)26 EntrypointImpl (org.eclipse.che.api.workspace.server.model.impl.devfile.EntrypointImpl)26 Map (java.util.Map)24 EnvImpl (org.eclipse.che.api.workspace.server.model.impl.devfile.EnvImpl)24 PodBuilder (io.fabric8.kubernetes.api.model.PodBuilder)22 Deployment (io.fabric8.kubernetes.api.model.apps.Deployment)20 Collections.emptyMap (java.util.Collections.emptyMap)18 DevfileException (org.eclipse.che.api.workspace.server.devfile.exception.DevfileException)18 ImmutableMap (com.google.common.collect.ImmutableMap)16 ArrayList (java.util.ArrayList)14 List (java.util.List)14