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();
}
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);
}
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);
}
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());
}
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();
}
Aggregations