CATEGORY=Category1 && runCategory
CATEGORY=authorization && runCategory
CATEGORY=measure && runCategory
+ CATEGORY=qualityGate && runCategory
CATEGORY=source && runCategory
;;
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;
EmailsTest.class,
PropertySetsTest.class,
SettingsTest.class,
- // quality gate
- QualityGateTest.class,
- QualityGateUiTest.class,
- QualityGateNotificationTest.class,
- QualityGateOnRatingMeasuresTest.class,
// measure
ProjectsPageTest.class
})
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;
OrganizationIdentityProviderTest.class,
OrganizationIssueAssignTest.class,
OrganizationIssuesPageTest.class,
- OrganizationQualityGateUiTest.class,
- OrganizationQualityProfilesUiTest.class,
BuiltInQualityProfilesTest.class,
QualityProfilesEditTest.class,
QualityProfilesWsTest.class,
--- /dev/null
+/*
+ * 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");
+ }
+}
--- /dev/null
+/*
+ * 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();
+
+}
--- /dev/null
+/*
+ * 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());
+ }
+}
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);
+++ /dev/null
-/*
- * 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");
- }
-}
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;
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();
}
}
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"));
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>");
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;
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 {
--- /dev/null
+/*
+ * 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();
+
+}
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;
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;
return getMeasure(orchestrator, projectKey, "alert_status");
}
- private static QualityGateClient qgClient() {
+ private QualityGateClient qgClient() {
return orchestrator.getServer().adminWsClient().qualityGateClient();
}
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;
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 {
+++ /dev/null
-/*
- * 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());
- }
-}