use of org.eclipse.che.api.workspace.server.model.impl.devfile.PreviewUrlImpl 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.devfile.PreviewUrlImpl in project devspaces-images by redhat-developer.
the class KubernetesPreviewUrlCommandProvisionerTest method shouldDoNothingWhenCantFindIngressForPreviewUrl.
@Test
public void shouldDoNothingWhenCantFindIngressForPreviewUrl() throws InfrastructureException {
int port = 8080;
List<CommandImpl> commands = Collections.singletonList(new CommandImpl("a", "a", "a", new PreviewUrlImpl(port, null), Collections.emptyMap()));
KubernetesEnvironment env = KubernetesEnvironment.builder().setCommands(new ArrayList<>(commands)).build();
Mockito.when(mockNamespace.services()).thenReturn(mockServices);
Service service = new Service();
ServiceSpec spec = new ServiceSpec();
spec.setPorts(Collections.singletonList(new ServicePort(null, "a", null, port, "TCP", new IntOrString(port))));
service.setSpec(spec);
Mockito.when(mockServices.get()).thenReturn(Collections.singletonList(service));
Mockito.when(mockNamespace.ingresses()).thenReturn(mockIngresses);
Mockito.when(mockIngresses.get()).thenReturn(Collections.emptyList());
previewUrlCommandProvisioner.provision(env, mockNamespace);
assertTrue(commands.containsAll(env.getCommands()));
assertTrue(env.getCommands().containsAll(commands));
assertEquals(env.getWarnings().get(0).getCode(), Warnings.NOT_ABLE_TO_PROVISION_OBJECTS_FOR_PREVIEW_URL);
}
use of org.eclipse.che.api.workspace.server.model.impl.devfile.PreviewUrlImpl in project devspaces-images by redhat-developer.
the class KubernetesPreviewUrlCommandProvisionerTest method shouldUpdateCommandWhenServiceAndIngressFound.
@Test
public void shouldUpdateCommandWhenServiceAndIngressFound() throws InfrastructureException {
final int PORT = 8080;
final String SERVICE_PORT_NAME = "service-" + PORT;
List<CommandImpl> commands = Collections.singletonList(new CommandImpl("a", "a", "a", new PreviewUrlImpl(PORT, null), Collections.emptyMap()));
KubernetesEnvironment env = KubernetesEnvironment.builder().setCommands(new ArrayList<>(commands)).build();
Mockito.when(mockNamespace.services()).thenReturn(mockServices);
Service service = new Service();
ObjectMeta metadata = new ObjectMeta();
metadata.setName("servicename");
service.setMetadata(metadata);
ServiceSpec spec = new ServiceSpec();
spec.setPorts(Collections.singletonList(new ServicePort(null, SERVICE_PORT_NAME, null, PORT, "TCP", new IntOrString(PORT))));
service.setSpec(spec);
Mockito.when(mockServices.get()).thenReturn(Collections.singletonList(service));
Ingress ingress = new Ingress();
IngressSpec ingressSpec = new IngressSpec();
IngressRule rule = new IngressRule("testhost", new HTTPIngressRuleValue(Collections.singletonList(new HTTPIngressPath(new IngressBackend(null, new IngressServiceBackend("servicename", new ServiceBackendPort(SERVICE_PORT_NAME, PORT))), null, null))));
ingressSpec.setRules(Collections.singletonList(rule));
ingress.setSpec(ingressSpec);
Mockito.when(mockNamespace.ingresses()).thenReturn(mockIngresses);
Mockito.when(mockIngresses.get()).thenReturn(Collections.singletonList(ingress));
previewUrlCommandProvisioner.provision(env, mockNamespace);
assertTrue(env.getCommands().get(0).getAttributes().containsKey("previewUrl"));
assertEquals(env.getCommands().get(0).getAttributes().get("previewUrl"), "testhost");
assertTrue(env.getWarnings().isEmpty());
}
use of org.eclipse.che.api.workspace.server.model.impl.devfile.PreviewUrlImpl in project devspaces-images by redhat-developer.
the class KubernetesPreviewUrlCommandProvisionerTest method shouldDoNothingWhenCantFindServiceForPreviewurl.
@Test
public void shouldDoNothingWhenCantFindServiceForPreviewurl() throws InfrastructureException {
List<CommandImpl> commands = Collections.singletonList(new CommandImpl("a", "a", "a", new PreviewUrlImpl(8080, null), Collections.emptyMap()));
KubernetesEnvironment env = KubernetesEnvironment.builder().setCommands(new ArrayList<>(commands)).build();
Mockito.when(mockNamespace.ingresses()).thenReturn(mockIngresses);
Mockito.when(mockNamespace.services()).thenReturn(mockServices);
Mockito.when(mockServices.get()).thenReturn(Collections.emptyList());
previewUrlCommandProvisioner.provision(env, mockNamespace);
assertTrue(commands.containsAll(env.getCommands()));
assertTrue(env.getCommands().containsAll(commands));
assertEquals(env.getWarnings().get(0).getCode(), Warnings.NOT_ABLE_TO_PROVISION_OBJECTS_FOR_PREVIEW_URL);
}
use of org.eclipse.che.api.workspace.server.model.impl.devfile.PreviewUrlImpl in project devspaces-images by redhat-developer.
the class OpenShiftPreviewUrlCommandProvisionerTest method shouldDoNothingWhenCantFindServiceForPreviewurl.
@Test
public void shouldDoNothingWhenCantFindServiceForPreviewurl() throws InfrastructureException {
List<CommandImpl> commands = Collections.singletonList(new CommandImpl("a", "a", "a", new PreviewUrlImpl(8080, null), Collections.emptyMap()));
OpenShiftEnvironment env = OpenShiftEnvironment.builder().setCommands(new ArrayList<>(commands)).build();
Mockito.when(mockProject.routes()).thenReturn(mockRoutes);
Mockito.when(mockProject.services()).thenReturn(mockServices);
Mockito.when(mockServices.get()).thenReturn(Collections.emptyList());
previewUrlCommandProvisioner.provision(env, mockProject);
assertTrue(commands.containsAll(env.getCommands()));
assertTrue(env.getCommands().containsAll(commands));
assertEquals(env.getWarnings().get(0).getCode(), Warnings.NOT_ABLE_TO_PROVISION_OBJECTS_FOR_PREVIEW_URL);
}
Aggregations