@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)); }
@Test public void shouldShowStopProcessButtonAtAddingTerminal() throws Exception { MachineDto machineDto = mock(MachineDto.class); MachineConfigDto machineConfigDto = mock(MachineConfigDto.class); when(machineDto.getConfig()).thenReturn(machineConfigDto); when(machineConfigDto.isDev()).thenReturn(true); when(machineDto.getStatus()).thenReturn(MachineStatus.RUNNING); ProcessTreeNode machineNode = mock(ProcessTreeNode.class); when(machineNode.getId()).thenReturn(MACHINE_ID); List<ProcessTreeNode> children = new ArrayList<>(); children.add(machineNode); presenter.rootNode = new ProcessTreeNode(ROOT_NODE, null, null, null, children); Machine machine = mock(Machine.class); when(entityFactory.createMachine(anyObject())).thenReturn(machine); TerminalPresenter terminal = mock(TerminalPresenter.class); when(terminalFactory.create(machine)).thenReturn(terminal); IsWidget terminalWidget = mock(IsWidget.class); when(terminal.getView()).thenReturn(terminalWidget); presenter.addCommandOutput(MACHINE_ID, outputConsole); presenter.onAddTerminal(MACHINE_ID); verify(machinePromise).then(machineCaptor.capture()); machineCaptor.getValue().apply(machineDto); verify(entityFactory).createMachine(anyObject()); verify(terminalFactory).create(eq(machine)); verify(terminal).getView(); verify(view, times(2)).setProcessesData(anyObject()); verify(view, times(2)).selectNode(anyObject()); verify(view).addProcessWidget(anyString(), eq(terminalWidget)); verify(view, times(2)).addProcessNode(anyObject()); verify(terminal).setVisible(eq(true)); verify(terminal).connect(); verify(terminal).setListener(anyObject()); verify(view).setProcessRunning(anyString(), eq(true)); }
@Test public void shouldFetchMachines() throws Exception { MachineDto machineDto = mock(MachineDto.class); MachineConfigDto machineConfigDto = mock(MachineConfigDto.class); when(machineDto.getConfig()).thenReturn(machineConfigDto); when(machineConfigDto.isDev()).thenReturn(true); when(machineDto.getStatus()).thenReturn(MachineStatus.RUNNING); List<MachineDto> machines = new ArrayList<>(2); machines.add(machineDto); when(appContext.getWorkspace()).thenReturn(workspace); DevMachineStateEvent devMachineStateEvent = mock(DevMachineStateEvent.class); verify(eventBus, times(4)).addHandler(anyObject(), devMachineStateHandlerCaptor.capture()); DevMachineStateHandler devMachineStateHandler = devMachineStateHandlerCaptor.getAllValues().get(0); devMachineStateHandler.onMachineStarted(devMachineStateEvent); verify(appContext, times(2)).getWorkspaceId(); verify(machineService, times(2)).getMachines(eq(WORKSPACE_ID)); verify(machinesPromise, times(2)).then(machinesCaptor.capture()); machinesCaptor.getValue().apply(machines); verify(view).setProcessesData(anyObject()); }