use of org.sonar.server.favorite.FavoriteFinder 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