diff options
author | Julien Lancelot <julien.lancelot@sonarsource.com> | 2017-08-03 16:31:50 +0200 |
---|---|---|
committer | Janos Gyerik <janos.gyerik@sonarsource.com> | 2017-09-12 10:55:10 +0200 |
commit | f2bdffe9ab4d8079a639d203b804bd1b3118bcf6 (patch) | |
tree | 5ae22ea3c49a1459b215c707fa4d3d942fffb831 /sonar-ws | |
parent | 66658a7557d78fd809d71227da15e56a2926d4f7 (diff) | |
download | sonarqube-f2bdffe9ab4d8079a639d203b804bd1b3118bcf6.tar.gz sonarqube-f2bdffe9ab4d8079a639d203b804bd1b3118bcf6.zip |
SONAR-9616 Support branch in api/project_analyses/search
Diffstat (limited to 'sonar-ws')
5 files changed, 24 insertions, 5 deletions
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/projectanalysis/ProjectAnalysesWsParameters.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/projectanalysis/ProjectAnalysesWsParameters.java index 2e7e42e1a0d..39607605092 100644 --- a/sonar-ws/src/main/java/org/sonarqube/ws/client/projectanalysis/ProjectAnalysesWsParameters.java +++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/projectanalysis/ProjectAnalysesWsParameters.java @@ -27,6 +27,7 @@ public class ProjectAnalysesWsParameters { public static final String PARAM_PROJECT = "project"; public static final String PARAM_FROM = "from"; public static final String PARAM_TO = "to"; + public static final String PARAM_BRANCH = "branch"; private ProjectAnalysesWsParameters() { // static access only diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/projectanalysis/ProjectAnalysisService.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/projectanalysis/ProjectAnalysisService.java index 024f5fd0ee7..23cd6034fae 100644 --- a/sonar-ws/src/main/java/org/sonarqube/ws/client/projectanalysis/ProjectAnalysisService.java +++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/projectanalysis/ProjectAnalysisService.java @@ -26,6 +26,7 @@ import org.sonarqube.ws.client.WsConnector; import static org.sonar.api.server.ws.WebService.Param.PAGE; import static org.sonar.api.server.ws.WebService.Param.PAGE_SIZE; +import static org.sonarqube.ws.client.projectanalysis.ProjectAnalysesWsParameters.PARAM_BRANCH; import static org.sonarqube.ws.client.projectanalysis.ProjectAnalysesWsParameters.PARAM_CATEGORY; import static org.sonarqube.ws.client.projectanalysis.ProjectAnalysesWsParameters.PARAM_PROJECT; @@ -39,6 +40,7 @@ public class ProjectAnalysisService extends BaseService { EventCategory eventCategory = searchRequest.getCategory(); GetRequest request = new GetRequest(path("search")) .setParam(PARAM_PROJECT, searchRequest.getProject()) + .setParam(PARAM_BRANCH, searchRequest.getBranch()) .setParam(PARAM_CATEGORY, eventCategory == null ? null : eventCategory.name()) .setParam(PAGE, searchRequest.getPage()) .setParam(PAGE_SIZE, searchRequest.getPageSize()); diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/projectanalysis/SearchRequest.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/projectanalysis/SearchRequest.java index c067a12621c..c415d62b6ad 100644 --- a/sonar-ws/src/main/java/org/sonarqube/ws/client/projectanalysis/SearchRequest.java +++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/projectanalysis/SearchRequest.java @@ -30,6 +30,7 @@ public class SearchRequest { public static final int MAX_SIZE = 500; private final String project; + private final String branch; private final EventCategory category; private final int page; private final int pageSize; @@ -38,6 +39,7 @@ public class SearchRequest { private SearchRequest(Builder builder) { this.project = builder.project; + this.branch= builder.branch; this.category = builder.category; this.page = builder.page; this.pageSize = builder.pageSize; @@ -50,6 +52,11 @@ public class SearchRequest { } @CheckForNull + public String getBranch() { + return branch; + } + + @CheckForNull public EventCategory getCategory() { return category; } @@ -78,6 +85,7 @@ public class SearchRequest { public static class Builder { private String project; + private String branch; private EventCategory category; private int page = 1; private int pageSize = DEFAULT_PAGE_SIZE; @@ -93,6 +101,11 @@ public class SearchRequest { return this; } + public Builder setBranch(@Nullable String branch) { + this.branch = branch; + return this; + } + public Builder setCategory(@Nullable EventCategory category) { this.category = category; return this; diff --git a/sonar-ws/src/test/java/org/sonarqube/ws/client/projectanalysis/ProjectAnalysisServiceTest.java b/sonar-ws/src/test/java/org/sonarqube/ws/client/projectanalysis/ProjectAnalysisServiceTest.java index 5e2d014944e..8139bd00434 100644 --- a/sonar-ws/src/test/java/org/sonarqube/ws/client/projectanalysis/ProjectAnalysisServiceTest.java +++ b/sonar-ws/src/test/java/org/sonarqube/ws/client/projectanalysis/ProjectAnalysisServiceTest.java @@ -31,6 +31,7 @@ import static org.mockito.Mockito.mock; import static org.sonar.api.server.ws.WebService.Param.PAGE; import static org.sonar.api.server.ws.WebService.Param.PAGE_SIZE; import static org.sonarqube.ws.client.projectanalysis.EventCategory.QUALITY_GATE; +import static org.sonarqube.ws.client.projectanalysis.ProjectAnalysesWsParameters.PARAM_BRANCH; import static org.sonarqube.ws.client.projectanalysis.ProjectAnalysesWsParameters.PARAM_CATEGORY; import static org.sonarqube.ws.client.projectanalysis.ProjectAnalysesWsParameters.PARAM_PROJECT; @@ -45,6 +46,7 @@ public class ProjectAnalysisServiceTest { public void search() { underTest.search(SearchRequest.builder() .setProject("project") + .setBranch("my_branch") .setCategory(QUALITY_GATE) .setPage(10) .setPageSize(50) @@ -54,6 +56,7 @@ public class ProjectAnalysisServiceTest { assertThat(serviceTester.getGetParser()).isSameAs(ProjectAnalyses.SearchResponse.parser()); serviceTester.assertThat(getRequest) .hasParam(PARAM_PROJECT, "project") + .hasParam(PARAM_BRANCH, "my_branch") .hasParam(PARAM_CATEGORY, QUALITY_GATE.name()) .hasParam(PAGE, 10) .hasParam(PAGE_SIZE, 50) @@ -61,19 +64,17 @@ public class ProjectAnalysisServiceTest { } @Test - public void search_without_category() { + public void search_with_minimal_fields() { underTest.search(SearchRequest.builder() .setProject("project") - .setPage(10) - .setPageSize(50) .build()); GetRequest getRequest = serviceTester.getGetRequest(); assertThat(serviceTester.getGetParser()).isSameAs(ProjectAnalyses.SearchResponse.parser()); serviceTester.assertThat(getRequest) .hasParam(PARAM_PROJECT, "project") - .hasParam(PAGE, 10) - .hasParam(PAGE_SIZE, 50) + .hasParam(PAGE, 1) + .hasParam(PAGE_SIZE, 100) .andNoOtherParam(); } diff --git a/sonar-ws/src/test/java/org/sonarqube/ws/client/projectanalysis/SearchRequestTest.java b/sonar-ws/src/test/java/org/sonarqube/ws/client/projectanalysis/SearchRequestTest.java index 355fd27e5e8..4abe04fa8a4 100644 --- a/sonar-ws/src/test/java/org/sonarqube/ws/client/projectanalysis/SearchRequestTest.java +++ b/sonar-ws/src/test/java/org/sonarqube/ws/client/projectanalysis/SearchRequestTest.java @@ -36,6 +36,7 @@ public class SearchRequestTest { public void search_request() { SearchRequest result = underTest .setProject("P1") + .setBranch("my_branch") .setCategory(QUALITY_GATE) .setPage(2) .setPageSize(500) @@ -44,6 +45,7 @@ public class SearchRequestTest { .build(); assertThat(result.getProject()).isEqualTo("P1"); + assertThat(result.getBranch()).isEqualTo("my_branch"); assertThat(result.getPage()).isEqualTo(2); assertThat(result.getPageSize()).isEqualTo(500); assertThat(result.getCategory()).isEqualTo(QUALITY_GATE); |