use of org.sonarqube.ws.Measures.Measure in project sonarqube by SonarSource.
the class ComponentTreeActionTest method pull_request.
@Test
public void pull_request() {
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 complexity = db.measures().insertMetric(m -> m.setValueType(INT.name()));
LiveMeasureDto measure = db.measures().insertLiveMeasure(file, complexity, m -> m.setValue(12.0d));
ComponentTreeWsResponse response = ws.newRequest().setParam(PARAM_COMPONENT, file.getKey()).setParam(PARAM_PULL_REQUEST, "pr-123").setParam(PARAM_METRIC_KEYS, complexity.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.getValue())).containsExactlyInAnyOrder(tuple(complexity.getKey(), measure.getValue()));
}
use of org.sonarqube.ws.Measures.Measure in project sonarqube by SonarSource.
the class ComponentTreeActionTest method return_is_best_value_on_leak_measures.
@Test
public void return_is_best_value_on_leak_measures() {
ComponentDto project = db.components().insertPrivateProject();
db.components().insertSnapshot(project);
userSession.anonymous().addProjectPermission(UserRole.USER, project);
ComponentDto file = newFileDto(project, null);
db.components().insertComponent(file);
MetricDto matchingBestValue = db.measures().insertMetric(m -> m.setKey("new_lines").setValueType(INT.name()).setBestValue(100d));
MetricDto doesNotMatchBestValue = db.measures().insertMetric(m -> m.setKey("new_lines_2").setValueType(INT.name()).setBestValue(100d));
MetricDto noBestValue = db.measures().insertMetric(m -> m.setKey("new_violations").setValueType(INT.name()).setBestValue(null));
db.measures().insertLiveMeasure(file, matchingBestValue, m -> m.setValue(null).setData((String) null).setVariation(100d));
db.measures().insertLiveMeasure(file, doesNotMatchBestValue, m -> m.setValue(null).setData((String) null).setVariation(10d));
db.measures().insertLiveMeasure(file, noBestValue, m -> m.setValue(null).setData((String) null).setVariation(42.0d));
ComponentTreeWsResponse response = ws.newRequest().setParam(PARAM_COMPONENT, project.getKey()).setParam(PARAM_METRIC_KEYS, "new_lines,new_lines_2,new_violations").executeProtobuf(ComponentTreeWsResponse.class);
// file measures
// verify backward compatibility
List<Measure> fileMeasures = response.getComponentsList().get(0).getMeasuresList();
assertThat(fileMeasures).extracting(Measure::getMetric, m -> m.getPeriods().getPeriodsValueList()).containsExactlyInAnyOrder(tuple(matchingBestValue.getKey(), singletonList(PeriodValue.newBuilder().setIndex(1).setValue("100").setBestValue(true).build())), tuple(doesNotMatchBestValue.getKey(), singletonList(PeriodValue.newBuilder().setIndex(1).setValue("10").setBestValue(false).build())), tuple(noBestValue.getKey(), singletonList(PeriodValue.newBuilder().setIndex(1).setValue("42").build())));
assertThat(fileMeasures).extracting(Measure::getMetric, Measure::getPeriod).containsExactlyInAnyOrder(tuple(matchingBestValue.getKey(), PeriodValue.newBuilder().setIndex(1).setValue("100").setBestValue(true).build()), tuple(doesNotMatchBestValue.getKey(), PeriodValue.newBuilder().setIndex(1).setValue("10").setBestValue(false).build()), tuple(noBestValue.getKey(), PeriodValue.newBuilder().setIndex(1).setValue("42").build()));
}
use of org.sonarqube.ws.Measures.Measure in project sonarqube by SonarSource.
the class ComponentTreeActionTest method load_measures_with_best_value.
@Test
public void load_measures_with_best_value() {
ComponentDto project = db.components().insertPrivateProject();
SnapshotDto projectSnapshot = db.components().insertSnapshot(project);
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 coverage = insertCoverageMetric();
dbClient.metricDao().insert(dbSession, MetricTesting.newMetricDto().setKey("ncloc").setValueType(INT.name()).setOptimizedBestValue(true).setBestValue(100d).setWorstValue(1000d));
dbClient.metricDao().insert(dbSession, newMetricDto().setKey("new_violations").setOptimizedBestValue(true).setBestValue(1984.0d).setValueType(INT.name()));
db.commit();
db.measures().insertLiveMeasure(file, coverage, m -> m.setValue(15.5d));
db.measures().insertLiveMeasure(directory, coverage, m -> m.setValue(42.0d));
ComponentTreeWsResponse response = ws.newRequest().setParam(PARAM_COMPONENT, project.getKey()).setParam(PARAM_METRIC_KEYS, "ncloc,coverage,new_violations").setParam(PARAM_ADDITIONAL_FIELDS, "metrics").executeProtobuf(ComponentTreeWsResponse.class);
// directory measures
assertThat(response.getComponentsList().get(0).getMeasuresList()).extracting("metric").containsOnly("coverage");
// file measures
List<Measure> fileMeasures = response.getComponentsList().get(1).getMeasuresList();
assertThat(fileMeasures).extracting(Measure::getMetric, Measure::getValue, Measure::getBestValue, Measure::hasBestValue).containsExactlyInAnyOrder(tuple("ncloc", "100", true, true), tuple("coverage", "15.5", false, false), tuple("new_violations", "", false, false));
List<Common.Metric> metrics = response.getMetrics().getMetricsList();
assertThat(metrics).extracting("bestValue").contains("100", "");
assertThat(metrics).extracting("worstValue").contains("1000");
}
use of org.sonarqube.ws.Measures.Measure in project sonarqube by SonarSource.
the class ComponentTreeActionTest method branch.
@Test
public void branch() {
ComponentDto project = db.components().insertPrivateProject();
ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey("my_branch"));
SnapshotDto analysis = db.components().insertSnapshot(branch);
ComponentDto file = db.components().insertComponent(newFileDto(branch));
MetricDto complexity = db.measures().insertMetric(m -> m.setValueType(INT.name()));
LiveMeasureDto measure = db.measures().insertLiveMeasure(file, complexity, m -> m.setValue(12.0d));
ComponentTreeWsResponse response = ws.newRequest().setParam(PARAM_COMPONENT, file.getKey()).setParam(PARAM_BRANCH, file.getBranch()).setParam(PARAM_METRIC_KEYS, complexity.getKey()).executeProtobuf(ComponentTreeWsResponse.class);
assertThat(response.getBaseComponent()).extracting(Component::getKey, Component::getBranch).containsExactlyInAnyOrder(file.getKey(), file.getBranch());
assertThat(response.getBaseComponent().getMeasuresList()).extracting(Measure::getMetric, m -> parseDouble(m.getValue())).containsExactlyInAnyOrder(tuple(complexity.getKey(), measure.getValue()));
}
use of org.sonarqube.ws.Measures.Measure 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));
}
Aggregations