Search in sources :

Example 91 with MetricDto

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

the class SearchActionTest method only_returns_authorized_projects.

@Test
public void only_returns_authorized_projects() {
    MetricDto metricDto = insertComplexityMetric();
    ComponentDto project1 = newProjectDto(db.getDefaultOrganization());
    SnapshotDto projectSnapshot1 = db.components().insertProjectAndSnapshot(project1);
    ComponentDto project2 = newProjectDto(db.getDefaultOrganization());
    SnapshotDto projectSnapshot2 = db.components().insertProjectAndSnapshot(project2);
    dbClient.measureDao().insert(dbSession, newMeasureDto(metricDto, project1, projectSnapshot1).setValue(15.5d), newMeasureDto(metricDto, project2, projectSnapshot2).setValue(42.0d));
    db.commit();
    setBrowsePermissionOnUser(project1);
    SearchWsResponse result = call(asList(project1.key(), project2.key()), singletonList("complexity"));
    assertThat(result.getMeasuresList()).extracting(Measure::getComponent).containsOnly(project1.key());
}
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) SearchWsResponse(org.sonarqube.ws.WsMeasures.SearchWsResponse) Test(org.junit.Test)

Example 92 with MetricDto

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

the class SearchActionTest 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)

Example 93 with MetricDto

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

the class SearchActionTest method sort_by_metric_key_then_project_name.

@Test
public void sort_by_metric_key_then_project_name() throws Exception {
    MetricDto coverage = insertCoverageMetric();
    MetricDto complexity = insertComplexityMetric();
    OrganizationDto organizationDto = db.organizations().insert();
    ComponentDto project1 = newProjectDto(organizationDto).setName("C");
    SnapshotDto projectSnapshot1 = db.components().insertProjectAndSnapshot(project1);
    ComponentDto project2 = newProjectDto(organizationDto).setName("A");
    SnapshotDto projectSnapshot2 = db.components().insertProjectAndSnapshot(project2);
    ComponentDto project3 = newProjectDto(organizationDto).setName("B");
    SnapshotDto projectSnapshot3 = db.components().insertProjectAndSnapshot(project3);
    setBrowsePermissionOnUser(project1, project2, project3);
    dbClient.measureDao().insert(dbSession, newMeasureDto(coverage, project1, projectSnapshot1).setValue(5.5d));
    dbClient.measureDao().insert(dbSession, newMeasureDto(coverage, project2, projectSnapshot2).setValue(6.5d));
    dbClient.measureDao().insert(dbSession, newMeasureDto(coverage, project3, projectSnapshot3).setValue(7.5d));
    dbClient.measureDao().insert(dbSession, newMeasureDto(complexity, project1, projectSnapshot1).setValue(10d));
    dbClient.measureDao().insert(dbSession, newMeasureDto(complexity, project2, projectSnapshot2).setValue(15d));
    dbClient.measureDao().insert(dbSession, newMeasureDto(complexity, project3, projectSnapshot3).setValue(20d));
    db.commit();
    SearchWsResponse result = call(asList(project1.key(), project2.key(), project3.key()), asList("coverage", "complexity"));
    assertThat(result.getMeasuresList()).extracting(Measure::getMetric, Measure::getComponent).containsExactly(tuple("complexity", project2.key()), tuple("complexity", project3.key()), tuple("complexity", project1.key()), tuple("coverage", project2.key()), tuple("coverage", project3.key()), tuple("coverage", project1.key()));
}
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) SearchWsResponse(org.sonarqube.ws.WsMeasures.SearchWsResponse) OrganizationDto(org.sonar.db.organization.OrganizationDto) Test(org.junit.Test)

Example 94 with MetricDto

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

the class SearchActionTest method do_not_verify_permissions_if_user_is_root.

