Search in sources :

Example 1 with HistoryMeasure

use of org.sonarqube.ws.WsMeasures.SearchHistoryResponse.HistoryMeasure in project sonarqube by SonarSource.

the class SearchHistoryActionTest method return_measures.

@Test
public void return_measures() {
    SnapshotDto laterAnalysis = dbClient.snapshotDao().insert(dbSession, newAnalysis(project).setCreatedAt(analysis.getCreatedAt() + 42_000));
    ComponentDto file = db.components().insertComponent(newFileDto(project));
    dbClient.measureDao().insert(dbSession, newMeasureDto(complexityMetric, project, analysis).setValue(101d), newMeasureDto(complexityMetric, project, laterAnalysis).setValue(100d), newMeasureDto(complexityMetric, file, analysis).setValue(42d), newMeasureDto(nclocMetric, project, analysis).setValue(201d), newMeasureDto(newViolationMetric, project, analysis).setVariation(5d), newMeasureDto(newViolationMetric, project, laterAnalysis).setVariation(10d));
    db.commit();
    SearchHistoryResponse result = call();
    assertThat(result.getPaging()).extracting(Paging::getPageIndex, Paging::getPageSize, Paging::getTotal).containsExactly(1, 100, 2);
    assertThat(result.getMeasuresList()).extracting(HistoryMeasure::getMetric).hasSize(3).containsExactly(complexityMetric.getKey(), nclocMetric.getKey(), newViolationMetric.getKey());
    String analysisDate = formatDateTime(analysis.getCreatedAt());
    String laterAnalysisDate = formatDateTime(laterAnalysis.getCreatedAt());
    // complexity measures
    HistoryMeasure complexityMeasures = result.getMeasures(0);
    assertThat(complexityMeasures.getMetric()).isEqualTo(complexityMetric.getKey());
    assertThat(complexityMeasures.getHistoryList()).extracting(HistoryValue::getDate, HistoryValue::getValue).containsExactly(tuple(analysisDate, "101"), tuple(laterAnalysisDate, "100"));
    // ncloc measures
    HistoryMeasure nclocMeasures = result.getMeasures(1);
    assertThat(nclocMeasures.getMetric()).isEqualTo(nclocMetric.getKey());
    assertThat(nclocMeasures.getHistoryList()).extracting(HistoryValue::getDate, HistoryValue::getValue).containsExactly(tuple(analysisDate, "201"));
    // new_violation measures
    HistoryMeasure newViolationMeasures = result.getMeasures(2);
    assertThat(newViolationMeasures.getMetric()).isEqualTo(newViolationMetric.getKey());
    assertThat(newViolationMeasures.getHistoryList()).extracting(HistoryValue::getDate, HistoryValue::getValue).containsExactly(tuple(analysisDate, "5"), tuple(laterAnalysisDate, "10"));
}
Also used : SnapshotDto(org.sonar.db.component.SnapshotDto) SearchHistoryResponse(org.sonarqube.ws.WsMeasures.SearchHistoryResponse) ComponentDto(org.sonar.db.component.ComponentDto) HistoryMeasure(org.sonarqube.ws.WsMeasures.SearchHistoryResponse.HistoryMeasure) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)1 ComponentDto (org.sonar.db.component.ComponentDto)1 SnapshotDto (org.sonar.db.component.SnapshotDto)1 SearchHistoryResponse (org.sonarqube.ws.WsMeasures.SearchHistoryResponse)1 HistoryMeasure (org.sonarqube.ws.WsMeasures.SearchHistoryResponse.HistoryMeasure)1