@Nullable @Override public JComponent createComponent() { if (cloudSdkPanel == null) { cloudSdkPanel = new CloudSdkPanel(); } return cloudSdkPanel.getComponent(); }
@Override public void apply() throws ConfigurationException { if (cloudSdkPanel != null) { cloudSdkPanel.apply(); } }
@VisibleForTesting protected void checkSdk(String path) { String message = buildSdkMessage(path, true /*htmlEnabled*/); if (!StringUtil.isEmpty(message)) { showWarning(message); } else { hideWarning(); } }
public CloudSdkPanel() { warningMessage.setVisible(false); warningMessage.setBackground(cloudSdkPanel.getBackground()); warningMessage.addHyperlinkListener(new BrowserOpeningHyperLinkListener()); warningIcon.setVisible(false); warningIcon.setIcon(RunConfigurations.ConfigurationWarning); checkManagedSdkFeatureStatus(); initEvents(); }
@Test public void testCheckSdk_nullSdk() { when(cloudSdkValidator.isValidCloudSdk(null)).thenReturn(false); panel.checkSdk(null); verify(panel, times(1)).showWarning(eq(MISSING_SDK_DIR_WARNING)); verify(panel, times(0)).hideWarning(); }
@Test public void testApplyWith_invalidSdk() { ApplicationManager.getApplication() .invokeAndWait( () -> { // use non-spy panel as spy messes up with UI event thread field updates. CloudSdkPanel sdkPanel = new CloudSdkPanel(); sdkPanel.reset(); setValidateCloudSdkResponse(CloudSdkValidationResult.CLOUD_SDK_NOT_FOUND); sdkPanel.getCloudSdkDirectoryField().setText("/non/empty/path"); // No exception should be thrown on invalid sdk entry from this panel try { sdkPanel.apply(); } catch (ConfigurationException e) { throw new AssertionError(e); } }); }
@Test public void managedSdk_choice_disableAutomaticUpdates_apply_validSettings() { ApplicationManager.getApplication() .invokeAndWait( () -> { // use non-spy panel as spy messes up with UI event thread field updates. CloudSdkPanel sdkPanel = new CloudSdkPanel(); sdkPanel.reset(); sdkPanel.getManagedRadioButton().doClick(); sdkPanel.getEnableAutomaticUpdatesCheckbox().setSelected(false); try { sdkPanel.apply(); } catch (ConfigurationException e) { throw new AssertionError(e); } verifyCloudSdkSettings( CloudSdkServiceType.MANAGED_SDK, false, /* no auto-updates */ null /* no custom path */); }); }
@Test public void updateNow_notEnabled_whenSdkNotReady() { when(mockCloudSdkService.getStatus()).thenReturn(SdkStatus.INSTALLING); ApplicationManager.getApplication() .invokeAndWait( () -> { // use non-spy panel as spy messes up with UI event thread field updates. CloudSdkPanel sdkPanel = new CloudSdkPanel(); CloudSdkServiceUserSettings.getInstance() .setUserSelectedSdkServiceType(CloudSdkServiceType.MANAGED_SDK); sdkPanel.reset(); assertThat(sdkPanel.getUpdateNowButton().isEnabled()).isFalse(); }); }
private void verifySdkPanelStateForCurrentSettings(CloudSdkPanel sdkPanel) { CloudSdkServiceUserSettings userSettings = CloudSdkServiceUserSettings.getInstance(); switch (userSettings.getUserSelectedSdkServiceType()) { case CUSTOM_SDK: assertThat(sdkPanel.getCustomRadioButton().isSelected()).isTrue(); assertThat(sdkPanel.getManagedRadioButton().isSelected()).isFalse(); assertThat(sdkPanel.getEnableAutomaticUpdatesCheckbox().isEnabled()).isFalse(); break; case MANAGED_SDK: assertThat(sdkPanel.getManagedRadioButton().isSelected()).isTrue(); assertThat(sdkPanel.getEnableAutomaticUpdatesCheckbox().isEnabled()).isTrue(); assertThat(sdkPanel.getCustomRadioButton().isSelected()).isFalse(); assertThat(sdkPanel.getCloudSdkDirectoryField().isEnabled()).isFalse(); break; } assertThat(sdkPanel.getEnableAutomaticUpdatesCheckbox().isSelected()) .isEqualTo(userSettings.isAutomaticUpdateEnabled()); assertThat(sdkPanel.getCloudSdkDirectoryText()) .isEqualTo(Strings.nullToEmpty(userSettings.getCustomSdkPath())); } }
@Test public void defaultSdkSettings_reset_validUiState() { ApplicationManager.getApplication() .invokeAndWait( () -> { // use non-spy panel as spy messes up with UI event thread field updates. CloudSdkPanel sdkPanel = new CloudSdkPanel(); // use built-in defaults. sdkPanel.reset(); verifySdkPanelStateForCurrentSettings(sdkPanel); }); }
@Override public void run() { checkSdk(sdkPath); } }
@Override public void reset() { if (cloudSdkPanel != null) { cloudSdkPanel.reset(); } }
@Before public void setUp() { when(mockCloudSdkServiceManager.getCloudSdkService()).thenReturn(mockCloudSdkService); // enable managed SDK UI - remove when feature is rolled out. when(pluginInfoService.shouldEnable(GctFeature.MANAGED_SDK)).thenReturn(true); // now safe to create panel spy. panel = Mockito.spy(new CloudSdkPanel()); // reset SDK settings on each run to clean previous settings. CloudSdkServiceUserSettings.reset(); }
public void apply() throws ConfigurationException { CloudSdkServiceUserSettings sdkServiceUserSettings = CloudSdkServiceUserSettings.getInstance(); if (customRadioButton.isSelected()) { String customSdkPathText = getCloudSdkDirectoryText(); if (CloudSdkValidator.getInstance() .validateCloudSdk(customSdkPathText) .contains(CloudSdkValidationResult.MALFORMED_PATH)) { throw new ConfigurationException( CloudSdkMessageBundle.message("appengine.cloudsdk.location.badchars.message")); } sdkServiceUserSettings.setCustomSdkPath(customSdkPathText); } CloudSdkServiceType previousSdkType = sdkServiceUserSettings.getUserSelectedSdkServiceType(); if (previousSdkType != selectedCloudSdkServiceType) { // notify SDK manager about changed selection ServiceManager.getService(CloudSdkServiceManager.class) .onNewCloudSdkServiceTypeSelected(selectedCloudSdkServiceType); } sdkServiceUserSettings.setUserSelectedSdkServiceType(selectedCloudSdkServiceType); boolean previousAutomaticUpdateEnabled = sdkServiceUserSettings.isAutomaticUpdateEnabled(); sdkServiceUserSettings.setEnableAutomaticUpdates(enableAutomaticUpdatesCheckbox.isSelected()); if (enableAutomaticUpdatesCheckbox.isSelected() && !previousAutomaticUpdateEnabled) { // activate updates again. ManagedCloudSdkUpdateService.getInstance().activate(); } // settings are applied and saved, clear modification status settingsModified = false; }
/** * Checks for custom SDK validation errors and shows error label if they exist. To be removed once * managed SDk feature is rolled out. */ private void updateSdkValidationLabel() { if (!ServiceManager.getService(PluginInfoService.class).shouldEnable(GctFeature.MANAGED_SDK)) { String sdkValidationMessage = CloudSdkPanel.buildSdkMessage( CloudSdkServiceUserSettings.getInstance().getCustomSdkPath(), false); if (sdkValidationMessage != null) { sdkValidationErrorLabel.setText(sdkValidationMessage); sdkValidationErrorLabel.setVisible(true); } else { sdkValidationErrorLabel.setVisible(false); } } else { sdkValidationErrorLabel.setVisible(false); } } }
@Test public void testCheckSdk_emptySdk() { when(cloudSdkValidator.isValidCloudSdk("")).thenReturn(false); panel.checkSdk(""); verify(panel, times(1)).showWarning(eq(MISSING_SDK_DIR_WARNING)); verify(panel, times(0)).hideWarning(); }
@Test public void customSdk_choice_apply_validSettings() { ApplicationManager.getApplication() .invokeAndWait( () -> { // use non-spy panel as spy messes up with UI event thread field updates. CloudSdkPanel sdkPanel = new CloudSdkPanel(); sdkPanel.reset(); sdkPanel.getCustomRadioButton().doClick(); String customSdkPath = "/home/gcloud"; sdkPanel.getCloudSdkDirectoryField().setText(customSdkPath); try { sdkPanel.apply(); } catch (ConfigurationException e) { throw new AssertionError(e); } verifyCloudSdkSettings( CloudSdkServiceType.CUSTOM_SDK, CloudSdkServiceUserSettings.DEFAULT_MANAGED_SDK_AUTOMATIC_UPDATES, customSdkPath); }); }
@Test public void managedSdk_choice_apply_validSettings() { ApplicationManager.getApplication() .invokeAndWait( () -> { // use non-spy panel as spy messes up with UI event thread field updates. CloudSdkPanel sdkPanel = new CloudSdkPanel(); sdkPanel.reset(); sdkPanel.getManagedRadioButton().doClick(); try { sdkPanel.apply(); } catch (ConfigurationException e) { throw new AssertionError(e); } verifyCloudSdkSettings( CloudSdkServiceType.MANAGED_SDK, CloudSdkServiceUserSettings.DEFAULT_MANAGED_SDK_AUTOMATIC_UPDATES, null /* no custom path */); }); }
@Test public void updateNow_notEnabled_whenSdkUpToDate() { ManagedCloudSdkService managedCloudSdkService = mock(ManagedCloudSdkService.class); when(mockCloudSdkServiceManager.getCloudSdkService()).thenReturn(managedCloudSdkService); when(managedCloudSdkService.getStatus()).thenReturn(SdkStatus.READY); when(managedCloudSdkService.isUpToDate()).thenReturn(true); ApplicationManager.getApplication() .invokeAndWait( () -> { // use non-spy panel as spy messes up with UI event thread field updates. CloudSdkPanel sdkPanel = new CloudSdkPanel(); CloudSdkServiceUserSettings.getInstance() .setUserSelectedSdkServiceType(CloudSdkServiceType.MANAGED_SDK); sdkPanel.reset(); assertThat(sdkPanel.getUpdateNowButton().isEnabled()).isFalse(); }); }
@Test public void customSdkSettings_reset_validUiState() { ApplicationManager.getApplication() .invokeAndWait( () -> { // use non-spy panel as spy messes up with UI event thread field updates. CloudSdkPanel sdkPanel = new CloudSdkPanel(); CloudSdkServiceUserSettings userSettings = CloudSdkServiceUserSettings.getInstance(); userSettings.setUserSelectedSdkServiceType(CloudSdkServiceType.CUSTOM_SDK); userSettings.setCustomSdkPath("/home/gcloud"); sdkPanel.reset(); verifySdkPanelStateForCurrentSettings(sdkPanel); }); }