@Override public void onPreviewSsh(@NotNull final String machineId) { ProcessTreeNode machineTreeNode = findProcessTreeNodeById(machineId); if (machineTreeNode == null) { return; } MachineDto machine = (MachineDto) machineTreeNode.getData(); OutputConsole defaultConsole = commandConsoleFactory.create("SSH"); addCommandOutput(machineId, defaultConsole); String machineName = machine.getConfig().getName(); String sshServiceAddress = getSshServerAddress(machine); String machineHost = ""; String sshPort = SSH_PORT; if (sshServiceAddress != null) { String[] parts = sshServiceAddress.split(":"); machineHost = parts[0]; sshPort = (parts.length == 2) ? parts[1] : sshPort; } if (defaultConsole instanceof DefaultOutputConsole) { ((DefaultOutputConsole) defaultConsole) .printText(localizationConstant.sshConnectInfo(machineName, machineHost, sshPort)); } }
@Test public void shouldRestoreState() throws Exception { CommandType commandType = mock(CommandType.class); CommandConfiguration commandConfiguration = mock(CommandConfiguration.class); CommandConfigurationFactory commandConfigurationFactory = mock(CommandConfigurationFactory.class); CommandOutputConsole outputConsole = mock(CommandOutputConsole.class); when(commandTypeRegistry.getCommandTypeById(anyString())).thenReturn(commandType); when(commandType.getConfigurationFactory()).thenReturn(commandConfigurationFactory); when(commandConfigurationFactory.createFromDto(anyObject())).thenReturn(commandConfiguration); when(commandConsoleFactory.create(anyObject(), anyString())).thenReturn(outputConsole); CommandDto commandDto = mock(CommandDto.class); when(dtoFactory.createDto(anyObject())).thenReturn(commandDto); when(commandDto.withName(anyString())).thenReturn(commandDto); when(commandDto.withCommandLine(anyString())).thenReturn(commandDto); when(commandDto.withType(anyString())).thenReturn(commandDto); MachineProcessDto machineProcessDto = mock(MachineProcessDto.class); when(machineProcessDto.getOutputChannel()).thenReturn(OUTPUT_CHANNEL); when(machineProcessDto.getPid()).thenReturn(PID); List<MachineProcessDto> processes = new ArrayList<>(1); processes.add(machineProcessDto); MachineDto machineDto = mock(MachineDto.class); MachineConfigDto machineConfigDto = mock(MachineConfigDto.class); when(machineDto.getConfig()).thenReturn(machineConfigDto); when(machineConfigDto.isDev()).thenReturn(true); when(machineDto.getId()).thenReturn(MACHINE_ID); when(machineDto.getStatus()).thenReturn(MachineStatus.RUNNING); List<MachineDto> machines = new ArrayList<>(2); machines.add(machineDto); verify(machinesPromise).then(machinesCaptor.capture()); machinesCaptor.getValue().apply(machines); verify(processesPromise).then(processesCaptor.capture()); processesCaptor.getValue().apply(processes); verify(outputConsole).listenToOutput(eq(OUTPUT_CHANNEL)); verify(outputConsole).attachToProcess(machineProcessDto); verify(workspaceAgent).setActivePart(eq(presenter)); }