use of org.sonar.server.measure.ws.SearchHistoryAction.SearchHistoryRequest in project sonarqube by SonarSource.
the class SearchHistoryActionTest method pagination_applies_to_analyses.
@Test
public void pagination_applies_to_analyses() {
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(i * 1_000_000_000))).peek(a -> dbClient.measureDao().insert(dbSession, newMeasureDto(complexityMetric, project, a).setValue(101d))).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())).setPage(2).setPageSize(3).build();
SearchHistoryResponse result = call(request);
assertThat(result.getPaging()).extracting(Paging::getPageIndex, Paging::getPageSize, Paging::getTotal).containsExactly(2, 3, 9);
assertThat(result.getMeasures(0).getHistoryList()).extracting(HistoryValue::getDate).containsExactly(analysisDates.get(3), analysisDates.get(4), analysisDates.get(5));
}
use of org.sonar.server.measure.ws.SearchHistoryAction.SearchHistoryRequest in project sonarqube by SonarSource.
the class SearchHistoryActionTest method return_best_values_for_files.
@Test
public void return_best_values_for_files() {
dbClient.metricDao().insert(dbSession, newMetricDto().setKey("optimized").setValueType(ValueType.INT.name()).setOptimizedBestValue(true).setBestValue(456d));
dbClient.metricDao().insert(dbSession, newMetricDto().setKey("new_optimized").setValueType(ValueType.INT.name()).setOptimizedBestValue(true).setBestValue(789d));
db.commit();
ComponentDto file = db.components().insertComponent(newFileDto(project));
SearchHistoryRequest request = SearchHistoryRequest.builder().setComponent(file.getDbKey()).setMetrics(asList("optimized", "new_optimized")).build();
SearchHistoryResponse result = call(request);
assertThat(result.getMeasuresCount()).isEqualTo(2);
assertThat(result.getMeasuresList().get(0).getHistoryList()).extracting(HistoryValue::getValue).containsExactly("789");
assertThat(result.getMeasuresList().get(1).getHistoryList()).extracting(HistoryValue::getValue).containsExactly("456");
// Best value is not applied to project
request = SearchHistoryRequest.builder().setComponent(project.getDbKey()).setMetrics(asList("optimized", "new_optimized")).build();
result = call(request);
assertThat(result.getMeasuresList().get(0).getHistoryCount()).isOne();
assertThat(result.getMeasuresList().get(0).getHistory(0).hasDate()).isTrue();
assertThat(result.getMeasuresList().get(0).getHistory(0).hasValue()).isFalse();
}
use of org.sonar.server.measure.ws.SearchHistoryAction.SearchHistoryRequest in project sonarqube by SonarSource.
the class SearchHistoryActionTest method fail_if_not_enough_permissions_for_application.
@Test
public void fail_if_not_enough_permissions_for_application() {
ComponentDto application = db.components().insertPrivateApplication();
ComponentDto project1 = db.components().insertPrivateProject();
ComponentDto project2 = db.components().insertPrivateProject();
userSession.logIn().registerApplication(toProjectDto(application, 1L), toProjectDto(project1, 1L), toProjectDto(project2, 1L)).addProjectPermission(UserRole.USER, application, project1);
SearchHistoryRequest request = SearchHistoryRequest.builder().setComponent(application.getDbKey()).setMetrics(singletonList(complexityMetric.getKey())).build();
assertThatThrownBy(() -> call(request)).isInstanceOf(ForbiddenException.class);
}
Aggregations