use of org.sonarqube.ws.Measures.ComponentTreeWsResponse in project sonarqube by SonarSource.
the class ComponentTreeActionTest method project_branch_reference_from_application_branch.
@Test
public void project_branch_reference_from_application_branch() {
MetricDto ncloc = insertNclocMetric();
ComponentDto application = db.components().insertPublicProject(c -> c.setQualifier(APP).setDbKey("app-key"));
ComponentDto applicationBranch = db.components().insertProjectBranch(application, a -> a.setKey("app-branch"));
ComponentDto project = db.components().insertPrivateProject(p -> p.setDbKey("project-key"));
ComponentDto projectBranch = db.components().insertProjectBranch(project, b -> b.setKey("project-branch"));
ComponentDto techProjectBranch = db.components().insertComponent(newProjectCopy(projectBranch, applicationBranch).setDbKey(applicationBranch.getKey() + applicationBranch.getBranch() + projectBranch.getDbKey()));
SnapshotDto applicationBranchAnalysis = db.components().insertSnapshot(applicationBranch);
db.measures().insertLiveMeasure(applicationBranch, ncloc, m -> m.setValue(5d));
db.measures().insertLiveMeasure(techProjectBranch, ncloc, m -> m.setValue(1d));
ComponentTreeWsResponse result = ws.newRequest().setParam(PARAM_COMPONENT, applicationBranch.getKey()).setParam(PARAM_BRANCH, applicationBranch.getBranch()).setParam(PARAM_METRIC_KEYS, ncloc.getKey()).executeProtobuf(ComponentTreeWsResponse.class);
assertThat(result.getBaseComponent()).extracting(Component::getKey, Component::getBranch).containsExactlyInAnyOrder(applicationBranch.getKey(), applicationBranch.getBranch());
assertThat(result.getComponentsList()).extracting(Component::getKey, Component::getBranch, Component::getRefKey).containsExactlyInAnyOrder(tuple(techProjectBranch.getKey(), projectBranch.getBranch(), project.getKey()));
}
use of org.sonarqube.ws.Measures.ComponentTreeWsResponse in project sonarqube by SonarSource.
the class ComponentTreeActionTest method metric_without_a_domain.
@Test
public void metric_without_a_domain() {
ComponentDto project = db.components().insertPrivateProject();
SnapshotDto analysis = db.getDbClient().snapshotDao().insert(dbSession, newAnalysis(project));
MetricDto metricWithoutDomain = db.measures().insertMetric(m -> m.setValueType(Metric.ValueType.INT.name()).setDomain(null));
db.measures().insertLiveMeasure(project, metricWithoutDomain);
ComponentTreeWsResponse result = ws.newRequest().setParam(PARAM_COMPONENT, project.getKey()).setParam(PARAM_METRIC_KEYS, metricWithoutDomain.getKey()).setParam(PARAM_ADDITIONAL_FIELDS, "metrics").executeProtobuf(ComponentTreeWsResponse.class);
assertThat(result.getBaseComponent().getMeasures(0).getMetric()).isEqualTo(metricWithoutDomain.getKey());
Common.Metric responseMetric = result.getMetrics().getMetrics(0);
assertThat(responseMetric.getKey()).isEqualTo(metricWithoutDomain.getKey());
assertThat(responseMetric.hasDomain()).isFalse();
}
use of org.sonarqube.ws.Measures.ComponentTreeWsResponse in project sonarqube by SonarSource.
the class ComponentTreeActionTest method sort_by_metric_period.
@Test
public void sort_by_metric_period() {
ComponentDto project = db.components().insertPrivateProject();
SnapshotDto projectSnapshot = db.components().insertSnapshot(project);
ComponentDto file3 = db.components().insertComponent(newFileDto(project, null, "file-uuid-3").setDbKey("file-3-key"));
ComponentDto file1 = db.components().insertComponent(newFileDto(project, null, "file-uuid-1").setDbKey("file-1-key"));
ComponentDto file2 = db.components().insertComponent(newFileDto(project, null, "file-uuid-2").setDbKey("file-2-key"));
MetricDto ncloc = newMetricDto().setKey("ncloc").setValueType(INT.name()).setDirection(1);
dbClient.metricDao().insert(dbSession, ncloc);
db.commit();
db.measures().insertLiveMeasure(file1, ncloc, m -> m.setVariation(1.0d));
db.measures().insertLiveMeasure(file2, ncloc, m -> m.setVariation(2.0d));
db.measures().insertLiveMeasure(file3, ncloc, m -> m.setVariation(3.0d));
ComponentTreeWsResponse response = ws.newRequest().setParam(PARAM_COMPONENT, project.getKey()).setParam(SORT, METRIC_PERIOD_SORT).setParam(PARAM_METRIC_SORT, "ncloc").setParam(PARAM_METRIC_KEYS, "ncloc").setParam(PARAM_METRIC_PERIOD_SORT, "1").executeProtobuf(ComponentTreeWsResponse.class);
assertThat(response.getComponentsList()).extracting("key").containsExactly("file-1-key", "file-2-key", "file-3-key");
}
use of org.sonarqube.ws.Measures.ComponentTreeWsResponse 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.ComponentTreeWsResponse in project sonarqube by SonarSource.
the class ComponentTreeActionTest method application_local_reference_in_portfolio.
@Test
public void application_local_reference_in_portfolio() {
ComponentDto view = db.components().insertComponent(ComponentTesting.newPortfolio("VIEW1-UUID").setDbKey("Apache-Projects").setName("Apache Projects"));
ComponentDto application = db.components().insertPrivateApplication();
ComponentDto localView = db.components().insertComponent(ComponentTesting.newSubPortfolio(view, "SUB-VIEW-UUID", "All-Projects").setName("All projects").setCopyComponentUuid(application.uuid()));
db.components().insertSnapshot(view);
MetricDto ncloc = insertNclocMetric();
db.measures().insertLiveMeasure(localView, ncloc, m -> m.setValue(5d));
ComponentTreeWsResponse result = ws.newRequest().setParam(PARAM_COMPONENT, view.getKey()).setParam(PARAM_METRIC_KEYS, ncloc.getKey()).executeProtobuf(ComponentTreeWsResponse.class);
assertThat(result.getComponentsList()).extracting(Component::getKey, Component::getRefKey, Component::getQualifier).containsExactlyInAnyOrder(tuple(localView.getKey(), application.getKey(), "APP"));
}
Aggregations