use of org.eclipse.che.api.environment.server.model.CheServiceImpl in project che by eclipse.
the class CheEnvironmentEngineTest method startEnv.
private List<Instance> startEnv(EnvironmentImpl env, CheServicesEnvironmentImpl cheServicesEnv) throws Exception {
String envName = "env-1";
String workspaceId = "wsId";
when(machineProvider.startService(anyString(), eq(workspaceId), eq(envName), anyString(), anyBoolean(), anyString(), any(CheServiceImpl.class), any(LineConsumer.class))).thenAnswer(invocationOnMock -> {
Object[] arguments = invocationOnMock.getArguments();
String machineName = (String) arguments[3];
boolean isDev = (boolean) arguments[4];
CheServiceImpl service = (CheServiceImpl) arguments[6];
Machine machine = createMachine(workspaceId, envName, service, machineName, isDev);
return spy(new NoOpMachineInstance(machine));
});
when(environmentParser.parse(env)).thenReturn(cheServicesEnv);
// when
return engine.start(workspaceId, envName, env, false, messageConsumer);
}
use of org.eclipse.che.api.environment.server.model.CheServiceImpl in project che by eclipse.
the class CheEnvironmentEngineTest method shouldSetDockerfileContentInsteadOfUrlIfUrlPointsToCheApiOnMachineStart.
@Test
public void shouldSetDockerfileContentInsteadOfUrlIfUrlPointsToCheApiOnMachineStart() throws Exception {
// given
List<Instance> instances = startEnv();
String workspaceId = instances.get(0).getWorkspaceId();
when(engine.generateMachineId()).thenReturn("newMachineId");
Instance newMachine = mock(Instance.class);
when(newMachine.getId()).thenReturn("newMachineId");
when(newMachine.getWorkspaceId()).thenReturn(workspaceId);
when(machineProvider.startService(anyString(), anyString(), anyString(), anyString(), anyBoolean(), anyString(), any(CheServiceImpl.class), any(LineConsumer.class))).thenReturn(newMachine);
MachineConfigImpl config = createConfig(false);
String machineName = "extraMachine";
config.setName(machineName);
config.setSource(new MachineSourceImpl("docker").setLocation(API_ENDPOINT + "/recipe/12345"));
String dockerfileContent = "this is dockerfile content";
when(recipeDownloader.getRecipe(anyString())).thenReturn("this is dockerfile content");
// when
engine.startMachine(workspaceId, config, emptyList());
// 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.CheServiceImpl in project che by eclipse.
the class CheEnvironmentEngineTest method createCheServicesEnv.
private CheServicesEnvironmentImpl createCheServicesEnv() {
CheServicesEnvironmentImpl cheServicesEnvironment = new CheServicesEnvironmentImpl();
Map<String, CheServiceImpl> services = new HashMap<>();
services.put("dev-machine", new CheServiceImpl().withBuild(new CheServiceBuildContextImpl().withContext("image")));
services.put("machine2", new CheServiceImpl().withBuild(new CheServiceBuildContextImpl().withContext("image")));
cheServicesEnvironment.setServices(services);
return cheServicesEnvironment;
}
use of org.eclipse.che.api.environment.server.model.CheServiceImpl in project che by eclipse.
the class CheEnvironmentEngineTest method shouldBeAbleToStartEnvironment.
@Test
public void shouldBeAbleToStartEnvironment() throws Exception {
// given
EnvironmentImpl env = createEnv();
String envName = "env-1";
String workspaceId = "wsId";
List<Instance> expectedMachines = new ArrayList<>();
when(machineProvider.startService(anyString(), eq(workspaceId), eq(envName), anyString(), anyBoolean(), anyString(), any(CheServiceImpl.class), any(LineConsumer.class))).thenAnswer(invocationOnMock -> {
Object[] arguments = invocationOnMock.getArguments();
String machineName = (String) arguments[3];
boolean isDev = (boolean) arguments[4];
CheServiceImpl service = (CheServiceImpl) arguments[6];
Machine machine = createMachine(workspaceId, envName, service, machineName, isDev);
NoOpMachineInstance instance = spy(new NoOpMachineInstance(machine));
expectedMachines.add(instance);
return instance;
});
when(environmentParser.parse(env)).thenReturn(createCheServicesEnv());
// when
List<Instance> machines = engine.start(workspaceId, envName, env, false, messageConsumer, startedHandler);
// then
assertEquals(machines, expectedMachines);
for (Instance expectedMachine : expectedMachines) {
verify(startedHandler).started(eq(expectedMachine), any(ExtendedMachine.class));
}
}
use of org.eclipse.che.api.environment.server.model.CheServiceImpl in project che by eclipse.
the class CheEnvironmentEngineTest method shouldNotSetDockerfileContentInsteadOfUrlIfUrlDoesNotPointToCheApiOnMachineStart.
@Test
public void shouldNotSetDockerfileContentInsteadOfUrlIfUrlDoesNotPointToCheApiOnMachineStart() throws Exception {
// given
List<Instance> instances = startEnv();
String workspaceId = instances.get(0).getWorkspaceId();
when(engine.generateMachineId()).thenReturn("newMachineId");
Instance newMachine = mock(Instance.class);
when(newMachine.getId()).thenReturn("newMachineId");
when(newMachine.getWorkspaceId()).thenReturn(workspaceId);
when(machineProvider.startService(anyString(), anyString(), anyString(), anyString(), anyBoolean(), anyString(), any(CheServiceImpl.class), any(LineConsumer.class))).thenReturn(newMachine);
MachineConfigImpl config = createConfig(false);
String machineName = "extraMachine";
config.setName(machineName);
String contextUrl = "http://another-server.com/recipe/12345";
config.setSource(new MachineSourceImpl("docker").setLocation(contextUrl));
// when
engine.startMachine(workspaceId, config, emptyList());
// 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().getDockerfilePath());
assertNull(actualService.getBuild().getDockerfileContent());
assertEquals(actualService.getBuild().getContext(), contextUrl);
}
Aggregations