diff options
author | Julien Lancelot <julien.lancelot@sonarsource.com> | 2017-09-05 14:12:04 +0200 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@sonarsource.com> | 2017-09-06 09:43:42 +0200 |
commit | 9dbd3143693c0313f065794d47d9dc5972f3d790 (patch) | |
tree | 02f2d4bce18744d5ccae659d74ad16a2879655e7 /tests | |
parent | 8451b5ffbc0a75bc88520698f3713030f9981bdb (diff) | |
download | sonarqube-9dbd3143693c0313f065794d47d9dc5972f3d790.tar.gz sonarqube-9dbd3143693c0313f065794d47d9dc5972f3d790.zip |
Add missing QualityGateOnRatingMeasuresTest in Category1Suite
Diffstat (limited to 'tests')
-rw-r--r-- | tests/src/test/java/org/sonarqube/tests/Category1Suite.java | 16 | ||||
-rw-r--r-- | tests/src/test/java/org/sonarqube/tests/qualityGate/QualityGateOnRatingMeasuresTest.java | 87 |
2 files changed, 38 insertions, 65 deletions
diff --git a/tests/src/test/java/org/sonarqube/tests/Category1Suite.java b/tests/src/test/java/org/sonarqube/tests/Category1Suite.java index 2c684a3fca2..836bd9807aa 100644 --- a/tests/src/test/java/org/sonarqube/tests/Category1Suite.java +++ b/tests/src/test/java/org/sonarqube/tests/Category1Suite.java @@ -20,8 +20,9 @@ package org.sonarqube.tests; import com.sonar.orchestrator.Orchestrator; -import org.sonarqube.tests.projectAdministration.ProjectVisibilityPageTest; -import org.sonarqube.tests.user.UsersPageTest; +import org.junit.ClassRule; +import org.junit.runner.RunWith; +import org.junit.runners.Suite; import org.sonarqube.tests.authorisation.ExecuteAnalysisPermissionTest; import org.sonarqube.tests.authorisation.IssuePermissionTest; import org.sonarqube.tests.authorisation.PermissionSearchTest; @@ -30,19 +31,21 @@ import org.sonarqube.tests.authorisation.QualityProfileAdminPermissionTest; import org.sonarqube.tests.complexity.ComplexityMeasuresTest; import org.sonarqube.tests.customMeasure.CustomMeasuresTest; import org.sonarqube.tests.i18n.I18nTest; +import org.sonarqube.tests.measure.DifferentialPeriodsTest; import org.sonarqube.tests.measure.MeasuresWsTest; import org.sonarqube.tests.measure.ProjectDashboardTest; import org.sonarqube.tests.measure.ProjectMeasuresPageTest; -import org.sonarqube.tests.measure.DifferentialPeriodsTest; import org.sonarqube.tests.measure.SincePreviousVersionHistoryTest; import org.sonarqube.tests.measure.SinceXDaysHistoryTest; import org.sonarqube.tests.measure.TimeMachineTest; import org.sonarqube.tests.projectAdministration.BackgroundTasksTest; -import org.sonarqube.tests.projectAdministration.ProjectBulkDeletionPageTest; import org.sonarqube.tests.projectAdministration.ProjectAdministrationTest; +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; @@ -52,9 +55,7 @@ import org.sonarqube.tests.settings.SettingsTest; import org.sonarqube.tests.sourceCode.EncodingTest; import org.sonarqube.tests.sourceCode.HighlightingTest; import org.sonarqube.tests.sourceCode.ProjectCodeTest; -import org.junit.ClassRule; -import org.junit.runner.RunWith; -import org.junit.runners.Suite; +import org.sonarqube.tests.user.UsersPageTest; import static util.ItUtils.pluginArtifact; import static util.ItUtils.xooPlugin; @@ -80,6 +81,7 @@ import static util.ItUtils.xooPlugin; QualityGateTest.class, QualityGateUiTest.class, QualityGateNotificationTest.class, + QualityGateOnRatingMeasuresTest.class, // authorisation ExecuteAnalysisPermissionTest.class, IssuePermissionTest.class, diff --git a/tests/src/test/java/org/sonarqube/tests/qualityGate/QualityGateOnRatingMeasuresTest.java b/tests/src/test/java/org/sonarqube/tests/qualityGate/QualityGateOnRatingMeasuresTest.java index db5b8e92bdc..7630cde5922 100644 --- a/tests/src/test/java/org/sonarqube/tests/qualityGate/QualityGateOnRatingMeasuresTest.java +++ b/tests/src/test/java/org/sonarqube/tests/qualityGate/QualityGateOnRatingMeasuresTest.java @@ -20,81 +20,56 @@ package org.sonarqube.tests.qualityGate; import com.sonar.orchestrator.Orchestrator; -import org.sonarqube.tests.Category1Suite; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; import org.junit.ClassRule; +import org.junit.Rule; import org.junit.Test; -import org.sonar.wsclient.qualitygate.QualityGateClient; +import org.sonarqube.tests.Category1Suite; +import org.sonarqube.tests.Tester; import org.sonarqube.ws.WsMeasures; -import org.sonarqube.ws.client.WsClient; +import org.sonarqube.ws.WsProjects.CreateWsResponse.Project; +import org.sonarqube.ws.WsQualityGates; import org.sonarqube.ws.client.qualitygate.CreateConditionRequest; -import org.sonarqube.ws.client.qualitygate.QualityGatesService; -import org.sonarqube.ws.client.qualitygate.SelectWsRequest; import util.ItUtils; import static org.assertj.core.api.Assertions.assertThat; import static util.ItUtils.getMeasure; -import static util.ItUtils.newAdminWsClient; -import static util.ItUtils.resetSettings; import static util.ItUtils.runProjectAnalysis; -import static util.ItUtils.setServerProperty; public class QualityGateOnRatingMeasuresTest { @ClassRule public static Orchestrator orchestrator = Category1Suite.ORCHESTRATOR; - private static final String PROJECT_KEY = "sample"; - - static WsClient wsClient; - - static QualityGatesService QUALITY_GATES; - - Long qualityGateId; - - @BeforeClass - public static void init() { - wsClient = newAdminWsClient(orchestrator); - QUALITY_GATES = wsClient.qualityGates(); - } - - @Before - public void prepareData() { - orchestrator.resetData(); - qualityGateId = QUALITY_GATES.create("QualityGate").getId(); - orchestrator.getServer().provisionProject(PROJECT_KEY, PROJECT_KEY); - QUALITY_GATES.associateProject(new SelectWsRequest().setGateId(qualityGateId).setProjectKey(PROJECT_KEY)); - } - - @After - public void resetData() throws Exception { - qgClient().destroy(qualityGateId); - resetSettings(orchestrator, null, "sonar.leak.period"); - } + @Rule + public Tester tester = new Tester(orchestrator).disableOrganizations(); @Test public void generate_warning_qgate_on_rating_metric() throws Exception { - QUALITY_GATES.createCondition(CreateConditionRequest.builder() - .setQualityGateId(qualityGateId.intValue()) + Project project = tester.projects().generate(null); + WsQualityGates.CreateWsResponse qualityGate = tester.qGates().generate(); + tester.qGates().associateProject(qualityGate, project); + tester.qGates().service().createCondition(CreateConditionRequest.builder() + .setQualityGateId(qualityGate.getId()) .setMetricKey("security_rating") .setOperator("GT") .setWarning("3") .build()); ItUtils.restoreProfile(orchestrator, getClass().getResource("/qualityGate/QualityGateOnRatingMeasuresTest/with-many-rules.xml")); - orchestrator.getServer().associateProjectToQualityProfile(PROJECT_KEY, "xoo", "with-many-rules"); + orchestrator.getServer().associateProjectToQualityProfile(project.getKey(), "xoo", "with-many-rules"); - runProjectAnalysis(orchestrator, "qualitygate/xoo-sample"); + runProjectAnalysis(orchestrator, "qualitygate/xoo-sample", "sonar.projectKey", project.getKey()); - assertThat(getGateStatusMeasure().getValue()).isEqualTo("WARN"); + assertThat(getGateStatusMeasure(project).getValue()).isEqualTo("WARN"); } @Test public void generate_error_qgate_on_rating_metric_on_leak_period() throws Exception { - setServerProperty(orchestrator, "sonar.leak.period", "previous_analysis"); - QUALITY_GATES.createCondition(CreateConditionRequest.builder() - .setQualityGateId(qualityGateId.intValue()) + Project project = tester.projects().generate(null); + WsQualityGates.CreateWsResponse qualityGate = tester.qGates().generate(); + tester.qGates().associateProject(qualityGate, project); + tester.settings().setGlobalSetting("sonar.leak.period", "previous_analysis"); + tester.wsClient().qualityGates().createCondition(CreateConditionRequest.builder() + .setQualityGateId(qualityGate.getId()) .setMetricKey("new_security_rating") .setOperator("GT") .setError("3") @@ -102,23 +77,19 @@ public class QualityGateOnRatingMeasuresTest { .build()); // Run first analysis with empty quality gate -> quality gate is green - orchestrator.getServer().associateProjectToQualityProfile(PROJECT_KEY, "xoo", "empty"); - runProjectAnalysis(orchestrator, "qualitygate/xoo-sample"); - assertThat(getGateStatusMeasure().getValue()).isEqualTo("OK"); + orchestrator.getServer().associateProjectToQualityProfile(project.getKey(), "xoo", "empty"); + runProjectAnalysis(orchestrator, "qualitygate/xoo-sample", "sonar.projectKey", project.getKey()); + assertThat(getGateStatusMeasure(project).getValue()).isEqualTo("OK"); // Run second analysis with some rules that makes Security Rating to E -> quality gate is red ItUtils.restoreProfile(orchestrator, getClass().getResource("/qualityGate/QualityGateOnRatingMeasuresTest/with-many-rules.xml")); - orchestrator.getServer().associateProjectToQualityProfile(PROJECT_KEY, "xoo", "with-many-rules"); - runProjectAnalysis(orchestrator, "qualitygate/xoo-sample"); - assertThat(getGateStatusMeasure().getValue()).isEqualTo("ERROR"); - } - - private WsMeasures.Measure getGateStatusMeasure() { - return getMeasure(orchestrator, PROJECT_KEY, "alert_status"); + orchestrator.getServer().associateProjectToQualityProfile(project.getKey(), "xoo", "with-many-rules"); + runProjectAnalysis(orchestrator, "qualitygate/xoo-sample", "sonar.projectKey", project.getKey()); + assertThat(getGateStatusMeasure(project).getValue()).isEqualTo("ERROR"); } - private static QualityGateClient qgClient() { - return orchestrator.getServer().adminWsClient().qualityGateClient(); + private WsMeasures.Measure getGateStatusMeasure(Project project) { + return getMeasure(orchestrator, project.getKey(), "alert_status"); } } |