]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-7759 Add checks on urls availability before and after upgrade
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Tue, 28 Jun 2016 09:02:44 +0000 (11:02 +0200)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Wed, 29 Jun 2016 06:44:00 +0000 (08:44 +0200)
tests/upgrade/pom.xml
tests/upgrade/src/test/java/org/sonarsource/sonarqube/upgrade/UpgradeTest.java

index b9746c94fd135fe9e8a092eea6a2b505e3c5b504..908f167c573241519c7211d54b2996a70639d2d1 100644 (file)
       <version>5.1</version>
       <scope>test</scope>
     </dependency>
+    <dependency>
+      <groupId>${project.groupId}</groupId>
+      <artifactId>sonar-ws</artifactId>
+      <version>${project.version}</version>
+      <scope>test</scope>
+    </dependency>
     <dependency>
       <groupId>${project.groupId}</groupId>
       <artifactId>sonar-application</artifactId>
index 08094969c2b1be66906d625986038a11ab293d9c..88eb5e55a1b50e62dd8a630837d06c6c5e91d8f5 100644 (file)
@@ -25,6 +25,7 @@ import com.sonar.orchestrator.Orchestrator;
 import com.sonar.orchestrator.OrchestratorBuilder;
 import com.sonar.orchestrator.build.MavenBuild;
 import com.sonar.orchestrator.config.Configuration;
+import com.sonar.orchestrator.container.Server;
 import com.sonar.orchestrator.locator.FileLocation;
 import com.sonar.orchestrator.version.Version;
 import java.io.File;
@@ -35,6 +36,11 @@ import org.apache.commons.io.IOUtils;
 import org.junit.After;
 import org.junit.Test;
 import org.sonar.wsclient.services.ResourceQuery;
+import org.sonarqube.ws.client.GetRequest;
+import org.sonarqube.ws.client.HttpConnector;
+import org.sonarqube.ws.client.WsClient;
+import org.sonarqube.ws.client.WsClientFactories;
+import org.sonarqube.ws.client.WsResponse;
 
 public class UpgradeTest {
 
@@ -70,8 +76,11 @@ public class UpgradeTest {
     // latest version
     startServer(Version.create(Orchestrator.builderEnv().getSonarVersion()), true);
     checkSystemStatus(ServerStatusResponse.Status.DB_MIGRATION_NEEDED);
+    checkUrlsBeforeUpgrade();
+
     upgradeDatabase();
     checkSystemStatus(ServerStatusResponse.Status.UP);
+    checkUrlsAfterUpgrade();
 
     assertThat(countFiles(PROJECT_KEY)).isEqualTo(files);
     scanProject();
@@ -85,6 +94,38 @@ public class UpgradeTest {
     assertThat(serverStatusResponse.getStatus()).isEqualTo(serverStatus);
   }
 
+  private void checkUrlsBeforeUpgrade() {
+    // These urls should be available when system requires a migration
+    checkUrlIsReturningOk("/api/system/status");
+    checkUrlIsReturningOk("/api/system/db_migration_status");
+    checkUrlIsReturningOk("/api/webservices/list");
+
+    // These urls should not be available when system requires a migration
+    checkUrlIsReturningNotFound("/api/issues/search?projectKeys=org.apache.struts%3Astruts-core");
+    checkUrlIsReturningNotFound("/api/components/tree?baseComponentKey=org.apache.struts%3Astruts-core");
+    checkUrlIsReturningNotFound("/api/measures/component_tree?baseComponentKey=org.apache.struts%3Astruts-core&metricKeys=ncloc,files,violations");
+    checkUrlIsReturningNotFound("/api/qualityprofiles/search");
+
+    // These page should all redirect to maintenance page
+    checkUrlIsRedirectedToMaintenancePage("/");
+    checkUrlIsRedirectedToMaintenancePage("/issues/index");
+    checkUrlIsRedirectedToMaintenancePage("/dashboard/index/org.apache.struts:struts-parent");
+    checkUrlIsRedirectedToMaintenancePage("/issues/search");
+    checkUrlIsRedirectedToMaintenancePage("/component/index?id=org.apache.struts%3Astruts-core%3Asrc%2Fmain%2Fjava%2Forg%2Fapache%2Fstruts%2Fchain%2Fcommands%2Fgeneric%2FWrappingLookupCommand.java");
+    checkUrlIsRedirectedToMaintenancePage("/profiles");
+  }
+
+  private void checkUrlsAfterUpgrade() {
+    checkUrlIsReturningOk("/api/system/status");
+    checkUrlIsReturningOk("/api/system/db_migration_status");
+    checkUrlIsReturningOk("/api/webservices/list");
+
+    checkUrlIsReturningOk("/api/issues/search?projectKeys=org.apache.struts%3Astruts-core");
+    checkUrlIsReturningOk("/api/components/tree?baseComponentKey=org.apache.struts%3Astruts-core");
+    checkUrlIsReturningOk("/api/measures/component_tree?baseComponentKey=org.apache.struts%3Astruts-core&metricKeys=ncloc,files,violations");
+    checkUrlIsReturningOk("/api/qualityprofiles/search");
+  }
+
   private void browseWebapp() {
     testUrl("/");
     testUrl("/api/issues/search?projectKeys=org.apache.struts%3Astruts-core");
@@ -161,4 +202,25 @@ public class UpgradeTest {
       }
     }
   }
+
+  private void checkUrlIsReturningOk(String url) {
+    newWsClient(orchestrator).wsConnector().call(new GetRequest(url)).failIfNotSuccessful();
+  }
+
+  private void checkUrlIsReturningNotFound(String url) {
+    WsResponse response = newWsClient(orchestrator).wsConnector().call(new GetRequest(url));
+    assertThat(response.code()).isEqualTo(HttpURLConnection.HTTP_NOT_FOUND);
+  }
+
+  private void checkUrlIsRedirectedToMaintenancePage(String url) {
+    WsResponse response = newWsClient(orchestrator).wsConnector().call(new GetRequest(url)).failIfNotSuccessful();
+    assertThat(response.requestUrl()).contains("/maintenance");
+  }
+
+  private static WsClient newWsClient(Orchestrator orchestrator) {
+    Server server = orchestrator.getServer();
+    return WsClientFactories.getDefault().newClient(HttpConnector.newBuilder()
+      .url(server.getUrl())
+      .build());
+  }
 }