use of org.sonar.wsclient.qualitygate.QualityGate in project sonarqube by SonarSource.
the class ProjectQualityGatePageTest method should_set_custom.
@Test
public void should_set_custom() {
QualityGate customQualityGate = createCustomQualityGate("should_set_custom");
ProjectQualityGatePage page = openPage();
page.setQualityGate(customQualityGate.name());
SelenideElement selectedQualityGate = page.getSelectedQualityGate();
selectedQualityGate.should(Condition.hasText(customQualityGate.name()));
}
use of org.sonar.wsclient.qualitygate.QualityGate in project sonarqube by SonarSource.
the class QualityGateUiTest method display_alerts_correctly_in_history_page.
/**
* SONAR-3326
*/
@Test
public void display_alerts_correctly_in_history_page() {
QualityGateClient qgClient = qgClient();
QualityGate qGate = qgClient.create("AlertsForHistory");
qgClient.setDefault(qGate.id());
String firstAnalysisDate = DateFormatUtils.ISO_DATE_FORMAT.format(addDays(new Date(), -2));
String secondAnalysisDate = DateFormatUtils.ISO_DATE_FORMAT.format(addDays(new Date(), -1));
// with this configuration, project should have an Orange alert
QualityGateCondition lowThresholds = qgClient.createCondition(NewCondition.create(qGate.id()).metricKey("lines").operator("GT").warningThreshold("5").errorThreshold("50"));
scanSampleWithDate(firstAnalysisDate);
// with this configuration, project should have a Green alert
qgClient.updateCondition(UpdateCondition.create(lowThresholds.id()).metricKey("lines").operator("GT").warningThreshold("5000").errorThreshold("5000"));
scanSampleWithDate(secondAnalysisDate);
ProjectActivityPage page = Navigation.get(orchestrator).openProjectActivity("sample");
page.assertFirstAnalysisOfTheDayHasText(secondAnalysisDate, "Green (was Orange)").assertFirstAnalysisOfTheDayHasText(firstAnalysisDate, "Orange");
qgClient.unsetDefault();
qgClient.destroy(qGate.id());
}
use of org.sonar.wsclient.qualitygate.QualityGate in project sonarqube by SonarSource.
the class QualityGateNotificationTest method status_on_metric_variation_and_send_notifications.
@Test
public void status_on_metric_variation_and_send_notifications() throws Exception {
setServerProperty(orchestrator, "email.smtp_host.secured", "localhost");
setServerProperty(orchestrator, "email.smtp_port.secured", Integer.toString(smtpServer.getServer().getPort()));
// Create user, who will receive notifications for new violations
userRule.createUser("tester", "Tester", "tester@example.org", "tester");
// Send test email to the test user
newAdminWsClient(orchestrator).wsConnector().call(new PostRequest("api/emails/send").setParam("to", "test@example.org").setParam("message", "This is a test message from SonarQube")).failIfNotSuccessful();
// Add notifications to the test user
WsClient wsClient = newUserWsClient(orchestrator, "tester", "tester");
wsClient.wsConnector().call(new PostRequest("api/notifications/add").setParam("type", "NewAlerts").setParam("channel", "EmailNotificationChannel")).failIfNotSuccessful();
// Create quality gate with conditions on variations
QualityGate simple = qgClient().create("SimpleWithDifferential");
qgClient().setDefault(simple.id());
qgClient().createCondition(NewCondition.create(simple.id()).metricKey("ncloc").period(1).operator("EQ").warningThreshold("0"));
SonarScanner analysis = SonarScanner.create(projectDir("qualitygate/xoo-sample"));
orchestrator.executeBuild(analysis);
assertThat(getGateStatusMeasure().getValue()).isEqualTo("OK");
orchestrator.executeBuild(analysis);
assertThat(getGateStatusMeasure().getValue()).isEqualTo("WARN");
qgClient().unsetDefault();
qgClient().destroy(simple.id());
waitUntilAllNotificationsAreDelivered(smtpServer);
Iterator<WiserMessage> emails = smtpServer.getMessages().iterator();
MimeMessage message = emails.next().getMimeMessage();
assertThat(message.getHeader("To", null)).isEqualTo("<test@example.org>");
assertThat((String) message.getContent()).contains("This is a test message from SonarQube");
assertThat(emails.hasNext()).isTrue();
message = emails.next().getMimeMessage();
assertThat(message.getHeader("To", null)).isEqualTo("<tester@example.org>");
assertThat((String) message.getContent()).contains("Quality gate status: Orange (was Green)");
assertThat((String) message.getContent()).contains("Quality gate threshold: Lines of Code variation = 0 since previous analysis");
assertThat((String) message.getContent()).contains("/dashboard/index/sample");
assertThat(emails.hasNext()).isFalse();
}
use of org.sonar.wsclient.qualitygate.QualityGate in project sonarqube by SonarSource.
the class QualityGateTest method test_status_error.
@Test
public void test_status_error() throws IOException {
QualityGate simple = qgClient().create("SimpleWithLowThreshold");
qgClient().setDefault(simple.id());
qgClient().createCondition(NewCondition.create(simple.id()).metricKey("ncloc").operator("GT").errorThreshold("10"));
try {
SonarScanner build = SonarScanner.create(projectDir("qualitygate/xoo-sample"));
BuildResult buildResult = orchestrator.executeBuild(build);
verifyQGStatusInPostTask(buildResult, TASK_STATUS_SUCCESS, QG_STATUS_ERROR);
assertThat(getGateStatusMeasure().getValue()).isEqualTo("ERROR");
} finally {
qgClient().unsetDefault();
qgClient().destroy(simple.id());
}
}
use of org.sonar.wsclient.qualitygate.QualityGate in project sonarqube by SonarSource.
the class QualityGateTest method ad_hoc_build_break_strategy.
@Test
public void ad_hoc_build_break_strategy() throws IOException {
QualityGate simple = qgClient().create("SimpleWithLowThresholdForBuildBreakStrategy");
qgClient().setDefault(simple.id());
qgClient().createCondition(NewCondition.create(simple.id()).metricKey("ncloc").operator("GT").errorThreshold("7"));
try {
File projectDir = projectDir("qualitygate/xoo-sample");
SonarScanner build = SonarScanner.create(projectDir);
BuildResult buildResult = orchestrator.executeBuild(build);
verifyQGStatusInPostTask(buildResult, TASK_STATUS_SUCCESS, QG_STATUS_ERROR);
String taskId = getTaskIdInLocalReport(projectDir);
String analysisId = getAnalysisId(taskId);
ProjectStatusWsResponse projectStatusWsResponse = wsClient.qualityGates().projectStatus(new ProjectStatusWsRequest().setAnalysisId(analysisId));
ProjectStatusWsResponse.ProjectStatus projectStatus = projectStatusWsResponse.getProjectStatus();
assertThat(projectStatus.getStatus()).isEqualTo(ProjectStatusWsResponse.Status.ERROR);
assertThat(projectStatus.getConditionsCount()).isEqualTo(1);
ProjectStatusWsResponse.Condition condition = projectStatus.getConditionsList().get(0);
assertThat(condition.getMetricKey()).isEqualTo("ncloc");
assertThat(condition.getErrorThreshold()).isEqualTo("7");
} finally {
qgClient().unsetDefault();
qgClient().destroy(simple.id());
}
}
Aggregations