GetSystemEnvironmentsAction extends AbstractRunnerAction { @Override public void perform() { if (!runnerUtil.hasRunPermission()) { return; } eventLogger.log(this); AsyncRequestCallback<RunnerEnvironmentTree> callback = callbackBuilderProvider .get() .unmarshaller(RunnerEnvironmentTree.class) .success(new SuccessCallback<RunnerEnvironmentTree>() { @Override public void onSuccess(RunnerEnvironmentTree result) { environmentTree = result; getEnvironments(result); } }) .failure(new FailureCallback() { @Override public void onFailure(@NotNull Throwable reason) { notificationManager.showError(locale.customRunnerGetEnvironmentFailed()); } }) .build(); if (environmentTree == null) { runnerService.getRunners(callback); } else { getEnvironments(environmentTree); } } @Inject  GetSystemEnvironmentsAction(RunnerServiceClient runnerService,
                                       NotificationManager notificationManager,
                                       Provider<AsyncCallbackBuilder<RunnerEnvironmentTree>> callbackBuilderProvider,
                                       RunnerLocalizationConstant locale,
                                       GetEnvironmentsUtil environmentUtil,
                                       RunnerUtil runnerUtil,
                                       ChooseRunnerAction chooseRunnerAction,
                                       AppContext appContext,
                                       Provider<TemplatesContainer> templatesPanelProvider,
                                       AnalyticsEventLogger eventLogger); @Override void perform();  }
@Test public void shouldNotPerformWhenProjectDoesNotHavePermission() { when(runnerUtil.hasRunPermission()).thenReturn(false); action.perform(); verify(runnerUtil).hasRunPermission(); verifyNoMoreInteractions(runnerService, notificationManager, callbackBuilderProvider, locale, environmentUtil, runnerUtil, chooseRunnerAction, appContext, templatesContainerProvider, eventLogger); }
@Test public void shouldSuccessPerformWhenEnvironmentTreeIsNull() { when(environmentUtil.getRunnerCategoryByProjectType(null, MESSAGE)).thenReturn(tree); action.perform(); verify(eventLogger).log(action); verify(asyncCallbackBuilder).success(successCallBackCaptor.capture()); SuccessCallback<RunnerEnvironmentTree> successCallback = successCallBackCaptor.getValue(); successCallback.onSuccess(null); verify(runnerService).getRunners(asyncRequestCallback); }
@Test public void shouldFailurePerformWhenEnvironmentTreeIsNull() { action.perform(); verify(eventLogger).log(action); verify(asyncCallbackBuilder).failure(failedCallBackCaptor.capture()); FailureCallback failureCallback = failedCallBackCaptor.getValue(); failureCallback.onFailure(reason); verify(notificationManager).showError(MESSAGE); verify(runnerService).getRunners(asyncRequestCallback); }
@Test public void getSystemEnvironmentsActionShouldBePerformedWhenEnvironmentTreeIsNotNull() throws Exception { when(currentProject.getRunner()).thenReturn(null); action.perform(); verify(eventLogger).log(action); verify(asyncCallbackBuilder).success(successCallBackCaptor.capture()); SuccessCallback<RunnerEnvironmentTree> successCallback = successCallBackCaptor.getValue(); successCallback.onSuccess(tree); reset(runnerService); action.perform(); verify(runnerService, never()).getRunners(asyncRequestCallback); verify(appContext, times(2)).getCurrentProject(); verify(environmentUtil, times(2)).getEnvironmentsByProjectType(tree, MESSAGE, SYSTEM); verify(templatesContainerProvider, times(2)).get(); verify(chooseRunnerAction, times(2)).addSystemRunners(Matchers.<List<Environment>>anyObject()); }
@Test public void correctCategoryNameShouldBeReturnedWhenDefaultProjectIsNotNull() throws Exception { when(currentProject.getRunner()).thenReturn(MESSAGE); when(environmentUtil.getCorrectCategoryName(MESSAGE)).thenReturn(MESSAGE); action.perform(); verify(asyncCallbackBuilder).success(successCallBackCaptor.capture()); SuccessCallback<RunnerEnvironmentTree> successCallback = successCallBackCaptor.getValue(); successCallback.onSuccess(tree); verify(currentProject).getRunner(); verify(environmentUtil, never()).getRunnerCategoryByProjectType(Matchers.<RunnerEnvironmentTree>anyObject(), anyString()); verify(templatesContainer).setDefaultEnvironment(environment); }
@Test public void environmentTreeShouldBeReturnedWhenDefaultRunnerWithProjectScope() throws Exception { when(currentProject.getRunner()).thenReturn(DEFAULT_RUNNER_PROJECT_TYPE + MESSAGE); action.perform(); verify(asyncCallbackBuilder).success(successCallBackCaptor.capture()); SuccessCallback<RunnerEnvironmentTree> successCallback = successCallBackCaptor.getValue(); successCallback.onSuccess(tree); verify(environmentUtil, never()).getCorrectCategoryName(anyString()); }
@Test public void systemEnvironmentsShouldNotBeGotWhenCurrentProjectIsNull() throws Exception { when(appContext.getCurrentProject()).thenReturn(null); action.perform(); verify(asyncCallbackBuilder).success(successCallBackCaptor.capture()); SuccessCallback<RunnerEnvironmentTree> successCallback = successCallBackCaptor.getValue(); successCallback.onSuccess(tree); verify(currentProject, never()).getProjectDescription(); }
@Test public void failureMethodShouldBeCalledWhenPerformAction() throws Exception { when(locale.customRunnerGetEnvironmentFailed()).thenReturn(MESSAGE); action.perform(); verify(asyncCallbackBuilder).failure(failedCallBackCaptor.capture()); failedCallBackCaptor.getValue().onFailure(reason); verify(notificationManager).showError(MESSAGE); }
@Test public void itemShouldNotBeAddedWhenActionIsPerformedTheSecondTime() { action.perform(); reset(templatesContainer); action.perform(); verify(eventLogger, times(2)).log(action); }
@Test public void shouldFailurePerformWhenEnvironmentTreeIsNotNull() { action.perform(); verify(eventLogger).log(action); verify(asyncCallbackBuilder).success(successCallBackCaptor.capture()); SuccessCallback<RunnerEnvironmentTree> successCallback = successCallBackCaptor.getValue(); successCallback.onSuccess(tree); action.perform(); verify(asyncCallbackBuilder, times(2)).failure(failedCallBackCaptor.capture()); FailureCallback failureCallback = failedCallBackCaptor.getValue(); failureCallback.onFailure(reason); verify(notificationManager).showError(MESSAGE); }