StopAction extends AbstractRunnerAction { @Override public void perform(@NotNull final Runner runner) { notification = new Notification(constant.messageRunnerShuttingDown(), PROGRESS); notificationManager.showNotification(notification); eventLogger.log(this); this.runner = runner; runner.setStatus(Runner.Status.STOPPED); presenter.update(runner); project = appContext.getCurrentProject(); if (project == null) { return; } Link stopLink = runner.getStopUrl(); if (stopLink == null) { runnerUtil.showError(runner, constant.applicationFailed(project.getProjectDescription().getName()), null); return; } AsyncRequestCallback<ApplicationProcessDescriptor> callback = callbackBuilderProvider .get() .unmarshaller(ApplicationProcessDescriptor.class) .success(new SuccessCallback<ApplicationProcessDescriptor>() { @Override public void onSuccess(ApplicationProcessDescriptor result) { processStoppedMessage(result); } }) .failure(new FailureCallback() { @Override public void onFailure(@NotNull Throwable reason) { runner.setStatus(FAILED); presenter.update(runner); runner.setProcessDescriptor(null); project.setIsRunningEnabled(true); runnerUtil.showError(runner, constant.applicationFailed(project.getProjectDescription().getName()), reason); eventBus.fireEvent(new RunnerApplicationStatusEvent(runner)); } }) .build(); service.stop(stopLink, callback); } @Inject  StopAction(RunnerServiceClient service,
                      AppContext appContext,
                      Provider<AsyncCallbackBuilder<ApplicationProcessDescriptor>> callbackBuilderProvider,
                      RunnerLocalizationConstant constant,
                      NotificationManager notificationManager,
                      RunnerUtil runnerUtil,
                      RunnerActionFactory actionFactory,
                      ConsoleContainer consoleContainer,
                      EventBus eventBus,
                      AnalyticsEventLogger eventLogger,
                      RunnerManagerPresenter runnerManagerPresenter); @Override void perform(@NotNull final Runner runner);  }
