use of org.sonarqube.ws.WsMeasures.ComponentTreeWsResponse in project sonarqube by SonarSource.
the class MeasuresWsTest method verifyComponentTreeWithChildren.
private void verifyComponentTreeWithChildren(String baseComponentKey, String... childKeys) {
ComponentTreeWsResponse response = wsClient.measures().componentTree(new ComponentTreeWsRequest().setBaseComponentKey(baseComponentKey).setMetricKeys(singletonList("ncloc")).setStrategy("children"));
assertThat(response.getBaseComponent().getKey()).isEqualTo(baseComponentKey);
assertThat(response.getComponentsList()).extracting("key").containsOnly(childKeys);
}
use of org.sonarqube.ws.WsMeasures.ComponentTreeWsResponse in project sonarqube by SonarSource.
the class MeasuresWsTest method component_tree.
@Test
public void component_tree() {
scanXooSample();
ComponentTreeWsResponse response = wsClient.measures().componentTree(new ComponentTreeWsRequest().setBaseComponentKey("sample").setMetricKeys(singletonList("ncloc")).setAdditionalFields(newArrayList("metrics", "periods")));
assertThat(response).isNotNull();
assertThat(response.getBaseComponent().getKey()).isEqualTo("sample");
assertThat(response.getMetrics().getMetricsList()).extracting("key").containsOnly("ncloc");
List<WsMeasures.Component> components = response.getComponentsList();
assertThat(components).hasSize(2).extracting("key").containsOnly(DIR_KEY, FILE_KEY);
assertThat(components.get(0).getMeasuresList().get(0).getValue()).isEqualTo("13");
}
use of org.sonarqube.ws.WsMeasures.ComponentTreeWsResponse in project sonarqube by SonarSource.
the class ComponentTreeAction method buildResponse.
private static ComponentTreeWsResponse buildResponse(ComponentTreeWsRequest request, ComponentTreeData data, Paging paging) {
ComponentTreeWsResponse.Builder response = ComponentTreeWsResponse.newBuilder();
response.getPagingBuilder().setPageIndex(paging.pageIndex()).setPageSize(paging.pageSize()).setTotal(paging.total()).build();
response.setBaseComponent(componentDtoToWsComponent(data.getBaseComponent(), data.getMeasuresByComponentUuidAndMetric().row(data.getBaseComponent().uuid()), data.getReferenceComponentsByUuid()));
for (ComponentDto componentDto : data.getComponents()) {
response.addComponents(componentDtoToWsComponent(componentDto, data.getMeasuresByComponentUuidAndMetric().row(componentDto.uuid()), data.getReferenceComponentsByUuid()));
}
if (areMetricsInResponse(request)) {
WsMeasures.Metrics.Builder metricsBuilder = response.getMetricsBuilder();
for (MetricDto metricDto : data.getMetrics()) {
metricsBuilder.addMetrics(metricDtoToWsMetric(metricDto));
}
}
if (arePeriodsInResponse(request)) {
response.getPeriodsBuilder().addAllPeriods(data.getPeriods());
}
return response.build();
}
use of org.sonarqube.ws.WsMeasures.ComponentTreeWsResponse in project sonarqube by SonarSource.
the class ComponentTreeActionTest method load_developer_measures_by_developer_uuid.
@Test
public void load_developer_measures_by_developer_uuid() {
ComponentDto developer = newDeveloper(db.getDefaultOrganization(), "developer", "developer-uuid");
ComponentDto project = newProjectDto(db.getDefaultOrganization(), "project-uuid").setKey("project-key");
componentDb.insertDeveloperAndSnapshot(developer);
SnapshotDto projectSnapshot = componentDb.insertProjectAndSnapshot(project);
ComponentDto file1 = componentDb.insertComponent(newFileDto(project, null, "file1-uuid"));
ComponentDto file2 = componentDb.insertComponent(newFileDto(project, null, "file2-uuid"));
componentDb.insertComponent(newDevProjectCopy("project-uuid-copy", project, developer));
MetricDto ncloc = insertNclocMetric();
dbClient.measureDao().insert(dbSession, newMeasureDto(ncloc, project, projectSnapshot).setDeveloperId(developer.getId()), newMeasureDto(ncloc, file1, projectSnapshot).setValue(3d).setDeveloperId(developer.getId()), // measures are not specific to the developer
newMeasureDto(ncloc, file1, projectSnapshot).setDeveloperId(null), newMeasureDto(ncloc, file2, projectSnapshot).setDeveloperId(null));
db.commit();
ComponentTreeWsResponse response = call(ws.newRequest().setParam(PARAM_BASE_COMPONENT_ID, "project-uuid").setParam(PARAM_DEVELOPER_ID, "developer-uuid").setParam(PARAM_STRATEGY, CHILDREN_STRATEGY).setParam(PARAM_METRIC_KEYS, "ncloc"));
assertThat(response.getComponentsCount()).isEqualTo(2);
WsMeasures.Component file = response.getComponents(0);
assertThat(file.getId()).isEqualTo("file1-uuid");
assertThat(file.getMeasuresCount()).isEqualTo(1);
assertThat(file.getMeasures(0).getValue()).isEqualTo("3");
}
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");
}
Aggregations