use of org.sonar.server.qualitygate.QualityGate in project sonarqube by SonarSource.
the class WebhookPayloadFactoryImplTest method create_payload_for_successful_analysis.
@Test
public void create_payload_for_successful_analysis() {
CeTask task = new CeTask("#1", CeTask.Status.SUCCESS);
Condition condition = new Condition("coverage", Condition.Operator.GREATER_THAN, "70.0");
EvaluatedQualityGate gate = EvaluatedQualityGate.newBuilder().setQualityGate(new QualityGate("G1", "Gate One", singleton(condition))).setStatus(Metric.Level.ERROR).addEvaluatedCondition(condition, EvaluatedCondition.EvaluationStatus.ERROR, "74.0").build();
ProjectAnalysis analysis = newAnalysis(task, gate, null, 1_500_000_000_000L, emptyMap());
WebhookPayload payload = underTest.create(analysis);
assertThat(payload.getProjectKey()).isEqualTo(PROJECT_KEY);
assertJson(payload.getJson()).isSimilarTo("{" + " \"serverUrl\": \"http://foo\"," + " \"taskId\": \"#1\"," + " \"status\": \"SUCCESS\"," + " \"analysedAt\": \"2017-07-14T04:40:00+0200\"," + " \"revision\": \"sha1\"," + " \"changedAt\": \"2017-07-14T04:40:00+0200\"," + " \"project\": {" + " \"key\": \"P1\"," + " \"name\": \"Project One\"," + " \"url\": \"http://foo/dashboard?id=P1\"" + " }," + " \"qualityGate\": {" + " \"name\": \"Gate One\"," + " \"status\": \"ERROR\"," + " \"conditions\": [" + " {" + " \"metric\": \"coverage\"," + " \"operator\": \"GREATER_THAN\"," + " \"value\": \"74.0\"," + " \"status\": \"ERROR\"," + " \"errorThreshold\": \"70.0\"" + " }" + " ]" + " }," + " \"properties\": {" + " }" + "}");
}
use of org.sonar.server.qualitygate.QualityGate in project sonarqube by SonarSource.
the class WebhookPayloadFactoryImplTest method create_payload_with_gate_conditions_without_value.
@Test
public void create_payload_with_gate_conditions_without_value() {
CeTask task = new CeTask("#1", CeTask.Status.SUCCESS);
Condition condition = new Condition("coverage", Condition.Operator.GREATER_THAN, "70.0");
EvaluatedQualityGate gate = EvaluatedQualityGate.newBuilder().setQualityGate(new QualityGate("G1", "Gate One", singleton(condition))).setStatus(Metric.Level.ERROR).addEvaluatedCondition(condition, EvaluatedCondition.EvaluationStatus.NO_VALUE, null).build();
ProjectAnalysis analysis = newAnalysis(task, gate, null, 1_500_000_000_000L, emptyMap());
WebhookPayload payload = underTest.create(analysis);
assertThat(payload.getProjectKey()).isEqualTo(PROJECT_KEY);
assertJson(payload.getJson()).isSimilarTo("{" + " \"serverUrl\": \"http://foo\"," + " \"taskId\": \"#1\"," + " \"status\": \"SUCCESS\"," + " \"analysedAt\": \"2017-07-14T04:40:00+0200\"," + " \"revision\": \"sha1\"," + " \"changedAt\": \"2017-07-14T04:40:00+0200\"," + " \"project\": {" + " \"key\": \"P1\"," + " \"name\": \"Project One\"," + " \"url\": \"http://foo/dashboard?id=P1\"" + " }," + " \"qualityGate\": {" + " \"name\": \"Gate One\"," + " \"status\": \"ERROR\"," + " \"conditions\": [" + " {" + " \"metric\": \"coverage\"," + " \"operator\": \"GREATER_THAN\"," + " \"status\": \"NO_VALUE\"," + " \"errorThreshold\": \"70.0\"" + " }" + " ]" + " }" + "}");
}
use of org.sonar.server.qualitygate.QualityGate in project sonarqube by SonarSource.
the class WebhookPayloadFactoryImplTest method create_payload_with_analysis_properties.
@Test
public void create_payload_with_analysis_properties() {
CeTask task = new CeTask("#1", CeTask.Status.SUCCESS);
EvaluatedQualityGate gate = EvaluatedQualityGate.newBuilder().setQualityGate(new QualityGate("G1", "Gate One", emptySet())).setStatus(Metric.Level.ERROR).build();
Map<String, String> scannerProperties = ImmutableMap.of("sonar.analysis.foo", "bar", "sonar.analysis.buildNumber", "B123", "not.prefixed.with.sonar.analysis", "should be ignored", "ignored", "should be ignored too");
ProjectAnalysis analysis = newAnalysis(task, gate, null, 1_500_000_000_000L, scannerProperties);
WebhookPayload payload = underTest.create(analysis);
assertJson(payload.getJson()).isSimilarTo("{" + " \"serverUrl\": \"http://foo\"," + " \"taskId\": \"#1\"," + " \"status\": \"SUCCESS\"," + " \"analysedAt\": \"2017-07-14T04:40:00+0200\"," + " \"revision\": \"sha1\"," + " \"changedAt\": \"2017-07-14T04:40:00+0200\"," + " \"project\": {" + " \"key\": \"P1\"," + " \"name\": \"Project One\"," + " \"url\": \"http://foo/dashboard?id=P1\"" + " }," + " \"qualityGate\": {" + " \"name\": \"Gate One\"," + " \"status\": \"ERROR\"," + " \"conditions\": [" + " ]" + " }," + " \"properties\": {" + " \"sonar.analysis.foo\": \"bar\"," + " \"sonar.analysis.buildNumber\": \"B123\"" + " }" + "}");
assertThat(payload.getJson()).doesNotContain("not.prefixed.with.sonar.analysis").doesNotContain("ignored");
}
use of org.sonar.server.qualitygate.QualityGate in project sonarqube by SonarSource.
the class ProjectAnalysisTest method defines_equals_based_on_all_fields.
@Test
public void defines_equals_based_on_all_fields() {
assertThat(underTest).isEqualTo(underTest).isEqualTo(new ProjectAnalysis(project, ceTask, analysis, branch, qualityGate, 1L, properties)).isNotNull().isNotEqualTo(new Object()).isNotEqualTo(new ProjectAnalysis(project, new CeTask("2", CeTask.Status.SUCCESS), analysis, branch, qualityGate, 1L, properties)).isNotEqualTo(new ProjectAnalysis(new Project("A", "B", "C"), ceTask, analysis, branch, qualityGate, 1L, properties)).isNotEqualTo(new ProjectAnalysis(new Project("A", "B", "C"), ceTask, analysis, branch, qualityGate, 1L, properties)).isNotEqualTo(new ProjectAnalysis(project, null, null, null, qualityGate, 1L, properties)).isNotEqualTo(new ProjectAnalysis(project, ceTask, null, null, qualityGate, 1L, properties)).isNotEqualTo(new ProjectAnalysis(project, ceTask, new Analysis("foo", 1_500L, "sha1"), null, qualityGate, 1L, properties)).isNotEqualTo(new ProjectAnalysis(project, ceTask, analysis, null, qualityGate, 1L, properties)).isNotEqualTo(new ProjectAnalysis(project, ceTask, analysis, new Branch(false, "B", Branch.Type.BRANCH), qualityGate, 1L, properties)).isNotEqualTo(new ProjectAnalysis(project, ceTask, analysis, branch, null, 1L, properties));
EvaluatedQualityGate otherQualityGate = EvaluatedQualityGate.newBuilder().setQualityGate(new QualityGate("A", "B", emptySet())).setStatus(Metric.Level.ERROR).build();
assertThat(underTest).isNotEqualTo(new ProjectAnalysis(project, ceTask, analysis, branch, otherQualityGate, 1L, properties));
assertThat(underTest).isNotEqualTo(new ProjectAnalysis(project, ceTask, analysis, branch, qualityGate, null, properties));
assertThat(underTest).isNotEqualTo(new ProjectAnalysis(project, ceTask, analysis, branch, qualityGate, 2L, properties));
assertThat(underTest).isNotEqualTo(new ProjectAnalysis(project, ceTask, analysis, branch, qualityGate, 1L, emptyMap()));
assertThat(underTest).isNotEqualTo(new ProjectAnalysis(project, ceTask, analysis, branch, qualityGate, 1L, ImmutableMap.of("A", "B")));
}
use of org.sonar.server.qualitygate.QualityGate in project sonarqube by SonarSource.
the class LiveQualityGateComputerImplTest method getMetricsRelatedTo.
@Test
public void getMetricsRelatedTo() {
Condition condition = new Condition("metric1", Condition.Operator.GREATER_THAN, "10");
QualityGate gate = new QualityGate("1", "foo", ImmutableSet.of(condition));
Set<String> result = underTest.getMetricsRelatedTo(gate);
assertThat(result).containsExactlyInAnyOrder(// the metrics needed to compute the status of gate
condition.getMetricKey(), // generated metrics
CoreMetrics.ALERT_STATUS_KEY, CoreMetrics.QUALITY_GATE_DETAILS_KEY);
}
Aggregations