]> source.dussan.org Git - sonarqube.git/commitdiff
Add category qualityGate to integration tests
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Sat, 11 Nov 2017 17:48:48 +0000 (18:48 +0100)
committerEric Hartmann <hartmann.eric@gmail.Com>
Tue, 14 Nov 2017 12:10:17 +0000 (13:10 +0100)
14 files changed:
cix.sh
tests/src/test/java/org/sonarqube/tests/Category1Suite.java
tests/src/test/java/org/sonarqube/tests/Category6Suite.java
tests/src/test/java/org/sonarqube/tests/qualityGate/OrganizationQualityGateForSmallChangesetsTest.java [new file with mode: 0644]
tests/src/test/java/org/sonarqube/tests/qualityGate/OrganizationQualityGateSuite.java [new file with mode: 0644]
tests/src/test/java/org/sonarqube/tests/qualityGate/OrganizationQualityGateTest.java [new file with mode: 0644]
tests/src/test/java/org/sonarqube/tests/qualityGate/OrganizationQualityGateUiTest.java
tests/src/test/java/org/sonarqube/tests/qualityGate/QualityGateForSmallChangesetsTest.java [deleted file]
tests/src/test/java/org/sonarqube/tests/qualityGate/QualityGateNotificationTest.java
tests/src/test/java/org/sonarqube/tests/qualityGate/QualityGateOnRatingMeasuresTest.java
tests/src/test/java/org/sonarqube/tests/qualityGate/QualityGateSuite.java [new file with mode: 0644]
tests/src/test/java/org/sonarqube/tests/qualityGate/QualityGateTest.java
tests/src/test/java/org/sonarqube/tests/qualityGate/QualityGateUiTest.java
tests/src/test/java/org/sonarqube/tests/qualityGate/QualityGateWithOrganizationsTest.java [deleted file]

diff --git a/cix.sh b/cix.sh
index 2830bc82ab4f75f8a45fa6a77bbe1d305240003e..8bd7fa7dc6739f3e8b687410667af4cb0b455746 100755 (executable)
--- a/cix.sh
+++ b/cix.sh
@@ -35,6 +35,7 @@ case "$RUN_ACTIVITY" in
           CATEGORY=Category1 && runCategory
           CATEGORY=authorization && runCategory
           CATEGORY=measure && runCategory
+          CATEGORY=qualityGate && runCategory
           CATEGORY=source && runCategory
           ;;
 
index 2cc1da3ed4a100e16007573b85f0c4b635c12ed6..2f48113bddc678456d87c33f41000ebe29621859 100644 (file)
@@ -29,10 +29,6 @@ import org.sonarqube.tests.projectAdministration.ProjectBulkDeletionPageTest;
 import org.sonarqube.tests.projectAdministration.ProjectLinksPageTest;
 import org.sonarqube.tests.projectAdministration.ProjectVisibilityPageTest;
 import org.sonarqube.tests.projectSearch.ProjectsPageTest;
-import org.sonarqube.tests.qualityGate.QualityGateNotificationTest;
-import org.sonarqube.tests.qualityGate.QualityGateOnRatingMeasuresTest;
-import org.sonarqube.tests.qualityGate.QualityGateTest;
-import org.sonarqube.tests.qualityGate.QualityGateUiTest;
 import org.sonarqube.tests.settings.DeprecatedPropertiesWsTest;
 import org.sonarqube.tests.settings.EmailsTest;
 import org.sonarqube.tests.settings.PropertySetsTest;
@@ -57,11 +53,6 @@ import static util.ItUtils.xooPlugin;
   EmailsTest.class,
   PropertySetsTest.class,
   SettingsTest.class,
-  // quality gate
-  QualityGateTest.class,
-  QualityGateUiTest.class,
-  QualityGateNotificationTest.class,
-  QualityGateOnRatingMeasuresTest.class,
   // measure
   ProjectsPageTest.class
 })
index aca8c327b4ceb93da67b06c3e1805097d16cb83b..dd582a25cd380709a55dba872973c92dfeab2cb7 100644 (file)
@@ -37,10 +37,8 @@ import org.sonarqube.tests.projectAdministration.ProjectProvisioningTest;
 import org.sonarqube.tests.projectAdministration.ProjectSearchTest;
 import org.sonarqube.tests.projectSearch.LeakProjectsPageTest;
 import org.sonarqube.tests.projectSearch.SearchProjectsTest;
-import org.sonarqube.tests.qualityGate.OrganizationQualityGateUiTest;
 import org.sonarqube.tests.qualityProfile.BuiltInQualityProfilesTest;
 import org.sonarqube.tests.qualityProfile.CustomQualityProfilesTest;
-import org.sonarqube.tests.qualityProfile.OrganizationQualityProfilesUiTest;
 import org.sonarqube.tests.qualityProfile.QualityProfilesEditTest;
 import org.sonarqube.tests.qualityProfile.QualityProfilesWsTest;
 import org.sonarqube.tests.rule.RulesWsTest;
@@ -57,8 +55,6 @@ import static util.ItUtils.xooPlugin;
   OrganizationIdentityProviderTest.class,
   OrganizationIssueAssignTest.class,
   OrganizationIssuesPageTest.class,
-  OrganizationQualityGateUiTest.class,
-  OrganizationQualityProfilesUiTest.class,
   BuiltInQualityProfilesTest.class,
   QualityProfilesEditTest.class,
   QualityProfilesWsTest.class,
