WorkspaceRuntimes { public void validate(WorkspaceImpl workspace, @Nullable String envName) throws ValidationException, NotFoundException, ServerException { WorkspaceConfigImpl config = workspace.getConfig(); if (workspace.getDevfile() != null) { config = devfileConverter.convert(workspace.getDevfile()); } if (envName != null && !config.getEnvironments().containsKey(envName)) { throw new NotFoundException( format( "Workspace '%s:%s' doesn't contain environment '%s'", workspace.getNamespace(), config.getName(), envName)); } if (envName == null) { envName = config.getDefaultEnv(); } if (envName == null && SidecarToolingWorkspaceUtil.isSidecarBasedWorkspace(config.getAttributes())) { return; } if (envName == null) { throw new NotFoundException( format( "Workspace %s:%s can't use null environment", workspace.getNamespace(), config.getName())); } Environment environment = config.getEnvironments().get(envName); if (environment == null) { throw new NotFoundException( format( "Workspace does not have environment with name %s that specified to be run", envName)); } String type = environment.getRecipe().getType(); if (!infrastructure.getRecipeTypes().contains(type)) { throw new NotFoundException("Infrastructure not found for type: " + type); } try { createInternalEnvironment(environment, emptyMap(), emptyList(), config.getDevfile()); } catch (InfrastructureException e) { throw new ServerException(e.getMessage(), e); } } @VisibleForTesting  WorkspaceRuntimes(
      ConcurrentMap<String, InternalRuntime<?>> runtimes,
      EventService eventService,
      Map<String, InternalEnvironmentFactory> envFactories,
      RuntimeInfrastructure infra,
      WorkspaceSharedPool sharedPool,
      WorkspaceDao workspaceDao,
      @SuppressWarnings("unused") DBInitializer ignored,
      ProbeScheduler probeScheduler,
      WorkspaceStatusCache statuses,
      WorkspaceLockService lockService,
      DevfileConverter devfileConverter); @Inject  WorkspaceRuntimes(
      EventService eventService,
      Map<String, InternalEnvironmentFactory> envFactories,
      RuntimeInfrastructure infra,
      WorkspaceSharedPool sharedPool,
      WorkspaceDao workspaceDao,
      @SuppressWarnings("unused") DBInitializer ignored,
      ProbeScheduler probeScheduler,
      WorkspaceStatusCache statuses,
      WorkspaceLockService lockService,
      DevfileConverter devfileConverter); void validate(WorkspaceImpl workspace, @Nullable String envName); String evalInfrastructureNamespace(NamespaceResolutionContext resolutionCtx); String evalLegacyInfrastructureNamespace(NamespaceResolutionContext resolutionContext); boolean isInfrastructureNamespaceValid(String namespaceName); void injectRuntime(WorkspaceImpl workspace); boolean hasRuntime(String workspaceId); InternalRuntime<?> getInternalRuntime(String workspaceId); WorkspaceStatus getStatus(String workspaceId); @Traced CompletableFuture<Void> startAsync(
      WorkspaceImpl workspace, @Nullable String envName, Map<String, String> options); @Traced CompletableFuture<Void> stopAsync(WorkspaceImpl workspace, Map<String, String> options); boolean refuseStart(); Set<String> getRunning(); Set<String> getActive(); Set<String> getActive(String owner); boolean isAnyActive(); Set<String> getInProgress(); Set<String> getInProgress(String owner); boolean isAnyInProgress(); Optional<RuntimeContext> getRuntimeContext(String workspaceId); Set<String> getSupportedRecipes();  }
@Test( expectedExceptions = NotFoundException.class, expectedExceptionsMessageRegExp = "Workspace 'account:ws' doesn't contain environment 'non-existing'") public void throwsNotFoundExceptionWhenStartWorkspaceWithNotExistingEnv() throws Exception { final WorkspaceImpl workspace = new WorkspaceImpl(); WorkspaceConfigImpl config = new WorkspaceConfigImpl(); workspace.setAccount(new AccountImpl("acc123", "account", "any")); workspace.setConfig(config); config.setName("ws"); config.getEnvironments().put("default", new EnvironmentImpl()); runtimes.validate(workspace, "non-existing"); }