Search in sources :

Example 31 with Folder

use of org.alfresco.rest.api.tests.client.data.Folder in project alfresco-remote-api by Alfresco.

the class NodeApiTest method testListChildrenWithinMyFiles.

/**
 * Tests list children.
 * <p>GET:</p>
 * {@literal <host>:<port>/alfresco/api/-default-/public/alfresco/versions/1/nodes/<nodeId>/children}
 */
@Test
public void testListChildrenWithinMyFiles() throws Exception {
    setRequestContext(user1);
    String myNodeId = getMyNodeId();
    String rootChildrenUrl = getNodeChildrenUrl(Nodes.PATH_ROOT);
    String folder0Name = "folder " + RUNID + " 0";
    String folder0Id = createFolder(myNodeId, folder0Name, null).getId();
    String childrenUrl = getNodeChildrenUrl(folder0Id);
    Map<String, Object> props = new HashMap<>(1);
    props.put("cm:title", "This is folder 1");
    String folder1 = "folder " + RUNID + " 1";
    String folder1_Id = createFolder(folder0Id, folder1, props).getId();
    String contentF1 = "content" + RUNID + " in folder 1";
    String contentF1_Id = createTextFile(folder1_Id, contentF1, "The quick brown fox jumps over the lazy dog 1.").getId();
    props = new HashMap<>(1);
    props.put("cm:title", "This is folder 2");
    String folder2 = "folder " + RUNID + " 2";
    String folder2_Id = createFolder(folder0Id, folder2, props).getId();
    String contentF2 = "content" + RUNID + " in folder 2.txt";
    String contentF2_Id = createTextFile(folder2_Id, contentF2, "The quick brown fox jumps over the lazy dog 2.").getId();
    String content1 = "content" + RUNID + " 1.txt";
    String content1_Id = createTextFile(folder0Id, content1, "The quick brown fox jumps over the lazy dog.").getId();
    props = new HashMap<>();
    props.put(PROP_OWNER, user1);
    props.put("cm:lastThumbnailModification", Collections.singletonList("doclib:1444660852296"));
    Node nodeUpdate = new Node();
    nodeUpdate.setProperties(props);
    put(URL_NODES, content1_Id, toJsonAsStringNonNull(nodeUpdate), null, 200);
    List<String> folderIds = Arrays.asList(folder1_Id, folder2_Id);
    List<String> contentIds = Arrays.asList(content1_Id);
    Paging paging = getPaging(0, 100);
    HttpResponse response = getAll(childrenUrl, paging, 200);
    List<Document> nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Document.class);
    assertEquals(3, nodes.size());
    // Order by folders and modified date first
    Map<String, String> orderBy = Collections.singletonMap("orderBy", "isFolder DESC,modifiedAt DESC");
    response = getAll(childrenUrl, paging, orderBy, 200);
    nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Document.class);
    assertEquals(3, nodes.size());
    assertEquals(folder2, nodes.get(0).getName());
    assertEquals(folder1, nodes.get(1).getName());
    Document node = nodes.get(2);
    assertEquals(content1, node.getName());
    assertEquals(TYPE_CM_CONTENT, node.getNodeType());
    assertEquals(content1_Id, node.getId());
    UserInfo createdByUser = node.getCreatedByUser();
    assertEquals(user1, createdByUser.getId());
    assertEquals(UserInfo.getTestDisplayName(user1), createdByUser.getDisplayName());
    UserInfo modifiedByUser = node.getModifiedByUser();
    assertEquals(user1, modifiedByUser.getId());
    assertEquals(UserInfo.getTestDisplayName(user1), modifiedByUser.getDisplayName());
    assertEquals(MimetypeMap.MIMETYPE_TEXT_PLAIN, node.getContent().getMimeType());
    assertNotNull(node.getContent().getMimeTypeName());
    assertNotNull(node.getContent().getEncoding());
    assertTrue(node.getContent().getSizeInBytes() > 0);
    // request without "include"
    Map<String, String> params = new HashMap<>();
    response = getAll(childrenUrl, paging, params, 200);
    nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Document.class);
    for (Node n : nodes) {
        assertNull("There shouldn't be a 'properties' object in the response.", n.getProperties());
        assertNull("There shouldn't be a 'isLink' object in the response.", n.getIsLink());
        assertNull("There shouldn't be a 'path' object in the response.", n.getPath());
        assertNull("There shouldn't be a 'aspectNames' object in the response.", n.getAspectNames());
    }
    // request with include - example 1
    params = new HashMap<>();
    params.put("include", "isLink");
    response = getAll(childrenUrl, paging, params, 200);
    nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Document.class);
    for (Node n : nodes) {
        assertNotNull("There should be a 'isLink' object in the response.", n.getIsLink());
    }
    // request with include - example 2
    params = new HashMap<>();
    params.put("include", "aspectNames,properties,path,isLink");
    response = getAll(childrenUrl, paging, params, 200);
    nodes = jacksonUtil.parseEntries(response.getJsonResponse(), Document.class);
    for (Node n : nodes) {
        // eg. cm:title, see above
        assertNotNull("There should be a 'properties' object in the response.", n.getProperties());
        assertNotNull("There should be a 'isLink' object in the response.", n.getIsLink());
        assertNotNull("There should be a 'path' object in the response.", n.getPath());
        assertNotNull("There should be a 'aspectNames' object in the response.", n.getAspectNames());
    }
    // request specific property via include
    params = new HashMap<>();
    params.put("include", "cm:lastThumbnailModification");
    params.put("orderBy", "isFolder DESC,modifiedAt DESC");
    response = getAll(childrenUrl, paging, params, 200);
    nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Document.class);
    assertEquals(3, nodes.size());
    assertNull("There shouldn't be a 'properties' object in the response.", nodes.get(0).getProperties());
    assertNull("There shouldn't be a 'properties' object in the response.", nodes.get(1).getProperties());
    assertNotNull("There should be a 'properties' object in the response.", nodes.get(2).getProperties());
    Set<Entry<String, Object>> propsSet = nodes.get(2).getProperties().entrySet();
    assertEquals(1, propsSet.size());
    Entry<String, Object> entry = propsSet.iterator().next();
    assertEquals("cm:lastThumbnailModification", entry.getKey());
    assertEquals("doclib:1444660852296", ((List<?>) entry.getValue()).get(0));
    // filtering, via where clause - folders only
    params = new HashMap<>();
    params.put("where", "(" + Nodes.PARAM_ISFOLDER + "=true)");
    response = getAll(childrenUrl, paging, params, 200);
    nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Document.class);
    assertEquals(2, nodes.size());
    assertTrue(nodes.get(0).getIsFolder());
    assertFalse(nodes.get(0).getIsFile());
    assertTrue(folderIds.contains(nodes.get(0).getId()));
    assertTrue(nodes.get(1).getIsFolder());
    assertFalse(nodes.get(1).getIsFile());
    assertTrue(folderIds.contains(nodes.get(1).getId()));
    // filtering, via where clause - content only
    params = new HashMap<>();
    params.put("where", "(" + Nodes.PARAM_ISFILE + "=true)");
    response = getAll(childrenUrl, paging, params, 200);
    nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Document.class);
    assertEquals(1, nodes.size());
    assertFalse(nodes.get(0).getIsFolder());
    assertTrue(nodes.get(0).getIsFile());
    assertTrue(contentIds.contains(nodes.get(0).getId()));
    // list children via relativePath
    params = Collections.singletonMap(Nodes.PARAM_RELATIVE_PATH, folder1);
    response = getAll(childrenUrl, paging, params, 200);
    JSONObject jsonResponse = response.getJsonResponse();
    nodes = RestApiUtil.parseRestApiEntries(jsonResponse, Document.class);
    assertEquals(1, nodes.size());
    assertEquals(contentF1_Id, nodes.get(0).getId());
    JSONObject jsonList = (JSONObject) jsonResponse.get("list");
    assertNotNull(jsonList);
    JSONObject jsonSrcObj = (JSONObject) jsonResponse.get("source");
    assertNull(jsonSrcObj);
    params = Collections.singletonMap(Nodes.PARAM_RELATIVE_PATH, "User Homes/" + user1 + "/" + folder0Name + "/" + folder2);
    response = getAll(rootChildrenUrl, paging, params, 200);
    jsonResponse = response.getJsonResponse();
    nodes = RestApiUtil.parseRestApiEntries(jsonResponse, Document.class);
    assertEquals(1, nodes.size());
    assertEquals(contentF2_Id, nodes.get(0).getId());
    jsonList = (JSONObject) jsonResponse.get("list");
    assertNotNull(jsonList);
    jsonSrcObj = (JSONObject) jsonResponse.get("source");
    assertNull(jsonSrcObj);
    // list children via relativePath and also return the source entity
    params = new HashMap<>();
    params.put(Nodes.PARAM_RELATIVE_PATH, "User Homes/" + user1 + "/" + folder0Name + "/" + folder2);
    params.put("includeSource", "true");
    params.put("include", "path,isLink");
    params.put("fields", "id");
    response = getAll(rootChildrenUrl, paging, params, 200);
    jsonResponse = response.getJsonResponse();
    nodes = RestApiUtil.parseRestApiEntries(jsonResponse, Document.class);
    assertEquals(1, nodes.size());
    Document doc = nodes.get(0);
    assertEquals(contentF2_Id, doc.getId());
    assertNotNull(doc.getPath());
    assertEquals(Boolean.FALSE, doc.getIsLink());
    assertNull(doc.getName());
    jsonList = (JSONObject) jsonResponse.get("list");
    assertNotNull(jsonList);
    // source is not affected by include (or fields for that matter) - returns the default node response
    Folder src = RestApiUtil.parsePojo("source", jsonList, Folder.class);
    assertEquals(folder2_Id, src.getId());
    assertNull(src.getPath());
    assertNull(src.getIsLink());
    assertNotNull(src.getName());
    assertNotNull(src.getAspectNames());
    assertNotNull(src.getProperties());
    // -ve test - Invalid QName (Namespace prefix cm... is not mapped to a namespace URI) for the orderBy parameter.
    params = Collections.singletonMap("orderBy", Nodes.PARAM_ISFOLDER + " DESC,cm" + System.currentTimeMillis() + ":modified DESC");
    getAll(childrenUrl, paging, params, 400);
    paging = getPaging(0, 10);
    // -ve test - list folder children for unknown node should return 404
    getAll(getNodeChildrenUrl(UUID.randomUUID().toString()), paging, 404);
    // -ve test - user2 tries to access user1's home folder
    setRequestContext(user2);
    getAll(getNodeChildrenUrl(myNodeId), paging, 403);
    setRequestContext(user1);
    // -ve test - try to list children using relative path to unknown node
    params = Collections.singletonMap(Nodes.PARAM_RELATIVE_PATH, "User Homes/" + user1 + "/unknown");
    getAll(rootChildrenUrl, paging, params, 404);
    // -ve test - try to list children using relative path to node for which user does not have read permission (expect 404 instead of 403)
    params = Collections.singletonMap(Nodes.PARAM_RELATIVE_PATH, "User Homes/" + user2);
    getAll(rootChildrenUrl, paging, params, 404);
    // -ve test - list folder children with relative path to unknown node should return 400
    params = Collections.singletonMap(Nodes.PARAM_RELATIVE_PATH, "/unknown");
    getAll(getNodeChildrenUrl(content1_Id), paging, params, 400);
    // filtering, via where clause - negated comparison
    params = new HashMap<>();
    params.put("where", "(NOT " + Nodes.PARAM_ISFILE + "=true)");
    getAll(childrenUrl, paging, params, 400);
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Node(org.alfresco.rest.api.tests.client.data.Node) 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) HttpResponse(org.alfresco.rest.api.tests.client.HttpResponse) UserInfo(org.alfresco.rest.api.tests.client.data.UserInfo) Document(org.alfresco.rest.api.tests.client.data.Document) Folder(org.alfresco.rest.api.tests.client.data.Folder) Entry(java.util.Map.Entry) JSONObject(org.json.simple.JSONObject) JSONObject(org.json.simple.JSONObject) Test(org.junit.Test) AbstractSingleNetworkSiteTest(org.alfresco.rest.AbstractSingleNetworkSiteTest)