diff --git a/tests/src/test/java/org/sonarqube/tests/qualityGate/OrganizationQualityGateForSmallChangesetsTest.java b/tests/src/test/java/org/sonarqube/tests/qualityGate/OrganizationQualityGateForSmallChangesetsTest.java
new file mode 100644 (file)
index 0000000..d67581b
--- /dev/null
@@ -0,0 +1,184 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonarqube.tests.qualityGate;
+
+import com.sonar.orchestrator.Orchestrator;
+import com.sonar.orchestrator.build.SonarScanner;
+import java.io.File;
+import java.io.IOException;
+import java.io.StringReader;
+import java.nio.charset.StandardCharsets;
+import java.util.Properties;
+import org.apache.commons.io.FileUtils;
+import org.junit.ClassRule;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonarqube.qa.util.Tester;
+import org.sonarqube.ws.MediaTypes;
+import org.sonarqube.ws.Organizations;
+import org.sonarqube.ws.WsCe;
+import org.sonarqube.ws.WsProjects.CreateWsResponse.Project;
+import org.sonarqube.ws.WsQualityGates;
+import org.sonarqube.ws.WsQualityGates.CreateWsResponse;
+import org.sonarqube.ws.WsUsers;
+import org.sonarqube.ws.client.GetRequest;
+import org.sonarqube.ws.client.WsResponse;
+import org.sonarqube.ws.client.qualitygate.CreateConditionRequest;
+import org.sonarqube.ws.client.qualitygate.ProjectStatusWsRequest;
+import org.sonarqube.ws.client.qualitygate.UpdateConditionRequest;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static util.ItUtils.getMeasure;
+import static util.ItUtils.projectDir;
+
+public class OrganizationQualityGateForSmallChangesetsTest {
+
+  @ClassRule
+  public static Orchestrator orchestrator = OrganizationQualityGateSuite.ORCHESTRATOR;
+
+  @Rule
+  public Tester tester = new Tester(orchestrator);
+
+  @Test
+  public void do_not_fail_quality_gate_with_poor_LEAK_coverage_and_a_max_of_19_lines_of_NEW_code() throws Exception {
+    Organizations.Organization organization = tester.organizations().generate();
+    Project project = tester.projects().generate(organization);
+    CreateWsResponse qualityGate = tester.qGates().generate();
+    tester.qGates().associateProject(qualityGate, project);
+    WsQualityGates.CreateConditionWsResponse condition = tester.wsClient().qualityGates().createCondition(CreateConditionRequest.builder()
+      .setQualityGateId(qualityGate.getId())
+      .setMetricKey("new_coverage")
+      .setOperator("LT")
+      .setWarning("90")
+      .setError("80")
+      .setPeriod(1)
+      .build());
+
+    tester.settings().setProjectSetting(project.getKey(), "sonar.leak.period", "previous_version");
+    String password = "password1";
+    WsUsers.CreateWsResponse.User user = tester.users().generateAdministrator(organization, u -> u.setPassword(password));
+
+    // no leak => use usual behaviour
+    SonarScanner analysis = SonarScanner
+      .create(projectDir("qualitygate/small-changesets/v1-1000-lines"))
+      .setProperty("sonar.projectKey", project.getKey())
+      .setProperty("sonar.organization", organization.getKey())
+      .setProperty("sonar.login", user.getLogin())
+      .setProperty("sonar.password", password)
+      .setProperty("sonar.scm.provider", "xoo")
+      .setProperty("sonar.scm.disabled", "false")
+      .setProperty("sonar.projectDate", "2013-04-01")
+      .setDebugLogs(true);
+    orchestrator.executeBuild(analysis);
+    assertThat(getMeasure(orchestrator, project.getKey(), "alert_status").getValue()).isEqualTo("OK");
+    assertIgnoredConditions("qualitygate/small-changesets/v1-1000-lines", false);
+
+    // small leak => ignore coverage warning or error
+    SonarScanner analysis2 = SonarScanner
+      .create(projectDir("qualitygate/small-changesets/v2-1019-lines"))
+      .setProperty("sonar.projectKey", project.getKey())
+      .setProperty("sonar.organization", organization.getKey())
+      .setProperty("sonar.login", user.getLogin())
+      .setProperty("sonar.password", password)
+      .setProperty("sonar.scm.provider", "xoo")
+      .setProperty("sonar.scm.disabled", "false")
+      .setProperty("sonar.projectDate", "2014-04-01")
+      .setDebugLogs(true);
+    orchestrator.executeBuild(analysis2);
+    assertThat(getMeasure(orchestrator, project.getKey(), "alert_status").getValue()).isEqualTo("OK");
+    assertIgnoredConditions("qualitygate/small-changesets/v2-1019-lines", true);
+
+    // small leak => if coverage is OK anyways, we do not have to ignore anything
+    tester.wsClient().qualityGates().updateCondition(UpdateConditionRequest.builder()
+      .setConditionId(condition.getId())
+      .setMetricKey("new_coverage")
+      .setOperator("LT")
+      .setWarning("10")
+      .setError("20")
+      .setPeriod(1)
+      .build());
+    SonarScanner analysis3 = SonarScanner
+      .create(projectDir("qualitygate/small-changesets/v2-1019-lines"))
+      .setProperty("sonar.projectKey", project.getKey())
+      .setProperty("sonar.organization", organization.getKey())
+      .setProperty("sonar.login", user.getLogin())
+      .setProperty("sonar.password", password)
+      .setProperty("sonar.scm.provider", "xoo")
+      .setProperty("sonar.scm.disabled", "false")
+      .setProperty("sonar.projectDate", "2014-04-02")
+      .setDebugLogs(true);
+    orchestrator.executeBuild(analysis3);
+    assertThat(getMeasure(orchestrator, project.getKey(), "alert_status").getValue()).isEqualTo("OK");
+    assertIgnoredConditions("qualitygate/small-changesets/v2-1019-lines", false);
+
+    // big leak => use usual behaviour
+    tester.wsClient().qualityGates().updateCondition(UpdateConditionRequest.builder()
+      .setConditionId(condition.getId())
+      .setMetricKey("new_coverage")
+      .setOperator("LT")
+      .setWarning(null)
+      .setError("70")
+      .setPeriod(1)
+      .build());
+    SonarScanner analysis4 = SonarScanner
+      .create(projectDir("qualitygate/small-changesets/v2-1020-lines"))
+      .setProperty("sonar.projectKey", project.getKey())
+      .setProperty("sonar.organization", organization.getKey())
+      .setProperty("sonar.login", user.getLogin())
+      .setProperty("sonar.password", password)
+      .setProperty("sonar.scm.provider", "xoo")
+      .setProperty("sonar.scm.disabled", "false")
+      .setProperty("sonar.projectDate", "2014-04-03")
+      .setDebugLogs(true);
+    orchestrator.executeBuild(analysis4);
+    assertThat(getMeasure(orchestrator, project.getKey(), "alert_status").getValue()).isEqualTo("ERROR");
+    assertIgnoredConditions("qualitygate/small-changesets/v2-1020-lines", false);
+  }
+
+  private void assertIgnoredConditions(String projectDir, boolean expected) throws IOException {
+    String analysisId = getAnalysisId(getTaskIdInLocalReport(projectDir(projectDir)));
+    boolean ignoredConditions = tester.wsClient().qualityGates()
+      .projectStatus(new ProjectStatusWsRequest().setAnalysisId(analysisId))
+      .getProjectStatus()
+      .getIgnoredConditions();
+    assertThat(ignoredConditions).isEqualTo(expected);
+  }
+
+  private String getAnalysisId(String taskId) throws IOException {
+    WsResponse activity = tester.wsClient()
+      .wsConnector()
+      .call(new GetRequest("api/ce/task")
+        .setParam("id", taskId)
+        .setMediaType(MediaTypes.PROTOBUF));
+    WsCe.TaskResponse activityWsResponse = WsCe.TaskResponse.parseFrom(activity.contentStream());
+    return activityWsResponse.getTask().getAnalysisId();
+  }
+
+  private String getTaskIdInLocalReport(File projectDirectory) throws IOException {
+    File metadata = new File(projectDirectory, ".sonar/report-task.txt");
+    assertThat(metadata).exists().isFile();
+    // verify properties
+    Properties props = new Properties();
+    props.load(new StringReader(FileUtils.readFileToString(metadata, StandardCharsets.UTF_8)));
+    assertThat(props.getProperty("ceTaskId")).isNotEmpty();
+
+    return props.getProperty("ceTaskId");
+  }
+}
diff --git a/tests/src/test/java/org/sonarqube/tests/qualityGate/OrganizationQualityGateSuite.java b/tests/src/test/java/org/sonarqube/tests/qualityGate/OrganizationQualityGateSuite.java
new file mode 100644 (file)
index 0000000..e56b4cf
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonarqube.tests.qualityGate;
+
+import com.sonar.orchestrator.Orchestrator;
+import org.junit.ClassRule;
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+
+import static util.ItUtils.pluginArtifact;
+import static util.ItUtils.xooPlugin;
+
+@RunWith(Suite.class)
+@Suite.SuiteClasses({
+  OrganizationQualityGateUiTest.class,
+  OrganizationQualityGateTest.class,
+  OrganizationQualityGateForSmallChangesetsTest.class
+})
+public class OrganizationQualityGateSuite {
+
+  @ClassRule
+  public static final Orchestrator ORCHESTRATOR = Orchestrator.builderEnv()
+    // required for notification tests
+    .setServerProperty("sonar.notifications.delay", "1")
+
+    // reduce memory for Elasticsearch
+    .setServerProperty("sonar.search.javaOpts", "-Xms128m -Xmx128m")
+
+    .addPlugin(pluginArtifact("posttask-plugin"))
+    .addPlugin(xooPlugin())
+    .build();
+
+}
diff --git a/tests/src/test/java/org/sonarqube/tests/qualityGate/OrganizationQualityGateTest.java b/tests/src/test/java/org/sonarqube/tests/qualityGate/OrganizationQualityGateTest.java
new file mode 100644 (file)
index 0000000..be243e0
--- /dev/null
@@ -0,0 +1,99 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonarqube.tests.qualityGate;
+
+import com.sonar.orchestrator.Orchestrator;
+import com.sonar.orchestrator.build.SonarScanner;
+import java.util.Map;
+import org.junit.ClassRule;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonarqube.qa.util.Tester;
+import org.sonarqube.ws.Organizations.Organization;
+import org.sonarqube.ws.WsProjects.CreateWsResponse.Project;
+import org.sonarqube.ws.WsQualityGates.CreateWsResponse;
+import org.sonarqube.ws.WsUsers;
+import org.sonarqube.ws.client.GetRequest;
+import org.sonarqube.ws.client.WsResponse;
+import org.sonarqube.ws.client.qualitygate.CreateConditionRequest;
+import util.ItUtils;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static util.ItUtils.projectDir;
+
+public class OrganizationQualityGateTest {
+
+  @ClassRule
+  public static Orchestrator orchestrator = OrganizationQualityGateSuite.ORCHESTRATOR;
+
+  @Rule
+  public Tester tester = new Tester(orchestrator);
+
+  @Test
+  public void always_display_current_quality_gate_in_effect() throws Exception {
+    Organization organization = tester.organizations().generate();
+    Project project = tester.projects().generate(organization);
+    CreateWsResponse qualityGate = tester.qGates().generate();
+    tester.qGates().associateProject(qualityGate, project);
+    tester.wsClient().qualityGates().createCondition(CreateConditionRequest.builder()
+      .setQualityGateId(qualityGate.getId())
+      .setMetricKey("new_coverage")
+      .setOperator("LT")
+      .setWarning("90")
+      .setError("80")
+      .setPeriod(1)
+      .build());
+    tester.settings().setProjectSetting(project.getKey(), "sonar.leak.period", "previous_version");
+    String password = "password1";
+    WsUsers.CreateWsResponse.User user = tester.users().generateAdministrator(organization, u -> u.setPassword(password));
+
+    WsResponse response = tester.wsClient().wsConnector().call(new GetRequest("api/navigation/component").setParam("componentKey", project.getKey()));
+    Map currentQualityGate = (Map) ItUtils.jsonToMap(response.content()).get("qualityGate");
+    assertThat((long) (double) (Double) currentQualityGate.get("key")).isEqualTo(qualityGate.getId());
+
+    orchestrator.executeBuild(
+      SonarScanner.create(projectDir("shared/xoo-sample"))
+        .setProperty("sonar.organization", organization.getKey())
+        .setProjectKey(project.getKey())
+        .setProjectName(project.getName())
+        .setProperty("sonar.login", user.getLogin())
+        .setProperty("sonar.password", password)
+        .setDebugLogs(true));
+
+    WsResponse response2 = tester.wsClient().wsConnector().call(new GetRequest("api/navigation/component").setParam("componentKey", project.getKey()));
+    Map currentQualityGate2 = (Map) ItUtils.jsonToMap(response2.content()).get("qualityGate");
+    assertThat((long) (double) (Double) currentQualityGate2.get("key")).isEqualTo(qualityGate.getId());
+
+    CreateWsResponse qualityGate2 = tester.qGates().generate();
+    tester.qGates().associateProject(qualityGate2, project);
+    tester.wsClient().qualityGates().createCondition(CreateConditionRequest.builder()
+      .setQualityGateId(qualityGate2.getId())
+      .setMetricKey("new_coverage")
+      .setOperator("LT")
+      .setWarning("90")
+      .setError("80")
+      .setPeriod(1)
+      .build());
+
+    WsResponse response3 = tester.wsClient().wsConnector().call(new GetRequest("api/navigation/component").setParam("componentKey", project.getKey()));
+    Map currentQualityGate3 = (Map) ItUtils.jsonToMap(response3.content()).get("qualityGate");
+    assertThat((long) (double) (Double) currentQualityGate3.get("key")).isEqualTo(qualityGate2.getId());
+  }
+}
index a859558d04e1e62d6939ccc19becf362fcad2972..9bb518dca2084de55222ad12f28e675a726cea56 100644 (file)
@@ -27,22 +27,21 @@ import org.junit.ClassRule;
 import org.junit.Rule;
 import org.junit.Test;
 import org.openqa.selenium.By;
