Search in sources :

Example 21 with SuggestionsWsResponse

use of org.sonarqube.ws.Components.SuggestionsWsResponse 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);
}
Also used : Category(org.sonarqube.ws.Components.SuggestionsWsResponse.Category) ComponentDto(org.sonar.db.component.ComponentDto) SuggestionsWsResponse(org.sonarqube.ws.Components.SuggestionsWsResponse) Test(org.junit.Test)

Example 22 with SuggestionsWsResponse

use of org.sonarqube.ws.Components.SuggestionsWsResponse 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());
}
Also used : Category(org.sonarqube.ws.Components.SuggestionsWsResponse.Category) ComponentDto(org.sonar.db.component.ComponentDto) SuggestionsWsResponse(org.sonarqube.ws.Components.SuggestionsWsResponse) Test(org.junit.Test)

Example 23 with SuggestionsWsResponse

use of org.sonarqube.ws.Components.SuggestionsWsResponse 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));
}
Also used : Category(org.sonarqube.ws.Components.SuggestionsWsResponse.Category) ComponentDto(org.sonar.db.component.ComponentDto) SuggestionsWsResponse(org.sonarqube.ws.Components.SuggestionsWsResponse) Test(org.junit.Test)

Example 24 with SuggestionsWsResponse

use of org.sonarqube.ws.Components.SuggestionsWsResponse 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));
}
Also used : Category(org.sonarqube.ws.Components.SuggestionsWsResponse.Category) ComponentDto(org.sonar.db.component.ComponentDto) SuggestionsWsResponse(org.sonarqube.ws.Components.SuggestionsWsResponse) Test(org.junit.Test)

Example 25 with SuggestionsWsResponse

use of org.sonarqube.ws.Components.SuggestionsWsResponse 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));
}
Also used : Category(org.sonarqube.ws.Components.SuggestionsWsResponse.Category) ComponentDto(org.sonar.db.component.ComponentDto) SuggestionsWsResponse(org.sonarqube.ws.Components.SuggestionsWsResponse) Test(org.junit.Test)

Aggregations

SuggestionsWsResponse (org.sonarqube.ws.Components.SuggestionsWsResponse)25 Test (org.junit.Test)23 ComponentDto (org.sonar.db.component.ComponentDto)23 Category (org.sonarqube.ws.Components.SuggestionsWsResponse.Category)17 Arrays.asList (java.util.Arrays.asList)4 Collections.singletonList (java.util.Collections.singletonList)4 List (java.util.List)4 Optional.ofNullable (java.util.Optional.ofNullable)4 Collectors (java.util.stream.Collectors)4 Collectors.joining (java.util.stream.Collectors.joining)4 IntStream.range (java.util.stream.IntStream.range)4 Stream (java.util.stream.Stream)4 Nullable (javax.annotation.Nullable)4 RandomStringUtils.randomAlphabetic (org.apache.commons.lang.RandomStringUtils.randomAlphabetic)4 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)4 Tuple.tuple (org.assertj.core.groups.Tuple.tuple)4 Before (org.junit.Before)4 Rule (org.junit.Rule)4 Mockito.doReturn (org.mockito.Mockito.doReturn)4 Mockito.mock (org.mockito.Mockito.mock)4