]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-9940 update mock to commit license when no change required
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Mon, 16 Oct 2017 15:50:28 +0000 (17:50 +0200)
committerGrégoire Aubert <gregoire.aubert@sonarsource.com>
Mon, 23 Oct 2017 15:01:13 +0000 (08:01 -0700)
in api/editions/apply_licence

server/sonar-server/src/main/java/org/sonar/server/edition/ws/ApplyLicenseAction.java
server/sonar-server/src/test/java/org/sonar/server/edition/ws/ApplyLicenseActionTest.java

index da7bb813090fc2c4fdec0a9319d2f5de8e4a5236..0d5c3b831ad63997a7db43ad1f712d4b61ebba1b 100644 (file)
@@ -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);
index 4cd01c677acbbf959371d4007ab3d66c91a757df..f12b5fc7753b2de43e22f8d58ac808c176415539 100644 (file)
@@ -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