Search in sources :

Example 31 with CheServicesEnvironmentImpl

use of org.eclipse.che.api.environment.server.model.CheServicesEnvironmentImpl in project che by eclipse.

the class ComposeEnvironmentParserTest method shouldBeAbleToParseComposeEnvironmentWithApplicationXYamlContentType.

@Test
public void shouldBeAbleToParseComposeEnvironmentWithApplicationXYamlContentType() throws Exception {
    // given
    when(recipe.getContentType()).thenReturn("application/x-yaml");
    when(recipe.getContent()).thenReturn(COMPOSE_CONTENT);
    CheServicesEnvironmentImpl expectedEnv = createTestEnv();
    //when
    CheServicesEnvironmentImpl cheServicesEnvironment = parser.parse(environment);
    //then
    assertEquals(cheServicesEnvironment, expectedEnv);
}
Also used : CheServicesEnvironmentImpl(org.eclipse.che.api.environment.server.model.CheServicesEnvironmentImpl) Test(org.testng.annotations.Test)

Example 32 with CheServicesEnvironmentImpl

use of org.eclipse.che.api.environment.server.model.CheServicesEnvironmentImpl in project che by eclipse.

the class CheEnvironmentEngineTest method shouldSetDockerfileContentInsteadOfUrlIfUrlPointsToCheApiOnEnvironmentStart.

@Test
public void shouldSetDockerfileContentInsteadOfUrlIfUrlPointsToCheApiOnEnvironmentStart() throws Exception {
    // given
    EnvironmentImpl env = createEnv();
    String machineName = "machineWithDockerfileFromApi";
    String dockerfileContent = "this is dockerfile content";
    when(recipeDownloader.getRecipe(anyString())).thenReturn(dockerfileContent);
    //prepare CheServicesEnvironmentImpl which should return compose parser
    CheServicesEnvironmentImpl cheServicesEnvironment = createCheServicesEnvByName(machineName);
    cheServicesEnvironment.getServices().get(machineName).withBuild(new CheServiceBuildContextImpl().withContext(API_ENDPOINT + "/recipe/12345"));
    // when
    startEnv(env, cheServicesEnvironment);
    // then
    ArgumentCaptor<CheServiceImpl> captor = ArgumentCaptor.forClass(CheServiceImpl.class);
    verify(machineProvider).startService(anyString(), anyString(), anyString(), eq(machineName), eq(false), anyString(), captor.capture(), any(LineConsumer.class));
    CheServiceImpl actualService = captor.getValue();
    assertNull(actualService.getBuild().getContext());
    assertNull(actualService.getBuild().getDockerfilePath());
    assertEquals(actualService.getBuild().getDockerfileContent(), dockerfileContent);
}
Also used : LineConsumer(org.eclipse.che.api.core.util.LineConsumer) CheServiceBuildContextImpl(org.eclipse.che.api.environment.server.model.CheServiceBuildContextImpl) CheServiceImpl(org.eclipse.che.api.environment.server.model.CheServiceImpl) CheServicesEnvironmentImpl(org.eclipse.che.api.environment.server.model.CheServicesEnvironmentImpl) EnvironmentImpl(org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl) CheServicesEnvironmentImpl(org.eclipse.che.api.environment.server.model.CheServicesEnvironmentImpl) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.testng.annotations.Test)

Example 33 with CheServicesEnvironmentImpl

use of org.eclipse.che.api.environment.server.model.CheServicesEnvironmentImpl in project che by eclipse.

the class CheEnvironmentEngineTest method shouldUseConfiguredInServiceRamInsteadOfSetDefaultOnEnvironmentStart.

