use of org.sonarqube.ws.Components.SuggestionsWsResponse.Category in project sonarqube by SonarSource.
the class SuggestionsActionTest method suggestions_without_query_should_contain_recently_browsed.
@Test
public void suggestions_without_query_should_contain_recently_browsed() {
ComponentDto project = db.components().insertComponent(newPrivateProjectDto());
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(PROJECT);
// assert correct id to be found
assertThat(response.getResultsList()).flatExtracting(Category::getItemsList).extracting(Suggestion::getKey, Suggestion::getIsRecentlyBrowsed).containsExactly(tuple(project.getDbKey(), true));
}
use of org.sonarqube.ws.Components.SuggestionsWsResponse.Category in project sonarqube by SonarSource.
the class SuggestionsActionTest method should_contain_component_names.
@Test
public void should_contain_component_names() {
ComponentDto project1 = db.components().insertComponent(newPrivateProjectDto().setName("Project1"));
componentIndexer.indexOnAnalysis(project1.projectUuid());
authorizationIndexerTester.allowOnlyAnyone(project1);
SuggestionsWsResponse response = ws.newRequest().setMethod("POST").setParam(PARAM_QUERY, "Project").executeProtobuf(SuggestionsWsResponse.class);
assertThat(response.getResultsList()).flatExtracting(Category::getItemsList).extracting(Suggestion::getKey, Suggestion::getName).containsExactlyInAnyOrder(tuple(project1.getDbKey(), project1.name()));
}
use of org.sonarqube.ws.Components.SuggestionsWsResponse.Category in project sonarqube by SonarSource.
the class SuggestionsActionTest method suggestions_without_query_should_contain_recently_browsed_public_project.
@Test
public void suggestions_without_query_should_contain_recently_browsed_public_project() {
ComponentDto project = db.components().insertComponent(newPublicProjectDto());
componentIndexer.indexAll();
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(PROJECT);
// assert correct id to be found
assertThat(response.getResultsList()).flatExtracting(Category::getItemsList).extracting(Suggestion::getKey, Suggestion::getIsRecentlyBrowsed).containsExactly(tuple(project.getDbKey(), true));
}
use of org.sonarqube.ws.Components.SuggestionsWsResponse.Category in project sonarqube by SonarSource.
the class SuggestionsActionTest method suggestions_without_query_should_return_empty_qualifiers.
@Test
public void suggestions_without_query_should_return_empty_qualifiers() {
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, Category::getItemsCount).containsExactlyInAnyOrder(tuple("VW", 0), tuple("APP", 0), tuple("SVW", 0), tuple("TRK", 1)).doesNotContain(tuple("BRC", 0), tuple("FIL", 0), tuple("UTS", 0));
}
use of org.sonarqube.ws.Components.SuggestionsWsResponse.Category 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));
}
Aggregations