use of org.sonarqube.ws.Measures.ComponentTreeWsResponse in project sonarqube by SonarSource.
the class ComponentTreeActionTest method new_issue_count_measures_are_not_transformed_if_they_dont_exist_in_pr.
@Test
public void new_issue_count_measures_are_not_transformed_if_they_dont_exist_in_pr() {
ComponentDto project = db.components().insertPrivateProject();
ComponentDto pr = db.components().insertProjectBranch(project, b -> b.setKey("pr").setBranchType(PULL_REQUEST));
SnapshotDto analysis = db.components().insertSnapshot(pr);
ComponentDto file = db.components().insertComponent(newFileDto(pr));
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));
ComponentTreeWsResponse response = ws.newRequest().setParam(PARAM_COMPONENT, file.getKey()).setParam(PARAM_PULL_REQUEST, "pr").setParam(PARAM_METRIC_KEYS, newBug.getKey() + "," + bug.getKey()).executeProtobuf(ComponentTreeWsResponse.class);
assertThat(response.getBaseComponent()).extracting(Component::getKey, Component::getPullRequest).containsExactlyInAnyOrder(file.getKey(), "pr");
assertThat(response.getBaseComponent().getMeasuresList()).isEmpty();
}
use of org.sonarqube.ws.Measures.ComponentTreeWsResponse in project sonarqube by SonarSource.
the class ComponentTreeActionTest method remove_components_without_measure_on_the_metric_period_sort.
@Test
public void remove_components_without_measure_on_the_metric_period_sort() {
ComponentDto project = db.components().insertPrivateProject();
SnapshotDto projectSnapshot = db.components().insertSnapshot(project);
ComponentDto file4 = db.components().insertComponent(newFileDto(project, null, "file-uuid-4").setDbKey("file-4-key"));
ComponentDto file3 = db.components().insertComponent(newFileDto(project, null, "file-uuid-3").setDbKey("file-3-key"));
ComponentDto file2 = db.components().insertComponent(newFileDto(project, null, "file-uuid-2").setDbKey("file-2-key"));
ComponentDto file1 = db.components().insertComponent(newFileDto(project, null, "file-uuid-1").setDbKey("file-1-key"));
MetricDto ncloc = newMetricDto().setKey("new_ncloc").setValueType(INT.name()).setDirection(1);
dbClient.metricDao().insert(dbSession, ncloc);
db.measures().insertLiveMeasure(file1, ncloc, m -> m.setData((String) null).setValue(null).setVariation(1.0d));
db.measures().insertLiveMeasure(file2, ncloc, m -> m.setData((String) null).setValue(null).setVariation(2.0d));
db.measures().insertLiveMeasure(file3, ncloc, m -> m.setData((String) null).setValue(null).setVariation(3.0d));
// file 4 measure is on absolute value
db.measures().insertLiveMeasure(file4, ncloc, m -> m.setData((String) null).setValue(4.0d).setVariation(null));
db.commit();
ComponentTreeWsResponse response = ws.newRequest().setParam(PARAM_COMPONENT, project.getKey()).setParam(SORT, METRIC_PERIOD_SORT + "," + NAME_SORT).setParam(PARAM_METRIC_SORT, "new_ncloc").setParam(PARAM_METRIC_KEYS, "new_ncloc").setParam(PARAM_METRIC_PERIOD_SORT, "1").setParam(PARAM_METRIC_SORT_FILTER, WITH_MEASURES_ONLY_METRIC_SORT_FILTER).executeProtobuf(ComponentTreeWsResponse.class);
assertThat(response.getComponentsList()).extracting("key").containsExactly("file-1-key", "file-2-key", "file-3-key").doesNotContain("file-4-key");
}
Aggregations