Search in sources :

Example 36 with MetricDto

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");
}
Also used : MetricDto(org.sonar.db.metric.MetricDto) CustomMeasureDto(org.sonar.db.measure.custom.CustomMeasureDto) Test(org.junit.Test)

Example 37 with MetricDto

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");
}
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 38 with MetricDto

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;
}
Also used : MetricTesting.newMetricDto(org.sonar.db.metric.MetricTesting.newMetricDto) MetricDto(org.sonar.db.metric.MetricDto)

Example 39 with MetricDto

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");
}
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 40 with MetricDto

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();
}
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)

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