Search in sources :

Example 86 with RuntimeIdentityImpl

use of org.eclipse.che.api.workspace.server.model.impl.RuntimeIdentityImpl in project devspaces-images by redhat-developer.

the class KubernetesNamespaceFactoryTest method shouldPrepareWorkspaceServiceAccountIfItIsConfiguredAndNamespaceIsNotPredefined.

@Test
public void shouldPrepareWorkspaceServiceAccountIfItIsConfiguredAndNamespaceIsNotPredefined() throws Exception {
    // given
    var serviceAccountCfg = spy(new WorkspaceServiceAccountConfigurator("serviceAccount", "", clientFactory));
    namespaceFactory = spy(new KubernetesNamespaceFactory("<username>-che", true, true, true, NAMESPACE_LABELS, NAMESPACE_ANNOTATIONS, Set.of(serviceAccountCfg), clientFactory, cheClientFactory, userManager, preferenceManager, pool));
    KubernetesNamespace toReturnNamespace = mock(KubernetesNamespace.class);
    prepareNamespace(toReturnNamespace);
    when(toReturnNamespace.getName()).thenReturn("workspace123");
    doReturn(toReturnNamespace).when(namespaceFactory).doCreateNamespaceAccess(any(), any());
    KubernetesWorkspaceServiceAccount serviceAccount = mock(KubernetesWorkspaceServiceAccount.class);
    doReturn(serviceAccount).when(serviceAccountCfg).doCreateServiceAccount(any(), any());
    // when
    RuntimeIdentity identity = new RuntimeIdentityImpl("workspace123", null, USER_ID, "workspace123");
    namespaceFactory.getOrCreate(identity);
    // then
    verify(serviceAccountCfg).doCreateServiceAccount("workspace123", "workspace123");
    verify(serviceAccount).prepare();
}
Also used : RuntimeIdentity(org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity) WorkspaceServiceAccountConfigurator(org.eclipse.che.workspace.infrastructure.kubernetes.namespace.configurator.WorkspaceServiceAccountConfigurator) RuntimeIdentityImpl(org.eclipse.che.api.workspace.server.model.impl.RuntimeIdentityImpl) Test(org.testng.annotations.Test)

Example 87 with RuntimeIdentityImpl

use of org.eclipse.che.api.workspace.server.model.impl.RuntimeIdentityImpl in project devspaces-images by redhat-developer.

the class BrokerStatusListenerTest method shouldNotCallAddResultWhenValidationFails.

@Test
public void shouldNotCallAddResultWhenValidationFails() throws Exception {
    // given
    doThrow(new ValidationException("test")).when(validator).validatePluginNames(anyList());
    BrokerEvent event = new BrokerEvent().withRuntimeId(new RuntimeIdentityImpl(WORKSPACE_ID, null, null, null)).withStatus(BrokerStatus.DONE).withTooling(emptyList());
    // when
    brokerStatusListener.onEvent(event);
    // then
    verify(brokersResult, never()).setResult(anyList());
}
Also used : ValidationException(org.eclipse.che.api.core.ValidationException) RuntimeIdentityImpl(org.eclipse.che.api.workspace.server.model.impl.RuntimeIdentityImpl) Test(org.testng.annotations.Test)

Example 88 with RuntimeIdentityImpl

use of org.eclipse.che.api.workspace.server.model.impl.RuntimeIdentityImpl in project devspaces-images by redhat-developer.

the class BrokerStatusListenerTest method shouldSubmitErrorWhenDoneEventIsReceivedButToolingIsValidationFails.

@Test
public void shouldSubmitErrorWhenDoneEventIsReceivedButToolingIsValidationFails() throws Exception {
    // given
    doThrow(new ValidationException("test")).when(validator).validatePluginNames(anyList());
    BrokerEvent event = new BrokerEvent().withRuntimeId(new RuntimeIdentityImpl(WORKSPACE_ID, null, null, null)).withStatus(BrokerStatus.DONE).withTooling(emptyList());
    // when
    brokerStatusListener.onEvent(event);
    // then
    verify(brokersResult).error(any(ValidationException.class));
}
Also used : ValidationException(org.eclipse.che.api.core.ValidationException) RuntimeIdentityImpl(org.eclipse.che.api.workspace.server.model.impl.RuntimeIdentityImpl) Test(org.testng.annotations.Test)

Example 89 with RuntimeIdentityImpl

use of org.eclipse.che.api.workspace.server.model.impl.RuntimeIdentityImpl in project devspaces-images by redhat-developer.

the class BrokerStatusListenerTest method shouldSubmitErrorWhenFailedEventIsReceived.

