use of org.sonar.db.measure.LiveMeasureDto in project sonarqube by SonarSource.
the class ComponentActionTest method new_issue_count_measures_are_transformed_in_pr.
@Test
public void new_issue_count_measures_are_transformed_in_pr() {
ComponentDto project = db.components().insertPrivateProject();
userSession.addProjectPermission(UserRole.USER, project);
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 bugs = db.measures().insertMetric(m1 -> m1.setKey("bugs").setValueType("INT"));
MetricDto newBugs = db.measures().insertMetric(m1 -> m1.setKey("new_bugs").setValueType("INT"));
MetricDto violations = db.measures().insertMetric(m1 -> m1.setKey("violations").setValueType("INT"));
MetricDto newViolations = db.measures().insertMetric(m1 -> m1.setKey("new_violations").setValueType("INT"));
LiveMeasureDto bugMeasure = db.measures().insertLiveMeasure(file, bugs, m -> m.setValue(12.0d).setVariation(null));
LiveMeasureDto newBugMeasure = db.measures().insertLiveMeasure(file, newBugs, m -> m.setVariation(1d).setValue(null));
LiveMeasureDto violationMeasure = db.measures().insertLiveMeasure(file, violations, m -> m.setValue(20.0d).setVariation(null));
ComponentWsResponse response = ws.newRequest().setParam(PARAM_COMPONENT, file.getKey()).setParam(PARAM_PULL_REQUEST, "pr-123").setParam(PARAM_METRIC_KEYS, newBugs.getKey() + "," + bugs.getKey() + "," + newViolations.getKey()).executeProtobuf(ComponentWsResponse.class);
assertThat(response.getComponent()).extracting(Component::getKey, Component::getPullRequest).containsExactlyInAnyOrder(file.getKey(), "pr-123");
Function<Measures.Measure, Double> extractVariation = m -> {
if (m.getPeriods().getPeriodsValueCount() > 0) {
return parseDouble(m.getPeriods().getPeriodsValue(0).getValue());
}
return null;
};
assertThat(response.getComponent().getMeasuresList()).extracting(Measures.Measure::getMetric, extractVariation, m -> m.getValue().isEmpty() ? null : parseDouble(m.getValue())).containsExactlyInAnyOrder(tuple(newBugs.getKey(), bugMeasure.getValue(), null), tuple(bugs.getKey(), null, bugMeasure.getValue()), tuple(newViolations.getKey(), violationMeasure.getValue(), null));
}
use of org.sonar.db.measure.LiveMeasureDto in project sonarqube by SonarSource.
the class ComponentActionTest method branch.
@Test
public void branch() {
ComponentDto project = db.components().insertPrivateProject();
userSession.addProjectPermission(UserRole.USER, project);
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(m1 -> m1.setKey("complexity").setValueType("INT"));
LiveMeasureDto measure = db.measures().insertLiveMeasure(file, complexity, m -> m.setValue(12.0d).setVariation(2.0d));
ComponentWsResponse response = ws.newRequest().setParam(PARAM_COMPONENT, file.getKey()).setParam(PARAM_BRANCH, file.getBranch()).setParam(PARAM_METRIC_KEYS, complexity.getKey()).executeProtobuf(ComponentWsResponse.class);
assertThat(response.getComponent()).extracting(Component::getKey, Component::getBranch).containsExactlyInAnyOrder(file.getKey(), file.getBranch());
assertThat(response.getComponent().getMeasuresList()).extracting(Measures.Measure::getMetric, m -> parseDouble(m.getValue())).containsExactlyInAnyOrder(tuple(complexity.getKey(), measure.getValue()));
}
use of org.sonar.db.measure.LiveMeasureDto in project sonarqube by SonarSource.
the class ComponentTreeSortTest method setUp.
@Before
public void setUp() {
components = newArrayList(newComponentWithoutSnapshotId("name-1", "qualifier-2", "path-9"), newComponentWithoutSnapshotId("name-3", "qualifier-3", "path-8"), newComponentWithoutSnapshotId("name-2", "qualifier-4", "path-7"), newComponentWithoutSnapshotId("name-4", "qualifier-5", "path-6"), newComponentWithoutSnapshotId("name-7", "qualifier-6", "path-5"), newComponentWithoutSnapshotId("name-6", "qualifier-7", "path-4"), newComponentWithoutSnapshotId("name-5", "qualifier-8", "path-3"), newComponentWithoutSnapshotId("name-9", "qualifier-9", "path-2"), newComponentWithoutSnapshotId("name-8", "qualifier-1", "path-1"));
MetricDto violationsMetric = newMetricDto().setKey(NUM_METRIC_KEY).setValueType(ValueType.INT.name());
MetricDto sqaleIndexMetric = newMetricDto().setKey(TEXT_METRIC_KEY).setValueType(ValueType.STRING.name());
metrics = newArrayList(violationsMetric, sqaleIndexMetric);
measuresByComponentUuidAndMetric = HashBasedTable.create(components.size(), 2);
// same number than path field
double currentValue = 9;
for (ComponentDto component : components) {
measuresByComponentUuidAndMetric.put(component.uuid(), violationsMetric, createFromMeasureDto(new LiveMeasureDto().setValue(currentValue).setVariation(-currentValue)));
measuresByComponentUuidAndMetric.put(component.uuid(), sqaleIndexMetric, createFromMeasureDto(new LiveMeasureDto().setData(String.valueOf(currentValue))));
currentValue--;
}
}
use of org.sonar.db.measure.LiveMeasureDto in project sonarqube by SonarSource.
the class MeasureMatrixTest method setValue_double_rounds_up_variation.
@Test
public void setValue_double_rounds_up_variation() {
MetricDto metric = newMetricDto().setDecimalScale(2);
LiveMeasureDto measure = newMeasure(metric, PROJECT).setValue(3.14).setVariation(1.14);
MeasureMatrix underTest = new MeasureMatrix(asList(PROJECT), asList(metric), asList(measure));
underTest.setValue(PROJECT, metric.getKey(), 3.569);
assertThat(underTest.getChanged()).hasSize(1);
verifyValue(underTest, PROJECT, metric, 3.57);
verifyVariation(underTest, PROJECT, metric, 1.57);
}
use of org.sonar.db.measure.LiveMeasureDto in project sonarqube by SonarSource.
the class MeasureMatrixTest method setLeakValue_rounds_up_and_updates_value.
@Test
public void setLeakValue_rounds_up_and_updates_value() {
MetricDto metric = newMetricDto().setDecimalScale(2);
LiveMeasureDto measure = newMeasure(metric, PROJECT).setValue(null);
MeasureMatrix underTest = new MeasureMatrix(asList(PROJECT), asList(metric), asList(measure));
underTest.setLeakValue(PROJECT, metric.getKey(), 3.14159);
verifyVariation(underTest, PROJECT, metric, 3.14);
// do not update value
verifyValue(underTest, PROJECT, metric, null);
underTest.setLeakValue(PROJECT, metric.getKey(), 3.148);
verifyVariation(underTest, PROJECT, metric, 3.15);
// do not update value
verifyValue(underTest, PROJECT, metric, null);
}
Aggregations