use of org.sonarqube.ws.Measures.ComponentWsResponse in project sonarqube by SonarSource.
the class ComponentAction method handle.
@Override
public void handle(Request request, Response response) throws Exception {
ComponentWsResponse componentWsResponse = doHandle(toComponentWsRequest(request));
writeProtobuf(componentWsResponse, request, response);
}
use of org.sonarqube.ws.Measures.ComponentWsResponse in project sonarqube by SonarSource.
the class ComponentActionTest method use_deprecated_component_id_parameter.
@Test
public void use_deprecated_component_id_parameter() {
ComponentDto project = db.components().insertPrivateProject();
userSession.addProjectPermission(UserRole.USER, project);
userSession.addProjectPermission(USER, project);
MetricDto metric = db.measures().insertMetric(m -> m.setValueType("INT"));
ComponentWsResponse response = ws.newRequest().setParam("component", project.getDbKey()).setParam(PARAM_METRIC_KEYS, metric.getKey()).executeProtobuf(ComponentWsResponse.class);
assertThat(response.getComponent().getKey()).isEqualTo(project.getDbKey());
}
use of org.sonarqube.ws.Measures.ComponentWsResponse in project sonarqube by SonarSource.
the class ComponentActionTest 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();
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").setOptimizedBestValue(false).setValueType("INT"));
MetricDto newBugs = db.measures().insertMetric(m1 -> m1.setKey("new_bugs").setOptimizedBestValue(false).setValueType("INT"));
ComponentWsResponse response = ws.newRequest().setParam(PARAM_COMPONENT, file.getKey()).setParam(PARAM_PULL_REQUEST, "pr-123").setParam(PARAM_METRIC_KEYS, newBugs.getKey() + "," + bugs.getKey()).executeProtobuf(ComponentWsResponse.class);
assertThat(response.getComponent()).extracting(Component::getKey, Component::getPullRequest).containsExactlyInAnyOrder(file.getKey(), "pr-123");
assertThat(response.getComponent().getMeasuresList()).isEmpty();
}
use of org.sonarqube.ws.Measures.ComponentWsResponse in project sonarqube by SonarSource.
the class ComponentAction method buildResponse.
private static ComponentWsResponse buildResponse(ComponentRequest request, ComponentDto component, Optional<ComponentDto> refComponent, Map<MetricDto, LiveMeasureDto> measuresByMetric, Collection<MetricDto> metrics, Optional<Measures.Period> period) {
ComponentWsResponse.Builder response = ComponentWsResponse.newBuilder();
if (refComponent.isPresent()) {
response.setComponent(componentDtoToWsComponent(component, measuresByMetric, singletonMap(refComponent.get().uuid(), refComponent.get())));
} else {
response.setComponent(componentDtoToWsComponent(component, measuresByMetric, emptyMap()));
}
List<String> additionalFields = request.getAdditionalFields();
if (additionalFields != null) {
if (additionalFields.contains(ADDITIONAL_METRICS)) {
for (MetricDto metric : metrics) {
response.getMetricsBuilder().addMetrics(metricDtoToWsMetric(metric));
}
}
// backward compatibility
if (additionalFields.contains(DEPRECATED_ADDITIONAL_PERIODS) && period.isPresent()) {
response.getPeriodsBuilder().addPeriods(period.get());
}
if (additionalFields.contains(ADDITIONAL_PERIOD) && period.isPresent()) {
response.setPeriod(period.get());
}
}
return response.build();
}
use of org.sonarqube.ws.Measures.ComponentWsResponse 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));
}
Aggregations