use of org.sonarqube.ws.Measures.SearchHistoryResponse in project sonarqube by SonarSource.
the class SearchHistoryAction method handle.
@Override
public void handle(Request request, Response response) throws Exception {
SearchHistoryResponse searchHistoryResponse = Stream.of(request).map(SearchHistoryAction::toWsRequest).map(search()).map(result -> new SearchHistoryResponseFactory(result).apply()).collect(MoreCollectors.toOneElement());
writeProtobuf(searchHistoryResponse, request, response);
}
use of org.sonarqube.ws.Measures.SearchHistoryResponse in project sonarqube by SonarSource.
the class SearchHistoryActionTest method analyses_but_no_measure.
@Test
public void analyses_but_no_measure() {
project = db.components().insertPrivateProject();
analysis = db.components().insertSnapshot(project);
userSession.addProjectPermission(UserRole.USER, project);
SearchHistoryRequest request = SearchHistoryRequest.builder().setComponent(project.getDbKey()).setMetrics(singletonList(complexityMetric.getKey())).build();
SearchHistoryResponse result = call(request);
assertThat(result.getPaging()).extracting(Paging::getPageIndex, Paging::getPageSize, Paging::getTotal).containsExactly(1, 100, 1);
assertThat(result.getMeasuresList()).hasSize(1);
assertThat(result.getMeasures(0).getHistoryList()).extracting(HistoryValue::hasDate, HistoryValue::hasValue).containsExactly(tuple(true, false));
}
use of org.sonarqube.ws.Measures.SearchHistoryResponse in project sonarqube by SonarSource.
the class SearchHistoryActionTest method branch.
@Test
public void branch() {
ComponentDto project = db.components().insertPrivateProject();
userSession.addProjectPermission(UserRole.USER, project);
ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey("my_branch"));
ComponentDto file = db.components().insertComponent(newFileDto(branch));
SnapshotDto analysis = db.components().insertSnapshot(branch);
MeasureDto measure = db.measures().insertMeasure(file, analysis, nclocMetric, m -> m.setValue(2d));
SearchHistoryResponse result = ws.newRequest().setParam(PARAM_COMPONENT, file.getKey()).setParam(PARAM_BRANCH, "my_branch").setParam(PARAM_METRICS, "ncloc").executeProtobuf(SearchHistoryResponse.class);
assertThat(result.getMeasuresList()).extracting(HistoryMeasure::getMetric).hasSize(1);
HistoryMeasure historyMeasure = result.getMeasures(0);
assertThat(historyMeasure.getMetric()).isEqualTo(nclocMetric.getKey());
assertThat(historyMeasure.getHistoryList()).extracting(m -> parseDouble(m.getValue())).containsExactlyInAnyOrder(measure.getValue());
}
use of org.sonarqube.ws.Measures.SearchHistoryResponse 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();
SearchHistoryRequest request = SearchHistoryRequest.builder().setComponent(project.getDbKey()).setMetrics(asList(complexityMetric.getKey(), nclocMetric.getKey(), newViolationMetric.getKey())).build();
SearchHistoryResponse result = call(request);
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, HistoryValue::hasValue).containsExactly(tuple(analysisDate, "201", true), tuple(laterAnalysisDate, "", false));
// 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"));
}
use of org.sonarqube.ws.Measures.SearchHistoryResponse in project sonarqube by SonarSource.
the class SearchHistoryActionTest method inclusive_from_and_to_dates.
@Test
public void inclusive_from_and_to_dates() {
project = db.components().insertPrivateProject();
userSession.addProjectPermission(UserRole.USER, project);
List<String> analysisDates = LongStream.rangeClosed(1, 9).mapToObj(i -> dbClient.snapshotDao().insert(dbSession, newAnalysis(project).setCreatedAt(System2.INSTANCE.now() + i * 1_000_000_000L))).peek(a -> dbClient.measureDao().insert(dbSession, newMeasureDto(complexityMetric, project, a).setValue(Double.valueOf(a.getCreatedAt())))).map(a -> formatDateTime(a.getCreatedAt())).collect(MoreCollectors.toList());
db.commit();
SearchHistoryRequest request = SearchHistoryRequest.builder().setComponent(project.getDbKey()).setMetrics(asList(complexityMetric.getKey(), nclocMetric.getKey(), newViolationMetric.getKey())).setFrom(analysisDates.get(1)).setTo(analysisDates.get(3)).build();
SearchHistoryResponse result = call(request);
assertThat(result.getPaging()).extracting(Paging::getPageIndex, Paging::getPageSize, Paging::getTotal).containsExactly(1, 100, 3);
assertThat(result.getMeasures(0).getHistoryList()).extracting(HistoryValue::getDate).containsExactly(analysisDates.get(1), analysisDates.get(2), analysisDates.get(3));
}
Aggregations