use of org.sonar.db.metric.MetricDto in project sonarqube by SonarSource.
the class CreateActionTest method create_text_custom_measure_in_db.
@Test
public void create_text_custom_measure_in_db() throws Exception {
insertProject(DEFAULT_PROJECT_UUID);
MetricDto metric = insertMetric(STRING);
newRequest().setParam(CreateAction.PARAM_PROJECT_ID, DEFAULT_PROJECT_UUID).setParam(CreateAction.PARAM_METRIC_ID, metric.getId().toString()).setParam(CreateAction.PARAM_VALUE, "custom-measure-free-text").execute();
CustomMeasureDto customMeasure = dbClient.customMeasureDao().selectByMetricId(dbSession, metric.getId()).get(0);
assertThat(customMeasure.getTextValue()).isEqualTo("custom-measure-free-text");
}
use of org.sonar.db.metric.MetricDto 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");
}
use of org.sonar.db.metric.MetricDto in project sonarqube by SonarSource.
the class ComponentTreeActionTest method insertNewViolationsMetric.
private MetricDto insertNewViolationsMetric() {
MetricDto metric = dbClient.metricDao().insert(dbSession, newMetricDtoWithoutOptimization().setKey("new_violations").setShortName("New issues").setDescription("New Issues").setDomain("Issues").setValueType("INT").setDirection(-1).setQualitative(true).setHidden(false).setUserManaged(false).setOptimizedBestValue(true).setBestValue(0.0d));
db.commit();
return metric;
}
use of org.sonar.db.metric.MetricDto in project sonarqube by SonarSource.
the class ComponentTreeActionTest method use_best_value_for_rating.
@Test
public void use_best_value_for_rating() {
userSession.anonymous().addProjectUuidPermissions(UserRole.USER, "project-uuid");
ComponentDto projectDto = newProjectDto(db.getDefaultOrganization(), "project-uuid");
componentDb.insertComponent(projectDto);
SnapshotDto projectSnapshot = dbClient.snapshotDao().insert(dbSession, newAnalysis(projectDto).setPeriodDate(parseDateTime("2016-01-11T10:49:50+0100").getTime()).setPeriodMode("previous_version").setPeriodParam("1.0-SNAPSHOT"));
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 metric = dbClient.metricDao().insert(dbSession, newMetricDtoWithoutOptimization().setKey(NEW_SECURITY_RATING_KEY).setOptimizedBestValue(true).setBestValue(1d).setValueType(ValueType.RATING.name()));
dbClient.measureDao().insert(dbSession, newMeasureDto(metric, directoryDto, projectSnapshot).setVariation(2d));
db.commit();
ComponentTreeWsResponse response = call(ws.newRequest().setParam(PARAM_BASE_COMPONENT_ID, "project-uuid").setParam(PARAM_METRIC_KEYS, NEW_SECURITY_RATING_KEY).setParam(PARAM_ADDITIONAL_FIELDS, "metrics"));
// directory
assertThat(response.getComponentsList().get(0).getMeasuresList().get(0).getPeriods().getPeriodsValue(0).getValue()).isEqualTo("2.0");
// file measures
assertThat(response.getComponentsList().get(1).getMeasuresList().get(0).getPeriods().getPeriodsValue(0).getValue()).isEqualTo("1.0");
}
use of org.sonar.db.metric.MetricDto in project sonarqube by SonarSource.
the class ComponentTreeActionTest method insertJsonExampleData.
private void insertJsonExampleData() {
ComponentDto project = newProjectDto(db.getDefaultOrganization(), "project-id").setKey("MY_PROJECT").setName("My Project").setQualifier(Qualifiers.PROJECT);
componentDb.insertComponent(project);
SnapshotDto projectSnapshot = dbClient.snapshotDao().insert(dbSession, newAnalysis(project).setPeriodDate(parseDateTime("2016-01-11T10:49:50+0100").getTime()).setPeriodMode("previous_version").setPeriodParam("1.0-SNAPSHOT"));
ComponentDto file1 = componentDb.insertComponent(newFileDto(project, null).setUuid("AVIwDXE-bJbJqrw6wFv5").setKey("com.sonarsource:java-markdown:src/main/java/com/sonarsource/markdown/impl/ElementImpl.java").setName("ElementImpl.java").setLanguage("java").setQualifier(Qualifiers.FILE).setPath("src/main/java/com/sonarsource/markdown/impl/ElementImpl.java"));
ComponentDto file2 = componentDb.insertComponent(newFileDto(project, null).setUuid("AVIwDXE_bJbJqrw6wFwJ").setKey("com.sonarsource:java-markdown:src/test/java/com/sonarsource/markdown/impl/ElementImplTest.java").setName("ElementImplTest.java").setLanguage("java").setQualifier(Qualifiers.UNIT_TEST_FILE).setPath("src/test/java/com/sonarsource/markdown/impl/ElementImplTest.java"));
ComponentDto dir = componentDb.insertComponent(newDirectory(project, "src/main/java/com/sonarsource/markdown/impl").setUuid("AVIwDXE-bJbJqrw6wFv8").setKey("com.sonarsource:java-markdown:src/main/java/com/sonarsource/markdown/impl").setQualifier(Qualifiers.DIRECTORY));
MetricDto complexity = insertComplexityMetric();
dbClient.measureDao().insert(dbSession, newMeasureDto(complexity, file1, projectSnapshot).setValue(12.0d), newMeasureDto(complexity, dir, projectSnapshot).setValue(35.0d).setVariation(0.0d), newMeasureDto(complexity, project, projectSnapshot).setValue(42.0d));
MetricDto ncloc = insertNclocMetric();
dbClient.measureDao().insert(dbSession, newMeasureDto(ncloc, file1, projectSnapshot).setValue(114.0d), newMeasureDto(ncloc, dir, projectSnapshot).setValue(217.0d).setVariation(0.0d), newMeasureDto(ncloc, project, projectSnapshot).setValue(1984.0d));
MetricDto newViolations = insertNewViolationsMetric();
dbClient.measureDao().insert(dbSession, newMeasureDto(newViolations, file1, projectSnapshot).setVariation(25.0d), newMeasureDto(newViolations, dir, projectSnapshot).setVariation(25.0d), newMeasureDto(newViolations, project, projectSnapshot).setVariation(255.0d));
db.commit();
}
Aggregations