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
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);
.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
--- /dev/null
+{
+ "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
--- /dev/null
+{
+ "results":
+ [
+ {
+ "key": "BCDE",
+ "name": "Project Two",
+ "selected": true
+ }
+ ],
+
+ "more": false
+}
\ No newline at end of file