use of org.eclipse.che.api.workspace.server.model.impl.devfile.PreviewUrlImpl in project devspaces-images by redhat-developer.
the class PreviewUrlExposerTest method shouldProvisionIngressWhenNotFound.
@Test
public void shouldProvisionIngressWhenNotFound() throws InternalInfrastructureException {
Mockito.when(externalServiceExposureStrategy.getExternalPath(Mockito.anyString(), Mockito.any())).thenReturn("some-server-path");
final int PORT = 8080;
final String SERVER_PORT_NAME = "server-" + PORT;
final String SERVICE_NAME = "servicename";
CommandImpl command = new CommandImpl("a", "a", "a", new PreviewUrlImpl(PORT, null), Collections.emptyMap());
Service service = new Service();
ObjectMeta serviceMeta = new ObjectMeta();
serviceMeta.setName(SERVICE_NAME);
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);
Map<String, Service> services = new HashMap<>();
services.put(SERVICE_NAME, service);
KubernetesEnvironment env = KubernetesEnvironment.builder().setCommands(singletonList(new CommandImpl(command))).setServices(services).setIngresses(new HashMap<>()).build();
previewUrlExposer.expose(env);
assertEquals(env.getIngresses().size(), 1);
Ingress provisionedIngress = env.getIngresses().values().iterator().next();
IngressBackend provisionedIngressBackend = provisionedIngress.getSpec().getRules().get(0).getHttp().getPaths().get(0).getBackend();
assertEquals(provisionedIngressBackend.getService().getPort().getName(), SERVER_PORT_NAME);
assertEquals(provisionedIngressBackend.getService().getName(), SERVICE_NAME);
}
use of org.eclipse.che.api.workspace.server.model.impl.devfile.PreviewUrlImpl in project devspaces-images by redhat-developer.
the class PreviewUrlExposerTest method shouldProvisionServiceAndIngressWhenNotFound.
@Test
public void shouldProvisionServiceAndIngressWhenNotFound() throws InternalInfrastructureException {
Mockito.when(externalServiceExposureStrategy.getExternalPath(Mockito.anyString(), Mockito.any())).thenReturn("some-server-path");
final int PORT = 8080;
final String SERVER_PORT_NAME = "server-" + PORT;
CommandImpl command = new CommandImpl("a", "a", "a", new PreviewUrlImpl(PORT, null), Collections.emptyMap());
KubernetesEnvironment env = KubernetesEnvironment.builder().setCommands(singletonList(new CommandImpl(command))).setIngresses(new HashMap<>()).setServices(new HashMap<>()).build();
previewUrlExposer.expose(env);
assertEquals(env.getIngresses().size(), 1);
assertEquals(env.getServices().size(), 1);
Service provisionedService = env.getServices().values().iterator().next();
ServicePort provisionedServicePort = provisionedService.getSpec().getPorts().get(0);
assertEquals(provisionedServicePort.getName(), SERVER_PORT_NAME);
assertEquals(provisionedServicePort.getPort().intValue(), PORT);
Ingress provisionedIngress = env.getIngresses().values().iterator().next();
IngressBackend provisionedIngressBackend = provisionedIngress.getSpec().getRules().get(0).getHttp().getPaths().get(0).getBackend();
assertEquals(provisionedIngressBackend.getService().getPort().getName(), SERVER_PORT_NAME);
assertEquals(provisionedIngressBackend.getService().getName(), provisionedService.getMetadata().getName());
}
use of org.eclipse.che.api.workspace.server.model.impl.devfile.PreviewUrlImpl in project devspaces-images by redhat-developer.
the class OpenShiftPreviewUrlExposerTest method shouldProvisionRouteWhenNotFound.
@Test
public void shouldProvisionRouteWhenNotFound() throws InternalInfrastructureException {
final int PORT = 8080;
final String SERVER_PORT_NAME = "server-" + PORT;
final String SERVICE_NAME = "servicename";
CommandImpl command = new CommandImpl("a", "a", "a", new PreviewUrlImpl(PORT, null), Collections.emptyMap());
Service service = new Service();
ObjectMeta serviceMeta = new ObjectMeta();
serviceMeta.setName(SERVICE_NAME);
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);
Map<String, Service> services = new HashMap<>();
services.put(SERVICE_NAME, service);
OpenShiftEnvironment env = OpenShiftEnvironment.builder().setCommands(singletonList(new CommandImpl(command))).setServices(services).setRoutes(new HashMap<>()).build();
previewUrlEndpointsProvisioner.expose(env);
assertEquals(env.getRoutes().size(), 1);
Route provisionedRoute = env.getRoutes().values().iterator().next();
assertEquals(provisionedRoute.getSpec().getTo().getName(), SERVICE_NAME);
assertEquals(provisionedRoute.getSpec().getPort().getTargetPort().getStrVal(), SERVER_PORT_NAME);
}
use of org.eclipse.che.api.workspace.server.model.impl.devfile.PreviewUrlImpl in project devspaces-images by redhat-developer.
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.devfile.PreviewUrlImpl in project devspaces-images by redhat-developer.
the class OpenShiftPreviewUrlExposerTest method shouldProvisionServiceAndRouteWhenNotFound.
@Test
public void shouldProvisionServiceAndRouteWhenNotFound() 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());
OpenShiftEnvironment env = OpenShiftEnvironment.builder().setCommands(singletonList(new CommandImpl(command))).setRoutes(new HashMap<>()).setServices(new HashMap<>()).build();
previewUrlEndpointsProvisioner.expose(env);
assertEquals(env.getRoutes().size(), 1);
assertEquals(env.getServices().size(), 1);
Service provisionedService = env.getServices().values().iterator().next();
ServicePort provisionedServicePort = provisionedService.getSpec().getPorts().get(0);
assertEquals(provisionedServicePort.getName(), SERVER_PORT_NAME);
assertEquals(provisionedServicePort.getPort().intValue(), PORT);
Route provisionedRoute = env.getRoutes().values().iterator().next();
assertEquals(provisionedRoute.getSpec().getTo().getName(), provisionedService.getMetadata().getName());
assertEquals(provisionedRoute.getSpec().getPort().getTargetPort().getStrVal(), SERVER_PORT_NAME);
}
Aggregations