Search in sources :

Example 36 with RecipeImpl

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

the class URLFactoryBuilderTest method checkWithCustomDevfileAndRecipe.

@Test
public void checkWithCustomDevfileAndRecipe() throws Exception {
    DevfileImpl devfile = new DevfileImpl();
    WorkspaceConfigImpl workspaceConfigImpl = new WorkspaceConfigImpl();
    String myLocation = "http://foo-location/";
    RecipeImpl expectedRecipe = new RecipeImpl(KUBERNETES_COMPONENT_TYPE, "application/x-yaml", "content", "");
    EnvironmentImpl expectedEnv = new EnvironmentImpl(expectedRecipe, emptyMap());
    workspaceConfigImpl.setEnvironments(singletonMap("name", expectedEnv));
    workspaceConfigImpl.setDefaultEnv("name");
    when(devfileParser.parseYamlRaw(anyString())).thenReturn(new ObjectNode(JsonNodeFactory.instance));
    when(devfileParser.parseJsonNode(any(JsonNode.class), anyMap())).thenReturn(devfile);
    when(devfileVersionDetector.devfileMajorVersion(any(JsonNode.class))).thenReturn(1);
    FactoryMetaDto factory = urlFactoryBuilder.createFactoryFromDevfile(new DefaultFactoryUrl().withDevfileFileLocation(myLocation), s -> myLocation + ".list", emptyMap()).get();
    assertNotNull(factory);
    assertNull(factory.getSource());
    assertTrue(factory instanceof FactoryDto);
}
Also used : UnknownScmProviderException(org.eclipse.che.api.factory.server.scm.exception.UnknownScmProviderException) Listeners(org.testng.annotations.Listeners) EnvironmentImpl(org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl) WorkspaceConfigImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl) Test(org.testng.annotations.Test) Collections.singletonList(java.util.Collections.singletonList) FactoryDto(org.eclipse.che.api.factory.shared.dto.FactoryDto) DevfileLocation(org.eclipse.che.api.factory.server.urlfactory.RemoteFactoryUrl.DevfileLocation) DevfileVersionDetector(org.eclipse.che.api.workspace.server.devfile.DevfileVersionDetector) FactoryMetaDto(org.eclipse.che.api.factory.shared.dto.FactoryMetaDto) Map(java.util.Map) JsonNode(com.fasterxml.jackson.databind.JsonNode) UnauthorizedException(org.eclipse.che.api.core.UnauthorizedException) MockitoTestNGListener(org.mockito.testng.MockitoTestNGListener) WORKSPACE_TOOLING_PLUGINS_ATTRIBUTE(org.eclipse.che.api.workspace.shared.Constants.WORKSPACE_TOOLING_PLUGINS_ATTRIBUTE) DtoFactory.newDto(org.eclipse.che.dto.server.DtoFactory.newDto) BeforeMethod(org.testng.annotations.BeforeMethod) Assert.assertNotNull(org.testng.Assert.assertNotNull) MetadataImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.MetadataImpl) List(java.util.List) JsonNodeFactory(com.fasterxml.jackson.databind.node.JsonNodeFactory) Optional(java.util.Optional) FactoryDevfileV2Dto(org.eclipse.che.api.factory.shared.dto.FactoryDevfileV2Dto) RecipeImpl(org.eclipse.che.api.workspace.server.model.impl.RecipeImpl) Mockito.mock(org.mockito.Mockito.mock) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) KUBERNETES_COMPONENT_TYPE(org.eclipse.che.api.workspace.server.devfile.Constants.KUBERNETES_COMPONENT_TYPE) Assert.assertNull(org.testng.Assert.assertNull) DataProvider(org.testng.annotations.DataProvider) URLFetcher(org.eclipse.che.api.workspace.server.devfile.URLFetcher) ScmCommunicationException(org.eclipse.che.api.factory.server.scm.exception.ScmCommunicationException) Mock(org.mockito.Mock) DevfileException(org.eclipse.che.api.workspace.server.devfile.exception.DevfileException) Assert.assertEquals(org.testng.Assert.assertEquals) ArgumentMatchers.anyMap(org.mockito.ArgumentMatchers.anyMap) HashMap(java.util.HashMap) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) DevfileParser(org.eclipse.che.api.workspace.server.devfile.DevfileParser) ApiException(org.eclipse.che.api.core.ApiException) DevfileImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.DevfileImpl) Collections.singletonMap(java.util.Collections.singletonMap) ExtendedError(org.eclipse.che.api.core.rest.shared.dto.ExtendedError) Collections.emptyMap(java.util.Collections.emptyMap) WorkspaceConfigDto(org.eclipse.che.api.workspace.shared.dto.WorkspaceConfigDto) IOException(java.io.IOException) Mockito.when(org.mockito.Mockito.when) WORKSPACE_TOOLING_EDITOR_ATTRIBUTE(org.eclipse.che.api.workspace.shared.Constants.WORKSPACE_TOOLING_EDITOR_ATTRIBUTE) FileContentProvider(org.eclipse.che.api.workspace.server.devfile.FileContentProvider) ScmUnauthorizedException(org.eclipse.che.api.factory.server.scm.exception.ScmUnauthorizedException) ServerException(org.eclipse.che.api.core.ServerException) OverrideParameterException(org.eclipse.che.api.workspace.server.devfile.exception.OverrideParameterException) Assert.assertTrue(org.testng.Assert.assertTrue) Collections(java.util.Collections) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) DevfileImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.DevfileImpl) RecipeImpl(org.eclipse.che.api.workspace.server.model.impl.RecipeImpl) FactoryMetaDto(org.eclipse.che.api.factory.shared.dto.FactoryMetaDto) FactoryDto(org.eclipse.che.api.factory.shared.dto.FactoryDto) WorkspaceConfigImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl) EnvironmentImpl(org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl) JsonNode(com.fasterxml.jackson.databind.JsonNode) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.testng.annotations.Test)

