use of org.sonar.server.component.ws.SuggestionsAction.PARAM_QUERY in project sonarqube by SonarSource.
the class SuggestionsActionTest method should_not_return_suggestion_on_non_existing_project.
@Test
public void should_not_return_suggestion_on_non_existing_project() {
ComponentDto project = db.components().insertComponent(newPrivateProjectDto());
componentIndexer.indexAll();
authorizationIndexerTester.allowOnlyAnyone(project);
db.getDbClient().purgeDao().deleteProject(db.getSession(), project.uuid(), PROJECT, project.name(), project.getKey());
db.commit();
SuggestionsWsResponse response = ws.newRequest().setMethod("POST").setParam(PARAM_QUERY, project.getDbKey()).executeProtobuf(SuggestionsWsResponse.class);
// assert match in qualifier "TRK"
assertThat(response.getResultsList()).filteredOn(q -> q.getItemsCount() > 0).isEmpty();
}
use of org.sonar.server.component.ws.SuggestionsAction.PARAM_QUERY in project sonarqube by SonarSource.
the class SuggestionsActionTest method should_only_provide_project_for_certain_qualifiers.
@Test
public void should_only_provide_project_for_certain_qualifiers() {
String query = randomAlphabetic(10);
ComponentDto app = db.components().insertPublicApplication(v -> v.setName(query));
ComponentDto view = db.components().insertPublicPortfolio(v -> v.setName(query));
ComponentDto subView = db.components().insertComponent(ComponentTesting.newSubPortfolio(view).setName(query));
ComponentDto project = db.components().insertPrivateProject(p -> p.setName(query));
ComponentDto module = db.components().insertComponent(ComponentTesting.newModuleDto(project).setName(query));
ComponentDto file = db.components().insertComponent(ComponentTesting.newFileDto(module).setName(query));
ComponentDto test = db.components().insertComponent(ComponentTesting.newFileDto(module).setName(query).setQualifier(UNIT_TEST_FILE));
componentIndexer.indexAll();
authorizationIndexerTester.allowOnlyAnyone(project);
authorizationIndexerTester.allowOnlyAnyone(view);
authorizationIndexerTester.allowOnlyAnyone(app);
SuggestionsWsResponse response = ws.newRequest().setMethod("POST").setParam(PARAM_QUERY, project.name()).executeProtobuf(SuggestionsWsResponse.class);
assertThat(response.getResultsList()).extracting(Category::getQ, c -> c.getItemsList().stream().map(Suggestion::hasProject).findFirst().orElse(null)).containsExactlyInAnyOrder(tuple(SuggestionCategory.APP.getName(), false), tuple(SuggestionCategory.VIEW.getName(), false), tuple(SuggestionCategory.SUBVIEW.getName(), false), tuple(SuggestionCategory.PROJECT.getName(), false));
}
use of org.sonar.server.component.ws.SuggestionsAction.PARAM_QUERY 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.server.component.ws.SuggestionsAction.PARAM_QUERY in project sonarqube by SonarSource.
the class SuggestionsActionTest method check_proposal_to_show_more_results.
private void check_proposal_to_show_more_results(int numberOfProjects, int expectedNumberOfResults, long expectedNumberOfMoreResults, @Nullable SuggestionCategory more, boolean useQuery) {
String namePrefix = "MyProject";
List<ComponentDto> projects = range(0, numberOfProjects).mapToObj(i -> db.components().insertComponent(newPublicProjectDto().setName(namePrefix + i))).collect(Collectors.toList());
componentIndexer.indexAll();
projects.forEach(authorizationIndexerTester::allowOnlyAnyone);
TestRequest request = ws.newRequest().setMethod("POST");
if (useQuery) {
request.setParam(PARAM_QUERY, namePrefix);
} else {
doReturn(projects).when(favoriteFinder).list();
}
ofNullable(more).ifPresent(c -> request.setParam(PARAM_MORE, c.getName()));
SuggestionsWsResponse response = request.executeProtobuf(SuggestionsWsResponse.class);
// include limited number of results in the response
assertThat(response.getResultsList()).flatExtracting(Category::getItemsList).hasSize(expectedNumberOfResults);
// indicate, that there are more results
if (expectedNumberOfResults == 0 && expectedNumberOfMoreResults == 0) {
assertThat(response.getResultsList()).filteredOn(q -> q.getItemsCount() > 0).isEmpty();
} else {
assertThat(response.getResultsList()).filteredOn(c -> "TRK".equals(c.getQ())).extracting(Category::getMore).containsExactly(expectedNumberOfMoreResults);
response.getResultsList().stream().filter(c -> !"TRK".equals(c.getQ())).map(Category::getMore).forEach(m -> assertThat(m).isEqualTo(0L));
}
}
Aggregations