Search in sources :

Example 71 with MetricDto

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

the class CreateAction method insertNewMetric.

private MetricDto insertNewMetric(DbSession dbSession, MetricDto metricTemplate) {
    MetricDto metric = new MetricDto().setKey(metricTemplate.getKey()).setShortName(metricTemplate.getShortName()).setValueType(metricTemplate.getValueType()).setDomain(metricTemplate.getDomain()).setDescription(metricTemplate.getDescription()).setEnabled(true).setUserManaged(true).setDirection(0).setQualitative(false).setHidden(false).setOptimizedBestValue(false).setDeleteHistoricalData(false);
    dbClient.metricDao().insert(dbSession, metric);
    dbSession.commit();
    return metric;
}
Also used : MetricDto(org.sonar.db.metric.MetricDto)

Example 72 with MetricDto

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

the class AppActionTest method insertMetrics.

private void insertMetrics() {
    metricsByKey = new HashMap<>();
    for (String metricKey : AppAction.METRIC_KEYS) {
        MetricDto dto = RegisterMetrics.MetricToDto.INSTANCE.apply(getMetric(metricKey));
        dbTester.getDbClient().metricDao().insert(dbTester.getSession(), dto);
        metricsByKey.put(metricKey, dto);
    }
    dbTester.commit();
}
Also used : MetricDto(org.sonar.db.metric.MetricDto)

Example 73 with MetricDto

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

the class MetricDtoToMetricTest method verify_mapping_from_dto.

@Test
public void verify_mapping_from_dto() {
    for (Metric.MetricType metricType : Metric.MetricType.values()) {
        MetricDto metricDto = createMetricDto(metricType);
        Metric metric = underTest.apply(metricDto);
        assertThat(metric.getId()).isEqualTo(metricDto.getId());
        assertThat(metric.getKey()).isEqualTo(metricDto.getKey());
        assertThat(metric.getName()).isEqualTo(metricDto.getShortName());
        assertThat(metric.getType()).isEqualTo(metricType);
        assertThat(metric.isBestValueOptimized()).isFalse();
        assertThat(metric.getBestValue()).isEqualTo(SOME_BEST_VALUE);
    }
}
Also used : MetricDto(org.sonar.db.metric.MetricDto) Test(org.junit.Test)

Example 74 with MetricDto

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

the class ComponentActionTest method insertNewViolationMetric.

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

Example 75 with MetricDto

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

the class ComponentActionTest method insertNclocMetric.

private MetricDto insertNclocMetric() {
    MetricDto metric = dbClient.metricDao().insert(dbSession, newMetricDtoWithoutOptimization().setKey("ncloc").setShortName("Lines of code").setDescription("Non Commenting Lines of Code").setDomain("Size").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)

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