use of org.sonar.db.measure.LiveMeasureDto 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.sonar.db.measure.LiveMeasureDto 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.sonar.db.measure.LiveMeasureDto in project sonarqube by SonarSource.
the class LiveMeasureComputerImplTest method variation_is_refreshed_when_rating_value_is_changed.
@Test
public void variation_is_refreshed_when_rating_value_is_changed() {
markProjectAsAnalyzed(project);
// value is:
// B on last analysis
// D on beginning of leak period --> variation is -2
db.measures().insertLiveMeasure(project, ratingMetric, m -> m.setValue((double) Rating.B.getIndex()).setData("B").setVariation(-2.0));
// new value is C, so variation on leak period is D to C = -1
List<QGChangeEvent> result = run(file1, newRatingConstantFormula(Rating.C));
LiveMeasureDto measure = assertThatRatingMeasureHasValue(project, Rating.C);
assertThat(measure.getVariation()).isEqualTo(-1.0);
assertThatProjectChanged(result, project);
}
use of org.sonar.db.measure.LiveMeasureDto in project sonarqube by SonarSource.
the class LiveMeasureComputerImplTest method variation_does_not_change_if_rating_value_does_not_change.
@Test
public void variation_does_not_change_if_rating_value_does_not_change() {
markProjectAsAnalyzed(project);
// value is:
// B on last analysis
// D on beginning of leak period --> variation is -2
db.measures().insertLiveMeasure(project, ratingMetric, m -> m.setValue((double) Rating.B.getIndex()).setData("B").setVariation(-2.0));
// new value is still B, so variation on leak period is still -2
List<QGChangeEvent> result = run(file1, newRatingConstantFormula(Rating.B));
LiveMeasureDto measure = assertThatRatingMeasureHasValue(project, Rating.B);
assertThat(measure.getVariation()).isEqualTo(-2.0);
assertThatProjectChanged(result, project);
}
use of org.sonar.db.measure.LiveMeasureDto in project sonarqube by SonarSource.
the class prMeasureFixTest method should_transform_measures.
@Test
public void should_transform_measures() {
Set<String> requestedKeys = new HashSet<>(Arrays.asList(NEW_BUGS_KEY, MINOR_VIOLATIONS_KEY, NEW_MINOR_VIOLATIONS_KEY));
MetricDto bugsMetric = new MetricDto().setKey(BUGS_KEY).setUuid("1");
MetricDto newBugsMetric = new MetricDto().setKey(NEW_BUGS_KEY).setUuid("2");
MetricDto violationsMetric = new MetricDto().setKey(MINOR_VIOLATIONS_KEY).setUuid("3");
MetricDto newViolationsMetric = new MetricDto().setKey(NEW_MINOR_VIOLATIONS_KEY).setUuid("4");
List<MetricDto> metricList = Arrays.asList(bugsMetric, newBugsMetric, violationsMetric, newViolationsMetric);
LiveMeasureDto bugs = createLiveMeasure(bugsMetric.getUuid(), 10.0, null);
LiveMeasureDto newBugs = createLiveMeasure(newBugsMetric.getUuid(), null, 5.0);
LiveMeasureDto violations = createLiveMeasure(violationsMetric.getUuid(), 20.0, null);
LiveMeasureDto newViolations = createLiveMeasure(newViolationsMetric.getUuid(), null, 3.0);
Map<MetricDto, LiveMeasureDto> measureByMetric = new HashMap<>();
measureByMetric.put(bugsMetric, bugs);
measureByMetric.put(newBugsMetric, newBugs);
measureByMetric.put(violationsMetric, violations);
measureByMetric.put(newViolationsMetric, newViolations);
PrMeasureFix.createReplacementMeasures(metricList, measureByMetric, requestedKeys);
assertThat(measureByMetric.entrySet()).extracting(e -> e.getKey().getKey(), e -> e.getValue().getValue(), e -> e.getValue().getVariation()).containsOnly(tuple(NEW_BUGS_KEY, null, 10.0), tuple(MINOR_VIOLATIONS_KEY, 20.0, null), tuple(NEW_MINOR_VIOLATIONS_KEY, null, 20.0));
}
Aggregations