use of org.sonarqube.ws.Components.SuggestionsWsResponse.Category in project sonarqube by SonarSource.
the class SuggestionsActionTest method should_mark_recently_browsed_items.
@Test
public void should_mark_recently_browsed_items() {
ComponentDto project = db.components().insertComponent(newPrivateProjectDto().setName("ProjectModule"));
ComponentDto module1 = newModuleDto(project).setName("Module1");
db.components().insertComponent(module1);
ComponentDto module2 = newModuleDto(project).setName("Module2");
db.components().insertComponent(module2);
componentIndexer.indexOnAnalysis(project.projectUuid());
authorizationIndexerTester.allowOnlyAnyone(project);
SuggestionsWsResponse response = ws.newRequest().setMethod("POST").setParam(PARAM_QUERY, "Module").setParam(PARAM_RECENTLY_BROWSED, Stream.of(module1.getDbKey(), project.getDbKey()).collect(joining(","))).executeProtobuf(SuggestionsWsResponse.class);
assertThat(response.getResultsList()).flatExtracting(Category::getItemsList).extracting(Suggestion::getIsRecentlyBrowsed).containsExactly(true);
}
use of org.sonarqube.ws.Components.SuggestionsWsResponse.Category in project sonarqube by SonarSource.
the class SuggestionsActionTest method exact_match_in_one_qualifier.
@Test
public void exact_match_in_one_qualifier() {
ComponentDto project = db.components().insertComponent(newPrivateProjectDto());
componentIndexer.indexAll();
authorizationIndexerTester.allowOnlyAnyone(project);
SuggestionsWsResponse response = ws.newRequest().setMethod("POST").setParam(PARAM_QUERY, 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).containsExactly(project.getDbKey());
}
use of org.sonarqube.ws.Components.SuggestionsWsResponse.Category in project sonarqube by SonarSource.
the class SuggestionsActionTest method suggestions_without_query_should_contain_favorites.
@Test
public void suggestions_without_query_should_contain_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").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::getIsFavorite).containsExactly(tuple(project.getDbKey(), true));
}
use of org.sonarqube.ws.Components.SuggestionsWsResponse.Category in project sonarqube by SonarSource.
the class SuggestionsActionTest method should_mark_favorite_items.
@Test
public void should_mark_favorite_items() {
ComponentDto favouriteProject = db.components().insertComponent(newPrivateProjectDto().setName("Project1"));
ComponentDto nonFavouriteProject = db.components().insertComponent(newPublicProjectDto().setName("Project2"));
doReturn(singletonList(favouriteProject)).when(favoriteFinder).list();
componentIndexer.indexOnAnalysis(favouriteProject.projectUuid());
componentIndexer.indexOnAnalysis(nonFavouriteProject.projectUuid());
authorizationIndexerTester.allowOnlyAnyone(favouriteProject, nonFavouriteProject);
SuggestionsWsResponse response = ws.newRequest().setMethod("POST").setParam(PARAM_QUERY, "Project").executeProtobuf(SuggestionsWsResponse.class);
assertThat(response.getResultsList()).flatExtracting(Category::getItemsList).extracting(Suggestion::getKey, Suggestion::getIsFavorite).containsExactly(tuple(favouriteProject.getDbKey(), true), tuple(nonFavouriteProject.getDbKey(), false));
}
use of org.sonarqube.ws.Components.SuggestionsWsResponse.Category in project sonarqube by SonarSource.
the class SuggestionsActionTest method suggestions_without_query_should_order_results.
@Test
public void suggestions_without_query_should_order_results() {
ComponentDto project1 = db.components().insertComponent(newPrivateProjectDto().setName("Alpha"));
ComponentDto project2 = db.components().insertComponent(newPrivateProjectDto().setName("Bravo"));
ComponentDto project3 = db.components().insertComponent(newPrivateProjectDto().setName("Charlie"));
ComponentDto project4 = db.components().insertComponent(newPrivateProjectDto().setName("Delta"));
doReturn(asList(project4, project2)).when(favoriteFinder).list();
componentIndexer.indexAll();
userSessionRule.addProjectPermission(USER, project1);
userSessionRule.addProjectPermission(USER, project2);
userSessionRule.addProjectPermission(USER, project3);
userSessionRule.addProjectPermission(USER, project4);
SuggestionsWsResponse response = ws.newRequest().setMethod("POST").setParam(PARAM_RECENTLY_BROWSED, Stream.of(project3, project1).map(ComponentDto::getDbKey).collect(joining(","))).executeProtobuf(SuggestionsWsResponse.class);
// assert order of keys
assertThat(response.getResultsList()).flatExtracting(Category::getItemsList).extracting(Suggestion::getName, Suggestion::getIsFavorite, Suggestion::getIsRecentlyBrowsed).containsExactly(tuple("Bravo", true, false), tuple("Delta", true, false), tuple("Alpha", false, true), tuple("Charlie", false, true));
}
Aggregations