use of org.eclipse.che.api.machine.server.model.impl.MachineSourceImpl 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.machine.server.model.impl.MachineSourceImpl 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);
}
use of org.eclipse.che.api.machine.server.model.impl.MachineSourceImpl in project che by eclipse.
the class CheEnvironmentEngineTest method shouldBeAbleToRemoveSnapshot.
@Test
public void shouldBeAbleToRemoveSnapshot() throws Exception {
// given
SnapshotImpl snapshot = mock(SnapshotImpl.class);
MachineSourceImpl machineSource = mock(MachineSourceImpl.class);
when(snapshot.getType()).thenReturn("docker");
when(snapshot.getMachineSource()).thenReturn(machineSource);
// when
engine.removeSnapshot(snapshot);
// then
verify(instanceProvider).removeInstanceSnapshot(machineSource);
}
use of org.eclipse.che.api.machine.server.model.impl.MachineSourceImpl in project che by eclipse.
the class CheEnvironmentEngineTest method shouldBeAbleToSaveMachineSnapshot.
@Test
public void shouldBeAbleToSaveMachineSnapshot() throws Exception {
// given
List<Instance> instances = startEnv();
Instance instance = instances.get(0);
doReturn(new MachineSourceImpl("someType").setContent("some content")).when(instance).saveToSnapshot();
// when
engine.saveSnapshot(instance.getWorkspaceId(), instance.getId());
// then
verify(instance).saveToSnapshot();
}
use of org.eclipse.che.api.machine.server.model.impl.MachineSourceImpl in project che by eclipse.
the class WorkspaceManagerTest method shouldRecoverWorkspaceWhenRecoverParameterIsTrueAndSnapshotExists.
@Test
public void shouldRecoverWorkspaceWhenRecoverParameterIsTrueAndSnapshotExists() throws Exception {
final WorkspaceImpl workspace = createAndMockWorkspace();
mockStart(workspace);
SnapshotImpl.SnapshotBuilder snapshotBuilder = SnapshotImpl.builder().generateId().setEnvName("env").setDev(true).setMachineName("machine1").setWorkspaceId(workspace.getId()).setType("docker").setMachineSource(new MachineSourceImpl("image"));
SnapshotImpl snapshot1 = snapshotBuilder.build();
SnapshotImpl snapshot2 = snapshotBuilder.generateId().setDev(false).setMachineName("machine2").build();
when(snapshotDao.findSnapshots(workspace.getId())).thenReturn(asList(snapshot1, snapshot2));
workspaceManager.startWorkspace(workspace.getId(), workspace.getConfig().getDefaultEnv(), true);
verify(runtimes).startAsync(workspace, workspace.getConfig().getDefaultEnv(), true);
assertNotNull(workspace.getAttributes().get(UPDATED_ATTRIBUTE_NAME));
}
Aggregations