diff options
author | Julien Lancelot <julien.lancelot@sonarsource.com> | 2017-01-18 09:23:43 +0100 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@sonarsource.com> | 2017-01-18 13:38:00 +0100 |
commit | 013a9aa964e25e0c70bec60eaa4484d5c7e8683f (patch) | |
tree | 072278a503c2d5fb1be39d28d59fa1fb40a63f06 | |
parent | 35de0ed9acb340b5f09281c733951e46ebe40276 (diff) | |
download | sonarqube-013a9aa964e25e0c70bec60eaa4484d5c7e8683f.tar.gz sonarqube-013a9aa964e25e0c70bec60eaa4484d5c7e8683f.zip |
SONAR-8467 Add ProjectAnalysisService
3 files changed, 131 insertions, 1 deletions
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 new file mode 100644 index 00000000000..a760ac3a130 --- /dev/null +++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/projectanalysis/ProjectAnalysisService.java @@ -0,0 +1,49 @@ +/* + * 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.projectanalysis; + +import org.sonarqube.ws.ProjectAnalyses; +import org.sonarqube.ws.client.BaseService; +import org.sonarqube.ws.client.GetRequest; +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_CATEGORY; +import static org.sonarqube.ws.client.projectanalysis.ProjectAnalysesWsParameters.PARAM_PROJECT; + +public class ProjectAnalysisService extends BaseService { + + public ProjectAnalysisService(WsConnector wsConnector) { + super(wsConnector, "api/project_analyses"); + } + + public void search(SearchRequest searchRequest) { + EventCategory eventCategory = searchRequest.getCategory(); + GetRequest request = new GetRequest(path("search")) + .setParam(PARAM_PROJECT, searchRequest.getProject()) + .setParam(PARAM_CATEGORY, eventCategory == null ? null : eventCategory.name()) + .setParam(PAGE, searchRequest.getPage()) + .setParam(PAGE_SIZE, searchRequest.getPageSize()); + call(request, ProjectAnalyses.SearchResponse.parser()); + } + +} 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 3f914a869b6..fa5589c6fe4 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 @@ -35,7 +35,7 @@ public class SearchRequest { private final int page; private final int pageSize; - public SearchRequest(Builder builder) { + private SearchRequest(Builder builder) { this.project = builder.project; this.category = builder.category; this.page = builder.page; 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 new file mode 100644 index 00000000000..717e58782a9 --- /dev/null +++ b/sonar-ws/src/test/java/org/sonarqube/ws/client/projectanalysis/ProjectAnalysisServiceTest.java @@ -0,0 +1,81 @@ +/* + * 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.projectanalysis; + +import org.junit.Rule; +import org.junit.Test; +import org.sonarqube.ws.ProjectAnalyses; +import org.sonarqube.ws.client.GetRequest; +import org.sonarqube.ws.client.ServiceTester; +import org.sonarqube.ws.client.WsConnector; + +import static org.assertj.core.api.Assertions.assertThat; +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_CATEGORY; +import static org.sonarqube.ws.client.projectanalysis.ProjectAnalysesWsParameters.PARAM_PROJECT; + +public class ProjectAnalysisServiceTest { + + @Rule + public ServiceTester<ProjectAnalysisService> serviceTester = new ServiceTester<>(new ProjectAnalysisService(mock(WsConnector.class))); + + private ProjectAnalysisService underTest = serviceTester.getInstanceUnderTest(); + + @Test + public void search() { + underTest.search(SearchRequest.builder() + .setProject("project") + .setCategory(QUALITY_GATE) + .setPage(10) + .setPageSize(50) + .build()); + GetRequest getRequest = serviceTester.getGetRequest(); + + assertThat(serviceTester.getGetParser()).isSameAs(ProjectAnalyses.SearchResponse.parser()); + serviceTester.assertThat(getRequest) + .hasParam(PARAM_PROJECT, "project") + .hasParam(PARAM_CATEGORY, QUALITY_GATE.name()) + .hasParam(PAGE, 10) + .hasParam(PAGE_SIZE, 50) + .andNoOtherParam(); + } + + @Test + public void search_without_category() { + 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) + .andNoOtherParam(); + } + +} |