use of org.alfresco.rest.api.tests.util.RestApiUtil.parsePaging in project alfresco-remote-api by Alfresco.
the class NodeApiTest method testListChildrenWithinSiteDocLib.
/**
* Tests get document library children.
* <p>GET:</p>
* {@literal <host>:<port>/alfresco/api/<networkId>/public/alfresco/versions/1/nodes/<nodeId>/children}
*/
@Test
public void testListChildrenWithinSiteDocLib() throws Exception {
setRequestContext(user1);
// create folder f0
String folder0Name = "f0-testListChildrenWithinSiteDocLib-" + RUNID;
String f0Id = createFolder(tDocLibNodeId, folder0Name).getId();
String folder1 = "folder" + RUNID + "_1";
createFolder(f0Id, folder1, null).getId();
String folder2 = "folder" + RUNID + "_2";
createFolder(f0Id, folder2, null).getId();
String content1 = "content" + RUNID + "_1";
createTextFile(f0Id, content1, "The quick brown fox jumps over the lazy dog 1.").getId();
String content2 = "content" + RUNID + "_2";
createTextFile(f0Id, content2, "The quick brown fox jumps over the lazy dog 2.").getId();
String forum1 = "forum" + RUNID + "_1";
createNode(f0Id, forum1, "fm:topic", null);
Paging paging = getPaging(0, 100);
HttpResponse response = getAll(getNodeChildrenUrl(f0Id), paging, 200);
List<Node> nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
// forum is part of the default ignored types
assertEquals(4, nodes.size());
// Paging
ExpectedPaging expectedPaging = RestApiUtil.parsePaging(response.getJsonResponse());
assertEquals(4, expectedPaging.getCount().intValue());
assertEquals(0, expectedPaging.getSkipCount().intValue());
assertEquals(100, expectedPaging.getMaxItems().intValue());
assertFalse(expectedPaging.getHasMoreItems().booleanValue());
// Order by folders and modified date first
Map<String, String> orderBy = Collections.singletonMap("orderBy", "isFolder DESC,modifiedAt DESC");
response = getAll(getNodeChildrenUrl(f0Id), paging, orderBy, 200);
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
assertEquals(4, nodes.size());
assertEquals(folder2, nodes.get(0).getName());
assertTrue(nodes.get(0).getIsFolder());
assertFalse(nodes.get(0).getIsFile());
assertEquals(folder1, nodes.get(1).getName());
assertTrue(nodes.get(1).getIsFolder());
assertFalse(nodes.get(1).getIsFile());
assertEquals(content2, nodes.get(2).getName());
assertFalse(nodes.get(2).getIsFolder());
assertTrue(nodes.get(2).getIsFile());
assertEquals(content1, nodes.get(3).getName());
assertFalse(nodes.get(3).getIsFolder());
assertTrue(nodes.get(3).getIsFile());
// Order by folders last and modified date first
orderBy = Collections.singletonMap("orderBy", "isFolder ASC,modifiedAt DESC");
response = getAll(getNodeChildrenUrl(f0Id), paging, orderBy, 200);
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
assertEquals(4, nodes.size());
assertEquals(content2, nodes.get(0).getName());
assertEquals(content1, nodes.get(1).getName());
assertEquals(folder2, nodes.get(2).getName());
assertEquals(folder1, nodes.get(3).getName());
// Order by folders and modified date last
orderBy = Collections.singletonMap("orderBy", "isFolder,modifiedAt");
response = getAll(getNodeChildrenUrl(f0Id), paging, orderBy, 200);
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
assertEquals(4, nodes.size());
assertEquals(content1, nodes.get(0).getName());
assertEquals(content2, nodes.get(1).getName());
assertEquals(folder1, nodes.get(2).getName());
assertEquals(folder2, nodes.get(3).getName());
// Order by folders and modified date first
orderBy = Collections.singletonMap("orderBy", "isFolder DESC,modifiedAt DESC");
// SkipCount=0,MaxItems=2
paging = getPaging(0, 2);
response = getAll(getNodeChildrenUrl(f0Id), paging, orderBy, 200);
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
assertEquals(2, nodes.size());
assertEquals(folder2, nodes.get(0).getName());
assertEquals(folder1, nodes.get(1).getName());
expectedPaging = RestApiUtil.parsePaging(response.getJsonResponse());
assertEquals(2, expectedPaging.getCount().intValue());
assertEquals(0, expectedPaging.getSkipCount().intValue());
assertEquals(2, expectedPaging.getMaxItems().intValue());
assertTrue(expectedPaging.getHasMoreItems().booleanValue());
// SkipCount=null,MaxItems=2
paging = getPaging(null, 2);
response = getAll(getNodeChildrenUrl(f0Id), paging, orderBy, 200);
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
assertEquals(2, nodes.size());
assertEquals(folder2, nodes.get(0).getName());
assertEquals(folder1, nodes.get(1).getName());
expectedPaging = RestApiUtil.parsePaging(response.getJsonResponse());
assertEquals(2, expectedPaging.getCount().intValue());
assertEquals(0, expectedPaging.getSkipCount().intValue());
assertEquals(2, expectedPaging.getMaxItems().intValue());
assertTrue(expectedPaging.getHasMoreItems().booleanValue());
// SkipCount=2,MaxItems=4
paging = getPaging(2, 4);
response = getAll(getNodeChildrenUrl(f0Id), paging, orderBy, 200);
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
assertEquals(2, nodes.size());
assertEquals(content2, nodes.get(0).getName());
assertEquals(content1, nodes.get(1).getName());
expectedPaging = RestApiUtil.parsePaging(response.getJsonResponse());
assertEquals(2, expectedPaging.getCount().intValue());
assertEquals(2, expectedPaging.getSkipCount().intValue());
assertEquals(4, expectedPaging.getMaxItems().intValue());
assertFalse(expectedPaging.getHasMoreItems().booleanValue());
// SkipCount=2,MaxItems=null
paging = getPaging(2, null);
response = getAll(getNodeChildrenUrl(f0Id), paging, orderBy, 200);
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
assertEquals(2, nodes.size());
assertEquals(content2, nodes.get(0).getName());
assertEquals(content1, nodes.get(1).getName());
expectedPaging = RestApiUtil.parsePaging(response.getJsonResponse());
assertEquals(2, expectedPaging.getCount().intValue());
assertEquals(2, expectedPaging.getSkipCount().intValue());
assertEquals(100, expectedPaging.getMaxItems().intValue());
assertFalse(expectedPaging.getHasMoreItems().booleanValue());
setRequestContext(user2);
// user2 tries to access user1's folder in a private docLib
paging = getPaging(0, Integer.MAX_VALUE);
getAll(getNodeChildrenUrl(f0Id), paging, 403);
setRequestContext(user1);
// -ve test - paging (via list children) cannot have skipCount < 0
paging = getPaging(-1, 4);
getAll(getNodeChildrenUrl(f0Id), paging, orderBy, 400);
// -ve test - paging (via list children) cannot have maxItems < 1
paging = getPaging(0, 0);
getAll(getNodeChildrenUrl(f0Id), paging, orderBy, 400);
}
Aggregations