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");
}
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());
}
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());
}
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);
}
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());
}
Aggregations