Search in sources :

Example 21 with HttpResponse

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

the class NodeApiTest method createDocument.

/**
 * Created an empty document in the given url path
 *
 * @param url
 * @return
 * @throws Exception
 */
private String createDocument(String url) throws Exception {
    Document d1 = new Document();
    d1.setName("testDoc" + GUID.generate());
    d1.setNodeType(TYPE_CM_CONTENT);
    HttpResponse response = post(url, toJsonAsStringNonNull(d1), 201);
    Document documentResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
    return documentResp.getId();
}
Also used : HttpResponse(org.alfresco.rest.api.tests.client.HttpResponse) Document(org.alfresco.rest.api.tests.client.data.Document)

Example 22 with HttpResponse

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

the class NodeApiTest method testUpdatePermissionsDefaultInheritFromParent.

/**
 * Test default inherit from parent
 *
 * @throws Exception
 */
private void testUpdatePermissionsDefaultInheritFromParent() throws Exception {
    // create folder
    Folder folder = new Folder();
    folder.setName("testFolder" + GUID.generate());
    folder.setNodeType(TYPE_CM_FOLDER);
    // set permissions on previously created folder
    NodePermissions nodePermissions = new NodePermissions();
    List<NodePermissions.NodePermission> locallySetPermissions = new ArrayList<>();
    locallySetPermissions.add(new NodePermissions.NodePermission(groupA, PermissionService.EDITOR, AccessStatus.DENIED.toString()));
    nodePermissions.setLocallySet(locallySetPermissions);
    folder.setPermissions(nodePermissions);
    HttpResponse response = post(getNodeChildrenUrl(Nodes.PATH_MY), RestApiUtil.toJsonAsStringNonNull(folder), 201);
    Folder f = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Folder.class);
    // create a new document in testFolder
    String docId = createDocument(getNodeChildrenUrl(f.getId()));
    Map params = new HashMap<>();
    params.put("include", "permissions");
    response = getSingle(NodesEntityResource.class, docId, params, 200);
    Document docResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
    assertTrue("Inheritance hasn't been enabled!", docResp.getPermissions().getIsInheritanceEnabled());
    assertTrue("Permissions were not inherited from parent!", docResp.getPermissions().getInherited().size() > 0);
}
Also used : NodePermissions(org.alfresco.rest.api.model.NodePermissions) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) HttpResponse(org.alfresco.rest.api.tests.client.HttpResponse) NodesEntityResource(org.alfresco.rest.api.nodes.NodesEntityResource) Folder(org.alfresco.rest.api.tests.client.data.Folder) Document(org.alfresco.rest.api.tests.client.data.Document) Map(java.util.Map) MimetypeMap(org.alfresco.repo.content.MimetypeMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Example 23 with HttpResponse

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

the class NodeApiTest method testAllowableOps.

/**
 * Tests optional lookup of Allowable Operations (eg. when getting node info, listing node children, ...)
 *
 * <p>GET:</p>
 * {@literal <host>:<port>/alfresco/api/-default-/public/alfresco/versions/1/nodes/<nodeId>/children?include=allowableOperations}
 * {@literal <host>:<port>/alfresco/api/-default-/public/alfresco/versions/1/nodes/<nodeId>?include=allowableOperations}
 */
@Test
public void testAllowableOps() throws Exception {
    // as user1 ...
    setRequestContext(user1);
    String rootNodeId = getRootNodeId();
    String sharedNodeId = getSharedNodeId();
    Map params = new HashMap<>();
    params.put(Nodes.PARAM_RELATIVE_PATH, "/Sites");
    HttpResponse response = getSingle(NodesEntityResource.class, rootNodeId, params, 200);
    Node nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
    String sitesNodeId = nodeResp.getId();
    params = new HashMap<>();
    params.put(Nodes.PARAM_RELATIVE_PATH, "/Data Dictionary");
    response = getSingle(NodesEntityResource.class, rootNodeId, params, 200);
    nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
    String ddNodeId = nodeResp.getId();
    params = new HashMap<>();
    params.put("include", "allowableOperations");
    response = getSingle(NodesEntityResource.class, rootNodeId, params, 200);
    nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
    assertNull(nodeResp.getAllowableOperations());
    response = getSingle(NodesEntityResource.class, sharedNodeId, params, 200);
    nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
    assertNotNull(nodeResp.getAllowableOperations());
    assertEquals(1, nodeResp.getAllowableOperations().size());
    assertTrue(nodeResp.getAllowableOperations().contains(Nodes.OP_CREATE));
    // -ve
    deleteNode(sharedNodeId, 403);
    response = getSingle(NodesEntityResource.class, getMyNodeId(), params, 200);
    nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
    assertNotNull(nodeResp.getAllowableOperations());
    assertEquals(4, nodeResp.getAllowableOperations().size());
    assertTrue(nodeResp.getAllowableOperations().contains(Nodes.OP_DELETE));
    assertTrue(nodeResp.getAllowableOperations().contains(Nodes.OP_CREATE));
    assertTrue(nodeResp.getAllowableOperations().contains(Nodes.OP_UPDATE));
    assertTrue(nodeResp.getAllowableOperations().contains(Nodes.OP_UPDATE_PERMISSIONS));
    // create folder
    nodeResp = createFolder(sharedNodeId, "folder 1 - " + RUNID);
    String folderId = nodeResp.getId();
    assertNull(nodeResp.getAllowableOperations());
    response = getSingle(NodesEntityResource.class, folderId, null, 200);
    nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
    assertNull(nodeResp.getAllowableOperations());
    response = getSingle(NodesEntityResource.class, folderId, params, 200);
    nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
    assertNotNull(nodeResp.getAllowableOperations());
    assertEquals(4, nodeResp.getAllowableOperations().size());
    assertTrue(nodeResp.getAllowableOperations().contains(Nodes.OP_DELETE));
    assertTrue(nodeResp.getAllowableOperations().contains(Nodes.OP_CREATE));
    assertTrue(nodeResp.getAllowableOperations().contains(Nodes.OP_UPDATE));
    assertTrue(nodeResp.getAllowableOperations().contains(Nodes.OP_UPDATE_PERMISSIONS));
    // create file
    nodeResp = createTextFile(folderId, "my file - " + RUNID + ".txt", "The quick brown fox jumps over the lazy dog");
    String fileId = nodeResp.getId();
    assertNull(nodeResp.getAllowableOperations());
    response = getSingle(NodesEntityResource.class, fileId, null, 200);
    nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
    assertNull(nodeResp.getAllowableOperations());
    // a file - no create
    response = getSingle(NodesEntityResource.class, fileId, params, 200);
    nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
    assertNotNull(nodeResp.getAllowableOperations());
    assertEquals(3, nodeResp.getAllowableOperations().size());
    assertTrue(nodeResp.getAllowableOperations().contains(Nodes.OP_DELETE));
    assertTrue(nodeResp.getAllowableOperations().contains(Nodes.OP_UPDATE));
    assertTrue(nodeResp.getAllowableOperations().contains(Nodes.OP_UPDATE_PERMISSIONS));
    // as user2 ...
    setRequestContext(user2);
    response = getSingle(NodesEntityResource.class, folderId, params, 200);
    nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
    assertNotNull(nodeResp.getAllowableOperations());
    assertEquals(1, nodeResp.getAllowableOperations().size());
    assertTrue(nodeResp.getAllowableOperations().contains(Nodes.OP_CREATE));
    // -ve
    deleteNode(folderId, 403);
    response = getSingle(NodesEntityResource.class, fileId, params, 200);
    nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
    assertNull(nodeResp.getAllowableOperations());
    // -ve
    deleteNode(fileId, 403);
    // as admin ...
    setRequestContext(networkAdmin);
    response = publicApiClient.get(NodesEntityResource.class, folderId, null, params);
    nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
    assertNotNull(nodeResp.getAllowableOperations());
    assertEquals(4, nodeResp.getAllowableOperations().size());
    assertTrue(nodeResp.getAllowableOperations().contains(Nodes.OP_DELETE));
    assertTrue(nodeResp.getAllowableOperations().contains(Nodes.OP_CREATE));
    assertTrue(nodeResp.getAllowableOperations().contains(Nodes.OP_UPDATE));
    assertTrue(nodeResp.getAllowableOperations().contains(Nodes.OP_UPDATE_PERMISSIONS));
    // a file - no create
    response = publicApiClient.get(NodesEntityResource.class, fileId, null, params);
    nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
    assertNotNull(nodeResp.getAllowableOperations());
    assertEquals(3, nodeResp.getAllowableOperations().size());
    assertTrue(nodeResp.getAllowableOperations().contains(Nodes.OP_DELETE));
    assertTrue(nodeResp.getAllowableOperations().contains(Nodes.OP_UPDATE));
    assertTrue(nodeResp.getAllowableOperations().contains(Nodes.OP_UPDATE_PERMISSIONS));
    response = publicApiClient.get(NodesEntityResource.class, sharedNodeId, null, params);
    nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
    assertNotNull(nodeResp.getAllowableOperations());
    assertEquals(4, nodeResp.getAllowableOperations().size());
    assertTrue(nodeResp.getAllowableOperations().contains(Nodes.OP_CREATE));
    assertTrue(nodeResp.getAllowableOperations().contains(Nodes.OP_UPDATE));
    assertTrue(nodeResp.getAllowableOperations().contains(Nodes.OP_DELETE));
    assertTrue(nodeResp.getAllowableOperations().contains(Nodes.OP_UPDATE_PERMISSIONS));
    // Company Home - no delete
    response = publicApiClient.get(NodesEntityResource.class, rootNodeId, null, params);
    nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
    assertNotNull(nodeResp.getAllowableOperations());
    assertEquals(3, nodeResp.getAllowableOperations().size());
    assertTrue(nodeResp.getAllowableOperations().contains(Nodes.OP_CREATE));
    assertTrue(nodeResp.getAllowableOperations().contains(Nodes.OP_UPDATE));
    assertTrue(nodeResp.getAllowableOperations().contains(Nodes.OP_UPDATE_PERMISSIONS));
    // -ve
    deleteNode(rootNodeId, 403);
    // Sites - no delete
    response = publicApiClient.get(NodesEntityResource.class, sitesNodeId, null, params);
    nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
    assertNotNull(nodeResp.getAllowableOperations());
    assertEquals(3, nodeResp.getAllowableOperations().size());
    assertTrue(nodeResp.getAllowableOperations().contains(Nodes.OP_CREATE));
    assertTrue(nodeResp.getAllowableOperations().contains(Nodes.OP_UPDATE));
    assertTrue(nodeResp.getAllowableOperations().contains(Nodes.OP_UPDATE_PERMISSIONS));
    // -ve
    deleteNode(sitesNodeId, 403);
    // Data Dictionary - no delete
    response = publicApiClient.get(NodesEntityResource.class, ddNodeId, null, params);
    nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
    assertNotNull(nodeResp.getAllowableOperations());
    assertEquals(3, nodeResp.getAllowableOperations().size());
    assertTrue(nodeResp.getAllowableOperations().contains(Nodes.OP_CREATE));
    assertTrue(nodeResp.getAllowableOperations().contains(Nodes.OP_UPDATE));
    assertTrue(nodeResp.getAllowableOperations().contains(Nodes.OP_UPDATE_PERMISSIONS));
    // -ve
    deleteNode(ddNodeId, 403);
    publicApiClient.setRequestContext(null);
    // as user1 ...
    String userId = user1;
    setRequestContext(userId);
    response = getSingle("sites", tSiteId, null, null, 200);
    Site siteResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Site.class);
    String siteNodeId = siteResp.getGuid();
    response = getSingle(NodesEntityResource.class, siteNodeId, params, 200);
    nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
    assertEquals(userId, nodeResp.getCreatedByUser().getId());
    assertNotNull(nodeResp.getAllowableOperations());
    assertEquals(3, nodeResp.getAllowableOperations().size());
    assertTrue(nodeResp.getAllowableOperations().contains(Nodes.OP_CREATE));
    assertTrue(nodeResp.getAllowableOperations().contains(Nodes.OP_UPDATE));
    assertTrue(nodeResp.getAllowableOperations().contains(Nodes.OP_UPDATE_PERMISSIONS));
    // -ve
    deleteNode(siteNodeId, 403);
    setRequestContext(user1);
    // fix for REPO-514 (NPE for a node that was neither a file/document nor a folder)
    Node n = new Node();
    n.setName("o1");
    n.setNodeType(TYPE_CM_OBJECT);
    response = post(getNodeChildrenUrl(folderId), toJsonAsStringNonNull(n), 201);
    nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
    String o1Id = nodeResp.getId();
    params = new HashMap<>();
    params.put("include", "allowableOperations");
    response = getSingle(NodesEntityResource.class, o1Id, params, 200);
    nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
    assertNotNull(nodeResp.getAllowableOperations());
    // some cleanup
    deleteNode(folderId, true, 204);
}
Also used : Site(org.alfresco.rest.api.model.Site) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Node(org.alfresco.rest.api.tests.client.data.Node) HttpResponse(org.alfresco.rest.api.tests.client.HttpResponse) NodesEntityResource(org.alfresco.rest.api.nodes.NodesEntityResource) Map(java.util.Map) MimetypeMap(org.alfresco.repo.content.MimetypeMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test) AbstractSingleNetworkSiteTest(org.alfresco.rest.AbstractSingleNetworkSiteTest)

