use of org.sonarqube.ws.WsMeasures.ComponentTreeWsResponse in project sonarqube by SonarSource.
the class ComponentTreeActionTest method load_developer_descendants.
@Test
public void load_developer_descendants() {
ComponentDto project = newProjectDto(db.getDefaultOrganization(), "project-uuid").setKey("project-key");
componentDb.insertProjectAndSnapshot(project);
ComponentDto developer = newDeveloper(db.getDefaultOrganization(), "developer", "developer-uuid");
componentDb.insertDeveloperAndSnapshot(developer);
componentDb.insertComponent(newDevProjectCopy("project-uuid-copy", project, developer));
insertNclocMetric();
db.commit();
ComponentTreeWsResponse response = call(ws.newRequest().setParam(PARAM_BASE_COMPONENT_ID, developer.uuid()).setParam(PARAM_METRIC_KEYS, "ncloc"));
assertThat(response.getComponentsCount()).isEqualTo(1);
WsMeasures.Component projectCopy = response.getComponents(0);
assertThat(projectCopy.getId()).isEqualTo("project-uuid-copy");
assertThat(projectCopy.getRefId()).isEqualTo("project-uuid");
assertThat(projectCopy.getRefKey()).isEqualTo("project-key");
}
use of org.sonarqube.ws.WsMeasures.ComponentTreeWsResponse in project sonarqube by SonarSource.
the class ComponentTreeActionTest method load_measures_multi_sort_with_metric_key_and_paginated.
@Test
public void load_measures_multi_sort_with_metric_key_and_paginated() {
ComponentDto projectDto = newProjectDto(db.getDefaultOrganization(), "project-uuid");
SnapshotDto projectSnapshot = componentDb.insertProjectAndSnapshot(projectDto);
ComponentDto file9 = componentDb.insertComponent(newFileDto(projectDto, null, "file-uuid-9").setName("file-1"));
ComponentDto file8 = componentDb.insertComponent(newFileDto(projectDto, null, "file-uuid-8").setName("file-1"));
ComponentDto file7 = componentDb.insertComponent(newFileDto(projectDto, null, "file-uuid-7").setName("file-1"));
ComponentDto file6 = componentDb.insertComponent(newFileDto(projectDto, null, "file-uuid-6").setName("file-1"));
ComponentDto file5 = componentDb.insertComponent(newFileDto(projectDto, null, "file-uuid-5").setName("file-1"));
ComponentDto file4 = componentDb.insertComponent(newFileDto(projectDto, null, "file-uuid-4").setName("file-1"));
ComponentDto file3 = componentDb.insertComponent(newFileDto(projectDto, null, "file-uuid-3").setName("file-1"));
ComponentDto file2 = componentDb.insertComponent(newFileDto(projectDto, null, "file-uuid-2").setName("file-1"));
ComponentDto file1 = componentDb.insertComponent(newFileDto(projectDto, null, "file-uuid-1").setName("file-1"));
MetricDto coverage = insertCoverageMetric();
dbClient.measureDao().insert(dbSession, newMeasureDto(coverage, file1, projectSnapshot).setValue(1.0d), newMeasureDto(coverage, file2, projectSnapshot).setValue(2.0d), newMeasureDto(coverage, file3, projectSnapshot).setValue(3.0d), newMeasureDto(coverage, file4, projectSnapshot).setValue(4.0d), newMeasureDto(coverage, file5, projectSnapshot).setValue(5.0d), newMeasureDto(coverage, file6, projectSnapshot).setValue(6.0d), newMeasureDto(coverage, file7, projectSnapshot).setValue(7.0d), newMeasureDto(coverage, file8, projectSnapshot).setValue(8.0d), newMeasureDto(coverage, file9, projectSnapshot).setValue(9.0d));
db.commit();
ComponentTreeWsResponse response = call(ws.newRequest().setParam(PARAM_BASE_COMPONENT_ID, "project-uuid").setParam(Param.SORT, NAME_SORT + ", " + METRIC_SORT).setParam(PARAM_METRIC_SORT, "coverage").setParam(PARAM_METRIC_KEYS, "coverage").setParam(PARAM_STRATEGY, "leaves").setParam(PARAM_QUALIFIERS, "FIL,UTS").setParam(Param.PAGE, "2").setParam(Param.PAGE_SIZE, "3"));
assertThat(response.getComponentsList()).extracting("id").containsExactly("file-uuid-4", "file-uuid-5", "file-uuid-6");
assertThat(response.getPaging().getPageIndex()).isEqualTo(2);
assertThat(response.getPaging().getPageSize()).isEqualTo(3);
assertThat(response.getPaging().getTotal()).isEqualTo(9);
}
use of org.sonarqube.ws.WsMeasures.ComponentTreeWsResponse in project sonarqube by SonarSource.
the class ComponentTreeActionTest method sort_by_metric_period.
@Test
public void sort_by_metric_period() {
ComponentDto projectDto = newProjectDto(db.getDefaultOrganization(), "project-uuid");
SnapshotDto projectSnapshot = componentDb.insertProjectAndSnapshot(projectDto);
ComponentDto file3 = componentDb.insertComponent(newFileDto(projectDto, null, "file-uuid-3"));
ComponentDto file1 = componentDb.insertComponent(newFileDto(projectDto, null, "file-uuid-1"));
ComponentDto file2 = componentDb.insertComponent(newFileDto(projectDto, null, "file-uuid-2"));
MetricDto ncloc = newMetricDtoWithoutOptimization().setKey("ncloc").setValueType(ValueType.INT.name()).setDirection(1);
dbClient.metricDao().insert(dbSession, ncloc);
dbClient.measureDao().insert(dbSession, newMeasureDto(ncloc, file1, projectSnapshot).setVariation(1.0d), newMeasureDto(ncloc, file2, projectSnapshot).setVariation(2.0d), newMeasureDto(ncloc, file3, projectSnapshot).setVariation(3.0d));
db.commit();
ComponentTreeWsResponse response = call(ws.newRequest().setParam(PARAM_BASE_COMPONENT_ID, "project-uuid").setParam(Param.SORT, METRIC_PERIOD_SORT).setParam(PARAM_METRIC_SORT, "ncloc").setParam(PARAM_METRIC_KEYS, "ncloc").setParam(PARAM_METRIC_PERIOD_SORT, "1"));
assertThat(response.getComponentsList()).extracting("id").containsExactly("file-uuid-1", "file-uuid-2", "file-uuid-3");
}
use of org.sonarqube.ws.WsMeasures.ComponentTreeWsResponse in project sonarqube by SonarSource.
the class ComponentTreeActionTest method load_measures_with_best_value.
@Test
public void load_measures_with_best_value() {
ComponentDto projectDto = newProjectDto(db.getDefaultOrganization(), "project-uuid");
SnapshotDto projectSnapshot = componentDb.insertProjectAndSnapshot(projectDto);
userSession.anonymous().addProjectUuidPermissions(UserRole.USER, "project-uuid");
ComponentDto directoryDto = newDirectory(projectDto, "directory-uuid", "path/to/directory").setName("directory-1");
componentDb.insertComponent(directoryDto);
ComponentDto file = newFileDto(directoryDto, null, "file-uuid").setName("file-1");
componentDb.insertComponent(file);
MetricDto coverage = insertCoverageMetric();
dbClient.metricDao().insert(dbSession, newMetricDto().setKey("ncloc").setValueType(ValueType.INT.name()).setOptimizedBestValue(true).setBestValue(100d).setWorstValue(1000d));
dbClient.metricDao().insert(dbSession, newMetricDtoWithoutOptimization().setKey("new_violations").setOptimizedBestValue(true).setBestValue(1984.0d).setValueType(ValueType.INT.name()));
dbClient.measureDao().insert(dbSession, newMeasureDto(coverage, file, projectSnapshot).setValue(15.5d), newMeasureDto(coverage, directoryDto, projectSnapshot).setValue(42.0d));
db.commit();
ComponentTreeWsResponse response = call(ws.newRequest().setParam(PARAM_BASE_COMPONENT_ID, "project-uuid").setParam(PARAM_METRIC_KEYS, "ncloc,coverage,new_violations").setParam(PARAM_ADDITIONAL_FIELDS, "metrics"));
// directory measures
assertThat(response.getComponentsList().get(0).getMeasuresList()).extracting("metric").containsOnly("coverage");
// file measures
List<WsMeasures.Measure> fileMeasures = response.getComponentsList().get(1).getMeasuresList();
assertThat(fileMeasures).extracting("metric").containsOnly("ncloc", "coverage", "new_violations");
assertThat(fileMeasures).extracting("value").containsOnly("100", "15.5", "");
List<Common.Metric> metrics = response.getMetrics().getMetricsList();
assertThat(metrics).extracting("bestValue").contains("100", "");
assertThat(metrics).extracting("worstValue").contains("1000");
}
use of org.sonarqube.ws.WsMeasures.ComponentTreeWsResponse in project sonarqube by SonarSource.
the class ComponentTreeAction method handle.
@Override
public void handle(Request request, Response response) throws Exception {
ComponentTreeWsResponse componentTreeWsResponse = doHandle(toComponentTreeWsRequest(request));
writeProtobuf(componentTreeWsResponse, request, response);
}
Aggregations