aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>2017-10-18 16:20:08 +0200
committerGrégoire Aubert <gregoire.aubert@sonarsource.com>2017-10-23 08:01:13 -0700
commitb7a7173803bf2329dceba52b11c04bad416def33 (patch)
tree4e302ca31831a5ed6cef4d21d55306c187ffb1bb /server
parent7632e64b35479702b0026506267d27ef06f20353 (diff)
downloadsonarqube-b7a7173803bf2329dceba52b11c04bad416def33.tar.gz
sonarqube-b7a7173803bf2329dceba52b11c04bad416def33.zip
SONAR-10002 install error in api/editions/apply_license response
Diffstat (limited to 'server')
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/edition/ws/ApplyLicenseAction.java7
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/edition/ws/ApplyLicenseActionTest.java30
2 files changed, 29 insertions, 8 deletions
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 8fc65d10ff9..a4e6239b5ae 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
@@ -99,10 +99,11 @@ public class ApplyLicenseAction implements EditionsWsAction {
}
private WsEditions.StatusResponse buildResponse() {
- return WsEditions.StatusResponse.newBuilder()
+ WsEditions.StatusResponse.Builder builder = WsEditions.StatusResponse.newBuilder()
.setNextEditionKey(editionManagementState.getPendingEditionKey().orElse(""))
.setCurrentEditionKey(editionManagementState.getCurrentEditionKey().orElse(""))
- .setInstallationStatus(WsEditions.InstallationStatus.valueOf(editionManagementState.getPendingInstallationStatus().name()))
- .build();
+ .setInstallationStatus(WsEditions.InstallationStatus.valueOf(editionManagementState.getPendingInstallationStatus().name()));
+ editionManagementState.getInstallErrorMessage().ifPresent(builder::setInstallError);
+ return builder.build();
}
}
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 5ec1227ae58..9c480103613 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
@@ -29,6 +29,7 @@ import java.util.Arrays;
import java.util.Base64;
import java.util.Optional;
import java.util.Properties;
+import javax.annotation.Nullable;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
@@ -159,7 +160,7 @@ public class ApplyLicenseActionTest {
@Test
public void verify_example() throws IOException {
userSessionRule.logIn().setSystemAdministrator();
- setPendingLicense(AUTOMATIC_IN_PROGRESS);
+ setPendingLicense(AUTOMATIC_IN_PROGRESS, null);
TestRequest request = actionTester.newRequest()
.setParam(PARAM_LICENSE, createLicenseParam("dev", "plugin1"));
@@ -170,7 +171,7 @@ public class ApplyLicenseActionTest {
@Test
public void apply_without_need_to_install() throws IOException {
userSessionRule.logIn().setSystemAdministrator();
- setPendingLicense(NONE);
+ setPendingLicense(NONE, null);
when(editionInstaller.requiresInstallationChange(singleton("plugin1"))).thenReturn(false);
TestRequest request = actionTester.newRequest()
@@ -185,7 +186,7 @@ public class ApplyLicenseActionTest {
@Test
public void apply_offline() throws IOException {
userSessionRule.logIn().setSystemAdministrator();
- setPendingLicense(PendingStatus.MANUAL_IN_PROGRESS);
+ setPendingLicense(PendingStatus.MANUAL_IN_PROGRESS, null);
when(editionInstaller.requiresInstallationChange(singleton("plugin1"))).thenReturn(true);
TestRequest request = actionTester.newRequest()
@@ -202,7 +203,7 @@ public class ApplyLicenseActionTest {
@Test
public void apply_successfully_auto_installation() throws IOException {
userSessionRule.logIn().setSystemAdministrator();
- setPendingLicense(PendingStatus.AUTOMATIC_IN_PROGRESS);
+ setPendingLicense(PendingStatus.AUTOMATIC_IN_PROGRESS, null);
when(editionInstaller.requiresInstallationChange(singleton("plugin1"))).thenReturn(true);
TestRequest request = actionTester.newRequest()
@@ -216,6 +217,24 @@ public class ApplyLicenseActionTest {
verify(mutableEditionManagementState, times(0)).startManualInstall(any(License.class));
}
+ @Test
+ public void returns_auto_install_fails_instantly() throws IOException {
+ userSessionRule.logIn().setSystemAdministrator();
+ String errorMessage = "error! an error!";
+ setPendingLicense(PendingStatus.NONE, errorMessage);
+ when(editionInstaller.requiresInstallationChange(singleton("plugin1"))).thenReturn(true);
+ when(mutableEditionManagementState.getInstallErrorMessage()).thenReturn(Optional.of(errorMessage));
+
+ TestRequest request = actionTester.newRequest()
+ .setMediaType(MediaTypes.PROTOBUF)
+ .setParam(PARAM_LICENSE, createLicenseParam(PENDING_EDITION_NAME, "plugin1"));
+
+ TestResponse response = request.execute();
+
+ StatusResponse parsedResponse = WsEditions.StatusResponse.parseFrom(response.getInputStream());
+ assertThat(parsedResponse.getInstallError()).isEqualTo(errorMessage);
+ }
+
private void assertResponse(TestResponse response, String expectedNextEditionKey, String expectedEditionKey,
PendingStatus expectedPendingStatus) throws IOException {
StatusResponse parsedResponse = WsEditions.StatusResponse.parseFrom(response.getInputStream());
@@ -224,12 +243,13 @@ public class ApplyLicenseActionTest {
assertThat(parsedResponse.getInstallationStatus()).isEqualTo(WsEditions.InstallationStatus.valueOf(expectedPendingStatus.toString()));
}
- private void setPendingLicense(PendingStatus pendingStatus) {
+ private void setPendingLicense(PendingStatus pendingStatus, @Nullable String errorMessage) {
when(mutableEditionManagementState.getCurrentEditionKey()).thenReturn(Optional.empty());
when(mutableEditionManagementState.getPendingEditionKey()).thenReturn(Optional.of(PENDING_EDITION_NAME));
when(mutableEditionManagementState.getPendingInstallationStatus())
.thenReturn(NONE)
.thenReturn(pendingStatus);
+ when(mutableEditionManagementState.getInstallErrorMessage()).thenReturn(Optional.ofNullable(errorMessage));
}
private static String createLicenseParam(String editionKey, String... pluginKeys) throws IOException {