Search in sources :

Example 1 with SearchResponse

use of org.sonarqube.ws.Favorites.SearchResponse in project sonarqube by SonarSource.

the class SearchActionTest method return_only_users_favorite.

@Test
public void return_only_users_favorite() {
    OrganizationDto organizationDto = db.organizations().insert();
    addComponent(newProjectDto(organizationDto).setKey("K1"));
    ComponentDto otherUserFavorite = newProjectDto(organizationDto).setKey("K42");
    db.components().insertComponent(otherUserFavorite);
    db.favorites().add(otherUserFavorite, 42);
    dbClient.userPermissionDao().insert(dbSession, new UserPermissionDto(organizationDto.getUuid(), UserRole.USER, 42, otherUserFavorite.getId()));
    db.commit();
    SearchResponse result = call();
    assertThat(result.getFavoritesList()).extracting(Favorite::getKey).containsExactly("K1");
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) UserPermissionDto(org.sonar.db.permission.UserPermissionDto) OrganizationDto(org.sonar.db.organization.OrganizationDto) SearchResponse(org.sonarqube.ws.Favorites.SearchResponse) Test(org.junit.Test)

Example 2 with SearchResponse

use of org.sonarqube.ws.Favorites.SearchResponse in project sonarqube by SonarSource.

the class SearchActionTest method paginate_results.

@Test
public void paginate_results() {
    IntStream.rangeClosed(1, 9).forEach(i -> addComponent(newProjectDto(db.getDefaultOrganization()).setKey("K" + i).setName("N" + i)));
    ComponentDto unauthorizedProject = db.components().insertComponent(newProjectDto(db.getDefaultOrganization()));
    db.favorites().add(unauthorizedProject, USER_ID);
    SearchResponse result = call(2, 3);
    assertThat(result.getFavoritesCount()).isEqualTo(3);
    assertThat(result.getFavoritesList()).extracting(Favorite::getKey).containsExactly("K4", "K5", "K6");
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) SearchResponse(org.sonarqube.ws.Favorites.SearchResponse) Test(org.junit.Test)

Example 3 with SearchResponse

use of org.sonarqube.ws.Favorites.SearchResponse in project sonarqube by SonarSource.

the class SearchActionTest method return_favorites.

@Test
public void return_favorites() {
    ComponentDto project = newProjectDto(db.getDefaultOrganization(), "P1").setKey("K1").setName("N1");
    addComponent(project);
    addComponent(newFileDto(project).setKey("K11").setName("N11"));
    addComponent(newProjectDto(db.getDefaultOrganization(), "P2").setKey("K2").setName("N2"));
    SearchResponse result = call();
    assertThat(result.getPaging()).extracting(Paging::getPageIndex, Paging::getPageSize, Paging::getTotal).containsExactly(1, 100, 3);
    assertThat(result.getFavoritesList()).extracting(Favorite::getKey, Favorite::getName, Favorite::getQualifier).containsOnly(tuple("K1", "N1", PROJECT), tuple("K11", "N11", FILE), tuple("K2", "N2", PROJECT));
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) SearchResponse(org.sonarqube.ws.Favorites.SearchResponse) Test(org.junit.Test)

Example 4 with SearchResponse

use of org.sonarqube.ws.Favorites.SearchResponse in project sonarqube by SonarSource.

the class SearchActionTest method favorites_ordered_by_name.

@Test
public void favorites_ordered_by_name() {
    OrganizationDto organizationDto = db.organizations().insert();
    addComponent(newProjectDto(organizationDto).setName("N2"));
    addComponent(newProjectDto(organizationDto).setName("N3"));
    addComponent(newProjectDto(organizationDto).setName("N1"));
    SearchResponse result = call();
    assertThat(result.getFavoritesList()).extracting(Favorite::getName).containsExactly("N1", "N2", "N3");
}
Also used : OrganizationDto(org.sonar.db.organization.OrganizationDto) SearchResponse(org.sonarqube.ws.Favorites.SearchResponse) Test(org.junit.Test)

Example 5 with SearchResponse

use of org.sonarqube.ws.Favorites.SearchResponse in project sonarqube by SonarSource.

the class SearchAction method handle.

@Override
public void handle(Request request, Response response) throws Exception {
    SearchRequest searchRequest = toWsRequest(request);
    SearchResults searchResults = toSearchResults(searchRequest);
    SearchResponse wsResponse = toSearchResponse(searchResults);
    writeProtobuf(wsResponse, request, response);
}
Also used : SearchRequest(org.sonarqube.ws.client.favorite.SearchRequest) SearchResponse(org.sonarqube.ws.Favorites.SearchResponse)

Aggregations

SearchResponse (org.sonarqube.ws.Favorites.SearchResponse)7 Test (org.junit.Test)6 ComponentDto (org.sonar.db.component.ComponentDto)4 OrganizationDto (org.sonar.db.organization.OrganizationDto)3 UserPermissionDto (org.sonar.db.permission.UserPermissionDto)1 SearchRequest (org.sonarqube.ws.client.favorite.SearchRequest)1