use of org.sonarqube.ws.Measures.Measure 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"));
}
use of org.sonarqube.ws.Measures.Measure 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");
}
use of org.sonarqube.ws.Measures.Measure in project sonarqube by SonarSource.
the class ComponentTreeActionTest method fix_pull_request_new_issue_count_metrics.
@Test
public void fix_pull_request_new_issue_count_metrics() {
ComponentDto project = db.components().insertPrivateProject();
ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey("pr-123").setBranchType(PULL_REQUEST));
SnapshotDto analysis = db.components().insertSnapshot(branch);
ComponentDto file = db.components().insertComponent(newFileDto(branch));
MetricDto bug = db.measures().insertMetric(m -> m.setValueType(INT.name()).setKey(CoreMetrics.BUGS_KEY));
MetricDto newBug = db.measures().insertMetric(m -> m.setValueType(INT.name()).setKey(CoreMetrics.NEW_BUGS_KEY));
LiveMeasureDto measure = db.measures().insertLiveMeasure(file, bug, m -> m.setValue(12.0d));
ComponentTreeWsResponse response = ws.newRequest().setParam(PARAM_COMPONENT, file.getKey()).setParam(PARAM_PULL_REQUEST, "pr-123").setParam(PARAM_METRIC_KEYS, newBug.getKey()).executeProtobuf(ComponentTreeWsResponse.class);
assertThat(response.getBaseComponent()).extracting(Component::getKey, Component::getPullRequest).containsExactlyInAnyOrder(file.getKey(), "pr-123");
assertThat(response.getBaseComponent().getMeasuresList()).extracting(Measure::getMetric, m -> parseDouble(m.getPeriods().getPeriodsValue(0).getValue()), Measure::getValue).containsExactlyInAnyOrder(tuple(newBug.getKey(), measure.getValue(), ""));
assertThat(response.getBaseComponent().getMeasuresList()).extracting(Measure::getMetric, m -> parseDouble(m.getPeriod().getValue()), Measure::getValue).containsExactlyInAnyOrder(tuple(newBug.getKey(), measure.getValue(), ""));
}
use of org.sonarqube.ws.Measures.Measure in project sonarqube by SonarSource.
the class ComponentTreeActionTest method load_measures_and_periods.
@Test
public void load_measures_and_periods() {
ComponentDto project = db.components().insertPrivateProject();
SnapshotDto projectSnapshot = dbClient.snapshotDao().insert(dbSession, newAnalysis(project).setPeriodDate(System.currentTimeMillis()).setPeriodMode("last_version").setPeriodDate(System.currentTimeMillis()));
userSession.anonymous().addProjectPermission(UserRole.USER, project);
ComponentDto directory = newDirectory(project, "directory-uuid", "path/to/directory").setName("directory-1");
db.components().insertComponent(directory);
ComponentDto file = newFileDto(directory, null, "file-uuid").setName("file-1");
db.components().insertComponent(file);
MetricDto ncloc = insertNclocMetric();
MetricDto coverage = insertCoverageMetric();
db.commit();
db.measures().insertLiveMeasure(file, ncloc, m -> m.setValue(5.0d).setVariation(4.0d));
db.measures().insertLiveMeasure(file, coverage, m -> m.setValue(15.5d));
db.measures().insertLiveMeasure(directory, coverage, m -> m.setValue(15.5d));
ComponentTreeWsResponse response = ws.newRequest().setParam(PARAM_COMPONENT, project.getKey()).setParam(PARAM_METRIC_KEYS, "ncloc,coverage").setParam(PARAM_ADDITIONAL_FIELDS, DEPRECATED_ADDITIONAL_PERIODS + "," + ADDITIONAL_PERIOD).executeProtobuf(ComponentTreeWsResponse.class);
assertThat(response.getComponentsList().get(0).getMeasuresList()).extracting("metric").containsOnly("coverage");
// file measures
List<Measure> fileMeasures = response.getComponentsList().get(1).getMeasuresList();
assertThat(fileMeasures).extracting("metric").containsOnly("ncloc", "coverage");
assertThat(fileMeasures).extracting("value").containsOnly("5", "15.5");
assertThat(response.getPeriod().getMode()).isEqualTo("last_version");
assertThat(response.getPeriods().getPeriodsList()).extracting("mode").containsOnly("last_version");
}
use of org.sonarqube.ws.Measures.Measure 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");
}
Aggregations