@Test
public void shouldUseConfiguredInServiceRamInsteadOfSetDefaultOnEnvironmentStart() throws Exception {
    // given
    EnvironmentImpl env = createEnv();
    String machineName = "machineWithoutRam";
    //prepare CheServicesEnvironmentImpl which should return compose parser
    CheServicesEnvironmentImpl cheServicesEnvironment = createCheServicesEnvByName(machineName);
    cheServicesEnvironment.getServices().get(machineName).withMemLimit(42943433L);
    // when
    startEnv(env, cheServicesEnvironment);
    // then
    ArgumentCaptor<CheServiceImpl> captor = ArgumentCaptor.forClass(CheServiceImpl.class);
    verify(machineProvider).startService(anyString(), anyString(), anyString(), eq(machineName), eq(false), anyString(), captor.capture(), any(LineConsumer.class));
    CheServiceImpl actualService = captor.getValue();
    assertEquals((long) actualService.getMemLimit(), 42943433L);
}
Also used : LineConsumer(org.eclipse.che.api.core.util.LineConsumer) CheServiceImpl(org.eclipse.che.api.environment.server.model.CheServiceImpl) CheServicesEnvironmentImpl(org.eclipse.che.api.environment.server.model.CheServicesEnvironmentImpl) EnvironmentImpl(org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl) CheServicesEnvironmentImpl(org.eclipse.che.api.environment.server.model.CheServicesEnvironmentImpl) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.testng.annotations.Test)

Example 34 with CheServicesEnvironmentImpl

use of org.eclipse.che.api.environment.server.model.CheServicesEnvironmentImpl in project che by eclipse.

the class CheEnvironmentEngineTest method shouldSetDefaultRamToMachinesWithoutRamOnEnvironmentStart.

@Test
public void shouldSetDefaultRamToMachinesWithoutRamOnEnvironmentStart() throws Exception {
    // given
    EnvironmentImpl env = createEnv();
    String machineName = "machineWithoutRam";
    //prepare CheServicesEnvironmentImpl which should return compose parser
    CheServicesEnvironmentImpl cheServicesEnvironment = createCheServicesEnvByName(machineName);
    // when
    startEnv(env, cheServicesEnvironment);
    // then
    ArgumentCaptor<CheServiceImpl> captor = ArgumentCaptor.forClass(CheServiceImpl.class);
    verify(machineProvider).startService(anyString(), anyString(), anyString(), eq(machineName), eq(false), anyString(), captor.capture(), any(LineConsumer.class));
    CheServiceImpl actualService = captor.getValue();
    assertEquals((long) actualService.getMemLimit(), DEFAULT_MACHINE_MEM_LIMIT_MB * 1024L * 1024L);
}
Also used : LineConsumer(org.eclipse.che.api.core.util.LineConsumer) CheServiceImpl(org.eclipse.che.api.environment.server.model.CheServiceImpl) CheServicesEnvironmentImpl(org.eclipse.che.api.environment.server.model.CheServicesEnvironmentImpl) EnvironmentImpl(org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl) CheServicesEnvironmentImpl(org.eclipse.che.api.environment.server.model.CheServicesEnvironmentImpl) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.testng.annotations.Test)

Example 35 with CheServicesEnvironmentImpl

use of org.eclipse.che.api.environment.server.model.CheServicesEnvironmentImpl in project che by eclipse.

the class CheEnvironmentValidatorTest method invalidServicesEnvironmentProvider.

