RunAction extends AbstractRunnerAction { @Override public void perform(@NotNull final Runner runner) { eventLogger.log(this); final CurrentProject project = appContext.getCurrentProject(); if (project == null) { return; } presenter.setActive(); AsyncRequestCallback<ApplicationProcessDescriptor> callback = callbackBuilderProvider .get() .unmarshaller(ApplicationProcessDescriptor.class) .success(new SuccessCallback<ApplicationProcessDescriptor>() { @Override public void onSuccess(ApplicationProcessDescriptor descriptor) { runner.setProcessDescriptor(descriptor); runner.setRAM(descriptor.getMemorySize()); presenter.addRunnerId(descriptor.getProcessId()); presenter.update(runner); launchAction.perform(runner); } }) .failure(new FailureCallback() { @Override public void onFailure(@NotNull Throwable reason) { if (project.getRunner() == null) { runnerUtil.showError(runner, locale.defaultRunnerAbsent(), null); return; } runnerUtil.showError(runner, locale.startApplicationFailed(project.getProjectDescription().getName()), null); } }) .build(); String encodedEnvironmentId = runner.getOptions().getEnvironmentId(); if (encodedEnvironmentId != null && !EnvironmentIdValidator.isValid(encodedEnvironmentId)) { runner.getOptions().setEnvironmentId(URL.encode(encodedEnvironmentId)); } service.run(project.getProjectDescription().getPath(), runner.getOptions(), callback); } @Inject  RunAction(RunnerServiceClient service,
                     AppContext appContext,
                     RunnerLocalizationConstant locale,
                     RunnerManagerPresenter presenter,
                     Provider<AsyncCallbackBuilder<ApplicationProcessDescriptor>> callbackBuilderProvider,
                     RunnerUtil runnerUtil,
                     RunnerActionFactory actionFactory,
                     AnalyticsEventLogger eventLogger); @Override void perform(@NotNull final Runner runner);  }
@Test public void shouldPerformWhenCurrentProjectIsNull() { reset(launchAction); when(appContext.getCurrentProject()).thenReturn(null); runAction.perform(runner); verify(eventLogger).log(runAction); verify(appContext).getCurrentProject(); verifyNoMoreInteractions(runner, service, locale, launchAction, presenter, callbackBuilderProvider); }
@Test public void shouldSuccessPerform() { when(descriptor.getMemorySize()).thenReturn(MB_500.getValue()); when(descriptor.getProcessId()).thenReturn(12345678L); when(runner.getOptions()).thenReturn(runOptions); runAction.perform(runner); verify(eventLogger).log(runAction); verify(presenter).setActive(); verify(asyncCallbackBuilder).success(successCallBackCaptor.capture()); SuccessCallback<ApplicationProcessDescriptor> successCallback = successCallBackCaptor.getValue(); successCallback.onSuccess(descriptor); verify(runner).setProcessDescriptor(descriptor); verify(runner).setRAM(MB_500.getValue()); verify(presenter).addRunnerId(12345678L); verify(presenter).update(runner); verify(launchAction).perform(runner); verify(service).run(PATH_TO_PROJECT, runOptions, asyncRequestCallback); }
@Test public void shouldFailedPerform() { String someRunningMessage = "run information"; when(runner.getOptions()).thenReturn(runOptions); when(locale.startApplicationFailed(PROJECT_NAME)).thenReturn(someRunningMessage); when(project.getRunner()).thenReturn(PROJECT_NAME); when(projectDescriptor.getName()).thenReturn(someRunningMessage); when(locale.startApplicationFailed(someRunningMessage)).thenReturn(someRunningMessage); runAction.perform(runner); verify(eventLogger).log(runAction); verify(presenter).setActive(); verify(asyncCallbackBuilder).failure(failedCallBackCaptor.capture()); FailureCallback failureCallback = failedCallBackCaptor.getValue(); failureCallback.onFailure(reason); verify(runnerUtil).showError(runner, someRunningMessage, null); verify(project).getRunner(); verify(project, times(2)).getProjectDescription(); verify(projectDescriptor).getName(); verify(locale).startApplicationFailed(someRunningMessage); verify(service).run(PATH_TO_PROJECT, runOptions, asyncRequestCallback); }
@Test public void shouldFailedWhenDefaultRunnerAbsent() { String someRunningMessage = "run information"; when(runner.getOptions()).thenReturn(runOptions); when(locale.startApplicationFailed(PROJECT_NAME)).thenReturn(someRunningMessage); when(projectDescriptor.getName()).thenReturn(someRunningMessage); when(locale.defaultRunnerAbsent()).thenReturn(someRunningMessage); runAction.perform(runner); verify(eventLogger).log(runAction); verify(presenter).setActive(); verify(asyncCallbackBuilder).failure(failedCallBackCaptor.capture()); FailureCallback failureCallback = failedCallBackCaptor.getValue(); failureCallback.onFailure(reason); verify(runnerUtil).showError(runner, someRunningMessage, null); verify(project).getRunner(); verify(locale).defaultRunnerAbsent(); verify(service).run(PATH_TO_PROJECT, runOptions, asyncRequestCallback); }