]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-6366 remove operational field from JSON response 233/head
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Mon, 4 May 2015 07:14:17 +0000 (09:14 +0200)
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Tue, 5 May 2015 07:18:54 +0000 (09:18 +0200)
remove operational field from response of /api/system/migrate_db, response from /api/system/status should be used instead

server/sonar-server/src/main/java/org/sonar/server/platform/ws/MigrateDbSystemWsAction.java
server/sonar-server/src/main/resources/org/sonar/server/platform/ws/example-migrate_db.json
server/sonar-server/src/test/java/org/sonar/server/platform/ws/MigrateDbSystemWsActionTest.java

index 0d38ef73cfbae44ff7a8ac8f8e01acad578f4959..97601e57f91d7a13c0c9540f9b2d6974de80b744 100644 (file)
@@ -28,9 +28,7 @@ import org.sonar.core.persistence.Database;
 import org.sonar.core.persistence.DatabaseVersion;
 import org.sonar.server.db.migrations.DatabaseMigration;
 
-import static org.sonar.server.db.migrations.DatabaseMigration.Status.NONE;
 import static org.sonar.server.db.migrations.DatabaseMigration.Status.RUNNING;
-import static org.sonar.server.db.migrations.DatabaseMigration.Status.SUCCEEDED;
 
 /**
  * Implementation of the {@code migrate_db} action for the System WebService.
@@ -43,12 +41,16 @@ public class MigrateDbSystemWsAction implements SystemWsAction {
   private static final String MESSAGE_STATUS_SUCCEEDED = "Migration succeeded.";
   private static final String MESSAGE_STATUS_FAILED = "Migration failed: %s.<br/> Please check logs.";
 
-  private static final String STATUS_NOT_SUPPORTED = "NOT_SUPPORTED";
   private static final String STATUS_NO_MIGRATION = "NO_MIGRATION";
+  private static final String STATUS_NOT_SUPPORTED = "NOT_SUPPORTED";
   private static final String STATUS_MIGRATION_RUNNING = "MIGRATION_RUNNING";
   private static final String STATUS_MIGRATION_FAILED = "MIGRATION_FAILED";
   private static final String STATUS_MIGRATION_SUCCEEDED = "MIGRATION_SUCCEEDED";
 
+  private static final String PROPERTY_STATE = "state";
+  private static final String PROPERTY_MESSAGE = "message";
+  private static final String PROPERTY_STARTED_AT = "startedAt";
+
   private final DatabaseVersion databaseVersion;
   private final DatabaseMigration databaseMigration;
   private final Database database;
@@ -115,9 +117,8 @@ public class MigrateDbSystemWsAction implements SystemWsAction {
   private void writeNotSupportedResponse(Response response) {
     JsonWriter jsonWriter = response.newJsonWriter();
     jsonWriter.beginObject()
-      .prop("operational", false)
-      .prop("state", STATUS_NOT_SUPPORTED)
-      .prop("message", "Upgrade is not supported on embedded database.")
+      .prop(PROPERTY_STATE, STATUS_NOT_SUPPORTED)
+      .prop(PROPERTY_MESSAGE, "Upgrade is not supported on embedded database.")
       .endObject();
     jsonWriter.close();
   }
@@ -125,10 +126,9 @@ public class MigrateDbSystemWsAction implements SystemWsAction {
   private void writeNoneResponse(Response response, DatabaseMigration databaseMigration) {
     JsonWriter jsonWriter = response.newJsonWriter();
     jsonWriter.beginObject()
-        .prop("operational", false)
-        .prop("state", statusToJson(RUNNING))
-        .prop("message", MESSAGE_STATUS_RUNNING)
-        .propDateTime("startedAt", databaseMigration.startedAt())
+        .prop(PROPERTY_STATE, statusToJson(RUNNING))
+        .prop(PROPERTY_MESSAGE, MESSAGE_STATUS_RUNNING)
+        .propDateTime(PROPERTY_STARTED_AT, databaseMigration.startedAt())
         .endObject();
     jsonWriter.close();
   }
@@ -136,10 +136,9 @@ public class MigrateDbSystemWsAction implements SystemWsAction {
   private void writeResponse(Response response, DatabaseMigration databaseMigration) {
     JsonWriter jsonWriter = response.newJsonWriter();
     jsonWriter.beginObject()
-      .prop("operational", isOperational(databaseMigration))
-      .prop("state", statusToJson(databaseMigration.status()))
-      .prop("message", buildMessage(databaseMigration))
-      .propDateTime("startedAt", databaseMigration.startedAt())
+      .prop(PROPERTY_STATE, statusToJson(databaseMigration.status()))
+      .prop(PROPERTY_MESSAGE, buildMessage(databaseMigration))
+      .propDateTime(PROPERTY_STARTED_AT, databaseMigration.startedAt())
       .endObject();
     jsonWriter.close();
   }
@@ -160,10 +159,6 @@ public class MigrateDbSystemWsAction implements SystemWsAction {
     }
   }
 
-  private static boolean isOperational(DatabaseMigration databaseMigration) {
-    return databaseMigration.status() == NONE || databaseMigration.status() == SUCCEEDED;
-  }
-
   private static String buildMessage(DatabaseMigration databaseMigration) {
     switch (databaseMigration.status()) {
       case NONE:
index 947e9a4d55b109b4c77b532050310d9807d20843..dd137d7cd21d24d881f7693d8a39949483df2e32 100644 (file)
@@ -1,5 +1,4 @@
 {
-  "operational": false,
   "state": "MIGRATION_RUNNING",
   "message": "Database migration is running.",
   "startedAt": "2015-02-23T18:54:23+0100"
index 051a555bb1fb6bc416f0370c65197cefac122ce1..e009211abf86da39282536799c5933d8cb14151a 100644 (file)
@@ -103,7 +103,7 @@ public class MigrateDbSystemWsActionTest {
 
     underTest.handle(request, response);
 
-    assertJson(response.outputAsString()).isSimilarTo(expectedResponse(true, STATUS_NONE, UPTODATE_MSG));
+    assertJson(response.outputAsString()).isSimilarTo(expectedResponse(STATUS_NONE, UPTODATE_MSG));
   }
 
   // this test will raise a IllegalArgumentException when an unsupported value is added to the Status enum
@@ -118,27 +118,27 @@ public class MigrateDbSystemWsActionTest {
   }
 
   @Test
-  public void msg_is_operational_and_state_from_databasemigration_when_databaseversion_greater_than_currentversion() throws Exception {
+  public void state_from_databasemigration_when_databaseversion_greater_than_currentversion() throws Exception {
     when(databaseVersion.getVersion()).thenReturn(NEWER_VERSION);
     when(databaseMigration.status()).thenReturn(NONE);
 
     underTest.handle(request, response);
 
-    assertJson(response.outputAsString()).isSimilarTo(expectedResponse(true, STATUS_NONE, UPTODATE_MSG));
+    assertJson(response.outputAsString()).isSimilarTo(expectedResponse(STATUS_NONE, UPTODATE_MSG));
   }
 
   @Test
-  public void msg_is_not_operational_and_state_is_NONE_with_specific_msg_when_version_is_less_than_current_version_and_dialect_does_not_support_migration() throws Exception {
+  public void state_is_NONE_with_specific_msg_when_version_is_less_than_current_version_and_dialect_does_not_support_migration() throws Exception {
     when(databaseVersion.getVersion()).thenReturn(OLD_VERSION);
     when(dialect.supportsMigration()).thenReturn(false);
 
     underTest.handle(request, response);
 
-    assertJson(response.outputAsString()).isSimilarTo(expectedResponse(false, STATUS_NOT_SUPPORTED, MIG_NOT_SUPPORTED_MSG));
+    assertJson(response.outputAsString()).isSimilarTo(expectedResponse(STATUS_NOT_SUPPORTED, MIG_NOT_SUPPORTED_MSG));
   }
 
   @Test
-  public void msg_is_not_operational_and_state_from_databasemigration_when_dbmigration_status_is_RUNNING() throws Exception {
+  public void state_from_databasemigration_when_dbmigration_status_is_RUNNING() throws Exception {
     when(databaseVersion.getVersion()).thenReturn(OLD_VERSION);
     when(dialect.supportsMigration()).thenReturn(true);
     when(databaseMigration.status()).thenReturn(RUNNING);
@@ -146,11 +146,11 @@ public class MigrateDbSystemWsActionTest {
 
     underTest.handle(request, response);
 
-    assertJson(response.outputAsString()).isSimilarTo(expectedResponse(false, STATUS_RUNNING, RUNNING_MSG, SOME_DATE));
+    assertJson(response.outputAsString()).isSimilarTo(expectedResponse(STATUS_RUNNING, RUNNING_MSG, SOME_DATE));
   }
 
   @Test
-  public void msg_is_not_operational_and_state_from_databasemigration_and_msg_includes_error_when_dbmigration_status_is_FAILED() throws Exception {
+  public void state_from_databasemigration_and_msg_includes_error_when_dbmigration_status_is_FAILED() throws Exception {
     when(databaseVersion.getVersion()).thenReturn(OLD_VERSION);
     when(dialect.supportsMigration()).thenReturn(true);
     when(databaseMigration.status()).thenReturn(FAILED);
@@ -159,11 +159,11 @@ public class MigrateDbSystemWsActionTest {
 
     underTest.handle(request, response);
 
-    assertJson(response.outputAsString()).isSimilarTo(expectedResponse(false, STATUS_FAILED, failedMsg(SOME_THROWABLE_MSG), SOME_DATE));
+    assertJson(response.outputAsString()).isSimilarTo(expectedResponse(STATUS_FAILED, failedMsg(SOME_THROWABLE_MSG), SOME_DATE));
   }
 
   @Test
-  public void msg_is_not_operational_and_state_from_databasemigration_and_msg_has_default_msg_when_dbmigration_status_is_FAILED() throws Exception {
+  public void state_from_databasemigration_and_msg_has_default_msg_when_dbmigration_status_is_FAILED() throws Exception {
     when(databaseVersion.getVersion()).thenReturn(OLD_VERSION);
     when(dialect.supportsMigration()).thenReturn(true);
     when(databaseMigration.status()).thenReturn(FAILED);
@@ -172,11 +172,11 @@ public class MigrateDbSystemWsActionTest {
 
     underTest.handle(request, response);
 
-    assertJson(response.outputAsString()).isSimilarTo(expectedResponse(false, STATUS_FAILED, failedMsg(DEFAULT_ERROR_MSG), SOME_DATE));
+    assertJson(response.outputAsString()).isSimilarTo(expectedResponse(STATUS_FAILED, failedMsg(DEFAULT_ERROR_MSG), SOME_DATE));
   }
 
   @Test
-  public void msg_is_operational_and_state_from_databasemigration_and_msg_has_default_msg_when_dbmigration_status_is_FAILED() throws Exception {
+  public void state_from_databasemigration_and_msg_has_default_msg_when_dbmigration_status_is_SUCCEEDED() throws Exception {
     when(databaseVersion.getVersion()).thenReturn(OLD_VERSION);
     when(dialect.supportsMigration()).thenReturn(true);
     when(databaseMigration.status()).thenReturn(SUCCEEDED);
@@ -184,11 +184,11 @@ public class MigrateDbSystemWsActionTest {
 
     underTest.handle(request, response);
 
-    assertJson(response.outputAsString()).isSimilarTo(expectedResponse(true, STATUS_SUCCEEDED, MIG_SUCCESS_MSG, SOME_DATE));
+    assertJson(response.outputAsString()).isSimilarTo(expectedResponse(STATUS_SUCCEEDED, MIG_SUCCESS_MSG, SOME_DATE));
   }
 
   @Test
-  public void start_migration_and_return_msg_is_not_operational_and_state_from_databasemigration_when_dbmigration_status_is_NONE() throws Exception {
+  public void start_migration_and_return_state_from_databasemigration_when_dbmigration_status_is_NONE() throws Exception {
     when(databaseVersion.getVersion()).thenReturn(OLD_VERSION);
     when(dialect.supportsMigration()).thenReturn(true);
     when(databaseMigration.status()).thenReturn(NONE);
@@ -197,24 +197,22 @@ public class MigrateDbSystemWsActionTest {
     underTest.handle(request, response);
 
     verify(databaseMigration).startIt();
-    assertJson(response.outputAsString()).isSimilarTo(expectedResponse(false, STATUS_RUNNING, RUNNING_MSG, SOME_DATE));
+    assertJson(response.outputAsString()).isSimilarTo(expectedResponse(STATUS_RUNNING, RUNNING_MSG, SOME_DATE));
   }
 
   private static String failedMsg(@Nullable String t) {
     return "Migration failed: " + t + ".<br/> Please check logs.";
   }
 
-  private static String expectedResponse(boolean operational, String status, String msg) {
+  private static String expectedResponse(String status, String msg) {
     return "{" +
-      "\"operational\":" + operational + "," +
       "\"state\":\"" + status + "\"," +
       "\"message\":\"" + msg + "\"" +
       "}";
   }
 
-  private static String expectedResponse(boolean operational, String status, String msg, Date date) {
+  private static String expectedResponse(String status, String msg, Date date) {
     return "{" +
-      "\"operational\":" + operational + "," +
       "\"state\":\"" + status + "\"," +
       "\"message\":\"" + msg + "\"," +
       "\"startedAt\":\"" + DateUtils.formatDateTime(date) + "\"" +