Search in sources :

Example 26 with MetricDto

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

the class UpdateActionTest method insertNewMetric.

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

Example 27 with MetricDto

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

the class UpdateActionTest method update_value_only.

@Test
public void update_value_only() throws Exception {
    MetricDto metric = insertNewMetric(ValueType.STRING);
    ComponentDto component = db.components().insertProject(db.getDefaultOrganization(), "project-uuid");
    CustomMeasureDto customMeasure = newCustomMeasure(component, metric).setDescription("custom-measure-description").setTextValue("text-measure-value");
    dbClient.customMeasureDao().insert(dbSession, customMeasure);
    dbSession.commit();
    when(system.now()).thenReturn(123_456_789L);
    logInAsProjectAdministrator(component);
    ws.newPostRequest(CustomMeasuresWs.ENDPOINT, UpdateAction.ACTION).setParam(PARAM_ID, String.valueOf(customMeasure.getId())).setParam(PARAM_DESCRIPTION, "new-custom-measure-description").execute();
    logInAsProjectAdministrator(component);
    CustomMeasureDto updatedCustomMeasure = dbClient.customMeasureDao().selectOrFail(dbSession, customMeasure.getId());
    assertThat(updatedCustomMeasure.getTextValue()).isEqualTo("text-measure-value");
    assertThat(updatedCustomMeasure.getDescription()).isEqualTo("new-custom-measure-description");
    assertThat(updatedCustomMeasure.getUpdatedAt()).isEqualTo(123_456_789L);
    assertThat(customMeasure.getCreatedAt()).isEqualTo(updatedCustomMeasure.getCreatedAt());
}
Also used : MetricDto(org.sonar.db.metric.MetricDto) ComponentDto(org.sonar.db.component.ComponentDto) CustomMeasureTesting.newCustomMeasureDto(org.sonar.db.measure.custom.CustomMeasureTesting.newCustomMeasureDto) CustomMeasureDto(org.sonar.db.measure.custom.CustomMeasureDto) Test(org.junit.Test)

Example 28 with MetricDto

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

the class MetricsActionTest method list_metrics_based_on_project_key.

@Test
public void list_metrics_based_on_project_key() throws Exception {
    MetricDto metric = insertCustomMetric("metric-key-1");
    insertCustomMetric("metric-key-2");
    insertProject("project-uuid-2", "project-key-2");
    CustomMeasureDto customMeasure = newCustomMeasureDto().setComponentUuid(defaultProject.uuid()).setMetricId(metric.getId());
    dbClient.customMeasureDao().insert(dbSession, customMeasure);
    dbSession.commit();
    String response = ws.newGetRequest(ENDPOINT, ACTION).setParam(MetricsAction.PARAM_PROJECT_KEY, DEFAULT_PROJECT_KEY).execute().outputAsString();
    assertThat(response).contains("metric-key-2").doesNotContain("metric-key-1");
}
Also used : MetricTesting.newMetricDto(org.sonar.db.metric.MetricTesting.newMetricDto) MetricDto(org.sonar.db.metric.MetricDto) CustomMeasureTesting.newCustomMeasureDto(org.sonar.db.measure.custom.CustomMeasureTesting.newCustomMeasureDto) CustomMeasureDto(org.sonar.db.measure.custom.CustomMeasureDto) Test(org.junit.Test)

Example 29 with MetricDto

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

the class MetricsActionTest method insertCustomMetric.

private MetricDto insertCustomMetric(String metricKey) {
    MetricDto metric = newCustomMetric(metricKey);
    dbClient.metricDao().insert(dbSession, metric);
    dbSession.commit();
    return metric;
}
Also used : MetricTesting.newMetricDto(org.sonar.db.metric.MetricTesting.newMetricDto) MetricDto(org.sonar.db.metric.MetricDto)

Example 30 with MetricDto

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

the class SearchActionTest method search_by_project_uuid.

@Test
public void search_by_project_uuid() throws Exception {
    MetricDto metric1 = insertCustomMetric(1);
    MetricDto metric2 = insertCustomMetric(2);
    MetricDto metric3 = insertCustomMetric(3);
    insertCustomMeasure(1, metric1);
    insertCustomMeasure(2, metric2);
    insertCustomMeasure(3, metric3);
    String response = newRequest().setParam(SearchAction.PARAM_PROJECT_ID, DEFAULT_PROJECT_UUID).execute().outputAsString();
    assertThat(response).contains("text-value-1", "text-value-2", "text-value-3");
}
Also used : MetricTesting.newMetricDto(org.sonar.db.metric.MetricTesting.newMetricDto) MetricDto(org.sonar.db.metric.MetricDto) 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