コード例 #1
0
  @Before
  public void setUp() {
    when(entityFactory.createMachine(machineDescriptor1)).thenReturn(machine1);
    when(entityFactory.createMachine(machineDescriptor2)).thenReturn(machine2);

    when(entityFactory.createMachineNode(
            isNull(MachineTreeNode.class),
            anyString(),
            Matchers.<List<MachineTreeNode>>anyObject()))
        .thenReturn(rootNode);

    //noinspection unchecked
    when(entityFactory.createMachineNode(eq(rootNode), eq(machineState2), isNull(List.class)))
        .thenReturn(machineNode2);
    //noinspection unchecked
    when(entityFactory.createMachineNode(eq(rootNode), eq(machineState1), isNull(List.class)))
        .thenReturn(machineNode1);

    presenter =
        new MachinePanelPresenter(
            view, service, entityFactory, locale, appliance, eventBus, resources, appContext);

    when(service.getMachinesStates(anyString())).thenReturn(machineStatePromise);
    when(machineStatePromise.then(Matchers.<Operation<List<MachineStateDto>>>anyObject()))
        .thenReturn(machineStatePromise);

    when(service.getMachine(anyString())).thenReturn(machinePromise);
    when(machinePromise.then(Matchers.<Operation<MachineDto>>anyObject()))
        .thenReturn(machinePromise);

    when(appContext.getWorkspace()).thenReturn(usersWorkspaceDto);
    when(usersWorkspaceDto.getId()).thenReturn(TEXT);
  }
コード例 #2
0
  @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));
  }