Example 32 with Folder

use of org.alfresco.rest.api.tests.client.data.Folder in project alfresco-remote-api by Alfresco.

the class InterceptingIdentityRemoteUserMapper method testCreateValidateDeleteTicketViaBasicAuthHeader.

/**
 * Tests login (create ticket), logout (delete ticket), and validate (get ticket).
 *
 * <p>POST:</p>
 * {@literal <host>:<port>/alfresco/api/<networkId>/public/authentication/versions/1/tickets}
 *
 * <p>GET:</p>
 * {@literal <host>:<port>/alfresco/api/<networkId>/public/authentication/versions/1/tickets/-me-}
 *
 * <p>DELETE:</p>
 * {@literal <host>:<port>/alfresco/api/<networkId>/public/authentication/versions/1/tickets/-me-}
 */
@Test
public void testCreateValidateDeleteTicketViaBasicAuthHeader() throws Exception {
    /*
         *  user2 login - Via Authorization header
         */
    Paging paging = getPaging(0, 100);
    setRequestContext(null);
    // Unauthorized call
    getAll(SiteEntityResource.class, paging, null, 401);
    // login request
    LoginTicket loginRequest = new LoginTicket();
    // Invalid login details
    post(TICKETS_URL, RestApiUtil.toJsonAsString(loginRequest), null, null, TICKETS_API_NAME, 400);
    loginRequest.setUserId(null);
    loginRequest.setPassword("user1Password");
    // Invalid login details
    post(TICKETS_URL, RestApiUtil.toJsonAsString(loginRequest), null, null, TICKETS_API_NAME, 400);
    setRequestContext(user2);
    // User2 create a folder within his home folder (-my-)
    Folder folderResp = createFolder(Nodes.PATH_MY, "F2", null);
    assertNotNull(folderResp.getId());
    setRequestContext(null);
    getAll(getNodeChildrenUrl(Nodes.PATH_MY), paging, 401);
    // User2 login request
    loginRequest = new LoginTicket();
    loginRequest.setUserId(user2);
    loginRequest.setPassword("wrongPassword");
    // Authentication failed - wrong password
    post(TICKETS_URL, RestApiUtil.toJsonAsString(loginRequest), null, null, TICKETS_API_NAME, 403);
    loginRequest.setUserId(user1);
    loginRequest.setPassword("user2Password");
    // Authentication failed - userId/password mismatch
    post(TICKETS_URL, RestApiUtil.toJsonAsString(loginRequest), null, null, TICKETS_API_NAME, 403);
    // Set the correct details
    loginRequest.setUserId(user2);
    loginRequest.setPassword("user2Password");
    // Authenticate and create a ticket
    HttpResponse response = post(TICKETS_URL, RestApiUtil.toJsonAsString(loginRequest), null, null, TICKETS_API_NAME, 201);
    LoginTicketResponse loginResponse = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), LoginTicketResponse.class);
    assertNotNull(loginResponse.getId());
    assertNotNull(loginResponse.getUserId());
    String encodedTicket = encodeB64(loginResponse.getId());
    // Set the authorization (encoded ticket only) header rather than appending the ticket to the URL
    Map<String, String> header = Collections.singletonMap("Authorization", "Basic " + encodedTicket);
    // Get children of user2 home folder
    response = getAll(getNodeChildrenUrl(Nodes.PATH_MY), paging, null, header, 200);
    List<Document> nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Document.class);
    assertEquals(1, nodes.size());
    // Validate ticket - Invalid parameter. Only '-me-' is supported
    getSingle(TICKETS_URL, loginResponse.getId(), null, header, TICKETS_API_NAME, 400);
    // Validate ticket - user2
    response = getSingle(TICKETS_URL, People.DEFAULT_USER, null, header, TICKETS_API_NAME, 200);
    LoginTicketResponse validatedTicket = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), LoginTicketResponse.class);
    assertEquals(loginResponse.getId(), validatedTicket.getId());
    // now use the "bearer" keyword with the alf-ticket  - should not succeed
    header = Collections.singletonMap("Authorization", "bearer " + encodedTicket);
    response = getSingle(TICKETS_URL, People.DEFAULT_USER, null, header, TICKETS_API_NAME, 401);
    // now send some junk  - should not succeed
    header = Collections.singletonMap("Authorization", "junk " + encodedTicket);
    response = getSingle(TICKETS_URL, People.DEFAULT_USER, null, header, TICKETS_API_NAME, 401);
    // Try list children for user2 again.
    // Encode Alfresco predefined userId for ticket authentication, ROLE_TICKET, and the ticket
    String encodedUserIdAndTicket = encodeB64("ROLE_TICKET:" + loginResponse.getId());
    // Set the authorization (encoded userId:ticket) header rather than appending the ticket to the URL
    header = Collections.singletonMap("Authorization", "Basic " + encodedUserIdAndTicket);
    // Get children of user2 home folder
    response = getAll(getNodeChildrenUrl(Nodes.PATH_MY), paging, null, header, 200);
    nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Document.class);
    assertEquals(1, nodes.size());
    // now use the "bearer" keyword with the alf-ticket  - should not succeed
    encodedUserIdAndTicket = encodeB64("ROLE_TICKET:" + loginResponse.getId());
    // Set the authorization (encoded userId:ticket) header rather than appending the ticket to the URL
    header = Collections.singletonMap("Authorization", "bearer " + encodedUserIdAndTicket);
    // Get children of user2 home folder
    response = getAll(getNodeChildrenUrl(Nodes.PATH_MY), paging, null, header, 401);
    // Try list children for user2 again - appending ticket
    Map<String, String> ticket = Collections.singletonMap("alf_ticket", loginResponse.getId());
    response = getAll(getNodeChildrenUrl(Nodes.PATH_MY), paging, ticket, 200);
    nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Document.class);
    assertEquals(1, nodes.size());
    setRequestContext(user2);
    // Try to validate the ticket without supplying the Authorization header or the alf_ticket param
    getSingle(TICKETS_URL, People.DEFAULT_USER, null, null, TICKETS_API_NAME, 400);
    setRequestContext(null);
    // Delete the ticket  - Invalid parameter. Only '-me-' is supported
    header = Collections.singletonMap("Authorization", "Basic " + encodedUserIdAndTicket);
    delete(TICKETS_URL, loginResponse.getId(), null, header, TICKETS_API_NAME, 400);
    // Delete the ticket  - Logout
    delete(TICKETS_URL, People.DEFAULT_USER, null, header, TICKETS_API_NAME, 204);
    // Get children of user2 home folder - invalidated ticket
    getAll(getNodeChildrenUrl(Nodes.PATH_MY), paging, null, header, 401);
}
Also used : LoginTicketResponse(org.alfresco.rest.api.model.LoginTicketResponse) Paging(org.alfresco.rest.api.tests.client.PublicApiClient.Paging) HttpResponse(org.alfresco.rest.api.tests.client.HttpResponse) Folder(org.alfresco.rest.api.tests.client.data.Folder) Document(org.alfresco.rest.api.tests.client.data.Document) LoginTicket(org.alfresco.rest.api.model.LoginTicket) Test(org.junit.Test) AbstractSingleNetworkSiteTest(org.alfresco.rest.AbstractSingleNetworkSiteTest)

