KubernetesNamespaceFactory { public List<KubernetesNamespaceMeta> list() throws InfrastructureException { if (!allowUserDefinedNamespaces) { return singletonList(getDefaultNamespace()); } List<KubernetesNamespaceMeta> namespaces = fetchNamespaces(); provisionDefaultNamespace(namespaces); return namespaces; } @Inject  KubernetesNamespaceFactory(
      @Nullable @Named("che.infra.kubernetes.namespace") String legacyNamespaceName,
      @Nullable @Named("che.infra.kubernetes.service_account_name") String serviceAccountName,
      @Nullable @Named("che.infra.kubernetes.workspace_sa_cluster_roles") String clusterRoleNames,
      @Nullable @Named("che.infra.kubernetes.namespace.default") String defaultNamespaceName,
      @Named("che.infra.kubernetes.namespace.allow_user_defined")
          boolean allowUserDefinedNamespaces,
      @Named("che.infra.kubernetes.namespace.creation_allowed") boolean namespaceCreationAllowed,
      KubernetesClientFactory clientFactory,
      UserManager userManager,
      PreferenceManager preferenceManager,
      KubernetesSharedPool sharedPool); KubernetesNamespace access(String workspaceId, String namespace); void checkIfNamespaceIsAllowed(String namespaceName); List<KubernetesNamespaceMeta> list(); KubernetesNamespace getOrCreate(RuntimeIdentity identity); KubernetesNamespace get(RuntimeIdentity identity); KubernetesNamespace get(Workspace workspace); String evaluateLegacyNamespaceName(NamespaceResolutionContext resolutionCtx); String evaluateNamespaceName(NamespaceResolutionContext resolutionCtx); void deleteIfManaged(Workspace workspace);  }
@Test( expectedExceptions = InfrastructureException.class, expectedExceptionsMessageRegExp = "Error occurred when tried to fetch default namespace. Cause: connection refused") public void shouldThrowExceptionWhenFailedToGetInfoAboutDefaultNamespace() throws Exception { namespaceFactory = new KubernetesNamespaceFactory( "predefined", "", "", "che", false, true, clientFactory, userManager, preferenceManager, pool); throwOnTryToGetNamespaceByName("che", new KubernetesClientException("connection refused")); namespaceFactory.list(); }
@Test( expectedExceptions = InfrastructureException.class, expectedExceptionsMessageRegExp = "Error occurred when tried to list all available namespaces. Cause: connection refused") public void shouldThrowExceptionWhenFailedToGetNamespaces() throws Exception { namespaceFactory = new KubernetesNamespaceFactory( "predefined", "", "", "default_ns", true, true, clientFactory, userManager, preferenceManager, pool); throwOnTryToGetNamespacesList(new KubernetesClientException("connection refused")); namespaceFactory.list(); }