Search in sources :

Example 6 with SuggestionsWsResponse

use of org.sonarqube.ws.Components.SuggestionsWsResponse 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));
}
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 7 with SuggestionsWsResponse

use of org.sonarqube.ws.Components.SuggestionsWsResponse 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));
}
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 8 with SuggestionsWsResponse

use of org.sonarqube.ws.Components.SuggestionsWsResponse in project sonarqube by SonarSource.

the class SuggestionsActionTest method should_warn_about_short_inputs.

@Test
public void should_warn_about_short_inputs() {
    SuggestionsWsResponse response = ws.newRequest().setMethod("POST").setParam(PARAM_QUERY, "validLongToken x").executeProtobuf(SuggestionsWsResponse.class);
    assertThat(response.getWarning()).contains(SHORT_INPUT_WARNING);
}
Also used : SuggestionsWsResponse(org.sonarqube.ws.Components.SuggestionsWsResponse) Test(org.junit.Test)

Example 9 with SuggestionsWsResponse

use of org.sonarqube.ws.Components.SuggestionsWsResponse in project sonarqube by SonarSource.

the class SuggestionsActionTest method should_return_empty_qualifiers.

@Test
public void should_return_empty_qualifiers() {
    ComponentDto project = db.components().insertComponent(newPrivateProjectDto());
    componentIndexer.indexOnAnalysis(project.projectUuid());
    authorizationIndexerTester.allowOnlyAnyone(project);
    SuggestionsWsResponse response = ws.newRequest().setMethod("POST").setParam(PARAM_QUERY, project.name()).executeProtobuf(SuggestionsWsResponse.class);
    assertThat(response.getResultsList()).extracting(Category::getQ, Category::getItemsCount).containsExactlyInAnyOrder(tuple("VW", 0), tuple("SVW", 0), tuple("APP", 0), tuple("TRK", 1));
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) SuggestionsWsResponse(org.sonarqube.ws.Components.SuggestionsWsResponse) Test(org.junit.Test)

Example 10 with SuggestionsWsResponse

use of org.sonarqube.ws.Components.SuggestionsWsResponse in project sonarqube by SonarSource.

the class SuggestionsActionTest method suggestions_without_query_should_not_contain_favorites_without_permission.

@Test
public void suggestions_without_query_should_not_contain_favorites_without_permission() {
    ComponentDto project = db.components().insertComponent(newPrivateProjectDto());
    doReturn(singletonList(project)).when(favoriteFinder).list();
    componentIndexer.indexAll();
    SuggestionsWsResponse response = ws.newRequest().setMethod("POST").executeProtobuf(SuggestionsWsResponse.class);
    assertThat(response.getResultsList()).flatExtracting(Category::getItemsList).isEmpty();
}
Also used : 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