Search in sources :

Example 31 with WorkspaceImpl

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

the class WorkspaceManagerTest method shouldBeAbleToGetWorkspacesAvailableForUser.

@Test
public void shouldBeAbleToGetWorkspacesAvailableForUser() throws Exception {
    // given
    final WorkspaceConfig config = createConfig();
    final WorkspaceImpl workspace1 = createAndMockWorkspace(config, NAMESPACE);
    final WorkspaceImpl workspace2 = createAndMockWorkspace(config, NAMESPACE_2);
    when(workspaceDao.getWorkspaces(NAMESPACE)).thenReturn(asList(workspace1, workspace2));
    mockRuntime(workspace1, STOPPED);
    mockRuntime(workspace2, RUNNING);
    // when
    final List<WorkspaceImpl> result = workspaceManager.getWorkspaces(NAMESPACE, true);
    // then
    assertEquals(result.size(), 2);
    final WorkspaceImpl res1 = result.get(0);
    assertEquals(res1.getStatus(), STOPPED);
    assertFalse(res1.isTemporary(), "Workspace must be permanent");
    final WorkspaceImpl res2 = result.get(1);
    assertEquals(res2.getStatus(), RUNNING, "Workspace status wasn't changed to the runtime instance status");
    assertFalse(res2.isTemporary(), "Workspace must be permanent");
}
Also used : WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) WorkspaceConfig(org.eclipse.che.api.core.model.workspace.WorkspaceConfig) Test(org.testng.annotations.Test)

Example 32 with WorkspaceImpl

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

the class WorkspaceManagerTest method shouldRemoveMachinesSnapshotsEvenSomeRemovalFails.

@Test
public void shouldRemoveMachinesSnapshotsEvenSomeRemovalFails() throws Exception {
    // given
    String testWsId = "testWsId";
    String testNamespace = "testNamespace";
    WorkspaceImpl workspaceMock = mock(WorkspaceImpl.class);
    when(workspaceDao.get(testWsId)).thenReturn(workspaceMock);
    when(workspaceMock.getNamespace()).thenReturn(testNamespace);
    SnapshotImpl.SnapshotBuilder snapshotBuilder = SnapshotImpl.builder().generateId().setEnvName("env").setDev(true).setMachineName("machine1").setWorkspaceId(testWsId).setType("docker").setMachineSource(new MachineSourceImpl("image"));
    SnapshotImpl snapshot1 = snapshotBuilder.build();
    SnapshotImpl snapshot2 = snapshotBuilder.generateId().setDev(false).setMachineName("machine2").build();
    when(snapshotDao.findSnapshots(testWsId)).thenReturn(asList(snapshot1, snapshot2));
    doThrow(new SnapshotException("test")).when(snapshotDao).removeSnapshot(snapshot1.getId());
    // when
    workspaceManager.removeSnapshots(testWsId);
    // then
    captureExecuteCallsAndRunSynchronously();
    verify(runtimes).removeBinaries(singletonList(snapshot2));
    verify(snapshotDao).removeSnapshot(snapshot1.getId());
    verify(snapshotDao).removeSnapshot(snapshot2.getId());
}
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) Matchers.anyString(org.mockito.Matchers.anyString) SnapshotException(org.eclipse.che.api.machine.server.exception.SnapshotException) Test(org.testng.annotations.Test)

Example 33 with WorkspaceImpl

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

the class WorkspaceManagerTest method shouldBeAbleToGetMachineInstanceIfWorkspaceIsRunning.

@Test
public void shouldBeAbleToGetMachineInstanceIfWorkspaceIsRunning() throws Exception {
    // given
    final WorkspaceImpl workspace = createAndMockWorkspace();
    WorkspaceRuntimeImpl runtime = mockRuntime(workspace, RUNNING);
    MachineImpl machine = runtime.getMachines().get(0);
    // when
    workspaceManager.getMachineInstance(workspace.getId(), machine.getId());
    // then
    verify(runtimes).getMachine(workspace.getId(), machine.getId());
}
Also used : WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) ExtendedMachineImpl(org.eclipse.che.api.workspace.server.model.impl.ExtendedMachineImpl) MachineImpl(org.eclipse.che.api.machine.server.model.impl.MachineImpl) WorkspaceRuntimeImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceRuntimeImpl) Test(org.testng.annotations.Test)

Example 34 with WorkspaceImpl

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

the class WorkspaceManagerTest method shouldBeAbleToGetWorkspaceByKeyWithoutOwner.

@Test
public void shouldBeAbleToGetWorkspaceByKeyWithoutOwner() throws Exception {
    WorkspaceImpl workspace = createAndMockWorkspace();
    WorkspaceImpl result = workspaceManager.getWorkspace(":" + workspace.getConfig().getName());
    assertEquals(result, workspace);
}
Also used : WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) Test(org.testng.annotations.Test)

Example 35 with WorkspaceImpl

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

the class WorkspaceManagerTest method shouldNotCreateSnapshotIfWorkspaceIsTemporaryAndAutoCreateSnapshotActivated.

@Test
public void shouldNotCreateSnapshotIfWorkspaceIsTemporaryAndAutoCreateSnapshotActivated() throws Exception {
    final WorkspaceImpl workspace = createAndMockWorkspace();
    workspace.getAttributes().put(Constants.AUTO_CREATE_SNAPSHOT, "true");
    mockRuntime(workspace, RUNNING);
    SnapshotImpl oldSnapshot = mock(SnapshotImpl.class);
    when(snapshotDao.getSnapshot(eq(workspace.getId()), eq(workspace.getConfig().getDefaultEnv()), anyString())).thenReturn(oldSnapshot);
    workspace.setTemporary(true);
    workspaceManager.stopWorkspace(workspace.getId());
    captureRunAsyncCallsAndRunSynchronously();
    verify(runtimes, never()).snapshot(workspace.getId());
    verify(runtimes).stop(workspace.getId());
}
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)

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