Example 37 with RecipeImpl

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

the class WorkspaceManagerTest method createConfig.

private static WorkspaceConfigImpl createConfig() {
    MachineConfigImpl machineConfig = new MachineConfigImpl(singletonMap("server", createServerConfig()), singletonMap("CHE_ENV", "value"), singletonMap(MEMORY_LIMIT_ATTRIBUTE, "10000"), emptyMap());
    EnvironmentImpl environment = new EnvironmentImpl(new RecipeImpl("type", "contentType", "content", null), singletonMap("dev-machine", machineConfig));
    return WorkspaceConfigImpl.builder().setName("dev-workspace").setDefaultEnv("dev-env").setEnvironments(singletonMap("dev-env", environment)).setCommands(asList(createCommand(), createCommand())).build();
}
Also used : MachineConfigImpl(org.eclipse.che.api.workspace.server.model.impl.MachineConfigImpl) RecipeImpl(org.eclipse.che.api.workspace.server.model.impl.RecipeImpl) EnvironmentImpl(org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl)

Example 38 with RecipeImpl

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

the class WorkspaceDaoTest method createWorkspaceConfig.

public static WorkspaceConfigImpl createWorkspaceConfig(String name) {
    // Project Sources configuration
    final SourceStorageImpl source1 = new SourceStorageImpl();
    source1.setType("type1");
    source1.setLocation("location1");
    source1.setParameters(new HashMap<>(ImmutableMap.of("param1", "value1", "param2", "value2", "param3", "value3")));
    final SourceStorageImpl source2 = new SourceStorageImpl();
    source2.setType("type2");
    source2.setLocation("location2");
    source2.setParameters(new HashMap<>(ImmutableMap.of("param4", "value1", "param5", "value2", "param6", "value3")));
    // Project Configuration
    final ProjectConfigImpl pCfg1 = new ProjectConfigImpl();
    pCfg1.setPath("/path1");
    pCfg1.setType("type1");
    pCfg1.setName("project1");
    pCfg1.setDescription("description1");
    pCfg1.getMixins().addAll(asList("mixin1", "mixin2"));
    pCfg1.setSource(source1);
    pCfg1.getAttributes().putAll(ImmutableMap.of("key1", asList("v1", "v2"), "key2", asList("v1", "v2")));
    final ProjectConfigImpl pCfg2 = new ProjectConfigImpl();
    pCfg2.setPath("/path2");
    pCfg2.setType("type2");
    pCfg2.setName("project2");
    pCfg2.setDescription("description2");
    pCfg2.getMixins().addAll(asList("mixin3", "mixin4"));
    pCfg2.setSource(source2);
    pCfg2.getAttributes().putAll(ImmutableMap.of("key3", asList("v1", "v2"), "key4", asList("v1", "v2")));
    final List<ProjectConfigImpl> projects = new ArrayList<>(asList(pCfg1, pCfg2));
    // Commands
    final CommandImpl cmd1 = new CommandImpl("name1", "cmd1", "type1");
    cmd1.getAttributes().putAll(ImmutableMap.of("key1", "value1", "key2", "value2", "key3", "value3"));
    final CommandImpl cmd2 = new CommandImpl("name2", "cmd2", "type2");
    cmd2.getAttributes().putAll(ImmutableMap.of("key4", "value4", "key5", "value5", "key6", "value6"));
    final List<CommandImpl> commands = new ArrayList<>(asList(cmd1, cmd2));
    // OldMachine configs
    final MachineConfigImpl exMachine1 = new MachineConfigImpl();
    final ServerConfigImpl serverConf1 = new ServerConfigImpl("2265", "http", "path1", singletonMap("key", "value"));
    final ServerConfigImpl serverConf2 = new ServerConfigImpl("2266", "ftp", "path2", singletonMap("key", "value"));
    exMachine1.setServers(ImmutableMap.of("ref1", serverConf1, "ref2", serverConf2));
    exMachine1.setAttributes(singletonMap("att1", "val"));
    exMachine1.setEnv(ImmutableMap.of("CHE_ENV1", "value", "CHE_ENV2", "value"));
    exMachine1.setVolumes(ImmutableMap.of("vol1", new VolumeImpl().withPath("/path/1"), "vol2", new VolumeImpl().withPath("/path/2")));
    final MachineConfigImpl exMachine2 = new MachineConfigImpl();
    final ServerConfigImpl serverConf3 = new ServerConfigImpl("2333", "https", "path3", singletonMap("key", "value"));
    final ServerConfigImpl serverConf4 = new ServerConfigImpl("2334", "wss", "path4", singletonMap("key", "value"));
    exMachine2.setServers(ImmutableMap.of("ref1", serverConf3, "ref2", serverConf4));
    exMachine2.setAttributes(singletonMap("att1", "val"));
    exMachine2.setEnv(singletonMap("CHE_ENV2", "value"));
    exMachine2.setVolumes(ImmutableMap.of("vol2", new VolumeImpl().withPath("/path/2")));
    final MachineConfigImpl exMachine3 = new MachineConfigImpl();
    final ServerConfigImpl serverConf5 = new ServerConfigImpl("2333", "https", "path5", singletonMap("key", "value"));
    exMachine3.setServers(singletonMap("ref1", serverConf5));
    exMachine3.setAttributes(singletonMap("att1", "val"));
    exMachine3.setEnv(singletonMap("CHE_ENV3", "value"));
    exMachine3.setVolumes(ImmutableMap.of("vol3", new VolumeImpl().withPath("/path/3")));
    // Environments
    final RecipeImpl recipe1 = new RecipeImpl();
    recipe1.setLocation("https://eclipse.che/Dockerfile");
    recipe1.setType("dockerfile");
    recipe1.setContentType("text/x-dockerfile");
    recipe1.setContent("content");
    final EnvironmentImpl env1 = new EnvironmentImpl();
    env1.setMachines(new HashMap<>(ImmutableMap.of("machine1", exMachine1, "machine2", exMachine2, "machine3", exMachine3)));
    env1.setRecipe(recipe1);
    final RecipeImpl recipe2 = new RecipeImpl();
    recipe2.setLocation("https://eclipse.che/Dockerfile");
    recipe2.setType("dockerfile");
    recipe2.setContentType("text/x-dockerfile");
    recipe2.setContent("content");
    final EnvironmentImpl env2 = new EnvironmentImpl();
    env2.setMachines(new HashMap<>(ImmutableMap.of("machine1", new MachineConfigImpl(exMachine1), "machine3", new MachineConfigImpl(exMachine3))));
    env2.setRecipe(recipe2);
    final Map<String, EnvironmentImpl> environments = ImmutableMap.of("env1", env1, "env2", env2);
    // Workspace configuration
    final WorkspaceConfigImpl wCfg = new WorkspaceConfigImpl();
    wCfg.setDefaultEnv("env1");
    wCfg.setName(name);
    wCfg.setDescription("description");
    wCfg.setCommands(commands);
    wCfg.setProjects(projects);
    wCfg.setEnvironments(new HashMap<>(environments));
    return wCfg;
}
Also used : CommandImpl(org.eclipse.che.api.workspace.server.model.impl.CommandImpl) ArrayList(java.util.ArrayList) ServerConfigImpl(org.eclipse.che.api.workspace.server.model.impl.ServerConfigImpl) EnvironmentImpl(org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl) SourceStorageImpl(org.eclipse.che.api.workspace.server.model.impl.SourceStorageImpl) MachineConfigImpl(org.eclipse.che.api.workspace.server.model.impl.MachineConfigImpl) RecipeImpl(org.eclipse.che.api.workspace.server.model.impl.RecipeImpl) VolumeImpl(org.eclipse.che.api.workspace.server.model.impl.VolumeImpl) WorkspaceConfigImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl) ProjectConfigImpl(org.eclipse.che.api.workspace.server.model.impl.ProjectConfigImpl)

