Search in sources :

Example 11 with WorkspaceImpl

use of org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl in project che by eclipse.

the class WorkspaceRuntimesTest method failsToCreateSnapshotWhenDevMachineSnapshottingFailed.

@Test(expectedExceptions = ServerException.class, expectedExceptionsMessageRegExp = "can't save")
public void failsToCreateSnapshotWhenDevMachineSnapshottingFailed() throws Exception {
    WorkspaceImpl workspace = newWorkspace("workspace", "env-name");
    setRuntime(workspace.getId(), WorkspaceStatus.RUNNING);
    prepareMachines(workspace.getId(), "env-name");
    when(envEngine.saveSnapshot(any(), any())).thenThrow(new ServerException("can't save"));
    try {
        runtimes.snapshot(workspace.getId());
    } catch (Exception x) {
        verifyEventsSequence(event(workspace.getId(), WorkspaceStatus.RUNNING, WorkspaceStatus.SNAPSHOTTING, EventType.SNAPSHOT_CREATING, null), event(workspace.getId(), WorkspaceStatus.SNAPSHOTTING, WorkspaceStatus.RUNNING, EventType.SNAPSHOT_CREATION_ERROR, "can't save"));
        throw x;
    }
}
Also used : WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) ServerException(org.eclipse.che.api.core.ServerException) EnvironmentStartInterruptedException(org.eclipse.che.api.environment.server.exception.EnvironmentStartInterruptedException) EnvironmentNotRunningException(org.eclipse.che.api.environment.server.exception.EnvironmentNotRunningException) CancellationException(java.util.concurrent.CancellationException) EnvironmentException(org.eclipse.che.api.environment.server.exception.EnvironmentException) ConflictException(org.eclipse.che.api.core.ConflictException) NotFoundException(org.eclipse.che.api.core.NotFoundException) ExecutionException(java.util.concurrent.ExecutionException) SnapshotException(org.eclipse.che.api.machine.server.exception.SnapshotException) ServerException(org.eclipse.che.api.core.ServerException) Test(org.testng.annotations.Test)

Example 12 with WorkspaceImpl

use of org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl in project che by eclipse.

the class WorkspaceRuntimesTest method injectsStoppedStatusWhenWorkspaceDoesNotHaveRuntime.

@Test
public void injectsStoppedStatusWhenWorkspaceDoesNotHaveRuntime() throws Exception {
    WorkspaceImpl workspace = WorkspaceImpl.builder().setId("workspace").build();
    runtimes.injectRuntime(workspace);
    assertEquals(workspace.getStatus(), WorkspaceStatus.STOPPED);
    assertNull(workspace.getRuntime());
}
Also used : WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) Test(org.testng.annotations.Test)

Example 13 with WorkspaceImpl

use of org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl in project che by eclipse.

the class WorkspaceRuntimesTest method removesOldSnapshotsWhenNewSnapshotsMetadataSuccessfullySaved.

@Test
public void removesOldSnapshotsWhenNewSnapshotsMetadataSuccessfullySaved() throws Exception {
    WorkspaceImpl workspace = newWorkspace("workspace", "env-name");
    setRuntime(workspace.getId(), WorkspaceStatus.RUNNING);
    SnapshotImpl oldSnapshot = mock(SnapshotImpl.class);
    doReturn((singletonList(oldSnapshot))).when(snapshotDao).replaceSnapshots(any(), any(), any());
    runtimes.snapshot(workspace.getId());
    verify(envEngine).removeSnapshot(oldSnapshot);
    verifyEventsSequence(event(workspace.getId(), WorkspaceStatus.RUNNING, WorkspaceStatus.SNAPSHOTTING, EventType.SNAPSHOT_CREATING, null), event(workspace.getId(), WorkspaceStatus.SNAPSHOTTING, WorkspaceStatus.RUNNING, EventType.SNAPSHOT_CREATED, null));
}
Also used : WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) SnapshotImpl(org.eclipse.che.api.machine.server.model.impl.SnapshotImpl) Test(org.testng.annotations.Test)

Example 14 with WorkspaceImpl

