use of org.eclipse.che.api.workspace.server.model.impl.CommandImpl in project che-server by eclipse-che.
the class OpenShiftPreviewUrlExposerTest method shouldNotProvisionWhenServiceAndRouteFound.
@Test
public void shouldNotProvisionWhenServiceAndRouteFound() throws InternalInfrastructureException {
final int PORT = 8080;
final String SERVER_PORT_NAME = "server-" + PORT;
CommandImpl command = new CommandImpl("a", "a", "a", new PreviewUrlImpl(PORT, null), Collections.emptyMap());
Service service = new Service();
ObjectMeta serviceMeta = new ObjectMeta();
serviceMeta.setName("servicename");
service.setMetadata(serviceMeta);
ServiceSpec serviceSpec = new ServiceSpec();
serviceSpec.setPorts(singletonList(new ServicePort(null, SERVER_PORT_NAME, null, PORT, "TCP", new IntOrString(PORT))));
service.setSpec(serviceSpec);
Route route = new Route();
RouteSpec routeSpec = new RouteSpec();
routeSpec.setPort(new RoutePort(new IntOrString(SERVER_PORT_NAME)));
routeSpec.setTo(new RouteTargetReference("routekind", "servicename", 1));
route.setSpec(routeSpec);
Map<String, Service> services = new HashMap<>();
services.put("servicename", service);
Map<String, Route> routes = new HashMap<>();
routes.put("routename", route);
OpenShiftEnvironment env = OpenShiftEnvironment.builder().setCommands(singletonList(new CommandImpl(command))).setServices(services).setRoutes(routes).build();
assertEquals(env.getRoutes().size(), 1);
previewUrlEndpointsProvisioner.expose(env);
assertEquals(env.getRoutes().size(), 1);
}
use of org.eclipse.che.api.workspace.server.model.impl.CommandImpl in project devspaces-images by redhat-developer.
the class KubernetesInternalRuntimeTest method shouldReturnCommandsAfterRuntimeStart.
@Test
public void shouldReturnCommandsAfterRuntimeStart() throws Exception {
// given
CommandImpl commandToProvision = new CommandImpl("provisioned-command", "build", "env");
doAnswer((Answer<Void>) invocationOnMock -> {
k8sEnv.getCommands().add(commandToProvision);
return null;
}).when(internalEnvironmentProvisioner).provision(any(), any());
internalRuntime.start(emptyMap());
// when
List<? extends Command> commands = internalRuntime.getCommands();
// then
assertEquals(commands.size(), 2);
Optional<? extends Command> envCommandOpt = commands.stream().filter(c -> "envCommand".equals(c.getName())).findAny();
assertTrue(envCommandOpt.isPresent());
Command envCommand = envCommandOpt.get();
assertEquals(envCommand.getCommandLine(), envCommand.getCommandLine());
assertEquals(envCommand.getType(), envCommand.getType());
Optional<? extends Command> provisionedCommandOpt = commands.stream().filter(c -> "provisioned-command".equals(c.getName())).findAny();
assertTrue(provisionedCommandOpt.isPresent());
Command provisionedCommand = provisionedCommandOpt.get();
assertEquals(provisionedCommand.getCommandLine(), provisionedCommand.getCommandLine());
assertEquals(provisionedCommand.getType(), provisionedCommand.getType());
}
use of org.eclipse.che.api.workspace.server.model.impl.CommandImpl in project devspaces-images by redhat-developer.
the class KubernetesRuntimeStateCacheTest method shouldThrowExceptionUpdateCommands.
@Test(expectedExceptions = InfrastructureException.class, expectedExceptionsMessageRegExp = "Runtime state for workspace with id 'non-existent-ws' was not found")
public void shouldThrowExceptionUpdateCommands() throws Exception {
// given
CommandImpl newCommand = new CommandImpl("new", "build", "custom");
// when
runtimesStatesCache.updateCommands(new RuntimeIdentityImpl("non-existent-ws", "defEnv", "acc1", "infraNamespace"), singletonList(newCommand));
}
use of org.eclipse.che.api.workspace.server.model.impl.CommandImpl in project devspaces-images by redhat-developer.
the class KubernetesRuntimeStateCacheTest method shouldUpdateCommandsAndDeleteRuntime.
// Ensure that we are not affected https://bugs.eclipse.org/bugs/show_bug.cgi?id=474203 Orphan
// Removal not working
// when, object is added to collection and then same object is removed from collection in same
// transaction.
//
// Probable reason - two different transactions was used.
@Test(dependsOnMethods = "shouldReturnCommands")
public void shouldUpdateCommandsAndDeleteRuntime() {
// given
List<CommandImpl> newCommands = new ArrayList<>();
CommandImpl newCommand = new CommandImpl("new", "build", "custom");
newCommands.add(newCommand);
// when
try {
runtimesStatesCache.updateCommands(runtimesStates[0].getRuntimeId(), newCommands);
runtimesStatesCache.remove(runtimesStates[0].getRuntimeId());
} catch (InfrastructureException e) {
fail("No exception expected here, got " + e.getLocalizedMessage());
}
// then
// if no exception happened during remove operation that means test passed correctly.
}
use of org.eclipse.che.api.workspace.server.model.impl.CommandImpl in project devspaces-images by redhat-developer.
the class KubernetesRuntimeStateCacheTest method shouldUpdateCommands.
@Test(dependsOnMethods = "shouldReturnCommands")
public void shouldUpdateCommands() throws Exception {
// given
List<CommandImpl> newCommands = new ArrayList<>();
CommandImpl newCommand = new CommandImpl("new", "build", "custom");
newCommands.add(newCommand);
// when
runtimesStatesCache.updateCommands(runtimesStates[0].getRuntimeId(), newCommands);
// then
List<? extends Command> updatedCommands = runtimesStatesCache.getCommands(runtimesStates[0].getRuntimeId());
assertEquals(updatedCommands.size(), 1);
assertEquals(new CommandImpl(updatedCommands.get(0)), newCommand);
}
Aggregations