Search in sources :

Example 16 with ComponentTreeWsResponse

use of org.sonarqube.ws.WsMeasures.ComponentTreeWsResponse in project sonarqube by SonarSource.

the class ComponentTreeActionTest method empty_response.

@Test
public void empty_response() {
    componentDb.insertComponent(newProjectDto(db.getDefaultOrganization(), "project-uuid"));
    ComponentTreeWsResponse response = call(ws.newRequest().setParam(PARAM_BASE_COMPONENT_ID, "project-uuid").setParam(PARAM_METRIC_KEYS, "ncloc, complexity"));
    assertThat(response.getBaseComponent().getId()).isEqualTo("project-uuid");
    assertThat(response.getComponentsList()).isEmpty();
    assertThat(response.getMetrics().getMetricsList()).isEmpty();
    assertThat(response.getPeriods().getPeriodsList()).isEmpty();
}
Also used : ComponentTreeWsResponse(org.sonarqube.ws.WsMeasures.ComponentTreeWsResponse) Test(org.junit.Test)

Example 17 with ComponentTreeWsResponse

use of org.sonarqube.ws.WsMeasures.ComponentTreeWsResponse in project sonarqube by SonarSource.

the class ComponentTreeActionTest method remove_components_without_measure_on_the_metric_sort.

@Test
public void remove_components_without_measure_on_the_metric_sort() {
    ComponentDto project = newProjectDto(db.getDefaultOrganization(), "project-uuid");
    SnapshotDto projectSnapshot = componentDb.insertProjectAndSnapshot(project);
    ComponentDto file1 = newFileDto(project, null, "file-uuid-1");
    ComponentDto file2 = newFileDto(project, null, "file-uuid-2");
    ComponentDto file3 = newFileDto(project, null, "file-uuid-3");
    ComponentDto file4 = newFileDto(project, null, "file-uuid-4");
    componentDb.insertComponent(file1);
    componentDb.insertComponent(file2);
    componentDb.insertComponent(file3);
    componentDb.insertComponent(file4);
    MetricDto ncloc = newMetricDtoWithoutOptimization().setKey("ncloc").setValueType(ValueType.INT.name()).setDirection(1);
    dbClient.metricDao().insert(dbSession, ncloc);
    dbClient.measureDao().insert(dbSession, newMeasureDto(ncloc, file1, projectSnapshot).setValue(1.0d), newMeasureDto(ncloc, file2, projectSnapshot).setValue(2.0d), newMeasureDto(ncloc, file3, projectSnapshot).setValue(3.0d), // measure on period 1
    newMeasureDto(ncloc, file4, projectSnapshot).setVariation(4.0d));
    db.commit();
    ComponentTreeWsResponse response = call(ws.newRequest().setParam(PARAM_BASE_COMPONENT_ID, project.uuid()).setParam(Param.SORT, METRIC_SORT).setParam(PARAM_METRIC_SORT, "ncloc").setParam(PARAM_METRIC_KEYS, "ncloc").setParam(PARAM_METRIC_SORT_FILTER, WITH_MEASURES_ONLY_METRIC_SORT_FILTER));
    assertThat(response.getComponentsList()).extracting("id").containsExactly(file1.uuid(), file2.uuid(), file3.uuid()).doesNotContain(file4.uuid());
    assertThat(response.getPaging().getTotal()).isEqualTo(3);
}
Also used : MetricTesting.newMetricDto(org.sonar.db.metric.MetricTesting.newMetricDto) MetricDto(org.sonar.db.metric.MetricDto) SnapshotDto(org.sonar.db.component.SnapshotDto) ComponentDto(org.sonar.db.component.ComponentDto) ComponentTreeWsResponse(org.sonarqube.ws.WsMeasures.ComponentTreeWsResponse) Test(org.junit.Test)

Aggregations

ComponentTreeWsResponse (org.sonarqube.ws.WsMeasures.ComponentTreeWsResponse)17 Test (org.junit.Test)14 ComponentDto (org.sonar.db.component.ComponentDto)13 MetricDto (org.sonar.db.metric.MetricDto)11 SnapshotDto (org.sonar.db.component.SnapshotDto)10 MetricTesting.newMetricDto (org.sonar.db.metric.MetricTesting.newMetricDto)10 WsMeasures (org.sonarqube.ws.WsMeasures)3 ComponentTreeWsRequest (org.sonarqube.ws.client.measure.ComponentTreeWsRequest)2