use of org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl in project che by eclipse.

the class WorkspaceRuntimesTest method removesNewlyCreatedSnapshotsWhenFailedToSaveTheirsMetadata.

@Test
public void removesNewlyCreatedSnapshotsWhenFailedToSaveTheirsMetadata() throws Exception {
    WorkspaceImpl workspace = newWorkspace("workspace", "env-name");
    setRuntime(workspace.getId(), WorkspaceStatus.RUNNING, "env-name");
    doThrow(new SnapshotException("test")).when(snapshotDao).replaceSnapshots(any(), any(), any());
    SnapshotImpl snapshot = mock(SnapshotImpl.class);
    when(envEngine.saveSnapshot(any(), any())).thenReturn(snapshot);
    try {
        runtimes.snapshot(workspace.getId());
    } catch (ServerException x) {
        assertEquals(x.getMessage(), "test");
    }
    verify(snapshotDao).replaceSnapshots(any(), any(), snapshotsCaptor.capture());
    verify(envEngine, times(snapshotsCaptor.getValue().size())).removeSnapshot(snapshot);
    verifyEventsSequence(event(workspace.getId(), WorkspaceStatus.RUNNING, WorkspaceStatus.SNAPSHOTTING, EventType.SNAPSHOT_CREATING, null), event(workspace.getId(), WorkspaceStatus.SNAPSHOTTING, WorkspaceStatus.RUNNING, EventType.SNAPSHOT_CREATION_ERROR, "test"));
}
Also used : WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) ServerException(org.eclipse.che.api.core.ServerException) SnapshotImpl(org.eclipse.che.api.machine.server.model.impl.SnapshotImpl) SnapshotException(org.eclipse.che.api.machine.server.exception.SnapshotException) Test(org.testng.annotations.Test)

Example 15 with WorkspaceImpl

use of org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl in project che by eclipse.

the class WorkspaceRuntimesTest method injectsStatusAndEmptyMachinesWhenCanNotGetEnvironmentMachines.

@Test
public void injectsStatusAndEmptyMachinesWhenCanNotGetEnvironmentMachines() throws Exception {
    setRuntime("workspace", WorkspaceStatus.RUNNING, "env-name");
    setNoMachinesForWorkspace("workspace");
    WorkspaceImpl workspace = WorkspaceImpl.builder().setId("workspace").build();
    runtimes.injectRuntime(workspace);
    assertEquals(workspace.getStatus(), WorkspaceStatus.RUNNING);
    assertEquals(workspace.getRuntime().getActiveEnv(), "env-name");
    assertTrue(workspace.getRuntime().getMachines().isEmpty());
}
Also used : WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) Test(org.testng.annotations.Test)

Aggregations

WorkspaceImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl)165 Test (org.testng.annotations.Test)130 Response (com.jayway.restassured.response.Response)34 WorkspaceRuntimeImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceRuntimeImpl)15 ServerException (org.eclipse.che.api.core.ServerException)14 SnapshotImpl (org.eclipse.che.api.machine.server.model.impl.SnapshotImpl)12 ApiOperation (io.swagger.annotations.ApiOperation)11 ApiResponses (io.swagger.annotations.ApiResponses)11 AccountImpl (org.eclipse.che.account.spi.AccountImpl)11 Path (javax.ws.rs.Path)10 Produces (javax.ws.rs.Produces)10 WorkspaceDto (org.eclipse.che.api.workspace.shared.dto.WorkspaceDto)10 EnvironmentImpl (org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl)9 WorkspaceConfigImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl)9 NotFoundException (org.eclipse.che.api.core.NotFoundException)8 MachineImpl (org.eclipse.che.api.machine.server.model.impl.MachineImpl)8 Consumes (javax.ws.rs.Consumes)7 ConflictException (org.eclipse.che.api.core.ConflictException)7 ExtendedMachineImpl (org.eclipse.che.api.workspace.server.model.impl.ExtendedMachineImpl)7 ProjectConfigImpl (org.eclipse.che.api.workspace.server.model.impl.ProjectConfigImpl)7