use of org.sonarqube.ws.Components.SuggestionsWsResponse.Category in project sonarqube by SonarSource.
the class SuggestionsActionTest method suggestions_should_filter_allowed_qualifiers.
@Test
public void suggestions_should_filter_allowed_qualifiers() {
resourceTypes.setAllQualifiers(PROJECT, MODULE, FILE, UNIT_TEST_FILE);
ComponentDto project = db.components().insertComponent(newPrivateProjectDto());
componentIndexer.indexOnAnalysis(project.projectUuid());
userSessionRule.addProjectPermission(USER, project);
SuggestionsWsResponse response = ws.newRequest().setMethod("POST").setParam(PARAM_RECENTLY_BROWSED, project.getDbKey()).executeProtobuf(SuggestionsWsResponse.class);
assertThat(response.getResultsList()).extracting(Category::getQ).containsExactlyInAnyOrder(PROJECT).doesNotContain(MODULE, FILE, UNIT_TEST_FILE);
}
use of org.sonarqube.ws.Components.SuggestionsWsResponse.Category in project sonarqube by SonarSource.
the class SuggestionsActionTest method suggestions_without_query_should_contain_recently_browsed_favorites.
@Test
public void suggestions_without_query_should_contain_recently_browsed_favorites() {
ComponentDto project = db.components().insertComponent(newPrivateProjectDto());
doReturn(singletonList(project)).when(favoriteFinder).list();
componentIndexer.indexAll();
userSessionRule.addProjectPermission(USER, project);
SuggestionsWsResponse response = ws.newRequest().setMethod("POST").setParam(PARAM_RECENTLY_BROWSED, project.getDbKey()).executeProtobuf(SuggestionsWsResponse.class);
// assert match in qualifier "TRK"
assertThat(response.getResultsList()).filteredOn(q -> q.getItemsCount() > 0).extracting(Category::getQ).containsExactly(Qualifiers.PROJECT);
// assert correct id to be found
assertThat(response.getResultsList()).flatExtracting(Category::getItemsList).extracting(Suggestion::getKey, Suggestion::getIsFavorite, Suggestion::getIsRecentlyBrowsed).containsExactly(tuple(project.getDbKey(), true, true));
}
use of org.sonarqube.ws.Components.SuggestionsWsResponse.Category 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.Category 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.Category 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