Search in sources :

Example 1 with MetricDto

use of org.sonar.db.metric.MetricDto in project sonarqube by SonarSource.

the class ProjectMeasuresIndexerIteratorTest method does_not_return_disabled_metrics.

@Test
public void does_not_return_disabled_metrics() throws Exception {
    MetricDto disabledMetric = insertMetric("disabled", false, false, INT);
    ComponentDto project = newProjectDto(dbTester.getDefaultOrganization());
    SnapshotDto analysis = dbTester.components().insertProjectAndSnapshot(project);
    insertMeasure(project, analysis, disabledMetric, 10d);
    Map<String, ProjectMeasures> docsById = createResultSetAndReturnDocsById();
    assertThat(docsById.get(project.uuid()).getMeasures().getNumericMeasures()).isEmpty();
}
Also used : MetricDto(org.sonar.db.metric.MetricDto) ProjectMeasures(org.sonar.db.measure.ProjectMeasuresIndexerIterator.ProjectMeasures) SnapshotDto(org.sonar.db.component.SnapshotDto) ComponentDto(org.sonar.db.component.ComponentDto) Test(org.junit.Test)

Example 2 with MetricDto

use of org.sonar.db.metric.MetricDto in project sonarqube by SonarSource.

the class ProjectMeasuresIndexerIteratorTest method return_quality_gate_status_measure.

@Test
public void return_quality_gate_status_measure() throws Exception {
    MetricDto metric = insertMetric("alert_status", LEVEL);
    insertProjectAndMeasure("project1", metric, WARN.name());
    insertProjectAndMeasure("project2", metric, OK.name());
    insertProjectAndMeasure("project3", metric, ERROR.name());
    Map<String, ProjectMeasures> docsById = createResultSetAndReturnDocsById();
    assertThat(docsById.get("project1").getMeasures().getQualityGateStatus()).isEqualTo("WARN");
    assertThat(docsById.get("project2").getMeasures().getQualityGateStatus()).isEqualTo("OK");
    assertThat(docsById.get("project3").getMeasures().getQualityGateStatus()).isEqualTo("ERROR");
}
Also used : MetricDto(org.sonar.db.metric.MetricDto) ProjectMeasures(org.sonar.db.measure.ProjectMeasuresIndexerIterator.ProjectMeasures) Test(org.junit.Test)

Example 3 with MetricDto

use of org.sonar.db.metric.MetricDto in project sonarqube by SonarSource.

the class ProjectMeasuresIndexerIteratorTest method return_project_measure_having_leak.

@Test
public void return_project_measure_having_leak() throws Exception {
    MetricDto metric = insertIntMetric("new_lines");
    ComponentDto project = newProjectDto(dbTester.getDefaultOrganization());
    SnapshotDto analysis = dbTester.components().insertProjectAndSnapshot(project);
    insertMeasureOnLeak(project, analysis, metric, 10d);
    Map<String, ProjectMeasures> docsById = createResultSetAndReturnDocsById();
    assertThat(docsById.get(project.uuid()).getMeasures().getNumericMeasures()).containsOnly(entry("new_lines", 10d));
}
Also used : MetricDto(org.sonar.db.metric.MetricDto) ProjectMeasures(org.sonar.db.measure.ProjectMeasuresIndexerIterator.ProjectMeasures) SnapshotDto(org.sonar.db.component.SnapshotDto) ComponentDto(org.sonar.db.component.ComponentDto) Test(org.junit.Test)

Example 4 with MetricDto

use of org.sonar.db.metric.MetricDto in project sonarqube by SonarSource.

the class ProjectMeasuresIndexerIteratorTest method fail_when_measure_return_no_value.

@Test
public void fail_when_measure_return_no_value() throws Exception {
    MetricDto metric = insertIntMetric("new_lines");
    ComponentDto project = newProjectDto(dbTester.getDefaultOrganization());
    SnapshotDto analysis = dbTester.components().insertProjectAndSnapshot(project);
    insertMeasure(project, analysis, metric, 10d);
    expectedException.expect(IllegalStateException.class);
    createResultSetAndReturnDocsById();
}
Also used : MetricDto(org.sonar.db.metric.MetricDto) SnapshotDto(org.sonar.db.component.SnapshotDto) ComponentDto(org.sonar.db.component.ComponentDto) Test(org.junit.Test)

Example 5 with MetricDto

use of org.sonar.db.metric.MetricDto in project sonarqube by SonarSource.

the class ProjectMeasuresIndexerIteratorTest method return_language_distribution_measure.

@Test
public void return_language_distribution_measure() throws Exception {
    MetricDto metric = insertMetric("ncloc_language_distribution", DATA);
    ComponentDto project = newProjectDto(dbTester.getDefaultOrganization());
    SnapshotDto analysis = dbTester.components().insertProjectAndSnapshot(project);
    insertMeasure(project, analysis, metric, "<null>=2;java=6;xoo=18");
    Map<String, ProjectMeasures> docsById = createResultSetAndReturnDocsById();
    assertThat(docsById.get(project.uuid()).getMeasures().getLanguages()).containsOnly("<null>", "java", "xoo");
}
Also used : MetricDto(org.sonar.db.metric.MetricDto) ProjectMeasures(org.sonar.db.measure.ProjectMeasuresIndexerIterator.ProjectMeasures) SnapshotDto(org.sonar.db.component.SnapshotDto) ComponentDto(org.sonar.db.component.ComponentDto) Test(org.junit.Test)

Aggregations

MetricDto (org.sonar.db.metric.MetricDto)137 Test (org.junit.Test)83 MetricTesting.newMetricDto (org.sonar.db.metric.MetricTesting.newMetricDto)61 ComponentDto (org.sonar.db.component.ComponentDto)49 SnapshotDto (org.sonar.db.component.SnapshotDto)33 CustomMeasureDto (org.sonar.db.measure.custom.CustomMeasureDto)26 DbSession (org.sonar.db.DbSession)11 ComponentTreeWsResponse (org.sonarqube.ws.WsMeasures.ComponentTreeWsResponse)11 CustomMeasureTesting.newCustomMeasureDto (org.sonar.db.measure.custom.CustomMeasureTesting.newCustomMeasureDto)10 MeasureDto (org.sonar.db.measure.MeasureDto)9 OrganizationDto (org.sonar.db.organization.OrganizationDto)8 ProjectMeasures (org.sonar.db.measure.ProjectMeasuresIndexerIterator.ProjectMeasures)7 QualityGateConditionDto (org.sonar.db.qualitygate.QualityGateConditionDto)6 JsonWriter (org.sonar.api.utils.text.JsonWriter)5 WsTester (org.sonar.server.ws.WsTester)5 SearchWsResponse (org.sonarqube.ws.WsMeasures.SearchWsResponse)5 MeasureQuery (org.sonar.db.measure.MeasureQuery)3 UserDto (org.sonar.db.user.UserDto)3 WsMeasures (org.sonarqube.ws.WsMeasures)3 ComponentWsResponse (org.sonarqube.ws.WsMeasures.ComponentWsResponse)3