Add tests for new classes and fix existing tests in openshift-infra module

6.19.x
Sergii Leshchenko 2017-11-16 11:50:36 +02:00
parent d0ef92b038
commit d7e13dec8b
11 changed files with 175 additions and 121 deletions

View File

@ -14,7 +14,6 @@ import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.inOrder;
import org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity;
import org.eclipse.che.api.workspace.server.spi.environment.InternalEnvironment;
import org.eclipse.che.workspace.infrastructure.openshift.environment.OpenShiftEnvironment;
import org.eclipse.che.workspace.infrastructure.openshift.provision.UniqueNamesProvisioner;
import org.eclipse.che.workspace.infrastructure.openshift.provision.env.EnvVarsConverter;
@ -30,16 +29,15 @@ import org.testng.annotations.Listeners;
import org.testng.annotations.Test;
/**
* Tests {@link OpenShiftInfrastructureProvisioner}.
* Tests {@link OpenShiftEnvironmentProvisioner}.
*
* @author Anton Korneta
*/
@Listeners(MockitoTestNGListener.class)
public class OpenShiftInfrastructureProvisionerTest {
public class OpenShiftEnvironmentProvisionerTest {
@Mock private PersistentVolumeClaimProvisioner pvcProvisioner;
@Mock private UniqueNamesProvisioner uniqueNamesProvisioner;
@Mock private InternalEnvironment environment;
@Mock private OpenShiftEnvironment osEnv;
@Mock private RuntimeIdentity runtimeIdentity;
@Mock private TlsRouteProvisioner tlsRouteProvisioner;
@ -47,14 +45,14 @@ public class OpenShiftInfrastructureProvisionerTest {
@Mock private ServersConverter serversProvisioner;
@Mock private RestartPolicyRewriter restartPolicyRewriter;
private OpenShiftInfrastructureProvisioner osInfraProvisioner;
private OpenShiftEnvironmentProvisioner osInfraProvisioner;
private InOrder provisionOrder;
@BeforeMethod
public void setUp() {
osInfraProvisioner =
new OpenShiftInfrastructureProvisioner(
new OpenShiftEnvironmentProvisioner(
pvcProvisioner,
uniqueNamesProvisioner,
tlsRouteProvisioner,
@ -73,26 +71,14 @@ public class OpenShiftInfrastructureProvisionerTest {
@Test
public void performsOrderedProvisioning() throws Exception {
osInfraProvisioner.provision(environment, osEnv, runtimeIdentity);
osInfraProvisioner.provision(osEnv, runtimeIdentity);
provisionOrder
.verify(serversProvisioner)
.provision(eq(environment), eq(osEnv), eq(runtimeIdentity));
provisionOrder
.verify(envVarsProvisioner)
.provision(eq(environment), eq(osEnv), eq(runtimeIdentity));
provisionOrder
.verify(restartPolicyRewriter)
.provision(eq(environment), eq(osEnv), eq(runtimeIdentity));
provisionOrder
.verify(pvcProvisioner)
.provision(eq(environment), eq(osEnv), eq(runtimeIdentity));
provisionOrder
.verify(uniqueNamesProvisioner)
.provision(eq(environment), eq(osEnv), eq(runtimeIdentity));
provisionOrder
.verify(tlsRouteProvisioner)
.provision(eq(environment), eq(osEnv), eq(runtimeIdentity));
provisionOrder.verify(serversProvisioner).provision(eq(osEnv), eq(runtimeIdentity));
provisionOrder.verify(envVarsProvisioner).provision(eq(osEnv), eq(runtimeIdentity));
provisionOrder.verify(restartPolicyRewriter).provision(eq(osEnv), eq(runtimeIdentity));
provisionOrder.verify(pvcProvisioner).provision(eq(osEnv), eq(runtimeIdentity));
provisionOrder.verify(uniqueNamesProvisioner).provision(eq(osEnv), eq(runtimeIdentity));
provisionOrder.verify(tlsRouteProvisioner).provision(eq(osEnv), eq(runtimeIdentity));
provisionOrder.verifyNoMoreInteractions();
}
}

View File

@ -67,16 +67,15 @@ import org.eclipse.che.api.workspace.server.hc.ServersChecker;
import org.eclipse.che.api.workspace.server.hc.ServersCheckerFactory;
import org.eclipse.che.api.workspace.server.model.impl.RuntimeIdentityImpl;
import org.eclipse.che.api.workspace.server.spi.InfrastructureException;
import org.eclipse.che.api.workspace.server.spi.environment.InternalEnvironment;
import org.eclipse.che.api.workspace.server.spi.InternalInfrastructureException;
import org.eclipse.che.api.workspace.shared.dto.event.MachineLogEvent;
import org.eclipse.che.api.workspace.server.spi.environment.InternalMachineConfig;
import org.eclipse.che.api.workspace.shared.dto.event.MachineLogEvent;
import org.eclipse.che.api.workspace.shared.dto.event.MachineStatusEvent;
import org.eclipse.che.dto.server.DtoFactory;
import org.eclipse.che.workspace.infrastructure.openshift.OpenShiftInternalRuntime.MachineLogsPublisher;
import org.eclipse.che.workspace.infrastructure.openshift.bootstrapper.OpenShiftBootstrapper;
import org.eclipse.che.workspace.infrastructure.openshift.bootstrapper.OpenShiftBootstrapperFactory;
import org.eclipse.che.workspace.infrastructure.openshift.environment.OpenShiftInternalEnvironment;
import org.eclipse.che.workspace.infrastructure.openshift.environment.OpenShiftEnvironment;
import org.eclipse.che.workspace.infrastructure.openshift.project.OpenShiftPods;
import org.eclipse.che.workspace.infrastructure.openshift.project.OpenShiftProject;
import org.eclipse.che.workspace.infrastructure.openshift.project.OpenShiftRoutes;
@ -119,13 +118,12 @@ public class OpenShiftInternalRuntimeTest {
@Mock private ServersCheckerFactory serverCheckerFactory;
@Mock private ServersChecker serversChecker;
@Mock private OpenShiftBootstrapperFactory bootstrapperFactory;
@Mock private OpenShiftInternalEnvironment osEnv;
@Mock private OpenShiftEnvironment osEnv;
@Mock private OpenShiftProject project;
@Mock private OpenShiftServices services;
@Mock private OpenShiftRoutes routes;
@Mock private OpenShiftPods pods;
@Mock private OpenShiftBootstrapper bootstrapper;
@Mock private InternalEnvironment environment;
@Captor private ArgumentCaptor<MachineStatusEvent> machineStatusEventCaptor;
@ -146,7 +144,7 @@ public class OpenShiftInternalRuntimeTest {
serverCheckerFactory,
context,
project);
when(context.getOpenShiftEnvironment()).thenReturn(osEnv);
when(context.getEnvironment()).thenReturn(osEnv);
when(serverCheckerFactory.create(any(), anyString(), any())).thenReturn(serversChecker);
when(context.getIdentity()).thenReturn(IDENTITY);
doNothing().when(project).cleanUp();
@ -155,9 +153,14 @@ public class OpenShiftInternalRuntimeTest {
when(project.pods()).thenReturn(pods);
when(bootstrapperFactory.create(any(), anyListOf(Installer.class), any()))
.thenReturn(bootstrapper);
when(context.getEnvironment()).thenReturn(environment);
doReturn(ImmutableMap.of(M1_NAME, mockMachine(), M2_NAME, mockMachine()))
.when(environment)
when(context.getEnvironment()).thenReturn(osEnv);
doReturn(
ImmutableMap.of(
M1_NAME,
mockMachine(mockInstaller("ws-agent")),
M2_NAME,
mockMachine(mockInstaller("terminal"))))
.when(osEnv)
.getMachines();
allServices = ImmutableMap.of(SERVICE_NAME, mockService());
allRoutes = ImmutableMap.of(SERVICE_NAME, mockRoute());
@ -401,6 +404,12 @@ public class OpenShiftInternalRuntimeTest {
return route;
}
private static InstallerImpl mockInstaller(String name) {
InstallerImpl installer = mock(InstallerImpl.class);
when(installer.getName()).thenReturn(name);
return installer;
}
private static InternalMachineConfig mockMachine(InstallerImpl... installers) {
final InternalMachineConfig machine1 = mock(InternalMachineConfig.class);
when(machine1.getInstallers()).thenReturn(Arrays.asList(installers));

View File

@ -52,7 +52,7 @@ public class ServerExposerTest {
private Container container;
@BeforeMethod
public void setUp() {
public void setUp() throws Exception {
container = new ContainerBuilder().withName("main").build();
Pod pod =
new PodBuilder()

View File

@ -11,18 +11,17 @@
package org.eclipse.che.workspace.infrastructure.openshift.environment;
import static java.util.Arrays.asList;
import static java.util.Collections.emptyList;
import static java.util.Collections.emptyMap;
import static java.util.Collections.singletonList;
import static org.eclipse.che.workspace.infrastructure.openshift.environment.OpenShiftEnvironmentFactory.PVC_IGNORED_WARNING_CODE;
import static org.eclipse.che.workspace.infrastructure.openshift.environment.OpenShiftEnvironmentFactory.PVC_IGNORED_WARNING_MESSAGE;
import static org.eclipse.che.workspace.infrastructure.openshift.environment.OpenShiftEnvironmentFactory.ROUTES_IGNORED_WARNING_MESSAGE;
import static org.eclipse.che.workspace.infrastructure.openshift.environment.OpenShiftEnvironmentFactory.ROUTE_IGNORED_WARNING_CODE;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.fail;
import io.fabric8.kubernetes.api.model.DoneableKubernetesList;
import io.fabric8.kubernetes.api.model.HasMetadata;
@ -33,20 +32,15 @@ import io.fabric8.kubernetes.client.dsl.RecreateFromServerGettable;
import io.fabric8.openshift.api.model.Route;
import io.fabric8.openshift.client.OpenShiftClient;
import java.io.InputStream;
import java.util.Iterator;
import java.util.List;
import org.eclipse.che.api.core.model.workspace.Warning;
import org.eclipse.che.api.core.model.workspace.config.Environment;
import org.eclipse.che.api.core.model.workspace.config.Recipe;
import org.eclipse.che.api.installer.server.InstallerRegistry;
import org.eclipse.che.api.workspace.server.model.impl.WarningImpl;
import org.eclipse.che.api.workspace.server.spi.environment.RecipeRetriever;
import org.eclipse.che.api.workspace.server.spi.environment.InternalEnvironment;
import org.eclipse.che.api.workspace.server.spi.environment.InternalRecipe;
import org.eclipse.che.workspace.infrastructure.openshift.OpenShiftClientFactory;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.mockito.testng.MockitoTestNGListener;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Listeners;
import org.testng.annotations.Test;
/**
@ -54,24 +48,20 @@ import org.testng.annotations.Test;
*
* @author Anton Korneta
*/
public class OpenShiftEnvironmentParserTest {
@Listeners(MockitoTestNGListener.class)
public class OpenShiftEnvironmentFactoryTest {
private static final String YAML_RECIPE = "application/x-yaml";
private OpenShiftEnvironmentFactory osEnvironmentParser;
private OpenShiftEnvironmentFactory osEnvironmentFactory;
@Mock private OpenShiftClientFactory factory;
@Mock private OpenShiftEnvironmentValidator osEnvValidator;
@Mock private OpenShiftClient client;
@Mock private Environment environment;
@Mock private Recipe recipe;
@Mock private InternalEnvironment internalEnvironment;
@Mock private InternalRecipe internalRecipe;
@Mock private KubernetesListMixedOperation listMixedOperation;
@Mock private KubernetesList validatedObjects;
@Mock private InstallerRegistry installerRegistry;
@Mock private RecipeRetriever recipeRetriever;
@Captor private ArgumentCaptor<Warning> warningCaptor;
OpenShiftInternalEnvironment parsed;
@Mock
private RecreateFromServerGettable<KubernetesList, KubernetesList, DoneableKubernetesList>
@ -79,16 +69,15 @@ public class OpenShiftEnvironmentParserTest {
@BeforeMethod
public void setup() {
MockitoAnnotations.initMocks(this);
osEnvironmentParser =
new OpenShiftEnvironmentFactory(installerRegistry, recipeRetriever, factory);
osEnvironmentFactory =
new OpenShiftEnvironmentFactory(null, null, null, factory, osEnvValidator);
when(factory.create()).thenReturn(client);
when(client.lists()).thenReturn(listMixedOperation);
when(listMixedOperation.load(any(InputStream.class))).thenReturn(serverGettable);
when(serverGettable.get()).thenReturn(validatedObjects);
when(environment.getRecipe()).thenReturn(recipe);
when(recipe.getContentType()).thenReturn(YAML_RECIPE);
when(recipe.getContent()).thenReturn("recipe content");
when(internalEnvironment.getRecipe()).thenReturn(internalRecipe);
when(internalRecipe.getContentType()).thenReturn(YAML_RECIPE);
when(internalRecipe.getContent()).thenReturn("recipe content");
}
@Test
@ -96,10 +85,14 @@ public class OpenShiftEnvironmentParserTest {
final List<HasMetadata> objects = asList(new Route(), new Route());
when(validatedObjects.getItems()).thenReturn(objects);
parsed = (OpenShiftInternalEnvironment) osEnvironmentParser.create(environment);
final OpenShiftEnvironment parsed =
osEnvironmentFactory.doCreate(internalRecipe, emptyMap(), emptyList());
assertTrue(parsed.getRoutes().isEmpty());
verifyWarnings(new WarningImpl(ROUTE_IGNORED_WARNING_CODE, ROUTES_IGNORED_WARNING_MESSAGE));
assertEquals(parsed.getWarnings().size(), 1);
assertEquals(
parsed.getWarnings().get(0),
new WarningImpl(ROUTE_IGNORED_WARNING_CODE, ROUTES_IGNORED_WARNING_MESSAGE));
}
@Test
@ -107,28 +100,13 @@ public class OpenShiftEnvironmentParserTest {
final List<HasMetadata> pvc = singletonList(new PersistentVolumeClaim());
when(validatedObjects.getItems()).thenReturn(pvc);
parsed = (OpenShiftInternalEnvironment) osEnvironmentParser.create(environment);
final OpenShiftEnvironment parsed =
osEnvironmentFactory.doCreate(internalRecipe, emptyMap(), emptyList());
assertTrue(parsed.getRoutes().isEmpty());
verifyWarnings(new WarningImpl(PVC_IGNORED_WARNING_CODE, PVC_IGNORED_WARNING_MESSAGE));
}
private void verifyWarnings(Warning... expectedWarnings) {
final Iterator<Warning> actualWarnings = captureWarnings().iterator();
for (Warning expected : expectedWarnings) {
if (!actualWarnings.hasNext()) {
fail("It is expected to receive environment warning");
}
final Warning actual = actualWarnings.next();
assertEquals(actual, expected);
}
if (actualWarnings.hasNext()) {
fail("No more warnings expected");
}
}
private List<Warning> captureWarnings() {
verify(parsed, atLeastOnce()).addWarning(warningCaptor.capture());
return warningCaptor.getAllValues();
assertEquals(parsed.getWarnings().size(), 1);
assertEquals(
parsed.getWarnings().get(0),
new WarningImpl(PVC_IGNORED_WARNING_CODE, PVC_IGNORED_WARNING_MESSAGE));
}
}

View File

@ -0,0 +1,92 @@
/*
* Copyright (c) 2012-2017 Red Hat, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
*/
package org.eclipse.che.workspace.infrastructure.openshift.environment;
import static java.util.Collections.emptyMap;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import com.google.common.collect.ImmutableMap;
import io.fabric8.kubernetes.api.model.Container;
import io.fabric8.kubernetes.api.model.ContainerBuilder;
import io.fabric8.kubernetes.api.model.Pod;
import io.fabric8.kubernetes.api.model.PodBuilder;
import java.util.Arrays;
import java.util.stream.Collectors;
import org.eclipse.che.api.core.ValidationException;
import org.eclipse.che.api.workspace.server.spi.environment.InternalMachineConfig;
import org.mockito.Mock;
import org.mockito.testng.MockitoTestNGListener;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Listeners;
import org.testng.annotations.Test;
/**
* Tests {@link OpenShiftEnvironmentValidator}.
*
* @author Sergii Leshchenko
*/
@Listeners(MockitoTestNGListener.class)
public class OpenShiftEnvironmentValidatorTest {
@Mock private OpenShiftEnvironment openShiftEnvironment;
private OpenShiftEnvironmentValidator environmentValidator;
@BeforeMethod
public void setUp() throws Exception {
environmentValidator = new OpenShiftEnvironmentValidator();
}
@Test(
expectedExceptions = ValidationException.class,
expectedExceptionsMessageRegExp = "Environment should contain at least 1 pod"
)
public void shouldThrowExceptionWhenEnvDoesNotHaveAnyPods() throws Exception {
// given
when(openShiftEnvironment.getPods()).thenReturn(emptyMap());
// when
environmentValidator.validate(openShiftEnvironment);
}
@Test(
expectedExceptions = ValidationException.class,
expectedExceptionsMessageRegExp =
"Environment contains machines that are missing in recipe: pod1/db"
)
public void shouldThrowExceptionWhenMachineIsDeclaredButThereIsNotContainerInOpenShiftRecipe()
throws Exception {
// given
Pod pod = createPod("pod1", "main");
when(openShiftEnvironment.getPods()).thenReturn(ImmutableMap.of("pod1", pod));
when(openShiftEnvironment.getMachines())
.thenReturn(ImmutableMap.of("pod1/db", mock(InternalMachineConfig.class)));
// when
environmentValidator.validate(openShiftEnvironment);
}
private Pod createPod(String name, String... containers) {
return new PodBuilder()
.withNewMetadata()
.withName(name)
.endMetadata()
.withNewSpec()
.withContainers(
Arrays.stream(containers).map(this::createContainer).collect(Collectors.toList()))
.endSpec()
.build();
}
private Container createContainer(String name) {
return new ContainerBuilder().withName(name).build();
}
}

View File

@ -38,7 +38,6 @@ import java.util.Map;
import java.util.concurrent.CompletableFuture;
import org.eclipse.che.api.core.model.workspace.config.ServerConfig;
import org.eclipse.che.api.workspace.server.spi.InfrastructureException;
import org.eclipse.che.api.workspace.server.spi.environment.InternalEnvironment;
import org.eclipse.che.api.workspace.server.spi.environment.InternalMachineConfig;
import org.eclipse.che.workspace.infrastructure.openshift.environment.OpenShiftEnvironment;
import org.eclipse.che.workspace.infrastructure.openshift.project.OpenShiftPersistentVolumeClaims;
@ -70,7 +69,6 @@ public class CommonPVCStrategyTest {
@Mock private Pod pod;
@Mock private PodSpec podSpec;
@Mock private Container container;
@Mock private InternalEnvironment env;
@Mock private OpenShiftEnvironment osEnv;
@Mock private PVCSubPathHelper pvcSubPathHelper;
@Mock private OpenShiftProjectFactory factory;
@ -92,7 +90,7 @@ public class CommonPVCStrategyTest {
final InternalMachineConfig machine = mock(InternalMachineConfig.class);
when(machine.getServers())
.thenReturn(singletonMap(SERVER_WS_AGENT_HTTP_REFERENCE, mock(ServerConfig.class)));
when(env.getMachines()).thenReturn(singletonMap(MACHINE_NAME, machine));
when(osEnv.getMachines()).thenReturn(singletonMap(MACHINE_NAME, machine));
doNothing().when(pvcSubPathHelper).execute(any(), any(), any());
when(osEnv.getPersistentVolumeClaims()).thenReturn(new HashMap<>());
when(pvcSubPathHelper.removeDirsAsync(anyString(), any(String.class)))
@ -103,9 +101,9 @@ public class CommonPVCStrategyTest {
@Test(expectedExceptions = InfrastructureException.class)
public void throwsInfrastructureExceptionWhenMachineWithWsAgentNotFound() throws Exception {
when(env.getMachines()).thenReturn(emptyMap());
when(osEnv.getMachines()).thenReturn(emptyMap());
commonPVCStrategy.prepare(env, osEnv, WORKSPACE_ID);
commonPVCStrategy.prepare(osEnv, WORKSPACE_ID);
}
@Test
@ -119,7 +117,7 @@ public class CommonPVCStrategyTest {
when(container.getName()).thenReturn(CONTAINER_NAME);
when(container.getVolumeMounts()).thenReturn(new ArrayList<>());
commonPVCStrategy.prepare(env, osEnv, WORKSPACE_ID);
commonPVCStrategy.prepare(osEnv, WORKSPACE_ID);
verify(container).getVolumeMounts();
verify(podSpec).getVolumes();
@ -137,7 +135,7 @@ public class CommonPVCStrategyTest {
claims.put(PVC_NAME, provisioned);
when(osEnv.getPersistentVolumeClaims()).thenReturn(claims);
commonPVCStrategy.prepare(env, osEnv, WORKSPACE_ID);
commonPVCStrategy.prepare(osEnv, WORKSPACE_ID);
verify(factory).create(WORKSPACE_ID);
assertNotEquals(osEnv.getPersistentVolumeClaims().get(PVC_NAME), provisioned);
@ -147,14 +145,14 @@ public class CommonPVCStrategyTest {
public void throwInfrastructureExceptionWhenOsProjectCreationFailed() throws Exception {
when(factory.create(any())).thenThrow(new InfrastructureException("Project creation failed"));
commonPVCStrategy.prepare(env, osEnv, WORKSPACE_ID);
commonPVCStrategy.prepare(osEnv, WORKSPACE_ID);
}
@Test(expectedExceptions = InfrastructureException.class)
public void throwInfrastructureExceptionWhenPVCCreationFailed() throws Exception {
doThrow(InfrastructureException.class).when(osPVCs).createIfNotExist(any());
commonPVCStrategy.prepare(env, osEnv, WORKSPACE_ID);
commonPVCStrategy.prepare(osEnv, WORKSPACE_ID);
}
@Test
@ -168,7 +166,7 @@ public class CommonPVCStrategyTest {
when(podSpec.getContainers()).thenReturn(singletonList(container));
when(container.getName()).thenReturn("container");
commonPVCStrategy.prepare(env, osEnv, WORKSPACE_ID);
commonPVCStrategy.prepare(osEnv, WORKSPACE_ID);
verify(container, never()).getVolumeMounts();
verify(podSpec, never()).getVolumes();

View File

@ -38,7 +38,6 @@ import java.util.HashMap;
import java.util.Map;
import org.eclipse.che.api.core.model.workspace.config.ServerConfig;
import org.eclipse.che.api.workspace.server.spi.InfrastructureException;
import org.eclipse.che.api.workspace.server.spi.environment.InternalEnvironment;
import org.eclipse.che.api.workspace.server.spi.environment.InternalMachineConfig;
import org.eclipse.che.workspace.infrastructure.openshift.OpenShiftClientFactory;
import org.eclipse.che.workspace.infrastructure.openshift.environment.OpenShiftEnvironment;
@ -70,7 +69,6 @@ public class UniqueWorkspacePVCStrategyTest {
private static final String PVC_ACCESS_MODE = "RWO";
private static final String PROJECT_FOLDER_PATH = "/projects";
@Mock private InternalEnvironment env;
@Mock private OpenShiftEnvironment osEnv;
@Mock private OpenShiftClientFactory clientFactory;
@Mock private OpenShiftClient client;
@ -98,7 +96,7 @@ public class UniqueWorkspacePVCStrategyTest {
final InternalMachineConfig machine = mock(InternalMachineConfig.class);
when(machine.getServers())
.thenReturn(singletonMap(SERVER_WS_AGENT_HTTP_REFERENCE, mock(ServerConfig.class)));
when(env.getMachines()).thenReturn(singletonMap(MACHINE_NAME, machine));
when(osEnv.getMachines()).thenReturn(singletonMap(MACHINE_NAME, machine));
when(factory.create(WORKSPACE_ID)).thenReturn(osProject);
when(osProject.persistentVolumeClaims()).thenReturn(osPVCs);
}
@ -110,7 +108,7 @@ public class UniqueWorkspacePVCStrategyTest {
claims.put(PVC_UNIQUE_NAME, provisioned);
when(osEnv.getPersistentVolumeClaims()).thenReturn(claims);
uniqueWorkspacePVCStrategy.prepare(env, osEnv, WORKSPACE_ID);
uniqueWorkspacePVCStrategy.prepare(osEnv, WORKSPACE_ID);
verify(factory).create(WORKSPACE_ID);
assertNotEquals(osEnv.getPersistentVolumeClaims().get(PVC_UNIQUE_NAME), provisioned);
@ -120,7 +118,7 @@ public class UniqueWorkspacePVCStrategyTest {
public void throwInfrastructureExceptionWhenPVCCreationFailed() throws Exception {
doThrow(InfrastructureException.class).when(osPVCs).createIfNotExist(any());
uniqueWorkspacePVCStrategy.prepare(env, osEnv, WORKSPACE_ID);
uniqueWorkspacePVCStrategy.prepare(osEnv, WORKSPACE_ID);
}
@Test
@ -134,7 +132,7 @@ public class UniqueWorkspacePVCStrategyTest {
when(container.getName()).thenReturn(CONTAINER_NAME);
when(container.getVolumeMounts()).thenReturn(new ArrayList<>());
uniqueWorkspacePVCStrategy.prepare(env, osEnv, WORKSPACE_ID);
uniqueWorkspacePVCStrategy.prepare(osEnv, WORKSPACE_ID);
verify(container).getVolumeMounts();
verify(podSpec).getVolumes();
@ -155,7 +153,7 @@ public class UniqueWorkspacePVCStrategyTest {
when(podSpec.getContainers()).thenReturn(singletonList(container));
when(container.getName()).thenReturn("test");
uniqueWorkspacePVCStrategy.prepare(env, osEnv, WORKSPACE_ID);
uniqueWorkspacePVCStrategy.prepare(osEnv, WORKSPACE_ID);
verify(container, never()).getVolumeMounts();
verify(podSpec, never()).getVolumes();

View File

@ -24,7 +24,6 @@ import io.fabric8.openshift.api.model.Route;
import io.fabric8.openshift.api.model.RouteBuilder;
import java.util.HashMap;
import org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity;
import org.eclipse.che.api.workspace.server.spi.environment.InternalEnvironment;
import org.eclipse.che.workspace.infrastructure.openshift.environment.OpenShiftEnvironment;
import org.mockito.Mock;
import org.mockito.testng.MockitoTestNGListener;
@ -44,7 +43,6 @@ public class UniqueNamesProvisionerTest {
private static final String POD_NAME = "testPod";
private static final String ROUTE_NAME = "testRoute";
@Mock private InternalEnvironment environment;
@Mock private OpenShiftEnvironment osEnv;
@Mock private RuntimeIdentity runtimeIdentity;
@ -63,7 +61,7 @@ public class UniqueNamesProvisionerTest {
pods.put(POD_NAME, pod);
doReturn(pods).when(osEnv).getPods();
uniqueNamesProvisioner.provision(environment, osEnv, runtimeIdentity);
uniqueNamesProvisioner.provision(osEnv, runtimeIdentity);
ObjectMeta podMetadata = pod.getMetadata();
assertNotEquals(podMetadata.getName(), POD_NAME);
@ -77,7 +75,7 @@ public class UniqueNamesProvisionerTest {
routes.put(POD_NAME, route);
doReturn(routes).when(osEnv).getRoutes();
uniqueNamesProvisioner.provision(environment, osEnv, runtimeIdentity);
uniqueNamesProvisioner.provision(osEnv, runtimeIdentity);
final ObjectMeta routeData = route.getMetadata();
assertNotEquals(routeData.getName(), ROUTE_NAME);

View File

@ -31,7 +31,6 @@ import java.util.List;
import org.eclipse.che.api.core.model.workspace.Warning;
import org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity;
import org.eclipse.che.api.workspace.server.model.impl.WarningImpl;
import org.eclipse.che.api.workspace.server.spi.environment.InternalEnvironment;
import org.eclipse.che.workspace.infrastructure.openshift.environment.OpenShiftEnvironment;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
@ -44,10 +43,10 @@ import org.testng.annotations.Test;
/** @author Alexander Garagatyi */
@Listeners(MockitoTestNGListener.class)
public class RestartPolicyRewriterTest {
private static final String TEST_POD_NAME = "app";
private static final String ALWAYS_RESTART_POLICY = "Always";
@Mock private InternalEnvironment environment;
@Mock private OpenShiftEnvironment osEnv;
@Mock private RuntimeIdentity runtimeIdentity;
@InjectMocks private RestartPolicyRewriter restartPolicyRewriter;
@ -59,7 +58,7 @@ public class RestartPolicyRewriterTest {
when(osEnv.getPods())
.thenReturn(singletonMap(TEST_POD_NAME, newPod(TEST_POD_NAME, ALWAYS_RESTART_POLICY)));
restartPolicyRewriter.provision(environment, osEnv, runtimeIdentity);
restartPolicyRewriter.provision(osEnv, runtimeIdentity);
assertEquals(
osEnv.getPods().get(TEST_POD_NAME).getSpec().getRestartPolicy(), DEFAULT_RESTART_POLICY);
@ -93,7 +92,7 @@ public class RestartPolicyRewriterTest {
}
private List<Warning> captureWarnings() {
verify(environment, atLeastOnce()).addWarning(warningCaptor.capture());
verify(osEnv, atLeastOnce()).addWarning(warningCaptor.capture());
return warningCaptor.getAllValues();
}
}

View File

@ -19,7 +19,6 @@ import io.fabric8.openshift.api.model.Route;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity;
import org.eclipse.che.api.workspace.server.spi.environment.InternalEnvironment;
import org.eclipse.che.workspace.infrastructure.openshift.environment.OpenShiftEnvironment;
import org.mockito.Mock;
import org.mockito.testng.MockitoTestNGListener;
@ -34,14 +33,13 @@ import org.testng.annotations.Test;
@Listeners(MockitoTestNGListener.class)
public class TlsRouteProvisionerTest {
@Mock private InternalEnvironment environment;
@Mock private OpenShiftEnvironment osEnv;
@Mock private RuntimeIdentity runtimeIdentity;
@Test
public void doNothingWhenTlsDisabled() throws Exception {
TlsRouteProvisioner tlsProvisioner = new TlsRouteProvisioner(false);
tlsProvisioner.provision(environment, osEnv, runtimeIdentity);
tlsProvisioner.provision(osEnv, runtimeIdentity);
verify(osEnv, never()).getRoutes();
}
@ -50,7 +48,7 @@ public class TlsRouteProvisionerTest {
TlsRouteProvisioner tlsProvisioner = new TlsRouteProvisioner(true);
final Map<String, Route> routes = new HashMap<>();
when(osEnv.getRoutes()).thenReturn(routes);
tlsProvisioner.provision(environment, osEnv, runtimeIdentity);
tlsProvisioner.provision(osEnv, runtimeIdentity);
verify(osEnv, times(1)).getRoutes();
}
}

View File

@ -15,7 +15,6 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity;
import org.eclipse.che.api.workspace.server.spi.environment.InternalEnvironment;
import org.eclipse.che.workspace.infrastructure.openshift.environment.OpenShiftEnvironment;
import org.eclipse.che.workspace.infrastructure.openshift.project.pvc.WorkspacePVCStrategy;
import org.mockito.Mock;
@ -34,7 +33,6 @@ public class PersistentVolumeClaimProvisionerTest {
private static final String WORKSPACE_ID = "workspace132";
@Mock private InternalEnvironment environment;
@Mock private OpenShiftEnvironment osEnv;
@Mock private RuntimeIdentity runtimeIdentity;
@Mock private WorkspacePVCStrategy pvcStrategy;
@ -49,17 +47,17 @@ public class PersistentVolumeClaimProvisionerTest {
@Test
public void doNothingWhenPvcDisabled() throws Exception {
provisioner.provision(environment, osEnv, runtimeIdentity);
provisioner.provision(osEnv, runtimeIdentity);
verify(runtimeIdentity, never()).getWorkspaceId();
verify(environment, never()).getMachines();
verify(osEnv, never()).getMachines();
}
@Test
public void testPrepareWorkspacePVCUsingConfiguredStrategy() throws Exception {
provisioner = new PersistentVolumeClaimProvisioner(true, pvcStrategy);
provisioner.provision(environment, osEnv, runtimeIdentity);
provisioner.provision(osEnv, runtimeIdentity);
verify(pvcStrategy).prepare(environment, osEnv, WORKSPACE_ID);
verify(pvcStrategy).prepare(osEnv, WORKSPACE_ID);
}
}