Search in sources :

Example 11 with Category

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);
}
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 12 with Category

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());
}
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 13 with Category

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));
}
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 14 with Category

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));
}
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 15 with Category

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));
}
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

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