diff options
author | Simon Brandhof <simon.brandhof@sonarsource.com> | 2017-12-04 15:52:09 +0100 |
---|---|---|
committer | Daniel Schwarz <bartfastiel@users.noreply.github.com> | 2017-12-06 14:40:17 +0100 |
commit | 9cba9e0a34bd4b7fa24a7b9c9b8616c0c47273da (patch) | |
tree | 9e2eacc6002d403c9bd32976d90003e1edd68646 /sonar-ws | |
parent | 2259c6808e011a95fa1d0b8e5681f507befdb4e9 (diff) | |
download | sonarqube-9cba9e0a34bd4b7fa24a7b9c9b8616c0c47273da.tar.gz sonarqube-9cba9e0a34bd4b7fa24a7b9c9b8616c0c47273da.zip |
Remove deprecated MeasuresService
Diffstat (limited to 'sonar-ws')
17 files changed, 13 insertions, 1240 deletions
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/BaseService.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/BaseService.java index 4c6a0e9449e..46e07dbb804 100644 --- a/sonar-ws/src/main/java/org/sonarqube/ws/client/BaseService.java +++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/BaseService.java @@ -52,7 +52,7 @@ public abstract class BaseService { return wsConnector.call(request).failIfNotSuccessful(); } - public <T extends Message> T convert(WsResponse response, Parser<T> parser) { + public static <T extends Message> T convert(WsResponse response, Parser<T> parser) { try (InputStream byteStream = response.contentStream()) { byte[] bytes = IOUtils.toByteArray(byteStream); // HTTP header "Content-Type" is not verified. It may be different than protobuf. diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/DefaultWsClient.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/DefaultWsClient.java index 27d06ffac66..71d261c2718 100644 --- a/sonar-ws/src/main/java/org/sonarqube/ws/client/DefaultWsClient.java +++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/DefaultWsClient.java @@ -63,7 +63,6 @@ class DefaultWsClient implements WsClient { private final UserGroupsService userGroupsService; private final UserTokensService userTokensService; private final QualitygatesService qualityGatesService; - private final org.sonarqube.ws.client.measure.MeasuresService measuresOld; private final MeasuresService measures; private final SystemService systemService; private final CeService ceService; @@ -90,7 +89,6 @@ class DefaultWsClient implements WsClient { this.userGroupsService = new UserGroupsService(wsConnector); this.userTokensService = new UserTokensService(wsConnector); this.qualityGatesService = new QualitygatesService(wsConnector); - this.measuresOld = new org.sonarqube.ws.client.measure.MeasuresService(wsConnector); this.measures = new MeasuresService(wsConnector); this.systemService = new SystemService(wsConnector); this.ceService = new CeService(wsConnector); @@ -166,11 +164,6 @@ class DefaultWsClient implements WsClient { } @Override - public org.sonarqube.ws.client.measure.MeasuresService measuresOld() { - return measuresOld; - } - - @Override public MeasuresService measures() { return measures; } diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/WsClient.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/WsClient.java index 1de94f492e4..75ac3a18e1c 100644 --- a/sonar-ws/src/main/java/org/sonarqube/ws/client/WsClient.java +++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/WsClient.java @@ -91,12 +91,6 @@ public interface WsClient { QualitygatesService qualityGates(); - /** - * @deprecated since 7.0 use {@link #measures()} instead - */ - @Deprecated - org.sonarqube.ws.client.measure.MeasuresService measuresOld(); - MeasuresService measures(); SystemService system(); diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/measure/ComponentRequest.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/measure/ComponentRequest.java deleted file mode 100644 index 4eb5bbcab20..00000000000 --- a/sonar-ws/src/main/java/org/sonarqube/ws/client/measure/ComponentRequest.java +++ /dev/null @@ -1,130 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 SonarSource SA - * mailto:info 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.measure; - -import java.util.List; -import javax.annotation.CheckForNull; -import javax.annotation.Nullable; - -public class ComponentRequest { - private String componentId; - private String componentKey; - private String component; - private String branch; - private List<String> metricKeys; - private List<String> additionalFields; - private String developerId; - private String developerKey; - - /** - * @deprecated since 6.6, please use {@link #getComponent()} instead - */ - @Deprecated - @CheckForNull - public String getComponentId() { - return componentId; - } - - /** - * @deprecated since 6.6, please use {@link #setComponent(String)} instead - */ - @Deprecated - public ComponentRequest setComponentId(@Nullable String componentId) { - this.componentId = componentId; - return this; - } - - /** - * @deprecated since 6.6, please use {@link #getComponent()} instead - */ - @Deprecated - @CheckForNull - public String getComponentKey() { - return componentKey; - } - - /** - * @deprecated since 6.6, please use {@link #setComponent(String)} instead - */ - @Deprecated - public ComponentRequest setComponentKey(@Nullable String componentKey) { - this.componentKey = componentKey; - return this; - } - - @CheckForNull - public String getComponent() { - return component; - } - - public ComponentRequest setComponent(@Nullable String component) { - this.component = component; - return this; - } - - @CheckForNull - public String getBranch() { - return branch; - } - - public ComponentRequest setBranch(@Nullable String branch) { - this.branch = branch; - return this; - } - - public List<String> getMetricKeys() { - return metricKeys; - } - - public ComponentRequest setMetricKeys(@Nullable List<String> metricKeys) { - this.metricKeys = metricKeys; - return this; - } - - @CheckForNull - public List<String> getAdditionalFields() { - return additionalFields; - } - - public ComponentRequest setAdditionalFields(@Nullable List<String> additionalFields) { - this.additionalFields = additionalFields; - return this; - } - - @CheckForNull - public String getDeveloperId() { - return developerId; - } - - public ComponentRequest setDeveloperId(@Nullable String developerId) { - this.developerId = developerId; - return this; - } - - @CheckForNull - public String getDeveloperKey() { - return developerKey; - } - - public ComponentRequest setDeveloperKey(@Nullable String developerKey) { - this.developerKey = developerKey; - return this; - } -} diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/measure/ComponentTreeRequest.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/measure/ComponentTreeRequest.java deleted file mode 100644 index fa6bb474a70..00000000000 --- a/sonar-ws/src/main/java/org/sonarqube/ws/client/measure/ComponentTreeRequest.java +++ /dev/null @@ -1,242 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 SonarSource SA - * mailto:info 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.measure; - -import java.util.List; -import javax.annotation.CheckForNull; -import javax.annotation.Nullable; - -public class ComponentTreeRequest { - - private String baseComponentId; - private String baseComponentKey; - private String component; - private String branch; - private String strategy; - private List<String> qualifiers; - private List<String> additionalFields; - private String query; - private List<String> sort; - private Boolean asc; - private String metricSort; - private Integer metricPeriodSort; - private String metricSortFilter; - private List<String> metricKeys; - private Integer page; - private Integer pageSize; - private String developerId; - private String developerKey; - - /** - * @deprecated since 6.6, please use {@link #getComponent()} instead - */ - @Deprecated - @CheckForNull - public String getBaseComponentId() { - return baseComponentId; - } - - /** - * @deprecated since 6.6, please use {@link #setComponent(String)} instead - */ - @Deprecated - public ComponentTreeRequest setBaseComponentId(@Nullable String baseComponentId) { - this.baseComponentId = baseComponentId; - return this; - } - - /** - * @deprecated since 6.6, please use {@link #getComponent()} instead - */ - @Deprecated - @CheckForNull - public String getBaseComponentKey() { - return baseComponentKey; - } - - /** - * @deprecated since 6.6, please use {@link #setComponent(String)} instead - */ - @Deprecated - public ComponentTreeRequest setBaseComponentKey(@Nullable String baseComponentKey) { - this.baseComponentKey = baseComponentKey; - return this; - } - - @CheckForNull - public String getComponent() { - return component; - } - - public ComponentTreeRequest setComponent(@Nullable String component) { - this.component = component; - return this; - } - - @CheckForNull - public String getBranch() { - return branch; - } - - public ComponentTreeRequest setBranch(@Nullable String branch) { - this.branch = branch; - return this; - } - - @CheckForNull - public String getStrategy() { - return strategy; - } - - public ComponentTreeRequest setStrategy(String strategy) { - this.strategy = strategy; - return this; - } - - @CheckForNull - public List<String> getQualifiers() { - return qualifiers; - } - - public ComponentTreeRequest setQualifiers(@Nullable List<String> qualifiers) { - this.qualifiers = qualifiers; - return this; - } - - @CheckForNull - public List<String> getAdditionalFields() { - return additionalFields; - } - - public ComponentTreeRequest setAdditionalFields(@Nullable List<String> additionalFields) { - this.additionalFields = additionalFields; - return this; - } - - @CheckForNull - public String getQuery() { - return query; - } - - public ComponentTreeRequest setQuery(@Nullable String query) { - this.query = query; - return this; - } - - @CheckForNull - public List<String> getSort() { - return sort; - } - - public ComponentTreeRequest setSort(@Nullable List<String> sort) { - this.sort = sort; - return this; - } - - @CheckForNull - public String getMetricSort() { - return metricSort; - } - - public ComponentTreeRequest setMetricSort(@Nullable String metricSort) { - this.metricSort = metricSort; - return this; - } - - @CheckForNull - public String getMetricSortFilter() { - return metricSortFilter; - } - - public ComponentTreeRequest setMetricSortFilter(@Nullable String metricSortFilter) { - this.metricSortFilter = metricSortFilter; - return this; - } - - @CheckForNull - public List<String> getMetricKeys() { - return metricKeys; - } - - public ComponentTreeRequest setMetricKeys(List<String> metricKeys) { - this.metricKeys = metricKeys; - return this; - } - - @CheckForNull - public Boolean getAsc() { - return asc; - } - - public ComponentTreeRequest setAsc(@Nullable Boolean asc) { - this.asc = asc; - return this; - } - - @CheckForNull - public Integer getPage() { - return page; - } - - public ComponentTreeRequest setPage(int page) { - this.page = page; - return this; - } - - @CheckForNull - public Integer getPageSize() { - return pageSize; - } - - public ComponentTreeRequest setPageSize(int pageSize) { - this.pageSize = pageSize; - return this; - } - - @CheckForNull - public Integer getMetricPeriodSort() { - return metricPeriodSort; - } - - public ComponentTreeRequest setMetricPeriodSort(@Nullable Integer metricPeriodSort) { - this.metricPeriodSort = metricPeriodSort; - return this; - } - - @CheckForNull - public String getDeveloperId() { - return developerId; - } - - public ComponentTreeRequest setDeveloperId(@Nullable String developerId) { - this.developerId = developerId; - return this; - } - - @CheckForNull - public String getDeveloperKey() { - return developerKey; - } - - public ComponentTreeRequest setDeveloperKey(@Nullable String developerKey) { - this.developerKey = developerKey; - return this; - } -} diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/measure/MeasuresService.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/measure/MeasuresService.java deleted file mode 100644 index e68608e655e..00000000000 --- a/sonar-ws/src/main/java/org/sonarqube/ws/client/measure/MeasuresService.java +++ /dev/null @@ -1,119 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 SonarSource SA - * mailto:info 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.measure; - -import org.sonar.api.server.ws.WebService.Param; -import org.sonarqube.ws.Measures.ComponentTreeWsResponse; -import org.sonarqube.ws.Measures.ComponentWsResponse; -import org.sonarqube.ws.Measures.SearchHistoryResponse; -import org.sonarqube.ws.Measures.SearchWsResponse; -import org.sonarqube.ws.client.BaseService; -import org.sonarqube.ws.client.GetRequest; -import org.sonarqube.ws.client.WsConnector; - -import static org.sonarqube.ws.client.measure.MeasuresWsParameters.ACTION_COMPONENT; -import static org.sonarqube.ws.client.measure.MeasuresWsParameters.ACTION_COMPONENT_TREE; -import static org.sonarqube.ws.client.measure.MeasuresWsParameters.ACTION_SEARCH_HISTORY; -import static org.sonarqube.ws.client.measure.MeasuresWsParameters.CONTROLLER_MEASURES; -import static org.sonarqube.ws.client.measure.MeasuresWsParameters.DEPRECATED_PARAM_BASE_COMPONENT_ID; -import static org.sonarqube.ws.client.measure.MeasuresWsParameters.DEPRECATED_PARAM_BASE_COMPONENT_KEY; -import static org.sonarqube.ws.client.measure.MeasuresWsParameters.DEPRECATED_PARAM_COMPONENT_ID; -import static org.sonarqube.ws.client.measure.MeasuresWsParameters.DEPRECATED_PARAM_COMPONENT_KEY; -import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_ADDITIONAL_FIELDS; -import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_BRANCH; -import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_COMPONENT; -import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_DEVELOPER_ID; -import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_DEVELOPER_KEY; -import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_FROM; -import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_METRICS; -import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_METRIC_KEYS; -import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_METRIC_SORT; -import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_METRIC_SORT_FILTER; -import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_PROJECT_KEYS; -import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_QUALIFIERS; -import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_STRATEGY; -import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_TO; - -/** - * @deprecated since 7.0, use {@link org.sonarqube.ws.client.measures.MeasuresService} instead - */ -@Deprecated -public class MeasuresService extends BaseService { - public MeasuresService(WsConnector wsConnector) { - super(wsConnector, CONTROLLER_MEASURES); - } - - public ComponentTreeWsResponse componentTree(ComponentTreeRequest request) { - GetRequest getRequest = new GetRequest(path(ACTION_COMPONENT_TREE)) - .setParam(DEPRECATED_PARAM_BASE_COMPONENT_ID, request.getBaseComponentId()) - .setParam(DEPRECATED_PARAM_BASE_COMPONENT_KEY, request.getBaseComponentKey()) - .setParam(PARAM_COMPONENT, request.getComponent()) - .setParam(PARAM_BRANCH, request.getBranch()) - .setParam(PARAM_STRATEGY, request.getStrategy()) - .setParam(PARAM_QUALIFIERS, inlineMultipleParamValue(request.getQualifiers())) - .setParam(PARAM_METRIC_KEYS, inlineMultipleParamValue(request.getMetricKeys())) - .setParam(PARAM_ADDITIONAL_FIELDS, inlineMultipleParamValue(request.getAdditionalFields())) - .setParam(PARAM_DEVELOPER_ID, request.getDeveloperId()) - .setParam(PARAM_DEVELOPER_KEY, request.getDeveloperKey()) - .setParam("q", request.getQuery()) - .setParam("p", request.getPage()) - .setParam("ps", request.getPageSize()) - .setParam("s", inlineMultipleParamValue(request.getSort())) - .setParam("asc", request.getAsc()) - .setParam(PARAM_METRIC_SORT, request.getMetricSort()) - .setParam(PARAM_METRIC_SORT_FILTER, request.getMetricSortFilter()); - - return call(getRequest, ComponentTreeWsResponse.parser()); - } - - public ComponentWsResponse component(ComponentRequest request) { - GetRequest getRequest = new GetRequest(path(ACTION_COMPONENT)) - .setParam(DEPRECATED_PARAM_COMPONENT_ID, request.getComponentId()) - .setParam(DEPRECATED_PARAM_COMPONENT_KEY, request.getComponentKey()) - .setParam(PARAM_COMPONENT, request.getComponent()) - .setParam(PARAM_BRANCH, request.getBranch()) - .setParam(PARAM_ADDITIONAL_FIELDS, inlineMultipleParamValue(request.getAdditionalFields())) - .setParam(PARAM_METRIC_KEYS, inlineMultipleParamValue(request.getMetricKeys())) - .setParam(PARAM_DEVELOPER_ID, request.getDeveloperId()) - .setParam(PARAM_DEVELOPER_KEY, request.getDeveloperKey()); - - return call(getRequest, ComponentWsResponse.parser()); - } - - public SearchHistoryResponse searchHistory(SearchHistoryRequest request) { - GetRequest getRequest = new GetRequest(path(ACTION_SEARCH_HISTORY)) - .setParam(PARAM_COMPONENT, request.getComponent()) - .setParam(PARAM_BRANCH, request.getBranch()) - .setParam(PARAM_METRICS, inlineMultipleParamValue(request.getMetrics())) - .setParam(PARAM_FROM, request.getFrom()) - .setParam(PARAM_TO, request.getTo()) - .setParam(Param.PAGE, request.getPage()) - .setParam(Param.PAGE_SIZE, request.getPageSize()); - - return call(getRequest, SearchHistoryResponse.parser()); - } - - public SearchWsResponse search(SearchRequest request) { - GetRequest getRequest = new GetRequest(path(ACTION_SEARCH_HISTORY)) - .setParam(PARAM_PROJECT_KEYS, inlineMultipleParamValue(request.getProjectKeys())) - .setParam(PARAM_METRIC_KEYS, inlineMultipleParamValue(request.getMetricKeys())); - return call(getRequest, SearchWsResponse.parser()); - } -} diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/measure/MeasuresWsParameters.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/measure/MeasuresWsParameters.java deleted file mode 100644 index 519ec102d41..00000000000 --- a/sonar-ws/src/main/java/org/sonarqube/ws/client/measure/MeasuresWsParameters.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 SonarSource SA - * mailto:info 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.measure; - -import com.google.common.collect.ImmutableSortedSet; -import java.util.Set; - -public class MeasuresWsParameters { - public static final String CONTROLLER_MEASURES = "api/measures"; - - // actions - public static final String ACTION_COMPONENT_TREE = "component_tree"; - public static final String ACTION_COMPONENT = "component"; - public static final String ACTION_SEARCH_HISTORY = "search_history"; - - // parameters - public static final String DEPRECATED_PARAM_BASE_COMPONENT_ID = "baseComponentId"; - public static final String DEPRECATED_PARAM_BASE_COMPONENT_KEY = "baseComponentKey"; - public static final String PARAM_COMPONENT = "component"; - public static final String PARAM_BRANCH = "branch"; - public static final String PARAM_STRATEGY = "strategy"; - public static final String PARAM_QUALIFIERS = "qualifiers"; - public static final String PARAM_METRICS = "metrics"; - public static final String PARAM_METRIC_KEYS = "metricKeys"; - public static final String PARAM_METRIC_SORT = "metricSort"; - public static final String PARAM_METRIC_PERIOD_SORT = "metricPeriodSort"; - public static final String PARAM_METRIC_SORT_FILTER = "metricSortFilter"; - public static final String PARAM_ADDITIONAL_FIELDS = "additionalFields"; - public static final String DEPRECATED_PARAM_COMPONENT_ID = "componentId"; - public static final String DEPRECATED_PARAM_COMPONENT_KEY = "componentKey"; - public static final String PARAM_PROJECT_KEYS = "projectKeys"; - public static final String PARAM_DEVELOPER_ID = "developerId"; - public static final String PARAM_DEVELOPER_KEY = "developerKey"; - public static final String PARAM_FROM = "from"; - public static final String PARAM_TO = "to"; - - public static final String ADDITIONAL_METRICS = "metrics"; - public static final String ADDITIONAL_PERIODS = "periods"; - - public static final Set<String> ADDITIONAL_FIELDS = ImmutableSortedSet.of(ADDITIONAL_METRICS, ADDITIONAL_PERIODS); - - private MeasuresWsParameters() { - // static constants only - } -} diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/measure/SearchHistoryRequest.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/measure/SearchHistoryRequest.java deleted file mode 100644 index b99b9b77b43..00000000000 --- a/sonar-ws/src/main/java/org/sonarqube/ws/client/measure/SearchHistoryRequest.java +++ /dev/null @@ -1,147 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 SonarSource SA - * mailto:info 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.measure; - -import java.util.List; -import javax.annotation.CheckForNull; -import javax.annotation.Nullable; - -import static java.lang.String.format; - -public class SearchHistoryRequest { - public static final int MAX_PAGE_SIZE = 1_000; - public static final int DEFAULT_PAGE_SIZE = 100; - - private final String component; - private final String branch; - private final List<String> metrics; - private final String from; - private final String to; - private final int page; - private final int pageSize; - - public SearchHistoryRequest(Builder builder) { - this.component = builder.component; - this.branch = builder.branch; - this.metrics = builder.metrics; - this.from = builder.from; - this.to = builder.to; - this.page = builder.page; - this.pageSize = builder.pageSize; - } - - public String getComponent() { - return component; - } - - @CheckForNull - public String getBranch() { - return branch; - } - - public List<String> getMetrics() { - return metrics; - } - - @CheckForNull - public String getFrom() { - return from; - } - - @CheckForNull - public String getTo() { - return to; - } - - public int getPage() { - return page; - } - - public int getPageSize() { - return pageSize; - } - - public static Builder builder() { - return new Builder(); - } - - public static class Builder { - private String component; - private String branch; - private List<String> metrics; - private String from; - private String to; - private int page = 1; - private int pageSize = DEFAULT_PAGE_SIZE; - - private Builder() { - // enforce build factory method - } - - public Builder setComponent(String component) { - this.component = component; - return this; - } - - public Builder setBranch(@Nullable String branch) { - this.branch = branch; - return this; - } - - public Builder setMetrics(List<String> metrics) { - this.metrics = metrics; - return this; - } - - public Builder setFrom(@Nullable String from) { - this.from = from; - return this; - } - - public Builder setTo(@Nullable String to) { - this.to = to; - return this; - } - - public Builder setPage(int page) { - this.page = page; - return this; - } - - public Builder setPageSize(int pageSize) { - this.pageSize = pageSize; - return this; - } - - public SearchHistoryRequest build() { - checkArgument(component != null && !component.isEmpty(), "Component key is required"); - checkArgument(metrics != null && !metrics.isEmpty(), "Metric keys are required"); - checkArgument(pageSize <= MAX_PAGE_SIZE, "Page size (%d) must be lower than or equal to %d", pageSize, MAX_PAGE_SIZE); - - return new SearchHistoryRequest(this); - } - - private static void checkArgument(boolean condition, String message, Object... args) { - if (!condition) { - throw new IllegalArgumentException(format(message, args)); - } - } - } -} diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/measure/SearchRequest.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/measure/SearchRequest.java deleted file mode 100644 index 5c8cc2bec0e..00000000000 --- a/sonar-ws/src/main/java/org/sonarqube/ws/client/measure/SearchRequest.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 SonarSource SA - * mailto:info 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.measure; - -import java.util.List; - -import static com.google.common.base.Preconditions.checkArgument; - -public class SearchRequest { - private static final int MAX_NB_PROJECTS = 100; - - private final List<String> metricKeys; - private final List<String> projectKeys; - - public SearchRequest(Builder builder) { - metricKeys = builder.metricKeys; - projectKeys = builder.projectKeys; - } - - public List<String> getMetricKeys() { - return metricKeys; - } - - public List<String> getProjectKeys() { - return projectKeys; - } - - public static Builder builder() { - return new Builder(); - } - - public static class Builder { - private List<String> metricKeys; - private List<String> projectKeys; - - private Builder() { - // enforce method constructor - } - - public Builder setMetricKeys(List<String> metricKeys) { - this.metricKeys = metricKeys; - return this; - } - - public Builder setProjectKeys(List<String> projectKeys) { - this.projectKeys = projectKeys; - return this; - } - - public SearchRequest build() { - checkArgument(metricKeys != null && !metricKeys.isEmpty(), "Metric keys must be provided"); - checkArgument(projectKeys != null && !projectKeys.isEmpty(), "Project keys must be provided"); - int nbComponents = projectKeys.size(); - checkArgument(nbComponents <= MAX_NB_PROJECTS, - "%s projects provided, more than maximum authorized (%s)", nbComponents, MAX_NB_PROJECTS); - return new SearchRequest(this); - } - } -} diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/measure/package-info.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/measure/package-info.java deleted file mode 100644 index f4cc7064364..00000000000 --- a/sonar-ws/src/main/java/org/sonarqube/ws/client/measure/package-info.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 SonarSource SA - * mailto:info 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. - */ -@ParametersAreNonnullByDefault -package org.sonarqube.ws.client.measure; - -import javax.annotation.ParametersAreNonnullByDefault; - diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/measures/ComponentRequest.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/measures/ComponentRequest.java index eea21c7966c..8611025b452 100644 --- a/sonar-ws/src/main/java/org/sonarqube/ws/client/measures/ComponentRequest.java +++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/measures/ComponentRequest.java @@ -37,7 +37,7 @@ public class ComponentRequest { private String componentId; private String developerId; private String developerKey; - private String metricKeys; + private List<String> metricKeys; /** * Example value: "periods,metrics" @@ -125,12 +125,12 @@ public class ComponentRequest { * This is a mandatory parameter. * Example value: "ncloc,complexity,violations" */ - public ComponentRequest setMetricKeys(String metricKeys) { + public ComponentRequest setMetricKeys(List<String> metricKeys) { this.metricKeys = metricKeys; return this; } - public String getMetricKeys() { + public List<String> getMetricKeys() { return metricKeys; } } diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/measures/ComponentTreeRequest.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/measures/ComponentTreeRequest.java index c63da756229..a7373c34f45 100644 --- a/sonar-ws/src/main/java/org/sonarqube/ws/client/measures/ComponentTreeRequest.java +++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/measures/ComponentTreeRequest.java @@ -38,7 +38,7 @@ public class ComponentTreeRequest { private String component; private String developerId; private String developerKey; - private String metricKeys; + private List<String> metricKeys; private String metricPeriodSort; private String metricSort; private String metricSortFilter; @@ -153,12 +153,12 @@ public class ComponentTreeRequest { * This is a mandatory parameter. * Example value: "ncloc,complexity,violations" */ - public ComponentTreeRequest setMetricKeys(String metricKeys) { + public ComponentTreeRequest setMetricKeys(List<String> metricKeys) { this.metricKeys = metricKeys; return this; } - public String getMetricKeys() { + public List<String> getMetricKeys() { return metricKeys; } diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/measures/MeasuresService.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/measures/MeasuresService.java index 7422d8aae2d..bbea8ca23d9 100644 --- a/sonar-ws/src/main/java/org/sonarqube/ws/client/measures/MeasuresService.java +++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/measures/MeasuresService.java @@ -57,7 +57,7 @@ public class MeasuresService extends BaseService { .setParam("componentId", request.getComponentId()) .setParam("developerId", request.getDeveloperId()) .setParam("developerKey", request.getDeveloperKey()) - .setParam("metricKeys", request.getMetricKeys()), + .setParam("metricKeys", request.getMetricKeys() == null ? null : request.getMetricKeys().stream().collect(Collectors.joining(","))), ComponentWsResponse.parser()); } @@ -78,7 +78,7 @@ public class MeasuresService extends BaseService { .setParam("component", request.getComponent()) .setParam("developerId", request.getDeveloperId()) .setParam("developerKey", request.getDeveloperKey()) - .setParam("metricKeys", request.getMetricKeys()) + .setParam("metricKeys", request.getMetricKeys() == null ? null : request.getMetricKeys().stream().collect(Collectors.joining(","))) .setParam("metricPeriodSort", request.getMetricPeriodSort()) .setParam("metricSort", request.getMetricSort()) .setParam("metricSortFilter", request.getMetricSortFilter()) @@ -101,7 +101,7 @@ public class MeasuresService extends BaseService { public SearchWsResponse search(SearchRequest request) { return call( new GetRequest(path("search")) - .setParam("metricKeys", request.getMetricKeys()) + .setParam("metricKeys", request.getMetricKeys() == null ? null : request.getMetricKeys().stream().collect(Collectors.joining(","))) .setParam("projectKeys", request.getProjectKeys() == null ? null : request.getProjectKeys().stream().collect(Collectors.joining(","))), SearchWsResponse.parser()); } diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/measures/SearchRequest.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/measures/SearchRequest.java index bd7614fb216..422c6ffa977 100644 --- a/sonar-ws/src/main/java/org/sonarqube/ws/client/measures/SearchRequest.java +++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/measures/SearchRequest.java @@ -31,19 +31,19 @@ import javax.annotation.Generated; @Generated("sonar-ws-generator") public class SearchRequest { - private String metricKeys; + private List<String> metricKeys; private List<String> projectKeys; /** * This is a mandatory parameter. * Example value: "ncloc,complexity,violations" */ - public SearchRequest setMetricKeys(String metricKeys) { + public SearchRequest setMetricKeys(List<String> metricKeys) { this.metricKeys = metricKeys; return this; } - public String getMetricKeys() { + public List<String> getMetricKeys() { return metricKeys; } diff --git a/sonar-ws/src/test/java/org/sonarqube/ws/client/measure/MeasuresServiceTest.java b/sonar-ws/src/test/java/org/sonarqube/ws/client/measure/MeasuresServiceTest.java deleted file mode 100644 index cfdc00f510c..00000000000 --- a/sonar-ws/src/test/java/org/sonarqube/ws/client/measure/MeasuresServiceTest.java +++ /dev/null @@ -1,200 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 SonarSource SA - * mailto:info 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.measure; - -import java.util.ArrayList; -import java.util.List; -import org.junit.Rule; -import org.junit.Test; -import org.sonarqube.ws.Measures; -import org.sonarqube.ws.Measures.ComponentTreeWsResponse; -import org.sonarqube.ws.Measures.ComponentWsResponse; -import org.sonarqube.ws.client.GetRequest; -import org.sonarqube.ws.client.ServiceTester; -import org.sonarqube.ws.client.WsConnector; - -import static com.google.common.collect.Lists.newArrayList; -import static java.util.Arrays.asList; -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.mock; -import static org.sonarqube.ws.client.measure.MeasuresWsParameters.DEPRECATED_PARAM_BASE_COMPONENT_ID; -import static org.sonarqube.ws.client.measure.MeasuresWsParameters.DEPRECATED_PARAM_BASE_COMPONENT_KEY; -import static org.sonarqube.ws.client.measure.MeasuresWsParameters.DEPRECATED_PARAM_COMPONENT_ID; -import static org.sonarqube.ws.client.measure.MeasuresWsParameters.DEPRECATED_PARAM_COMPONENT_KEY; -import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_ADDITIONAL_FIELDS; -import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_BRANCH; -import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_COMPONENT; -import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_DEVELOPER_ID; -import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_DEVELOPER_KEY; -import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_FROM; -import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_METRICS; -import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_METRIC_KEYS; -import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_METRIC_SORT; -import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_METRIC_SORT_FILTER; -import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_PROJECT_KEYS; -import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_QUALIFIERS; -import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_STRATEGY; -import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_TO; - -public class MeasuresServiceTest { - private static final String VALUE_BASE_COMPONENT_ID = "base-component-id"; - private static final String VALUE_BASE_COMPONENT_KEY = "base-component-key"; - private static final String VALUE_COMPONENT = "component-key"; - private static final List<String> VALUE_METRIC_KEYS = newArrayList("ncloc", "complexity"); - private static final List<String> VALUE_METRICS = newArrayList("ncloc", "complexity"); - private static final String VALUE_STRATEGY = "all"; - private static final List<String> VALUE_QUALIFIERS = newArrayList("FIL", "PRJ"); - private static final ArrayList<String> VALUE_ADDITIONAL_FIELDS = newArrayList("metrics"); - private static final List<String> VALUE_SORT = newArrayList("qualifier", "metric"); - private static final boolean VALUE_ASC = false; - private static final String VALUE_METRIC_SORT = "ncloc"; - private static final String VALUE_METRIC_SORT_FILTER = "all"; - private static final int VALUE_PAGE = 42; - private static final int VALUE_PAGE_SIZE = 1000; - private static final String VALUE_QUERY = "query-sq"; - private static final String VALUE_DEVELOPER_ID = "developer-id"; - private static final String VALUE_DEVELOPER_KEY = "developer-key"; - private static final String VALUE_FROM = "2017-10-01"; - private static final String VALUE_TO = "2017-11-01"; - - @Rule - public ServiceTester<MeasuresService> serviceTester = new ServiceTester<>(new MeasuresService(mock(WsConnector.class))); - - private MeasuresService underTest = serviceTester.getInstanceUnderTest(); - - @Test - public void component() { - ComponentRequest request = new ComponentRequest() - .setComponentId(VALUE_BASE_COMPONENT_ID) - .setComponentKey(VALUE_BASE_COMPONENT_KEY) - .setComponent(VALUE_BASE_COMPONENT_KEY) - .setBranch("my_branch") - .setMetricKeys(VALUE_METRIC_KEYS) - .setAdditionalFields(VALUE_ADDITIONAL_FIELDS) - .setMetricKeys(VALUE_METRICS) - .setDeveloperId(VALUE_DEVELOPER_ID) - .setDeveloperKey(VALUE_DEVELOPER_KEY); - - underTest.component(request); - GetRequest getRequest = serviceTester.getGetRequest(); - - assertThat(serviceTester.getGetParser()).isSameAs(ComponentWsResponse.parser()); - serviceTester.assertThat(getRequest) - .hasParam(DEPRECATED_PARAM_COMPONENT_ID, VALUE_BASE_COMPONENT_ID) - .hasParam(DEPRECATED_PARAM_COMPONENT_KEY, VALUE_BASE_COMPONENT_KEY) - .hasParam(PARAM_COMPONENT, VALUE_BASE_COMPONENT_KEY) - .hasParam(PARAM_BRANCH, "my_branch") - .hasParam(PARAM_METRIC_KEYS, "ncloc,complexity") - .hasParam(PARAM_ADDITIONAL_FIELDS, "metrics") - .hasParam(PARAM_DEVELOPER_ID, VALUE_DEVELOPER_ID) - .hasParam(PARAM_DEVELOPER_KEY, VALUE_DEVELOPER_KEY) - .andNoOtherParam(); - } - - @Test - public void component_tree() { - ComponentTreeRequest componentTreeRequest = new ComponentTreeRequest() - .setBaseComponentId(VALUE_BASE_COMPONENT_ID) - .setBaseComponentKey(VALUE_BASE_COMPONENT_KEY) - .setComponent(VALUE_BASE_COMPONENT_KEY) - .setBranch("my_branch") - .setMetricKeys(VALUE_METRIC_KEYS) - .setStrategy(VALUE_STRATEGY) - .setQualifiers(VALUE_QUALIFIERS) - .setAdditionalFields(VALUE_ADDITIONAL_FIELDS) - .setSort(VALUE_SORT) - .setAsc(VALUE_ASC) - .setMetricSort(VALUE_METRIC_SORT) - .setPage(VALUE_PAGE) - .setPageSize(VALUE_PAGE_SIZE) - .setQuery(VALUE_QUERY) - .setDeveloperId(VALUE_DEVELOPER_ID) - .setDeveloperKey(VALUE_DEVELOPER_KEY) - .setMetricSortFilter(VALUE_METRIC_SORT_FILTER); - - underTest.componentTree(componentTreeRequest); - GetRequest getRequest = serviceTester.getGetRequest(); - - assertThat(serviceTester.getGetParser()).isSameAs(ComponentTreeWsResponse.parser()); - serviceTester.assertThat(getRequest) - .hasParam(DEPRECATED_PARAM_BASE_COMPONENT_ID, VALUE_BASE_COMPONENT_ID) - .hasParam(DEPRECATED_PARAM_BASE_COMPONENT_KEY, VALUE_BASE_COMPONENT_KEY) - .hasParam(PARAM_COMPONENT, VALUE_BASE_COMPONENT_KEY) - .hasParam(PARAM_BRANCH, "my_branch") - .hasParam(PARAM_METRIC_KEYS, "ncloc,complexity") - .hasParam(PARAM_STRATEGY, VALUE_STRATEGY) - .hasParam(PARAM_QUALIFIERS, "FIL,PRJ") - .hasParam(PARAM_ADDITIONAL_FIELDS, "metrics") - .hasParam("s", "qualifier,metric") - .hasParam("asc", VALUE_ASC) - .hasParam(PARAM_METRIC_SORT, VALUE_METRIC_SORT) - .hasParam("p", VALUE_PAGE) - .hasParam("ps", VALUE_PAGE_SIZE) - .hasParam("q", VALUE_QUERY) - .hasParam(PARAM_DEVELOPER_ID, VALUE_DEVELOPER_ID) - .hasParam(PARAM_DEVELOPER_KEY, VALUE_DEVELOPER_KEY) - .hasParam(PARAM_METRIC_SORT_FILTER, VALUE_METRIC_SORT_FILTER) - .andNoOtherParam(); - } - - @Test - public void search_history() { - SearchHistoryRequest request = SearchHistoryRequest.builder() - .setComponent(VALUE_COMPONENT) - .setBranch("my_branch") - .setMetrics(VALUE_METRICS) - .setFrom(VALUE_FROM) - .setTo(VALUE_TO) - .setPage(VALUE_PAGE) - .setPageSize(VALUE_PAGE_SIZE) - .build(); - - underTest.searchHistory(request); - GetRequest getRequest = serviceTester.getGetRequest(); - - assertThat(serviceTester.getGetParser()).isSameAs(Measures.SearchHistoryResponse.parser()); - serviceTester.assertThat(getRequest) - .hasParam(PARAM_COMPONENT, VALUE_COMPONENT) - .hasParam(PARAM_BRANCH, "my_branch") - .hasParam(PARAM_METRICS, "ncloc,complexity") - .hasParam(PARAM_FROM, VALUE_FROM) - .hasParam(PARAM_TO, VALUE_TO) - .hasParam("p", VALUE_PAGE) - .hasParam("ps", VALUE_PAGE_SIZE) - .andNoOtherParam(); - } - - @Test - public void search() { - SearchRequest request = SearchRequest.builder() - .setProjectKeys(asList("P1", "P2")) - .setMetricKeys(asList("ncloc", "complexity")) - .build(); - - underTest.search(request); - GetRequest getRequest = serviceTester.getGetRequest(); - - assertThat(serviceTester.getGetParser()).isSameAs(Measures.SearchWsResponse.parser()); - serviceTester.assertThat(getRequest) - .hasParam(PARAM_PROJECT_KEYS, "P1,P2") - .hasParam(PARAM_METRIC_KEYS, "ncloc,complexity") - .andNoOtherParam(); - } -} diff --git a/sonar-ws/src/test/java/org/sonarqube/ws/client/measure/SearchHistoryRequestTest.java b/sonar-ws/src/test/java/org/sonarqube/ws/client/measure/SearchHistoryRequestTest.java deleted file mode 100644 index 85a9dab34e1..00000000000 --- a/sonar-ws/src/test/java/org/sonarqube/ws/client/measure/SearchHistoryRequestTest.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 SonarSource SA - * mailto:info 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.measure; - -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; - -import static java.util.Collections.emptyList; -import static java.util.Collections.singletonList; -import static org.assertj.core.api.Assertions.assertThat; -import static org.sonarqube.ws.client.measure.SearchHistoryRequest.DEFAULT_PAGE_SIZE; -import static org.sonarqube.ws.client.measure.SearchHistoryRequest.MAX_PAGE_SIZE; - -public class SearchHistoryRequestTest { - @Rule - public ExpectedException expectedException = ExpectedException.none(); - - private SearchHistoryRequest.Builder underTest = SearchHistoryRequest.builder(); - - @Test - public void full_example() { - SearchHistoryRequest result = underTest - .setComponent("C1") - .setBranch("my_branch") - .setMetrics(singletonList("new_lines")) - .setFrom("2017-01-15") - .setTo("2017-01-20") - .setPage(23) - .setPageSize(42) - .build(); - - assertThat(result) - .extracting(SearchHistoryRequest::getComponent, SearchHistoryRequest::getBranch, SearchHistoryRequest::getMetrics, SearchHistoryRequest::getFrom, SearchHistoryRequest::getTo, - SearchHistoryRequest::getPage, SearchHistoryRequest::getPageSize) - .containsExactly("C1", "my_branch", singletonList("new_lines"), "2017-01-15", "2017-01-20", 23, 42); - } - - @Test - public void default_values() { - SearchHistoryRequest result = underTest.setComponent("C1").setMetrics(singletonList("new_lines")).build(); - - assertThat(result.getPage()).isEqualTo(1); - assertThat(result.getPageSize()).isEqualTo(DEFAULT_PAGE_SIZE); - } - - @Test - public void fail_if_no_component() { - expectedException.expect(IllegalArgumentException.class); - expectedException.expectMessage("Component key is required"); - - underTest.setMetrics(singletonList("new_lines")).build(); - } - - @Test - public void fail_if_empty_component() { - expectedException.expect(IllegalArgumentException.class); - expectedException.expectMessage("Component key is required"); - - underTest.setComponent("").setMetrics(singletonList("new_lines")).build(); - } - - @Test - public void fail_if_no_metric() { - expectedException.expect(IllegalArgumentException.class); - expectedException.expectMessage("Metric keys are required"); - - underTest.setComponent("C1").build(); - } - - @Test - public void fail_if_empty_metrics() { - expectedException.expect(IllegalArgumentException.class); - expectedException.expectMessage("Metric keys are required"); - - underTest.setComponent("C1").setMetrics(emptyList()).build(); - } - - @Test - public void fail_if_page_size_greater_than_max_authorized_size() { - expectedException.expect(IllegalArgumentException.class); - expectedException.expectMessage("Page size (1001) must be lower than or equal to 1000"); - - underTest.setComponent("C1").setMetrics(singletonList("violations")).setPageSize(MAX_PAGE_SIZE + 1).build(); - } -} diff --git a/sonar-ws/src/test/java/org/sonarqube/ws/client/measure/SearchRequestTest.java b/sonar-ws/src/test/java/org/sonarqube/ws/client/measure/SearchRequestTest.java deleted file mode 100644 index 90c36dc7ad5..00000000000 --- a/sonar-ws/src/test/java/org/sonarqube/ws/client/measure/SearchRequestTest.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 SonarSource SA - * mailto:info 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.measure; - -import java.util.stream.Collectors; -import java.util.stream.IntStream; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; - -import static java.util.Collections.emptyList; -import static java.util.Collections.singletonList; -import static org.assertj.core.api.Assertions.assertThat; - -public class SearchRequestTest { - - @Rule - public ExpectedException expectedException = ExpectedException.none(); - - SearchRequest.Builder underTest = SearchRequest.builder(); - - @Test - public void create_request() { - SearchRequest result = underTest - .setMetricKeys(singletonList("metric")) - .setProjectKeys(singletonList("key")) - .build(); - - assertThat(result.getMetricKeys()).containsExactly("metric"); - assertThat(result.getProjectKeys()).containsExactly("key"); - } - - @Test - public void create_request_with_100_keys() { - SearchRequest result = underTest - .setMetricKeys(singletonList("metric")) - .setProjectKeys(IntStream.rangeClosed(1, 100).mapToObj(Integer::toString).collect(Collectors.toList())) - .build(); - - assertThat(result.getProjectKeys()).hasSize(100); - } - - @Test - public void fail_when_non_null_metric_keys() { - expectExceptionOnMetricKeys(); - - underTest.setMetricKeys(null).build(); - } - - @Test - public void fail_when_non_empty_metric_keys() { - expectExceptionOnMetricKeys(); - - underTest.setMetricKeys(emptyList()).build(); - } - - @Test - public void fail_when_unset_metric_keys() { - expectExceptionOnMetricKeys(); - - underTest.build(); - } - - @Test - public void fail_when_component_keys_is_empty() { - expectExceptionOnComponents(); - - underTest - .setMetricKeys(singletonList("metric")) - .setProjectKeys(emptyList()) - .build(); - } - - @Test - public void fail_when_component_keys_contains_more_than_100_keys() { - expectedException.expect(IllegalArgumentException.class); - expectedException.expectMessage("101 projects provided, more than maximum authorized (100)"); - - underTest - .setMetricKeys(singletonList("metric")) - .setProjectKeys(IntStream.rangeClosed(1, 101).mapToObj(Integer::toString).collect(Collectors.toList())) - .build(); - } - - private void expectExceptionOnMetricKeys() { - expectedException.expect(IllegalArgumentException.class); - expectedException.expectMessage("Metric keys must be provided"); - } - - private void expectExceptionOnComponents() { - expectedException.expect(IllegalArgumentException.class); - expectedException.expectMessage("Project keys must be provided"); - } -} |