Example 24 with HttpResponse

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

the class NodeApiTest method testUploadUsingRelativePath.

/**
 * Test upload using relativePath
 */
@Test
public void testUploadUsingRelativePath() throws Exception {
    setRequestContext(user1);
    // user1 creates a private site and adds user2 as a site consumer
    String site1Title = "site-testGetPathElements_DocLib-" + RUNID;
    String site1Id = createSite(site1Title, SiteVisibility.PRIVATE).getId();
    addSiteMember(site1Id, user2, SiteRole.SiteConsumer);
    String site1DocLibNodeId = getSiteContainerNodeId(site1Id, "documentLibrary");
    // /Company
    // Home/Sites/RandomSite<timestamp>/documentLibrary/folder<timestamp>_A
    String folderA = "folder" + RUNID + "_A";
    String folderA_Id = createFolder(site1DocLibNodeId, folderA).getId();
    // /Company
    // Home/Sites/RandomSite<timestamp>/documentLibrary/folder<timestamp>_A/folder<timestamp>_B
    String folderB = "folder" + RUNID + "_B";
    String folderB_Id = createFolder(folderA_Id, folderB).getId();
    NodeRef folderB_Ref = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, folderB_Id);
    // /Company
    // Home/Sites/RandomSite<timestamp>/documentLibrary/folder<timestamp>_A/folder<timestamp>_B/folder<timestamp>_C
    String folderC = "folder" + RUNID + "_C";
    String folderC_Id = createFolder(folderB_Id, folderC).getId();
    NodeRef folderC_Ref = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, folderC_Id);
    // /Company
    // Home/Sites/RandomSite<timestamp>/documentLibrary/folder<timestamp>_A/folder<timestamp>_B/folder<timestamp>_C/content<timestamp>
    String content = "content" + RUNID;
    String content_Id = createTextFile(folderC_Id, content, "The quick brown fox jumps over the lazy dog.").getId();
    Map<String, String> params = new HashMap<>();
    params.put("include", "path");
    params.put("relativePath", folderA + "/" + folderB + "/" + folderC);
    // call get with relativePathParam
    HttpResponse response = getAll(getNodeChildrenUrl(site1DocLibNodeId), null, params, 200);
    List<Node> nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
    assertEquals(1, nodes.size());
    assertEquals("/" + folderA + "/" + folderB + "/" + folderC, ((Node) (nodes.get(0))).getPath().getRelativePath());
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Node(org.alfresco.rest.api.tests.client.data.Node) HttpResponse(org.alfresco.rest.api.tests.client.HttpResponse) Test(org.junit.Test) AbstractSingleNetworkSiteTest(org.alfresco.rest.AbstractSingleNetworkSiteTest)

