use of org.sonarqube.ws.Components.SuggestionsWsResponse 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.sonarqube.ws.Components.SuggestionsWsResponse in project sonarqube by SonarSource.
the class SuggestionsActionTest method suggestions_without_query_should_not_contain_recently_browsed_without_permission.
@Test
public void suggestions_without_query_should_not_contain_recently_browsed_without_permission() {
ComponentDto project = db.components().insertComponent(newPrivateProjectDto());
componentIndexer.indexAll();
SuggestionsWsResponse response = ws.newRequest().setMethod("POST").setParam(PARAM_RECENTLY_BROWSED, project.getDbKey()).executeProtobuf(SuggestionsWsResponse.class);
assertThat(response.getResultsList()).flatExtracting(Category::getItemsList).isEmpty();
}
use of org.sonarqube.ws.Components.SuggestionsWsResponse 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 in project sonarqube by SonarSource.
the class SuggestionsAction method handle.
@Override
public void handle(Request wsRequest, Response wsResponse) throws Exception {
String query = wsRequest.param(PARAM_QUERY);
String more = wsRequest.param(PARAM_MORE);
Set<String> recentlyBrowsedKeys = getRecentlyBrowsedKeys(wsRequest);
List<String> qualifiers = getQualifiers(more);
int skip = more == null ? 0 : DEFAULT_LIMIT;
int limit = more == null ? DEFAULT_LIMIT : EXTENDED_LIMIT;
SuggestionsWsResponse searchWsResponse = loadSuggestions(query, skip, limit, recentlyBrowsedKeys, qualifiers);
writeProtobuf(searchWsResponse, wsRequest, wsResponse);
}
use of org.sonarqube.ws.Components.SuggestionsWsResponse 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));
}
Aggregations