]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-2024: Add "limit" parameter to ViolationQuery
authorGodin <mandrikov@gmail.com>
Mon, 6 Dec 2010 23:09:23 +0000 (23:09 +0000)
committerGodin <mandrikov@gmail.com>
Mon, 6 Dec 2010 23:09:23 +0000 (23:09 +0000)
sonar-ws-client/src/main/java/org/sonar/wsclient/services/ViolationQuery.java
sonar-ws-client/src/test/java/org/sonar/wsclient/services/ViolationQueryTest.java

index 92fe1f9d30648a26d91b6cd6346c92cf67cab670..1288dfc9d2ee3da330cf9eb16b969b019770c3fe 100644 (file)
@@ -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;
index 57e97f9ed46978e8eac2cf607616f839ff155ab3..881a113aeb6acf89c78bcfdc9164e156ca5470c0 100644 (file)
@@ -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&"));
   }
 }