Example 39 with RecipeImpl

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

the class TestObjectsFactory method createEnv.

public static EnvironmentImpl createEnv() {
    final RecipeImpl newRecipe = new RecipeImpl();
    newRecipe.setLocation("new-location");
    newRecipe.setType("new-type");
    newRecipe.setContentType("new-content-type");
    newRecipe.setContent("new-content");
    final MachineConfigImpl newMachine = new MachineConfigImpl();
    final ServerConfigImpl serverConf1 = new ServerConfigImpl("2265", "http", "/path1", singletonMap("key", "value"));
    final ServerConfigImpl serverConf2 = new ServerConfigImpl("2266", "ftp", "/path2", singletonMap("key", "value"));
    newMachine.setServers(ImmutableMap.of("ref1", serverConf1, "ref2", serverConf2));
    newMachine.setAttributes(singletonMap("att1", "val"));
    newMachine.setEnv(singletonMap("CHE_ENV", "value"));
    final EnvironmentImpl newEnv = new EnvironmentImpl();
    newEnv.setMachines(ImmutableMap.of("new-machine", newMachine));
    newEnv.setRecipe(newRecipe);
    return newEnv;
}
Also used : MachineConfigImpl(org.eclipse.che.api.workspace.server.model.impl.MachineConfigImpl) RecipeImpl(org.eclipse.che.api.workspace.server.model.impl.RecipeImpl) ServerConfigImpl(org.eclipse.che.api.workspace.server.model.impl.ServerConfigImpl) EnvironmentImpl(org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl)

