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");
}
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");
}
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;
}
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");
}
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");
}
Aggregations