WorkspaceManager { public Page<WorkspaceImpl> getWorkspaces( String user, boolean includeRuntimes, int maxItems, long skipCount) throws ServerException { requireNonNull(user, "Required non-null user id"); final Page<WorkspaceImpl> workspaces = workspaceDao.getWorkspaces(user, maxItems, skipCount); for (WorkspaceImpl workspace : workspaces.getItems()) { normalizeState(workspace, includeRuntimes); } return workspaces; } @Inject  WorkspaceManager(
      WorkspaceDao workspaceDao,
      WorkspaceRuntimes runtimes,
      EventService eventService,
      AccountManager accountManager,
      PreferenceManager preferenceManager,
      WorkspaceValidator validator,
      DevfileIntegrityValidator devfileIntegrityValidator); @Traced WorkspaceImpl createWorkspace(
      WorkspaceConfig config, String namespace, Map<String, String> attributes); @Traced WorkspaceImpl createWorkspace(
      Devfile devfile,
      String namespace,
      Map<String, String> attributes,
      FileContentProvider contentProvider); WorkspaceImpl getWorkspace(String key); WorkspaceImpl getWorkspace(String name, String namespace); Page<WorkspaceImpl> getWorkspaces(
      String user, boolean includeRuntimes, int maxItems, long skipCount); Page<WorkspaceImpl> getByNamespace(
      String namespace, boolean includeRuntimes, int maxItems, long skipCount); WorkspaceImpl updateWorkspace(String id, Workspace update); @Traced void removeWorkspace(String workspaceId); WorkspaceImpl startWorkspace(
      String workspaceId, @Nullable String envName, @Nullable Map<String, String> options); WorkspaceImpl startWorkspace(
      WorkspaceConfig config, String namespace, boolean isTemporary, Map<String, String> options); void stopWorkspace(String workspaceId, Map<String, String> options); Set<String> getSupportedRecipes(); long getWorkspacesTotalCount();  }
@Test public void getsWorkspacesAvailableForUserWithRuntimes() throws Exception { final WorkspaceConfig config = createConfig(); final WorkspaceImpl workspace1 = createAndMockWorkspace(config, NAMESPACE_1); final WorkspaceImpl workspace2 = createAndMockWorkspace(config, NAMESPACE_2); final TestRuntime runtime2 = mockRuntime(workspace2, RUNNING); when(workspaceDao.getWorkspaces(eq(NAMESPACE_1), anyInt(), anyLong())) .thenReturn(new Page<>(asList(workspace1, workspace2), 0, 2, 2)); final Page<WorkspaceImpl> result = workspaceManager.getWorkspaces(NAMESPACE_1, true, 30, 0); assertEquals(result.getItems().size(), 2); final WorkspaceImpl res1 = result.getItems().get(0); assertEquals( res1.getStatus(), STOPPED, "Workspace status wasn't changed from STARTING to STOPPED"); assertNull(res1.getRuntime(), "Workspace has unexpected runtime"); assertFalse(res1.isTemporary(), "Workspace must be permanent"); final WorkspaceImpl res2 = result.getItems().get(1); assertEquals( res2.getStatus(), RUNNING, "Workspace status wasn't changed to the runtime instance status"); assertEquals( res2.getRuntime(), new RuntimeImpl(runtime2), "Workspace doesn't have expected runtime"); assertFalse(res2.isTemporary(), "Workspace must be permanent"); }
@Test public void getsWorkspacesAvailableForUserWithoutRuntimes() throws Exception { final WorkspaceConfig config = createConfig(); final WorkspaceImpl workspace1 = createAndMockWorkspace(config, NAMESPACE_1); final WorkspaceImpl workspace2 = createAndMockWorkspace(config, NAMESPACE_2); when(workspaceDao.getWorkspaces(eq(NAMESPACE_1), anyInt(), anyLong())) .thenReturn(new Page<>(asList(workspace1, workspace2), 0, 2, 2)); mockRuntimeStatus(workspace1, STOPPED); mockRuntimeStatus(workspace2, RUNNING); doNothing().when(runtimes).injectRuntime(workspace1); final Page<WorkspaceImpl> result = workspaceManager.getWorkspaces(NAMESPACE_1, false, 30, 0); assertEquals(result.getItems().size(), 2); final WorkspaceImpl res1 = result.getItems().get(0); assertEquals( res1.getStatus(), STOPPED, "Workspace status wasn't changed from STARTING to STOPPED"); assertNull(res1.getRuntime(), "Workspace has unexpected runtime"); assertFalse(res1.isTemporary(), "Workspace must be permanent"); final WorkspaceImpl res2 = result.getItems().get(1); assertEquals( res2.getStatus(), RUNNING, "Workspace status wasn't changed to the runtime instance status"); assertNull(res1.getRuntime(), "Workspace has unexpected runtime"); assertFalse(res2.isTemporary(), "Workspace must be permanent"); }