use of org.eclipse.che.api.workspace.server.spi.NamespaceResolutionContext in project che-server by eclipse-che.
the class WorkspaceServiceAccountConfiguratorTest method setUp.
@BeforeMethod
public void setUp() throws InfrastructureException {
configurator = spy(new WorkspaceServiceAccountConfigurator(TEST_SERVICE_ACCOUNT, TEST_CLUSTER_ROLES, clientFactory));
// when(configurator.doCreateServiceAccount(TEST_WORKSPACE_ID,
// TEST_NAMESPACE_NAME)).thenReturn(kubeWSA);
serverMock = new KubernetesServer(true, true);
serverMock.before();
client = spy(serverMock.getClient());
lenient().when(clientFactory.create(TEST_WORKSPACE_ID)).thenReturn(client);
namespaceResolutionContext = new NamespaceResolutionContext(TEST_WORKSPACE_ID, TEST_USER_ID, TEST_USERNAME);
}
use of org.eclipse.che.api.workspace.server.spi.NamespaceResolutionContext in project che-server by eclipse-che.
the class KubernetesNamespaceServiceTest method shouldProvisionNamespaceWithCorrectContext.
@Test
public void shouldProvisionNamespaceWithCorrectContext() throws Exception {
// given
KubernetesNamespaceMetaImpl namespaceMeta = new KubernetesNamespaceMetaImpl("ws-namespace", ImmutableMap.of("phase", "active", "default", "true"));
when(namespaceProvisioner.provision(any(NamespaceResolutionContext.class))).thenReturn(namespaceMeta);
// when
final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).when().post(SECURE_PATH + "/kubernetes/namespace/provision");
// then
assertEquals(response.getStatusCode(), 200);
ArgumentCaptor<NamespaceResolutionContext> captor = ArgumentCaptor.forClass(NamespaceResolutionContext.class);
verify(namespaceProvisioner).provision(captor.capture());
NamespaceResolutionContext actualContext = captor.getValue();
assertEquals(actualContext.getUserId(), SUBJECT.getUserId());
assertEquals(actualContext.getUserName(), SUBJECT.getUserName());
Assert.assertNull(actualContext.getWorkspaceId());
}
use of org.eclipse.che.api.workspace.server.spi.NamespaceResolutionContext in project che-server by eclipse-che.
the class WorkspaceManagerTest method evaluatesLegacyInfraNamespaceIfMissingOnWorkspaceStart.
@Test
public void evaluatesLegacyInfraNamespaceIfMissingOnWorkspaceStart() throws Exception {
DevfileImpl devfile = mock(DevfileImpl.class);
WorkspaceImpl workspace = createAndMockWorkspace(devfile, NAMESPACE_1, new HashMap<>());
workspace.getAttributes().remove(WORKSPACE_INFRASTRUCTURE_NAMESPACE_ATTRIBUTE);
when(runtimes.evalInfrastructureNamespace(any())).thenReturn("evaluated-legacy");
mockAnyWorkspaceStart();
workspaceManager.startWorkspace(workspace.getId(), null, emptyMap());
verify(runtimes).startAsync(eq(workspace), eq(null), anyMap());
verify(workspaceDao, times(2)).update(workspaceCaptor.capture());
assertEquals(workspaceCaptor.getAllValues().get(0).getAttributes().get(WORKSPACE_INFRASTRUCTURE_NAMESPACE_ATTRIBUTE), "evaluated-legacy");
verify(runtimes).evalInfrastructureNamespace(new NamespaceResolutionContext(workspace.getId(), USER_ID, NAMESPACE_1));
}
use of org.eclipse.che.api.workspace.server.spi.NamespaceResolutionContext in project che-server by eclipse-che.
the class WorkspaceManagerTest method evaluatesDefaultInfraNamespaceIfInvalidOnWorkspaceStart.
@Test
public void evaluatesDefaultInfraNamespaceIfInvalidOnWorkspaceStart() throws Exception {
DevfileImpl devfile = mock(DevfileImpl.class);
WorkspaceImpl workspace = createAndMockWorkspace(devfile, NAMESPACE_1, ImmutableMap.of(WORKSPACE_INFRASTRUCTURE_NAMESPACE_ATTRIBUTE, "-invalid-dns-name"));
when(runtimes.evalInfrastructureNamespace(any())).thenReturn("evaluated-legal");
when(runtimes.isInfrastructureNamespaceValid(eq("-invalid-dns-name"))).thenReturn(false);
mockAnyWorkspaceStart();
workspaceManager.startWorkspace(workspace.getId(), null, emptyMap());
verify(runtimes).startAsync(eq(workspace), eq(null), anyMap());
verify(workspaceDao, times(2)).update(workspaceCaptor.capture());
assertEquals(workspaceCaptor.getAllValues().get(0).getAttributes().get(WORKSPACE_INFRASTRUCTURE_NAMESPACE_ATTRIBUTE), "evaluated-legal");
verify(runtimes).evalInfrastructureNamespace(new NamespaceResolutionContext(workspace.getId(), USER_ID, NAMESPACE_1));
}
use of org.eclipse.che.api.workspace.server.spi.NamespaceResolutionContext in project che-server by eclipse-che.
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"));
}
Aggregations