Example 33 with Folder

use of org.alfresco.rest.api.tests.client.data.Folder in project alfresco-remote-api by Alfresco.

the class ActivitiesPostingTest method testCreateUpdate.

/**
 * Tests the main activites, added, updated, deleted, downloaded
 */
@Test
public void testCreateUpdate() throws Exception {
    setRequestContext(user1);
    List<Activity> activities = getMyActivities();
    int beforeCount = activities.size();
    String folder1 = "folder" + System.currentTimeMillis() + "_1";
    Folder createdFolder = createFolder(tDocLibNodeId, folder1, null);
    assertNotNull(createdFolder);
    String f1Id = createdFolder.getId();
    String docName = "d1.txt";
    Document documentResp = createEmptyTextFile(f1Id, docName);
    // Update the file
    Document dUpdate = new Document();
    dUpdate.setName("d1b.txt");
    put(URL_NODES, documentResp.getId(), toJsonAsStringNonNull(dUpdate), null, 200);
    // Now download it
    HttpResponse response = getSingle(NodesEntityResource.class, documentResp.getId() + "/content", null, 200);
    String textContent = response.getResponse();
    assertNotNull(textContent);
    deleteNode(documentResp.getId());
    deleteNode(createdFolder.getId());
    activities = getMyActivities();
    assertEquals(beforeCount + 6, activities.size());
    Activity act = matchActivity(activities, ActivityType.FOLDER_ADDED, user1, tSiteId, tDocLibNodeId, folder1);
    assertNotNull(act);
    act = matchActivity(activities, ActivityType.FILE_ADDED, user1, tSiteId, createdFolder.getId(), docName);
    assertNotNull(act);
    act = matchActivity(activities, ActivityType.FILE_UPDATED, user1, tSiteId, createdFolder.getId(), dUpdate.getName());
    assertNotNull(act);
    act = matchActivity(activities, ActivityType.FOLDER_DELETED, user1, tSiteId, tDocLibNodeId, folder1);
    assertNotNull(act);
    act = matchActivity(activities, ActivityType.FILE_DELETED, user1, tSiteId, createdFolder.getId(), dUpdate.getName());
    assertNotNull(act);
    act = matchActivity(activities, ActivityPoster.DOWNLOADED, user1, tSiteId, createdFolder.getId(), dUpdate.getName());
    assertNotNull(act);
}
Also used : Activity(org.alfresco.rest.api.tests.client.data.Activity) HttpResponse(org.alfresco.rest.api.tests.client.HttpResponse) Folder(org.alfresco.rest.api.tests.client.data.Folder) Document(org.alfresco.rest.api.tests.client.data.Document) Test(org.junit.Test) AbstractSingleNetworkSiteTest(org.alfresco.rest.AbstractSingleNetworkSiteTest)