Example 25 with HttpResponse

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

the class NodeApiTest method getSitesNodeId.

private String getSitesNodeId() throws Exception {
    Map params = new HashMap<>();
    params.put(Nodes.PARAM_RELATIVE_PATH, "/Sites");
    HttpResponse response = getSingle(NodesEntityResource.class, getRootNodeId(), params, 200);
    Node nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
    return nodeResp.getId();
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Node(org.alfresco.rest.api.tests.client.data.Node) HttpResponse(org.alfresco.rest.api.tests.client.HttpResponse) Map(java.util.Map) MimetypeMap(org.alfresco.repo.content.MimetypeMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

HttpResponse (org.alfresco.rest.api.tests.client.HttpResponse)162 Test (org.junit.Test)114 HashMap (java.util.HashMap)59 AbstractSingleNetworkSiteTest (org.alfresco.rest.AbstractSingleNetworkSiteTest)50 Document (org.alfresco.rest.api.tests.client.data.Document)49 Node (org.alfresco.rest.api.tests.client.data.Node)49 LinkedHashMap (java.util.LinkedHashMap)31 ArrayList (java.util.ArrayList)29 Paging (org.alfresco.rest.api.tests.client.PublicApiClient.Paging)27 Folder (org.alfresco.rest.api.tests.client.data.Folder)26 File (java.io.File)25 NodesEntityResource (org.alfresco.rest.api.nodes.NodesEntityResource)25 RequestContext (org.alfresco.rest.api.tests.client.RequestContext)22 CustomModel (org.alfresco.rest.api.model.CustomModel)16 ContentInfo (org.alfresco.rest.api.tests.client.data.ContentInfo)15 MultiPartBuilder (org.alfresco.rest.api.tests.util.MultiPartBuilder)15 JSONObject (org.json.simple.JSONObject)15 NodeRef (org.alfresco.service.cmr.repository.NodeRef)14 Map (java.util.Map)13 CustomAspect (org.alfresco.rest.api.model.CustomAspect)13