Search in sources :

Example 46 with MetricDto

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

the class CreateActionTest method create_text_custom_measure_with_metric_key.

@Test
public void create_text_custom_measure_with_metric_key() throws Exception {
    insertProject(DEFAULT_PROJECT_UUID);
    MetricDto metric = insertMetric(STRING);
    newRequest().setParam(CreateAction.PARAM_PROJECT_ID, DEFAULT_PROJECT_UUID).setParam(CreateAction.PARAM_METRIC_KEY, metric.getKey()).setParam(CreateAction.PARAM_VALUE, "whatever-value").execute();
    CustomMeasureDto customMeasure = dbClient.customMeasureDao().selectByMetricId(dbSession, metric.getId()).get(0);
    assertThat(customMeasure).isNotNull();
}
Also used : MetricDto(org.sonar.db.metric.MetricDto) CustomMeasureDto(org.sonar.db.measure.custom.CustomMeasureDto) Test(org.junit.Test)

Example 47 with MetricDto

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

the class CreateActionTest method fail_when_project_id_nor_project_key_provided.

@Test
public void fail_when_project_id_nor_project_key_provided() throws Exception {
    expectedException.expect(IllegalArgumentException.class);
    expectedException.expectMessage("Either 'projectId' or 'projectKey' must be provided, not both");
    insertProject(DEFAULT_PROJECT_UUID);
    MetricDto metric = insertMetric(STRING);
    newRequest().setParam(CreateAction.PARAM_METRIC_ID, "whatever-id").setParam(CreateAction.PARAM_VALUE, metric.getId().toString()).execute();
}
Also used : MetricDto(org.sonar.db.metric.MetricDto) Test(org.junit.Test)

Example 48 with MetricDto

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

the class ComponentActionTest method insertJsonExampleData.

private void insertJsonExampleData() {
    ComponentDto project = newProjectDto(db.getDefaultOrganization(), PROJECT_UUID);
    SnapshotDto projectSnapshot = SnapshotTesting.newAnalysis(project).setPeriodDate(parseDateTime("2016-01-11T10:49:50+0100").getTime()).setPeriodMode("previous_version").setPeriodParam("1.0-SNAPSHOT");
    ComponentDto file = newFileDto(project, null).setUuid("AVIwDXE-bJbJqrw6wFv5").setKey("MY_PROJECT:ElementImpl.java").setName("ElementImpl.java").setQualifier(Qualifiers.FILE).setLanguage("java").setPath("src/main/java/com/sonarsource/markdown/impl/ElementImpl.java");
    componentDb.insertComponents(project, file);
    dbClient.snapshotDao().insert(dbSession, projectSnapshot);
    MetricDto complexity = insertComplexityMetric();
    dbClient.measureDao().insert(dbSession, newMeasureDto(complexity, file, projectSnapshot).setValue(12.0d).setVariation(2.0d));
    MetricDto ncloc = insertNclocMetric();
    dbClient.measureDao().insert(dbSession, newMeasureDto(ncloc, file, projectSnapshot).setValue(114.0d).setVariation(3.0d));
    MetricDto newViolations = insertNewViolationMetric();
    dbClient.measureDao().insert(dbSession, newMeasureDto(newViolations, file, projectSnapshot).setVariation(25.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)

Example 49 with MetricDto

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

the class ComponentActionTest 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 50 with MetricDto

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

the class ComponentTreeActionTest method insertCoverageMetric.

private MetricDto insertCoverageMetric() {
    MetricDto metric = dbClient.metricDao().insert(dbSession, newMetricDtoWithoutOptimization().setKey("coverage").setShortName("Coverage").setDescription("Code Coverage").setDomain("Coverage").setValueType(ValueType.FLOAT.name()).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)

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