From 20aa9f04b4c635d68fd40ea4247eeb9719eecf34 Mon Sep 17 00:00:00 2001 From: =?utf8?q?S=C3=A9bastien=20Lesaint?= Date: Mon, 16 Oct 2017 17:50:28 +0200 Subject: [PATCH] SONAR-9940 update mock to commit license when no change required in api/editions/apply_licence --- .../server/edition/ws/ApplyLicenseAction.java | 17 +++++++++++++++++ .../edition/ws/ApplyLicenseActionTest.java | 4 +++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/server/sonar-server/src/main/java/org/sonar/server/edition/ws/ApplyLicenseAction.java b/server/sonar-server/src/main/java/org/sonar/server/edition/ws/ApplyLicenseAction.java index da7bb813090..0d5c3b831ad 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/edition/ws/ApplyLicenseAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/edition/ws/ApplyLicenseAction.java @@ -20,6 +20,8 @@ package org.sonar.server.edition.ws; import java.util.Collections; +import javax.annotation.CheckForNull; +import javax.annotation.Nullable; import org.sonar.api.server.ws.Request; import org.sonar.api.server.ws.Response; import org.sonar.api.server.ws.WebService; @@ -27,19 +29,30 @@ import org.sonar.server.edition.EditionManagementState; import org.sonar.server.edition.License; import org.sonar.server.edition.MutableEditionManagementState; import org.sonar.server.exceptions.BadRequestException; +import org.sonar.server.license.LicenseCommit; import org.sonar.server.user.UserSession; import org.sonar.server.ws.WsUtils; import org.sonarqube.ws.WsEditions; +import static com.google.common.base.Preconditions.checkState; + public class ApplyLicenseAction implements EditionsWsAction { private static final String PARAM_LICENSE = "license"; private final UserSession userSession; private final MutableEditionManagementState editionManagementState; + @CheckForNull + private final LicenseCommit licenseCommit; public ApplyLicenseAction(UserSession userSession, MutableEditionManagementState editionManagementState) { + this(userSession, editionManagementState, null); + } + + public ApplyLicenseAction(UserSession userSession, MutableEditionManagementState editionManagementState, + @Nullable LicenseCommit licenseCommit) { this.userSession = userSession; this.editionManagementState = editionManagementState; + this.licenseCommit = licenseCommit; } @Override @@ -70,6 +83,10 @@ public class ApplyLicenseAction implements EditionsWsAction { if (license.contains("manual")) { editionManagementState.startManualInstall(newLicense); } else if (license.contains("done")) { + checkState(licenseCommit != null, + "Can't decide edition does not require install if LicenseCommit instance is null. " + + "License-manager plugin should be installed."); + licenseCommit.update(newLicense.getContent()); editionManagementState.newEditionWithoutInstall(newLicense.getEditionKey()); } else { editionManagementState.startAutomaticInstall(newLicense); diff --git a/server/sonar-server/src/test/java/org/sonar/server/edition/ws/ApplyLicenseActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/edition/ws/ApplyLicenseActionTest.java index 4cd01c677ac..f12b5fc7753 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/edition/ws/ApplyLicenseActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/edition/ws/ApplyLicenseActionTest.java @@ -34,6 +34,7 @@ import org.sonar.server.edition.MutableEditionManagementState; import org.sonar.server.exceptions.BadRequestException; import org.sonar.server.exceptions.ForbiddenException; import org.sonar.server.exceptions.UnauthorizedException; +import org.sonar.server.license.LicenseCommit; import org.sonar.server.tester.UserSessionRule; import org.sonar.server.ws.TestRequest; import org.sonar.server.ws.WsActionTester; @@ -55,7 +56,8 @@ public class ApplyLicenseActionTest { public UserSessionRule userSessionRule = UserSessionRule.standalone(); private MutableEditionManagementState mutableEditionManagementState = mock(MutableEditionManagementState.class); - private ApplyLicenseAction underTest = new ApplyLicenseAction(userSessionRule, mutableEditionManagementState); + private LicenseCommit licenseCommit = mock(LicenseCommit.class); + private ApplyLicenseAction underTest = new ApplyLicenseAction(userSessionRule, mutableEditionManagementState, licenseCommit); private WsActionTester actionTester = new WsActionTester(underTest); @Test -- 2.39.5