PropertiesEnvironmentPanel extends PropertiesPanelPresenter { @Override public void onSaveButtonClicked() { isParameterChanged = false; final String newEnvironmentName = view.getName(); final String environmentName = environment.getName(); final String environmentId = environment.getId(); final String encodedEnvironmentId = URL.encode(environmentId); final String pathToProject = projectDescriptor.getPath(); final String path = pathToProject + ROOT_FOLDER + environmentName; final AsyncRequestCallback<Void> renameAsyncRequestCallback = voidAsyncCallbackBuilder .success(new SuccessCallback<Void>() { @Override public void onSuccess(Void result) { RunnerConfiguration config = runnerConfigs.get(encodedEnvironmentId); runnerConfigs.remove(encodedEnvironmentId); runnerConfigs.put(generateEnvironmentId(newEnvironmentName), config); String defaultRunner = currentProject.getRunner(); if (defaultRunner != null && defaultRunner.equals(environmentId)) { projectDescriptor.getRunners().setDefault(generateEnvironmentId(newEnvironmentName)); } updateProject(); } }) .failure(new FailureCallback() { @Override public void onFailure(@NotNull Throwable reason) { notificationManager.showError(reason.getMessage()); } }) .build(); if (editor.isDirty()) { editor.doSave(new AsyncCallback<EditorInput>() { @Override public void onSuccess(EditorInput editorInput) { view.setEnableSaveButton(false); view.setEnableCancelButton(false); if (!environmentName.equals(newEnvironmentName)) { projectService.rename(path, newEnvironmentName, null, renameAsyncRequestCallback); } } @Override public void onFailure(Throwable throwable) { Log.error(getClass(), throwable.getMessage()); } }); } else { if (!environmentName.equals(newEnvironmentName)) { projectService.rename(path, newEnvironmentName, null, renameAsyncRequestCallback); } } Map<String, String> variables = new HashMap<>(); variables.put(CONFIGURATION_TYPE, environment.getType()); RunnerConfiguration config = dtoFactory.createDto(RunnerConfiguration.class).withRam(environment.getRam()).withVariables(variables); runnerConfigs.put(encodedEnvironmentId, config); updateProject(); projectEnvironmentsAction.perform(); } @AssistedInject  PropertiesEnvironmentPanel(final PropertiesPanelView view,
                                      DtoFactory dtoFactory,
                                      @Named("DefaultEditorProvider") EditorProvider editorProvider,
                                      @NotNull final FileTypeRegistry fileTypeRegistry,
                                      final DockerFileFactory dockerFileFactory,
                                      final ProjectServiceClient projectService,
                                      EventBus eventBus,
                                      AppContext appContext,
                                      ChooseRunnerAction chooseRunnerAction,
                                      DialogFactory dialogFactory,
                                      RunnerLocalizationConstant locale,
                                      GetProjectEnvironmentsAction projectEnvironmentsAction,
                                      NotificationManager notificationManager,
                                      DtoUnmarshallerFactory unmarshallerFactory,
                                      AsyncCallbackBuilder<ItemReference> asyncCallbackBuilder,
                                      AsyncCallbackBuilder<List<ItemReference>> asyncArrayCallbackBuilder,
                                      AsyncCallbackBuilder<Void> voidAsyncCallbackBuilder,
                                      AsyncCallbackBuilder<ProjectDescriptor> asyncDescriptorCallbackBuilder,
                                      TemplatesContainer templatesContainer,
                                      EditorAgent editorAgent,
                                      @Assisted @NotNull final Environment environment); @Override void onCopyButtonClicked(); @Override void onConfigurationChanged(); @Override void onSaveButtonClicked(); @Override void onDeleteButtonClicked(); @Override void onCancelButtonClicked(); @Override void update(@NotNull Environment environment); @Override void onSwitcherChanged(boolean isOn); @Override void addListener(@NotNull RemovePanelListener listener); static final String ENVIRONMENT_ID_PREFIX; }
@Test public void defaultRunnerShouldBeRenamedWhenClickOnSaveButton() { reset(projectDescriptor); when(projectDescriptor.getRunners()).thenReturn(runnersDescriptor); when(environment.getId()).thenReturn(TEXT); when(currentProject.getRunner()).thenReturn(TEXT); when(environment.getName()).thenReturn(TEXT); when(view.getName()).thenReturn(TEXT2); presenter.onSaveButtonClicked(); verify(voidAsyncCallbackBuilder).success(voidArgumentCaptor.capture()); voidArgumentCaptor.getValue().onSuccess(null); verify(projectDescriptor).getRunners(); verify(runnersDescriptor).setDefault(anyString()); }
@Test public void defaultRunnerShouldNotBeRenamedWhenDefaultRunnerIsNull() { reset(projectDescriptor); when(projectDescriptor.getRunners()).thenReturn(runnersDescriptor); when(environment.getId()).thenReturn(TEXT); when(currentProject.getRunner()).thenReturn(null); when(environment.getName()).thenReturn(TEXT); when(view.getName()).thenReturn(TEXT2); presenter.onSaveButtonClicked(); verify(voidAsyncCallbackBuilder).success(voidArgumentCaptor.capture()); voidArgumentCaptor.getValue().onSuccess(null); verify(projectDescriptor, never()).getRunners(); verify(runnersDescriptor, never()).setDefault(anyString()); }
@Test public void defaultRunnerShouldNotBeRenamedWhenRenameNotDefaultRunner() { reset(projectDescriptor); when(projectDescriptor.getRunners()).thenReturn(runnersDescriptor); when(environment.getId()).thenReturn(TEXT2); when(currentProject.getRunner()).thenReturn(TEXT); when(environment.getName()).thenReturn(TEXT); when(view.getName()).thenReturn(TEXT2); presenter.onSaveButtonClicked(); verify(voidAsyncCallbackBuilder).success(voidArgumentCaptor.capture()); voidArgumentCaptor.getValue().onSuccess(null); verify(projectDescriptor, never()).getRunners(); verify(runnersDescriptor, never()).setDefault(anyString()); }