Search in sources :

Example 61 with MetricDto

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

the class SearchActionTest method insertNewViolationsMetric.

private MetricDto insertNewViolationsMetric() {
    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).setOptimizedBestValue(true).setBestValue(0.0d));
    db.commit();
    return metric;
}
Also used : MetricTesting.newMetricDto(org.sonar.db.metric.MetricTesting.newMetricDto) MetricDto(org.sonar.db.metric.MetricDto)

Example 62 with MetricDto

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

the class SearchActionTest method return_measures.

@Test
public void return_measures() throws Exception {
    ComponentDto project = newProjectDto(db.getDefaultOrganization());
    SnapshotDto projectSnapshot = db.components().insertProjectAndSnapshot(project);
    setBrowsePermissionOnUser(project);
    MetricDto coverage = insertCoverageMetric();
    dbClient.measureDao().insert(dbSession, newMeasureDto(coverage, project, projectSnapshot).setValue(15.5d));
    db.commit();
    SearchWsResponse result = call(singletonList(project.key()), singletonList("coverage"));
    List<Measure> measures = result.getMeasuresList();
    assertThat(measures).hasSize(1);
    Measure measure = measures.get(0);
    assertThat(measure.getMetric()).isEqualTo("coverage");
    assertThat(measure.getValue()).isEqualTo("15.5");
}
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) Measure(org.sonarqube.ws.WsMeasures.Measure) SearchWsResponse(org.sonarqube.ws.WsMeasures.SearchWsResponse) Test(org.junit.Test)

Example 63 with MetricDto

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

the class SearchActionTest method return_measures_on_leak_period.

@Test
public void return_measures_on_leak_period() throws Exception {
    ComponentDto project = newProjectDto(db.organizations().insert());
    SnapshotDto projectSnapshot = db.components().insertProjectAndSnapshot(project);
    setBrowsePermissionOnUser(project);
    MetricDto coverage = insertCoverageMetric();
    dbClient.measureDao().insert(dbSession, newMeasureDto(coverage, project, projectSnapshot).setValue(15.5d).setVariation(10d));
    db.commit();
    SearchWsResponse result = call(singletonList(project.key()), singletonList("coverage"));
    List<Measure> measures = result.getMeasuresList();
    assertThat(measures).hasSize(1);
    Measure measure = measures.get(0);
    assertThat(measure.getMetric()).isEqualTo("coverage");
    assertThat(measure.getValue()).isEqualTo("15.5");
    assertThat(measure.getPeriods().getPeriodsValueList()).extracting(WsMeasures.PeriodValue::getIndex, WsMeasures.PeriodValue::getValue).containsOnly(tuple(1, "10.0"));
}
Also used : MetricTesting.newMetricDto(org.sonar.db.metric.MetricTesting.newMetricDto) MetricDto(org.sonar.db.metric.MetricDto) WsMeasures(org.sonarqube.ws.WsMeasures) SnapshotDto(org.sonar.db.component.SnapshotDto) ComponentDto(org.sonar.db.component.ComponentDto) Measure(org.sonarqube.ws.WsMeasures.Measure) SearchWsResponse(org.sonarqube.ws.WsMeasures.SearchWsResponse) Test(org.junit.Test)

Example 64 with MetricDto

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

the class ProjectStatusActionTest method return_status_by_project_key.

@Test
public void return_status_by_project_key() throws IOException {
    ComponentDto project = db.components().insertComponent(newProjectDto(db.organizations().insert()).setKey("project-key"));
    SnapshotDto snapshot = dbClient.snapshotDao().insert(dbSession, newAnalysis(project).setPeriodMode("last_version").setPeriodParam("2015-12-07").setPeriodDate(956789123987L));
    MetricDto metric = dbClient.metricDao().insert(dbSession, newMetricDto().setEnabled(true).setKey(CoreMetrics.QUALITY_GATE_DETAILS_KEY));
    dbClient.measureDao().insert(dbSession, newMeasureDto(metric, project, snapshot).setData(IOUtils.toString(getClass().getResource("ProjectStatusActionTest/measure_data.json"))));
    dbSession.commit();
    userSession.addProjectUuidPermissions(UserRole.USER, project.uuid());
    String response = ws.newRequest().setParam(PARAM_PROJECT_KEY, "project-key").execute().getInput();
    assertJson(response).isSimilarTo(getClass().getResource("project_status-example.json"));
}
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) Test(org.junit.Test)

Example 65 with MetricDto

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

the class QualityGateConditionsUpdaterTest method create_error_condition_with_period.

@Test
public void create_error_condition_with_period() {
    MetricDto metricDto = dbClient.metricDao().insert(dbSession, newMetricDto().setKey("new_coverage").setValueType(INT.name()).setHidden(false));
    dbSession.commit();
    QualityGateConditionDto result = underTest.createCondition(dbSession, qualityGateDto.getId(), "new_coverage", "LT", null, "80", 1);
    verifyCondition(result, metricDto.getId(), "LT", null, "80", 1);
}
Also used : MetricTesting.newMetricDto(org.sonar.db.metric.MetricTesting.newMetricDto) MetricDto(org.sonar.db.metric.MetricDto) QualityGateConditionDto(org.sonar.db.qualitygate.QualityGateConditionDto) 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