aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-ws-client/src
diff options
context:
space:
mode:
authorGodin <mandrikov@gmail.com>2010-12-06 23:09:23 +0000
committerGodin <mandrikov@gmail.com>2010-12-06 23:09:23 +0000
commit2b9e4602bfaa4585724eb99137b439d0632fe0c5 (patch)
treee60c8415077e30f51d912b756e166908e35c7930 /sonar-ws-client/src
parent1dcef2da02a23f2d1bc77f49f80f38972db2259d (diff)
downloadsonarqube-2b9e4602bfaa4585724eb99137b439d0632fe0c5.tar.gz
sonarqube-2b9e4602bfaa4585724eb99137b439d0632fe0c5.zip
SONAR-2024: Add "limit" parameter to ViolationQuery
Diffstat (limited to 'sonar-ws-client/src')
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/services/ViolationQuery.java50
-rw-r--r--sonar-ws-client/src/test/java/org/sonar/wsclient/services/ViolationQueryTest.java8
2 files changed, 30 insertions, 28 deletions
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/ViolationQuery.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/ViolationQuery.java
index 92fe1f9d306..1288dfc9d2e 100644
--- a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/ViolationQuery.java
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/ViolationQuery.java
@@ -22,13 +22,14 @@ package org.sonar.wsclient.services;
public class ViolationQuery extends Query<Violation> {
public static final String BASE_URL = "/api/violations";
+ private String resourceKeyOrId;
+ private int depth = 0;
private String[] scopes;
private String[] qualifiers;
private String[] ruleKeys;
private String[] categories;
private String[] severities;
- private int depth = 0;
- private String resourceKeyOrId;
+ private Integer limit;
public ViolationQuery(String resourceKeyOrId) {
this.resourceKeyOrId = resourceKeyOrId;
@@ -111,37 +112,38 @@ public class ViolationQuery extends Query<Violation> {
return this;
}
+ /**
+ * @since 2.5
+ */
+ public Integer getLimit() {
+ return limit;
+ }
+
+ /**
+ * @since 2.5
+ */
+ public ViolationQuery setLimit(Integer limit) {
+ this.limit = limit;
+ return this;
+ }
+
@Override
public String getUrl() {
StringBuilder url = new StringBuilder(BASE_URL);
- url.append("?resource=")
- .append(resourceKeyOrId)
- .append("&");
-
+ url.append('?');
+ appendUrlParameter(url, "resource", resourceKeyOrId);
if (depth != 0) {
url.append("depth=").append(depth).append("&");
}
- append(url, "scopes", scopes);
- append(url, "qualifiers", qualifiers);
- append(url, "rules", ruleKeys);
- append(url, "categories", categories);
- append(url, "priorities", severities);
+ appendUrlParameter(url, "limit", limit);
+ appendUrlParameter(url, "scopes", scopes);
+ appendUrlParameter(url, "qualifiers", qualifiers);
+ appendUrlParameter(url, "rules", ruleKeys);
+ appendUrlParameter(url, "categories", categories);
+ appendUrlParameter(url, "priorities", severities);
return url.toString();
}
- private void append(StringBuilder url, String paramKey, Object[] paramValues) {
- if (paramValues != null && paramValues.length > 0) {
- url.append(paramKey).append('=');
- for (int index = 0; index < paramValues.length; index++) {
- if (index > 0) {
- url.append(',');
- }
- url.append(paramValues[index]);
- }
- url.append('&');
- }
- }
-
@Override
public Class<Violation> getModelClass() {
return Violation.class;
diff --git a/sonar-ws-client/src/test/java/org/sonar/wsclient/services/ViolationQueryTest.java b/sonar-ws-client/src/test/java/org/sonar/wsclient/services/ViolationQueryTest.java
index 57e97f9ed46..881a113aeb6 100644
--- a/sonar-ws-client/src/test/java/org/sonar/wsclient/services/ViolationQueryTest.java
+++ b/sonar-ws-client/src/test/java/org/sonar/wsclient/services/ViolationQueryTest.java
@@ -19,7 +19,6 @@
*/
package org.sonar.wsclient.services;
-import org.hamcrest.core.Is;
import org.junit.Test;
import static org.hamcrest.Matchers.is;
@@ -31,16 +30,17 @@ public class ViolationQueryTest {
public void resourceViolations() {
ViolationQuery query = ViolationQuery.createForResource("myproject:org.foo:bar");
assertThat(query.getUrl(), is("/api/violations?resource=myproject:org.foo:bar&"));
- assertThat(query.getModelClass().getName(), Is.is(Violation.class.getName()));
+ assertThat(query.getModelClass().getName(), is(Violation.class.getName()));
}
@Test
public void resourceTreeViolations() {
ViolationQuery query = ViolationQuery.createForResource("myproject")
.setDepth(-1)
- .setPriorities("MAJOR", "BLOCKER")
+ .setLimit(20)
+ .setSeverities("MAJOR", "BLOCKER")
.setQualifiers("FIL")
.setRuleKeys("checkstyle:foo", "pmd:bar");
- assertThat(query.getUrl(), is("/api/violations?resource=myproject&depth=-1&qualifiers=FIL&rules=checkstyle:foo,pmd:bar&priorities=MAJOR,BLOCKER&"));
+ assertThat(query.getUrl(), is("/api/violations?resource=myproject&depth=-1&limit=20&qualifiers=FIL&rules=checkstyle:foo,pmd:bar&priorities=MAJOR,BLOCKER&"));
}
}