+import org.sonarqube.qa.util.Tester;
 import org.sonarqube.qa.util.pageobjects.ProjectDashboardPage;
 import org.sonarqube.qa.util.pageobjects.QualityGatePage;
-import org.sonarqube.tests.Category6Suite;
-import org.sonarqube.qa.util.Tester;
 import org.sonarqube.ws.Organizations;
 import org.sonarqube.ws.WsUsers;
 import util.issue.IssueRule;
 
 import static com.codeborne.selenide.Selenide.$;
+import static org.assertj.core.api.Assertions.assertThat;
 import static util.ItUtils.restoreProfile;
 import static util.ItUtils.runProjectAnalysis;
-import static org.assertj.core.api.Assertions.assertThat;
 
 public class OrganizationQualityGateUiTest {
   @ClassRule
-  public static Orchestrator orchestrator = Category6Suite.ORCHESTRATOR;
+  public static Orchestrator orchestrator = OrganizationQualityGateSuite.ORCHESTRATOR;
 
   @Rule
   public Tester tester = new Tester(orchestrator);
diff --git a/tests/src/test/java/org/sonarqube/tests/qualityGate/QualityGateForSmallChangesetsTest.java b/tests/src/test/java/org/sonarqube/tests/qualityGate/QualityGateForSmallChangesetsTest.java
deleted file mode 100644 (file)
index f41911e..0000000
+++ /dev/null
@@ -1,185 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2017 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonarqube.tests.qualityGate;
-
-import com.sonar.orchestrator.Orchestrator;
-import com.sonar.orchestrator.build.SonarScanner;
-import java.io.File;
-import java.io.IOException;
-import java.io.StringReader;
-import java.nio.charset.StandardCharsets;
-import java.util.Properties;
-import org.apache.commons.io.FileUtils;
-import org.junit.ClassRule;
-import org.junit.Rule;
-import org.junit.Test;
-import org.sonarqube.tests.Category6Suite;
-import org.sonarqube.qa.util.Tester;
-import org.sonarqube.ws.MediaTypes;
-import org.sonarqube.ws.Organizations;
-import org.sonarqube.ws.WsCe;
-import org.sonarqube.ws.WsProjects.CreateWsResponse.Project;
-import org.sonarqube.ws.WsQualityGates;
-import org.sonarqube.ws.WsQualityGates.CreateWsResponse;
-import org.sonarqube.ws.WsUsers;
-import org.sonarqube.ws.client.GetRequest;
-import org.sonarqube.ws.client.WsResponse;
-import org.sonarqube.ws.client.qualitygate.CreateConditionRequest;
-import org.sonarqube.ws.client.qualitygate.ProjectStatusWsRequest;
-import org.sonarqube.ws.client.qualitygate.UpdateConditionRequest;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static util.ItUtils.getMeasure;
-import static util.ItUtils.projectDir;
-
-public class QualityGateForSmallChangesetsTest {
-
-  @ClassRule
-  public static Orchestrator orchestrator = Category6Suite.ORCHESTRATOR;
-
-  @Rule
-  public Tester tester = new Tester(orchestrator);
-
-  @Test
-  public void do_not_fail_quality_gate_with_poor_LEAK_coverage_and_a_max_of_19_lines_of_NEW_code() throws Exception {
-    Organizations.Organization organization = tester.organizations().generate();
-    Project project = tester.projects().generate(organization);
-    CreateWsResponse qualityGate = tester.qGates().generate();
-    tester.qGates().associateProject(qualityGate, project);
-    WsQualityGates.CreateConditionWsResponse condition = tester.wsClient().qualityGates().createCondition(CreateConditionRequest.builder()
-      .setQualityGateId(qualityGate.getId())
-      .setMetricKey("new_coverage")
-      .setOperator("LT")
-      .setWarning("90")
-      .setError("80")
-      .setPeriod(1)
-      .build());
-
-    tester.settings().setProjectSetting(project.getKey(), "sonar.leak.period", "previous_version");
-    String password = "password1";
-    WsUsers.CreateWsResponse.User user = tester.users().generateAdministrator(organization, u -> u.setPassword(password));
-
-    // no leak => use usual behaviour
-    SonarScanner analysis = SonarScanner
-      .create(projectDir("qualitygate/small-changesets/v1-1000-lines"))
-      .setProperty("sonar.projectKey", project.getKey())
-      .setProperty("sonar.organization", organization.getKey())
-      .setProperty("sonar.login", user.getLogin())
-      .setProperty("sonar.password", password)
-      .setProperty("sonar.scm.provider", "xoo")
-      .setProperty("sonar.scm.disabled", "false")
-      .setProperty("sonar.projectDate", "2013-04-01")
-      .setDebugLogs(true);
-    orchestrator.executeBuild(analysis);
-    assertThat(getMeasure(orchestrator, project.getKey(), "alert_status").getValue()).isEqualTo("OK");
-    assertIgnoredConditions(project, "qualitygate/small-changesets/v1-1000-lines", false);
-
-    // small leak => ignore coverage warning or error
-    SonarScanner analysis2 = SonarScanner
-      .create(projectDir("qualitygate/small-changesets/v2-1019-lines"))
-      .setProperty("sonar.projectKey", project.getKey())
-      .setProperty("sonar.organization", organization.getKey())
-      .setProperty("sonar.login", user.getLogin())
-      .setProperty("sonar.password", password)
-      .setProperty("sonar.scm.provider", "xoo")
-      .setProperty("sonar.scm.disabled", "false")
-      .setProperty("sonar.projectDate", "2014-04-01")
-      .setDebugLogs(true);
-    orchestrator.executeBuild(analysis2);
-    assertThat(getMeasure(orchestrator, project.getKey(), "alert_status").getValue()).isEqualTo("OK");
-    assertIgnoredConditions(project, "qualitygate/small-changesets/v2-1019-lines", true);
-
-    // small leak => if coverage is OK anyways, we do not have to ignore anything
-    tester.wsClient().qualityGates().updateCondition(UpdateConditionRequest.builder()
-      .setConditionId(condition.getId())
-      .setMetricKey("new_coverage")
-      .setOperator("LT")
-      .setWarning("10")
-      .setError("20")
-      .setPeriod(1)
-      .build());
-    SonarScanner analysis3 = SonarScanner
-      .create(projectDir("qualitygate/small-changesets/v2-1019-lines"))
-      .setProperty("sonar.projectKey", project.getKey())
-      .setProperty("sonar.organization", organization.getKey())
-      .setProperty("sonar.login", user.getLogin())
-      .setProperty("sonar.password", password)
-      .setProperty("sonar.scm.provider", "xoo")
-      .setProperty("sonar.scm.disabled", "false")
-      .setProperty("sonar.projectDate", "2014-04-02")
-      .setDebugLogs(true);
-    orchestrator.executeBuild(analysis3);
-    assertThat(getMeasure(orchestrator, project.getKey(), "alert_status").getValue()).isEqualTo("OK");
-    assertIgnoredConditions(project, "qualitygate/small-changesets/v2-1019-lines", false);
-
-    // big leak => use usual behaviour
-    tester.wsClient().qualityGates().updateCondition(UpdateConditionRequest.builder()
-      .setConditionId(condition.getId())
-      .setMetricKey("new_coverage")
-      .setOperator("LT")
-      .setWarning(null)
-      .setError("70")
-      .setPeriod(1)
-      .build());
-    SonarScanner analysis4 = SonarScanner
-      .create(projectDir("qualitygate/small-changesets/v2-1020-lines"))
-      .setProperty("sonar.projectKey", project.getKey())
-      .setProperty("sonar.organization", organization.getKey())
-      .setProperty("sonar.login", user.getLogin())
-      .setProperty("sonar.password", password)
-      .setProperty("sonar.scm.provider", "xoo")
-      .setProperty("sonar.scm.disabled", "false")
-      .setProperty("sonar.projectDate", "2014-04-03")
-      .setDebugLogs(true);
-    orchestrator.executeBuild(analysis4);
-    assertThat(getMeasure(orchestrator, project.getKey(), "alert_status").getValue()).isEqualTo("ERROR");
-    assertIgnoredConditions(project, "qualitygate/small-changesets/v2-1020-lines", false);
-  }
-
-  private void assertIgnoredConditions(Project project, String projectDir, boolean expected) throws IOException {
-    String analysisId = getAnalysisId(getTaskIdInLocalReport(projectDir(projectDir)));
-    boolean ignoredConditions = tester.wsClient().qualityGates()
-      .projectStatus(new ProjectStatusWsRequest().setAnalysisId(analysisId))
-      .getProjectStatus()
-      .getIgnoredConditions();
-    assertThat(ignoredConditions).isEqualTo(expected);
-  }
-
-  private String getAnalysisId(String taskId) throws IOException {
-    WsResponse activity = tester.wsClient()
-      .wsConnector()
-      .call(new GetRequest("api/ce/task")
-        .setParam("id", taskId)
-        .setMediaType(MediaTypes.PROTOBUF));
-    WsCe.TaskResponse activityWsResponse = WsCe.TaskResponse.parseFrom(activity.contentStream());
-    return activityWsResponse.getTask().getAnalysisId();
-  }
-
-  private String getTaskIdInLocalReport(File projectDirectory) throws IOException {
-    File metadata = new File(projectDirectory, ".sonar/report-task.txt");
-    assertThat(metadata).exists().isFile();
-    // verify properties
-    Properties props = new Properties();
-    props.load(new StringReader(FileUtils.readFileToString(metadata, StandardCharsets.UTF_8)));
-    assertThat(props.getProperty("ceTaskId")).isNotEmpty();
-
-    return props.getProperty("ceTaskId");
-  }
-}
index de000ee5e616aa111361cfb78e73eaa0c12ad594..84b31c58e83828dfb8bd19bc1cadfa04e52677c2 100644 (file)
@@ -28,7 +28,6 @@ import org.junit.BeforeClass;
 import org.junit.ClassRule;
 import org.junit.Rule;
 import org.junit.Test;
-import org.sonarqube.tests.Category1Suite;
 import org.sonarqube.qa.util.Tester;
 import org.sonarqube.ws.WsProjects.CreateWsResponse.Project;
 import org.sonarqube.ws.WsQualityGates;
@@ -45,23 +44,25 @@ import static util.ItUtils.projectDir;
 public class QualityGateNotificationTest {
 
   @ClassRule
-  public static Orchestrator orchestrator = Category1Suite.ORCHESTRATOR;
+  public static Orchestrator orchestrator = QualityGateSuite.ORCHESTRATOR;
 
   @Rule
-  public Tester tester = new Tester(orchestrator).disableOrganizations();
+  public Tester tester = new Tester(orchestrator)
+    // all the tests of QualityGateSuite must disable organizations
+    .disableOrganizations();
 
-  private static Wiser SMTP_SERVER;
+  private static Wiser smtpServer;
 
   @BeforeClass
   public static void startSmtpServer() throws Exception {
-    SMTP_SERVER = new Wiser(0);
-    SMTP_SERVER.start();
+    smtpServer = new Wiser(0);
+    smtpServer.start();
   }
 
   @AfterClass
   public static void stopSmtpServer() throws Exception {
-    if (SMTP_SERVER != null) {
-      SMTP_SERVER.stop();
+    if (smtpServer != null) {
+      smtpServer.stop();
     }
   }
 
@@ -69,7 +70,7 @@ public class QualityGateNotificationTest {
   public void status_on_metric_variation_and_send_notifications() throws Exception {
     tester.settings().setGlobalSettings("sonar.leak.period", "previous_version");
     tester.settings().setGlobalSettings("email.smtp_host.secured", "localhost");
-    tester.settings().setGlobalSettings("email.smtp_port.secured", Integer.toString(SMTP_SERVER.getServer().getPort()));
+    tester.settings().setGlobalSettings("email.smtp_port.secured", Integer.toString(smtpServer.getServer().getPort()));
 
     // Create user, who will receive notifications for new violations
     tester.users().generate(u -> u.setLogin("tester").setPassword("tester").setEmail("tester@example.org"));
@@ -98,9 +99,9 @@ public class QualityGateNotificationTest {
     orchestrator.executeBuild(analysis);
     assertThat(getGateStatusMeasure(project).getValue()).isEqualTo("WARN");
 
-    waitUntilAllNotificationsAreDelivered(SMTP_SERVER);
+    waitUntilAllNotificationsAreDelivered(smtpServer);
 
-    Iterator<WiserMessage> emails = SMTP_SERVER.getMessages().iterator();
+    Iterator<WiserMessage> emails = smtpServer.getMessages().iterator();
 
     MimeMessage message = emails.next().getMimeMessage();
     assertThat(message.getHeader("To", null)).isEqualTo("<test@example.org>");
index a90b54cbc1ac5b7f230b6462943a40673a04befb..da87a001fe3ecd6d599011ef0d050ded8cbf7042 100644 (file)
@@ -23,7 +23,6 @@ import com.sonar.orchestrator.Orchestrator;
 import org.junit.ClassRule;
 import org.junit.Rule;
 import org.junit.Test;
-import org.sonarqube.tests.Category1Suite;
 import org.sonarqube.qa.util.Tester;
 import org.sonarqube.ws.WsMeasures;
 import org.sonarqube.ws.WsProjects.CreateWsResponse.Project;
@@ -38,10 +37,12 @@ import static util.ItUtils.runProjectAnalysis;
 public class QualityGateOnRatingMeasuresTest {
 
   @ClassRule
-  public static Orchestrator orchestrator = Category1Suite.ORCHESTRATOR;
+  public static Orchestrator orchestrator = QualityGateSuite.ORCHESTRATOR;
 
   @Rule
-  public Tester tester = new Tester(orchestrator).disableOrganizations();
+  public Tester tester = new Tester(orchestrator)
+    // all the tests of QualityGateSuite must disable organizations
+    .disableOrganizations();
 
   @Test
   public void generate_warning_qgate_on_rating_metric() throws Exception {
diff --git a/tests/src/test/java/org/sonarqube/tests/qualityGate/QualityGateSuite.java b/tests/src/test/java/org/sonarqube/tests/qualityGate/QualityGateSuite.java
new file mode 100644 (file)
index 0000000..ce4632b
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonarqube.tests.qualityGate;
+
+import com.sonar.orchestrator.Orchestrator;
+import org.junit.ClassRule;
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+
+import static util.ItUtils.pluginArtifact;
+import static util.ItUtils.xooPlugin;
+
+@RunWith(Suite.class)
+@Suite.SuiteClasses({
+  QualityGateTest.class,
+  QualityGateUiTest.class,
+  QualityGateNotificationTest.class,
+  QualityGateOnRatingMeasuresTest.class,
+})
+public class QualityGateSuite {
+
+  @ClassRule
+  public static final Orchestrator ORCHESTRATOR = Orchestrator.builderEnv()
+    // required for notification tests
+    .setServerProperty("sonar.notifications.delay", "1")
+
+    // reduce memory for Elasticsearch
+    .setServerProperty("sonar.search.javaOpts", "-Xms128m -Xmx128m")
+
+    .addPlugin(pluginArtifact("posttask-plugin"))
+    .addPlugin(xooPlugin())
+    .build();
+
+}
index 400b897fadd0ae81fdde0963b2608189f9a792a2..a88574e4866da17feb6f3db090b64f8c2b0202e9 100644 (file)
@@ -42,9 +42,8 @@ import org.junit.Test;
 import org.sonar.wsclient.qualitygate.NewCondition;
 import org.sonar.wsclient.qualitygate.QualityGate;
 import org.sonar.wsclient.qualitygate.QualityGateClient;
-import org.sonarqube.tests.Category1Suite;
-import org.sonarqube.qa.util.TesterSession;
 import org.sonarqube.qa.util.Tester;
+import org.sonarqube.qa.util.TesterSession;
 import org.sonarqube.ws.MediaTypes;
 import org.sonarqube.ws.Organizations.Organization;
 import org.sonarqube.ws.WsCe;
@@ -81,10 +80,12 @@ public class QualityGateTest {
   private static final String QG_STATUS_WARN = "WARN";
 
   @ClassRule
-  public static Orchestrator orchestrator = Category1Suite.ORCHESTRATOR;
+  public static Orchestrator orchestrator = QualityGateSuite.ORCHESTRATOR;
 
   @Rule
-  public Tester tester = new Tester(orchestrator).disableOrganizations();
+  public Tester tester = new Tester(orchestrator)
+    // all the tests of QualityGateSuite must disable organizations
+    .disableOrganizations();
 
   private QualityGate defaultGate;
 
@@ -348,7 +349,7 @@ public class QualityGateTest {
     return getMeasure(orchestrator, projectKey, "alert_status");
   }
 
-  private static QualityGateClient qgClient() {
+  private QualityGateClient qgClient() {
     return orchestrator.getServer().adminWsClient().qualityGateClient();
   }
 
index 1fb41c1145405a52dfc8dff3e747afffb0b9c7bd..9c9dc04617ca0f84c48acdeafa9b9de6f5b95fb1 100644 (file)
@@ -31,10 +31,9 @@ import org.junit.ClassRule;
 import org.junit.Rule;
 import org.junit.Test;
 import org.openqa.selenium.By;
+import org.sonarqube.qa.util.Tester;
 import org.sonarqube.qa.util.pageobjects.Navigation;
 import org.sonarqube.qa.util.pageobjects.ProjectActivityPage;
-import org.sonarqube.tests.Category1Suite;
-import org.sonarqube.qa.util.Tester;
 import org.sonarqube.ws.WsProjects.CreateWsResponse.Project;
 import org.sonarqube.ws.WsQualityGates;
 import org.sonarqube.ws.client.qualitygate.CreateConditionRequest;
@@ -49,10 +48,12 @@ import static util.selenium.Selenese.runSelenese;
 public class QualityGateUiTest {
 
   @ClassRule
-  public static Orchestrator orchestrator = Category1Suite.ORCHESTRATOR;
+  public static Orchestrator orchestrator = QualityGateSuite.ORCHESTRATOR;
 
   @Rule
-  public Tester tester = new Tester(orchestrator).disableOrganizations();
+  public Tester tester = new Tester(orchestrator)
+    // all the tests of QualityGateSuite must disable organizations
+    .disableOrganizations();
 
   @Before
   public void initPeriod() throws Exception {
diff --git a/tests/src/test/java/org/sonarqube/tests/qualityGate/QualityGateWithOrganizationsTest.java b/tests/src/test/java/org/sonarqube/tests/qualityGate/QualityGateWithOrganizationsTest.java
deleted file mode 100644 (file)
index 2bc320d..0000000
+++ /dev/null
@@ -1,100 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2017 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonarqube.tests.qualityGate;
-
-import com.sonar.orchestrator.Orchestrator;
-import com.sonar.orchestrator.build.SonarScanner;
-import java.util.Map;
-import org.junit.ClassRule;
-import org.junit.Rule;
-import org.junit.Test;
-import org.sonarqube.tests.Category6Suite;
-import org.sonarqube.qa.util.Tester;
-import org.sonarqube.ws.Organizations.Organization;
-import org.sonarqube.ws.WsProjects.CreateWsResponse.Project;
-import org.sonarqube.ws.WsQualityGates.CreateWsResponse;
-import org.sonarqube.ws.WsUsers;
-import org.sonarqube.ws.client.GetRequest;
-import org.sonarqube.ws.client.WsResponse;
-import org.sonarqube.ws.client.qualitygate.CreateConditionRequest;
-import util.ItUtils;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static util.ItUtils.projectDir;
-
-public class QualityGateWithOrganizationsTest {
-
-  @ClassRule
-  public static Orchestrator orchestrator = Category6Suite.ORCHESTRATOR;
-
-  @Rule
-  public Tester tester = new Tester(orchestrator);
-
-  @Test
-  public void always_display_current_quality_gate_in_effect() throws Exception {
-    Organization organization = tester.organizations().generate();
-    Project project = tester.projects().generate(organization);
-    CreateWsResponse qualityGate = tester.qGates().generate();
-    tester.qGates().associateProject(qualityGate, project);
-    tester.wsClient().qualityGates().createCondition(CreateConditionRequest.builder()
-      .setQualityGateId(qualityGate.getId())
-      .setMetricKey("new_coverage")
-      .setOperator("LT")
-      .setWarning("90")
-      .setError("80")
-      .setPeriod(1)
-      .build());
-    tester.settings().setProjectSetting(project.getKey(), "sonar.leak.period", "previous_version");
-    String password = "password1";
-    WsUsers.CreateWsResponse.User user = tester.users().generateAdministrator(organization, u -> u.setPassword(password));
-
-    WsResponse response = tester.wsClient().wsConnector().call(new GetRequest("api/navigation/component").setParam("componentKey", project.getKey()));
-    Map currentQualityGate = (Map) ItUtils.jsonToMap(response.content()).get("qualityGate");
-    assertThat((long) (double) (Double) currentQualityGate.get("key")).isEqualTo(qualityGate.getId());
-
-    orchestrator.executeBuild(
-      SonarScanner.create(projectDir("shared/xoo-sample"))
-        .setProperty("sonar.organization", organization.getKey())
-        .setProjectKey(project.getKey())
-        .setProjectName(project.getName())
-        .setProperty("sonar.login", user.getLogin())
-        .setProperty("sonar.password", password)
-        .setDebugLogs(true));
-
-    WsResponse response2 = tester.wsClient().wsConnector().call(new GetRequest("api/navigation/component").setParam("componentKey", project.getKey()));
-    Map currentQualityGate2 = (Map) ItUtils.jsonToMap(response2.content()).get("qualityGate");
-    assertThat((long) (double) (Double) currentQualityGate2.get("key")).isEqualTo(qualityGate.getId());
-
-    CreateWsResponse qualityGate2 = tester.qGates().generate();
-    tester.qGates().associateProject(qualityGate2, project);
-    tester.wsClient().qualityGates().createCondition(CreateConditionRequest.builder()
-      .setQualityGateId(qualityGate2.getId())
-      .setMetricKey("new_coverage")
-      .setOperator("LT")
-      .setWarning("90")
-      .setError("80")
-      .setPeriod(1)
-      .build());
-
-    WsResponse response3 = tester.wsClient().wsConnector().call(new GetRequest("api/navigation/component").setParam("componentKey", project.getKey()));
-    Map currentQualityGate3 = (Map) ItUtils.jsonToMap(response3.content()).get("qualityGate");
-    assertThat((long) (double) (Double) currentQualityGate3.get("key")).isEqualTo(qualityGate2.getId());
-  }
-}