@DataProvider
public static Object[][] invalidServicesEnvironmentProvider() {
    // Format of result array:
    // [ [InvalidCheServicesEnvironmentObject, ExceptionMessage], ... ]
    CheServicesEnvironmentImpl env;
    Map.Entry<String, CheServiceImpl> serviceEntry;
    CheServiceImpl service;
    List<List<Object>> data = new ArrayList<>();
    env = createServicesEnv();
    env.setServices(null);
    data.add(asList(env, "Environment 'env' should contain at least 1 machine"));
    env = createServicesEnv();
    env.setServices(emptyMap());
    data.add(asList(env, "Environment 'env' should contain at least 1 machine"));
    env = createServicesEnv();
    serviceEntry = getAnyService(env);
    env.getServices().put("invalid service name", serviceEntry.getValue());
    data.add(asList(env, "Name of machine 'invalid service name' in environment 'env' is invalid"));
    env = createServicesEnv();
    serviceEntry = getAnyService(env);
    service = serviceEntry.getValue();
    service.setImage(null);
    service.setBuild(null);
    data.add(asList(env, format("Field 'image' or 'build.context' is required in machine '%s' in environment 'env'", serviceEntry.getKey())));
    env = createServicesEnv();
    serviceEntry = getAnyService(env);
    service = serviceEntry.getValue();
    service.setImage("");
    service.setBuild(null);
    data.add(asList(env, format("Field 'image' or 'build.context' is required in machine '%s' in environment 'env'", serviceEntry.getKey())));
    env = createServicesEnv();
    serviceEntry = getAnyService(env);
    service = serviceEntry.getValue();
    service.setImage(null);
    service.setBuild(new CheServiceBuildContextImpl());
    data.add(asList(env, format("Field 'image' or 'build.context' is required in machine '%s' in environment 'env'", serviceEntry.getKey())));
    env = createServicesEnv();
    serviceEntry = getAnyService(env);
    service = serviceEntry.getValue();
    service.setImage("");
    service.setBuild(new CheServiceBuildContextImpl());
    data.add(asList(env, format("Field 'image' or 'build.context' is required in machine '%s' in environment 'env'", serviceEntry.getKey())));
    env = createServicesEnv();
    serviceEntry = getAnyService(env);
    service = serviceEntry.getValue();
    service.setPorts(new ArrayList<>(singletonList("8080:8080")));
    data.add(asList(env, format("Ports binding is forbidden but found in machine '%s' of environment 'env'", serviceEntry.getKey())));
    env = createServicesEnv();
    serviceEntry = getAnyService(env);
    service = serviceEntry.getValue();
    service.setVolumes(new ArrayList<>(singletonList("volume")));
    data.add(asList(env, format("Volumes binding is forbidden but found in machine '%s' of environment 'env'", serviceEntry.getKey())));
    env = createServicesEnv();
    serviceEntry = getAnyService(env);
    service = serviceEntry.getValue();
    service.setNetworks(new ArrayList<>(singletonList("network1")));
    data.add(asList(env, format("Networks configuration is forbidden but found in machine '%s' of environment 'env'", serviceEntry.getKey())));
    env = createServicesEnv();
    serviceEntry = getAnyService(env);
    service = serviceEntry.getValue();
    service.setImage(null);
    service.setBuild(new CheServiceBuildContextImpl(null, "dockerfile", null, null));
    data.add(asList(env, format("Field 'image' or 'build.context' is required in machine '%s' in environment 'env'", serviceEntry.getKey())));
    env = createServicesEnv();
    serviceEntry = getAnyService(env);
    service = serviceEntry.getValue();
    service.setImage("");
    service.setBuild(new CheServiceBuildContextImpl("", "dockerfile", null, null));
    data.add(asList(env, format("Field 'image' or 'build.context' is required in machine '%s' in environment 'env'", serviceEntry.getKey())));
    env = createServicesEnv();
    serviceEntry = getAnyService(env);
    service = serviceEntry.getValue();
    service.setImage("");
    service.setBuild(new CheServiceBuildContextImpl(null, null, null, null));
    data.add(asList(env, format("Field 'image' or 'build.context' is required in machine '%s' in environment 'env'", serviceEntry.getKey())));
    env = createServicesEnv();
    serviceEntry = getAnyService(env);
    service = serviceEntry.getValue();
    service.setImage("");
    service.setBuild(new CheServiceBuildContextImpl("some url", null, "some content", new HashMap<String, String>() {

        {
            put("argkey", "argvalue");
        }
    }));
    data.add(asList(env, format("Machine '%s' in environment 'env' contains mutually exclusive dockerfile content and build context.", serviceEntry.getKey())));
    return data.stream().map(list -> list.toArray(new Object[list.size()])).toArray(value -> new Object[data.size()][]);
}
Also used : Listeners(org.testng.annotations.Listeners) MachineInstanceProviders(org.eclipse.che.api.machine.server.MachineInstanceProviders) EnvironmentImpl(org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl) DataProvider(org.testng.annotations.DataProvider) Mock(org.mockito.Mock) DtoConverter(org.eclipse.che.api.workspace.server.DtoConverter) Assert.assertEquals(org.testng.Assert.assertEquals) Test(org.testng.annotations.Test) HashMap(java.util.HashMap) ExtendedMachineImpl(org.eclipse.che.api.workspace.server.model.impl.ExtendedMachineImpl) ServerConfDto(org.eclipse.che.api.machine.shared.dto.ServerConfDto) Mockito.spy(org.mockito.Mockito.spy) ServerConf2Impl(org.eclipse.che.api.workspace.server.model.impl.ServerConf2Impl) CheServicesEnvironmentImpl(org.eclipse.che.api.environment.server.model.CheServicesEnvironmentImpl) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) EnvironmentDto(org.eclipse.che.api.workspace.shared.dto.EnvironmentDto) MachineConfigDto(org.eclipse.che.api.machine.shared.dto.MachineConfigDto) Collections.singleton(java.util.Collections.singleton) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) CheServiceBuildContextImpl(org.eclipse.che.api.environment.server.model.CheServiceBuildContextImpl) Collections.singletonMap(java.util.Collections.singletonMap) InjectMocks(org.mockito.InjectMocks) Collections.emptyMap(java.util.Collections.emptyMap) EnvironmentRecipeImpl(org.eclipse.che.api.workspace.server.model.impl.EnvironmentRecipeImpl) MockitoTestNGListener(org.mockito.testng.MockitoTestNGListener) MachineSourceDto(org.eclipse.che.api.machine.shared.dto.MachineSourceDto) Collections.emptyList(java.util.Collections.emptyList) Assert.fail(org.testng.Assert.fail) BeforeMethod(org.testng.annotations.BeforeMethod) DtoFactory.newDto(org.eclipse.che.dto.server.DtoFactory.newDto) ExtendedMachineDto(org.eclipse.che.api.workspace.shared.dto.ExtendedMachineDto) Mockito.when(org.mockito.Mockito.when) String.format(java.lang.String.format) Matchers.any(org.mockito.Matchers.any) List(java.util.List) Environment(org.eclipse.che.api.core.model.workspace.Environment) ServerException(org.eclipse.che.api.core.ServerException) CheServiceImpl(org.eclipse.che.api.environment.server.model.CheServiceImpl) Joiner(com.google.common.base.Joiner) CheServiceBuildContextImpl(org.eclipse.che.api.environment.server.model.CheServiceBuildContextImpl) CheServiceImpl(org.eclipse.che.api.environment.server.model.CheServiceImpl) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) CheServicesEnvironmentImpl(org.eclipse.che.api.environment.server.model.CheServicesEnvironmentImpl) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) Arrays.asList(java.util.Arrays.asList) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) Collections.singletonMap(java.util.Collections.singletonMap) Collections.emptyMap(java.util.Collections.emptyMap) DataProvider(org.testng.annotations.DataProvider)

