use of org.alfresco.rest.api.tests.client.HttpResponse in project alfresco-remote-api by Alfresco.
the class NodeApiTest method testLock.
/**
* Tests lock of a node
* <p>POST:</p>
* {@literal <host>:<port>/alfresco/api/-default-/public/alfresco/versions/1/nodes/<nodeId>/lock}
*/
@Test
public void testLock() throws Exception {
setRequestContext(user1);
// create folder
Folder folderResp = createFolder(Nodes.PATH_MY, "folder" + RUNID);
String folderId = folderResp.getId();
// try to lock the folder and check that is not allowed
LockInfo lockInfo = new LockInfo();
lockInfo.setTimeToExpire(60);
lockInfo.setType("FULL");
lockInfo.setLifetime("PERSISTENT");
HttpResponse response = post(getNodeOperationUrl(folderId, "lock"), toJsonAsStringNonNull(lockInfo), null, 400);
// create document d1
String d1Name = "content" + RUNID + "_1l";
Document d1 = createTextFile(folderId, d1Name, "The quick brown fox jumps over the lazy dog 1.");
String d1Id = d1.getId();
// lock d1 document
lockInfo = new LockInfo();
lockInfo.setTimeToExpire(30);
lockInfo.setType("FULL");
lockInfo.setLifetime("PERSISTENT");
response = post(getNodeOperationUrl(d1Id, "lock"), toJsonAsStringNonNull(lockInfo), null, 200);
Document documentResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
assertEquals(d1Name, documentResp.getName());
assertEquals(d1Id, documentResp.getId());
assertEquals(LockType.READ_ONLY_LOCK.toString(), documentResp.getProperties().get("cm:lockType"));
assertNotNull(documentResp.getProperties().get("cm:lockOwner"));
assertNull(documentResp.getIsLocked());
// invalid test - delete a locked node
deleteNode(d1Id, true, 409);
// wait for expiration time set to pass and delete node
TimeUnit.SECONDS.sleep(30);
deleteNode(d1Id, true, 204);
// create doc d2
String d2Name = "content" + RUNID + "_2l";
Document d2 = createTextFile(folderId, d2Name, "The quick brown fox jumps over the lazy dog 2.");
String d2Id = d2.getId();
response = getSingle(URL_NODES, d2Id, null, null, 200);
Node node = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
assertNull(node.getProperties().get("cm:lockType"));
assertNull(node.getProperties().get("cm:lockOwner"));
assertNull(node.getIsLocked());
Map<String, String> params = Collections.singletonMap("include", "isLocked");
response = getSingle(URL_NODES, d2Id, params, null, 200);
node = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
assertNull(node.getProperties().get("cm:lockType"));
assertNull(node.getProperties().get("cm:lockOwner"));
assertFalse(node.getIsLocked());
lockInfo = new LockInfo();
lockInfo.setTimeToExpire(60);
lockInfo.setType("FULL");
lockInfo.setLifetime("PERSISTENT");
response = post(getNodeOperationUrl(d2Id, "lock"), toJsonAsStringNonNull(lockInfo), null, 200);
documentResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
assertEquals(d2Name, documentResp.getName());
assertEquals(d2Id, documentResp.getId());
assertEquals(LockType.READ_ONLY_LOCK.toString(), documentResp.getProperties().get("cm:lockType"));
assertNotNull(documentResp.getProperties().get("cm:lockOwner"));
assertNull(documentResp.getIsLocked());
unlock(d2Id);
// Empty lock body, the default values are used
post(getNodeOperationUrl(d2Id, "lock"), EMPTY_BODY, null, 200);
// Lock on already locked node
post(getNodeOperationUrl(d2Id, "lock"), toJsonAsStringNonNull(lockInfo), null, 200);
// Test delete on a folder which contains a locked node - NodeLockedException
deleteNode(folderId, true, 409);
// Content update on a locked node
updateTextFile(d2Id, "Updated text", null, 409);
unlock(d2Id);
// Test lock file
// create folder
String folderAName = "folder" + RUNID + "_A";
Folder folderA = createFolder(Nodes.PATH_MY, folderAName);
String folderAId = folderA.getId();
// create a file in the folderA
Document dA1 = createTextFile(folderAId, "content" + RUNID + "_A1", "A1 content");
String dA1Id = dA1.getId();
lockInfo = new LockInfo();
lockInfo.setTimeToExpire(60);
lockInfo.setType("ALLOW_OWNER_CHANGES");
lockInfo.setLifetime("EPHEMERAL");
// lock the file
post(getNodeOperationUrl(dA1Id, "lock"), toJsonAsStringNonNull(lockInfo), null, 200);
params = Collections.singletonMap("include", "aspectNames,properties,isLocked");
response = getSingle(URL_NODES, dA1Id, params, null, 200);
node = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
assertTrue(node.getIsLocked());
// note: this can be updated by the owner since the lock type is "ALLOW_OWNER_CHANGES"
updateTextFile(node.getId(), "Updated text", null, 200);
// Lock body properties - boundary values
Document dB1 = createTextFile(folderAId, "content" + RUNID + "_dB1", "dB1 content");
String dB1Id = dB1.getId();
lockInfo = new LockInfo();
// values lower than 0 are considered as no expiry time
lockInfo.setTimeToExpire(-100);
post(getNodeOperationUrl(dB1Id, "lock"), toJsonAsStringNonNull(lockInfo), null, 200);
// Lock node by a different user than the owner
setRequestContext(user1);
Folder folder1Resp = createFolder(Nodes.PATH_SHARED, "folder1" + RUNID);
String folder1Id = folder1Resp.getId();
String f1d1Name = "content f1" + RUNID + "_1l";
Document f1d1 = createTextFile(folder1Id, f1d1Name, "The quick brown fox jumps over the lazy dog 1.");
String f1d1Id = f1d1.getId();
// use admin for now (might be better to use a user with given WRITE permission)
setRequestContext(networkAdmin);
post(getNodeOperationUrl(f1d1Id, "lock"), EMPTY_BODY, null, 200);
unlock(f1d1Id);
// -ve tests
// Missing target node
lockInfo = new LockInfo();
post(getNodeOperationUrl("fakeId", "lock"), toJsonAsStringNonNull(lockInfo), null, 404);
// Cannot lock Data Dictionary node
params = new HashMap<>();
params.put(Nodes.PARAM_RELATIVE_PATH, "/Data Dictionary");
response = getSingle(NodesEntityResource.class, getRootNodeId(), params, 200);
Node nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
String ddNodeId = nodeResp.getId();
setRequestContext(networkAdmin);
post(getNodeOperationUrl(ddNodeId, "lock"), toJsonAsStringNonNull(lockInfo), null, 403);
// Lock node already locked by another user - UnableToAquireLockException
post(getNodeOperationUrl(dB1Id, "lock"), EMPTY_BODY, null, 422);
// Lock node without permission (node created by user 1 in the Home folder)
setRequestContext(user1);
Folder folder2Resp = createFolder(Nodes.PATH_MY, "folder2" + RUNID);
String folder2Id = folder2Resp.getId();
String f2d1Name = "content f2" + RUNID + "_1l";
Document f2d1 = createTextFile(folder2Id, f2d1Name, "The quick brown fox jumps over the lazy dog 1.");
String f2d1Id = f2d1.getId();
setRequestContext(user2);
post(getNodeOperationUrl(f2d1Id, "lock"), EMPTY_BODY, null, 403);
// Invalid lock body values
setRequestContext(user1);
Folder folderC = createFolder(Nodes.PATH_MY, "folder" + RUNID + "_C");
String folderCId = folderC.getId();
Document dC1 = createTextFile(folderCId, "content" + RUNID + "_dC1", "dC1 content");
String dC1Id = dC1.getId();
Map<String, String> body = new HashMap<>();
body.put("type", "FULL123");
post(getNodeOperationUrl(dC1Id, "lock"), toJsonAsStringNonNull(body), null, 400);
body = new HashMap<>();
body.put("type", "ALLOW_ADD_CHILDREN");
post(getNodeOperationUrl(dC1Id, "lock"), toJsonAsStringNonNull(body), null, 400);
body = new HashMap<>();
body.put("lifetime", "PERSISTENT123");
post(getNodeOperationUrl(dC1Id, "lock"), toJsonAsStringNonNull(body), null, 400);
body = new HashMap<>();
body.put("includeChildren", "true");
post(getNodeOperationUrl(dC1Id, "lock"), toJsonAsStringNonNull(body), null, 400);
body = new HashMap<>();
body.put("timeToExpire", "NaN");
post(getNodeOperationUrl(dC1Id, "lock"), toJsonAsStringNonNull(body), null, 400);
body = new HashMap<>();
body.put("invalid_property", "true");
post(getNodeOperationUrl(dC1Id, "lock"), toJsonAsStringNonNull(body), null, 400);
// Invalid lock of a folder
post(getNodeOperationUrl(folderId, "lock"), toJsonAsStringNonNull(lockInfo), null, 400);
// cleanup
// all locks were made by user1
setRequestContext(user1);
unlock(dB1Id);
deleteNode(dB1Id);
deleteNode(folderId);
deleteNode(folderAId);
deleteNode(folderCId);
deleteNode(folder1Id);
deleteNode(folder2Id);
}
use of org.alfresco.rest.api.tests.client.HttpResponse in project alfresco-remote-api by Alfresco.
the class NodeApiTest method testGetNodeInfo.
/**
* Tests get node information.
* <p>GET:</p>
* {@literal <host>:<port>/alfresco/api/-default-/public/alfresco/versions/1/nodes/<nodeId>}
*/
@Test
public void testGetNodeInfo() throws Exception {
setRequestContext(user1);
HttpResponse response = getSingle(NodesEntityResource.class, Nodes.PATH_ROOT, null, 200);
Node node = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
String rootNodeId = node.getId();
response = getSingle(NodesEntityResource.class, Nodes.PATH_MY, null, 200);
node = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
String myFilesNodeId = node.getId();
assertNotNull(myFilesNodeId);
assertEquals(user1, node.getName());
assertTrue(node.getIsFolder());
assertFalse(node.getIsFile());
String userHomesId = node.getParentId();
// /Company Home/User Homes/user<timestamp>/folder<timestamp>_A
String folderA = "folder" + RUNID + "_A";
String folderA_Id = createFolder(myFilesNodeId, folderA).getId();
// /Company Home/User Homes/user<timestamp>/folder<timestamp>_A/folder<timestamp>_B
String folderB = "folder" + RUNID + "_B";
String folderB_Id = createFolder(folderA_Id, folderB).getId();
// /Company Home/User Homes/user<timestamp>/folder<timestamp>_A/folder<timestamp>_B/content<timestamp>
String title = "test title";
Map<String, String> docProps = new HashMap<>();
docProps.put("cm:title", title);
String contentName = "content " + RUNID + ".txt";
String content1Id = createTextFile(folderB_Id, contentName, "The quick brown fox jumps over the lazy dog.", "UTF-8", docProps).getId();
// get node info
response = getSingle(NodesEntityResource.class, content1Id, null, 200);
Document documentResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
String content_Id = documentResp.getId();
// Expected result ...
UserInfo expectedUser = new UserInfo(user1);
Document d1 = new Document();
d1.setId(content_Id);
d1.setParentId(folderB_Id);
d1.setName(contentName);
d1.setNodeType(TYPE_CM_CONTENT);
ContentInfo ciExpected = new ContentInfo();
ciExpected.setMimeType("text/plain");
ciExpected.setMimeTypeName("Plain Text");
ciExpected.setSizeInBytes(44L);
ciExpected.setEncoding("ISO-8859-1");
d1.setContent(ciExpected);
d1.setCreatedByUser(expectedUser);
d1.setModifiedByUser(expectedUser);
Map<String, Object> props = new HashMap<>();
props.put("cm:title", title);
props.put("cm:versionLabel", "1.0");
props.put("cm:versionType", "MAJOR");
d1.setProperties(props);
d1.setAspectNames(Arrays.asList("cm:auditable", "cm:titled", "cm:versionable", "cm:author"));
// Note: Path is not part of the default info
d1.expected(documentResp);
// get node info + path
// ...nodes/nodeId?include=path
Map<String, String> params = Collections.singletonMap("include", "path");
response = getSingle(NodesEntityResource.class, content1Id, params, 200);
documentResp = jacksonUtil.parseEntry(response.getJsonResponse(), Document.class);
// Expected path ...
// note: the pathInfo should only include the parents (not the requested node)
List<ElementInfo> elements = new ArrayList<>(5);
elements.add(new ElementInfo(rootNodeId, "Company Home"));
elements.add(new ElementInfo(userHomesId, "User Homes"));
elements.add(new ElementInfo(myFilesNodeId, user1));
elements.add(new ElementInfo(folderA_Id, folderA));
elements.add(new ElementInfo(folderB_Id, folderB));
PathInfo expectedPath = new PathInfo("/Company Home/User Homes/" + user1 + "/" + folderA + "/" + folderB, true, elements);
d1.setPath(expectedPath);
d1.expected(documentResp);
// get node info via relativePath
params = Collections.singletonMap(Nodes.PARAM_RELATIVE_PATH, "/" + folderA + "/" + folderB);
response = getSingle(NodesEntityResource.class, Nodes.PATH_MY, params, 200);
Folder folderResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Folder.class);
assertEquals(folderB_Id, folderResp.getId());
params = Collections.singletonMap(Nodes.PARAM_RELATIVE_PATH, folderA + "/" + folderB + "/" + contentName);
response = getSingle(NodesEntityResource.class, Nodes.PATH_MY, params, 200);
documentResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
assertEquals(content_Id, documentResp.getId());
// test path with utf-8 encoded param (eg. ¢ => )
String folderC = "folder" + RUNID + " ¢";
String folderC_Id = createFolder(folderB_Id, folderC).getId();
params = Collections.singletonMap(Nodes.PARAM_RELATIVE_PATH, "/" + folderA + "/" + folderB + "/" + folderC);
response = getSingle(NodesEntityResource.class, Nodes.PATH_MY, params, 200);
folderResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Folder.class);
assertEquals(folderC_Id, folderResp.getId());
// -ve test - get info for unknown node should return 404
getSingle(NodesEntityResource.class, UUID.randomUUID().toString(), null, 404);
// -ve test - user2 tries to get node info about user1's home folder
setRequestContext(user2);
getSingle(NodesEntityResource.class, myFilesNodeId, null, 403);
setRequestContext(user1);
// -ve test - try to get node info using relative path to unknown node
params = Collections.singletonMap(Nodes.PARAM_RELATIVE_PATH, folderA + "/unknown");
getSingle(NodesEntityResource.class, Nodes.PATH_MY, params, 404);
// -ve test - try to get node info 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);
getSingle(NodesEntityResource.class, Nodes.PATH_ROOT, params, 404);
// -ve test - attempt to get node info for non-folder node with relative path should return 400
params = Collections.singletonMap(Nodes.PARAM_RELATIVE_PATH, "/unknown");
getSingle(NodesEntityResource.class, content_Id, params, 400);
}
use of org.alfresco.rest.api.tests.client.HttpResponse in project alfresco-remote-api by Alfresco.
the class NodeApiTest method testDelete.
/**
* Tests delete (file or folder)
* <p>DELETE:</p>
* {@literal <host>:<port>/alfresco/api/-default-/public/alfresco/versions/1/nodes/<nodeId>}
*/
@Test
public void testDelete() throws Exception {
setRequestContext(user1);
// create folder f0
String folder0Name = "f0-testDelete-" + RUNID;
String f0Id = createFolder(Nodes.PATH_MY, folder0Name).getId();
String content1Id = createTextFile(f0Id, "content" + RUNID + "_1", "The quick brown fox jumps over the lazy dog.").getId();
// delete file
deleteNode(content1Id);
assertTrue(existsArchiveNode(content1Id));
// -ve test
deleteNode(content1Id, 404);
String folder1Id = createFolder(f0Id, "folder " + RUNID + "_1").getId();
String folder2Id = createFolder(folder1Id, "folder " + RUNID + "_2").getId();
String content2Id = createTextFile(folder2Id, "content" + RUNID + "_2", "The quick brown fox jumps over the lazy dog.").getId();
// cascade delete folder
deleteNode(folder1Id);
assertTrue(existsArchiveNode(folder1Id));
assertTrue(existsArchiveNode(folder2Id));
assertTrue(existsArchiveNode(content2Id));
// -ve test
deleteNode(folder2Id, 404);
deleteNode(content2Id, 404);
// -ve test
String rootNodeId = getRootNodeId();
deleteNode(rootNodeId, 403);
//
// permanently delete - ie. bypass trashcan (archive store)
//
String folder3Id = createFolder(f0Id, "folder " + RUNID + "_3").getId();
String folder4Id = createFolder(folder3Id, "folder " + RUNID + "_4").getId();
deleteNode(folder3Id, true, 204);
assertFalse(existsArchiveNode(folder3Id));
assertFalse(existsArchiveNode(folder4Id));
String sharedNodeId = getSharedNodeId();
final String folder5Id = createFolder(sharedNodeId, "folder " + RUNID + "_5").getId();
// -ve test - another user cannot delete
setRequestContext(user2);
deleteNode(folder5Id, 403);
setRequestContext(user1);
Map<String, Object> props = new HashMap<>();
props.put(PROP_OWNER, user2);
Node nUpdate = new Node();
nUpdate.setProperties(props);
HttpResponse response = put(URL_NODES, folder5Id, toJsonAsStringNonNull(nUpdate), null, 200);
Node nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
assertEquals(user2, ((Map) nodeResp.getProperties().get(PROP_OWNER)).get("id"));
// TODO see REPO-907. Apparently returns 204 here in tenant context ?? (eg. if useDefaultNetwork=false)
if (useDefaultNetwork) {
// -ve test - user1 can no longer delete
deleteNode(folder5Id, 403);
}
// TODO refactor with remote permission api calls (maybe use v0 until we have v1 ?)
final String tenantDomain = (networkOne != null ? networkOne.getId() : TenantService.DEFAULT_DOMAIN);
AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork<Void>() {
@Override
public Void doWork() throws Exception {
return TenantUtil.runAsTenant(new TenantUtil.TenantRunAsWork<Void>() {
public Void doWork() throws Exception {
permissionService.setPermission(new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, folder5Id), user1, PermissionService.DELETE, true);
return null;
}
}, tenantDomain);
}
}, user1);
// -ve test - non-owner cannot bypass trashcan
deleteNode(folder5Id, true, 403);
// user1 has permission to delete (via trashcan)
deleteNode(folder5Id);
// admin can permanently delete
String folder6Id = createFolder(sharedNodeId, "folder " + RUNID + "_6").getId();
setRequestContext(networkAdmin);
deleteNode(folder6Id, true, 204);
// -ve - cannot delete Company Home root node
deleteNode(rootNodeId, true, 403);
Map<String, String> params = new HashMap<>();
params.put(Nodes.PARAM_RELATIVE_PATH, "/Sites");
response = getSingle(NodesEntityResource.class, rootNodeId, params, 200);
nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
String sitesNodeId = nodeResp.getId();
// -ve - cannot delete Sites node
deleteNode(sitesNodeId, true, 403);
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();
// -ve - cannot delete Data Dictionary node
deleteNode(ddNodeId, true, 403);
}
use of org.alfresco.rest.api.tests.client.HttpResponse in project alfresco-remote-api by Alfresco.
the class NodeApiTest method testGetNodeWithKnownAlias.
/**
* Tests well-known aliases.
* <p>GET:</p>
* <ul>
* <li> {@literal <host>:<port>/alfresco/api/-default-/public/alfresco/versions/1/nodes/-root-}</li>
* <li> {@literal <host>:<port>/alfresco/api/-default-/public/alfresco/versions/1/nodes/-my-} </li>
* <li> {@literal <host>:<port>/alfresco/api/-default-/public/alfresco/versions/1/nodes/-shared-} </li>
* </ul>
*/
@Test
public void testGetNodeWithKnownAlias() throws Exception {
setRequestContext(user1);
HttpResponse response = getSingle(NodesEntityResource.class, Nodes.PATH_ROOT, null, 200);
Node node = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
assertEquals("Company Home", node.getName());
assertNotNull(node.getId());
assertNull(node.getPath());
// unknown alias
getSingle(NodesEntityResource.class, "testSomeUndefinedAlias", null, 404);
response = getSingle(NodesEntityResource.class, Nodes.PATH_MY, null, 200);
node = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
String myFilesNodeId = node.getId();
assertNotNull(myFilesNodeId);
assertEquals(user1, node.getName());
assertTrue(node.getIsFolder());
assertFalse(node.getIsFile());
// note: path can be optionally "include"'ed - see separate test
assertNull(node.getPath());
response = getSingle(NodesEntityResource.class, Nodes.PATH_SHARED, null, 200);
node = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
String sharedFilesNodeId = node.getId();
assertNotNull(sharedFilesNodeId);
assertEquals("Shared", node.getName());
assertTrue(node.getIsFolder());
assertFalse(node.getIsFile());
assertNull(node.getPath());
// Delete user1's home
setRequestContext(networkAdmin);
deleteNode(myFilesNodeId);
setRequestContext(user1);
// Not found
getSingle(NodesEntityResource.class, Nodes.PATH_MY, null, 404);
}
use of org.alfresco.rest.api.tests.client.HttpResponse in project alfresco-remote-api by Alfresco.
the class NodeApiTest method testMoveCopyBetweenSites.
/**
* Tests move and copy folder between sites.
*
* <p>POST:</p>
* {@literal <host>:<port>/alfresco/api/<networkId>/public/alfresco/versions/1/nodes/<nodeId>/move}
*
* <p>POST:</p>
* {@literal <host>:<port>/alfresco/api/<networkId>/public/alfresco/versions/1/nodes/<nodeId>/copy}
*/
@Test
public void testMoveCopyBetweenSites() throws Exception {
setRequestContext(user1);
/*
* Precondition - create two sites, invite users, create folders
*/
// user1 creates a public site and adds user2 as a site collaborator
String site1Title = "site-testMoveCopyBetweenSites1-" + RUNID;
final String site1Id = createSite(site1Title, SiteVisibility.PUBLIC).getId();
addSiteMember(site1Id, user2, SiteRole.SiteCollaborator);
// Get user1Site's docLib node id
final String user1SitetDocLibNodeId = getSiteContainerNodeId(site1Id, "documentLibrary");
// user1 creates a folder in the docLib of his site (user1Site)
String user1Folder = "folder" + RUNID + "_user1";
String user1FolderNodeId = createFolder(user1SitetDocLibNodeId, user1Folder, null).getId();
setRequestContext(user2);
// user2 creates a public site and adds user1 as a site collaborator
String site2Title = "site-testMoveCopyBetweenSites2--" + RUNID;
final String site2Id = createSite(site2Title, SiteVisibility.PUBLIC).getId();
addSiteMember(site2Id, user1, SiteRole.SiteCollaborator);
// Get user2Site's docLib node id
final String user2SitetDocLibNodeId = getSiteContainerNodeId(site2Id, "documentLibrary");
// user2 creates 2 folders within the docLib of the user1Site
String user2Folder1 = "folder1" + RUNID + "_user2";
String user2FolderNodeId = createFolder(user1SitetDocLibNodeId, user2Folder1, null).getId();
String user2Folder2 = "folder2" + RUNID + "_user2";
String user2Folder2NodeId = createFolder(user1SitetDocLibNodeId, user2Folder2, null).getId();
/*
* Test move between sites
*/
// user1 moves the folder created by user2 to the user2Site's docLib
setRequestContext(user1);
NodeTarget target = new NodeTarget();
target.setTargetParentId(user2SitetDocLibNodeId);
HttpResponse response = post("nodes/" + user2FolderNodeId + "/move", toJsonAsStringNonNull(target), null, 200);
Folder moveFolderResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Folder.class);
assertEquals(user2SitetDocLibNodeId, moveFolderResp.getParentId());
// user1 tries to undo the move (moves back the folder to its original place)
// as user1 is just a SiteCollaborator in the user2Site, he can't move the folder which he doesn't own - ACL access permission.
target = new NodeTarget();
target.setTargetParentId(user1SitetDocLibNodeId);
post("nodes/" + user2FolderNodeId + "/move", toJsonAsStringNonNull(target), null, 403);
// user1 moves the folder created by himself to the docLib of the user2Site
target = new NodeTarget();
target.setTargetParentId(user2SitetDocLibNodeId);
response = post("nodes/" + user1FolderNodeId + "/move", toJsonAsStringNonNull(target), null, 200);
moveFolderResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Folder.class);
assertEquals(user2SitetDocLibNodeId, moveFolderResp.getParentId());
// user1 tries to undo the move (moves back the folder to its original place)
// The undo should be successful as user1 owns the folder
target = new NodeTarget();
target.setTargetParentId(user1SitetDocLibNodeId);
response = post("nodes/" + user1FolderNodeId + "/move", toJsonAsStringNonNull(target), null, 200);
moveFolderResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Folder.class);
assertEquals(user1SitetDocLibNodeId, moveFolderResp.getParentId());
/*
* Test copy between sites
*/
// user1 copies the folder created by user2 to the user2Site's docLib
target = new NodeTarget();
target.setTargetParentId(user2SitetDocLibNodeId);
response = post("nodes/" + user2Folder2NodeId + "/copy", toJsonAsStringNonNull(target), null, 201);
Folder copyFolderResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Folder.class);
assertEquals(user2SitetDocLibNodeId, copyFolderResp.getParentId());
// user1 tries to undo the copy (hard deletes the created copy)
deleteNode(copyFolderResp.getId(), true, 204);
// Check it's deleted
getSingle("nodes", copyFolderResp.getId(), 404);
// cleanup
setRequestContext(user1);
deleteSite(site1Id, true, 204);
setRequestContext(user2);
deleteSite(site2Id, true, 204);
}
Aggregations