use of org.sonarqube.ws.Measures.SearchWsResponse 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");
}
use of org.sonarqube.ws.Measures.SearchWsResponse 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");
}
use of org.sonarqube.ws.Measures.SearchWsResponse 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 metric = db.measures().insertMetric(m -> m.setValueType(FLOAT.name()));
ComponentDto project1 = db.components().insertPrivateProject();
db.measures().insertLiveMeasure(project1, metric, m -> m.setValue(15.5d));
userSession.setNonRoot();
SearchWsResponse result = call(singletonList(project1.getDbKey()), singletonList(metric.getKey()));
assertThat(result.getMeasuresCount()).isZero();
userSession.setRoot();
result = call(singletonList(project1.getDbKey()), singletonList(metric.getKey()));
assertThat(result.getMeasuresCount()).isOne();
}
use of org.sonarqube.ws.Measures.SearchWsResponse in project sonarqube by SonarSource.
the class SearchActionTest method only_returns_authorized_projects.
@Test
public void only_returns_authorized_projects() {
MetricDto metric = db.measures().insertMetric(m -> m.setValueType(FLOAT.name()));
ComponentDto project1 = db.components().insertPrivateProject();
ComponentDto project2 = db.components().insertPrivateProject();
db.measures().insertLiveMeasure(project1, metric, m -> m.setValue(15.5d));
db.measures().insertLiveMeasure(project2, metric, m -> m.setValue(42.0d));
Arrays.stream(new ComponentDto[] { project1 }).forEach(p -> userSession.addProjectPermission(UserRole.USER, p));
SearchWsResponse result = call(asList(project1.getDbKey(), project2.getDbKey()), singletonList(metric.getKey()));
assertThat(result.getMeasuresList()).extracting(Measure::getComponent).containsOnly(project1.getDbKey());
}
use of org.sonarqube.ws.Measures.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() {
MetricDto coverage = db.measures().insertMetric(m -> m.setKey("coverage").setValueType(FLOAT.name()));
MetricDto complexity = db.measures().insertMetric(m -> m.setKey("complexity").setValueType(INT.name()));
ComponentDto project1 = db.components().insertPrivateProject(p -> p.setName("C"));
ComponentDto project2 = db.components().insertPrivateProject(p -> p.setName("A"));
ComponentDto project3 = db.components().insertPrivateProject(p -> p.setName("B"));
userSession.addProjectPermission(UserRole.USER, project1);
userSession.addProjectPermission(UserRole.USER, project2);
userSession.addProjectPermission(UserRole.USER, project3);
db.measures().insertLiveMeasure(project1, coverage, m -> m.setValue(5.5d));
db.measures().insertLiveMeasure(project2, coverage, m -> m.setValue(6.5d));
db.measures().insertLiveMeasure(project3, coverage, m -> m.setValue(7.5d));
db.measures().insertLiveMeasure(project1, complexity, m -> m.setValue(10d));
db.measures().insertLiveMeasure(project2, complexity, m -> m.setValue(15d));
db.measures().insertLiveMeasure(project3, complexity, m -> m.setValue(20d));
SearchWsResponse result = call(asList(project1.getDbKey(), project2.getDbKey(), project3.getDbKey()), asList(coverage.getKey(), complexity.getKey()));
assertThat(result.getMeasuresList()).extracting(Measure::getMetric, Measure::getComponent).containsExactly(tuple(complexity.getKey(), project2.getDbKey()), tuple(complexity.getKey(), project3.getDbKey()), tuple(complexity.getKey(), project1.getDbKey()), tuple(coverage.getKey(), project2.getDbKey()), tuple(coverage.getKey(), project3.getDbKey()), tuple(coverage.getKey(), project1.getDbKey()));
}
Aggregations