use of org.sonarqube.ws.Components.SuggestionsWsResponse in project sonarqube by SonarSource.
the class SuggestionsActionTest method does_not_return_branches.
@Test
public void does_not_return_branches() {
ComponentDto project = db.components().insertPublicProject();
authorizationIndexerTester.allowOnlyAnyone(project);
ComponentDto branch = db.components().insertProjectBranch(project);
componentIndexer.indexAll();
authorizationIndexerTester.allowOnlyAnyone(project);
SuggestionsWsResponse response = ws.newRequest().setMethod("POST").setParam(PARAM_QUERY, project.name()).executeProtobuf(SuggestionsWsResponse.class);
assertThat(response.getResultsList()).filteredOn(c -> "TRK".equals(c.getQ())).extracting(Category::getItemsList).hasSize(1);
}
use of org.sonarqube.ws.Components.SuggestionsWsResponse in project sonarqube by SonarSource.
the class SuggestionsActionTest method should_not_return_modules.
@Test
public void should_not_return_modules() {
ComponentDto project = db.components().insertComponent(newPrivateProjectDto().setName("ProjectWithModules"));
db.components().insertComponent(newModuleDto(project).setName("Module1"));
db.components().insertComponent(newModuleDto(project).setName("Module2"));
componentIndexer.indexOnAnalysis(project.projectUuid());
authorizationIndexerTester.allowOnlyAnyone(project);
SuggestionsWsResponse response = ws.newRequest().setMethod("POST").setParam(PARAM_QUERY, "Module").executeProtobuf(SuggestionsWsResponse.class);
assertThat(response.getResultsList()).flatExtracting(Category::getItemsList).extracting(Suggestion::getKey).containsOnly(project.getDbKey());
}
use of org.sonarqube.ws.Components.SuggestionsWsResponse 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.sonarqube.ws.Components.SuggestionsWsResponse in project sonarqube by SonarSource.
the class SuggestionsActionTest method should_warn_about_short_inputs_but_return_results_based_on_other_terms.
@Test
public void should_warn_about_short_inputs_but_return_results_based_on_other_terms() {
ComponentDto project = db.components().insertComponent(newPrivateProjectDto().setName("SonarQube"));
componentIndexer.indexAll();
authorizationIndexerTester.allowOnlyAnyone(project);
SuggestionsWsResponse response = ws.newRequest().setMethod("POST").setParam(PARAM_QUERY, "Sonar Q").executeProtobuf(SuggestionsWsResponse.class);
assertThat(response.getResultsList()).flatExtracting(Category::getItemsList).extracting(Suggestion::getKey).contains(project.getDbKey());
assertThat(response.getWarning()).contains(SHORT_INPUT_WARNING);
}
use of org.sonarqube.ws.Components.SuggestionsWsResponse 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