@Test public void shouldPerformWhenCurrentProjectIsNull() { reset(launchAction, actionFactory, presenter); when(appContext.getCurrentProject()).thenReturn(null); stopAction.perform(runner); verify(eventLogger).log(stopAction); verify(appContext).getCurrentProject(); verifyNoMoreInteractions(service, appContext, callbackBuilderProvider, runnerUtil, actionFactory); }
@Test public void shouldFailedPerformWhenStopLinkIsNull() { reset(launchAction, actionFactory, presenter); when(runner.getStopUrl()).thenReturn(null); when(constant.applicationFailed(PROJECT_NAME)).thenReturn(MESSAGE); stopAction.perform(runner); verify(eventLogger).log(stopAction); verify(runner).getStopUrl(); verify(runnerUtil).showError(runner, MESSAGE, null); verify(runner).setStatus(Runner.Status.STOPPED); verify(presenter).update(runner); verifyNoMoreInteractions(callbackBuilderProvider); verify(service, never()).stop(any(Link.class), Matchers.<AsyncRequestCallback<ApplicationProcessDescriptor>>anyObject()); }
@Test public void shouldFailedPerform() { when(constant.applicationFailed(PROJECT_NAME)).thenReturn(MESSAGE); when(runner.getOptions()).thenReturn(runOptions); stopAction.perform(runner); verify(eventLogger).log(stopAction); verify(runner).getStopUrl(); verify(asyncCallbackBuilder).failure(failedCallBackCaptor.capture()); FailureCallback failureCallback = failedCallBackCaptor.getValue(); failureCallback.onFailure(reason); verify(runner).setStatus(Runner.Status.FAILED); verify(runner).setProcessDescriptor(null); verify(project).setIsRunningEnabled(true); verify(runnerUtil).showError(runner, MESSAGE, reason); verify(eventBus).fireEvent(Matchers.<RunnerApplicationStatusEvent>any()); verify(service).stop(stopLink, callback); }
@Test public void shouldSuccessPerformWithStatusRunning() { when(runner.getStatus()).thenReturn(Runner.Status.RUNNING); when(runner.getOptions()).thenReturn(runOptions); stopAction.perform(runner); verify(eventLogger).log(stopAction); verify(runner).getStopUrl(); verify(asyncCallbackBuilder).success(successCallBackCaptor.capture()); SuccessCallback<ApplicationProcessDescriptor> successCallback = successCallBackCaptor.getValue(); successCallback.onSuccess(descriptor); verify(runner).setProcessDescriptor(descriptor); verify(project).setIsRunningEnabled(true); verify(runner).getStatus(); verify(runner).setStatus(Runner.Status.STOPPED); verify(consoleContainer).printInfo(runner, MESSAGE); verify(notificationManager).showNotification(notificationCaptor.capture()); Notification notification = notificationCaptor.getValue(); assertThat(notification.getMessage(), is(MESSAGE)); assertThat(notification.getType(), is(Notification.Type.INFO)); verify(presenter, times(2)).update(runner); verify(service).stop(stopLink, callback); verify(eventBus).fireEvent(Matchers.<RunnerApplicationStatusEvent>any()); }
@Test public void shouldSuccessPerformWithStatusDone() { when(runner.getStatus()).thenReturn(Runner.Status.DONE); when(runner.getOptions()).thenReturn(runOptions); stopAction.perform(runner); verify(eventLogger).log(stopAction); verify(runner).getStopUrl(); verify(asyncCallbackBuilder).success(successCallBackCaptor.capture()); SuccessCallback<ApplicationProcessDescriptor> successCallback = successCallBackCaptor.getValue(); successCallback.onSuccess(descriptor); verify(runner).setProcessDescriptor(descriptor); verify(project).setIsRunningEnabled(true); verify(runner).getStatus(); verify(runner).setStatus(Runner.Status.STOPPED); verify(consoleContainer).printInfo(runner, MESSAGE); verify(notificationManager).showNotification(notificationCaptor.capture()); Notification notification = notificationCaptor.getValue(); assertThat(notification.getMessage(), is(MESSAGE)); assertThat(notification.getType(), is(Notification.Type.INFO)); verify(presenter, times(2)).update(runner); verify(service).stop(stopLink, callback); verify(eventBus).fireEvent(Matchers.<RunnerApplicationStatusEvent>any()); }
@Test public void shouldSuccessPerformWithStatusIsFailed() { when(runner.getStatus()).thenReturn(Runner.Status.FAILED); when(runner.getOptions()).thenReturn(runOptions); stopAction.perform(runner); verify(eventLogger).log(stopAction); verify(runner).getStopUrl(); verify(asyncCallbackBuilder).success(successCallBackCaptor.capture()); SuccessCallback<ApplicationProcessDescriptor> successCallback = successCallBackCaptor.getValue(); successCallback.onSuccess(descriptor); verify(runner).setProcessDescriptor(descriptor); verify(project).setIsRunningEnabled(true); verify(runner).getStatus(); verify(runner).setStatus(Runner.Status.FAILED); verify(logsAction).perform(runner); verify(consoleContainer).printError(runner, MESSAGE); verify(notificationManager).showNotification(notificationCaptor.capture()); Notification notification = notificationCaptor.getValue(); assertThat(notification.getType(), is(Notification.Type.ERROR)); verify(presenter, times(2)).update(runner); verify(service).stop(stopLink, callback); verify(eventBus).fireEvent(Matchers.<RunnerApplicationStatusEvent>any()); }
@Test public void notificationStopInProgressShouldBeShown() throws Exception { when(constant.messageRunnerShuttingDown()).thenReturn(MESSAGE); stopAction.perform(runner); verify(constant).messageRunnerShuttingDown(); verify(notificationManager).showNotification(notificationCaptor.capture()); Notification notification = notificationCaptor.getValue(); assertThat(notification.getMessage(), equalTo(MESSAGE)); assertThat(notification.isFinished(), is(false)); }