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);
}
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);
}
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);
}
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);
}
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()][]);
}
Aggregations