use of org.sonarqube.ws.WsMeasures.SearchWsResponse in project sonarqube by SonarSource.
the class SearchAction method handle.
@Override
public void handle(Request httpRequest, Response httpResponse) throws Exception {
try (DbSession dbSession = dbClient.openSession(false)) {
SearchWsResponse response = new ResponseBuilder(httpRequest, dbSession).build();
writeProtobuf(response, httpRequest, httpResponse);
}
}
use of org.sonarqube.ws.WsMeasures.SearchWsResponse 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");
}
use of org.sonarqube.ws.WsMeasures.SearchWsResponse 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"));
}
use of org.sonarqube.ws.WsMeasures.SearchWsResponse 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.sonarqube.ws.WsMeasures.SearchWsResponse 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()));
}
Aggregations