Example 34 with Folder

use of org.alfresco.rest.api.tests.client.data.Folder in project alfresco-remote-api by Alfresco.

the class DeletedNodesTest method testListRenditions.

/**
 * Test retrieve renditions for deleted nodes
 * <p>post:</p>
 * {@literal <host>:<port>/alfresco/api/-default-/public/alfresco/versions/1/deleted-nodes/<nodeId>/renditions}
 * {@literal <host>:<port>/alfresco/api/-default-/public/alfresco/versions/1/deleted-nodes/<nodeId>/rendition/<renditionId>}
 */
@Test
public void testListRenditions() throws Exception {
    setRequestContext(user1);
    Date now = new Date();
    String folder1 = "folder" + now.getTime() + "_1";
    Folder createdFolder = createFolder(tDocLibNodeId, folder1, null);
    assertNotNull(createdFolder);
    String f1Id = createdFolder.getId();
    // Create multipart request
    String fileName = "quick.pdf";
    File file = getResourceFile(fileName);
    MultiPartBuilder multiPartBuilder = MultiPartBuilder.create().setFileData(new MultiPartBuilder.FileData(fileName, file));
    MultiPartBuilder.MultiPartRequest reqBody = multiPartBuilder.build();
    // Upload quick.pdf file into the folder previously created
    HttpResponse response = post(getNodeChildrenUrl(f1Id), reqBody.getBody(), null, reqBody.getContentType(), 201);
    Document document = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
    String contentNodeId = document.getId();
    // create doclib rendition and move node to trashcan
    createAndGetRendition(contentNodeId, "doclib");
    deleteNode(contentNodeId);
    // List all renditions and check for results
    PublicApiClient.Paging paging = getPaging(0, 50);
    response = getAll(getDeletedNodeRenditionsUrl(contentNodeId), paging, 200);
    List<Rendition> renditions = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Rendition.class);
    assertTrue(renditions.size() >= 3);
    // +ve test - get previously created 'doclib' rendition
    response = getSingle(getDeletedNodeRenditionsUrl(contentNodeId), "doclib", 200);
    Rendition doclibRendition = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Rendition.class);
    assertNotNull(doclibRendition);
    assertEquals(Rendition.RenditionStatus.CREATED, doclibRendition.getStatus());
    ContentInfo contentInfo = doclibRendition.getContent();
    assertNotNull(contentInfo);
    assertEquals(MimetypeMap.MIMETYPE_IMAGE_PNG, contentInfo.getMimeType());
    assertEquals("PNG Image", contentInfo.getMimeTypeName());
    assertNotNull(contentInfo.getEncoding());
    assertTrue(contentInfo.getSizeInBytes() > 0);
    // +ve test - Add a filter on rendition 'status' and list only 'NOT_CREATED' renditions
    Map<String, String> params = new HashMap<>(1);
    params.put("where", "(status='NOT_CREATED')");
    response = getAll(getDeletedNodeRenditionsUrl(contentNodeId), paging, params, 200);
    renditions = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Rendition.class);
    assertTrue(renditions.size() >= 2);
    // +ve test - Add a filter on rendition 'status' and list only the CREATED renditions
    params.put("where", "(status='CREATED')");
    response = getAll(getDeletedNodeRenditionsUrl(contentNodeId), paging, params, 200);
    renditions = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Rendition.class);
    assertEquals("Only 'doclib' rendition should be returned.", 1, renditions.size());
    // SkipCount=0,MaxItems=2
    paging = getPaging(0, 2);
    // List all available renditions
    response = getAll(getDeletedNodeRenditionsUrl(contentNodeId), paging, 200);
    renditions = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Rendition.class);
    assertEquals(2, renditions.size());
    PublicApiClient.ExpectedPaging expectedPaging = RestApiUtil.parsePaging(response.getJsonResponse());
    assertEquals(2, expectedPaging.getCount().intValue());
    assertEquals(0, expectedPaging.getSkipCount().intValue());
    assertEquals(2, expectedPaging.getMaxItems().intValue());
    assertTrue(expectedPaging.getTotalItems() >= 3);
    assertTrue(expectedPaging.getHasMoreItems());
    // SkipCount=1,MaxItems=3
    paging = getPaging(1, 3);
    // List all available renditions
    response = getAll(getDeletedNodeRenditionsUrl(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(1, expectedPaging.getSkipCount().intValue());
    assertEquals(3, expectedPaging.getMaxItems().intValue());
    assertTrue(expectedPaging.getTotalItems() >= 3);
    // +ve test - Test returned renditions are ordered (natural sort order)
    response = getAll(getDeletedNodeRenditionsUrl(contentNodeId), paging, params, 200);
    renditions = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Rendition.class);
    assertTrue(Ordering.natural().isOrdered(renditions));
    // Check again to make sure the ordering wasn't coincidental
    response = getAll(getDeletedNodeRenditionsUrl(contentNodeId), paging, params, 200);
    renditions = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Rendition.class);
    assertTrue(Ordering.natural().isOrdered(renditions));
    // -ve - nodeId in the path parameter does not exist
    getAll(getDeletedNodeRenditionsUrl(UUID.randomUUID().toString()), paging, params, 404);
    // -ve test - Create an empty text file
    Document emptyDoc = createEmptyTextFile(f1Id, "d1.txt");
    getAll(getDeletedNodeRenditionsUrl(emptyDoc.getId()), paging, params, 404);
    // -ve - nodeId in the path parameter does not represent a file
    deleteNode(f1Id);
    getAll(getDeletedNodeRenditionsUrl(f1Id), paging, params, 400);
    // -ve - Invalid status value
    params.put("where", "(status='WRONG')");
    getAll(getDeletedNodeRenditionsUrl(contentNodeId), paging, params, 400);
    // -ve - Invalid filter (only 'status' is supported)
    params.put("where", "(id='doclib')");
    getAll(getDeletedNodeRenditionsUrl(contentNodeId), paging, params, 400);
    // -ve test - Authentication failed
    setRequestContext(null);
    getAll(getDeletedNodeRenditionsUrl(contentNodeId), paging, params, 401);
    // -ve - Current user does not have permission for nodeId
    setRequestContext(user2);
    getAll(getDeletedNodeRenditionsUrl(contentNodeId), paging, params, 403);
    // Test get single node rendition
    setRequestContext(user1);
    // -ve - nodeId in the path parameter does not exist
    getSingle(getDeletedNodeRenditionsUrl(UUID.randomUUID().toString()), "doclib", 404);
    // -ve - renditionId in the path parameter is not registered/available
    getSingle(getNodeRenditionsUrl(contentNodeId), ("renditionId" + System.currentTimeMillis()), 404);
    // -ve - nodeId in the path parameter does not represent a file
    getSingle(getDeletedNodeRenditionsUrl(f1Id), "doclib", 400);
    // -ve test - Authentication failed
    setRequestContext(null);
    getSingle(getDeletedNodeRenditionsUrl(contentNodeId), "doclib", 401);
    // -ve - Current user does not have permission for nodeId
    setRequestContext(user2);
    getSingle(getDeletedNodeRenditionsUrl(contentNodeId), "doclib", 403);
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Rendition(org.alfresco.rest.api.tests.client.data.Rendition) HttpResponse(org.alfresco.rest.api.tests.client.HttpResponse) Folder(org.alfresco.rest.api.tests.client.data.Folder) Document(org.alfresco.rest.api.tests.client.data.Document) Date(java.util.Date) MultiPartBuilder(org.alfresco.rest.api.tests.util.MultiPartBuilder) ContentInfo(org.alfresco.rest.api.tests.client.data.ContentInfo) PublicApiClient(org.alfresco.rest.api.tests.client.PublicApiClient) File(java.io.File) Test(org.junit.Test)

