From 649fa6f74e2bcf36e98ceba4758ac5736ee20569 Mon Sep 17 00:00:00 2001 From: Duarte Meneses Date: Thu, 19 Oct 2017 15:06:38 +0200 Subject: [PATCH] SONAR-9996 Minor improvements uninstall of edition --- .../org/sonar/server/edition/ws/UninstallAction.java | 10 ++++++---- .../sonar/server/edition/ws/UninstallActionTest.java | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/server/sonar-server/src/main/java/org/sonar/server/edition/ws/UninstallAction.java b/server/sonar-server/src/main/java/org/sonar/server/edition/ws/UninstallAction.java index 67c1d269616..64df2f3229a 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/edition/ws/UninstallAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/edition/ws/UninstallAction.java @@ -22,12 +22,15 @@ package org.sonar.server.edition.ws; import org.sonar.api.server.ws.Request; import org.sonar.api.server.ws.Response; import org.sonar.api.server.ws.WebService; -import org.sonar.server.edition.EditionManagementState; +import org.sonar.server.edition.EditionManagementState.PendingStatus; import org.sonar.server.edition.MutableEditionManagementState; import org.sonar.server.exceptions.BadRequestException; import org.sonar.server.plugins.edition.EditionInstaller; import org.sonar.server.user.UserSession; +import static org.sonar.server.edition.EditionManagementState.PendingStatus.NONE; +import static org.sonar.server.edition.EditionManagementState.PendingStatus.UNINSTALL_IN_PROGRESS; + public class UninstallAction implements EditionsWsAction { private final UserSession userSession; private final MutableEditionManagementState mutableEditionManagementState; @@ -51,9 +54,8 @@ public class UninstallAction implements EditionsWsAction { @Override public void handle(Request request, Response response) throws Exception { userSession.checkLoggedIn().checkIsSystemAdministrator(); - - if (mutableEditionManagementState.getPendingInstallationStatus() != EditionManagementState.PendingStatus.NONE - && mutableEditionManagementState.getPendingInstallationStatus() != EditionManagementState.PendingStatus.UNINSTALL_IN_PROGRESS) { + PendingStatus status = mutableEditionManagementState.getPendingInstallationStatus(); + if (status != NONE && status != UNINSTALL_IN_PROGRESS) { throw BadRequestException.create("Uninstall of the current edition is not allowed when install of an edition is in progress"); } diff --git a/server/sonar-server/src/test/java/org/sonar/server/edition/ws/UninstallActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/edition/ws/UninstallActionTest.java index aecb77356d4..4c7a0008873 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/edition/ws/UninstallActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/edition/ws/UninstallActionTest.java @@ -95,7 +95,7 @@ public class UninstallActionTest { @Test @UseDataProvider("notNoneOrUninstallStatuses") - public void request_fails_if_current_status_is_not_none(EditionManagementState.PendingStatus notNoneOrUninstall) { + public void request_fails_if_current_status_is_not_none_nor_uninstall(EditionManagementState.PendingStatus notNoneOrUninstall) { userSessionRule.logIn().setSystemAdministrator(); when(mutableEditionManagementState.getPendingInstallationStatus()).thenReturn(notNoneOrUninstall); -- 2.39.5