WorkspaceLinksGenerator { public Map<String, String> genLinks(WorkspaceImpl workspace, ServiceContext serviceContext) throws ServerException { final UriBuilder uriBuilder = serviceContext.getServiceUriBuilder(); final LinkedHashMap<String, String> links = new LinkedHashMap<>(); links.put( LINK_REL_SELF, uriBuilder .clone() .path(WorkspaceService.class, "getByKey") .build(workspace.getId()) .toString()); links.put( LINK_REL_IDE_URL, uriBuilder .clone() .replacePath("") .path(workspace.getNamespace()) .path(workspace.getName()) .build() .toString()); if (workspace.getStatus() != WorkspaceStatus.STOPPED) { addRuntimeLinks(links, workspace.getId(), serviceContext); } links.putAll( previewUrlLinksVariableGenerator.genLinksMapAndUpdateCommands( workspace, uriBuilder.clone())); return links; } @Inject  WorkspaceLinksGenerator(
      WorkspaceRuntimes workspaceRuntimes,
      PreviewUrlLinksVariableGenerator previewUrlLinksVariableGenerator,
      @Named("che.websocket.endpoint") String cheWebsocketEndpoint); Map<String, String> genLinks(WorkspaceImpl workspace, ServiceContext serviceContext);  }
@Test public void genOfRunningWorkspaceLinks() throws Exception { when(workspace.getStatus()).thenReturn(WorkspaceStatus.RUNNING); assertEquals(linksGenerator.genLinks(workspace, serviceContextMock), expectedRunningLinks); }
@Test public void genOfStoppedWorkspaceLinks() throws Exception { when(workspace.getStatus()).thenReturn(WorkspaceStatus.STOPPED); assertEquals(linksGenerator.genLinks(workspace, serviceContextMock), expectedStoppedLinks); }
@Test public void genOfDifferentUrl() throws Exception { UriBuilder uriBuilder = new UriBuilderImpl(); uriBuilder.uri("https: doReturn(uriBuilder).when(serviceContextMock).getServiceUriBuilder(); linksGenerator = new WorkspaceLinksGenerator(runtimes, previewUrlGenerator, "ws: Map<String, String> actual = linksGenerator.genLinks(workspace, serviceContextMock); expectedRunningLinks = ImmutableMap.of( LINK_REL_SELF, "https: LINK_REL_IDE_URL, "https: LINK_REL_ENVIRONMENT_STATUS_CHANNEL, "wss: LINK_REL_ENVIRONMENT_OUTPUT_CHANNEL, "ws: assertEquals(actual, expectedRunningLinks); }