RunnerManagerPresenter extends BasePresenter implements RunnerManager,
                                                                     RunnerManagerView.ActionDelegate,
                                                                     ProjectActionHandler,
                                                                     SelectionManager.SelectionChangeListener { @NotNull public Runner addRunner(@NotNull ApplicationProcessDescriptor processDescriptor) { RunOptions runOptions = dtoFactory.createDto(RunOptions.class); Runner runner = modelsFactory.createRunner(runOptions); String environmentId = processDescriptor.getEnvironmentId(); if (environmentId != null && environmentId.startsWith(PROJECT_PREFIX)) { runner.setScope(PROJECT); } runnersId.add(processDescriptor.getProcessId()); runner.setProcessDescriptor(processDescriptor); runner.setRAM(processDescriptor.getMemorySize()); runner.setStatus(Runner.Status.DONE); runner.resetCreationTime(); history.addRunner(runner); onSelectionChanged(RUNNER); runnerTimer.schedule(ONE_SEC.getValue()); LaunchAction launchAction = actionFactory.createLaunch(); runnerActions.put(runner, launchAction); launchAction.perform(runner); selectHistoryTab(); return runner; } @Inject  RunnerManagerPresenter(final RunnerManagerView view,
                                  RunnerActionFactory actionFactory,
                                  ModelsFactory modelsFactory,
                                  AppContext appContext,
                                  DtoFactory dtoFactory,
                                  ChooseRunnerAction chooseRunnerAction,
                                  EventBus eventBus,
                                  final RunnerLocalizationConstant locale,
                                  @LeftPanel TabContainer leftTabContainer,
                                  @LeftPropertiesPanel TabContainer leftPropertiesContainer,
                                  @RightPropertiesPanel TabContainer rightPropertiesContainer,
                                  PanelState panelState,
                                  Provider<TabBuilder> tabBuilderProvider,
                                  final ConsoleContainer consoleContainer,
                                  TerminalContainer terminalContainer,
                                  PropertiesContainer propertiesContainer,
                                  HistoryPanel history,
                                  TemplatesContainer templateContainer,
                                  RunnerCounter runnerCounter,
                                  SelectionManager selectionManager,
                                  TimerFactory timerFactory,
                                  GetSystemEnvironmentsAction getSystemEnvironmentsAction,
                                  RunnerUtil runnerUtil,
                                  @Run ResourcesLockedActionPermit runActionPermit,
                                  @Run ActionDenyAccessDialog runActionDenyAccessDialog); @NotNull RunnerManagerView getView(); void update(@NotNull Runner runner); @Override void onRunButtonClicked(); @Override void onRerunButtonClicked(); @Override void onStopButtonClicked(); @Override void onLogsButtonClicked(); @Override void stopRunner(@NotNull Runner runner); @Override void onMoreInfoBtnMouseOver(); @Override void onToggleSplitterClicked(boolean isShowSplitter); @Override Runner launchRunner(); @NotNull @Override Runner launchRunner(@NotNull RunOptions runOptions); @Override @NotNull Runner launchRunner(@NotNull RunOptions runOptions, @NotNull Scope scope, @NotNull String environmentName); @Override void go(@NotNull AcceptsOneWidget container); void setActive(); @NotNull @Override String getTitle(); @Nullable @Override ImageResource getTitleImage(); @Nullable @Override String getTitleToolTip(); @Override void onProjectReady(@NotNull ProjectActionEvent projectActionEvent); @Override void onProjectClosing(ProjectActionEvent event); @Override void onProjectClosed(@NotNull ProjectActionEvent projectActionEvent); @Override void onProjectOpened(ProjectActionEvent event); @NotNull Runner addRunner(@NotNull ApplicationProcessDescriptor processDescriptor); void addRunnerId(@NotNull Long runnerId); boolean isRunnerExist(@NotNull Long runnerId); @Override void onSelectionChanged(@NotNull Selection selection); static final String TIMER_STUB; }
@Test public void projectScopeShouldBeSetAfterReloadProjectWithProjectScopeRunner() { when(processDescriptor.getEnvironmentId()).thenReturn("project: presenter.addRunner(processDescriptor); verify(runner).setScope(PROJECT); }
@Test public void verifyTimer() { presenter.addRunner(processDescriptor); verify(timerFactory, times(2)).newInstance(timerCaptor.capture()); timerCaptor.getAllValues().get(0).onRun(); verify(runner, times(2)).getTimeout(); verify(view, times(2)).updateMoreInfoPopup(runner); verify(view, times(2)).setTimeout(TEXT); verify(runnerTimer, times(2)).schedule(TimeInterval.ONE_SEC.getValue()); }
@Test public void consoleHandlerShouldPerformActionWhenSelectedRunnerIsNotNull() { presenter.addRunner(processDescriptor); verifyTabSelectHandler(tabBuilderConsole); verify(locale, times(2)).runnerTabConsole(); verify(runner).setActiveTab(CONSOLE); }
@Test public void propertiesHandlerShouldPerformActionWhenSelectedRunnerIsNotNullAndPanelStateIsRunner() { presenter.addRunner(processDescriptor); verifyTabSelectHandler(tabBuilderProperties); verify(propertiesContainer).show(runner); verify(runner).setActiveTab(PROPERTIES); verify(locale, times(2)).runnerTabProperties(); verify(runner).setActiveTab(PROPERTIES); }
@Test public void propertiesHandlerShouldPerformActionWhenSelectedRunnerIsNotNullAndPanelStateIsProperties() { when(panelState.getState()).thenReturn(TEMPLATE); presenter.addRunner(processDescriptor); reset(locale); verifyTabSelectHandler(tabBuilderProperties); verify(propertiesContainer).show(isNull(Environment.class)); }
@Test public void runnerShouldBeAdded() { presenter.addRunner(processDescriptor); verify(dtoFactory).createDto(RunOptions.class); verify(modelsFactory).createRunner(runOptions); verify(processDescriptor).getProcessId(); verify(runner).setProcessDescriptor(processDescriptor); verify(runner).setRAM(DEFAULT.getValue()); verify(runner).setStatus(Runner.Status.DONE); verify(runner).resetCreationTime(); verify(history).addRunner(runner); verify(panelState).setState(RUNNERS); verify(view).setEnableRunButton(anyBoolean()); verify(view).showOtherButtons(); verifyRunnerSelected(); verify(runnerTimer).schedule(TimeInterval.ONE_SEC.getValue()); verify(actionFactory).createLaunch(); verify(launchAction).perform(runner); }