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