use of org.sonar.api.resources.Qualifiers.PROJECT 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.sonar.api.resources.Qualifiers.PROJECT in project sonarqube by SonarSource.
the class ComponentTreeActionTest method return_is_best_value_on_leak_measures.
@Test
public void return_is_best_value_on_leak_measures() {
ComponentDto project = db.components().insertPrivateProject();
db.components().insertSnapshot(project);
userSession.anonymous().addProjectPermission(UserRole.USER, project);
ComponentDto file = newFileDto(project, null);
db.components().insertComponent(file);
MetricDto matchingBestValue = db.measures().insertMetric(m -> m.setKey("new_lines").setValueType(INT.name()).setBestValue(100d));
MetricDto doesNotMatchBestValue = db.measures().insertMetric(m -> m.setKey("new_lines_2").setValueType(INT.name()).setBestValue(100d));
MetricDto noBestValue = db.measures().insertMetric(m -> m.setKey("new_violations").setValueType(INT.name()).setBestValue(null));
db.measures().insertLiveMeasure(file, matchingBestValue, m -> m.setValue(null).setData((String) null).setVariation(100d));
db.measures().insertLiveMeasure(file, doesNotMatchBestValue, m -> m.setValue(null).setData((String) null).setVariation(10d));
db.measures().insertLiveMeasure(file, noBestValue, m -> m.setValue(null).setData((String) null).setVariation(42.0d));
ComponentTreeWsResponse response = ws.newRequest().setParam(PARAM_COMPONENT, project.getKey()).setParam(PARAM_METRIC_KEYS, "new_lines,new_lines_2,new_violations").executeProtobuf(ComponentTreeWsResponse.class);
// file measures
// verify backward compatibility
List<Measure> fileMeasures = response.getComponentsList().get(0).getMeasuresList();
assertThat(fileMeasures).extracting(Measure::getMetric, m -> m.getPeriods().getPeriodsValueList()).containsExactlyInAnyOrder(tuple(matchingBestValue.getKey(), singletonList(PeriodValue.newBuilder().setIndex(1).setValue("100").setBestValue(true).build())), tuple(doesNotMatchBestValue.getKey(), singletonList(PeriodValue.newBuilder().setIndex(1).setValue("10").setBestValue(false).build())), tuple(noBestValue.getKey(), singletonList(PeriodValue.newBuilder().setIndex(1).setValue("42").build())));
assertThat(fileMeasures).extracting(Measure::getMetric, Measure::getPeriod).containsExactlyInAnyOrder(tuple(matchingBestValue.getKey(), PeriodValue.newBuilder().setIndex(1).setValue("100").setBestValue(true).build()), tuple(doesNotMatchBestValue.getKey(), PeriodValue.newBuilder().setIndex(1).setValue("10").setBestValue(false).build()), tuple(noBestValue.getKey(), PeriodValue.newBuilder().setIndex(1).setValue("42").build()));
}
use of org.sonar.api.resources.Qualifiers.PROJECT in project sonarqube by SonarSource.
the class ComponentTreeActionTest method fail_when_setting_more_than_15_metric_keys.
@Test
public void fail_when_setting_more_than_15_metric_keys() {
ComponentDto project = db.components().insertPrivateProject();
db.components().insertSnapshot(project);
List<String> metrics = IntStream.range(0, 20).mapToObj(i -> "metric" + i).collect(MoreCollectors.toList());
db.commit();
assertThatThrownBy(() -> {
ws.newRequest().setParam(PARAM_COMPONENT, project.getKey()).setParam(PARAM_METRIC_KEYS, Joiner.on(",").join(metrics)).execute();
}).isInstanceOf(IllegalArgumentException.class).hasMessage("'metricKeys' can contains only 15 values, got 20");
}
use of org.sonar.api.resources.Qualifiers.PROJECT 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.sonar.api.resources.Qualifiers.PROJECT in project sonarqube by SonarSource.
the class TagsActionTest method search_tags_ignores_hotspots.
@Test
public void search_tags_ignores_hotspots() {
ComponentDto project = db.components().insertPrivateProject();
RuleDefinitionDto issueRule = db.rules().insertIssueRule();
RuleDefinitionDto hotspotRule = db.rules().insertHotspotRule();
Consumer<IssueDto> setTags = issue -> issue.setTags(asList("tag1", "tag2"));
db.issues().insertIssue(issueRule, project, project, setTags);
db.issues().insertHotspot(hotspotRule, project, project, setTags);
indexIssues();
permissionIndexer.allowOnlyAnyone(project);
TestRequest testRequest = ws.newRequest();
assertThat(tagListOf(testRequest)).containsExactly("tag1", "tag2");
}
Aggregations