use of org.eclipse.che.api.workspace.server.model.impl.devfile.PreviewUrlImpl in project devspaces-images by redhat-developer.
the class OpenShiftPreviewUrlCommandProvisionerTest method shouldUpdateCommandWhenServiceAndIngressFound.
@Test
public void shouldUpdateCommandWhenServiceAndIngressFound() throws InfrastructureException {
int port = 8080;
List<CommandImpl> commands = Collections.singletonList(new CommandImpl("a", "a", "a", new PreviewUrlImpl(port, null), Collections.emptyMap()));
OpenShiftEnvironment env = OpenShiftEnvironment.builder().setCommands(new ArrayList<>(commands)).build();
Mockito.when(mockProject.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, "8080", null, port, "TCP", new IntOrString(port))));
service.setSpec(spec);
Mockito.when(mockServices.get()).thenReturn(Collections.singletonList(service));
Route route = new Route();
RouteSpec routeSpec = new RouteSpec();
routeSpec.setPort(new RoutePort(new IntOrString("8080")));
routeSpec.setTo(new RouteTargetReference("a", "servicename", 1));
routeSpec.setHost("testhost");
route.setSpec(routeSpec);
Mockito.when(mockProject.routes()).thenReturn(mockRoutes);
Mockito.when(mockRoutes.get()).thenReturn(Collections.singletonList(route));
previewUrlCommandProvisioner.provision(env, mockProject);
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 OpenShiftPreviewUrlCommandProvisionerTest method shouldDoNothingWhenCantFindRouteForPreviewUrl.
@Test
public void shouldDoNothingWhenCantFindRouteForPreviewUrl() throws InfrastructureException {
int port = 8080;
List<CommandImpl> commands = Collections.singletonList(new CommandImpl("a", "a", "a", new PreviewUrlImpl(port, null), Collections.emptyMap()));
OpenShiftEnvironment env = OpenShiftEnvironment.builder().setCommands(new ArrayList<>(commands)).build();
Mockito.when(mockProject.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(mockProject.routes()).thenReturn(mockRoutes);
Mockito.when(mockRoutes.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);
}
use of org.eclipse.che.api.workspace.server.model.impl.devfile.PreviewUrlImpl in project devspaces-images by redhat-developer.
the class PreviewUrlLinksVariableGeneratorTest method shouldAppendPathWithQueryParamsWhenDefinedInPreviewUrl.
@Test
public void shouldAppendPathWithQueryParamsWhenDefinedInPreviewUrl() {
Map<String, String> commandAttrs = new HashMap<>();
commandAttrs.put(Command.PREVIEW_URL_ATTRIBUTE, "preview_url_host");
CommandImpl command = new CommandImpl("run command", "a", "a", new PreviewUrlImpl(123, "/hello?a=b"), commandAttrs);
WorkspaceImpl workspace = createWorkspaceWithCommands(singletonList(command));
Map<String, String> linkMap = generator.genLinksMapAndUpdateCommands(workspace, uriBuilder);
assertTrue(linkMap.values().iterator().next().endsWith("preview_url_host"));
String linkKey = linkMap.keySet().iterator().next();
assertEquals(workspace.getRuntime().getCommands().get(0).getAttributes().get(Command.PREVIEW_URL_ATTRIBUTE), "${" + linkKey + "}/hello?a=b");
}
use of org.eclipse.che.api.workspace.server.model.impl.devfile.PreviewUrlImpl in project devspaces-images by redhat-developer.
the class PreviewUrlLinksVariableGeneratorTest method shouldDoNothingWhenNoCommandWithPreviewurlAttribute.
@Test
public void shouldDoNothingWhenNoCommandWithPreviewurlAttribute() {
CommandImpl command = new CommandImpl("a", "a", "a", new PreviewUrlImpl(123, null), Collections.emptyMap());
WorkspaceImpl w = createWorkspaceWithCommands(singletonList(command));
assertTrue(generator.genLinksMapAndUpdateCommands(w, uriBuilder).isEmpty());
}
use of org.eclipse.che.api.workspace.server.model.impl.devfile.PreviewUrlImpl in project devspaces-images by redhat-developer.
the class PreviewUrlLinksVariableGeneratorTest method shouldAppendQueryParamsWhenDefinedInPreviewUrl.
@Test
public void shouldAppendQueryParamsWhenDefinedInPreviewUrl() {
Map<String, String> commandAttrs = new HashMap<>();
commandAttrs.put(Command.PREVIEW_URL_ATTRIBUTE, "preview_url_host");
CommandImpl command = new CommandImpl("run command", "a", "a", new PreviewUrlImpl(123, "?a=b"), commandAttrs);
WorkspaceImpl workspace = createWorkspaceWithCommands(singletonList(command));
Map<String, String> linkMap = generator.genLinksMapAndUpdateCommands(workspace, uriBuilder);
assertTrue(linkMap.values().iterator().next().endsWith("preview_url_host"));
String linkKey = linkMap.keySet().iterator().next();
assertEquals(workspace.getRuntime().getCommands().get(0).getAttributes().get(Command.PREVIEW_URL_ATTRIBUTE), "${" + linkKey + "}?a=b");
}
Aggregations