From: Sébastien Lesaint Date: Wed, 18 Oct 2017 10:55:57 +0000 (+0200) Subject: SONAR-10003 add MutableEditionManagementState#clearInstallErrorMessage X-Git-Tag: 6.7-RC1~75 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=e385878da500a0f42c096c4607665ca7e8309248;p=sonarqube.git SONAR-10003 add MutableEditionManagementState#clearInstallErrorMessage --- diff --git a/server/sonar-server/src/main/java/org/sonar/server/edition/MutableEditionManagementState.java b/server/sonar-server/src/main/java/org/sonar/server/edition/MutableEditionManagementState.java index ba3235146dc..69678588805 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/edition/MutableEditionManagementState.java +++ b/server/sonar-server/src/main/java/org/sonar/server/edition/MutableEditionManagementState.java @@ -75,6 +75,12 @@ public interface MutableEditionManagementState extends EditionManagementState { */ PendingStatus installFailed(@Nullable String errorMessage); + /** + * Clears the error message set by {@link #installFailed(String)} (String)} if there is any and which ever the current + * status. + */ + void clearInstallErrorMessage(); + /** * Uninstalls the currently installed edition * diff --git a/server/sonar-server/src/main/java/org/sonar/server/edition/StandaloneEditionManagementStateImpl.java b/server/sonar-server/src/main/java/org/sonar/server/edition/StandaloneEditionManagementStateImpl.java index d9debf0e10a..25b68072782 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/edition/StandaloneEditionManagementStateImpl.java +++ b/server/sonar-server/src/main/java/org/sonar/server/edition/StandaloneEditionManagementStateImpl.java @@ -174,6 +174,15 @@ public class StandaloneEditionManagementStateImpl implements MutableEditionManag return this.pendingInstallationStatus; } + @Override + public synchronized void clearInstallErrorMessage() { + ensureStarted(); + if (this.installErrorMessage != null) { + this.installErrorMessage = null; + persistProperties(); + } + } + @Override public synchronized PendingStatus finalizeInstallation() { ensureStarted(); diff --git a/server/sonar-server/src/test/java/org/sonar/server/edition/StandaloneEditionManagementStateImplTest.java b/server/sonar-server/src/test/java/org/sonar/server/edition/StandaloneEditionManagementStateImplTest.java index 238dcb756b1..ea16c7da7e1 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/edition/StandaloneEditionManagementStateImplTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/edition/StandaloneEditionManagementStateImplTest.java @@ -1086,4 +1086,83 @@ public class StandaloneEditionManagementStateImplTest { expectedException.expectMessage("StandaloneEditionManagementStateImpl is not started"); } + @Test + public void clearInstallErrorMessage_fails_with_ISE_if_not_started() { + expectISENotStarted(); + + underTest.clearInstallErrorMessage(); + } + + @Test + public void clearInstallErrorMessage_succeeds_after_state() { + underTest.start(); + + underTest.clearInstallErrorMessage(); + + assertThat(underTest.getInstallErrorMessage()).isEmpty(); + } + + @Test + public void clearInstallErrorMessage_succeeds_after_manualInstall() { + underTest.start(); + underTest.startManualInstall(LICENSE_WITHOUT_PLUGINS); + + underTest.clearInstallErrorMessage(); + + assertThat(underTest.getInstallErrorMessage()).isEmpty(); + } + + @Test + public void clearInstallErrorMessage_succeeds_after_automaticInstall() { + underTest.start(); + underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS); + + underTest.clearInstallErrorMessage(); + + assertThat(underTest.getInstallErrorMessage()).isEmpty(); + } + + @Test + public void clearInstallErrorMessage_succeeds_after_automaticInstallReady() { + underTest.start(); + underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS); + underTest.automaticInstallReady(); + + underTest.clearInstallErrorMessage(); + + assertThat(underTest.getInstallErrorMessage()).isEmpty(); + } + + @Test + public void clearInstallErrorMessage_succeeds_after_automaticInstallFailed_and_clears_message() { + underTest.start(); + underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS); + underTest.installFailed(errorMessage); + + underTest.clearInstallErrorMessage(); + + assertThat(underTest.getInstallErrorMessage()).isEmpty(); + } + + @Test + public void clearInstallErrorMessage_succeeds_after_automaticInstallFailed_without_message() { + underTest.start(); + underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS); + underTest.installFailed(null); + + underTest.clearInstallErrorMessage(); + + assertThat(underTest.getInstallErrorMessage()).isEmpty(); + } + + @Test + public void clearInstallErrorMessage_succeeds_after_newEditionWithoutInstall() { + underTest.start(); + underTest.newEditionWithoutInstall(randomAlphanumeric(4)); + + underTest.clearInstallErrorMessage(); + + assertThat(underTest.getInstallErrorMessage()).isEmpty(); + } + }