Search in sources :

Example 31 with NamespaceResolutionContext

use of org.eclipse.che.api.workspace.server.spi.NamespaceResolutionContext in project che-server by eclipse-che.

the class KubernetesNamespaceFactoryTest method testEvalNamespaceUsesNamespaceFromUserPreferencesIfExist.

@Test
public void testEvalNamespaceUsesNamespaceFromUserPreferencesIfExist() throws Exception {
    namespaceFactory = new KubernetesNamespaceFactory("che-<userid>", true, true, true, NAMESPACE_LABELS, NAMESPACE_ANNOTATIONS, emptySet(), clientFactory, cheClientFactory, userManager, preferenceManager, pool);
    Map<String, String> prefs = new HashMap<>();
    prefs.put(WORKSPACE_INFRASTRUCTURE_NAMESPACE_ATTRIBUTE, "che-123");
    prefs.put(NAMESPACE_TEMPLATE_ATTRIBUTE, "che-<userid>");
    when(preferenceManager.find(anyString())).thenReturn(prefs);
    String namespace = namespaceFactory.evaluateNamespaceName(new NamespaceResolutionContext("workspace123", "user123", "jondoe"));
    assertEquals(namespace, "che-123");
}
Also used : NamespaceResolutionContext(org.eclipse.che.api.workspace.server.spi.NamespaceResolutionContext) HashMap(java.util.HashMap) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.testng.annotations.Test)

Example 32 with NamespaceResolutionContext

use of org.eclipse.che.api.workspace.server.spi.NamespaceResolutionContext in project che-server by eclipse-che.

the class CredentialsSecretConfiguratorTest method setUp.

@BeforeMethod
public void setUp() throws InfrastructureException {
    configurator = new CredentialsSecretConfigurator(clientFactory);
    serverMock = new KubernetesServer(true, true);
    serverMock.before();
    KubernetesClient client = spy(serverMock.getClient());
    when(clientFactory.create()).thenReturn(client);
    namespaceResolutionContext = new NamespaceResolutionContext(TEST_WORKSPACE_ID, TEST_USER_ID, TEST_USERNAME);
}
Also used : NamespaceResolutionContext(org.eclipse.che.api.workspace.server.spi.NamespaceResolutionContext) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) KubernetesServer(io.fabric8.kubernetes.client.server.mock.KubernetesServer) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 33 with NamespaceResolutionContext

use of org.eclipse.che.api.workspace.server.spi.NamespaceResolutionContext in project che-server by eclipse-che.

the class PreferencesConfigMapConfiguratorTest method setUp.

@BeforeMethod
public void setUp() throws InfrastructureException {
    configurator = new PreferencesConfigMapConfigurator(clientFactory);
    serverMock = new KubernetesServer(true, true);
    serverMock.before();
    KubernetesClient client = spy(serverMock.getClient());
    when(clientFactory.create()).thenReturn(client);
    namespaceResolutionContext = new NamespaceResolutionContext(TEST_WORKSPACE_ID, TEST_USER_ID, TEST_USERNAME);
}
Also used : NamespaceResolutionContext(org.eclipse.che.api.workspace.server.spi.NamespaceResolutionContext) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) KubernetesServer(io.fabric8.kubernetes.client.server.mock.KubernetesServer) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 34 with NamespaceResolutionContext

use of org.eclipse.che.api.workspace.server.spi.NamespaceResolutionContext in project che-server by eclipse-che.

the class SshKeysConfiguratorTest method setUp.

@BeforeMethod
public void setUp() throws InfrastructureException, NotFoundException, ServerException {
    context = new NamespaceResolutionContext(null, USER_ID, USER_NAME);
    kubernetesServer = new KubernetesServer(true, true);
    kubernetesServer.before();
    when(sshManager.getPairs(USER_ID, "vcs")).thenReturn(Collections.singletonList(sshPair));
    when(clientFactory.create()).thenReturn(kubernetesServer.getClient());
}
Also used : NamespaceResolutionContext(org.eclipse.che.api.workspace.server.spi.NamespaceResolutionContext) KubernetesServer(io.fabric8.kubernetes.client.server.mock.KubernetesServer) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 35 with NamespaceResolutionContext

use of org.eclipse.che.api.workspace.server.spi.NamespaceResolutionContext in project che-server by eclipse-che.

the class UserPreferencesConfiguratorTest method setUp.

@BeforeMethod
public void setUp() throws InfrastructureException, NotFoundException, ServerException {
    context = new NamespaceResolutionContext(null, USER_ID, USER_NAME);
    kubernetesServer = new KubernetesServer(true, true);
    kubernetesServer.before();
    Map<String, String> preferences = new HashMap<>();
    preferences.put("preference-name", "preference");
    lenient().when(userManager.getById(USER_ID)).thenReturn(new UserImpl(USER_ID, USER_EMAIL, USER_NAME));
    lenient().when(namespaceFactory.evaluateNamespaceName(any())).thenReturn(USER_NAMESPACE);
    lenient().when(clientFactory.create()).thenReturn(kubernetesServer.getClient());
    lenient().when(preferenceManager.find(USER_ID)).thenReturn(preferences);
}
Also used : NamespaceResolutionContext(org.eclipse.che.api.workspace.server.spi.NamespaceResolutionContext) HashMap(java.util.HashMap) UserImpl(org.eclipse.che.api.user.server.model.impl.UserImpl) KubernetesServer(io.fabric8.kubernetes.client.server.mock.KubernetesServer) BeforeMethod(org.testng.annotations.BeforeMethod)

Aggregations

NamespaceResolutionContext (org.eclipse.che.api.workspace.server.spi.NamespaceResolutionContext)56 Test (org.testng.annotations.Test)30 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)16 KubernetesServer (io.fabric8.kubernetes.client.server.mock.KubernetesServer)14 BeforeMethod (org.testng.annotations.BeforeMethod)14 HashMap (java.util.HashMap)8 KubernetesNamespaceMetaImpl (org.eclipse.che.workspace.infrastructure.kubernetes.api.server.impls.KubernetesNamespaceMetaImpl)8 WorkspaceImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl)6 InfrastructureException (org.eclipse.che.api.workspace.server.spi.InfrastructureException)6 KubernetesNamespaceMeta (org.eclipse.che.workspace.infrastructure.kubernetes.api.shared.KubernetesNamespaceMeta)6 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)4 RuntimeIdentity (org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity)4 UserImpl (org.eclipse.che.api.user.server.model.impl.UserImpl)4 RuntimeIdentityImpl (org.eclipse.che.api.workspace.server.model.impl.RuntimeIdentityImpl)4 DevfileImpl (org.eclipse.che.api.workspace.server.model.impl.devfile.DevfileImpl)4 SubjectImpl (org.eclipse.che.commons.subject.SubjectImpl)4 NamespaceConfigurator (org.eclipse.che.workspace.infrastructure.kubernetes.namespace.configurator.NamespaceConfigurator)4 Namespace (io.fabric8.kubernetes.api.model.Namespace)2 NamespaceBuilder (io.fabric8.kubernetes.api.model.NamespaceBuilder)2 Project (io.fabric8.openshift.api.model.Project)2