]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-10002 add install error to response of api/editions/status
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Wed, 18 Oct 2017 12:38:12 +0000 (14:38 +0200)
committerGrégoire Aubert <gregoire.aubert@sonarsource.com>
Mon, 23 Oct 2017 15:01:13 +0000 (08:01 -0700)
server/sonar-server/src/main/java/org/sonar/server/edition/ws/StatusAction.java
server/sonar-server/src/test/java/org/sonar/server/edition/ws/StatusActionTest.java
sonar-ws/src/main/protobuf/ws-editions.proto

index 4c93a2e2caca7f5fefacdf32a2b562a03fe21697..604d964c7dcf3b48513ebb633b532dff59e5ea7d 100644 (file)
@@ -56,6 +56,7 @@ public class StatusAction implements EditionsWsAction {
       .setCurrentEditionKey(editionManagementState.getCurrentEditionKey().orElse(""))
       .setNextEditionKey(editionManagementState.getPendingEditionKey().orElse(""))
       .setInstallationStatus(WsEditions.InstallationStatus.valueOf(editionManagementState.getPendingInstallationStatus().name()));
+    editionManagementState.getInstallErrorMessage().ifPresent(responseBuilder::setInstallError);
 
     WsUtils.writeProtobuf(responseBuilder.build(), request, response);
   }
index e37a88ffa126930e52009d86f87893df4b4aab5d..6b94b8a796a539ea6eb67ac6ddc16d0f3e7ba67f 100644 (file)
@@ -19,7 +19,6 @@
  */
 package org.sonar.server.edition.ws;
 
-import java.util.Optional;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
@@ -32,9 +31,12 @@ import org.sonar.server.ws.TestRequest;
 import org.sonar.server.ws.WsActionTester;
 import org.sonar.test.JsonAssert;
 
+import static java.util.Optional.empty;
+import static java.util.Optional.of;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
+import static org.sonar.server.edition.EditionManagementState.PendingStatus.NONE;
 
 public class StatusActionTest {
   @Rule
@@ -81,9 +83,10 @@ public class StatusActionTest {
   @Test
   public void verify_example() {
     userSessionRule.logIn().setSystemAdministrator();
-    when(editionManagementState.getCurrentEditionKey()).thenReturn(Optional.empty());
-    when(editionManagementState.getPendingEditionKey()).thenReturn(Optional.of("developer-edition"));
+    when(editionManagementState.getCurrentEditionKey()).thenReturn(empty());
+    when(editionManagementState.getPendingEditionKey()).thenReturn(of("developer-edition"));
     when(editionManagementState.getPendingInstallationStatus()).thenReturn(EditionManagementState.PendingStatus.AUTOMATIC_READY);
+    when(editionManagementState.getInstallErrorMessage()).thenReturn(empty());
 
     TestRequest request = actionTester.newRequest();
 
@@ -93,9 +96,10 @@ public class StatusActionTest {
   @Test
   public void response_contains_optional_fields_as_empty_string() {
     userSessionRule.logIn().setSystemAdministrator();
-    when(editionManagementState.getCurrentEditionKey()).thenReturn(Optional.empty());
-    when(editionManagementState.getPendingEditionKey()).thenReturn(Optional.empty());
-    when(editionManagementState.getPendingInstallationStatus()).thenReturn(EditionManagementState.PendingStatus.NONE);
+    when(editionManagementState.getCurrentEditionKey()).thenReturn(empty());
+    when(editionManagementState.getPendingEditionKey()).thenReturn(empty());
+    when(editionManagementState.getPendingInstallationStatus()).thenReturn(NONE);
+    when(editionManagementState.getInstallErrorMessage()).thenReturn(empty());
 
     TestRequest request = actionTester.newRequest();
 
@@ -106,4 +110,23 @@ public class StatusActionTest {
         "  \"nextEditionKey\": \"\"" +
         "}");
   }
+
+  @Test
+  public void response_contains_automaticInstallError_when_present() {
+    userSessionRule.logIn().setSystemAdministrator();
+    when(editionManagementState.getCurrentEditionKey()).thenReturn(empty());
+    when(editionManagementState.getPendingEditionKey()).thenReturn(empty());
+    when(editionManagementState.getPendingInstallationStatus()).thenReturn(NONE);
+    String errorMessage = "an error! oh god, an error!";
+    when(editionManagementState.getInstallErrorMessage()).thenReturn(of(errorMessage));
+    TestRequest request = actionTester.newRequest();
+
+    JsonAssert.assertJson(request.execute().getInput())
+      .isSimilarTo("{" +
+        "  \"currentEditionKey\": \"\"," +
+        "  \"installationStatus\": \"NONE\"," +
+        "  \"nextEditionKey\": \"\"," +
+        "  \"installError\": \"" + errorMessage + "\"" +
+        "}");
+  }
 }
index 32503be43611c00af91daf7335b60c58f2720bc7..e916bf393571746990bf6550052ca951f3b85050 100644 (file)
@@ -30,6 +30,7 @@ message StatusResponse {
   optional string currentEditionKey = 1;
   optional InstallationStatus installationStatus = 2;
   optional string nextEditionKey = 3;
+  optional string installError = 4;
 }
 
 enum InstallationStatus {