aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorTeryk Bellahsene <teryk.bellahsene@sonarsource.com>2015-05-27 18:41:25 +0200
committerTeryk Bellahsene <teryk.bellahsene@sonarsource.com>2015-05-27 18:42:11 +0200
commitb4d6096122c9a76d29f221fe50b71848b2d23605 (patch)
treef04fa6a708c804005ea8337646e72a961eadeb55 /server
parent4626491b61aa5fa33d39e5c0cf8ece638d68dd45 (diff)
downloadsonarqube-b4d6096122c9a76d29f221fe50b71848b2d23605.tar.gz
sonarqube-b4d6096122c9a76d29f221fe50b71848b2d23605.zip
refactoring - WS parameters in one place WebService.Param.XXX
Diffstat (limited to 'server')
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/component/ws/ResourcesWs.java11
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/issue/IssueQueryService.java6
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/rule/ws/SearchAction.java39
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/search/ws/SearchOptions.java23
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/component/ws/SearchActionTest.java7
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ChangelogActionTest.java12
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/QProfilesWsMediumTest.java8
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/QProfilesWsTest.java3
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/SearchActionTest.java5
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/rule/RubyRuleServiceTest.java5
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/rule/ws/RuleMappingTest.java41
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/rule/ws/RulesWsMediumTest.java75
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/search/ws/SearchOptionsTest.java35
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/user/ws/GroupsActionTest.java7
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/user/ws/SearchActionTest.java13
15 files changed, 138 insertions, 152 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/component/ws/ResourcesWs.java b/server/sonar-server/src/main/java/org/sonar/server/component/ws/ResourcesWs.java
index 7c6eaee9b76..a3d65cac902 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/component/ws/ResourcesWs.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/component/ws/ResourcesWs.java
@@ -119,6 +119,7 @@ public class ResourcesWs implements WebService {
NewAction action = controller.createAction("search")
.setDescription("Search for components")
.setSince("3.3")
+ .addPagingParams(10)
.setInternal(true)
.setHandler(RailsHandler.INSTANCE)
.setResponseExample(Resources.getResource(this.getClass(), "resources-example-search.json"));
@@ -144,16 +145,6 @@ public class ResourcesWs implements WebService {
.setDescription("If 's2', then it will return a select2 compatible format")
.setExampleValue("s2");
- action.createParam("p")
- .setDescription("Page index")
- .setDefaultValue("1")
- .setExampleValue("2");
-
- action.createParam("ps")
- .setDescription("Page size")
- .setDefaultValue("10")
- .setExampleValue("15");
-
RailsHandler.addJsonOnlyFormatParam(action);
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/IssueQueryService.java b/server/sonar-server/src/main/java/org/sonar/server/issue/IssueQueryService.java
index 8fc90b871d3..6396e61a71d 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/issue/IssueQueryService.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/issue/IssueQueryService.java
@@ -38,6 +38,7 @@ import org.sonar.api.server.ServerSide;
import org.sonar.api.resources.Qualifiers;
import org.sonar.api.rule.RuleKey;
import org.sonar.api.server.ws.Request;
+import org.sonar.api.server.ws.WebService;
import org.sonar.api.utils.System2;
import org.sonar.api.web.UserRole;
import org.sonar.core.component.ComponentDto;
@@ -45,7 +46,6 @@ import org.sonar.core.persistence.DbSession;
import org.sonar.server.component.ComponentService;
import org.sonar.server.db.DbClient;
import org.sonar.server.issue.filter.IssueFilterParameters;
-import org.sonar.server.rule.ws.SearchAction;
import org.sonar.server.user.UserSession;
import org.sonar.server.util.RubyUtils;
@@ -196,10 +196,10 @@ public class IssueQueryService {
request.paramAsStrings(IssueFilterParameters.FILE_UUIDS),
request.paramAsStrings(IssueFilterParameters.AUTHORS));
- String sort = request.param(SearchAction.PARAM_SORT);
+ String sort = request.param(WebService.Param.SORT);
if (!Strings.isNullOrEmpty(sort)) {
builder.sort(sort);
- builder.asc(request.paramAsBoolean(SearchAction.PARAM_ASCENDING));
+ builder.asc(request.paramAsBoolean(WebService.Param.ASCENDING));
}
return builder.build();
diff --git a/server/sonar-server/src/main/java/org/sonar/server/rule/ws/SearchAction.java b/server/sonar-server/src/main/java/org/sonar/server/rule/ws/SearchAction.java
index 2ee7424a24c..e840173fb94 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/rule/ws/SearchAction.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/rule/ws/SearchAction.java
@@ -40,6 +40,7 @@ import org.sonar.api.server.debt.DebtCharacteristic;
import org.sonar.api.server.ws.Request;
import org.sonar.api.server.ws.Response;
import org.sonar.api.server.ws.WebService;
+import org.sonar.api.server.ws.WebService.Param;
import org.sonar.api.utils.text.JsonWriter;
import org.sonar.core.qualityprofile.db.QualityProfileDto;
import org.sonar.server.qualityprofile.ActiveRule;
@@ -52,7 +53,6 @@ import org.sonar.server.search.FacetValue;
import org.sonar.server.search.QueryContext;
import org.sonar.server.search.Result;
import org.sonar.server.search.ws.SearchOptions;
-import org.sonar.server.search.ws.SearchRequestHandler;
import org.sonar.server.user.UserSession;
/**
@@ -77,13 +77,6 @@ public class SearchAction implements RulesWsAction, org.sonar.api.server.ws.Requ
public static final String PARAM_IS_TEMPLATE = "is_template";
public static final String PARAM_TEMPLATE_KEY = "template_key";
- public static final String PARAM_PAGE = "p";
- public static final String PARAM_PAGE_SIZE = "ps";
- public static final String PARAM_FIELDS = "f";
- public static final String PARAM_SORT = "s";
- public static final String PARAM_ASCENDING = "asc";
- public static final String PARAM_FACETS = "facets";
-
private static final Collection<String> DEFAULT_FACETS = ImmutableSet.of(PARAM_LANGUAGES, PARAM_REPOSITORIES, "tags");
private final RuleService ruleService;
@@ -105,7 +98,7 @@ public class SearchAction implements RulesWsAction, org.sonar.api.server.ws.Requ
.setHandler(this);
Collection<String> possibleFacets = possibleFacets();
- WebService.NewParam paramFacets = action.createParam(PARAM_FACETS)
+ WebService.NewParam paramFacets = action.createParam(Param.FACETS)
.setDescription("Comma-separated list of the facets to be computed. No facet is computed by default.")
.setPossibleValues(possibleFacets);
if (possibleFacets != null && possibleFacets.size() > 1) {
@@ -114,7 +107,7 @@ public class SearchAction implements RulesWsAction, org.sonar.api.server.ws.Requ
}
Collection<String> possibleFields = possibleFields();
- WebService.NewParam paramFields = action.createParam(PARAM_FIELDS)
+ WebService.NewParam paramFields = action.createParam(Param.FIELDS)
.setDescription("Comma-separated list of the fields to be returned in response. All the fields are returned by default.")
.setPossibleValues(possibleFields);
if (possibleFields != null && possibleFields.size() > 1) {
@@ -142,8 +135,8 @@ public class SearchAction implements RulesWsAction, org.sonar.api.server.ws.Requ
protected void writeStatistics(JsonWriter json, Result searchResult, QueryContext context) {
json.prop("total", searchResult.getTotal());
- json.prop(SearchAction.PARAM_PAGE, context.getPage());
- json.prop(SearchAction.PARAM_PAGE_SIZE, context.getLimit());
+ json.prop(Param.PAGE, context.getPage());
+ json.prop(Param.PAGE_SIZE, context.getLimit());
}
protected void doDefinition(WebService.NewAction action) {
@@ -175,7 +168,7 @@ public class SearchAction implements RulesWsAction, org.sonar.api.server.ws.Requ
*/
public static void defineRuleSearchParameters(WebService.NewAction action) {
action
- .createParam(SearchOptions.PARAM_TEXT_QUERY)
+ .createParam(Param.TEXT_QUERY)
.setDescription("UTF-8 search query")
.setExampleValue("xpath");
@@ -265,7 +258,7 @@ public class SearchAction implements RulesWsAction, org.sonar.api.server.ws.Requ
.setExampleValue("java:S001");
action
- .createParam(SearchOptions.PARAM_SORT)
+ .createParam(Param.SORT)
.setDescription("Sort field")
.setPossibleValues(RuleNormalizer.RuleField.NAME.field(),
RuleNormalizer.RuleField.UPDATED_AT.field(),
@@ -274,14 +267,14 @@ public class SearchAction implements RulesWsAction, org.sonar.api.server.ws.Requ
.setExampleValue(RuleNormalizer.RuleField.NAME.field());
action
- .createParam(SearchOptions.PARAM_ASCENDING)
+ .createParam(Param.ASCENDING)
.setDescription("Ascending sort")
.setBooleanPossibleValues()
.setDefaultValue(true);
}
public static RuleQuery createRuleQuery(RuleQuery query, Request request) {
- query.setQueryText(request.param(SearchOptions.PARAM_TEXT_QUERY));
+ query.setQueryText(request.param(Param.TEXT_QUERY));
query.setSeverities(request.paramAsStrings(PARAM_SEVERITIES));
query.setRepositories(request.paramAsStrings(PARAM_REPOSITORIES));
query.setAvailableSince(request.paramAsDate(PARAM_AVAILABLE_SINCE));
@@ -298,10 +291,10 @@ public class SearchAction implements RulesWsAction, org.sonar.api.server.ws.Requ
query.setTemplateKey(request.param(PARAM_TEMPLATE_KEY));
query.setKey(request.param(PARAM_KEY));
- String sortParam = request.param(SearchOptions.PARAM_SORT);
+ String sortParam = request.param(Param.SORT);
if (sortParam != null) {
query.setSortField(RuleNormalizer.RuleField.of(sortParam));
- query.setAscendingSort(request.mandatoryParamAsBoolean(SearchOptions.PARAM_ASCENDING));
+ query.setAscendingSort(request.mandatoryParamAsBoolean(Param.ASCENDING));
}
return query;
}
@@ -330,16 +323,16 @@ public class SearchAction implements RulesWsAction, org.sonar.api.server.ws.Requ
}
private QueryContext loadCommonContext(Request request) {
- int pageSize = request.mandatoryParamAsInt(SearchAction.PARAM_PAGE_SIZE);
- QueryContext context = new QueryContext(userSession).addFieldsToReturn(request.paramAsStrings(SearchAction.PARAM_FIELDS));
- List<String> facets = request.paramAsStrings(SearchAction.PARAM_FACETS);
+ int pageSize = request.mandatoryParamAsInt(Param.PAGE_SIZE);
+ QueryContext context = new QueryContext(userSession).addFieldsToReturn(request.paramAsStrings(Param.FIELDS));
+ List<String> facets = request.paramAsStrings(Param.FACETS);
if (facets != null) {
context.addFacets(facets);
}
if (pageSize < 1) {
- context.setPage(request.mandatoryParamAsInt(SearchAction.PARAM_PAGE), 0).setMaxLimit();
+ context.setPage(request.mandatoryParamAsInt(Param.PAGE), 0).setMaxLimit();
} else {
- context.setPage(request.mandatoryParamAsInt(SearchAction.PARAM_PAGE), pageSize);
+ context.setPage(request.mandatoryParamAsInt(Param.PAGE), pageSize);
}
return context;
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/search/ws/SearchOptions.java b/server/sonar-server/src/main/java/org/sonar/server/search/ws/SearchOptions.java
index e162db5d59b..5ee8d82aa96 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/search/ws/SearchOptions.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/search/ws/SearchOptions.java
@@ -38,13 +38,6 @@ import java.util.List;
*/
public class SearchOptions {
- public static final String PARAM_TEXT_QUERY = "q";
- public static final String PARAM_PAGE = "p";
- public static final String PARAM_PAGE_SIZE = "ps";
- public static final String PARAM_FIELDS = "f";
- public static final String PARAM_SORT = "s";
- public static final String PARAM_ASCENDING = "asc";
-
private int pageSize;
private int page;
private List<String> fields;
@@ -88,8 +81,8 @@ public class SearchOptions {
public SearchOptions writeStatistics(JsonWriter json, Result searchResult) {
json.prop("total", searchResult.getTotal());
- json.prop(PARAM_PAGE, page);
- json.prop(PARAM_PAGE_SIZE, pageSize);
+ json.prop(WebService.Param.PAGE, page);
+ json.prop(WebService.Param.PAGE_SIZE, pageSize);
return this;
}
@@ -97,18 +90,18 @@ public class SearchOptions {
SearchOptions options = new SearchOptions();
// both parameters have default values
- options.setPage(request.mandatoryParamAsInt(PARAM_PAGE));
- options.setPageSize(request.mandatoryParamAsInt(PARAM_PAGE_SIZE));
+ options.setPage(request.mandatoryParamAsInt(WebService.Param.PAGE));
+ options.setPageSize(request.mandatoryParamAsInt(WebService.Param.PAGE_SIZE));
// optional field
- options.setFields(request.paramAsStrings(PARAM_FIELDS));
+ options.setFields(request.paramAsStrings(WebService.Param.FIELDS));
return options;
}
public static void defineFieldsParam(WebService.NewAction action, @Nullable Collection<String> possibleFields) {
WebService.NewParam newParam = action
- .createParam(PARAM_FIELDS)
+ .createParam(WebService.Param.FIELDS)
.setDescription("Comma-separated list of the fields to be returned in response. All the fields are returned by default.")
.setPossibleValues(possibleFields);
if (possibleFields != null && possibleFields.size() > 1) {
@@ -119,13 +112,13 @@ public class SearchOptions {
public static void definePageParams(WebService.NewAction action) {
action
- .createParam(PARAM_PAGE)
+ .createParam(WebService.Param.PAGE)
.setDescription("1-based page number")
.setExampleValue("42")
.setDefaultValue("1");
action
- .createParam(PARAM_PAGE_SIZE)
+ .createParam(WebService.Param.PAGE_SIZE)
.setDescription("Page size. Must be greater than 0.")
.setExampleValue("20")
.setDefaultValue(String.valueOf(QueryContext.DEFAULT_LIMIT));
diff --git a/server/sonar-server/src/test/java/org/sonar/server/component/ws/SearchActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/component/ws/SearchActionTest.java
index 7e3a0766895..e32288433bd 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/component/ws/SearchActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/component/ws/SearchActionTest.java
@@ -25,6 +25,7 @@ import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
+import org.sonar.api.server.ws.WebService.Param;
import org.sonar.api.web.UserRole;
import org.sonar.core.persistence.DbTester;
import org.sonar.core.user.AuthorizationDao;
@@ -90,7 +91,8 @@ public class SearchActionTest {
dbTester.prepareDbUnit(getClass(), "shared.xml");
userSessionRule.login("john").addProjectUuidPermissions(UserRole.USER, "EFGH");
- WsTester.TestRequest request = tester.newGetRequest("api/components", "search").setParam("componentUuid", "EFGH").setParam("q", "st").setParam("p", "2").setParam("ps", "1");
+ WsTester.TestRequest request = tester.newGetRequest("api/components", "search").setParam("componentUuid", "EFGH").setParam("q", "st").setParam(Param.PAGE, "2")
+ .setParam(Param.PAGE_SIZE, "1");
request.execute().assertJson(getClass(), "return_paged_result.json");
}
@@ -99,7 +101,8 @@ public class SearchActionTest {
dbTester.prepareDbUnit(getClass(), "shared.xml");
userSessionRule.login("john").addProjectUuidPermissions(UserRole.USER, "EFGH");
- WsTester.TestRequest request = tester.newGetRequest("api/components", "search").setParam("componentUuid", "EFGH").setParam("q", "st").setParam("p", "1").setParam("ps", "1");
+ WsTester.TestRequest request = tester.newGetRequest("api/components", "search").setParam("componentUuid", "EFGH").setParam("q", "st").setParam(Param.PAGE, "1")
+ .setParam(Param.PAGE_SIZE, "1");
request.execute().assertJson(getClass(), "return_only_first_page.json");
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ChangelogActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ChangelogActionTest.java
index 3aaf7638a58..7862c75fb3e 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ChangelogActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ChangelogActionTest.java
@@ -20,6 +20,8 @@
package org.sonar.server.qualityprofile.ws;
import com.google.common.collect.Maps;
+import java.util.Date;
+import java.util.Map;
import org.joda.time.DateTime;
import org.junit.After;
import org.junit.Before;
@@ -27,6 +29,7 @@ import org.junit.ClassRule;
import org.junit.Test;
import org.sonar.api.config.Settings;
import org.sonar.api.rule.Severity;
+import org.sonar.api.server.ws.WebService.Param;
import org.sonar.api.utils.DateUtils;
import org.sonar.api.utils.System2;
import org.sonar.api.utils.internal.Uuids;
@@ -53,9 +56,6 @@ import org.sonar.server.rule.db.RuleDao;
import org.sonar.server.user.db.UserDao;
import org.sonar.server.ws.WsTester;
-import java.util.Date;
-import java.util.Map;
-
import static org.mockito.Mockito.mock;
import static org.sonar.server.qualityprofile.QProfileTesting.XOO_P1_KEY;
@@ -172,11 +172,11 @@ public class ChangelogActionTest {
Date nearest = new Date(1_500_000_100_000L);
createActivity(login, ActiveRuleChange.Type.ACTIVATED, ActiveRuleKey.of(XOO_P1_KEY, RuleTesting.XOO_X1), Severity.CRITICAL, nearest, "max", "20");
- wsTester.newGetRequest(QProfilesWs.API_ENDPOINT, "changelog").setParam("profileKey", XOO_P1_KEY).setParam("ps", "1")
+ wsTester.newGetRequest(QProfilesWs.API_ENDPOINT, "changelog").setParam("profileKey", XOO_P1_KEY).setParam(Param.PAGE_SIZE, "1")
.execute().assertJson(getClass(), "changelog_page1.json");
- wsTester.newGetRequest(QProfilesWs.API_ENDPOINT, "changelog").setParam("profileKey", XOO_P1_KEY).setParam("ps", "1").setParam("p", "2")
+ wsTester.newGetRequest(QProfilesWs.API_ENDPOINT, "changelog").setParam("profileKey", XOO_P1_KEY).setParam(Param.PAGE_SIZE, "1").setParam(Param.PAGE, "2")
.execute().assertJson(getClass(), "changelog_page2.json");
- wsTester.newGetRequest(QProfilesWs.API_ENDPOINT, "changelog").setParam("profileKey", XOO_P1_KEY).setParam("ps", "1").setParam("p", "3")
+ wsTester.newGetRequest(QProfilesWs.API_ENDPOINT, "changelog").setParam("profileKey", XOO_P1_KEY).setParam(Param.PAGE_SIZE, "1").setParam(Param.PAGE, "3")
.execute().assertJson(getClass(), "changelog_page3.json");
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/QProfilesWsMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/QProfilesWsMediumTest.java
index 7af3fba73e6..64b7f15e42a 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/QProfilesWsMediumTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/QProfilesWsMediumTest.java
@@ -28,6 +28,7 @@ import org.junit.Test;
import org.sonar.api.rule.RuleKey;
import org.sonar.api.rule.RuleStatus;
import org.sonar.api.rule.Severity;
+import org.sonar.api.server.ws.WebService;
import org.sonar.core.component.ComponentDto;
import org.sonar.core.permission.GlobalPermissions;
import org.sonar.core.persistence.DbSession;
@@ -46,7 +47,6 @@ import org.sonar.server.rule.index.RuleIndex;
import org.sonar.server.rule.index.RuleQuery;
import org.sonar.server.rule.ws.SearchAction;
import org.sonar.server.search.QueryContext;
-import org.sonar.server.search.ws.SearchOptions;
import org.sonar.server.tester.ServerTester;
import org.sonar.server.tester.UserSessionRule;
import org.sonar.server.ws.WsTester;
@@ -169,7 +169,7 @@ public class QProfilesWsMediumTest {
// 1. Deactivate Rule
WsTester.TestRequest request = wsTester.newPostRequest(QProfilesWs.API_ENDPOINT, BulkRuleActivationActions.BULK_DEACTIVATE_ACTION);
request.setParam(RuleActivationActions.PROFILE_KEY, profile.getKey().toString());
- request.setParam(SearchOptions.PARAM_TEXT_QUERY, "hello");
+ request.setParam(WebService.Param.TEXT_QUERY, "hello");
WsTester.Result result = request.execute();
session.clearCache();
@@ -305,7 +305,7 @@ public class QProfilesWsMediumTest {
// 1. Activate Rule with query returning 0 hits
WsTester.TestRequest request = wsTester.newPostRequest(QProfilesWs.API_ENDPOINT, BulkRuleActivationActions.BULK_ACTIVATE_ACTION);
request.setParam(RuleActivationActions.PROFILE_KEY, profile.getKey().toString());
- request.setParam(SearchOptions.PARAM_TEXT_QUERY, "php");
+ request.setParam(WebService.Param.TEXT_QUERY, "php");
WsTester.Result result = request.execute();
session.clearCache();
@@ -315,7 +315,7 @@ public class QProfilesWsMediumTest {
// 1. Activate Rule with query returning 1 hits
request = wsTester.newPostRequest(QProfilesWs.API_ENDPOINT, BulkRuleActivationActions.BULK_ACTIVATE_ACTION);
request.setParam(RuleActivationActions.PROFILE_KEY, profile.getKey().toString());
- request.setParam(SearchOptions.PARAM_TEXT_QUERY, "world");
+ request.setParam(WebService.Param.TEXT_QUERY, "world");
result = request.execute();
session.commit();
diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/QProfilesWsTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/QProfilesWsTest.java
index a27423428e0..ca2963ab26e 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/QProfilesWsTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/QProfilesWsTest.java
@@ -30,6 +30,7 @@ import org.sonar.api.profiles.RulesProfile;
import org.sonar.api.resources.Language;
import org.sonar.api.resources.Languages;
import org.sonar.api.server.ws.WebService;
+import org.sonar.api.server.ws.WebService.Param;
import org.sonar.api.utils.ValidationMessages;
import org.sonar.server.language.LanguageTesting;
import org.sonar.server.qualityprofile.QProfileExporters;
@@ -123,7 +124,7 @@ public class QProfilesWsTest {
assertThat(search.isPost()).isFalse();
assertThat(search.params()).hasSize(2);
assertThat(search.param("language").possibleValues()).containsOnly(xoo1Key, xoo2Key);
- assertThat(search.param("f").possibleValues())
+ assertThat(search.param(Param.FIELDS).possibleValues())
.containsOnly("key", "name", "language", "languageName", "isInherited", "parentKey", "parentName", "isDefault", "activeRuleCount", "projectCount");
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/SearchActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/SearchActionTest.java
index 28650acc86a..7b538b1fb4e 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/SearchActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/SearchActionTest.java
@@ -26,6 +26,7 @@ import org.junit.ClassRule;
import org.junit.Test;
import org.sonar.api.resources.Language;
import org.sonar.api.resources.Languages;
+import org.sonar.api.server.ws.WebService.Param;
import org.sonar.api.utils.System2;
import org.sonar.core.persistence.DbSession;
import org.sonar.core.persistence.DbTester;
@@ -116,12 +117,12 @@ public class SearchActionTest {
);
session.commit();
- tester.newGetRequest("api/qualityprofiles", "search").setParam("f", "key,language").execute().assertJson(this.getClass(), "search_fields.json");
+ tester.newGetRequest("api/qualityprofiles", "search").setParam(Param.FIELDS, "key,language").execute().assertJson(this.getClass(), "search_fields.json");
}
@Test(expected = IllegalArgumentException.class)
public void fail_on_unknown_fields() throws Exception {
- tester.newGetRequest("api/qualityprofiles", "search").setParam("f", "polop").execute();
+ tester.newGetRequest("api/qualityprofiles", "search").setParam(Param.FIELDS, "polop").execute();
}
@Test
diff --git a/server/sonar-server/src/test/java/org/sonar/server/rule/RubyRuleServiceTest.java b/server/sonar-server/src/test/java/org/sonar/server/rule/RubyRuleServiceTest.java
index 7ffc74e00b9..40bedc5965d 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/rule/RubyRuleServiceTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/rule/RubyRuleServiceTest.java
@@ -32,6 +32,7 @@ import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.sonar.api.rule.RuleKey;
import org.sonar.api.rule.RuleStatus;
+import org.sonar.api.server.ws.WebService.Param;
import org.sonar.server.paging.PagedResult;
import org.sonar.server.rule.index.RuleQuery;
import org.sonar.server.search.QueryContext;
@@ -92,7 +93,7 @@ public class RubyRuleServiceTest {
params.put("tags", "tag1,tag2");
params.put("debtCharacteristics", "char1,char2");
params.put("hasDebtCharacteristic", "true");
- params.put("p", "1");
+ params.put(Param.PAGE, "1");
params.put("pageSize", "40");
service.find(params);
@@ -134,7 +135,7 @@ public class RubyRuleServiceTest {
when(ruleService.search(any(RuleQuery.class), any(QueryContext.class))).thenReturn(mock(Result.class));
HashMap<String, Object> params = newHashMap();
- params.put("p", "1");
+ params.put(Param.PAGE, "1");
service.find(params);
verify(ruleService).search(ruleQueryCaptor.capture(), optionsCaptor.capture());
diff --git a/server/sonar-server/src/test/java/org/sonar/server/rule/ws/RuleMappingTest.java b/server/sonar-server/src/test/java/org/sonar/server/rule/ws/RuleMappingTest.java
index 676e034d746..ec6e1b4f84d 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/rule/ws/RuleMappingTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/rule/ws/RuleMappingTest.java
@@ -23,6 +23,7 @@ import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.resources.Languages;
import org.sonar.api.server.debt.DebtModel;
+import org.sonar.api.server.ws.WebService.Param;
import org.sonar.api.server.ws.internal.SimpleGetRequest;
import org.sonar.server.rule.index.RuleNormalizer;
import org.sonar.server.search.QueryContext;
@@ -45,8 +46,8 @@ public class RuleMappingTest {
public void toQueryOptions_load_all_fields() {
RuleMapping mapping = new RuleMapping(languages, macroInterpreter, debtModel, userSessionRule);
SimpleGetRequest request = new SimpleGetRequest();
- request.setParam("p", "1");
- request.setParam("ps", "10");
+ request.setParam(Param.PAGE, "1");
+ request.setParam(Param.PAGE_SIZE, "10");
QueryContext queryContext = mapping.newQueryOptions(SearchOptions.create(request));
assertThat(queryContext.getFieldsToReturn()).isEmpty();
@@ -56,9 +57,9 @@ public class RuleMappingTest {
public void toQueryOptions_load_only_few_simple_fields() {
RuleMapping mapping = new RuleMapping(languages, macroInterpreter, debtModel, userSessionRule);
SimpleGetRequest request = new SimpleGetRequest();
- request.setParam("p", "1");
- request.setParam("ps", "10");
- request.setParam("f", "repo,name,lang");
+ request.setParam(Param.PAGE, "1");
+ request.setParam(Param.PAGE_SIZE, "10");
+ request.setParam(Param.FIELDS, "repo,name,lang");
QueryContext queryContext = mapping.newQueryOptions(SearchOptions.create(request));
assertThat(queryContext.getFieldsToReturn()).containsOnly(
@@ -71,9 +72,9 @@ public class RuleMappingTest {
public void toQueryOptions_langName_requires_lang() {
RuleMapping mapping = new RuleMapping(languages, macroInterpreter, debtModel, userSessionRule);
SimpleGetRequest request = new SimpleGetRequest();
- request.setParam("p", "1");
- request.setParam("ps", "10");
- request.setParam("f", "langName");
+ request.setParam(Param.PAGE, "1");
+ request.setParam(Param.PAGE_SIZE, "10");
+ request.setParam(Param.FIELDS, "langName");
QueryContext queryContext = mapping.newQueryOptions(SearchOptions.create(request));
assertThat(queryContext.getFieldsToReturn()).containsOnly(RuleNormalizer.RuleField.LANGUAGE.field());
@@ -83,9 +84,9 @@ public class RuleMappingTest {
public void toQueryOptions_debt_requires_group_of_fields() {
RuleMapping mapping = new RuleMapping(languages, macroInterpreter, debtModel, userSessionRule);
SimpleGetRequest request = new SimpleGetRequest();
- request.setParam("p", "1");
- request.setParam("ps", "10");
- request.setParam("f", "debtRemFn");
+ request.setParam(Param.PAGE, "1");
+ request.setParam(Param.PAGE_SIZE, "10");
+ request.setParam(Param.FIELDS, "debtRemFn");
QueryContext queryContext = mapping.newQueryOptions(SearchOptions.create(request));
assertThat(queryContext.getFieldsToReturn()).containsOnly(
@@ -98,9 +99,9 @@ public class RuleMappingTest {
public void toQueryOptions_html_note_requires_markdown_note() {
RuleMapping mapping = new RuleMapping(languages, macroInterpreter, debtModel, userSessionRule);
SimpleGetRequest request = new SimpleGetRequest();
- request.setParam("p", "1");
- request.setParam("ps", "10");
- request.setParam("f", "htmlNote");
+ request.setParam(Param.PAGE, "1");
+ request.setParam(Param.PAGE_SIZE, "10");
+ request.setParam(Param.FIELDS, "htmlNote");
QueryContext queryContext = mapping.newQueryOptions(SearchOptions.create(request));
assertThat(queryContext.getFieldsToReturn()).containsOnly(RuleNormalizer.RuleField.NOTE.field());
@@ -110,9 +111,9 @@ public class RuleMappingTest {
public void toQueryOptions_debt_characteristics() {
RuleMapping mapping = new RuleMapping(languages, macroInterpreter, debtModel, userSessionRule);
SimpleGetRequest request = new SimpleGetRequest();
- request.setParam("p", "1");
- request.setParam("ps", "10");
- request.setParam("f", "debtChar");
+ request.setParam(Param.PAGE, "1");
+ request.setParam(Param.PAGE_SIZE, "10");
+ request.setParam(Param.FIELDS, "debtChar");
QueryContext queryContext = mapping.newQueryOptions(SearchOptions.create(request));
assertThat(queryContext.getFieldsToReturn()).containsOnly(
@@ -123,9 +124,9 @@ public class RuleMappingTest {
public void toQueryOptions_debt_overloaded() {
RuleMapping mapping = new RuleMapping(languages, macroInterpreter, debtModel, userSessionRule);
SimpleGetRequest request = new SimpleGetRequest();
- request.setParam("p", "1");
- request.setParam("ps", "10");
- request.setParam("f", "debtOverloaded");
+ request.setParam(Param.PAGE, "1");
+ request.setParam(Param.PAGE_SIZE, "10");
+ request.setParam(Param.FIELDS, "debtOverloaded");
QueryContext queryContext = mapping.newQueryOptions(SearchOptions.create(request));
assertThat(queryContext.getFieldsToReturn()).containsOnly(
diff --git a/server/sonar-server/src/test/java/org/sonar/server/rule/ws/RulesWsMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/rule/ws/RulesWsMediumTest.java
index 31e049b67fb..6b5b9a57962 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/rule/ws/RulesWsMediumTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/rule/ws/RulesWsMediumTest.java
@@ -50,7 +50,6 @@ import org.sonar.server.qualityprofile.db.ActiveRuleDao;
import org.sonar.server.rule.RuleTesting;
import org.sonar.server.rule.db.RuleDao;
import org.sonar.server.rule.index.RuleNormalizer;
-import org.sonar.server.search.ws.SearchOptions;
import org.sonar.server.tester.ServerTester;
import org.sonar.server.tester.UserSessionRule;
import org.sonar.server.ws.WsTester;
@@ -138,7 +137,7 @@ public class RulesWsMediumTest {
@Test
public void search_no_rules() throws Exception {
WsTester.TestRequest request = tester.wsTester().newGetRequest(API_ENDPOINT, API_SEARCH_METHOD);
- request.setParam(SearchOptions.PARAM_FIELDS, "actives");
+ request.setParam(WebService.Param.FIELDS, "actives");
WsTester.Result result = request.execute();
result.assertJson(this.getClass(), "search_no_rules.json");
@@ -152,13 +151,13 @@ public class RulesWsMediumTest {
WsTester.TestRequest request = tester.wsTester().newGetRequest(API_ENDPOINT, API_SEARCH_METHOD);
request.setParam(SearchAction.PARAM_KEY, RuleTesting.XOO_X1.toString());
- request.setParam(SearchOptions.PARAM_FIELDS, "actives");
+ request.setParam(WebService.Param.FIELDS, "actives");
WsTester.Result result = request.execute();
result.assertJson("{\"total\":1,\"p\":1,\"ps\":100,\"rules\":[{\"key\":\"xoo:x1\"}]}");
request = tester.wsTester().newGetRequest(API_ENDPOINT, API_SEARCH_METHOD);
request.setParam(SearchAction.PARAM_KEY, RuleKey.of("xoo", "unknown").toString());
- request.setParam(SearchOptions.PARAM_FIELDS, "actives");
+ request.setParam(WebService.Param.FIELDS, "actives");
result = request.execute();
result.assertJson("{\"total\":0,\"p\":1,\"ps\":100,\"rules\":[],\"actives\":{}}");
@@ -182,7 +181,7 @@ public class RulesWsMediumTest {
ruleDao.insert(session, RuleTesting.newXooX2().setDescription("A *Xoo* rule").setDescriptionFormat(Format.MARKDOWN));
session.commit();
- WsTester.TestRequest request = tester.wsTester().newGetRequest(API_ENDPOINT, API_SEARCH_METHOD).setParam(SearchOptions.PARAM_FIELDS, "name,htmlDesc,mdDesc");
+ WsTester.TestRequest request = tester.wsTester().newGetRequest(API_ENDPOINT, API_SEARCH_METHOD).setParam(WebService.Param.FIELDS, "name,htmlDesc,mdDesc");
WsTester.Result result = request.execute();
result.assertJson(getClass(), "search_2_rules_fields.json");
@@ -206,8 +205,8 @@ public class RulesWsMediumTest {
session.commit();
WsTester.TestRequest request = tester.wsTester().newGetRequest(API_ENDPOINT, API_SEARCH_METHOD);
- request.setParam(SearchOptions.PARAM_FIELDS, "debtChar,debtCharName,debtSubChar,debtSubCharName,debtRemFn,debtOverloaded,defaultDebtChar,defaultDebtSubChar,defaultDebtRemFn");
- request.setParam(SearchAction.PARAM_FACETS, "debt_characteristics");
+ request.setParam(WebService.Param.FIELDS, "debtChar,debtCharName,debtSubChar,debtSubCharName,debtRemFn,debtOverloaded,defaultDebtChar,defaultDebtSubChar,defaultDebtRemFn");
+ request.setParam(WebService.Param.FACETS, "debt_characteristics");
WsTester.Result result = request.execute();
result.assertJson(this.getClass(), "search_debt_rule.json");
}
@@ -230,7 +229,7 @@ public class RulesWsMediumTest {
session.commit();
WsTester.TestRequest request = tester.wsTester().newGetRequest(API_ENDPOINT, API_SEARCH_METHOD);
- request.setParam(SearchOptions.PARAM_FIELDS, "debtChar,debtCharName,debtSubChar,debtSubCharName,debtRemFn,debtOverloaded,defaultDebtChar,defaultDebtSubChar,defaultDebtRemFn");
+ request.setParam(WebService.Param.FIELDS, "debtChar,debtCharName,debtSubChar,debtSubCharName,debtRemFn,debtOverloaded,defaultDebtChar,defaultDebtSubChar,defaultDebtRemFn");
WsTester.Result result = request.execute();
result.assertJson(this.getClass(), "search_debt_rules_with_default_and_overridden_debt_values.json");
}
@@ -253,7 +252,7 @@ public class RulesWsMediumTest {
session.commit();
WsTester.TestRequest request = tester.wsTester().newGetRequest(API_ENDPOINT, API_SEARCH_METHOD);
- request.setParam(SearchOptions.PARAM_FIELDS, "debtChar,debtCharName,debtSubChar,debtSubCharName,debtRemFn,debtOverloaded,defaultDebtChar,defaultDebtSubChar,defaultDebtRemFn");
+ request.setParam(WebService.Param.FIELDS, "debtChar,debtCharName,debtSubChar,debtSubCharName,debtRemFn,debtOverloaded,defaultDebtChar,defaultDebtSubChar,defaultDebtRemFn");
WsTester.Result result = request.execute();
result.assertJson(this.getClass(), "search_debt_rules_with_default_linear_offset_and_overridden_constant_debt.json");
}
@@ -276,7 +275,7 @@ public class RulesWsMediumTest {
session.commit();
WsTester.TestRequest request = tester.wsTester().newGetRequest(API_ENDPOINT, API_SEARCH_METHOD);
- request.setParam(SearchOptions.PARAM_FIELDS, "debtChar,debtCharName,debtSubChar,debtSubCharName,debtRemFn,debtOverloaded,defaultDebtChar,defaultDebtSubChar,defaultDebtRemFn");
+ request.setParam(WebService.Param.FIELDS, "debtChar,debtCharName,debtSubChar,debtSubCharName,debtRemFn,debtOverloaded,defaultDebtChar,defaultDebtSubChar,defaultDebtRemFn");
WsTester.Result result = request.execute();
result.assertJson(this.getClass(), "search_debt_rules_with_default_linear_offset_and_overridden_linear_debt.json");
}
@@ -332,9 +331,9 @@ public class RulesWsMediumTest {
session.commit();
WsTester.Result result = tester.wsTester().newGetRequest(API_ENDPOINT, API_SEARCH_METHOD)
- .setParam(SearchOptions.PARAM_FIELDS, "debtChar,debtCharName,debtSubChar,debtSubCharName,debtRemFn,debtOverloaded,defaultDebtChar,defaultDebtSubChar,defaultDebtRemFn")
+ .setParam(WebService.Param.FIELDS, "debtChar,debtCharName,debtSubChar,debtSubCharName,debtRemFn,debtOverloaded,defaultDebtChar,defaultDebtSubChar,defaultDebtRemFn")
.setParam("debt_characteristics", "SOFT_RELIABILITY")
- .setParam(SearchAction.PARAM_FACETS, "debt_characteristics")
+ .setParam(WebService.Param.FACETS, "debt_characteristics")
.execute();
result.assertJson(this.getClass(), "search_debt_rules_sticky.json");
}
@@ -347,7 +346,7 @@ public class RulesWsMediumTest {
session.commit();
WsTester.TestRequest request = tester.wsTester().newGetRequest(API_ENDPOINT, API_SEARCH_METHOD);
- request.setParam(SearchOptions.PARAM_FIELDS, "isTemplate");
+ request.setParam(WebService.Param.FIELDS, "isTemplate");
request.setParam(SearchAction.PARAM_IS_TEMPLATE, "true");
WsTester.Result result = request.execute();
result.assertJson(this.getClass(), "search_template_rules.json");
@@ -361,7 +360,7 @@ public class RulesWsMediumTest {
session.commit();
WsTester.TestRequest request = tester.wsTester().newGetRequest(API_ENDPOINT, API_SEARCH_METHOD);
- request.setParam(SearchOptions.PARAM_FIELDS, "templateKey");
+ request.setParam(WebService.Param.FIELDS, "templateKey");
request.setParam(SearchAction.PARAM_TEMPLATE_KEY, "xoo:x1");
WsTester.Result result = request.execute();
result.assertJson(this.getClass(), "search_rules_from_template_key.json");
@@ -380,9 +379,9 @@ public class RulesWsMediumTest {
session.commit();
WsTester.TestRequest request = tester.wsTester().newGetRequest(API_ENDPOINT, API_SEARCH_METHOD);
- request.setParam(SearchOptions.PARAM_TEXT_QUERY, "x1");
+ request.setParam(WebService.Param.TEXT_QUERY, "x1");
request.setParam(SearchAction.PARAM_ACTIVATION, "true");
- request.setParam(SearchOptions.PARAM_FIELDS, "");
+ request.setParam(WebService.Param.FIELDS, "");
WsTester.Result result = request.execute();
result.assertJson(this.getClass(), "search_active_rules.json");
@@ -409,17 +408,17 @@ public class RulesWsMediumTest {
session.commit();
WsTester.TestRequest request = tester.wsTester().newGetRequest(API_ENDPOINT, API_SEARCH_METHOD);
- request.setParam(SearchOptions.PARAM_TEXT_QUERY, "x1");
+ request.setParam(WebService.Param.TEXT_QUERY, "x1");
request.setParam(SearchAction.PARAM_ACTIVATION, "true");
request.setParam(SearchAction.PARAM_QPROFILE, profile2.getKey());
- request.setParam(SearchOptions.PARAM_FIELDS, "actives");
+ request.setParam(WebService.Param.FIELDS, "actives");
WsTester.Result result = request.execute();
result.assertJson(this.getClass(), "search_profile_active_rules.json");
tester.wsTester().newGetRequest(API_ENDPOINT, API_SEARCH_METHOD)
.setParam(SearchAction.PARAM_ACTIVATION, "true")
.setParam(SearchAction.PARAM_QPROFILE, "unknown_profile")
- .setParam(SearchOptions.PARAM_FIELDS, "actives")
+ .setParam(WebService.Param.FIELDS, "actives")
.execute()
.assertJson(this.getClass(), "search_no_rules.json");
}
@@ -445,10 +444,10 @@ public class RulesWsMediumTest {
session.commit();
WsTester.TestRequest request = tester.wsTester().newGetRequest(API_ENDPOINT, API_SEARCH_METHOD);
- request.setParam(SearchOptions.PARAM_TEXT_QUERY, "x1");
+ request.setParam(WebService.Param.TEXT_QUERY, "x1");
request.setParam(SearchAction.PARAM_ACTIVATION, "true");
request.setParam(SearchAction.PARAM_QPROFILE, profile2.getKey());
- request.setParam(SearchOptions.PARAM_FIELDS, "actives");
+ request.setParam(WebService.Param.FIELDS, "actives");
WsTester.Result result = request.execute();
result.assertJson(this.getClass(), "search_profile_active_rules_inheritance.json");
}
@@ -488,9 +487,9 @@ public class RulesWsMediumTest {
session.commit();
WsTester.TestRequest request = tester.wsTester().newGetRequest(API_ENDPOINT, API_SEARCH_METHOD);
- request.setParam(SearchOptions.PARAM_TEXT_QUERY, "x1");
+ request.setParam(WebService.Param.TEXT_QUERY, "x1");
request.setParam(SearchAction.PARAM_ACTIVATION, "true");
- request.setParam(SearchOptions.PARAM_FIELDS, "params");
+ request.setParam(WebService.Param.FIELDS, "params");
WsTester.Result result = request.execute();
result.assertJson(this.getClass(), "search_active_rules_params.json");
@@ -528,7 +527,7 @@ public class RulesWsMediumTest {
session.commit();
WsTester.TestRequest request = tester.wsTester().newGetRequest(API_ENDPOINT, API_SEARCH_METHOD);
- request.setParam(SearchOptions.PARAM_FIELDS, "htmlNote, mdNote");
+ request.setParam(WebService.Param.FIELDS, "htmlNote, mdNote");
WsTester.Result result = request.execute();
result.assertJson(this.getClass(), "get_note_as_markdown_and_html.json");
}
@@ -545,8 +544,8 @@ public class RulesWsMediumTest {
WsTester.TestRequest request = tester.wsTester().newGetRequest(API_ENDPOINT, API_SEARCH_METHOD);
request.setParam(SearchAction.PARAM_TAGS, "tag1");
- request.setParam(SearchOptions.PARAM_FIELDS, "sysTags, tags");
- request.setParam(SearchAction.PARAM_FACETS, "tags");
+ request.setParam(WebService.Param.FIELDS, "sysTags, tags");
+ request.setParam(WebService.Param.FACETS, "tags");
WsTester.Result result = request.execute();
result.assertJson(this.getClass(), "filter_by_tags.json");
}
@@ -554,14 +553,14 @@ public class RulesWsMediumTest {
@Test
public void severities_facet_should_have_all_severities() throws Exception {
WsTester.TestRequest request = tester.wsTester().newGetRequest(API_ENDPOINT, API_SEARCH_METHOD);
- request.setParam(SearchAction.PARAM_FACETS, "severities");
+ request.setParam(WebService.Param.FACETS, "severities");
request.execute().assertJson(this.getClass(), "severities_facet.json");
}
@Test
public void statuses_facet_should_have_all_statuses_except_removed() throws Exception {
WsTester.TestRequest request = tester.wsTester().newGetRequest(API_ENDPOINT, API_SEARCH_METHOD);
- request.setParam(SearchAction.PARAM_FACETS, "statuses");
+ request.setParam(WebService.Param.FACETS, "statuses");
request.execute().assertJson(this.getClass(), "statuses_facet.json");
}
@@ -574,7 +573,7 @@ public class RulesWsMediumTest {
WsTester.TestRequest request = tester.wsTester().newGetRequest(API_ENDPOINT, API_SEARCH_METHOD);
request.setParam(SearchAction.PARAM_STATUSES, "DEPRECATED");
- request.setParam(SearchAction.PARAM_FACETS, "statuses");
+ request.setParam(WebService.Param.FACETS, "statuses");
request.execute().assertJson(this.getClass(), "statuses_facet_sticky.json");
}
@@ -587,18 +586,18 @@ public class RulesWsMediumTest {
// 1. Sort Name Asc
WsTester.TestRequest request = tester.wsTester().newGetRequest(API_ENDPOINT, API_SEARCH_METHOD);
- request.setParam(SearchOptions.PARAM_FIELDS, "");
- request.setParam(SearchOptions.PARAM_SORT, "name");
- request.setParam(SearchOptions.PARAM_ASCENDING, "true");
+ request.setParam(WebService.Param.FIELDS, "");
+ request.setParam(WebService.Param.SORT, "name");
+ request.setParam(WebService.Param.ASCENDING, "true");
WsTester.Result result = request.execute();
result.assertJson("{\"total\":3,\"p\":1,\"ps\":100,\"rules\":[{\"key\":\"xoo:x2\"},{\"key\":\"xoo:x1\"},{\"key\":\"xoo:x3\"}]}");
// 2. Sort Name DESC
request = tester.wsTester().newGetRequest(API_ENDPOINT, API_SEARCH_METHOD);
- request.setParam(SearchOptions.PARAM_FIELDS, "");
- request.setParam(SearchOptions.PARAM_SORT, RuleNormalizer.RuleField.NAME.field());
- request.setParam(SearchOptions.PARAM_ASCENDING, "false");
+ request.setParam(WebService.Param.FIELDS, "");
+ request.setParam(WebService.Param.SORT, RuleNormalizer.RuleField.NAME.field());
+ request.setParam(WebService.Param.ASCENDING, "false");
result = request.execute();
result.assertJson("{\"total\":3,\"p\":1,\"ps\":100,\"rules\":[{\"key\":\"xoo:x3\"},{\"key\":\"xoo:x1\"},{\"key\":\"xoo:x2\"}]}");
@@ -616,9 +615,9 @@ public class RulesWsMediumTest {
// 1. find today's rules
WsTester.TestRequest request = tester.wsTester().newGetRequest(API_ENDPOINT, API_SEARCH_METHOD);
- request.setParam(SearchOptions.PARAM_FIELDS, "");
+ request.setParam(WebService.Param.FIELDS, "");
request.setParam(SearchAction.PARAM_AVAILABLE_SINCE, DateUtils.formatDate(since));
- request.setParam(SearchOptions.PARAM_SORT, RuleNormalizer.RuleField.KEY.field());
+ request.setParam(WebService.Param.SORT, RuleNormalizer.RuleField.KEY.field());
WsTester.Result result = request.execute();
result.assertJson("{\"total\":2,\"p\":1,\"ps\":100,\"rules\":[{\"key\":\"xoo:x1\"},{\"key\":\"xoo:x2\"}]}");
@@ -628,7 +627,7 @@ public class RulesWsMediumTest {
// 2. no rules since tomorrow
request = tester.wsTester().newGetRequest(API_ENDPOINT, API_SEARCH_METHOD);
- request.setParam(SearchOptions.PARAM_FIELDS, "");
+ request.setParam(WebService.Param.FIELDS, "");
request.setParam(SearchAction.PARAM_AVAILABLE_SINCE, DateUtils.formatDate(c.getTime()));
result = request.execute();
result.assertJson("{\"total\":0,\"p\":1,\"ps\":100,\"rules\":[]}");
diff --git a/server/sonar-server/src/test/java/org/sonar/server/search/ws/SearchOptionsTest.java b/server/sonar-server/src/test/java/org/sonar/server/search/ws/SearchOptionsTest.java
index f30ee445908..462f65e36e1 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/search/ws/SearchOptionsTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/search/ws/SearchOptionsTest.java
@@ -23,6 +23,7 @@ import com.google.common.collect.Lists;
import org.junit.Test;
import org.sonar.api.server.ws.RequestHandler;
import org.sonar.api.server.ws.WebService;
+import org.sonar.api.server.ws.WebService.Param;
import org.sonar.api.server.ws.internal.SimpleGetRequest;
import org.sonar.api.utils.text.JsonWriter;
import org.sonar.server.search.QueryContext;
@@ -40,9 +41,9 @@ public class SearchOptionsTest {
@Test
public void create_from_http_request() {
SimpleGetRequest request = new SimpleGetRequest();
- request.setParam("p", "3");
- request.setParam("ps", "10");
- request.setParam("f", "name,repo");
+ request.setParam(Param.PAGE, "3");
+ request.setParam(Param.PAGE_SIZE, "10");
+ request.setParam(Param.FIELDS, "name,repo");
request.setParam("severities", "BLOCKER");
SearchOptions options = SearchOptions.create(request);
@@ -55,9 +56,9 @@ public class SearchOptionsTest {
@Test
public void hasField() {
SimpleGetRequest request = new SimpleGetRequest();
- request.setParam("p", "3");
- request.setParam("ps", "10");
- request.setParam("f", "name,repo");
+ request.setParam(Param.PAGE, "3");
+ request.setParam(Param.PAGE_SIZE, "10");
+ request.setParam(Param.FIELDS, "name,repo");
SearchOptions options = SearchOptions.create(request);
assertThat(options.hasField("repo")).isTrue();
@@ -67,8 +68,8 @@ public class SearchOptionsTest {
@Test
public void hasField_always_true_by_default() {
SimpleGetRequest request = new SimpleGetRequest();
- request.setParam("p", "3");
- request.setParam("ps", "10");
+ request.setParam(Param.PAGE, "3");
+ request.setParam(Param.PAGE_SIZE, "10");
SearchOptions options = SearchOptions.create(request);
assertThat(options.hasField("repo")).isTrue();
@@ -77,9 +78,9 @@ public class SearchOptionsTest {
@Test
public void hasField_no_if_empty_value() {
SimpleGetRequest request = new SimpleGetRequest();
- request.setParam("p", "3");
- request.setParam("ps", "10");
- request.setParam("f", "");
+ request.setParam(Param.PAGE, "3");
+ request.setParam(Param.PAGE_SIZE, "10");
+ request.setParam(Param.FIELDS, "");
SearchOptions options = SearchOptions.create(request);
assertThat(options.hasField("repo")).isFalse();
@@ -88,9 +89,9 @@ public class SearchOptionsTest {
@Test
public void write_statistics_to_json_response() {
SimpleGetRequest request = new SimpleGetRequest();
- request.setParam("p", "3");
- request.setParam("ps", "10");
- request.setParam("f", "name,repo");
+ request.setParam(Param.PAGE, "3");
+ request.setParam(Param.PAGE_SIZE, "10");
+ request.setParam(Param.FIELDS, "name,repo");
request.setParam("severities", "BLOCKER");
SearchOptions options = SearchOptions.create(request);
@@ -118,7 +119,7 @@ public class SearchOptionsTest {
}.define(context);
WebService.Action searchAction = context.controller("api/foo").action("search");
- WebService.Param param = searchAction.param("f");
+ Param param = searchAction.param(Param.FIELDS);
assertThat(param).isNotNull();
assertThat(param.possibleValues()).containsOnly("name", "lang", "severity");
assertThat(param.exampleValue()).isEqualTo("name,lang");
@@ -138,10 +139,10 @@ public class SearchOptionsTest {
}.define(context);
WebService.Action searchAction = context.controller("api/foo").action("search");
- WebService.Param page = searchAction.param("p");
+ Param page = searchAction.param(Param.PAGE);
assertThat(page).isNotNull();
assertThat(page.defaultValue()).isEqualTo("1");
- WebService.Param pageSize = searchAction.param("ps");
+ Param pageSize = searchAction.param(Param.PAGE_SIZE);
assertThat(pageSize).isNotNull();
assertThat(pageSize.defaultValue()).isEqualTo("" + QueryContext.DEFAULT_LIMIT);
diff --git a/server/sonar-server/src/test/java/org/sonar/server/user/ws/GroupsActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/user/ws/GroupsActionTest.java
index f4537b4ebfb..1764914bd18 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/user/ws/GroupsActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/user/ws/GroupsActionTest.java
@@ -25,6 +25,7 @@ import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Test;
import org.sonar.api.server.ws.WebService;
+import org.sonar.api.server.ws.WebService.Param;
import org.sonar.api.utils.System2;
import org.sonar.core.persistence.DbSession;
import org.sonar.core.persistence.DbTester;
@@ -156,14 +157,14 @@ public class GroupsActionTest {
tester.newGetRequest("api/users", "groups")
.setParam("login", "john")
- .setParam("ps", "1")
+ .setParam(Param.PAGE_SIZE, "1")
.execute()
.assertJson(getClass(), "all_page1.json");
tester.newGetRequest("api/users", "groups")
.setParam("login", "john")
- .setParam("ps", "1")
- .setParam("p", "2")
+ .setParam(Param.PAGE_SIZE, "1")
+ .setParam(Param.PAGE, "2")
.execute()
.assertJson(getClass(), "all_page2.json");
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/user/ws/SearchActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/user/ws/SearchActionTest.java
index d3e8b7d421b..85b5b575321 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/user/ws/SearchActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/user/ws/SearchActionTest.java
@@ -31,6 +31,7 @@ import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.sonar.api.config.Settings;
import org.sonar.api.server.ws.WebService;
+import org.sonar.api.server.ws.WebService.Param;
import org.sonar.api.utils.System2;
import org.sonar.core.permission.GlobalPermissions;
import org.sonar.core.persistence.DbSession;
@@ -125,8 +126,8 @@ public class SearchActionTest {
injectUsers(10);
loginAsAdmin();
- tester.newGetRequest("api/users", "search").setParam("ps", "5").execute().assertJson(getClass(), "page_one.json");
- tester.newGetRequest("api/users", "search").setParam("ps", "5").setParam("p", "2").execute().assertJson(getClass(), "page_two.json");
+ tester.newGetRequest("api/users", "search").setParam(Param.PAGE_SIZE, "5").execute().assertJson(getClass(), "page_one.json");
+ tester.newGetRequest("api/users", "search").setParam(Param.PAGE_SIZE, "5").setParam(Param.PAGE, "2").execute().assertJson(getClass(), "page_two.json");
}
@Test
@@ -142,28 +143,28 @@ public class SearchActionTest {
.contains("scmAccounts")
.contains("groups");
- assertThat(tester.newGetRequest("api/users", "search").setParam("f", "").execute().outputAsString())
+ assertThat(tester.newGetRequest("api/users", "search").setParam(Param.FIELDS, "").execute().outputAsString())
.contains("login")
.contains("name")
.contains("email")
.contains("scmAccounts")
.contains("groups");
- assertThat(tester.newGetRequest("api/users", "search").setParam("f", "login").execute().outputAsString())
+ assertThat(tester.newGetRequest("api/users", "search").setParam(Param.FIELDS, "login").execute().outputAsString())
.contains("login")
.doesNotContain("name")
.doesNotContain("email")
.doesNotContain("scmAccounts")
.doesNotContain("groups");
- assertThat(tester.newGetRequest("api/users", "search").setParam("f", "scmAccounts").execute().outputAsString())
+ assertThat(tester.newGetRequest("api/users", "search").setParam(Param.FIELDS, "scmAccounts").execute().outputAsString())
.doesNotContain("login")
.doesNotContain("name")
.doesNotContain("email")
.contains("scmAccounts")
.doesNotContain("groups");
- assertThat(tester.newGetRequest("api/users", "search").setParam("f", "groups").execute().outputAsString())
+ assertThat(tester.newGetRequest("api/users", "search").setParam(Param.FIELDS, "groups").execute().outputAsString())
.doesNotContain("login")
.doesNotContain("name")
.doesNotContain("email")