From d0189372d6db69b38a1af4eab50ebc2ab6721b3f Mon Sep 17 00:00:00 2001 From: =?utf8?q?S=C3=A9bastien=20Lesaint?= Date: Thu, 19 Oct 2017 14:54:33 +0200 Subject: [PATCH] SONAR-10002 MutableEditionManagementState#installFailed only during install --- .../MutableEditionManagementState.java | 4 +-- .../StandaloneEditionManagementStateImpl.java | 2 +- ...ndaloneEditionManagementStateImplTest.java | 35 ++++--------------- 3 files changed, 9 insertions(+), 32 deletions(-) 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 69678588805..cd96b760a3d 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 @@ -70,8 +70,8 @@ public interface MutableEditionManagementState extends EditionManagementState { * * @return the new pending status, always {@link PendingStatus#NONE} * - * @throws IllegalStateException if current status is neither {@link PendingStatus#AUTOMATIC_IN_PROGRESS}, - * {@link PendingStatus#AUTOMATIC_READY} nor {@link PendingStatus#MANUAL_IN_PROGRESS} + * @throws IllegalStateException if current status is neither {@link PendingStatus#AUTOMATIC_IN_PROGRESS} nor + * {@link PendingStatus#MANUAL_IN_PROGRESS} */ PendingStatus installFailed(@Nullable String errorMessage); 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 475ed421c36..1b89c142ccc 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 @@ -172,7 +172,7 @@ public class StandaloneEditionManagementStateImpl implements MutableEditionManag @Override public synchronized PendingStatus installFailed(@Nullable String errorMessage) { ensureStarted(); - State newState = changeStatusToFrom(NONE, AUTOMATIC_IN_PROGRESS, AUTOMATIC_READY, MANUAL_IN_PROGRESS) + State newState = changeStatusToFrom(NONE, AUTOMATIC_IN_PROGRESS, MANUAL_IN_PROGRESS) .setInstallErrorMessage(nullableTrimmedEmptyToNull(errorMessage)) .clearPendingFields() .build(); 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 f999efc09e4..db97fb09441 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 @@ -908,7 +908,7 @@ public class StandaloneEditionManagementStateImplTest { underTest.start(); expectedException.expect(IllegalStateException.class); - expectedException.expectMessage("Can't move to NONE when status is NONE (should be any of [AUTOMATIC_IN_PROGRESS, AUTOMATIC_READY, MANUAL_IN_PROGRESS])"); + expectedException.expectMessage("Can't move to NONE when status is NONE (should be any of [AUTOMATIC_IN_PROGRESS, MANUAL_IN_PROGRESS])"); underTest.installFailed(nullableErrorMessage); } @@ -1033,40 +1033,17 @@ public class StandaloneEditionManagementStateImplTest { } @Test - public void installFailed_after_automaticInstallReady_changes_status_to_NONE_stores_non_null_error_message_and_clear_pending_fields_when_current_install_exists() { + public void installFailed_fails_with_ISE_after_automaticInstallReady() { underTest.start(); String currentEdition = "current-edition"; underTest.newEditionWithoutInstall(currentEdition); underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS); underTest.automaticInstallReady(); - String errorMessage = randomAlphanumeric(4); - - PendingStatus newStatus = underTest.installFailed(errorMessage); - - assertThat(newStatus).isEqualTo(NONE); - assertThat(underTest.getPendingInstallationStatus()).isEqualTo(NONE); - assertThat(underTest.getPendingEditionKey()).isEmpty(); - assertThat(underTest.getPendingLicense()).isEmpty(); - assertThat(underTest.getCurrentEditionKey()).contains(currentEdition); - assertThat(underTest.getInstallErrorMessage()).contains(errorMessage); - } - @Test - public void installFailed_after_automaticInstallReady_changes_status_to_NONE_without_error_message_and_clear_pending_fields_when_current_install_exists() { - underTest.start(); - String currentEdition = "current-edition"; - underTest.newEditionWithoutInstall(currentEdition); - underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS); - underTest.automaticInstallReady(); - - PendingStatus newStatus = underTest.installFailed(null); + expectedException.expect(IllegalStateException.class); + expectedException.expectMessage("Can't move to NONE when status is AUTOMATIC_READY (should be any of [AUTOMATIC_IN_PROGRESS, MANUAL_IN_PROGRESS])"); - assertThat(newStatus).isEqualTo(NONE); - assertThat(underTest.getPendingInstallationStatus()).isEqualTo(NONE); - assertThat(underTest.getPendingEditionKey()).isEmpty(); - assertThat(underTest.getPendingLicense()).isEmpty(); - assertThat(underTest.getCurrentEditionKey()).contains(currentEdition); - assertThat(underTest.getInstallErrorMessage()).isEmpty(); + underTest.installFailed(nullableErrorMessage); } @Test @@ -1076,7 +1053,7 @@ public class StandaloneEditionManagementStateImplTest { underTest.installFailed(nullableErrorMessage); expectedException.expect(IllegalStateException.class); - expectedException.expectMessage("Can't move to NONE when status is NONE (should be any of [AUTOMATIC_IN_PROGRESS, AUTOMATIC_READY, MANUAL_IN_PROGRESS])"); + expectedException.expectMessage("Can't move to NONE when status is NONE (should be any of [AUTOMATIC_IN_PROGRESS, MANUAL_IN_PROGRESS])"); underTest.installFailed(nullableErrorMessage); } -- 2.39.5