Example 35 with Folder

use of org.alfresco.rest.api.tests.client.data.Folder in project alfresco-remote-api by Alfresco.

the class DeletedNodesTest method testCreateAndPurge.

/**
 * Tests purging a deleted node
 * <p>delete:</p>
 * {@literal <host>:<port>/alfresco/api/-default-/public/alfresco/versions/1/deleted-nodes/<nodeId>/}
 */
@Test
public void testCreateAndPurge() throws Exception {
    setRequestContext(user1);
    Date now = new Date();
    String folder1 = "folder" + now.getTime() + "_1";
    Folder createdFolder = createFolder(tDocLibNodeId, folder1, null);
    assertNotNull(createdFolder);
    deleteNode(createdFolder.getId());
    HttpResponse response = getSingle(URL_DELETED_NODES, createdFolder.getId(), 200);
    Folder fNode = jacksonUtil.parseEntry(response.getJsonResponse(), Folder.class);
    assertNotNull(fNode);
    // try purging "nonsense"
    delete(URL_DELETED_NODES, "nonsense", 404);
    // User 2 can't do it
    setRequestContext(user2);
    delete(URL_DELETED_NODES, createdFolder.getId(), Status.STATUS_FORBIDDEN);
    setRequestContext(user1);
    // Now purge the folder
    delete(URL_DELETED_NODES, createdFolder.getId(), 204);
    // This time we can't find it.
    getSingle(URL_DELETED_NODES, createdFolder.getId(), 404);
}
Also used : HttpResponse(org.alfresco.rest.api.tests.client.HttpResponse) Folder(org.alfresco.rest.api.tests.client.data.Folder) Date(java.util.Date) Test(org.junit.Test)

