Search in sources :

Example 86 with ComponentImpl

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

the class PluginComponentToWorkspaceApplierTest method shouldProvisionPluginWorkspaceAttributeWithReferenceDuringChePluginComponentApplying.

@Test
public void shouldProvisionPluginWorkspaceAttributeWithReferenceDuringChePluginComponentApplying() throws Exception {
    String superPluginId = "eclipse/super-plugin/0.0.1";
    String reference = "https://myregistry.com/infolder/meta.yaml";
    String meta = "apiVersion: v2\n" + "publisher: eclipse\n" + "name: super-plugin\n" + "version: 0.0.1\n" + "type: Che Plugin";
    // given
    ComponentImpl superPluginComponent = new ComponentImpl();
    superPluginComponent.setAlias("super-plugin");
    superPluginComponent.setId(superPluginId);
    superPluginComponent.setType(PLUGIN_COMPONENT_TYPE);
    superPluginComponent.setMemoryLimit("1234M");
    when(fileContentProvider.fetchContent(anyString())).thenReturn(meta);
    ComponentImpl customPluginComponent = new ComponentImpl();
    customPluginComponent.setAlias("custom");
    customPluginComponent.setType(PLUGIN_COMPONENT_TYPE);
    customPluginComponent.setReference(reference);
    WorkspaceConfigImpl workspaceConfig = new WorkspaceConfigImpl();
    // when
    pluginComponentApplier.apply(workspaceConfig, superPluginComponent, fileContentProvider);
    pluginComponentApplier.apply(workspaceConfig, customPluginComponent, fileContentProvider);
    // then
    String workspaceTooling = workspaceConfig.getAttributes().get(WORKSPACE_TOOLING_PLUGINS_ATTRIBUTE);
    assertTrue(workspaceTooling.matches("(.+/.+/.+),(https://.+/.+/.+)"));
    assertTrue(workspaceTooling.contains(superPluginId));
    assertTrue(workspaceTooling.contains(reference));
    assertEquals(customPluginComponent.getId(), "eclipse/super-plugin/0.0.1");
}
Also used : WorkspaceConfigImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ComponentImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl) Test(org.testng.annotations.Test)

Example 87 with ComponentImpl

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

the class PluginComponentToWorkspaceApplierTest method shouldProvisionPluginCommandAttributeWhenIdIsURLToCustomPluginRegistry.

@Test
public void shouldProvisionPluginCommandAttributeWhenIdIsURLToCustomPluginRegistry() throws Exception {
    // given
    ComponentImpl superPluginComponent = new ComponentImpl();
    superPluginComponent.setAlias("super-plugin");
    superPluginComponent.setId("https://custom-plugin.registry/plugins/#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 88 with ComponentImpl

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

the class PluginComponentToWorkspaceApplierTest method shouldProvisionPluginWorkspaceAttributeDuringChePluginComponentApplying.

@Test
public void shouldProvisionPluginWorkspaceAttributeDuringChePluginComponentApplying() throws Exception {
    String superPluginId = "eclipse/super-plugin/0.0.1";
    // given
    ComponentImpl superPluginComponent = new ComponentImpl();
    superPluginComponent.setAlias("super-plugin");
    superPluginComponent.setId(superPluginId);
    superPluginComponent.setType(PLUGIN_COMPONENT_TYPE);
    superPluginComponent.setMemoryLimit("1234M");
    superPluginComponent.getPreferences().put("java-home", "/home/user/jdk11");
    ComponentImpl customPluginComponent = new ComponentImpl();
    customPluginComponent.setAlias("custom");
    customPluginComponent.setId("publisher1/custom-plugin/v1");
    customPluginComponent.setType(PLUGIN_COMPONENT_TYPE);
    WorkspaceConfigImpl workspaceConfig = new WorkspaceConfigImpl();
    // when
    pluginComponentApplier.apply(workspaceConfig, superPluginComponent, null);
    pluginComponentApplier.apply(workspaceConfig, customPluginComponent, null);
    // then
    String workspaceTooling = workspaceConfig.getAttributes().get(WORKSPACE_TOOLING_PLUGINS_ATTRIBUTE);
    assertTrue(workspaceTooling.matches("(.+/.+/.+),(.+/.+/.+)"));
    assertTrue(workspaceTooling.contains(superPluginId));
    assertTrue(workspaceTooling.contains("publisher1/custom-plugin/v1"));
}
Also used : WorkspaceConfigImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ComponentImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl) Test(org.testng.annotations.Test)

Example 89 with ComponentImpl

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

the class DevfileIntegrityValidatorTest method shouldRequireAliasWhenDockerImageComponentsHaveSameImage.

@Test(expectedExceptions = DevfileFormatException.class, expectedExceptionsMessageRegExp = "There are multiple components 'dockerimage:latest' of type 'dockerimage' that cannot be" + " uniquely identified. Please add aliases that would distinguish the components.")
public void shouldRequireAliasWhenDockerImageComponentsHaveSameImage() throws Exception {
    // given
    DevfileImpl devfile = new DevfileImpl(initialDevfile);
    ComponentImpl docker1 = new ComponentImpl();
    docker1.setType(DOCKERIMAGE_COMPONENT_TYPE);
    docker1.setImage("dockerimage:latest");
    ComponentImpl docker2 = new ComponentImpl();
    docker2.setType(DOCKERIMAGE_COMPONENT_TYPE);
    docker2.setImage("dockerimage:latest");
    devfile.getComponents().add(docker1);
    devfile.getComponents().add(docker2);
    // 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 90 with ComponentImpl

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

the class DevfileIntegrityValidatorTest method shouldThrowExceptionOnDuplicateEnvironmentVariable.

@Test(expectedExceptions = DevfileFormatException.class, expectedExceptionsMessageRegExp = "Duplicate environment variable 'foo' found in component 'test1'")
public void shouldThrowExceptionOnDuplicateEnvironmentVariable() throws Exception {
    DevfileImpl broken = new DevfileImpl(initialDevfile);
    ComponentImpl k8s1 = new ComponentImpl();
    k8s1.setType(OPENSHIFT_COMPONENT_TYPE);
    k8s1.setAlias("test1");
    k8s1.getEnv().add(new EnvImpl("foo", "bar"));
    k8s1.getEnv().add(new EnvImpl("foo", "baz"));
    broken.getComponents().add(k8s1);
    // when
    integrityValidator.validateDevfile(broken);
}
Also used : DevfileImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.DevfileImpl) EnvImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.EnvImpl) 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