Search in sources :

Example 11 with ComponentTreeWsResponse

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

the class ComponentTreeActionTest method load_measures_when_no_leave_qualifier.

@Test
public void load_measures_when_no_leave_qualifier() {
    resourceTypes.setLeavesQualifiers();
    String projectUuid = "project-uuid";
    ComponentDto project = newProjectDto(db.getDefaultOrganization(), projectUuid);
    componentDb.insertProjectAndSnapshot(project);
    componentDb.insertComponent(newFileDto(project, null));
    insertNclocMetric();
    ComponentTreeWsResponse result = call(ws.newRequest().setParam(PARAM_BASE_COMPONENT_ID, projectUuid).setParam(PARAM_STRATEGY, LEAVES_STRATEGY).setParam(PARAM_METRIC_KEYS, "ncloc"));
    assertThat(result.getBaseComponent().getId()).isEqualTo(projectUuid);
    assertThat(result.getComponentsCount()).isEqualTo(0);
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) ComponentTreeWsResponse(org.sonarqube.ws.WsMeasures.ComponentTreeWsResponse) Test(org.junit.Test)

Example 12 with ComponentTreeWsResponse

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

the class ComponentTreeActionTest method load_developer_measures_by_developer_key.

@Test
public void load_developer_measures_by_developer_key() {
    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"));
    componentDb.insertComponent(newDevProjectCopy("project-uuid-copy", project, developer));
    MetricDto ncloc = insertNclocMetric();
    dbClient.measureDao().insert(dbSession, newMeasureDto(ncloc, file1, projectSnapshot).setValue(3d).setDeveloperId(developer.getId()));
    db.commit();
    ComponentTreeWsResponse response = call(ws.newRequest().setParam(PARAM_BASE_COMPONENT_ID, "project-uuid").setParam(PARAM_DEVELOPER_KEY, developer.key()).setParam(PARAM_METRIC_KEYS, "ncloc"));
    assertThat(response.getComponentsCount()).isEqualTo(1);
    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 13 with ComponentTreeWsResponse

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

the class ComponentTreeActionTest method load_measures_and_periods.

@Test
public void load_measures_and_periods() {
    ComponentDto projectDto = newProjectDto(db.getDefaultOrganization(), "project-uuid");
    componentDb.insertComponent(projectDto);
    SnapshotDto projectSnapshot = dbClient.snapshotDao().insert(dbSession, newAnalysis(projectDto).setPeriodDate(System.currentTimeMillis()).setPeriodMode("last_version").setPeriodDate(System.currentTimeMillis()));
    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 ncloc = insertNclocMetric();
    MetricDto coverage = insertCoverageMetric();
    dbClient.measureDao().insert(dbSession, newMeasureDto(ncloc, file, projectSnapshot).setValue(5.0d).setVariation(4.0d), newMeasureDto(coverage, file, projectSnapshot).setValue(15.5d), newMeasureDto(coverage, directoryDto, projectSnapshot).setValue(15.0d));
    db.commit();
    ComponentTreeWsResponse response = call(ws.newRequest().setParam(PARAM_BASE_COMPONENT_ID, "project-uuid").setParam(PARAM_METRIC_KEYS, "ncloc,coverage").setParam(PARAM_ADDITIONAL_FIELDS, ADDITIONAL_PERIODS));
    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");
    assertThat(fileMeasures).extracting("value").containsOnly("5", "15.5");
    assertThat(response.getPeriods().getPeriodsList()).extracting("mode").containsOnly("last_version");
}
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)

Example 14 with ComponentTreeWsResponse

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

the class ComponentTreeActionTest method sort_by_metric_value.

@Test
public void sort_by_metric_value() {
    ComponentDto projectDto = newProjectDto(db.getDefaultOrganization(), "project-uuid");
    SnapshotDto projectSnapshot = componentDb.insertProjectAndSnapshot(projectDto);
    ComponentDto file4 = componentDb.insertComponent(newFileDto(projectDto, null, "file-uuid-4"));
    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).setValue(1.0d), newMeasureDto(ncloc, file2, projectSnapshot).setValue(2.0d), newMeasureDto(ncloc, file3, projectSnapshot).setValue(3.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"));
    assertThat(response.getComponentsList()).extracting("id").containsExactly("file-uuid-1", "file-uuid-2", "file-uuid-3", "file-uuid-4");
    assertThat(response.getPaging().getTotal()).isEqualTo(4);
}
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)

Example 15 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_period_sort.

@Test
public void remove_components_without_measure_on_the_metric_period_sort() {
    ComponentDto projectDto = newProjectDto(db.getDefaultOrganization(), "project-uuid");
    SnapshotDto projectSnapshot = componentDb.insertProjectAndSnapshot(projectDto);
    ComponentDto file4 = componentDb.insertComponent(newFileDto(projectDto, null, "file-uuid-4"));
    ComponentDto file3 = componentDb.insertComponent(newFileDto(projectDto, null, "file-uuid-3"));
    ComponentDto file2 = componentDb.insertComponent(newFileDto(projectDto, null, "file-uuid-2"));
    ComponentDto file1 = componentDb.insertComponent(newFileDto(projectDto, null, "file-uuid-1"));
    MetricDto ncloc = newMetricDtoWithoutOptimization().setKey("new_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), // file 4 measure is on absolute value
    newMeasureDto(ncloc, file4, projectSnapshot).setValue(4.0d));
    db.commit();
    ComponentTreeWsResponse response = call(ws.newRequest().setParam(PARAM_BASE_COMPONENT_ID, "project-uuid").setParam(Param.SORT, METRIC_PERIOD_SORT + "," + NAME_SORT).setParam(PARAM_METRIC_SORT, "new_ncloc").setParam(PARAM_METRIC_KEYS, "new_ncloc").setParam(PARAM_METRIC_PERIOD_SORT, "1").setParam(PARAM_METRIC_SORT_FILTER, WITH_MEASURES_ONLY_METRIC_SORT_FILTER));
    assertThat(response.getComponentsList()).extracting("id").containsExactly("file-uuid-1", "file-uuid-2", "file-uuid-3").doesNotContain("file-uuid-4");
}
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