Search in sources :

Example 41 with MetricDto

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

the class CreateActionTest method fail_when_project_id_and_project_key_are_provided.

@Test
public void fail_when_project_id_and_project_key_are_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_PROJECT_ID, DEFAULT_PROJECT_UUID).setParam(CreateAction.PARAM_PROJECT_KEY, DEFAULT_PROJECT_KEY).setParam(CreateAction.PARAM_METRIC_ID, metric.getId().toString()).setParam(CreateAction.PARAM_VALUE, "whatever-value").execute();
}
Also used : MetricDto(org.sonar.db.metric.MetricDto) Test(org.junit.Test)

Example 42 with MetricDto

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

the class CreateActionTest method create_level_type_custom_measure_in_db.

@Test
public void create_level_type_custom_measure_in_db() throws Exception {
    insertProject(DEFAULT_PROJECT_UUID);
    MetricDto metric = insertMetric(LEVEL);
    newRequest().setParam(CreateAction.PARAM_PROJECT_ID, DEFAULT_PROJECT_UUID).setParam(CreateAction.PARAM_METRIC_ID, metric.getId().toString()).setParam(CreateAction.PARAM_VALUE, Metric.Level.WARN.name()).execute();
    CustomMeasureDto customMeasure = dbClient.customMeasureDao().selectByMetricId(dbSession, metric.getId()).get(0);
    assertThat(customMeasure.getTextValue()).isEqualTo(Metric.Level.WARN.name());
}
Also used : MetricDto(org.sonar.db.metric.MetricDto) CustomMeasureDto(org.sonar.db.measure.custom.CustomMeasureDto) Test(org.junit.Test)

Example 43 with MetricDto

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

the class CreateActionTest method insertMetric.

private MetricDto insertMetric(ValueType metricType) {
    MetricDto metric = MetricTesting.newMetricDto().setEnabled(true).setValueType(metricType.name()).setKey("metric-key");
    dbClient.metricDao().insert(dbSession, metric);
    dbSession.commit();
    return metric;
}
Also used : MetricDto(org.sonar.db.metric.MetricDto)

Example 44 with MetricDto

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

the class CreateActionTest method fail_when_metric_id_nor_metric_key_is_provided.

@Test
public void fail_when_metric_id_nor_metric_key_is_provided() throws Exception {
    expectedException.expect(IllegalArgumentException.class);
    expectedException.expectMessage("The metric id or the metric key must be provided, not both.");
    insertProject(DEFAULT_PROJECT_UUID);
    MetricDto metric = insertMetric(STRING);
    newRequest().setParam(CreateAction.PARAM_PROJECT_ID, DEFAULT_PROJECT_UUID).setParam(CreateAction.PARAM_VALUE, "whatever-value").execute();
}
Also used : MetricDto(org.sonar.db.metric.MetricDto) Test(org.junit.Test)

Example 45 with MetricDto

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

the class CreateActionTest method create_float_custom_measure_in_db.

@Test
public void create_float_custom_measure_in_db() throws Exception {
    insertProject(DEFAULT_PROJECT_UUID);
    MetricDto metric = insertMetric(FLOAT);
    newRequest().setParam(CreateAction.PARAM_PROJECT_ID, DEFAULT_PROJECT_UUID).setParam(CreateAction.PARAM_METRIC_ID, metric.getId().toString()).setParam(CreateAction.PARAM_VALUE, "4.2").execute();
    CustomMeasureDto customMeasure = dbClient.customMeasureDao().selectByMetricId(dbSession, metric.getId()).get(0);
    assertThat(customMeasure.getValue()).isCloseTo(4.2d, Offset.offset(0.01d));
    assertThat(customMeasure.getTextValue()).isNullOrEmpty();
}
Also used : MetricDto(org.sonar.db.metric.MetricDto) CustomMeasureDto(org.sonar.db.measure.custom.CustomMeasureDto) 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