@Test
public void shouldSubmitErrorWhenFailedEventIsReceived() {
    // given
    BrokerEvent event = new BrokerEvent().withRuntimeId(new RuntimeIdentityImpl(WORKSPACE_ID, null, null, null)).withStatus(BrokerStatus.FAILED).withError("error");
    // when
    brokerStatusListener.onEvent(event);
    // then
    verify(brokersResult).error(any(InfrastructureException.class));
}
Also used : RuntimeIdentityImpl(org.eclipse.che.api.workspace.server.model.impl.RuntimeIdentityImpl) InfrastructureException(org.eclipse.che.api.workspace.server.spi.InfrastructureException) InternalInfrastructureException(org.eclipse.che.api.workspace.server.spi.InternalInfrastructureException) Test(org.testng.annotations.Test)

Example 90 with RuntimeIdentityImpl

use of org.eclipse.che.api.workspace.server.model.impl.RuntimeIdentityImpl in project devspaces-images by redhat-developer.

the class OpenShiftProjectFactoryTest method shouldNotCreatePreferencesConfigmapIfExist.

@Test
public void shouldNotCreatePreferencesConfigmapIfExist() throws Exception {
    // given
    projectFactory = spy(new OpenShiftProjectFactory("<userid>-che", true, true, true, NAMESPACE_LABELS, NAMESPACE_ANNOTATIONS, true, Set.of(new PreferencesConfigMapConfigurator(clientFactory)), clientFactory, cheClientFactory, cheServerOpenshiftClientFactory, userManager, preferenceManager, pool, NO_OAUTH_IDENTITY_PROVIDER));
    OpenShiftProject toReturnProject = mock(OpenShiftProject.class);
    prepareProject(toReturnProject);
    doReturn(toReturnProject).when(projectFactory).doCreateProjectAccess(any(), any());
    when(toReturnProject.getName()).thenReturn("namespace123");
    NonNamespaceOperation namespaceOperation = mock(NonNamespaceOperation.class);
    MixedOperation mixedOperation = mock(MixedOperation.class);
    when(osClient.configMaps()).thenReturn(mixedOperation);
    when(mixedOperation.inNamespace(anyString())).thenReturn(namespaceOperation);
    Resource<ConfigMap> cmResource = mock(Resource.class);
    when(namespaceOperation.withName(PREFERENCES_CONFIGMAP_NAME)).thenReturn(cmResource);
    when(cmResource.get()).thenReturn(mock(ConfigMap.class));
    // when
    RuntimeIdentity identity = new RuntimeIdentityImpl("workspace123", null, USER_ID, "workspace123");
    projectFactory.getOrCreate(identity);
    // then
    verify(namespaceOperation, never()).create(any());
}
Also used : RuntimeIdentity(org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity) PreferencesConfigMapConfigurator(org.eclipse.che.workspace.infrastructure.kubernetes.namespace.configurator.PreferencesConfigMapConfigurator) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) MixedOperation(io.fabric8.kubernetes.client.dsl.MixedOperation) NonNamespaceOperation(io.fabric8.kubernetes.client.dsl.NonNamespaceOperation) RuntimeIdentityImpl(org.eclipse.che.api.workspace.server.model.impl.RuntimeIdentityImpl) Test(org.testng.annotations.Test)

Aggregations

RuntimeIdentityImpl (org.eclipse.che.api.workspace.server.model.impl.RuntimeIdentityImpl)98 Test (org.testng.annotations.Test)92 RuntimeIdentity (org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity)68 WorkspaceImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl)22 MixedOperation (io.fabric8.kubernetes.client.dsl.MixedOperation)18 RuntimeContext (org.eclipse.che.api.workspace.server.spi.RuntimeContext)18 InternalEnvironment (org.eclipse.che.api.workspace.server.spi.environment.InternalEnvironment)16 InfrastructureException (org.eclipse.che.api.workspace.server.spi.InfrastructureException)14 SubjectImpl (org.eclipse.che.commons.subject.SubjectImpl)12 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)12 NonNamespaceOperation (io.fabric8.kubernetes.client.dsl.NonNamespaceOperation)10 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)8 Secret (io.fabric8.kubernetes.api.model.Secret)8 ValidationException (org.eclipse.che.api.core.ValidationException)8 Environment (org.eclipse.che.api.core.model.workspace.config.Environment)8 EventService (org.eclipse.che.api.core.notification.EventService)8 InternalInfrastructureException (org.eclipse.che.api.workspace.server.spi.InternalInfrastructureException)8 CredentialsSecretConfigurator (org.eclipse.che.workspace.infrastructure.kubernetes.namespace.configurator.CredentialsSecretConfigurator)8 PreferencesConfigMapConfigurator (org.eclipse.che.workspace.infrastructure.kubernetes.namespace.configurator.PreferencesConfigMapConfigurator)8 WorkspaceServiceAccountConfigurator (org.eclipse.che.workspace.infrastructure.kubernetes.namespace.configurator.WorkspaceServiceAccountConfigurator)8