]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5921 Apply feedback from tests
authorJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>
Fri, 3 Apr 2015 11:28:15 +0000 (13:28 +0200)
committerJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>
Fri, 3 Apr 2015 11:28:15 +0000 (13:28 +0200)
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/QProfileProjectsAction.java
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/QProfileProjectsActionTest.java
server/sonar-server/src/test/resources/org/sonar/server/qualityprofile/ws/QProfileProjectsActionTest/selected_ps3_page1.json [new file with mode: 0644]
server/sonar-server/src/test/resources/org/sonar/server/qualityprofile/ws/QProfileProjectsActionTest/selected_ps3_page2.json [new file with mode: 0644]

index d351b0fde1f71f253852638320957082ef03b81f..9755a806fe7b4533d802578a87cca229863f109c 100644 (file)
@@ -78,9 +78,9 @@ public class QProfileProjectsAction implements BaseQProfileWsAction {
     projects.createParam(PARAM_QUERY)
       .setDescription("If specified, return only projects whose name match the query.");
     projects.createParam(PARAM_PAGE_SIZE)
-      .setDescription("Size for the paging to apply").setDefaultValue(100);
+      .setDescription("Size for the paging to apply.").setDefaultValue(100);
     projects.createParam(PARAM_PAGE)
-      .setDescription("Index of the page to display").setDefaultValue(1);
+      .setDescription("Index of the page to display.").setDefaultValue(1);
   }
 
   @Override
@@ -130,7 +130,8 @@ public class QProfileProjectsAction implements BaseQProfileWsAction {
       if (pagedAuthorizedProjects.size() <= paging.offset()) {
         pagedAuthorizedProjects = Lists.newArrayList();
       } else if (pagedAuthorizedProjects.size() > paging.pageSize()) {
-        pagedAuthorizedProjects = pagedAuthorizedProjects.subList(paging.offset(), paging.offset() + pageSize);
+        int endIndex = Math.min(paging.offset() + pageSize, pagedAuthorizedProjects.size());
+        pagedAuthorizedProjects = pagedAuthorizedProjects.subList(paging.offset(), endIndex);
       }
 
       writeProjects(response.newJsonWriter(), pagedAuthorizedProjects, paging);
index 9b73c6a39572a736d412da58da3a708922736e4a..73ede38f285f3a2acd7617b485e7e388aaa4ae41 100644 (file)
@@ -136,6 +136,13 @@ public class QProfileProjectsActionTest {
       .execute().assertJson(this.getClass(), "empty.json");
     newRequest().setParam("key", xooP1.getKey()).setParam("selected", "selected").setParam("pageSize", "2").setParam("page", "4")
       .execute().assertJson(this.getClass(), "empty.json");
+
+    newRequest().setParam("key", xooP1.getKey()).setParam("selected", "selected").setParam("pageSize", "3").setParam("page", "1")
+      .execute().assertJson(this.getClass(), "selected_ps3_page1.json");
+    newRequest().setParam("key", xooP1.getKey()).setParam("selected", "selected").setParam("pageSize", "3").setParam("page", "2")
+      .execute().assertJson(this.getClass(), "selected_ps3_page2.json");
+    newRequest().setParam("key", xooP1.getKey()).setParam("selected", "selected").setParam("pageSize", "3").setParam("page", "3")
+      .execute().assertJson(this.getClass(), "empty.json");
   }
 
   @Test
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/qualityprofile/ws/QProfileProjectsActionTest/selected_ps3_page1.json b/server/sonar-server/src/test/resources/org/sonar/server/qualityprofile/ws/QProfileProjectsActionTest/selected_ps3_page1.json
new file mode 100644 (file)
index 0000000..978447e
--- /dev/null
@@ -0,0 +1,22 @@
+{
+  "results":
+  [
+    {
+      "key": "DEFA",
+      "name": "Project Four",
+      "selected": true
+    },
+    {
+      "key": "ABCD",
+      "name": "Project One",
+      "selected": true
+    },
+    {
+      "key": "CDEF",
+      "name": "Project Three",
+      "selected": true
+    }
+  ],
+
+  "more": true
+}
\ No newline at end of file
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/qualityprofile/ws/QProfileProjectsActionTest/selected_ps3_page2.json b/server/sonar-server/src/test/resources/org/sonar/server/qualityprofile/ws/QProfileProjectsActionTest/selected_ps3_page2.json
new file mode 100644 (file)
index 0000000..daf6e7e
--- /dev/null
@@ -0,0 +1,12 @@
+{
+  "results":
+  [
+    {
+      "key": "BCDE",
+      "name": "Project Two",
+      "selected": true
+    }
+  ],
+
+  "more": false
+}
\ No newline at end of file