diff options
author | Teryk Bellahsene <teryk.bellahsene@sonarsource.com> | 2016-12-21 17:25:06 +0100 |
---|---|---|
committer | Teryk Bellahsene <teryk.bellahsene@sonarsource.com> | 2016-12-21 17:53:01 +0100 |
commit | d24f6e9968eaf33323a2b443f8c62af34e32dc62 (patch) | |
tree | 8c66aa9340d21d95a26b4759a3a19fc33a5fb803 /sonar-ws | |
parent | 028b8c4cf67ff299698024924a18641c97f1104f (diff) | |
download | sonarqube-d24f6e9968eaf33323a2b443f8c62af34e32dc62.tar.gz sonarqube-d24f6e9968eaf33323a2b443f8c62af34e32dc62.zip |
WS api/favorites/search use a SearchRequest
Diffstat (limited to 'sonar-ws')
4 files changed, 111 insertions, 6 deletions
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/favorite/FavoritesService.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/favorite/FavoritesService.java index c24e8c3f7a1..727e05ed684 100644 --- a/sonar-ws/src/main/java/org/sonarqube/ws/client/favorite/FavoritesService.java +++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/favorite/FavoritesService.java @@ -20,7 +20,6 @@ package org.sonarqube.ws.client.favorite; -import javax.annotation.Nullable; import org.sonar.api.server.ws.WebService.Param; import org.sonarqube.ws.Favorites.SearchResponse; import org.sonarqube.ws.client.BaseService; @@ -51,13 +50,13 @@ public class FavoritesService extends BaseService { call(post); } - public SearchResponse search(@Nullable Integer page, @Nullable Integer pageSize) { + public SearchResponse search(SearchRequest request) { GetRequest get = new GetRequest(path(ACTION_SEARCH)); - if (page != null) { - get.setParam(Param.PAGE, page); + if (request.getPage() != null) { + get.setParam(Param.PAGE, request.getPage()); } - if (pageSize != null) { - get.setParam(Param.PAGE_SIZE, pageSize); + if (request.getPageSize() != null) { + get.setParam(Param.PAGE_SIZE, request.getPageSize()); } return call(get, SearchResponse.parser()); diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/favorite/SearchRequest.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/favorite/SearchRequest.java new file mode 100644 index 00000000000..a4d00bee1ae --- /dev/null +++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/favorite/SearchRequest.java @@ -0,0 +1,54 @@ +/* + * SonarQube + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +package org.sonarqube.ws.client.favorite; + +import javax.annotation.CheckForNull; +import javax.annotation.Nullable; + +public class SearchRequest { + public static final int MAX_PAGE_SIZE = 500; + + private Integer page; + private Integer pageSize; + + @CheckForNull + public Integer getPage() { + return page; + } + + public SearchRequest setPage(@Nullable Integer page) { + this.page = page; + return this; + } + + @CheckForNull + public Integer getPageSize() { + return pageSize; + } + + public SearchRequest setPageSize(@Nullable Integer pageSize) { + if (pageSize != null && pageSize > MAX_PAGE_SIZE) { + throw new IllegalArgumentException("Page size must be lower than or equals to " + MAX_PAGE_SIZE); + } + this.pageSize = pageSize; + return this; + } +} diff --git a/sonar-ws/src/test/java/org/sonarqube/ws/client/favorite/FavoritesServiceTest.java b/sonar-ws/src/test/java/org/sonarqube/ws/client/favorite/FavoritesServiceTest.java index b6ce72fa1da..05202813f23 100644 --- a/sonar-ws/src/test/java/org/sonarqube/ws/client/favorite/FavoritesServiceTest.java +++ b/sonar-ws/src/test/java/org/sonarqube/ws/client/favorite/FavoritesServiceTest.java @@ -22,6 +22,7 @@ package org.sonarqube.ws.client.favorite; import org.junit.Rule; import org.junit.Test; +import org.sonar.api.server.ws.WebService.Param; import org.sonarqube.ws.client.ServiceTester; import org.sonarqube.ws.client.WsConnector; @@ -53,4 +54,15 @@ public class FavoritesServiceTest { .hasParam(PARAM_COMPONENT, "my_project") .andNoOtherParam(); } + + @Test + public void search() { + underTest.search(new SearchRequest().setPage(42).setPageSize(255)); + + serviceTester.assertThat(serviceTester.getGetRequest()) + .hasPath("search") + .hasParam(Param.PAGE, 42) + .hasParam(Param.PAGE_SIZE, 255) + .andNoOtherParam(); + } } diff --git a/sonar-ws/src/test/java/org/sonarqube/ws/client/favorite/SearchRequestTest.java b/sonar-ws/src/test/java/org/sonarqube/ws/client/favorite/SearchRequestTest.java new file mode 100644 index 00000000000..d0a10c13c92 --- /dev/null +++ b/sonar-ws/src/test/java/org/sonarqube/ws/client/favorite/SearchRequestTest.java @@ -0,0 +1,40 @@ +/* + * SonarQube + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +package org.sonarqube.ws.client.favorite; + +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; + +public class SearchRequestTest { + @Rule + public ExpectedException expectedException = ExpectedException.none(); + + private SearchRequest underTest = new SearchRequest(); + + @Test + public void fail_if_page_size_greater_than_500() { + expectedException.expect(IllegalArgumentException.class); + expectedException.expectMessage("Page size must be lower than or equals to 500"); + + underTest.setPageSize(501); + } +} |