Search in sources :

Example 1 with MachineSourceImpl

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);
}
Also used : LineConsumer(org.eclipse.che.api.core.util.LineConsumer) MachineConfigImpl(org.eclipse.che.api.machine.server.model.impl.MachineConfigImpl) Instance(org.eclipse.che.api.machine.server.spi.Instance) CheServiceImpl(org.eclipse.che.api.environment.server.model.CheServiceImpl) MachineSourceImpl(org.eclipse.che.api.machine.server.model.impl.MachineSourceImpl) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.testng.annotations.Test)

Example 2 with MachineSourceImpl

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);
}
Also used : LineConsumer(org.eclipse.che.api.core.util.LineConsumer) MachineConfigImpl(org.eclipse.che.api.machine.server.model.impl.MachineConfigImpl) Instance(org.eclipse.che.api.machine.server.spi.Instance) CheServiceImpl(org.eclipse.che.api.environment.server.model.CheServiceImpl) MachineSourceImpl(org.eclipse.che.api.machine.server.model.impl.MachineSourceImpl) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.testng.annotations.Test)

Example 3 with MachineSourceImpl

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);
}
Also used : SnapshotImpl(org.eclipse.che.api.machine.server.model.impl.SnapshotImpl) MachineSourceImpl(org.eclipse.che.api.machine.server.model.impl.MachineSourceImpl) Test(org.testng.annotations.Test)

Example 4 with MachineSourceImpl

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();
}
Also used : Instance(org.eclipse.che.api.machine.server.spi.Instance) MachineSourceImpl(org.eclipse.che.api.machine.server.model.impl.MachineSourceImpl) Test(org.testng.annotations.Test)

Example 5 with MachineSourceImpl

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));
}
Also used : WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) SnapshotImpl(org.eclipse.che.api.machine.server.model.impl.SnapshotImpl) MachineSourceImpl(org.eclipse.che.api.machine.server.model.impl.MachineSourceImpl) Test(org.testng.annotations.Test)

Aggregations

MachineSourceImpl (org.eclipse.che.api.machine.server.model.impl.MachineSourceImpl)19 Test (org.testng.annotations.Test)13 SnapshotImpl (org.eclipse.che.api.machine.server.model.impl.SnapshotImpl)10 Instance (org.eclipse.che.api.machine.server.spi.Instance)7 Matchers.anyString (org.mockito.Matchers.anyString)7 LineConsumer (org.eclipse.che.api.core.util.LineConsumer)5 WorkspaceImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl)5 IOException (java.io.IOException)4 CheServiceImpl (org.eclipse.che.api.environment.server.model.CheServiceImpl)4 SourceNotFoundException (org.eclipse.che.api.machine.server.exception.SourceNotFoundException)4 MachineConfigImpl (org.eclipse.che.api.machine.server.model.impl.MachineConfigImpl)4 MachineImpl (org.eclipse.che.api.machine.server.model.impl.MachineImpl)4 NotFoundException (org.eclipse.che.api.core.NotFoundException)3 ServerException (org.eclipse.che.api.core.ServerException)3 MachineLimitsImpl (org.eclipse.che.api.machine.server.model.impl.MachineLimitsImpl)3 Response (com.jayway.restassured.response.Response)2 ArrayList (java.util.ArrayList)2 MachineSource (org.eclipse.che.api.core.model.machine.MachineSource)2 MachineException (org.eclipse.che.api.machine.server.exception.MachineException)2 MachineRuntimeInfoImpl (org.eclipse.che.api.machine.server.model.impl.MachineRuntimeInfoImpl)2