Search in sources :

Example 1 with ProjectMeasures

use of org.sonar.db.measure.ProjectMeasuresIndexerIterator.ProjectMeasures in project sonarqube by SonarSource.

the class ProjectMeasuresIndexerIteratorTest method return_project_without_analysis.

@Test
public void return_project_without_analysis() {
    ComponentDto project = dbTester.components().insertPrivateProject();
    dbClient.snapshotDao().insert(dbSession, newAnalysis(project).setLast(false));
    dbSession.commit();
    Map<String, ProjectMeasures> docsById = createResultSetAndReturnDocsById();
    assertThat(docsById).hasSize(1);
    ProjectMeasures doc = docsById.get(project.uuid());
    assertThat(doc.getProject().getAnalysisDate()).isNull();
}
Also used : ProjectMeasures(org.sonar.db.measure.ProjectMeasuresIndexerIterator.ProjectMeasures) ComponentDto(org.sonar.db.component.ComponentDto) Test(org.junit.Test)

Example 2 with ProjectMeasures

use of org.sonar.db.measure.ProjectMeasuresIndexerIterator.ProjectMeasures in project sonarqube by SonarSource.

the class ProjectMeasuresIndexerIteratorTest method return_nothing_on_unknown_project.

@Test
public void return_nothing_on_unknown_project() {
    ComponentDto project = dbTester.components().insertPrivateProject();
    dbTester.components().insertSnapshot(project);
    Map<String, ProjectMeasures> docsById = createResultSetAndReturnDocsById("UNKNOWN");
    assertThat(docsById).isEmpty();
}
Also used : ProjectMeasures(org.sonar.db.measure.ProjectMeasuresIndexerIterator.ProjectMeasures) ComponentDto(org.sonar.db.component.ComponentDto) Test(org.junit.Test)

Example 3 with ProjectMeasures

use of org.sonar.db.measure.ProjectMeasuresIndexerIterator.ProjectMeasures in project sonarqube by SonarSource.

the class ProjectMeasuresIndexerIteratorTest method return_project_measure_having_leak.

@Test
public void return_project_measure_having_leak() {
    ComponentDto project = dbTester.components().insertPrivateProject(c -> c.setDbKey("Project-Key").setName("Project Name"), p -> p.setTagsString("platform,java"));
    MetricDto metric = dbTester.measures().insertMetric(m -> m.setValueType(INT.name()).setKey("new_lines"));
    dbTester.measures().insertLiveMeasure(project, metric, m -> m.setVariation(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) ComponentDto(org.sonar.db.component.ComponentDto) Test(org.junit.Test)

Example 4 with ProjectMeasures

use of org.sonar.db.measure.ProjectMeasuresIndexerIterator.ProjectMeasures in project sonarqube by SonarSource.

the class ProjectMeasuresIndexerIteratorTest method return_application_measure.

@Test
public void return_application_measure() {
    ComponentDto project = dbTester.components().insertPrivateApplication(c -> c.setDbKey("App-Key").setName("App Name"));
    SnapshotDto analysis = dbTester.components().insertSnapshot(project);
    MetricDto metric1 = dbTester.measures().insertMetric(m -> m.setValueType(INT.name()).setKey("ncloc"));
    MetricDto metric2 = dbTester.measures().insertMetric(m -> m.setValueType(INT.name()).setKey("coverage"));
    dbTester.measures().insertLiveMeasure(project, metric1, m -> m.setValue(10d));
    dbTester.measures().insertLiveMeasure(project, metric2, m -> m.setValue(20d));
    Map<String, ProjectMeasures> docsById = createResultSetAndReturnDocsById();
    assertThat(docsById).hasSize(1);
    ProjectMeasures doc = docsById.get(project.uuid());
    assertThat(doc).isNotNull();
    assertThat(doc.getProject().getUuid()).isEqualTo(project.uuid());
    assertThat(doc.getProject().getKey()).isEqualTo("App-Key");
    assertThat(doc.getProject().getName()).isEqualTo("App Name");
    assertThat(doc.getProject().getAnalysisDate()).isNotNull().isEqualTo(analysis.getCreatedAt());
    assertThat(doc.getMeasures().getNumericMeasures()).containsOnly(entry(metric1.getKey(), 10d), entry(metric2.getKey(), 20d));
}
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 5 with ProjectMeasures

use of org.sonar.db.measure.ProjectMeasuresIndexerIterator.ProjectMeasures in project sonarqube by SonarSource.

the class ProjectMeasuresIndexerIteratorTest method return_language_distribution_measure.

@Test
public void return_language_distribution_measure() {
    ComponentDto project = dbTester.components().insertPrivateProject();
    MetricDto metric = dbTester.measures().insertMetric(m -> m.setValueType(DATA.name()).setKey("ncloc_language_distribution"));
    dbTester.measures().insertLiveMeasure(project, metric, m -> m.setValue(null).setData("<null>=2;java=6;xoo=18"));
    Map<String, ProjectMeasures> docsById = createResultSetAndReturnDocsById();
    assertThat(docsById.get(project.uuid()).getMeasures().getNclocByLanguages()).containsOnly(entry("<null>", 2), entry("java", 6), entry("xoo", 18));
}
Also used : MetricDto(org.sonar.db.metric.MetricDto) ProjectMeasures(org.sonar.db.measure.ProjectMeasuresIndexerIterator.ProjectMeasures) ComponentDto(org.sonar.db.component.ComponentDto) Test(org.junit.Test)

Aggregations

ProjectMeasures (org.sonar.db.measure.ProjectMeasuresIndexerIterator.ProjectMeasures)14 Test (org.junit.Test)12 ComponentDto (org.sonar.db.component.ComponentDto)12 MetricDto (org.sonar.db.metric.MetricDto)9 SnapshotDto (org.sonar.db.component.SnapshotDto)3 DbSession (org.sonar.db.DbSession)1 ProjectMeasuresIndexerIterator (org.sonar.db.measure.ProjectMeasuresIndexerIterator)1 BulkIndexer (org.sonar.server.es.BulkIndexer)1