Example 40 with RecipeImpl

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

the class InternalEnvironmentFactoryTest method shouldUseRetrievedRecipeWhileInternalEnvironmentCreation.

@Test
public void shouldUseRetrievedRecipeWhileInternalEnvironmentCreation() throws Exception {
    // given
    RecipeImpl recipe = new RecipeImpl("type", "contentType", "content", "location");
    InternalRecipe retrievedRecipe = mock(InternalRecipe.class);
    doReturn(retrievedRecipe).when(recipeRetriever).getRecipe(any());
    EnvironmentImpl env = new EnvironmentImpl(recipe, null);
    // when
    environmentFactory.create(env);
    // then
    verify(recipeRetriever).getRecipe(recipe);
    verify(environmentFactory).doCreate(eq(retrievedRecipe), any(), any());
}
Also used : RecipeImpl(org.eclipse.che.api.workspace.server.model.impl.RecipeImpl) EnvironmentImpl(org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl) Test(org.testng.annotations.Test)

Aggregations

RecipeImpl (org.eclipse.che.api.workspace.server.model.impl.RecipeImpl)42 EnvironmentImpl (org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl)38 Test (org.testng.annotations.Test)20 MachineConfigImpl (org.eclipse.che.api.workspace.server.model.impl.MachineConfigImpl)18 ArrayList (java.util.ArrayList)16 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)12 ServerConfigImpl (org.eclipse.che.api.workspace.server.model.impl.ServerConfigImpl)12 WorkspaceConfigImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl)12 WorkspaceImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl)8 CommandImpl (org.eclipse.che.api.workspace.server.model.impl.CommandImpl)7 ProjectConfigImpl (org.eclipse.che.api.workspace.server.model.impl.ProjectConfigImpl)7 SourceStorageImpl (org.eclipse.che.api.workspace.server.model.impl.SourceStorageImpl)7 HashMap (java.util.HashMap)6 AccountImpl (org.eclipse.che.account.spi.AccountImpl)6 WorkspaceDao (org.eclipse.che.api.workspace.server.spi.WorkspaceDao)6 Deployment (io.fabric8.kubernetes.api.model.apps.Deployment)5 DeploymentBuilder (io.fabric8.kubernetes.api.model.apps.DeploymentBuilder)5 VolumeImpl (org.eclipse.che.api.workspace.server.model.impl.VolumeImpl)5 ServerException (org.eclipse.che.api.core.ServerException)4 TypeLiteral (com.google.inject.TypeLiteral)3