From e385878da500a0f42c096c4607665ca7e8309248 Mon Sep 17 00:00:00 2001 From: =?utf8?q?S=C3=A9bastien=20Lesaint?= Date: Wed, 18 Oct 2017 12:55:57 +0200 Subject: [PATCH] SONAR-10003 add MutableEditionManagementState#clearInstallErrorMessage --- .../MutableEditionManagementState.java | 6 ++ .../StandaloneEditionManagementStateImpl.java | 9 +++ ...ndaloneEditionManagementStateImplTest.java | 79 +++++++++++++++++++ 3 files changed, 94 insertions(+) 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(); + } + } -- 2.39.5