use of org.alfresco.rest.api.tests.client.PublicApiClient.ExpectedPaging in project alfresco-remote-api by Alfresco.
the class ListParser method parseList.
public ListResponse<T> parseList(JSONObject jsonResponse) {
List<T> entries = new ArrayList<T>();
JSONObject jsonList = (JSONObject) jsonResponse.get("list");
assertNotNull(jsonList);
JSONArray jsonEntries = (JSONArray) jsonList.get("entries");
assertNotNull(jsonEntries);
for (int i = 0; i < jsonEntries.size(); i++) {
JSONObject jsonEntry = (JSONObject) jsonEntries.get(i);
JSONObject entry = (JSONObject) jsonEntry.get("entry");
entries.add(parseEntry(entry));
}
ExpectedPaging paging = ExpectedPaging.parsePagination(jsonList);
ListResponse<T> resp = new ListResponse<T>(paging, entries);
return resp;
}
use of org.alfresco.rest.api.tests.client.PublicApiClient.ExpectedPaging 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);
}
use of org.alfresco.rest.api.tests.client.PublicApiClient.ExpectedPaging in project alfresco-remote-api by Alfresco.
the class RenditionsTest method testListNodeRenditions.
/**
* Tests get node renditions.
* <p>GET:</p>
* {@literal <host>:<port>/alfresco/api/<networkId>/public/alfresco/versions/1/nodes/<nodeId>/renditions}
*/
@Test
public void testListNodeRenditions() throws Exception {
setRequestContext(networkN1.getId(), userOneN1.getId(), null);
// Create a folder within the site document's library
String folderName = "folder" + System.currentTimeMillis();
String folder_Id = addToDocumentLibrary(userOneN1Site, folderName, TYPE_CM_FOLDER, userOneN1.getId());
// Create multipart request
String fileName = "quick.pdf";
File file = getResourceFile(fileName);
MultiPartBuilder multiPartBuilder = MultiPartBuilder.create().setFileData(new FileData(fileName, file));
MultiPartRequest reqBody = multiPartBuilder.build();
// Upload quick.pdf file into 'folder'
HttpResponse response = post(getNodeChildrenUrl(folder_Id), reqBody.getBody(), null, reqBody.getContentType(), 201);
Document document = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
String contentNodeId = document.getId();
Paging paging = getPaging(0, 50);
// List all available renditions (includes those that have been created and those that are yet to be created)
response = getAll(getNodeRenditionsUrl(contentNodeId), paging, 200);
List<Rendition> renditions = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Rendition.class);
assertTrue(renditions.size() >= 5);
Rendition docLib = getRendition(renditions, "doclib");
assertNotNull(docLib);
assertEquals(RenditionStatus.NOT_CREATED, docLib.getStatus());
ContentInfo contentInfo = docLib.getContent();
assertNotNull(contentInfo);
assertEquals(MimetypeMap.MIMETYPE_IMAGE_PNG, contentInfo.getMimeType());
assertEquals("PNG Image", contentInfo.getMimeTypeName());
assertNull(contentInfo.getEncoding());
assertNull(contentInfo.getSizeInBytes());
// Add a filter to select the renditions based on the given status
Map<String, String> params = new HashMap<>(1);
params.put("where", "(status='NOT_CREATED')");
// List only the NOT_CREATED renditions
response = getAll(getNodeRenditionsUrl(contentNodeId), paging, params, 200);
renditions = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Rendition.class);
assertTrue(renditions.size() >= 5);
params.put("where", "(status='CREATED')");
// List only the CREATED renditions
response = getAll(getNodeRenditionsUrl(contentNodeId), paging, params, 200);
renditions = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Rendition.class);
assertEquals("There is no rendition created yet.", 0, renditions.size());
// Test paging
// SkipCount=0,MaxItems=2
paging = getPaging(0, 2);
// List all available renditions
response = getAll(getNodeRenditionsUrl(contentNodeId), paging, 200);
renditions = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Rendition.class);
assertEquals(2, renditions.size());
ExpectedPaging expectedPaging = RestApiUtil.parsePaging(response.getJsonResponse());
assertEquals(2, expectedPaging.getCount().intValue());
assertEquals(0, expectedPaging.getSkipCount().intValue());
assertEquals(2, expectedPaging.getMaxItems().intValue());
assertTrue(expectedPaging.getTotalItems() >= 5);
assertTrue(expectedPaging.getHasMoreItems());
// SkipCount=2,MaxItems=3
paging = getPaging(2, 3);
// List all available renditions
response = getAll(getNodeRenditionsUrl(contentNodeId), paging, 200);
renditions = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Rendition.class);
assertEquals(3, renditions.size());
expectedPaging = RestApiUtil.parsePaging(response.getJsonResponse());
assertEquals(3, expectedPaging.getCount().intValue());
assertEquals(2, expectedPaging.getSkipCount().intValue());
assertEquals(3, expectedPaging.getMaxItems().intValue());
assertTrue(expectedPaging.getTotalItems() >= 5);
// Create 'doclib' rendition
createAndGetRendition(contentNodeId, docLib.getId());
// List all available renditions (includes those that have been created and those that are yet to be created)
paging = getPaging(0, 50);
response = getAll(getNodeRenditionsUrl(contentNodeId), paging, 200);
renditions = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Rendition.class);
assertTrue(renditions.size() >= 5);
docLib = getRendition(renditions, "doclib");
assertNotNull(docLib);
assertEquals(RenditionStatus.CREATED, docLib.getStatus());
contentInfo = docLib.getContent();
assertNotNull(contentInfo);
assertEquals(MimetypeMap.MIMETYPE_IMAGE_PNG, contentInfo.getMimeType());
assertEquals("PNG Image", contentInfo.getMimeTypeName());
assertNotNull(contentInfo.getEncoding());
assertTrue(contentInfo.getSizeInBytes() > 0);
// List only the CREATED renditions
response = getAll(getNodeRenditionsUrl(contentNodeId), paging, params, 200);
renditions = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Rendition.class);
assertEquals("Should've only returned the 'doclib' rendition.", 1, renditions.size());
params.put("where", "(status='NOT_CREATED')");
// List only the NOT_CREATED renditions
response = getAll(getNodeRenditionsUrl(contentNodeId), paging, params, 200);
renditions = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Rendition.class);
assertTrue(renditions.size() > 0);
docLib = getRendition(renditions, "doclib");
assertNull("'doclib' rendition has already been created.", docLib);
// Test returned renditions are ordered (natural sort order)
// List all renditions
response = getAll(getNodeRenditionsUrl(contentNodeId), paging, params, 200);
renditions = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Rendition.class);
assertTrue(Ordering.natural().isOrdered(renditions));
// Try again to make sure the ordering wasn't coincidental
response = getAll(getNodeRenditionsUrl(contentNodeId), paging, params, 200);
renditions = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Rendition.class);
assertTrue(Ordering.natural().isOrdered(renditions));
// nodeId in the path parameter does not represent a file
getAll(getNodeRenditionsUrl(folder_Id), paging, params, 400);
// nodeId in the path parameter does not exist
getAll(getNodeRenditionsUrl(UUID.randomUUID().toString()), paging, params, 404);
// Create a node without any content
String emptyContentNodeId = addToDocumentLibrary(userOneN1Site, "emptyDoc.txt", TYPE_CM_CONTENT, userOneN1.getId());
getAll(getNodeRenditionsUrl(emptyContentNodeId), paging, params, 200);
// Invalid status value
params.put("where", "(status='WRONG')");
getAll(getNodeRenditionsUrl(contentNodeId), paging, params, 400);
// Invalid filter (only 'status' is supported)
params.put("where", "(id='doclib')");
getAll(getNodeRenditionsUrl(contentNodeId), paging, params, 400);
}
use of org.alfresco.rest.api.tests.client.PublicApiClient.ExpectedPaging in project alfresco-remote-api by Alfresco.
the class Group method parseGroups.
public static ListResponse<Group> parseGroups(JSONObject jsonObject) {
List<Group> groups = new ArrayList<>();
JSONObject jsonList = (JSONObject) jsonObject.get("list");
assertNotNull(jsonList);
JSONArray jsonEntries = (JSONArray) jsonList.get("entries");
assertNotNull(jsonEntries);
for (int i = 0; i < jsonEntries.size(); i++) {
JSONObject jsonEntry = (JSONObject) jsonEntries.get(i);
JSONObject entry = (JSONObject) jsonEntry.get("entry");
groups.add(parseGroup(entry));
}
ExpectedPaging paging = ExpectedPaging.parsePagination(jsonList);
ListResponse<Group> resp = new ListResponse<>(paging, groups);
return resp;
}
use of org.alfresco.rest.api.tests.client.PublicApiClient.ExpectedPaging in project alfresco-remote-api by Alfresco.
the class MemberOfSite method parseMemberOfSites.
public static ListResponse<MemberOfSite> parseMemberOfSites(JSONObject jsonObject) {
List<MemberOfSite> siteMembers = new ArrayList<MemberOfSite>();
JSONObject jsonList = (JSONObject) jsonObject.get("list");
assertNotNull(jsonList);
JSONArray jsonEntries = (JSONArray) jsonList.get("entries");
assertNotNull(jsonEntries);
for (int i = 0; i < jsonEntries.size(); i++) {
JSONObject jsonEntry = (JSONObject) jsonEntries.get(i);
JSONObject entry = (JSONObject) jsonEntry.get("entry");
siteMembers.add(parseMemberOfSite(entry));
}
ExpectedPaging paging = ExpectedPaging.parsePagination(jsonList);
ListResponse<MemberOfSite> resp = new ListResponse<MemberOfSite>(paging, siteMembers);
return resp;
}
Aggregations