Search in sources :

Example 1 with ComponentTreeWsResponse

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);
}
Also used : ComponentTreeWsRequest(org.sonarqube.ws.client.measure.ComponentTreeWsRequest) ComponentTreeWsResponse(org.sonarqube.ws.WsMeasures.ComponentTreeWsResponse)

Example 2 with ComponentTreeWsResponse

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");
}
Also used : ComponentTreeWsRequest(org.sonarqube.ws.client.measure.ComponentTreeWsRequest) ComponentTreeWsResponse(org.sonarqube.ws.WsMeasures.ComponentTreeWsResponse) Test(org.junit.Test)

Example 3 with ComponentTreeWsResponse

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();
}
Also used : MetricDto(org.sonar.db.metric.MetricDto) ComponentDto(org.sonar.db.component.ComponentDto) ComponentTreeWsResponse(org.sonarqube.ws.WsMeasures.ComponentTreeWsResponse)

Example 4 with ComponentTreeWsResponse

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");
}
Also used : MetricTesting.newMetricDto(org.sonar.db.metric.MetricTesting.newMetricDto) MetricDto(org.sonar.db.metric.MetricDto) WsMeasures(org.sonarqube.ws.WsMeasures) SnapshotDto(org.sonar.db.component.SnapshotDto) ComponentDto(org.sonar.db.component.ComponentDto) ComponentTreeWsResponse(org.sonarqube.ws.WsMeasures.ComponentTreeWsResponse) Test(org.junit.Test)

Example 5 with ComponentTreeWsResponse

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");
}
Also used : WsMeasures(org.sonarqube.ws.WsMeasures) ComponentDto(org.sonar.db.component.ComponentDto) ComponentTreeWsResponse(org.sonarqube.ws.WsMeasures.ComponentTreeWsResponse) Test(org.junit.Test)

Aggregations

ComponentTreeWsResponse (org.sonarqube.ws.WsMeasures.ComponentTreeWsResponse)6 Test (org.junit.Test)4 ComponentDto (org.sonar.db.component.ComponentDto)4 MetricDto (org.sonar.db.metric.MetricDto)3 WsMeasures (org.sonarqube.ws.WsMeasures)3 SnapshotDto (org.sonar.db.component.SnapshotDto)2 MetricTesting.newMetricDto (org.sonar.db.metric.MetricTesting.newMetricDto)2 ComponentTreeWsRequest (org.sonarqube.ws.client.measure.ComponentTreeWsRequest)2