use of org.eclipse.che.workspace.infrastructure.kubernetes.api.shared.KubernetesNamespaceMeta in project che-server by eclipse-che.
the class OpenShiftProjectFactoryTest method shouldReturnDefaultProjectWhenItDoesNotExistAndUserDefinedIsNotAllowed.
@Test
public void shouldReturnDefaultProjectWhenItDoesNotExistAndUserDefinedIsNotAllowed() throws Exception {
throwOnTryToGetProjectByName(USER_NAME + "-che", new KubernetesClientException("forbidden", 403, null));
projectFactory = new OpenShiftProjectFactory("<username>-che", true, true, true, NAMESPACE_LABELS, NAMESPACE_ANNOTATIONS, true, emptySet(), clientFactory, cheClientFactory, cheServerOpenshiftClientFactory, userManager, preferenceManager, pool, NO_OAUTH_IDENTITY_PROVIDER);
List<KubernetesNamespaceMeta> availableNamespaces = projectFactory.list();
assertEquals(availableNamespaces.size(), 1);
KubernetesNamespaceMeta defaultNamespace = availableNamespaces.get(0);
assertEquals(defaultNamespace.getName(), USER_NAME + "-che");
assertEquals(defaultNamespace.getAttributes().get(DEFAULT_ATTRIBUTE), "true");
assertNull(defaultNamespace.getAttributes().get(// no phase - means such project does not exist
PHASE_ATTRIBUTE));
}
use of org.eclipse.che.workspace.infrastructure.kubernetes.api.shared.KubernetesNamespaceMeta in project devspaces-images by redhat-developer.
the class KubernetesNamespaceFactoryTest method shouldReturnDefaultNamespaceWhenItExists.
@Test
public void shouldReturnDefaultNamespaceWhenItExists() throws Exception {
prepareNamespaceToBeFoundByName("jondoe-che", new NamespaceBuilder().withNewMetadata().withName("jondoe-che").endMetadata().withNewStatus().withNewPhase("Active").endStatus().build());
namespaceFactory = new KubernetesNamespaceFactory("<username>-che", true, true, true, NAMESPACE_LABELS, NAMESPACE_ANNOTATIONS, emptySet(), clientFactory, cheClientFactory, userManager, preferenceManager, pool);
List<KubernetesNamespaceMeta> availableNamespaces = namespaceFactory.list();
assertEquals(availableNamespaces.size(), 1);
KubernetesNamespaceMeta defaultNamespace = availableNamespaces.get(0);
assertEquals(defaultNamespace.getName(), "jondoe-che");
assertEquals(defaultNamespace.getAttributes().get(DEFAULT_ATTRIBUTE), "true");
assertEquals(defaultNamespace.getAttributes().get(PHASE_ATTRIBUTE), "Active");
}
use of org.eclipse.che.workspace.infrastructure.kubernetes.api.shared.KubernetesNamespaceMeta in project devspaces-images by redhat-developer.
the class KubernetesNamespaceFactoryTest method shouldReturnDefaultNamespaceWhenItDoesNotExistAndUserDefinedIsNotAllowed.
@Test
public void shouldReturnDefaultNamespaceWhenItDoesNotExistAndUserDefinedIsNotAllowed() throws Exception {
prepareNamespaceToBeFoundByName("jondoe-che", null);
namespaceFactory = new KubernetesNamespaceFactory("<username>-che", true, true, true, NAMESPACE_LABELS, NAMESPACE_ANNOTATIONS, emptySet(), clientFactory, cheClientFactory, userManager, preferenceManager, pool);
List<KubernetesNamespaceMeta> availableNamespaces = namespaceFactory.list();
assertEquals(availableNamespaces.size(), 1);
KubernetesNamespaceMeta defaultNamespace = availableNamespaces.get(0);
assertEquals(defaultNamespace.getName(), "jondoe-che");
assertEquals(defaultNamespace.getAttributes().get(DEFAULT_ATTRIBUTE), "true");
assertNull(defaultNamespace.getAttributes().get(// no phase - means such namespace does not exist
PHASE_ATTRIBUTE));
}
use of org.eclipse.che.workspace.infrastructure.kubernetes.api.shared.KubernetesNamespaceMeta in project devspaces-images by redhat-developer.
the class KubernetesNamespaceFactoryTest method shouldHandleProvision.
@Test
public void shouldHandleProvision() throws InfrastructureException {
// given
namespaceFactory = spy(new KubernetesNamespaceFactory("<username>-che", false, true, true, NAMESPACE_LABELS, NAMESPACE_ANNOTATIONS, emptySet(), clientFactory, cheClientFactory, userManager, preferenceManager, pool));
KubernetesNamespace toReturnNamespace = mock(KubernetesNamespace.class);
prepareNamespace(toReturnNamespace);
when(toReturnNamespace.getName()).thenReturn("jondoe-che");
doReturn(toReturnNamespace).when(namespaceFactory).doCreateNamespaceAccess(any(), any());
KubernetesNamespaceMetaImpl namespaceMeta = new KubernetesNamespaceMetaImpl("jondoe-che", ImmutableMap.of("phase", "active", "default", "true"));
doReturn(Optional.of(namespaceMeta)).when(namespaceFactory).fetchNamespace(eq("jondoe-che"));
// when
NamespaceResolutionContext context = new NamespaceResolutionContext("workspace123", "user123", "jondoe");
KubernetesNamespaceMeta actual = testProvisioning(context);
// then
assertEquals(actual.getName(), "jondoe-che");
assertEquals(actual.getAttributes(), ImmutableMap.of("phase", "active", "default", "true"));
}
use of org.eclipse.che.workspace.infrastructure.kubernetes.api.shared.KubernetesNamespaceMeta in project devspaces-images by redhat-developer.
the class KubernetesNamespaceFactoryTest method shouldNotThrowAnExceptionWhenNotAllowedToListNamespaces.
@Test
public void shouldNotThrowAnExceptionWhenNotAllowedToListNamespaces() throws Exception {
// given
Namespace ns = new NamespaceBuilder().withNewMetadata().withName("ns1").endMetadata().withNewStatus().withNewPhase("Active").endStatus().build();
doThrow(new KubernetesClientException("Not allowed.", 403, new Status())).when(namespaceList).getItems();
prepareNamespaceToBeFoundByName("jondoe-che", ns);
namespaceFactory = new KubernetesNamespaceFactory("<username>-che", true, true, true, NAMESPACE_LABELS, NAMESPACE_ANNOTATIONS, emptySet(), clientFactory, cheClientFactory, userManager, preferenceManager, pool);
EnvironmentContext.getCurrent().setSubject(new SubjectImpl("jondoe", "123", null, false));
// when
List<KubernetesNamespaceMeta> availableNamespaces = namespaceFactory.list();
// then
assertEquals(availableNamespaces.get(0).getName(), "ns1");
}
Aggregations