use of org.sonar.server.qualitygate.EvaluatedQualityGate in project sonarqube by SonarSource.
the class WebhookPostTask method convert.
private static org.sonar.server.webhook.ProjectAnalysis convert(ProjectAnalysis projectAnalysis) {
CeTask ceTask = new CeTask(projectAnalysis.getCeTask().getId(), CeTask.Status.valueOf(projectAnalysis.getCeTask().getStatus().name()));
Analysis analysis = projectAnalysis.getAnalysis().map(a -> new Analysis(a.getAnalysisUuid(), a.getDate().getTime(), a.getRevision().orElse(null))).orElse(null);
Branch branch = projectAnalysis.getBranch().map(b -> new Branch(b.isMain(), b.getName().orElse(null), Branch.Type.valueOf(b.getType().name()))).orElse(null);
EvaluatedQualityGate qualityGate = Optional.ofNullable(projectAnalysis.getQualityGate()).map(QGToEvaluatedQG.INSTANCE).orElse(null);
Long date = projectAnalysis.getAnalysis().map(a -> a.getDate().getTime()).orElse(null);
Map<String, String> properties = projectAnalysis.getScannerContext().getProperties();
Project project = new Project(projectAnalysis.getProject().getUuid(), projectAnalysis.getProject().getKey(), projectAnalysis.getProject().getName());
return new org.sonar.server.webhook.ProjectAnalysis(project, ceTask, analysis, branch, qualityGate, date, properties);
}
use of org.sonar.server.qualitygate.EvaluatedQualityGate 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.EvaluatedQualityGate 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.EvaluatedQualityGate 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.EvaluatedQualityGate 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")));
}
Aggregations