use of org.sonarqube.ws.Measures.Component 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.sonarqube.ws.Measures.Component 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.Component in project sonarqube by SonarSource.
the class ComponentDtoToWsComponent method componentDtoToWsComponent.
static Component.Builder componentDtoToWsComponent(ComponentDto component, Map<MetricDto, LiveMeasureDto> measuresByMetric, Map<String, ComponentDto> referenceComponentsByUuid) {
Component.Builder wsComponent = componentDtoToWsComponent(component);
ComponentDto referenceComponent = referenceComponentsByUuid.get(component.getCopyComponentUuid());
if (referenceComponent != null) {
wsComponent.setRefKey(referenceComponent.getDbKey());
}
Measures.Measure.Builder measureBuilder = Measures.Measure.newBuilder();
for (Map.Entry<MetricDto, LiveMeasureDto> entry : measuresByMetric.entrySet()) {
MeasureDtoToWsMeasure.updateMeasureBuilder(measureBuilder, entry.getKey(), entry.getValue());
wsComponent.addMeasures(measureBuilder);
measureBuilder.clear();
}
return wsComponent;
}
use of org.sonarqube.ws.Measures.Component in project sonarqube by SonarSource.
the class ComponentTreeActionTest method fix_pull_request_new_issue_count_metrics.
@Test
public void fix_pull_request_new_issue_count_metrics() {
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 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));
LiveMeasureDto measure = db.measures().insertLiveMeasure(file, bug, m -> m.setValue(12.0d));
ComponentTreeWsResponse response = ws.newRequest().setParam(PARAM_COMPONENT, file.getKey()).setParam(PARAM_PULL_REQUEST, "pr-123").setParam(PARAM_METRIC_KEYS, newBug.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.getPeriods().getPeriodsValue(0).getValue()), Measure::getValue).containsExactlyInAnyOrder(tuple(newBug.getKey(), measure.getValue(), ""));
assertThat(response.getBaseComponent().getMeasuresList()).extracting(Measure::getMetric, m -> parseDouble(m.getPeriod().getValue()), Measure::getValue).containsExactlyInAnyOrder(tuple(newBug.getKey(), measure.getValue(), ""));
}
use of org.sonarqube.ws.Measures.Component in project sonarqube by SonarSource.
the class ComponentActionTest method pull_request.
@Test
public void pull_request() {
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 complexity = db.measures().insertMetric(m1 -> m1.setKey("complexity").setValueType("INT"));
LiveMeasureDto measure = db.measures().insertLiveMeasure(file, complexity, m -> m.setValue(12.0d).setVariation(2.0d));
ComponentWsResponse response = ws.newRequest().setParam(PARAM_COMPONENT, file.getKey()).setParam(PARAM_PULL_REQUEST, "pr-123").setParam(PARAM_METRIC_KEYS, complexity.getKey()).executeProtobuf(ComponentWsResponse.class);
assertThat(response.getComponent()).extracting(Component::getKey, Component::getPullRequest).containsExactlyInAnyOrder(file.getKey(), "pr-123");
assertThat(response.getComponent().getMeasuresList()).extracting(Measures.Measure::getMetric, m -> parseDouble(m.getValue())).containsExactlyInAnyOrder(tuple(complexity.getKey(), measure.getValue()));
}
Aggregations