Search in sources :

Example 16 with Instance

use of org.eclipse.che.api.machine.server.spi.Instance in project che by eclipse.

the class CheEnvironmentEngineTest method shouldThrowExceptionOnGetMachineIfMachineIsNotFound.

@Test(expectedExceptions = NotFoundException.class, expectedExceptionsMessageRegExp = "Machine with ID .* is not found in the environment of workspace .*")
public void shouldThrowExceptionOnGetMachineIfMachineIsNotFound() throws Exception {
    // given
    List<Instance> instances = startEnv();
    Instance instance = instances.get(0);
    String workspaceId = instance.getWorkspaceId();
    // when
    engine.getMachine(workspaceId, "nonExistingInstanceId");
}
Also used : Instance(org.eclipse.che.api.machine.server.spi.Instance) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.testng.annotations.Test)

Example 17 with Instance

use of org.eclipse.che.api.machine.server.spi.Instance 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 18 with Instance

use of org.eclipse.che.api.machine.server.spi.Instance 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));
    }
}
Also used : Instance(org.eclipse.che.api.machine.server.spi.Instance) CheServiceImpl(org.eclipse.che.api.environment.server.model.CheServiceImpl) ArrayList(java.util.ArrayList) 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) ExtendedMachine(org.eclipse.che.api.core.model.workspace.ExtendedMachine) ExtendedMachine(org.eclipse.che.api.core.model.workspace.ExtendedMachine) Machine(org.eclipse.che.api.core.model.machine.Machine) LineConsumer(org.eclipse.che.api.core.util.LineConsumer) Test(org.testng.annotations.Test)

Example 19 with Instance

use of org.eclipse.che.api.machine.server.spi.Instance 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 20 with Instance

use of org.eclipse.che.api.machine.server.spi.Instance in project che by eclipse.

the class CheEnvironmentEngineTest method envStartShouldThrowsExceptionIfSameEnvironmentExists.

@Test(expectedExceptions = ConflictException.class, expectedExceptionsMessageRegExp = "Environment of workspace '.*' already exists")
public void envStartShouldThrowsExceptionIfSameEnvironmentExists() throws Exception {
    // given
    List<Instance> instances = startEnv();
    Instance instance = instances.get(0);
    EnvironmentImpl env = createEnv();
    String envName = "env-1";
    // when
    engine.start(instance.getWorkspaceId(), envName, env, false, messageConsumer);
}
Also used : Instance(org.eclipse.che.api.machine.server.spi.Instance) 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)

Aggregations

Instance (org.eclipse.che.api.machine.server.spi.Instance)47 Test (org.testng.annotations.Test)36 Matchers.anyString (org.mockito.Matchers.anyString)22 LineConsumer (org.eclipse.che.api.core.util.LineConsumer)19 CheServiceImpl (org.eclipse.che.api.environment.server.model.CheServiceImpl)17 MachineConfigImpl (org.eclipse.che.api.machine.server.model.impl.MachineConfigImpl)17 NotFoundException (org.eclipse.che.api.core.NotFoundException)13 MachineSourceImpl (org.eclipse.che.api.machine.server.model.impl.MachineSourceImpl)11 ArrayList (java.util.ArrayList)10 ServerException (org.eclipse.che.api.core.ServerException)10 Machine (org.eclipse.che.api.core.model.machine.Machine)10 ExtendedMachine (org.eclipse.che.api.core.model.workspace.ExtendedMachine)10 EnvironmentNotRunningException (org.eclipse.che.api.environment.server.exception.EnvironmentNotRunningException)10 CheServicesEnvironmentImpl (org.eclipse.che.api.environment.server.model.CheServicesEnvironmentImpl)10 EnvironmentImpl (org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl)9 ConflictException (org.eclipse.che.api.core.ConflictException)8 MachineException (org.eclipse.che.api.machine.server.exception.MachineException)7 MachineImpl (org.eclipse.che.api.machine.server.model.impl.MachineImpl)7 SnapshotImpl (org.eclipse.che.api.machine.server.model.impl.SnapshotImpl)7 ExtendedMachineImpl (org.eclipse.che.api.workspace.server.model.impl.ExtendedMachineImpl)7