Search in sources :

Example 11 with ExpectedPaging

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;
}
Also used : JSONObject(org.json.simple.JSONObject) ListResponse(org.alfresco.rest.api.tests.client.PublicApiClient.ListResponse) ArrayList(java.util.ArrayList) JSONArray(org.json.simple.JSONArray) ExpectedPaging(org.alfresco.rest.api.tests.client.PublicApiClient.ExpectedPaging)

Example 12 with ExpectedPaging

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);
}
Also used : RestApiUtil.parsePaging(org.alfresco.rest.api.tests.util.RestApiUtil.parsePaging) Paging(org.alfresco.rest.api.tests.client.PublicApiClient.Paging) ExpectedPaging(org.alfresco.rest.api.tests.client.PublicApiClient.ExpectedPaging) Node(org.alfresco.rest.api.tests.client.data.Node) HttpResponse(org.alfresco.rest.api.tests.client.HttpResponse) ExpectedPaging(org.alfresco.rest.api.tests.client.PublicApiClient.ExpectedPaging) Test(org.junit.Test) AbstractSingleNetworkSiteTest(org.alfresco.rest.AbstractSingleNetworkSiteTest)

Example 13 with ExpectedPaging

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);
}
Also used : HashMap(java.util.HashMap) Rendition(org.alfresco.rest.api.tests.client.data.Rendition) Paging(org.alfresco.rest.api.tests.client.PublicApiClient.Paging) ExpectedPaging(org.alfresco.rest.api.tests.client.PublicApiClient.ExpectedPaging) HttpResponse(org.alfresco.rest.api.tests.client.HttpResponse) MultiPartRequest(org.alfresco.rest.api.tests.util.MultiPartBuilder.MultiPartRequest) RestApiUtil.toJsonAsString(org.alfresco.rest.api.tests.util.RestApiUtil.toJsonAsString) Document(org.alfresco.rest.api.tests.client.data.Document) MultiPartBuilder(org.alfresco.rest.api.tests.util.MultiPartBuilder) ContentInfo(org.alfresco.rest.api.tests.client.data.ContentInfo) ExpectedPaging(org.alfresco.rest.api.tests.client.PublicApiClient.ExpectedPaging) File(java.io.File) FileData(org.alfresco.rest.api.tests.util.MultiPartBuilder.FileData) Test(org.junit.Test)

Example 14 with ExpectedPaging

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;
}
Also used : JSONObject(org.json.simple.JSONObject) ListResponse(org.alfresco.rest.api.tests.client.PublicApiClient.ListResponse) ArrayList(java.util.ArrayList) JSONArray(org.json.simple.JSONArray) ExpectedPaging(org.alfresco.rest.api.tests.client.PublicApiClient.ExpectedPaging)

Example 15 with ExpectedPaging

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;
}
Also used : JSONObject(org.json.simple.JSONObject) ListResponse(org.alfresco.rest.api.tests.client.PublicApiClient.ListResponse) ArrayList(java.util.ArrayList) JSONArray(org.json.simple.JSONArray) ExpectedPaging(org.alfresco.rest.api.tests.client.PublicApiClient.ExpectedPaging)

Aggregations

ExpectedPaging (org.alfresco.rest.api.tests.client.PublicApiClient.ExpectedPaging)22 ListResponse (org.alfresco.rest.api.tests.client.PublicApiClient.ListResponse)19 JSONArray (org.json.simple.JSONArray)19 JSONObject (org.json.simple.JSONObject)19 ArrayList (java.util.ArrayList)18 HttpResponse (org.alfresco.rest.api.tests.client.HttpResponse)3 Test (org.junit.Test)3 AbstractSingleNetworkSiteTest (org.alfresco.rest.AbstractSingleNetworkSiteTest)2 Paging (org.alfresco.rest.api.tests.client.PublicApiClient.Paging)2 Node (org.alfresco.rest.api.tests.client.data.Node)2 File (java.io.File)1 HashMap (java.util.HashMap)1 ContentInfo (org.alfresco.rest.api.tests.client.data.ContentInfo)1 Document (org.alfresco.rest.api.tests.client.data.Document)1 FolderNode (org.alfresco.rest.api.tests.client.data.FolderNode)1 Rendition (org.alfresco.rest.api.tests.client.data.Rendition)1 MultiPartBuilder (org.alfresco.rest.api.tests.util.MultiPartBuilder)1 FileData (org.alfresco.rest.api.tests.util.MultiPartBuilder.FileData)1 MultiPartRequest (org.alfresco.rest.api.tests.util.MultiPartBuilder.MultiPartRequest)1 RestApiUtil.parsePaging (org.alfresco.rest.api.tests.util.RestApiUtil.parsePaging)1