Search in sources :

Example 76 with MetricDto

use of org.sonar.db.metric.MetricDto in project sonarqube by SonarSource.

the class ComponentActionTest method developer_measure_by_developer_key.

@Test
public void developer_measure_by_developer_key() {
    OrganizationDto organizationDto = db.organizations().insert();
    ComponentDto developer = newDeveloper(organizationDto, "developer-name");
    componentDb.insertDeveloperAndSnapshot(developer);
    ComponentDto project = newProjectDto(organizationDto, PROJECT_UUID);
    SnapshotDto projectSnapshot = componentDb.insertProjectAndSnapshot(project);
    ComponentDto file = newFileDto(project, null, "file-uuid");
    componentDb.insertComponent(file);
    MetricDto ncloc = insertNclocMetric();
    dbClient.measureDao().insert(dbSession, newMeasureDto(ncloc, file, projectSnapshot).setValue(42.0d).setDeveloperId(null), newMeasureDto(ncloc, file, projectSnapshot).setValue(1984.0d).setDeveloperId(developer.getId()));
    db.commit();
    ComponentWsResponse result = call(ws.newRequest().setParam(PARAM_COMPONENT_ID, "file-uuid").setParam(PARAM_DEVELOPER_KEY, developer.key()).setParam(PARAM_METRIC_KEYS, "ncloc"));
    assertThat(result.getComponent().getMeasuresCount()).isEqualTo(1);
    assertThat(result.getComponent().getMeasures(0).getValue()).isEqualTo("1984");
}
Also used : MetricTesting.newMetricDto(org.sonar.db.metric.MetricTesting.newMetricDto) MetricDto(org.sonar.db.metric.MetricDto) ComponentWsResponse(org.sonarqube.ws.WsMeasures.ComponentWsResponse) SnapshotDto(org.sonar.db.component.SnapshotDto) ComponentDto(org.sonar.db.component.ComponentDto) OrganizationDto(org.sonar.db.organization.OrganizationDto) Test(org.junit.Test)

Example 77 with MetricDto

use of org.sonar.db.metric.MetricDto in project sonarqube by SonarSource.

the class ComponentActionTest method developer_measure_by_developer_uuid.

@Test
public void developer_measure_by_developer_uuid() {
    OrganizationDto organizationDto = db.organizations().insert();
    ComponentDto developer = newDeveloper(organizationDto, "developer-name");
    componentDb.insertDeveloperAndSnapshot(developer);
    ComponentDto project = newProjectDto(organizationDto, "project-uuid");
    SnapshotDto projectSnapshot = componentDb.insertProjectAndSnapshot(project);
    ComponentDto file = newFileDto(project, null, "file-uuid");
    componentDb.insertComponent(file);
    MetricDto ncloc = insertNclocMetric();
    dbClient.measureDao().insert(dbSession, newMeasureDto(ncloc, file, projectSnapshot).setValue(42.0d).setDeveloperId(null), newMeasureDto(ncloc, file, projectSnapshot).setValue(1984.0d).setDeveloperId(developer.getId()));
    db.commit();
    ComponentWsResponse result = call(ws.newRequest().setParam(PARAM_COMPONENT_ID, "file-uuid").setParam(PARAM_DEVELOPER_ID, developer.uuid()).setParam(PARAM_METRIC_KEYS, "ncloc"));
    assertThat(result.getComponent().getMeasuresCount()).isEqualTo(1);
    assertThat(result.getComponent().getMeasures(0).getValue()).isEqualTo("1984");
}
Also used : MetricTesting.newMetricDto(org.sonar.db.metric.MetricTesting.newMetricDto) MetricDto(org.sonar.db.metric.MetricDto) ComponentWsResponse(org.sonarqube.ws.WsMeasures.ComponentWsResponse) SnapshotDto(org.sonar.db.component.SnapshotDto) ComponentDto(org.sonar.db.component.ComponentDto) OrganizationDto(org.sonar.db.organization.OrganizationDto) Test(org.junit.Test)

Example 78 with MetricDto

use of org.sonar.db.metric.MetricDto in project sonarqube by SonarSource.

the class ComponentTreeActionTest method insertComplexityMetric.

private MetricDto insertComplexityMetric() {
    MetricDto metric = dbClient.metricDao().insert(dbSession, newMetricDtoWithoutOptimization().setKey("complexity").setShortName("Complexity").setDescription("Cyclomatic complexity").setDomain("Complexity").setValueType("INT").setDirection(-1).setQualitative(false).setHidden(false).setUserManaged(false));
    db.commit();
    return metric;
}
Also used : MetricTesting.newMetricDto(org.sonar.db.metric.MetricTesting.newMetricDto) MetricDto(org.sonar.db.metric.MetricDto)

Example 79 with MetricDto

use of org.sonar.db.metric.MetricDto 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 80 with MetricDto

use of org.sonar.db.metric.MetricDto 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)

Aggregations

MetricDto (org.sonar.db.metric.MetricDto)137 Test (org.junit.Test)83 MetricTesting.newMetricDto (org.sonar.db.metric.MetricTesting.newMetricDto)61 ComponentDto (org.sonar.db.component.ComponentDto)49 SnapshotDto (org.sonar.db.component.SnapshotDto)33 CustomMeasureDto (org.sonar.db.measure.custom.CustomMeasureDto)26 DbSession (org.sonar.db.DbSession)11 ComponentTreeWsResponse (org.sonarqube.ws.WsMeasures.ComponentTreeWsResponse)11 CustomMeasureTesting.newCustomMeasureDto (org.sonar.db.measure.custom.CustomMeasureTesting.newCustomMeasureDto)10 MeasureDto (org.sonar.db.measure.MeasureDto)9 OrganizationDto (org.sonar.db.organization.OrganizationDto)8 ProjectMeasures (org.sonar.db.measure.ProjectMeasuresIndexerIterator.ProjectMeasures)7 QualityGateConditionDto (org.sonar.db.qualitygate.QualityGateConditionDto)6 JsonWriter (org.sonar.api.utils.text.JsonWriter)5 WsTester (org.sonar.server.ws.WsTester)5 SearchWsResponse (org.sonarqube.ws.WsMeasures.SearchWsResponse)5 MeasureQuery (org.sonar.db.measure.MeasureQuery)3 UserDto (org.sonar.db.user.UserDto)3 WsMeasures (org.sonarqube.ws.WsMeasures)3 ComponentWsResponse (org.sonarqube.ws.WsMeasures.ComponentWsResponse)3