Search in sources :

Example 16 with MeasureDto

use of org.sonar.db.measure.MeasureDto in project sonarqube by SonarSource.

the class MeasureToMeasureDtoTest method toMeasureDto_maps_to_only_data_for_STRING_metric.

@Test
public void toMeasureDto_maps_to_only_data_for_STRING_metric() {
    MeasureDto trueMeasureDto = underTest.toMeasureDto(Measure.newMeasureBuilder().create(SOME_STRING), SOME_STRING_METRIC, SOME_COMPONENT);
    assertThat(trueMeasureDto.getValue()).isNull();
    assertThat(trueMeasureDto.getData()).isEqualTo(SOME_STRING);
}
Also used : MeasureDto(org.sonar.db.measure.MeasureDto) Test(org.junit.Test)

Example 17 with MeasureDto

use of org.sonar.db.measure.MeasureDto in project sonarqube by SonarSource.

the class MeasureToMeasureDtoTest method toMeasureDto_maps_value_and_data_from_data_field_for_INT_metric.

@Test
public void toMeasureDto_maps_value_and_data_from_data_field_for_INT_metric() {
    MeasureDto trueMeasureDto = underTest.toMeasureDto(Measure.newMeasureBuilder().create(123, SOME_DATA), SOME_INT_METRIC, SOME_COMPONENT);
    assertThat(trueMeasureDto.getValue()).isEqualTo(123);
    assertThat(trueMeasureDto.getData()).isEqualTo(SOME_DATA);
}
Also used : MeasureDto(org.sonar.db.measure.MeasureDto) Test(org.junit.Test)

Example 18 with MeasureDto

use of org.sonar.db.measure.MeasureDto in project sonarqube by SonarSource.

the class MeasureToMeasureDtoTest method toMeasureDto_maps_value_and_data_from_data_field_for_DOUBLE_metric.

@Test
public void toMeasureDto_maps_value_and_data_from_data_field_for_DOUBLE_metric() {
    MeasureDto trueMeasureDto = underTest.toMeasureDto(Measure.newMeasureBuilder().create((double) 789, 1, SOME_DATA), SOME_DOUBLE_METRIC, SOME_COMPONENT);
    assertThat(trueMeasureDto.getValue()).isEqualTo(789);
    assertThat(trueMeasureDto.getData()).isEqualTo(SOME_DATA);
}
Also used : MeasureDto(org.sonar.db.measure.MeasureDto) Test(org.junit.Test)

Example 19 with MeasureDto

use of org.sonar.db.measure.MeasureDto in project sonarqube by SonarSource.

the class ComponentTreeSortTest method sort_by_alert_status_ascending.

@Test
public void sort_by_alert_status_ascending() {
    components = newArrayList(newComponentWithoutSnapshotId("PROJECT OK 1", Qualifiers.PROJECT, "PROJECT_OK_PATH_1"), newComponentWithoutSnapshotId("PROJECT WARN 1", Qualifiers.PROJECT, "PROJECT_WARN_PATH_1"), newComponentWithoutSnapshotId("PROJECT ERROR 1", Qualifiers.PROJECT, "PROJECT_ERROR_PATH_1"), newComponentWithoutSnapshotId("PROJECT OK 2", Qualifiers.PROJECT, "PROJECT_OK_PATH_2"), newComponentWithoutSnapshotId("PROJECT WARN 2", Qualifiers.PROJECT, "PROJECT_WARN_PATH_2"), newComponentWithoutSnapshotId("PROJECT ERROR 2", Qualifiers.PROJECT, "PROJECT_ERROR_PATH_2"));
    metrics = singletonList(newMetricDto().setKey(CoreMetrics.ALERT_STATUS_KEY).setValueType(ValueType.LEVEL.name()));
    measuresByComponentUuidAndMetric = HashBasedTable.create();
    List<String> statuses = newArrayList("OK", "WARN", "ERROR");
    for (int i = 0; i < components.size(); i++) {
        ComponentDto component = components.get(i);
        String alertStatus = statuses.get(i % 3);
        measuresByComponentUuidAndMetric.put(component.uuid(), metrics.get(0), new MeasureDto().setData(alertStatus));
    }
    ComponentTreeWsRequest wsRequest = newRequest(newArrayList(METRIC_SORT, NAME_SORT), true, CoreMetrics.ALERT_STATUS_KEY);
    List<ComponentDto> result = sortComponents(wsRequest);
    assertThat(result).extracting("name").containsExactly("PROJECT ERROR 1", "PROJECT ERROR 2", "PROJECT WARN 1", "PROJECT WARN 2", "PROJECT OK 1", "PROJECT OK 2");
}
Also used : MeasureDto(org.sonar.db.measure.MeasureDto) ComponentDto(org.sonar.db.component.ComponentDto) ComponentTreeWsRequest(org.sonarqube.ws.client.measure.ComponentTreeWsRequest) Test(org.junit.Test)

Example 20 with MeasureDto

use of org.sonar.db.measure.MeasureDto in project sonarqube by SonarSource.

the class AppAction method handle.

@Override
public void handle(Request request, Response response) {
    try (DbSession session = dbClient.openSession(false)) {
        ComponentDto component = componentFinder.getByUuidOrKey(session, request.param(PARAM_COMPONENT_ID), request.param(PARAM_COMPONENT), ParamNames.COMPONENT_ID_AND_COMPONENT);
        userSession.checkComponentPermission(UserRole.USER, component);
        JsonWriter json = response.newJsonWriter();
        json.beginObject();
        Map<String, MeasureDto> measuresByMetricKey = measuresByMetricKey(component, session);
        appendComponent(json, component, userSession, session);
        appendPermissions(json, component, userSession);
        appendMeasures(json, measuresByMetricKey);
        json.endObject();
        json.close();
    }
}
Also used : MeasureDto(org.sonar.db.measure.MeasureDto) DbSession(org.sonar.db.DbSession) ComponentDto(org.sonar.db.component.ComponentDto) JsonWriter(org.sonar.api.utils.text.JsonWriter)

Aggregations

MeasureDto (org.sonar.db.measure.MeasureDto)36 Test (org.junit.Test)21 MetricDto (org.sonar.db.metric.MetricDto)9 ComponentDto (org.sonar.db.component.ComponentDto)7 MeasureQuery (org.sonar.db.measure.MeasureQuery)6 DbSession (org.sonar.db.DbSession)4 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)3 SnapshotDto (org.sonar.db.component.SnapshotDto)3 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 CheckForNull (javax.annotation.CheckForNull)1 Nonnull (javax.annotation.Nonnull)1 Before (org.junit.Before)1 JsonWriter (org.sonar.api.utils.text.JsonWriter)1 ComponentLinkDto (org.sonar.db.component.ComponentLinkDto)1 ComponentTreeQuery (org.sonar.db.component.ComponentTreeQuery)1 MeasureTreeQuery (org.sonar.db.measure.MeasureTreeQuery)1 MetricTesting.newMetricDto (org.sonar.db.metric.MetricTesting.newMetricDto)1 Developer (org.sonar.server.computation.task.projectanalysis.component.Developer)1