Skip to content

Commit

Permalink
Add category qualityGate to integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Brandhof authored and ehartmann committed Nov 14, 2017
1 parent 522c9d8 commit da5a35e
Show file tree
Hide file tree
Showing 12 changed files with 141 additions and 51 deletions.
1 change: 1 addition & 0 deletions cix.sh
Expand Up @@ -35,6 +35,7 @@ case "$RUN_ACTIVITY" in
CATEGORY=Category1 && runCategory
CATEGORY=authorization && runCategory
CATEGORY=measure && runCategory
CATEGORY=qualityGate && runCategory
CATEGORY=source && runCategory
;;

Expand Down
9 changes: 0 additions & 9 deletions tests/src/test/java/org/sonarqube/tests/Category1Suite.java
Expand Up @@ -29,10 +29,6 @@
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;
Expand All @@ -57,11 +53,6 @@
EmailsTest.class,
PropertySetsTest.class,
SettingsTest.class,
// quality gate
QualityGateTest.class,
QualityGateUiTest.class,
QualityGateNotificationTest.class,
QualityGateOnRatingMeasuresTest.class,
// measure
ProjectsPageTest.class
})
Expand Down
4 changes: 0 additions & 4 deletions tests/src/test/java/org/sonarqube/tests/Category6Suite.java
Expand Up @@ -37,10 +37,8 @@
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;
Expand All @@ -57,8 +55,6 @@
OrganizationIdentityProviderTest.class,
OrganizationIssueAssignTest.class,
OrganizationIssuesPageTest.class,
OrganizationQualityGateUiTest.class,
OrganizationQualityProfilesUiTest.class,
BuiltInQualityProfilesTest.class,
QualityProfilesEditTest.class,
QualityProfilesWsTest.class,
Expand Down
Expand Up @@ -30,7 +30,6 @@
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;
Expand All @@ -49,10 +48,10 @@
import static util.ItUtils.getMeasure;
import static util.ItUtils.projectDir;

public class QualityGateForSmallChangesetsTest {
public class OrganizationQualityGateForSmallChangesetsTest {

@ClassRule
public static Orchestrator orchestrator = Category6Suite.ORCHESTRATOR;
public static Orchestrator orchestrator = OrganizationQualityGateSuite.ORCHESTRATOR;

@Rule
public Tester tester = new Tester(orchestrator);
Expand Down Expand Up @@ -89,7 +88,7 @@ public void do_not_fail_quality_gate_with_poor_LEAK_coverage_and_a_max_of_19_lin
.setDebugLogs(true);
orchestrator.executeBuild(analysis);
assertThat(getMeasure(orchestrator, project.getKey(), "alert_status").getValue()).isEqualTo("OK");
assertIgnoredConditions(project, "qualitygate/small-changesets/v1-1000-lines", false);
assertIgnoredConditions("qualitygate/small-changesets/v1-1000-lines", false);

// small leak => ignore coverage warning or error
SonarScanner analysis2 = SonarScanner
Expand All @@ -104,7 +103,7 @@ public void do_not_fail_quality_gate_with_poor_LEAK_coverage_and_a_max_of_19_lin
.setDebugLogs(true);
orchestrator.executeBuild(analysis2);
assertThat(getMeasure(orchestrator, project.getKey(), "alert_status").getValue()).isEqualTo("OK");
assertIgnoredConditions(project, "qualitygate/small-changesets/v2-1019-lines", true);
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()
Expand All @@ -127,7 +126,7 @@ public void do_not_fail_quality_gate_with_poor_LEAK_coverage_and_a_max_of_19_lin
.setDebugLogs(true);
orchestrator.executeBuild(analysis3);
assertThat(getMeasure(orchestrator, project.getKey(), "alert_status").getValue()).isEqualTo("OK");
assertIgnoredConditions(project, "qualitygate/small-changesets/v2-1019-lines", false);
assertIgnoredConditions("qualitygate/small-changesets/v2-1019-lines", false);

// big leak => use usual behaviour
tester.wsClient().qualityGates().updateCondition(UpdateConditionRequest.builder()
Expand All @@ -150,10 +149,10 @@ public void do_not_fail_quality_gate_with_poor_LEAK_coverage_and_a_max_of_19_lin
.setDebugLogs(true);
orchestrator.executeBuild(analysis4);
assertThat(getMeasure(orchestrator, project.getKey(), "alert_status").getValue()).isEqualTo("ERROR");
assertIgnoredConditions(project, "qualitygate/small-changesets/v2-1020-lines", false);
assertIgnoredConditions("qualitygate/small-changesets/v2-1020-lines", false);
}

private void assertIgnoredConditions(Project project, String projectDir, boolean expected) throws IOException {
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))
Expand Down
@@ -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();

}
Expand Up @@ -25,7 +25,6 @@
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;
Expand All @@ -39,10 +38,10 @@
import static org.assertj.core.api.Assertions.assertThat;
import static util.ItUtils.projectDir;

public class QualityGateWithOrganizationsTest {
public class OrganizationQualityGateTest {

@ClassRule
public static Orchestrator orchestrator = Category6Suite.ORCHESTRATOR;
public static Orchestrator orchestrator = OrganizationQualityGateSuite.ORCHESTRATOR;

@Rule
public Tester tester = new Tester(orchestrator);
Expand Down
Expand Up @@ -27,22 +27,21 @@
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);
Expand Down
Expand Up @@ -28,7 +28,6 @@
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;
Expand All @@ -45,31 +44,33 @@
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();
}
}

@Test
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"));
Expand Down Expand Up @@ -98,9 +99,9 @@ public void status_on_metric_variation_and_send_notifications() throws Exception
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>");
Expand Down
Expand Up @@ -23,7 +23,6 @@
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;
Expand All @@ -38,10 +37,12 @@
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 {
Expand Down
@@ -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();

}
Expand Up @@ -42,9 +42,8 @@
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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -348,7 +349,7 @@ private Measure getGateStatusMeasure(String projectKey) {
return getMeasure(orchestrator, projectKey, "alert_status");
}

private static QualityGateClient qgClient() {
private QualityGateClient qgClient() {
return orchestrator.getServer().adminWsClient().qualityGateClient();
}

Expand Down

0 comments on commit da5a35e

Please sign in to comment.