Search in sources :

Example 11 with Measure

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

the class SearchActionTest method return_measures_on_application.

@Test
public void return_measures_on_application() {
    ComponentDto application = db.components().insertPrivateApplication();
    userSession.addProjectPermission(UserRole.USER, application);
    MetricDto coverage = db.measures().insertMetric(m -> m.setValueType(FLOAT.name()));
    db.measures().insertLiveMeasure(application, coverage, m -> m.setValue(15.5d));
    SearchWsResponse result = call(singletonList(application.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 12 with Measure

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

the class SearchActionTest method return_measures_on_sub_view.

@Test
public void return_measures_on_sub_view() {
    ComponentDto view = db.components().insertPrivatePortfolio();
    ComponentDto subView = db.components().insertComponent(newSubPortfolio(view));
    userSession.addProjectPermission(UserRole.USER, subView);
    MetricDto metric = db.measures().insertMetric(m -> m.setValueType(FLOAT.name()));
    db.measures().insertLiveMeasure(subView, metric, m -> m.setValue(15.5d));
    SearchWsResponse result = call(singletonList(subView.getDbKey()), singletonList(metric.getKey()));
    List<Measure> measures = result.getMeasuresList();
    assertThat(measures).hasSize(1);
    Measure measure = measures.get(0);
    assertThat(measure.getMetric()).isEqualTo(metric.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

Test (org.junit.Test)12 ComponentDto (org.sonar.db.component.ComponentDto)12 MetricDto (org.sonar.db.metric.MetricDto)12 Measure (org.sonarqube.ws.Measures.Measure)12 SnapshotDto (org.sonar.db.component.SnapshotDto)6 ComponentTreeWsResponse (org.sonarqube.ws.Measures.ComponentTreeWsResponse)6 Metric (org.sonar.api.measures.Metric)5 Joiner (com.google.common.base.Joiner)4 Double.parseDouble (java.lang.Double.parseDouble)4 String.format (java.lang.String.format)4 Collections.singletonList (java.util.Collections.singletonList)4 List (java.util.List)4 IntStream (java.util.stream.IntStream)4 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)4 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)4 Assertions.tuple (org.assertj.core.api.Assertions.tuple)4 Rule (org.junit.Rule)4 CoreMetrics (org.sonar.api.measures.CoreMetrics)4 NEW_SECURITY_RATING_KEY (org.sonar.api.measures.CoreMetrics.NEW_SECURITY_RATING_KEY)4 DISTRIB (org.sonar.api.measures.Metric.ValueType.DISTRIB)4