Aggregations

Folder (org.alfresco.rest.api.tests.client.data.Folder)37 Test (org.junit.Test)34 HttpResponse (org.alfresco.rest.api.tests.client.HttpResponse)31 Document (org.alfresco.rest.api.tests.client.data.Document)29 AbstractSingleNetworkSiteTest (org.alfresco.rest.AbstractSingleNetworkSiteTest)28 HashMap (java.util.HashMap)20 LinkedHashMap (java.util.LinkedHashMap)19 NodesEntityResource (org.alfresco.rest.api.nodes.NodesEntityResource)12 Node (org.alfresco.rest.api.tests.client.data.Node)12 JSONObject (org.json.simple.JSONObject)10 Paging (org.alfresco.rest.api.tests.client.PublicApiClient.Paging)8 ContentInfo (org.alfresco.rest.api.tests.client.data.ContentInfo)8 ArrayList (java.util.ArrayList)7 File (java.io.File)6 PublicApiClient (org.alfresco.rest.api.tests.client.PublicApiClient)6 UserInfo (org.alfresco.rest.api.tests.client.data.UserInfo)6 Date (java.util.Date)5 MultiValueMap (org.apache.commons.collections.map.MultiValueMap)5 RandomAccessFile (java.io.RandomAccessFile)4 Map (java.util.Map)4