use of org.sonarqube.ws.Measures.ComponentTreeWsResponse in project sonarqube by SonarSource.
the class ComponentTreeActionTest method portfolio_local_reference_in_portfolio.
@Test
public void portfolio_local_reference_in_portfolio() {
ComponentDto view = db.components().insertComponent(ComponentTesting.newPortfolio("VIEW1-UUID").setDbKey("Apache-Projects").setName("Apache Projects"));
ComponentDto view2 = db.components().insertPrivatePortfolio();
ComponentDto localView = db.components().insertComponent(ComponentTesting.newSubPortfolio(view, "SUB-VIEW-UUID", "All-Projects").setName("All projects").setCopyComponentUuid(view2.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(), view2.getKey(), "SVW"));
}
use of org.sonarqube.ws.Measures.ComponentTreeWsResponse 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.ComponentTreeWsResponse in project sonarqube by SonarSource.
the class ComponentTreeActionTest method use_best_value_for_rating.
@Test
public void use_best_value_for_rating() {
ComponentDto project = db.components().insertPrivateProject();
userSession.anonymous().addProjectPermission(UserRole.USER, project);
SnapshotDto projectSnapshot = dbClient.snapshotDao().insert(dbSession, newAnalysis(project).setPeriodDate(parseDateTime("2016-01-11T10:49:50+0100").getTime()).setPeriodMode("previous_version").setPeriodParam("1.0-SNAPSHOT"));
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 metric = dbClient.metricDao().insert(dbSession, newMetricDto().setKey(NEW_SECURITY_RATING_KEY).setOptimizedBestValue(true).setBestValue(1d).setValueType(RATING.name()));
db.commit();
db.measures().insertLiveMeasure(directory, metric, m -> m.setVariation(2d));
ComponentTreeWsResponse response = ws.newRequest().setParam(PARAM_COMPONENT, project.getKey()).setParam(PARAM_METRIC_KEYS, NEW_SECURITY_RATING_KEY).setParam(PARAM_ADDITIONAL_FIELDS, "metrics").executeProtobuf(ComponentTreeWsResponse.class);
// directory
assertThat(response.getComponentsList().get(0).getMeasuresList().get(0).getPeriods().getPeriodsValue(0).getValue()).isEqualTo("2.0");
assertThat(response.getComponentsList().get(0).getMeasuresList().get(0).getPeriod().getValue()).isEqualTo("2.0");
// file measures
assertThat(response.getComponentsList().get(1).getMeasuresList().get(0).getPeriods().getPeriodsValue(0).getValue()).isEqualTo("1.0");
assertThat(response.getComponentsList().get(1).getMeasuresList().get(0).getPeriod().getValue()).isEqualTo("1.0");
}
use of org.sonarqube.ws.Measures.ComponentTreeWsResponse in project sonarqube by SonarSource.
the class ComponentTreeAction method handle.
@Override
public void handle(Request request, Response response) throws Exception {
ComponentTreeWsResponse componentTreeWsResponse = doHandle(toComponentTreeWsRequest(request));
writeProtobuf(componentTreeWsResponse, request, response);
}
use of org.sonarqube.ws.Measures.ComponentTreeWsResponse in project sonarqube by SonarSource.
the class ComponentTreeActionTest method load_measures_when_no_leave_qualifier.
@Test
public void load_measures_when_no_leave_qualifier() {
resourceTypes.setLeavesQualifiers();
ComponentDto project = db.components().insertPrivateProject();
db.components().insertSnapshot(project);
db.components().insertComponent(newFileDto(project, null));
insertNclocMetric();
ComponentTreeWsResponse result = ws.newRequest().setParam(PARAM_COMPONENT, project.getKey()).setParam(PARAM_STRATEGY, LEAVES_STRATEGY).setParam(PARAM_METRIC_KEYS, "ncloc").executeProtobuf(ComponentTreeWsResponse.class);
assertThat(result.getBaseComponent().getKey()).isEqualTo(project.getKey());
assertThat(result.getComponentsCount()).isZero();
}
Aggregations