RunnerManagerPresenter extends BasePresenter implements RunnerManager,
                                                                     RunnerManagerView.ActionDelegate,
                                                                     ProjectActionHandler,
                                                                     SelectionManager.SelectionChangeListener { @Override public Runner launchRunner() { CurrentProject currentProject = appContext.getCurrentProject(); if (currentProject == null) { throw new IllegalStateException("Can't launch runner for current project. Current project is absent..."); } int ram = DEFAULT.getValue(); RunnersDescriptor runnersDescriptor = currentProject.getProjectDescription().getRunners(); String defaultRunner = runnersDescriptor.getDefault(); if (!EnvironmentIdValidator.isValid(defaultRunner)) { defaultRunner = URL.encode(defaultRunner); } RunnerConfiguration defaultConfigs = runnersDescriptor.getConfigs().get(defaultRunner); if (defaultRunner != null && defaultConfigs != null) { ram = defaultConfigs.getRam(); } RunOptions runOptions = dtoFactory.createDto(RunOptions.class) .withSkipBuild(Boolean.valueOf(currentProject.getAttributeValue("runner:skipBuild"))) .withEnvironmentId(defaultRunner) .withMemorySize(ram); Environment environment = chooseRunnerAction.selectEnvironment(); if (environment != null) { if (defaultRunner != null && defaultRunner.equals(environment.getId())) { Runner runner = modelsFactory.createRunner(runOptions); if (defaultRunner.startsWith(PROJECT_PREFIX)) { runner.setScope(PROJECT); } return launchRunner(runner); } runOptions = runOptions.withOptions(environment.getOptions()) .withMemorySize(environment.getRam()) .withEnvironmentId(environment.getId()); Runner runner = modelsFactory.createRunner(runOptions, environment.getScope(), environment.getName()); if (environment.getId().startsWith(PROJECT_PREFIX)) { runner.setScope(PROJECT); } return launchRunner(runner); } Runner runner = modelsFactory.createRunner(runOptions); if (defaultRunner != null && defaultRunner.startsWith(PROJECT_PREFIX)) { runner.setScope(PROJECT); } return launchRunner(modelsFactory.createRunner(runOptions)); } @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(expected = IllegalStateException.class) public void runnerShouldNotBeLaunchedIfCurrentProjectIsNull() { when(appContext.getCurrentProject()).thenReturn(null); presenter.launchRunner(); }
@Test public void runnerShouldNotBeLaunched() { when(runActionPermit.isAllowed()).thenReturn(true); presenter.launchRunner(); verifyLaunchRunnerWithNotNullCurrentProject(); }
@Test public void shouldCreateAndLaunchRunnerFromRunOptions() { presenter.launchRunner(runOptions); verify(modelsFactory).createRunner(runOptions); }
@Test public void shouldCreateAndLaunchRunnerFromRunOptionsAndEnvironmentName() { when(modelsFactory.createRunner(runOptions, SYSTEM, TEXT)).thenReturn(runner); presenter.launchRunner(runOptions, SYSTEM, TEXT); verify(modelsFactory).createRunner(runOptions, SYSTEM, TEXT); }
@Test(expected = IllegalStateException.class) public void runnerShouldNotLaunchWhenCurrentProjectIsNull() { when(appContext.getCurrentProject()).thenReturn(null); when(runActionPermit.isAllowed()).thenReturn(true); presenter.launchRunner(runOptions); }