feat: adapted test for namespacesProvisioner
Signed-off-by: xbaran4 <pbaran@redhat.com>pull/117/head
parent
5b12d7db12
commit
d0aed8657d
|
|
@ -29,6 +29,8 @@ import java.util.stream.Collectors;
|
|||
import javax.inject.Inject;
|
||||
import org.eclipse.che.api.core.rest.Service;
|
||||
import org.eclipse.che.api.workspace.server.spi.InfrastructureException;
|
||||
import org.eclipse.che.api.workspace.server.spi.NamespaceResolutionContext;
|
||||
import org.eclipse.che.commons.env.EnvironmentContext;
|
||||
import org.eclipse.che.dto.server.DtoFactory;
|
||||
import org.eclipse.che.workspace.infrastructure.kubernetes.api.shared.KubernetesNamespaceMeta;
|
||||
import org.eclipse.che.workspace.infrastructure.kubernetes.api.shared.dto.KubernetesNamespaceMetaDto;
|
||||
|
|
@ -89,7 +91,9 @@ public class KubernetesNamespaceService extends Service {
|
|||
description = "Internal server error occurred during namespace provisioning")
|
||||
})
|
||||
public KubernetesNamespaceMetaDto provision() throws InfrastructureException {
|
||||
return asDto(namespaceProvisioner.provision());
|
||||
return asDto(
|
||||
namespaceProvisioner.provision(
|
||||
new NamespaceResolutionContext(EnvironmentContext.getCurrent().getSubject())));
|
||||
}
|
||||
|
||||
private KubernetesNamespaceMetaDto asDto(KubernetesNamespaceMeta kubernetesNamespaceMeta) {
|
||||
|
|
|
|||
|
|
@ -30,8 +30,6 @@ import org.eclipse.che.api.user.server.UserManager;
|
|||
import org.eclipse.che.api.user.server.event.PostUserPersistedEvent;
|
||||
import org.eclipse.che.api.workspace.server.spi.InfrastructureException;
|
||||
import org.eclipse.che.api.workspace.server.spi.NamespaceResolutionContext;
|
||||
import org.eclipse.che.commons.env.EnvironmentContext;
|
||||
import org.eclipse.che.commons.subject.Subject;
|
||||
import org.eclipse.che.workspace.infrastructure.kubernetes.KubernetesClientFactory;
|
||||
import org.eclipse.che.workspace.infrastructure.kubernetes.api.shared.KubernetesNamespaceMeta;
|
||||
import org.slf4j.Logger;
|
||||
|
|
@ -56,14 +54,13 @@ public class NamespaceProvisioner implements EventSubscriber<PostUserPersistedEv
|
|||
this.preferenceManager = preferenceManager;
|
||||
}
|
||||
|
||||
public KubernetesNamespaceMeta provision() throws InfrastructureException {
|
||||
public KubernetesNamespaceMeta provision(NamespaceResolutionContext namespaceResolutionContext)
|
||||
throws InfrastructureException {
|
||||
|
||||
Subject subject = EnvironmentContext.getCurrent().getSubject();
|
||||
KubernetesNamespaceMeta kubernetesNamespaceMeta =
|
||||
namespaceFactory.provision(new NamespaceResolutionContext(subject));
|
||||
|
||||
namespaceFactory.provision(namespaceResolutionContext);
|
||||
try {
|
||||
createOrUpdateSecrets(userManager.getById(subject.getUserId()));
|
||||
createOrUpdateSecrets(userManager.getById(namespaceResolutionContext.getUserId()));
|
||||
} catch (NotFoundException | ServerException e) {
|
||||
LOG.error("Could not find current user. Skipping creation of user information secrets.", e);
|
||||
} catch (InfrastructureException e) {
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ import org.eclipse.che.dto.server.DtoFactory;
|
|||
import org.eclipse.che.workspace.infrastructure.kubernetes.api.server.impls.KubernetesNamespaceMetaImpl;
|
||||
import org.eclipse.che.workspace.infrastructure.kubernetes.api.shared.dto.KubernetesNamespaceMetaDto;
|
||||
import org.eclipse.che.workspace.infrastructure.kubernetes.namespace.KubernetesNamespaceFactory;
|
||||
import org.eclipse.che.workspace.infrastructure.kubernetes.namespace.NamespaceProvisioner;
|
||||
import org.everrest.assured.EverrestJetty;
|
||||
import org.everrest.core.Filter;
|
||||
import org.everrest.core.GenericContainerRequest;
|
||||
|
|
@ -67,6 +68,7 @@ public class KubernetesNamespaceServiceTest {
|
|||
private CheJsonProvider jsonProvider = new CheJsonProvider(Collections.emptySet());
|
||||
|
||||
@Mock private KubernetesNamespaceFactory namespaceFactory;
|
||||
@Mock private NamespaceProvisioner namespaceProvisioner;
|
||||
|
||||
@InjectMocks private KubernetesNamespaceService service;
|
||||
|
||||
|
|
@ -98,7 +100,7 @@ public class KubernetesNamespaceServiceTest {
|
|||
KubernetesNamespaceMetaImpl namespaceMeta =
|
||||
new KubernetesNamespaceMetaImpl(
|
||||
"ws-namespace", ImmutableMap.of("phase", "active", "default", "true"));
|
||||
when(namespaceFactory.provision(any(NamespaceResolutionContext.class)))
|
||||
when(namespaceProvisioner.provision(any(NamespaceResolutionContext.class)))
|
||||
.thenReturn(namespaceMeta);
|
||||
// when
|
||||
final Response response =
|
||||
|
|
@ -113,7 +115,7 @@ public class KubernetesNamespaceServiceTest {
|
|||
KubernetesNamespaceMetaDto actual = unwrapDto(response, KubernetesNamespaceMetaDto.class);
|
||||
assertEquals(actual.getName(), namespaceMeta.getName());
|
||||
assertEquals(actual.getAttributes(), namespaceMeta.getAttributes());
|
||||
verify(namespaceFactory).provision(any(NamespaceResolutionContext.class));
|
||||
verify(namespaceProvisioner).provision(any(NamespaceResolutionContext.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -122,7 +124,7 @@ public class KubernetesNamespaceServiceTest {
|
|||
KubernetesNamespaceMetaImpl namespaceMeta =
|
||||
new KubernetesNamespaceMetaImpl(
|
||||
"ws-namespace", ImmutableMap.of("phase", "active", "default", "true"));
|
||||
when(namespaceFactory.provision(any(NamespaceResolutionContext.class)))
|
||||
when(namespaceProvisioner.provision(any(NamespaceResolutionContext.class)))
|
||||
.thenReturn(namespaceMeta);
|
||||
// when
|
||||
final Response response =
|
||||
|
|
@ -136,7 +138,7 @@ public class KubernetesNamespaceServiceTest {
|
|||
assertEquals(response.getStatusCode(), 200);
|
||||
ArgumentCaptor<NamespaceResolutionContext> captor =
|
||||
ArgumentCaptor.forClass(NamespaceResolutionContext.class);
|
||||
verify(namespaceFactory).provision(captor.capture());
|
||||
verify(namespaceProvisioner).provision(captor.capture());
|
||||
NamespaceResolutionContext actualContext = captor.getValue();
|
||||
assertEquals(actualContext.getUserId(), SUBJECT.getUserId());
|
||||
assertEquals(actualContext.getUserName(), SUBJECT.getUserName());
|
||||
|
|
|
|||
Loading…
Reference in New Issue