@Test
public void do_not_verify_permissions_if_user_is_root() {
    MetricDto metricDto = insertComplexityMetric();
    ComponentDto project1 = newProjectDto(db.getDefaultOrganization());
    SnapshotDto projectSnapshot1 = db.components().insertProjectAndSnapshot(project1);
    dbClient.measureDao().insert(dbSession, newMeasureDto(metricDto, project1, projectSnapshot1).setValue(15.5d));
    db.commit();
    userSession.setNonRoot();
    SearchWsResponse result = call(asList(project1.key()), singletonList("complexity"));
    assertThat(result.getMeasuresCount()).isEqualTo(0);
    userSession.setRoot();
    result = call(asList(project1.key()), singletonList("complexity"));
    assertThat(result.getMeasuresCount()).isEqualTo(1);
}
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) SearchWsResponse(org.sonarqube.ws.WsMeasures.SearchWsResponse) Test(org.junit.Test)

Example 95 with MetricDto

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

the class SearchActionTest method insertJsonExampleData.

private List<String> insertJsonExampleData() {
    List<String> projectKeys = new ArrayList<>();
    OrganizationDto organizationDto = db.organizations().insert();
    ComponentDto project1 = newProjectDto(organizationDto).setKey("MY_PROJECT_1").setName("Project 1");
    ComponentDto project2 = newProjectDto(organizationDto).setKey("MY_PROJECT_2").setName("Project 2");
    ComponentDto project3 = newProjectDto(organizationDto).setKey("MY_PROJECT_3").setName("Project 3");
    projectKeys.addAll(asList(project1.key(), project2.key(), project3.key()));
    db.components().insertComponents(project1, project2, project3);
    SnapshotDto projectSnapshot1 = dbClient.snapshotDao().insert(dbSession, newAnalysis(project1).setPeriodDate(parseDateTime("2016-01-11T10:49:50+0100").getTime()).setPeriodMode("previous_version").setPeriodParam("1.0-SNAPSHOT"));
    SnapshotDto projectSnapshot2 = dbClient.snapshotDao().insert(dbSession, newAnalysis(project2).setPeriodDate(parseDateTime("2016-01-11T10:49:50+0100").getTime()).setPeriodMode("previous_version").setPeriodParam("1.0-SNAPSHOT"));
    SnapshotDto projectSnapshot3 = dbClient.snapshotDao().insert(dbSession, newAnalysis(project3).setPeriodDate(parseDateTime("2016-01-11T10:49:50+0100").getTime()).setPeriodMode("previous_version").setPeriodParam("1.0-SNAPSHOT"));
    MetricDto complexity = insertComplexityMetric();
    dbClient.measureDao().insert(dbSession, newMeasureDto(complexity, project1, projectSnapshot1).setValue(12.0d), newMeasureDto(complexity, project2, projectSnapshot2).setValue(35.0d).setVariation(0.0d), newMeasureDto(complexity, project1, projectSnapshot3).setValue(42.0d));
    MetricDto ncloc = insertNclocMetric();
    dbClient.measureDao().insert(dbSession, newMeasureDto(ncloc, project1, projectSnapshot1).setValue(114.0d), newMeasureDto(ncloc, project2, projectSnapshot2).setValue(217.0d).setVariation(0.0d), newMeasureDto(ncloc, project3, projectSnapshot3).setValue(1984.0d));
    MetricDto newViolations = insertNewViolationsMetric();
    dbClient.measureDao().insert(dbSession, newMeasureDto(newViolations, project1, projectSnapshot1).setVariation(25.0d), newMeasureDto(newViolations, project2, projectSnapshot2).setVariation(25.0d), newMeasureDto(newViolations, project3, projectSnapshot3).setVariation(255.0d));
    db.commit();
    setBrowsePermissionOnUser(project1, project2, project3);
    return projectKeys;
}
Also used : MetricTesting.newMetricDto(org.sonar.db.metric.MetricTesting.newMetricDto) MetricDto(org.sonar.db.metric.MetricDto) SnapshotDto(org.sonar.db.component.SnapshotDto) ArrayList(java.util.ArrayList) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) ComponentDto(org.sonar.db.component.ComponentDto) OrganizationDto(org.sonar.db.organization.OrganizationDto)

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