Search in sources :

Example 1 with SearchWsResponse

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);
    }
}
Also used : DbSession(org.sonar.db.DbSession) SearchWsResponse(org.sonarqube.ws.WsMeasures.SearchWsResponse)

Example 2 with SearchWsResponse

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");
}
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 3 with SearchWsResponse

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"));
}
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 4 with SearchWsResponse

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());
}
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 5 with SearchWsResponse

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

Aggregations

SearchWsResponse (org.sonarqube.ws.WsMeasures.SearchWsResponse)6 Test (org.junit.Test)5 ComponentDto (org.sonar.db.component.ComponentDto)5 SnapshotDto (org.sonar.db.component.SnapshotDto)5 MetricDto (org.sonar.db.metric.MetricDto)5 MetricTesting.newMetricDto (org.sonar.db.metric.MetricTesting.newMetricDto)5 Measure (org.sonarqube.ws.WsMeasures.Measure)2 DbSession (org.sonar.db.DbSession)1 OrganizationDto (org.sonar.db.organization.OrganizationDto)1 WsMeasures (org.sonarqube.ws.WsMeasures)1