Aggregations

CheServicesEnvironmentImpl (org.eclipse.che.api.environment.server.model.CheServicesEnvironmentImpl)54 CheServiceImpl (org.eclipse.che.api.environment.server.model.CheServiceImpl)44 Test (org.testng.annotations.Test)38 EnvironmentImpl (org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl)15 CheServiceBuildContextImpl (org.eclipse.che.api.environment.server.model.CheServiceBuildContextImpl)13 Matchers.anyString (org.mockito.Matchers.anyString)8 HashMap (java.util.HashMap)7 LineConsumer (org.eclipse.che.api.core.util.LineConsumer)7 Environment (org.eclipse.che.api.core.model.workspace.Environment)6 ExtendedMachineImpl (org.eclipse.che.api.workspace.server.model.impl.ExtendedMachineImpl)6 Map (java.util.Map)3 EnvironmentRecipe (org.eclipse.che.api.core.model.workspace.EnvironmentRecipe)3 ExtendedMachine (org.eclipse.che.api.core.model.workspace.ExtendedMachine)3 EnvironmentRecipeImpl (org.eclipse.che.api.workspace.server.model.impl.EnvironmentRecipeImpl)3 Joiner (com.google.common.base.Joiner)2 String.format (java.lang.String.format)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 NotFoundException (org.eclipse.che.api.core.NotFoundException)2 ServerException (org.eclipse.che.api.core.ServerException)2