use of org.sonar.api.resources.Qualifiers.PROJECT in project sonarqube by SonarSource.
the class ComponentIndexTest method assertResultOrder.
protected void assertResultOrder(String query, String... resultsInOrder) {
ComponentDto project = indexProject("key-1", "Quality Product");
List<ComponentDto> files = Arrays.stream(resultsInOrder).map(r -> ComponentTesting.newFileDto(project).setName(r)).peek(f -> f.setUuid(f.uuid() + "_" + f.name().replaceAll("[^a-zA-Z0-9]", ""))).collect(Collectors.toList());
// index them, but not in the expected order
files.stream().sorted(Comparator.comparing(ComponentDto::uuid).reversed()).forEach(this::index);
assertExactResults(query, files.toArray(new ComponentDto[0]));
}
use of org.sonar.api.resources.Qualifiers.PROJECT in project sonarqube by SonarSource.
the class SuggestionsActionTest method must_not_search_if_no_valid_tokens_are_provided.
@Test
public void must_not_search_if_no_valid_tokens_are_provided() {
ComponentDto project = db.components().insertComponent(newPrivateProjectDto().setName("SonarQube"));
componentIndexer.indexAll();
authorizationIndexerTester.allowOnlyAnyone(project);
SuggestionsWsResponse response = ws.newRequest().setMethod("POST").setParam(PARAM_QUERY, "S o").executeProtobuf(SuggestionsWsResponse.class);
assertThat(response.getResultsList()).filteredOn(q -> q.getItemsCount() > 0).isEmpty();
assertThat(response.getWarning()).contains(SHORT_INPUT_WARNING);
}
use of org.sonar.api.resources.Qualifiers.PROJECT in project sonarqube by SonarSource.
the class ListActionTest method response_contains_date_of_last_analysis.
@Test
public void response_contains_date_of_last_analysis() {
Long lastAnalysisBranch = dateToLong(parseDateTime("2017-04-01T00:00:00+0100"));
ComponentDto project = db.components().insertPrivateProject();
userSession.logIn().addProjectPermission(USER, project);
ComponentDto branch2 = db.components().insertProjectBranch(project, b -> b.setBranchType(org.sonar.db.component.BranchType.BRANCH));
db.getDbClient().snapshotDao().insert(db.getSession(), newAnalysis(branch2).setCreatedAt(lastAnalysisBranch));
db.commit();
indexIssues();
permissionIndexerTester.allowOnlyAnyone(project);
ListWsResponse response = ws.newRequest().setParam("project", project.getKey()).executeProtobuf(ListWsResponse.class);
assertThat(response.getBranchesList()).extracting(ProjectBranches.Branch::getType, ProjectBranches.Branch::hasAnalysisDate, b -> "".equals(b.getAnalysisDate()) ? null : dateToLong(parseDateTime(b.getAnalysisDate()))).containsExactlyInAnyOrder(tuple(BranchType.BRANCH, false, null), tuple(BranchType.BRANCH, true, lastAnalysisBranch));
}
use of org.sonar.api.resources.Qualifiers.PROJECT 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.sonar.api.resources.Qualifiers.PROJECT in project sonarqube by SonarSource.
the class PermissionTemplateServiceTest method apply_permission_template_with_key_pattern_collision.
@Test
public void apply_permission_template_with_key_pattern_collision() {
final String key = "hi-test";
final String keyPattern = ".*-test";
Stream<PermissionTemplateDto> templates = Stream.of(templateDb.insertTemplate(t -> t.setKeyPattern(keyPattern)), templateDb.insertTemplate(t -> t.setKeyPattern(keyPattern)));
String templateNames = templates.map(PermissionTemplateDto::getName).sorted(String.CASE_INSENSITIVE_ORDER).map(x -> String.format("\"%s\"", x)).collect(Collectors.joining(", "));
ComponentDto project = dbTester.components().insertPrivateProject(p -> p.setDbKey(key));
assertThatThrownBy(() -> underTest.applyDefaultToNewComponent(session, project, null)).isInstanceOf(TemplateMatchingKeyException.class).hasMessageContaining("The \"%s\" key matches multiple permission templates: %s.", key, templateNames);
}
Aggregations