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());
}
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;
}
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()));
}
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);
}
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;
}
Aggregations