StatusAction extends AbstractRunnerAction { @Override public void perform(@NotNull final Runner runner) { this.runner = runner; project = appContext.getCurrentProject(); webSocketChannel = STATUS_CHANNEL + runner.getProcessId(); runnerStatusHandler = new SubscriptionHandler<ApplicationProcessDescriptor>( dtoUnmarshallerFactory.newWSUnmarshaller(ApplicationProcessDescriptor.class)) { @Override protected void onMessageReceived(ApplicationProcessDescriptor descriptor) { onApplicationStatusUpdated(descriptor); } @Override protected void onErrorReceived(Throwable exception) { runner.setStatus(Runner.Status.FAILED); showError(exception); stop(); project.setIsRunningEnabled(true); } }; webSocketUtil.subscribeHandler(webSocketChannel, runnerStatusHandler); notification.setStatus(FINISHED); } @Inject  StatusAction(DtoUnmarshallerFactory dtoUnmarshallerFactory,
                        DtoFactory dtoFactory,
                        TerminalContainer terminalContainer,
                        WebSocketUtil webSocketUtil,
                        AppContext appContext,
                        EventBus eventBus,
                        RunnerLocalizationConstant locale,
                        RunnerManagerPresenter presenter,
                        RunnerUtil runnerUtil,
                        ConsoleContainer consoleContainer,
                        RunnerActionFactory actionFactory,
                        @NotNull @Assisted Notification notification,
                        ResourcesLockedActionPermit resourcesLockedActionPermit); @Override void perform(@NotNull final Runner runner); @Override void stop();  }
@Test public void shouldCheckPerformActionBeforeSendCallBackOnServer() { statusAction.perform(runner); verify(appContext).getCurrentProject(); verify(runner).getProcessId(); }
@Test public void shouldCheckPerformActionAfterSendCallBackOnServer() throws Exception { when(descriptor.getStatus()).thenReturn(ApplicationStatus.RUNNING); statusAction.perform(runner); verify(webSocketUtil).subscribeHandler(eq(WEB_SOCKET_CHANNEL), subscriptionHandlerCaptor.capture()); SubscriptionHandler<ApplicationProcessDescriptor> processStartedHandler = subscriptionHandlerCaptor.getValue(); TestUtil.invokeMethodByName(processStartedHandler, "onMessageReceived", descriptor); verify(webSocketUtil).subscribeHandler(WEB_SOCKET_CHANNEL, processStartedHandler); verify(notification).setStatus(Notification.Status.FINISHED); }
@Test public void shouldOnPerformWithStatusRunning() throws Exception { when(descriptor.getStatus()).thenReturn(ApplicationStatus.RUNNING); statusAction.perform(runner); verify(webSocketUtil).subscribeHandler(eq(WEB_SOCKET_CHANNEL), subscriptionHandlerCaptor.capture()); SubscriptionHandler<ApplicationProcessDescriptor> processStartedHandler = subscriptionHandlerCaptor.getValue(); TestUtil.invokeMethodByName(processStartedHandler, "onMessageReceived", descriptor); verify(dtoUnmarshallerFactory).newWSUnmarshaller(ApplicationProcessDescriptor.class); verify(runner).setProcessDescriptor(descriptor); verify(descriptor).getStatus(); verify(runner).setStatus(Runner.Status.RUNNING); verify(presenter).update(runner); verify(checkHealthStatusAction).perform(runner); verify(project).getProjectDescription(); verify(projectDescriptor).getName(); verify(locale).applicationStarting(PROJECT_NAME); verify(notification).update(MESSAGE, Notification.Type.INFO, Notification.Status.FINISHED, null, true); verify(consoleContainer).printInfo(runner, MESSAGE); verify(eventBus).fireEvent(any(RunnerApplicationStatusEvent.class)); }
@Test public void shouldOnPerformWithStatusNEW() throws Exception { when(locale.applicationFailed(PROJECT_NAME)).thenReturn(FailedMessage); when(descriptor.getStatus()).thenReturn(ApplicationStatus.NEW); statusAction.perform(runner); verify(webSocketUtil).subscribeHandler(eq(WEB_SOCKET_CHANNEL), subscriptionHandlerCaptor.capture()); SubscriptionHandler<ApplicationProcessDescriptor> processStartedHandler = subscriptionHandlerCaptor.getValue(); TestUtil.invokeMethodByName(processStartedHandler, "onMessageReceived", descriptor); verify(dtoUnmarshallerFactory).newWSUnmarshaller(ApplicationProcessDescriptor.class); verify(runner).setProcessDescriptor(descriptor); verify(descriptor).getStatus(); verify(runner).setStatus(Runner.Status.IN_PROGRESS); verify(presenter).update(runner); verify(eventBus).fireEvent(any(RunnerApplicationStatusEvent.class)); }