Search in sources :

Example 1 with SearchWsResponse

use of org.sonarqube.ws.Measures.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.Measures.SearchWsResponse)

Example 2 with SearchWsResponse

use of org.sonarqube.ws.Measures.SearchWsResponse in project sonarqube by SonarSource.

the class SearchActionTest method return_best_value.

@Test
public void return_best_value() {
    ComponentDto project = db.components().insertPrivateProject();
    userSession.addProjectPermission(UserRole.USER, project);
    MetricDto matchBestValue = db.measures().insertMetric(m -> m.setValueType(FLOAT.name()).setBestValue(15.5d));
    db.measures().insertLiveMeasure(project, matchBestValue, m -> m.setValue(15.5d));
    MetricDto doesNotMatchBestValue = db.measures().insertMetric(m -> m.setValueType(INT.name()).setBestValue(50d));
    db.measures().insertLiveMeasure(project, doesNotMatchBestValue, m -> m.setValue(40d));
    MetricDto noBestValue = db.measures().insertMetric(m -> m.setValueType(INT.name()).setBestValue(null));
    db.measures().insertLiveMeasure(project, noBestValue, m -> m.setValue(123d));
    SearchWsResponse result = call(singletonList(project.getDbKey()), asList(matchBestValue.getKey(), doesNotMatchBestValue.getKey(), noBestValue.getKey()));
    List<Measure> measures = result.getMeasuresList();
    assertThat(measures).extracting(Measure::getMetric, Measure::getValue, Measure::getBestValue, Measure::hasBestValue).containsExactlyInAnyOrder(tuple(matchBestValue.getKey(), "15.5", true, true), tuple(doesNotMatchBestValue.getKey(), "40", false, true), tuple(noBestValue.getKey(), "123", false, false));
}
Also used : MetricDto(org.sonar.db.metric.MetricDto) ComponentDto(org.sonar.db.component.ComponentDto) Measure(org.sonarqube.ws.Measures.Measure) SearchWsResponse(org.sonarqube.ws.Measures.SearchWsResponse) Test(org.junit.Test)

Example 3 with SearchWsResponse

use of org.sonarqube.ws.Measures.SearchWsResponse in project sonarqube by SonarSource.

the class SearchActionTest method return_measures_on_new_code_period.

@Test
public void return_measures_on_new_code_period() {
    ComponentDto project = db.components().insertPrivateProject();
    userSession.addProjectPermission(UserRole.USER, project);
    MetricDto coverage = db.measures().insertMetric(m -> m.setValueType(FLOAT.name()));
    db.measures().insertLiveMeasure(project, coverage, m -> m.setValue(15.5d).setVariation(10d));
    SearchWsResponse result = call(singletonList(project.getDbKey()), singletonList(coverage.getKey()));
    List<Measure> measures = result.getMeasuresList();
    assertThat(measures).hasSize(1);
    Measure measure = measures.get(0);
    assertThat(measure.getMetric()).isEqualTo(coverage.getKey());
    assertThat(measure.getValue()).isEqualTo("15.5");
    assertThat(measure.getPeriods().getPeriodsValueList()).extracting(Measures.PeriodValue::getIndex, Measures.PeriodValue::getValue).containsOnly(tuple(1, "10.0"));
}
Also used : MetricDto(org.sonar.db.metric.MetricDto) Measures(org.sonarqube.ws.Measures) ComponentDto(org.sonar.db.component.ComponentDto) Measure(org.sonarqube.ws.Measures.Measure) SearchWsResponse(org.sonarqube.ws.Measures.SearchWsResponse) Test(org.junit.Test)

Example 4 with SearchWsResponse

use of org.sonarqube.ws.Measures.SearchWsResponse in project sonarqube by SonarSource.

the class SearchActionTest method return_measures.

@Test
public void return_measures() {
    ComponentDto project = db.components().insertPrivateProject();
    userSession.addProjectPermission(UserRole.USER, project);
    MetricDto coverage = db.measures().insertMetric(m -> m.setValueType(FLOAT.name()));
    db.measures().insertLiveMeasure(project, coverage, m -> m.setValue(15.5d));
    SearchWsResponse result = call(singletonList(project.getDbKey()), singletonList(coverage.getKey()));
    List<Measure> measures = result.getMeasuresList();
    assertThat(measures).hasSize(1);
    Measure measure = measures.get(0);
    assertThat(measure.getMetric()).isEqualTo(coverage.getKey());
    assertThat(measure.getValue()).isEqualTo("15.5");
}
Also used : MetricDto(org.sonar.db.metric.MetricDto) ComponentDto(org.sonar.db.component.ComponentDto) Measure(org.sonarqube.ws.Measures.Measure) SearchWsResponse(org.sonarqube.ws.Measures.SearchWsResponse) Test(org.junit.Test)

Example 5 with SearchWsResponse

use of org.sonarqube.ws.Measures.SearchWsResponse in project sonarqube by SonarSource.

the class SearchActionTest method return_measures_on_view.

@Test
public void return_measures_on_view() {
    ComponentDto view = db.components().insertPrivatePortfolio();
    userSession.addProjectPermission(UserRole.USER, view);
    MetricDto coverage = db.measures().insertMetric(m -> m.setValueType(FLOAT.name()));
    db.measures().insertLiveMeasure(view, coverage, m -> m.setValue(15.5d));
    SearchWsResponse result = call(singletonList(view.getDbKey()), singletonList(coverage.getKey()));
    List<Measure> measures = result.getMeasuresList();
    assertThat(measures).hasSize(1);
    Measure measure = measures.get(0);
    assertThat(measure.getMetric()).isEqualTo(coverage.getKey());
    assertThat(measure.getValue()).isEqualTo("15.5");
}
Also used : MetricDto(org.sonar.db.metric.MetricDto) ComponentDto(org.sonar.db.component.ComponentDto) Measure(org.sonarqube.ws.Measures.Measure) SearchWsResponse(org.sonarqube.ws.Measures.SearchWsResponse) Test(org.junit.Test)

Aggregations

SearchWsResponse (org.sonarqube.ws.Measures.SearchWsResponse)11 Test (org.junit.Test)10 ComponentDto (org.sonar.db.component.ComponentDto)10 MetricDto (org.sonar.db.metric.MetricDto)10 Measure (org.sonarqube.ws.Measures.Measure)6 DbSession (org.sonar.db.DbSession)1 Measures (org.sonarqube.ws.Measures)1