mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
Merged 5.2.N (5.2.1) to HEAD (5.2)
129176 mmuller: Merged RETURN-OF-THE-API (5.2.0) to 5.2.N (5.2.1) 128601 jvonka: V1 REST API: cleanup and rationalise new api tests (re: remotable helpers & runAs user / admin) - round 3 REPO-113 (also relates to REPO-28, REPO-825) git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@129350 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -26,20 +26,9 @@
|
||||
|
||||
package org.alfresco.rest;
|
||||
|
||||
import static org.alfresco.rest.api.tests.util.RestApiUtil.toJsonAsStringNonNull;
|
||||
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.repo.transaction.RetryingTransactionHelper;
|
||||
import org.alfresco.rest.api.tests.AbstractBaseApiTest;
|
||||
import org.alfresco.rest.api.tests.RepoService;
|
||||
import org.alfresco.rest.api.tests.client.HttpResponse;
|
||||
import org.alfresco.rest.api.tests.client.data.ContentInfo;
|
||||
import org.alfresco.rest.api.tests.client.data.Document;
|
||||
import org.alfresco.rest.api.tests.client.data.Folder;
|
||||
import org.alfresco.rest.api.tests.util.JacksonUtil;
|
||||
import org.alfresco.rest.api.tests.util.RestApiUtil;
|
||||
import org.alfresco.rest.framework.jacksonextensions.JacksonHelper;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.security.MutableAuthenticationService;
|
||||
import org.alfresco.service.cmr.security.PersonService;
|
||||
import org.alfresco.service.cmr.site.SiteVisibility;
|
||||
@@ -48,39 +37,57 @@ import org.junit.Before;
|
||||
|
||||
/**
|
||||
* @author Gethin James
|
||||
* @author janv
|
||||
*/
|
||||
public class AbstractSingleNetworkSiteTest extends AbstractBaseApiTest
|
||||
{
|
||||
protected MutableAuthenticationService authenticationService;
|
||||
protected PersonService personService;
|
||||
|
||||
protected RepoService.TestNetwork networkOne;
|
||||
protected RepoService.TestPerson u1;
|
||||
protected String tSiteId;
|
||||
protected String tDocLibNodeId;
|
||||
|
||||
protected JacksonUtil jacksonUtil;
|
||||
|
||||
// TODO make this a runtime option to allow creation of non-default network
|
||||
protected final static boolean useDefaultNetwork = true;
|
||||
|
||||
@Override
|
||||
public String getScope()
|
||||
{
|
||||
return "public";
|
||||
}
|
||||
|
||||
@Override
|
||||
@Before
|
||||
public void setup() throws Exception
|
||||
{
|
||||
jacksonUtil = new JacksonUtil(applicationContext.getBean("jsonHelper", JacksonHelper.class));
|
||||
|
||||
// createTestData=false
|
||||
getTestFixture(false);
|
||||
|
||||
if (! useDefaultNetwork)
|
||||
{
|
||||
networkOne = getRepoService().createNetwork(this.getClass().getName().toLowerCase(), true);
|
||||
networkOne.create();
|
||||
}
|
||||
else
|
||||
{
|
||||
networkOne = getRepoService().getSystemNetwork();
|
||||
}
|
||||
|
||||
user1 = createUser("user1-" + RUNID, "user1Password", networkOne);
|
||||
user2 = createUser("user2-" + RUNID, "user2Password", networkOne);
|
||||
|
||||
// to enable admin access via test calls - eg. via PublicApiClient -> AbstractTestApi -> findUserByUserName
|
||||
getOrCreateUser("admin", "admin");
|
||||
|
||||
// used-by teardown to cleanup
|
||||
authenticationService = applicationContext.getBean("authenticationService", MutableAuthenticationService.class);
|
||||
personService = applicationContext.getBean("personService", PersonService.class);
|
||||
|
||||
jacksonUtil = new JacksonUtil(applicationContext.getBean("jsonHelper", JacksonHelper.class));
|
||||
users.add(user1);
|
||||
users.add(user2);
|
||||
|
||||
getTestFixture(false);
|
||||
networkOne = getRepoService().createNetwork(this.getClass().getName().toLowerCase(), true);
|
||||
networkOne.create();
|
||||
u1 = networkOne.createUser();
|
||||
|
||||
setRequestContext(networkOne.getId(), u1.getId(), null);
|
||||
setRequestContext(networkOne.getId(), user1, null);
|
||||
|
||||
tSiteId = createSite("Test Site - " + System.currentTimeMillis(), SiteVisibility.PRIVATE).getId();
|
||||
tDocLibNodeId = getSiteContainerNodeId(tSiteId, "documentLibrary");
|
||||
@@ -88,38 +95,13 @@ public class AbstractSingleNetworkSiteTest extends AbstractBaseApiTest
|
||||
setRequestContext(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@After
|
||||
public void tearDown() throws Exception
|
||||
{
|
||||
AuthenticationUtil.setAdminUserAsFullyAuthenticatedUser();
|
||||
transactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Void>()
|
||||
{
|
||||
@Override
|
||||
public Void execute() throws Throwable
|
||||
{
|
||||
if (personService.personExists(u1.getId()))
|
||||
{
|
||||
authenticationService.deleteAuthentication(u1.getId());
|
||||
personService.deletePerson(u1.getId());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
});
|
||||
AuthenticationUtil.clearCurrentSecurityContext();
|
||||
}
|
||||
setRequestContext(networkOne.getId(), user1, null);
|
||||
deleteSite(tSiteId, 204); // TODO permanent=true
|
||||
|
||||
|
||||
protected Document createDocument(Folder parentFolder, String docName) throws Exception
|
||||
{
|
||||
Document d1 = new Document();
|
||||
d1.setName(docName);
|
||||
d1.setNodeType("cm:content");
|
||||
ContentInfo ci = new ContentInfo();
|
||||
ci.setMimeType("text/plain");
|
||||
d1.setContent(ci);
|
||||
|
||||
// create empty file
|
||||
HttpResponse response = post(getNodeChildrenUrl(parentFolder.getId()), u1.getId(), toJsonAsStringNonNull(d1), 201);
|
||||
return RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
|
||||
super.tearDown();
|
||||
}
|
||||
}
|
||||
|
@@ -31,15 +31,14 @@ import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.alfresco.rest.api.Nodes;
|
||||
import org.alfresco.rest.api.tests.RepoService;
|
||||
import org.alfresco.rest.api.tests.client.HttpResponse;
|
||||
import org.alfresco.rest.api.tests.client.PublicApiClient;
|
||||
import org.alfresco.rest.api.tests.client.RequestContext;
|
||||
import org.alfresco.rest.api.tests.client.data.Document;
|
||||
import org.alfresco.rest.api.tests.client.data.Folder;
|
||||
import org.alfresco.rest.api.tests.client.data.Node;
|
||||
import org.alfresco.rest.api.tests.client.data.PathInfo;
|
||||
import org.alfresco.rest.api.tests.util.RestApiUtil;
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
import org.springframework.extensions.webscripts.Status;
|
||||
|
||||
@@ -57,13 +56,17 @@ public class DeletedNodesTest extends AbstractSingleNetworkSiteTest
|
||||
{
|
||||
|
||||
protected static final String URL_DELETED_NODES = "deleted-nodes";
|
||||
private RepoService.TestPerson u2;
|
||||
|
||||
@Override
|
||||
public void setup() throws Exception
|
||||
{
|
||||
super.setup();
|
||||
u2 = networkOne.createUser();
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception
|
||||
{
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -75,7 +78,7 @@ public class DeletedNodesTest extends AbstractSingleNetworkSiteTest
|
||||
@Test
|
||||
public void testCreateAndDelete() throws Exception
|
||||
{
|
||||
setRequestContext(u1.getId());
|
||||
setRequestContext(user1);
|
||||
|
||||
Date now = new Date();
|
||||
String folder1 = "folder" + now.getTime() + "_1";
|
||||
@@ -86,11 +89,11 @@ public class DeletedNodesTest extends AbstractSingleNetworkSiteTest
|
||||
Folder createdFolderNonSite = createFolder(Nodes.PATH_MY, folder1, null);
|
||||
assertNotNull(createdFolderNonSite);
|
||||
|
||||
Document document = createDocument(createdFolder, "d1.txt");
|
||||
Document document = createEmptyTextFile(createdFolder, "d1.txt");
|
||||
|
||||
PublicApiClient.Paging paging = getPaging(0, 5);
|
||||
//First get any deleted nodes
|
||||
HttpResponse response = getAll(URL_DELETED_NODES, u1.getId(), paging, 200);
|
||||
HttpResponse response = getAll(URL_DELETED_NODES, user1, paging, 200);
|
||||
List<Node> nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
|
||||
assertNotNull(nodes);
|
||||
int numOfNodes = nodes.size();
|
||||
@@ -99,25 +102,25 @@ public class DeletedNodesTest extends AbstractSingleNetworkSiteTest
|
||||
deleteNode(createdFolder.getId());
|
||||
deleteNode(createdFolderNonSite.getId());
|
||||
|
||||
response = getAll(URL_DELETED_NODES, u1.getId(), paging, 200);
|
||||
response = getAll(URL_DELETED_NODES, user1, paging, 200);
|
||||
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
|
||||
assertNotNull(nodes);
|
||||
assertEquals(numOfNodes+3,nodes.size());
|
||||
|
||||
Map<String, String> params = Collections.singletonMap("include", "path");
|
||||
response = getSingle(URL_DELETED_NODES, u1.getId(), document.getId(), params, 200);
|
||||
response = getSingle(URL_DELETED_NODES, user1, document.getId(), params, 200);
|
||||
Document node = jacksonUtil.parseEntry(response.getJsonResponse(), Document.class);
|
||||
assertNotNull(node);
|
||||
assertEquals(u1.getId(), node.getArchivedByUser().getId());
|
||||
assertEquals(user1, node.getArchivedByUser().getId());
|
||||
assertTrue(node.getArchivedAt().after(now));
|
||||
PathInfo path = node.getPath();
|
||||
assertNull("Path should be null because its parent has been deleted",path);
|
||||
assertNull("We don't show the parent id for a deleted node",node.getParentId());
|
||||
|
||||
response = getSingle(URL_DELETED_NODES, u1.getId(), createdFolder.getId(), params, 200);
|
||||
response = getSingle(URL_DELETED_NODES, user1, createdFolder.getId(), params, 200);
|
||||
Folder fNode = jacksonUtil.parseEntry(response.getJsonResponse(), Folder.class);
|
||||
assertNotNull(fNode);
|
||||
assertEquals(u1.getId(), fNode.getArchivedByUser().getId());
|
||||
assertEquals(user1, fNode.getArchivedByUser().getId());
|
||||
assertTrue(fNode.getArchivedAt().after(now));
|
||||
path = fNode.getPath();
|
||||
assertNotNull(path);
|
||||
@@ -125,27 +128,27 @@ public class DeletedNodesTest extends AbstractSingleNetworkSiteTest
|
||||
assertTrue(path.getIsComplete());
|
||||
assertNull("We don't show the parent id for a deleted node",fNode.getParentId());
|
||||
|
||||
response = getSingle(URL_DELETED_NODES, u1.getId(), createdFolderNonSite.getId(), params, 200);
|
||||
response = getSingle(URL_DELETED_NODES, user1, createdFolderNonSite.getId(), params, 200);
|
||||
fNode = jacksonUtil.parseEntry(response.getJsonResponse(), Folder.class);
|
||||
assertNotNull(fNode);
|
||||
assertEquals(u1.getId(), fNode.getArchivedByUser().getId());
|
||||
assertEquals(user1, fNode.getArchivedByUser().getId());
|
||||
assertTrue(fNode.getArchivedAt().after(now));
|
||||
path = fNode.getPath();
|
||||
assertNotNull(path);
|
||||
assertEquals("/Company Home/User Homes/"+u1.getId(), path.getName());
|
||||
assertEquals("/Company Home/User Homes/"+user1, path.getName());
|
||||
assertTrue(path.getIsComplete());
|
||||
|
||||
//The list is ordered with the most recently deleted node first
|
||||
checkDeletedNodes(now, createdFolder, createdFolderNonSite, document, nodes);
|
||||
|
||||
//User 2 can't get it but user 1 can.
|
||||
getSingle(URL_DELETED_NODES, u2.getId(), createdFolderNonSite.getId(), Status.STATUS_FORBIDDEN);
|
||||
getSingle(URL_DELETED_NODES, user2, createdFolderNonSite.getId(), Status.STATUS_FORBIDDEN);
|
||||
|
||||
//Invalid node ref
|
||||
getSingle(URL_DELETED_NODES, u1.getId(), "iddontexist", 404);
|
||||
getSingle(URL_DELETED_NODES, user1, "iddontexist", 404);
|
||||
|
||||
//Now as admin
|
||||
publicApiClient.setRequestContext(new RequestContext(networkOne.getId(), "admin@"+networkOne.getId(), "admin"));
|
||||
setRequestContext("admin");
|
||||
response = publicApiClient.get(getScope(), URL_DELETED_NODES, null, null, null, createParams(paging, null));
|
||||
checkStatus(200, response.getStatusCode());
|
||||
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
|
||||
@@ -161,7 +164,7 @@ public class DeletedNodesTest extends AbstractSingleNetworkSiteTest
|
||||
@Test
|
||||
public void testCreateAndRestore() throws Exception
|
||||
{
|
||||
setRequestContext(u1.getId());
|
||||
setRequestContext(user1);
|
||||
|
||||
Date now = new Date();
|
||||
String folder1 = "folder" + now.getTime() + "_1";
|
||||
@@ -172,31 +175,31 @@ public class DeletedNodesTest extends AbstractSingleNetworkSiteTest
|
||||
Folder createdFolderNonSite = createFolder(Nodes.PATH_MY, folder1, null);
|
||||
assertNotNull(createdFolderNonSite);
|
||||
|
||||
Document document = createDocument(createdFolder, "restoreme.txt");
|
||||
Document document = createEmptyTextFile(createdFolder, "restoreme.txt");
|
||||
deleteNode(document.getId());
|
||||
|
||||
//Create another document with the same name
|
||||
Document documentSameName = createDocument(createdFolder, "restoreme.txt");
|
||||
Document documentSameName = createEmptyTextFile(createdFolder, "restoreme.txt");
|
||||
|
||||
//Can't restore a node of the same name
|
||||
post(URL_DELETED_NODES+"/"+document.getId()+"/restore", u1.getId(), null, null, Status.STATUS_CONFLICT);
|
||||
post(URL_DELETED_NODES+"/"+document.getId()+"/restore", user1, null, null, Status.STATUS_CONFLICT);
|
||||
|
||||
deleteNode(documentSameName.getId());
|
||||
|
||||
//Now we can restore it.
|
||||
post(URL_DELETED_NODES+"/"+document.getId()+"/restore", u1.getId(), null, null, 200);
|
||||
post(URL_DELETED_NODES+"/"+document.getId()+"/restore", user1, null, null, 200);
|
||||
|
||||
deleteNode(createdFolder.getId());
|
||||
|
||||
//We deleted the parent folder so lets see if we can restore a child doc, hopefully not.
|
||||
post(URL_DELETED_NODES+"/"+documentSameName.getId()+"/restore", u1.getId(), null, null, Status.STATUS_NOT_FOUND);
|
||||
post(URL_DELETED_NODES+"/"+documentSameName.getId()+"/restore", user1, null, null, Status.STATUS_NOT_FOUND);
|
||||
|
||||
//Can't delete "nonsense" noderef
|
||||
post("deleted-nodes/nonsense/restore", u1.getId(), null, null, Status.STATUS_NOT_FOUND);
|
||||
post("deleted-nodes/nonsense/restore", user1, null, null, Status.STATUS_NOT_FOUND);
|
||||
|
||||
//User 2 can't restore it but user 1 can.
|
||||
post(URL_DELETED_NODES+"/"+createdFolder.getId()+"/restore", u2.getId(), null, null, Status.STATUS_FORBIDDEN);
|
||||
post(URL_DELETED_NODES+"/"+createdFolder.getId()+"/restore", u1.getId(), null, null, 200);
|
||||
post(URL_DELETED_NODES+"/"+createdFolder.getId()+"/restore", user2, null, null, Status.STATUS_FORBIDDEN);
|
||||
post(URL_DELETED_NODES+"/"+createdFolder.getId()+"/restore", user1, null, null, 200);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -207,7 +210,7 @@ public class DeletedNodesTest extends AbstractSingleNetworkSiteTest
|
||||
@Test
|
||||
public void testCreateAndPurge() throws Exception
|
||||
{
|
||||
setRequestContext(u1.getId());
|
||||
setRequestContext(user1);
|
||||
|
||||
Date now = new Date();
|
||||
String folder1 = "folder" + now.getTime() + "_1";
|
||||
@@ -216,21 +219,21 @@ public class DeletedNodesTest extends AbstractSingleNetworkSiteTest
|
||||
|
||||
deleteNode(createdFolder.getId());
|
||||
|
||||
HttpResponse response = getSingle(URL_DELETED_NODES, u1.getId(), createdFolder.getId(), 200);
|
||||
HttpResponse response = getSingle(URL_DELETED_NODES, user1, createdFolder.getId(), 200);
|
||||
Folder fNode = jacksonUtil.parseEntry(response.getJsonResponse(), Folder.class);
|
||||
assertNotNull(fNode);
|
||||
|
||||
//try purging "nonsense"
|
||||
delete(URL_DELETED_NODES, u1.getId(), "nonsense", 404);
|
||||
delete(URL_DELETED_NODES, user1, "nonsense", 404);
|
||||
|
||||
//User 2 can't do it
|
||||
delete(URL_DELETED_NODES, u2.getId(), createdFolder.getId(), Status.STATUS_FORBIDDEN);
|
||||
delete(URL_DELETED_NODES, user2, createdFolder.getId(), Status.STATUS_FORBIDDEN);
|
||||
|
||||
//Now purge the folder
|
||||
delete(URL_DELETED_NODES, u1.getId(), createdFolder.getId(), 204);
|
||||
delete(URL_DELETED_NODES, user1, createdFolder.getId(), 204);
|
||||
|
||||
//This time we can't find it.
|
||||
getSingle(URL_DELETED_NODES, u1.getId(), createdFolder.getId(), 404);
|
||||
getSingle(URL_DELETED_NODES, user1, createdFolder.getId(), 404);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -241,14 +244,14 @@ public class DeletedNodesTest extends AbstractSingleNetworkSiteTest
|
||||
Node aNode = (Node) nodes.get(0);
|
||||
assertNotNull(aNode);
|
||||
assertEquals("This folder was deleted most recently", createdFolderNonSite.getId(), aNode.getId());
|
||||
assertEquals(u1.getId(), aNode.getArchivedByUser().getId());
|
||||
assertEquals(user1, aNode.getArchivedByUser().getId());
|
||||
assertTrue(aNode.getArchivedAt().after(now));
|
||||
assertNull("We don't show the parent id for a deleted node",aNode.getParentId());
|
||||
|
||||
Node folderNode = (Node) nodes.get(1);
|
||||
assertNotNull(folderNode);
|
||||
assertEquals(createdFolder.getId(), folderNode.getId());
|
||||
assertEquals(u1.getId(), folderNode.getArchivedByUser().getId());
|
||||
assertEquals(user1, folderNode.getArchivedByUser().getId());
|
||||
assertTrue(folderNode.getArchivedAt().after(now));
|
||||
assertTrue("This folder was deleted before the non-site folder", folderNode.getArchivedAt().before(aNode.getArchivedAt()));
|
||||
assertNull("We don't show the parent id for a deleted node",folderNode.getParentId());
|
||||
@@ -256,7 +259,7 @@ public class DeletedNodesTest extends AbstractSingleNetworkSiteTest
|
||||
aNode = (Node) nodes.get(2);
|
||||
assertNotNull(aNode);
|
||||
assertEquals(document.getId(), aNode.getId());
|
||||
assertEquals(u1.getId(), aNode.getArchivedByUser().getId());
|
||||
assertEquals(user1, aNode.getArchivedByUser().getId());
|
||||
assertTrue(aNode.getArchivedAt().after(now));
|
||||
assertNull("We don't show the parent id for a deleted node",aNode.getParentId());
|
||||
}
|
||||
|
@@ -33,6 +33,7 @@ import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.repo.tenant.TenantService;
|
||||
import org.alfresco.repo.transaction.RetryingTransactionHelper;
|
||||
import org.alfresco.rest.api.Nodes;
|
||||
import org.alfresco.rest.api.model.Site;
|
||||
@@ -44,6 +45,7 @@ import org.alfresco.rest.api.tests.client.PublicApiClient;
|
||||
import org.alfresco.rest.api.tests.client.PublicApiHttpClient.BinaryPayload;
|
||||
import org.alfresco.rest.api.tests.client.PublicApiHttpClient.RequestBuilder;
|
||||
import org.alfresco.rest.api.tests.client.RequestContext;
|
||||
import org.alfresco.rest.api.tests.client.data.ContentInfo;
|
||||
import org.alfresco.rest.api.tests.client.data.Document;
|
||||
import org.alfresco.rest.api.tests.client.data.Folder;
|
||||
import org.alfresco.rest.api.tests.client.data.Node;
|
||||
@@ -127,21 +129,20 @@ public abstract class AbstractBaseApiTest extends EnterpriseTestApi
|
||||
@Before
|
||||
public void setup() throws Exception
|
||||
{
|
||||
authenticationService = applicationContext.getBean("authenticationService", MutableAuthenticationService.class);
|
||||
personService = applicationContext.getBean("personService", PersonService.class);
|
||||
|
||||
// note: createUser currently relies on repoService
|
||||
user1 = createUser("user1-" + RUNID, "user1Password");
|
||||
user2 = createUser("user2-" + RUNID, "user2Password");
|
||||
user1 = createUser("user1-" + RUNID, "user1Password", null);
|
||||
user2 = createUser("user2-" + RUNID, "user2Password", null);
|
||||
|
||||
// to enable admin access via test calls - eg. after clean/purge
|
||||
// to enable admin access via test calls - eg. via PublicApiClient -> AbstractTestApi -> findUserByUserName
|
||||
getOrCreateUser("admin", "admin");
|
||||
|
||||
// We just need to clean the on-premise-users,
|
||||
// so the tests for the specific network would work.
|
||||
// used-by teardown to cleanup
|
||||
authenticationService = applicationContext.getBean("authenticationService", MutableAuthenticationService.class);
|
||||
personService = applicationContext.getBean("personService", PersonService.class);
|
||||
users.add(user1);
|
||||
users.add(user2);
|
||||
|
||||
// TODO this causes createTestData to be called
|
||||
networkOne = getTestFixture().getRandomNetwork();
|
||||
userOneN1 = networkOne.createUser();
|
||||
userTwoN1 = networkOne.createUser();
|
||||
@@ -446,16 +447,16 @@ public abstract class AbstractBaseApiTest extends EnterpriseTestApi
|
||||
|
||||
protected String createUser(String username)
|
||||
{
|
||||
return createUser(username, "password");
|
||||
return createUser(username, "password", null);
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO implement as remote api call
|
||||
*/
|
||||
protected String createUser(String username, String password)
|
||||
protected String createUser(String username, String password, TestNetwork network)
|
||||
{
|
||||
PersonInfo personInfo = new PersonInfo(username, username, username, password, null, null, null, null, null, null, null);
|
||||
RepoService.TestPerson person = repoService.createUser(personInfo, username, null);
|
||||
RepoService.TestPerson person = repoService.createUser(personInfo, username, network);
|
||||
return person.getId();
|
||||
}
|
||||
|
||||
@@ -537,11 +538,20 @@ public abstract class AbstractBaseApiTest extends EnterpriseTestApi
|
||||
password = DEFAULT_ADMIN_PWD;
|
||||
}
|
||||
|
||||
setRequestContext("-default-", runAsUser, password);
|
||||
setRequestContext(null, runAsUser, password);
|
||||
}
|
||||
|
||||
protected void setRequestContext(String runAsNetwork, String runAsUser, String password)
|
||||
{
|
||||
if ((runAsNetwork == null) || TenantService.DEFAULT_DOMAIN.equals(runAsNetwork))
|
||||
{
|
||||
runAsNetwork = "-default-";
|
||||
}
|
||||
else if (runAsUser.equals(DEFAULT_ADMIN))
|
||||
{
|
||||
runAsUser = runAsUser+"@"+runAsNetwork;
|
||||
}
|
||||
|
||||
publicApiClient.setRequestContext(new RequestContext(runAsNetwork, runAsUser, password));
|
||||
}
|
||||
|
||||
@@ -655,6 +665,20 @@ public abstract class AbstractBaseApiTest extends EnterpriseTestApi
|
||||
return RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
|
||||
}
|
||||
|
||||
protected Document createEmptyTextFile(Folder parentFolder, String docName) throws Exception
|
||||
{
|
||||
Document d1 = new Document();
|
||||
d1.setName(docName);
|
||||
d1.setNodeType("cm:content");
|
||||
ContentInfo ci = new ContentInfo();
|
||||
ci.setMimeType("text/plain");
|
||||
d1.setContent(ci);
|
||||
|
||||
// create empty file
|
||||
HttpResponse response = post(getNodeChildrenUrl(parentFolder.getId()), publicApiClient.getRequestContext().getRunAsUser(), toJsonAsStringNonNull(d1), 201);
|
||||
return RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
|
||||
}
|
||||
|
||||
protected Document updateTextFile(String contentId, String textContent, Map<String, String> parameters) throws IOException, Exception
|
||||
{
|
||||
ByteArrayInputStream inputStream = new ByteArrayInputStream(textContent.getBytes());
|
||||
|
@@ -59,22 +59,22 @@ public class ActivitiesPostingTest extends AbstractSingleNetworkSiteTest
|
||||
@Test
|
||||
public void testCreateUpdate() throws Exception
|
||||
{
|
||||
setRequestContext(u1.getId());
|
||||
setRequestContext(user1);
|
||||
|
||||
String folder1 = "folder" + System.currentTimeMillis() + "_1";
|
||||
Folder createdFolder = createFolder(tDocLibNodeId, folder1, null);
|
||||
assertNotNull(createdFolder);
|
||||
|
||||
String docName = "d1.txt";
|
||||
Document documentResp = createDocument(createdFolder, docName);
|
||||
Document documentResp = createEmptyTextFile(createdFolder, docName);
|
||||
|
||||
//Update the file
|
||||
Document dUpdate = new Document();
|
||||
dUpdate.setName("d1b.txt");
|
||||
put(URL_NODES, u1.getId(), documentResp.getId(), toJsonAsStringNonNull(dUpdate), null, 200);
|
||||
put(URL_NODES, user1, documentResp.getId(), toJsonAsStringNonNull(dUpdate), null, 200);
|
||||
|
||||
//Now download it
|
||||
HttpResponse response = getSingle(NodesEntityResource.class, u1.getId(), documentResp.getId()+"/content", null, 200);
|
||||
HttpResponse response = getSingle(NodesEntityResource.class, user1, documentResp.getId()+"/content", null, 200);
|
||||
String textContent = response.getResponse();
|
||||
assertNotNull(textContent);
|
||||
|
||||
@@ -83,22 +83,22 @@ public class ActivitiesPostingTest extends AbstractSingleNetworkSiteTest
|
||||
|
||||
List<Activity> activities = getMyActivities();
|
||||
assertEquals(activities.size(),6);
|
||||
Activity act = matchActivity(activities, ActivityType.FOLDER_ADDED, u1.getId(), tSiteId, tDocLibNodeId, folder1);
|
||||
Activity act = matchActivity(activities, ActivityType.FOLDER_ADDED, user1, tSiteId, tDocLibNodeId, folder1);
|
||||
assertNotNull(act);
|
||||
|
||||
act = matchActivity(activities, ActivityType.FILE_ADDED, u1.getId(), tSiteId, createdFolder.getId(), docName);
|
||||
act = matchActivity(activities, ActivityType.FILE_ADDED, user1, tSiteId, createdFolder.getId(), docName);
|
||||
assertNotNull(act);
|
||||
|
||||
act = matchActivity(activities, ActivityType.FILE_UPDATED, u1.getId(), tSiteId, createdFolder.getId(), dUpdate.getName());
|
||||
act = matchActivity(activities, ActivityType.FILE_UPDATED, user1, tSiteId, createdFolder.getId(), dUpdate.getName());
|
||||
assertNotNull(act);
|
||||
|
||||
act = matchActivity(activities, ActivityType.FOLDER_DELETED, u1.getId(), tSiteId, tDocLibNodeId, folder1);
|
||||
act = matchActivity(activities, ActivityType.FOLDER_DELETED, user1, tSiteId, tDocLibNodeId, folder1);
|
||||
assertNotNull(act);
|
||||
|
||||
act = matchActivity(activities, ActivityType.FILE_DELETED, u1.getId(), tSiteId, createdFolder.getId(), dUpdate.getName());
|
||||
act = matchActivity(activities, ActivityType.FILE_DELETED, user1, tSiteId, createdFolder.getId(), dUpdate.getName());
|
||||
assertNotNull(act);
|
||||
|
||||
act = matchActivity(activities, ActivityPoster.DOWNLOADED, u1.getId(), tSiteId, createdFolder.getId(), dUpdate.getName());
|
||||
act = matchActivity(activities, ActivityPoster.DOWNLOADED, user1, tSiteId, createdFolder.getId(), dUpdate.getName());
|
||||
assertNotNull(act);
|
||||
}
|
||||
|
||||
@@ -108,7 +108,7 @@ public class ActivitiesPostingTest extends AbstractSingleNetworkSiteTest
|
||||
@Test
|
||||
public void testNonFileActivities() throws Exception
|
||||
{
|
||||
setRequestContext(u1.getId());
|
||||
setRequestContext(user1);
|
||||
|
||||
String folder1 = "InSitefolder" + System.currentTimeMillis() + "_1";
|
||||
Folder createdFolder = createFolder(tDocLibNodeId, folder1, null);
|
||||
@@ -131,7 +131,7 @@ public class ActivitiesPostingTest extends AbstractSingleNetworkSiteTest
|
||||
@Test
|
||||
public void testNonSite() throws Exception
|
||||
{
|
||||
setRequestContext(u1.getId());
|
||||
setRequestContext(user1);
|
||||
|
||||
List<Activity> activities = getMyActivities();
|
||||
String folder1 = "nonSitefolder" + System.currentTimeMillis() + "_1";
|
||||
@@ -140,13 +140,13 @@ public class ActivitiesPostingTest extends AbstractSingleNetworkSiteTest
|
||||
assertNotNull(createdFolder);
|
||||
|
||||
String docName = "nonsite_d1.txt";
|
||||
Document documentResp = createDocument(createdFolder, docName);
|
||||
Document documentResp = createEmptyTextFile(createdFolder, docName);
|
||||
assertNotNull(documentResp);
|
||||
|
||||
//Update the file
|
||||
Document dUpdate = new Document();
|
||||
dUpdate.setName("nonsite_d2.txt");
|
||||
put(URL_NODES, u1.getId(), documentResp.getId(), toJsonAsStringNonNull(dUpdate), null, 200);
|
||||
put(URL_NODES, user1, documentResp.getId(), toJsonAsStringNonNull(dUpdate), null, 200);
|
||||
|
||||
List<Activity> activitiesAgain = getMyActivities();
|
||||
assertEquals("No activites should be created for non-site nodes", activities, activitiesAgain);
|
||||
@@ -161,11 +161,11 @@ public class ActivitiesPostingTest extends AbstractSingleNetworkSiteTest
|
||||
{
|
||||
repoService.generateFeed();
|
||||
|
||||
setRequestContext(u1.getId());
|
||||
setRequestContext(user1);
|
||||
|
||||
Map<String, String> meParams = new HashMap<>();
|
||||
meParams.put("who", String.valueOf(Activities.ActivityWho.me));
|
||||
return publicApiClient.people().getActivities(u1.getId(), meParams).getList();
|
||||
return publicApiClient.people().getActivities(user1, meParams).getList();
|
||||
}
|
||||
|
||||
|
||||
|
@@ -37,8 +37,8 @@ import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.alfresco.repo.content.ContentLimitProvider.SimpleFixedLimitProvider;
|
||||
import org.alfresco.repo.content.MimetypeMap;
|
||||
import org.alfresco.repo.node.archive.NodeArchiveService;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.rest.AbstractSingleNetworkSiteTest;
|
||||
import org.alfresco.rest.api.Nodes;
|
||||
import org.alfresco.rest.api.model.NodeTarget;
|
||||
import org.alfresco.rest.api.model.Site;
|
||||
@@ -58,21 +58,18 @@ import org.alfresco.rest.api.tests.client.data.PathInfo.ElementInfo;
|
||||
import org.alfresco.rest.api.tests.client.data.SiteMember;
|
||||
import org.alfresco.rest.api.tests.client.data.SiteRole;
|
||||
import org.alfresco.rest.api.tests.client.data.UserInfo;
|
||||
import org.alfresco.rest.api.tests.util.JacksonUtil;
|
||||
import org.alfresco.rest.api.tests.util.MultiPartBuilder;
|
||||
import org.alfresco.rest.api.tests.util.MultiPartBuilder.FileData;
|
||||
import org.alfresco.rest.api.tests.util.MultiPartBuilder.MultiPartRequest;
|
||||
import org.alfresco.rest.api.tests.util.RestApiUtil;
|
||||
import org.alfresco.rest.framework.jacksonextensions.JacksonHelper;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.cmr.repository.StoreRef;
|
||||
import org.alfresco.service.cmr.security.PermissionService;
|
||||
import org.alfresco.service.cmr.security.PersonService;
|
||||
import org.alfresco.service.cmr.site.SiteVisibility;
|
||||
import org.alfresco.util.GUID;
|
||||
import org.alfresco.util.TempFileProvider;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -100,22 +97,19 @@ import java.util.UUID;
|
||||
*
|
||||
* TODO
|
||||
* - improve test 'fwk' to enable api tests to be run against remote repo (rather than embedded jetty)
|
||||
* - requires replacement of non-remote calls with remote (preferably public) apis
|
||||
* - eg. createUser (or any other usage of repoService), permissionService, node/archiveService
|
||||
* - requires replacement of remaining non-remote calls with remote (preferably public) apis
|
||||
* - eg. createUser (or any other usage of repoService), permissionService, ...
|
||||
*
|
||||
* @author Jamal Kaabi-Mofrad
|
||||
* @author janv
|
||||
*/
|
||||
public class NodeApiTest extends AbstractBaseApiTest
|
||||
public class NodeApiTest extends AbstractSingleNetworkSiteTest
|
||||
{
|
||||
private static final String PROP_OWNER = "cm:owner";
|
||||
|
||||
protected PersonService personService;
|
||||
protected JacksonUtil jacksonUtil;
|
||||
protected PermissionService permissionService;
|
||||
private static final String URL_DELETED_NODES = "deleted-nodes";
|
||||
|
||||
protected NodeArchiveService nodeArchiveService;
|
||||
protected NodeService nodeService;
|
||||
protected PermissionService permissionService;
|
||||
|
||||
|
||||
@Before
|
||||
@@ -123,13 +117,13 @@ public class NodeApiTest extends AbstractBaseApiTest
|
||||
{
|
||||
super.setup();
|
||||
|
||||
personService = applicationContext.getBean("personService", PersonService.class);
|
||||
jacksonUtil = new JacksonUtil(applicationContext.getBean("jsonHelper", JacksonHelper.class));
|
||||
permissionService = applicationContext.getBean("permissionService", PermissionService.class);
|
||||
}
|
||||
|
||||
// TODO replace with V1 REST API for Trashcan
|
||||
nodeArchiveService = applicationContext.getBean("nodeArchiveService", NodeArchiveService.class);
|
||||
nodeService = applicationContext.getBean("nodeService", NodeService.class);
|
||||
@After
|
||||
public void tearDown() throws Exception
|
||||
{
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -140,30 +134,25 @@ public class NodeApiTest extends AbstractBaseApiTest
|
||||
@Test
|
||||
public void testListDocLibChildren() throws Exception
|
||||
{
|
||||
String userOneId = userOneN1.getId();
|
||||
String userTwoId = userTwoN1.getId();
|
||||
|
||||
setRequestContext(networkOne.getId(), userOneId, null);
|
||||
|
||||
String docLibNodeId = getSiteContainerNodeId(userOneN1SiteId, "documentLibrary");
|
||||
setRequestContext(user1);
|
||||
|
||||
String folder1 = "folder" + System.currentTimeMillis() + "_1";
|
||||
createFolder(docLibNodeId, folder1, null).getId();
|
||||
createFolder(tDocLibNodeId, folder1, null).getId();
|
||||
|
||||
String folder2 = "folder" + System.currentTimeMillis() + "_2";
|
||||
createFolder(docLibNodeId, folder2, null).getId();
|
||||
createFolder(tDocLibNodeId, folder2, null).getId();
|
||||
|
||||
String content1 = "content" + System.currentTimeMillis() + "_1";
|
||||
createTextFile(docLibNodeId, content1, "The quick brown fox jumps over the lazy dog 1.").getId();
|
||||
createTextFile(tDocLibNodeId, content1, "The quick brown fox jumps over the lazy dog 1.").getId();
|
||||
|
||||
String content2 = "content" + System.currentTimeMillis() + "_2";
|
||||
createTextFile(docLibNodeId, content2, "The quick brown fox jumps over the lazy dog 2.").getId();
|
||||
createTextFile(tDocLibNodeId, content2, "The quick brown fox jumps over the lazy dog 2.").getId();
|
||||
|
||||
String forum1 = "forum" + System.currentTimeMillis() + "_1";
|
||||
createNode(docLibNodeId, forum1, "fm:topic", null);
|
||||
createNode(tDocLibNodeId, forum1, "fm:topic", null);
|
||||
|
||||
Paging paging = getPaging(0, 100);
|
||||
HttpResponse response = getAll(getNodeChildrenUrl(docLibNodeId), userOneId, paging, 200);
|
||||
HttpResponse response = getAll(getNodeChildrenUrl(tDocLibNodeId), user1, paging, 200);
|
||||
List<Node> nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
|
||||
assertEquals(4, nodes.size()); // forum is part of the default ignored types
|
||||
// Paging
|
||||
@@ -175,7 +164,7 @@ public class NodeApiTest extends AbstractBaseApiTest
|
||||
|
||||
// Order by folders and modified date first
|
||||
Map<String, String> orderBy = Collections.singletonMap("orderBy", "isFolder DESC,modifiedAt DESC");
|
||||
response = getAll(getNodeChildrenUrl(docLibNodeId), userOneId, paging, orderBy, 200);
|
||||
response = getAll(getNodeChildrenUrl(tDocLibNodeId), user1, paging, orderBy, 200);
|
||||
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
|
||||
assertEquals(4, nodes.size());
|
||||
assertEquals(folder2, nodes.get(0).getName());
|
||||
@@ -193,7 +182,7 @@ public class NodeApiTest extends AbstractBaseApiTest
|
||||
|
||||
// Order by folders last and modified date first
|
||||
orderBy = Collections.singletonMap("orderBy", "isFolder ASC,modifiedAt DESC");
|
||||
response = getAll(getNodeChildrenUrl(docLibNodeId), userOneId, paging, orderBy, 200);
|
||||
response = getAll(getNodeChildrenUrl(tDocLibNodeId), user1, paging, orderBy, 200);
|
||||
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
|
||||
assertEquals(4, nodes.size());
|
||||
assertEquals(content2, nodes.get(0).getName());
|
||||
@@ -203,7 +192,7 @@ public class NodeApiTest extends AbstractBaseApiTest
|
||||
|
||||
// Order by folders and modified date last
|
||||
orderBy = Collections.singletonMap("orderBy", "isFolder,modifiedAt");
|
||||
response = getAll(getNodeChildrenUrl(docLibNodeId), userOneId, paging, orderBy, 200);
|
||||
response = getAll(getNodeChildrenUrl(tDocLibNodeId), user1, paging, orderBy, 200);
|
||||
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
|
||||
assertEquals(4, nodes.size());
|
||||
assertEquals(content1, nodes.get(0).getName());
|
||||
@@ -216,7 +205,7 @@ public class NodeApiTest extends AbstractBaseApiTest
|
||||
|
||||
// SkipCount=0,MaxItems=2
|
||||
paging = getPaging(0, 2);
|
||||
response = getAll(getNodeChildrenUrl(docLibNodeId), userOneId, paging, orderBy, 200);
|
||||
response = getAll(getNodeChildrenUrl(tDocLibNodeId), user1, paging, orderBy, 200);
|
||||
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
|
||||
assertEquals(2, nodes.size());
|
||||
assertEquals(folder2, nodes.get(0).getName());
|
||||
@@ -229,7 +218,7 @@ public class NodeApiTest extends AbstractBaseApiTest
|
||||
|
||||
// SkipCount=null,MaxItems=2
|
||||
paging = getPaging(null, 2);
|
||||
response = getAll(getNodeChildrenUrl(docLibNodeId), userOneId, paging, orderBy, 200);
|
||||
response = getAll(getNodeChildrenUrl(tDocLibNodeId), user1, paging, orderBy, 200);
|
||||
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
|
||||
assertEquals(2, nodes.size());
|
||||
assertEquals(folder2, nodes.get(0).getName());
|
||||
@@ -242,7 +231,7 @@ public class NodeApiTest extends AbstractBaseApiTest
|
||||
|
||||
// SkipCount=2,MaxItems=4
|
||||
paging = getPaging(2, 4);
|
||||
response = getAll(getNodeChildrenUrl(docLibNodeId), userOneId, paging, orderBy, 200);
|
||||
response = getAll(getNodeChildrenUrl(tDocLibNodeId), user1, paging, orderBy, 200);
|
||||
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
|
||||
assertEquals(2, nodes.size());
|
||||
assertEquals(content2, nodes.get(0).getName());
|
||||
@@ -256,7 +245,7 @@ public class NodeApiTest extends AbstractBaseApiTest
|
||||
|
||||
// SkipCount=2,MaxItems=null
|
||||
paging = getPaging(2, null);
|
||||
response = getAll(getNodeChildrenUrl(docLibNodeId), userOneId, paging, orderBy, 200);
|
||||
response = getAll(getNodeChildrenUrl(tDocLibNodeId), user1, paging, orderBy, 200);
|
||||
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
|
||||
assertEquals(2, nodes.size());
|
||||
assertEquals(content2, nodes.get(0).getName());
|
||||
@@ -267,23 +256,22 @@ public class NodeApiTest extends AbstractBaseApiTest
|
||||
assertEquals(100, expectedPaging.getMaxItems().intValue());
|
||||
assertFalse(expectedPaging.getHasMoreItems().booleanValue());
|
||||
|
||||
setRequestContext(userTwoId);
|
||||
setRequestContext(user2);
|
||||
|
||||
// userTwoN1 tries to access userOneN1's docLib
|
||||
AuthenticationUtil.setFullyAuthenticatedUser(userTwoId);
|
||||
// user2 tries to access user1's docLib
|
||||
paging = getPaging(0, Integer.MAX_VALUE);
|
||||
getAll(getNodeChildrenUrl(docLibNodeId), userTwoId, paging, 403);
|
||||
getAll(getNodeChildrenUrl(tDocLibNodeId), user2, paging, 403);
|
||||
|
||||
setRequestContext(userOneId);
|
||||
setRequestContext(user1);
|
||||
|
||||
// -ve test - paging (via list children) cannot have skipCount < 0
|
||||
paging = getPaging(-1, 4);
|
||||
getAll(getNodeChildrenUrl(docLibNodeId), userOneId, paging, orderBy, 400);
|
||||
getAll(getNodeChildrenUrl(tDocLibNodeId), user1, paging, orderBy, 400);
|
||||
|
||||
|
||||
// -ve test - paging (via list children) cannot have maxItems < 1
|
||||
paging = getPaging(0, 0);
|
||||
getAll(getNodeChildrenUrl(docLibNodeId), userOneId, paging, orderBy, 400);
|
||||
getAll(getNodeChildrenUrl(tDocLibNodeId), user1, paging, orderBy, 400);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -525,18 +513,14 @@ public class NodeApiTest extends AbstractBaseApiTest
|
||||
@Test
|
||||
public void testGetPathElements_DocLib() throws Exception
|
||||
{
|
||||
String userId = userOneN1.getId();
|
||||
|
||||
setRequestContext(networkOne.getId(), userId, null);
|
||||
setRequestContext(user1);
|
||||
|
||||
PublicApiClient.Sites sitesProxy = publicApiClient.sites();
|
||||
sitesProxy.createSiteMember(userOneN1SiteId, new SiteMember(userTwoN1.getId(), SiteRole.SiteConsumer.toString()));
|
||||
|
||||
String docLibNodeId = getSiteContainerNodeId(userOneN1SiteId, "documentLibrary");
|
||||
sitesProxy.createSiteMember(tSiteId, new SiteMember(user2, SiteRole.SiteConsumer.toString()));
|
||||
|
||||
// /Company Home/Sites/RandomSite<timestamp>/documentLibrary/folder<timestamp>_A
|
||||
String folderA = "folder" + System.currentTimeMillis() + "_A";
|
||||
String folderA_Id = createFolder(docLibNodeId, folderA).getId();
|
||||
String folderA_Id = createFolder(tDocLibNodeId, folderA).getId();
|
||||
|
||||
// /Company Home/Sites/RandomSite<timestamp>/documentLibrary/folder<timestamp>_A/folder<timestamp>_B
|
||||
String folderB = "folder" + System.currentTimeMillis() + "_B";
|
||||
@@ -554,15 +538,15 @@ public class NodeApiTest extends AbstractBaseApiTest
|
||||
|
||||
|
||||
// TODO refactor with remote permission api calls (use v0 until we have v1 ?)
|
||||
AuthenticationUtil.setFullyAuthenticatedUser(userId);
|
||||
AuthenticationUtil.setFullyAuthenticatedUser(user1);
|
||||
// Revoke folderB inherited permissions
|
||||
permissionService.setInheritParentPermissions(folderB_Ref, false);
|
||||
// Grant userTwoN1 permission for folderC
|
||||
permissionService.setPermission(folderC_Ref, userTwoN1.getId(), PermissionService.CONSUMER, true);
|
||||
// Grant user2 permission for folderC
|
||||
permissionService.setPermission(folderC_Ref, user2, PermissionService.CONSUMER, true);
|
||||
|
||||
//...nodes/nodeId?include=path
|
||||
Map<String, String> params = Collections.singletonMap("include", "path");
|
||||
HttpResponse response = getSingle(NodesEntityResource.class, userOneN1.getId(), content1_Id, params, 200);
|
||||
HttpResponse response = getSingle(NodesEntityResource.class, user1, content1_Id, params, 200);
|
||||
Document node = jacksonUtil.parseEntry(response.getJsonResponse(), Document.class);
|
||||
PathInfo path = node.getPath();
|
||||
assertNotNull(path);
|
||||
@@ -575,24 +559,24 @@ public class NodeApiTest extends AbstractBaseApiTest
|
||||
assertEquals(7, pathElements.size());
|
||||
assertEquals("Company Home", pathElements.get(0).getName());
|
||||
assertEquals("Sites", pathElements.get(1).getName());
|
||||
assertEquals(userOneN1SiteId, pathElements.get(2).getName());
|
||||
assertEquals(tSiteId, pathElements.get(2).getName());
|
||||
assertEquals("documentLibrary", pathElements.get(3).getName());
|
||||
assertEquals(folderA, pathElements.get(4).getName());
|
||||
assertEquals(folderB, pathElements.get(5).getName());
|
||||
assertEquals(folderC, pathElements.get(6).getName());
|
||||
|
||||
// Try the above tests with userTwoN1 (site consumer)
|
||||
setRequestContext(userTwoN1.getId());
|
||||
// Try the above tests with user2 (site consumer)
|
||||
setRequestContext(user2);
|
||||
|
||||
AuthenticationUtil.setFullyAuthenticatedUser(userTwoN1.getId());
|
||||
response = getSingle(NodesEntityResource.class, userTwoN1.getId(), content1_Id, params, 200);
|
||||
AuthenticationUtil.setFullyAuthenticatedUser(user2);
|
||||
response = getSingle(NodesEntityResource.class, user2, content1_Id, params, 200);
|
||||
node = jacksonUtil.parseEntry(response.getJsonResponse(), Document.class);
|
||||
path = node.getPath();
|
||||
assertNotNull(path);
|
||||
assertFalse("The path is not complete as the user doesn't have permission to access the full path.", path.getIsComplete());
|
||||
assertNotNull(path.getName());
|
||||
// site consumer (userTwoN1) dose not have access to the folderB
|
||||
assertFalse("site consumer (userTwoN1) dose not have access to the folderB", path.getName().contains(folderB));
|
||||
// site consumer (user2) dose not have access to the folderB
|
||||
assertFalse("site consumer (user2) dose not have access to the folderB", path.getName().contains(folderB));
|
||||
assertFalse(path.getName().startsWith("/Company Home"));
|
||||
// Go up as far as they can, before getting access denied (i.e. "/folderC")
|
||||
assertTrue(path.getName().endsWith(folderC));
|
||||
@@ -1163,18 +1147,16 @@ public class NodeApiTest extends AbstractBaseApiTest
|
||||
@Test
|
||||
public void testUploadToSite() throws Exception
|
||||
{
|
||||
setRequestContext(networkOne.getId(), userOneN1.getId(), null);
|
||||
setRequestContext(user1);
|
||||
|
||||
final String fileName = "quick-1.txt";
|
||||
final File file = getResourceFile(fileName);
|
||||
|
||||
String docLibNodeId = getSiteContainerNodeId(userOneN1SiteId, "documentLibrary");
|
||||
|
||||
String folderA = "folder" + System.currentTimeMillis() + "_A";
|
||||
String folderA_id = createFolder(docLibNodeId, folderA).getId();
|
||||
String folderA_id = createFolder(tDocLibNodeId, folderA).getId();
|
||||
|
||||
Paging paging = getPaging(0, Integer.MAX_VALUE);
|
||||
HttpResponse response = getAll(getNodeChildrenUrl(folderA_id), userOneN1.getId(), paging, 200);
|
||||
HttpResponse response = getAll(getNodeChildrenUrl(folderA_id), user1, paging, 200);
|
||||
PublicApiClient.ExpectedPaging pagingResult = parsePaging(response.getJsonResponse());
|
||||
assertNotNull(paging);
|
||||
final int numOfNodes = pagingResult.getCount();
|
||||
@@ -1183,7 +1165,7 @@ public class NodeApiTest extends AbstractBaseApiTest
|
||||
.setFileData(new FileData(fileName, file));
|
||||
MultiPartRequest reqBody = multiPartBuilder.build();
|
||||
// Try to upload
|
||||
response = post(getNodeChildrenUrl(folderA_id), userOneN1.getId(), reqBody.getBody(), null, reqBody.getContentType(), 201);
|
||||
response = post(getNodeChildrenUrl(folderA_id), user1, reqBody.getBody(), null, reqBody.getContentType(), 201);
|
||||
Document document = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
|
||||
// Check the upload response
|
||||
assertEquals(fileName, document.getName());
|
||||
@@ -1193,7 +1175,7 @@ public class NodeApiTest extends AbstractBaseApiTest
|
||||
assertEquals(MimetypeMap.MIMETYPE_TEXT_PLAIN, contentInfo.getMimeType());
|
||||
|
||||
// Retrieve the uploaded file
|
||||
response = getSingle(NodesEntityResource.class, userOneN1.getId(), document.getId(), null, 200);
|
||||
response = getSingle(NodesEntityResource.class, user1, document.getId(), null, 200);
|
||||
document = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
|
||||
assertEquals(fileName, document.getName());
|
||||
contentInfo = document.getContent();
|
||||
@@ -1201,15 +1183,15 @@ public class NodeApiTest extends AbstractBaseApiTest
|
||||
assertEquals(MimetypeMap.MIMETYPE_TEXT_PLAIN, contentInfo.getMimeType());
|
||||
|
||||
// Check 'get children' is confirming the upload
|
||||
response = getAll(getNodeChildrenUrl(folderA_id), userOneN1.getId(), paging, 200);
|
||||
response = getAll(getNodeChildrenUrl(folderA_id), user1, paging, 200);
|
||||
pagingResult = parsePaging(response.getJsonResponse());
|
||||
assertNotNull(paging);
|
||||
assertEquals(numOfNodes + 1, pagingResult.getCount().intValue());
|
||||
|
||||
// Upload the same file again to check the name conflicts handling
|
||||
post(getNodeChildrenUrl(folderA_id), userOneN1.getId(), reqBody.getBody(), null, reqBody.getContentType(), 409);
|
||||
post(getNodeChildrenUrl(folderA_id), user1, reqBody.getBody(), null, reqBody.getContentType(), 409);
|
||||
|
||||
response = getAll(getNodeChildrenUrl(folderA_id), userOneN1.getId(), paging, 200);
|
||||
response = getAll(getNodeChildrenUrl(folderA_id), user1, paging, 200);
|
||||
pagingResult = parsePaging(response.getJsonResponse());
|
||||
assertNotNull(paging);
|
||||
assertEquals(numOfNodes + 1, pagingResult.getCount().intValue());
|
||||
@@ -1219,11 +1201,11 @@ public class NodeApiTest extends AbstractBaseApiTest
|
||||
reqBody = MultiPartBuilder.create()
|
||||
.setFileData(new FileData(fileName2, file2))
|
||||
.build();
|
||||
// userTwoN1 tries to upload a new file into the folderA of userOneN1
|
||||
post(getNodeChildrenUrl(folderA_id), userTwoN1.getId(), reqBody.getBody(), null, reqBody.getContentType(), 403);
|
||||
// user2 tries to upload a new file into the folderA of user1
|
||||
post(getNodeChildrenUrl(folderA_id), user2, reqBody.getBody(), null, reqBody.getContentType(), 403);
|
||||
|
||||
// Test upload with properties
|
||||
response = post(getNodeChildrenUrl(folderA_id), userOneN1.getId(), reqBody.getBody(), null, reqBody.getContentType(), 201);
|
||||
response = post(getNodeChildrenUrl(folderA_id), user1, reqBody.getBody(), null, reqBody.getContentType(), 201);
|
||||
document = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
|
||||
// Check the upload response
|
||||
assertEquals(fileName2, document.getName());
|
||||
@@ -1244,7 +1226,7 @@ public class NodeApiTest extends AbstractBaseApiTest
|
||||
.setProperties(props)
|
||||
.build();
|
||||
|
||||
response = post(getNodeChildrenUrl(folderA_id), userOneN1.getId(), reqBody.getBody(), null, reqBody.getContentType(), 201);
|
||||
response = post(getNodeChildrenUrl(folderA_id), user1, reqBody.getBody(), null, reqBody.getContentType(), 201);
|
||||
document = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
|
||||
// Check the upload response
|
||||
// "quick-2-1.txt" => fileName2 + autoRename
|
||||
@@ -1265,7 +1247,7 @@ public class NodeApiTest extends AbstractBaseApiTest
|
||||
.setProperties(props)
|
||||
.build();
|
||||
// Prop prefix is unknown
|
||||
post(getNodeChildrenUrl(folderA_id), userOneN1.getId(), reqBody.getBody(), null, reqBody.getContentType(), 400);
|
||||
post(getNodeChildrenUrl(folderA_id), user1, reqBody.getBody(), null, reqBody.getContentType(), 400);
|
||||
|
||||
// Test relativePath multi-part field.
|
||||
// Any folders in the relativePath that do not exist, are created before the content is created.
|
||||
@@ -1274,7 +1256,7 @@ public class NodeApiTest extends AbstractBaseApiTest
|
||||
.setRelativePath("X/Y/Z");
|
||||
reqBody = multiPartBuilder.build();
|
||||
|
||||
response = post(getNodeChildrenUrl(folderA_id), userOneN1.getId(), reqBody.getBody(), "?include=path", reqBody.getContentType(), 201);
|
||||
response = post(getNodeChildrenUrl(folderA_id), user1, reqBody.getBody(), "?include=path", reqBody.getContentType(), 201);
|
||||
document = jacksonUtil.parseEntry(response.getJsonResponse(), Document.class);
|
||||
// Check the upload response
|
||||
assertEquals(fileName, document.getName());
|
||||
@@ -1298,7 +1280,7 @@ public class NodeApiTest extends AbstractBaseApiTest
|
||||
reqBody = MultiPartBuilder.copy(multiPartBuilder)
|
||||
.setRelativePath("X/Y/Z/" + document.getName())
|
||||
.build();
|
||||
post(getNodeChildrenUrl(folderA_id), userOneN1.getId(), reqBody.getBody(), null, reqBody.getContentType(), 409);
|
||||
post(getNodeChildrenUrl(folderA_id), user1, reqBody.getBody(), null, reqBody.getContentType(), 409);
|
||||
|
||||
// Test the same functionality as "mkdir -p x/y/z" which the folders should be created
|
||||
// as needed but no errors thrown if the path or any part of the path already exists.
|
||||
@@ -1306,7 +1288,7 @@ public class NodeApiTest extends AbstractBaseApiTest
|
||||
reqBody = MultiPartBuilder.copy(multiPartBuilder)
|
||||
.setRelativePath("/X/ Y/Z /CoolFolder/")
|
||||
.build();
|
||||
response = post(getNodeChildrenUrl(folderA_id), userOneN1.getId(), reqBody.getBody(), null, reqBody.getContentType(), 201);
|
||||
response = post(getNodeChildrenUrl(folderA_id), user1, reqBody.getBody(), null, reqBody.getContentType(), 201);
|
||||
document = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
|
||||
// Check the upload response
|
||||
assertEquals(fileName, document.getName());
|
||||
@@ -1315,7 +1297,7 @@ public class NodeApiTest extends AbstractBaseApiTest
|
||||
assertEquals(MimetypeMap.MIMETYPE_TEXT_PLAIN, contentInfo.getMimeType());
|
||||
|
||||
// Retrieve the uploaded file parent folder
|
||||
response = getSingle(NodesEntityResource.class, userOneN1.getId(), document.getParentId(), null, 200);
|
||||
response = getSingle(NodesEntityResource.class, user1, document.getParentId(), null, 200);
|
||||
Folder coolFolder = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Folder.class);
|
||||
assertEquals(document.getParentId(), coolFolder.getId());
|
||||
assertEquals("CoolFolder", coolFolder.getName());
|
||||
@@ -1325,13 +1307,13 @@ public class NodeApiTest extends AbstractBaseApiTest
|
||||
.setRelativePath(" ")// blank
|
||||
.build();
|
||||
// 409 -> as the blank string is ignored and quick-1.txt already exists in the coolFolder
|
||||
post(getNodeChildrenUrl(coolFolder.getId()), userOneN1.getId(), reqBody.getBody(), null, reqBody.getContentType(), 409);
|
||||
post(getNodeChildrenUrl(coolFolder.getId()), user1, reqBody.getBody(), null, reqBody.getContentType(), 409);
|
||||
|
||||
// userTwoN1 tries to upload the same file by creating sub-folders in the folderA of userOneN1
|
||||
// user2 tries to upload the same file by creating sub-folders in the folderA of user1
|
||||
reqBody = MultiPartBuilder.copy(multiPartBuilder)
|
||||
.setRelativePath("userTwoFolder1/userTwoFolder2")
|
||||
.build();
|
||||
post(getNodeChildrenUrl(folderA_id), userTwoN1.getId(), reqBody.getBody(), null, reqBody.getContentType(), 403);
|
||||
post(getNodeChildrenUrl(folderA_id), user2, reqBody.getBody(), null, reqBody.getContentType(), 403);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1353,7 +1335,7 @@ public class NodeApiTest extends AbstractBaseApiTest
|
||||
// delete file
|
||||
deleteNode(content1Id);
|
||||
|
||||
assertTrue(existsArchiveNode(user1, content1Id));
|
||||
assertTrue(existsArchiveNode(content1Id));
|
||||
|
||||
// -ve test
|
||||
deleteNode(content1Id, 404);
|
||||
@@ -1366,9 +1348,9 @@ public class NodeApiTest extends AbstractBaseApiTest
|
||||
// cascade delete folder
|
||||
deleteNode(folder1Id);
|
||||
|
||||
assertTrue(existsArchiveNode(user1, folder1Id));
|
||||
assertTrue(existsArchiveNode(user1, folder2Id));
|
||||
assertTrue(existsArchiveNode(user1, content2Id));
|
||||
assertTrue(existsArchiveNode(folder1Id));
|
||||
assertTrue(existsArchiveNode(folder2Id));
|
||||
assertTrue(existsArchiveNode(content2Id));
|
||||
|
||||
// -ve test
|
||||
deleteNode(folder2Id, 404);
|
||||
@@ -1387,8 +1369,8 @@ public class NodeApiTest extends AbstractBaseApiTest
|
||||
|
||||
deleteNode(folder3Id, true, 204);
|
||||
|
||||
assertFalse(existsArchiveNode(user1, folder3Id));
|
||||
assertFalse(existsArchiveNode(user1, folder4Id));
|
||||
assertFalse(existsArchiveNode(folder3Id));
|
||||
assertFalse(existsArchiveNode(folder4Id));
|
||||
|
||||
String sharedNodeId = getSharedNodeId();
|
||||
String folder5Id = createFolder(sharedNodeId, "folder " + runId + "_5").getId();
|
||||
@@ -1450,20 +1432,18 @@ public class NodeApiTest extends AbstractBaseApiTest
|
||||
deleteNode(ddNodeId, true, 403);
|
||||
}
|
||||
|
||||
private boolean existsArchiveNode(String userId, String nodeId)
|
||||
private boolean existsArchiveNode(String nodeId) throws Exception
|
||||
{
|
||||
// TODO replace with calls to future V1 REST API for Trashcan
|
||||
try
|
||||
boolean result = false;
|
||||
|
||||
HttpResponse response = publicApiClient.get(getScope(), URL_DELETED_NODES, nodeId, null, null, null);
|
||||
if ((response != null) && (response.getStatusCode() == 200))
|
||||
{
|
||||
AuthenticationUtil.setFullyAuthenticatedUser(userId);
|
||||
NodeRef originalNodeRef = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, nodeId);
|
||||
NodeRef archiveNodeRef = nodeArchiveService.getArchivedNode(originalNodeRef);
|
||||
return nodeService.exists(archiveNodeRef);
|
||||
}
|
||||
finally
|
||||
{
|
||||
AuthenticationUtil.clearCurrentSecurityContext();
|
||||
Node node = jacksonUtil.parseEntry(response.getJsonResponse(), Node.class);
|
||||
result = ((node != null) && (node.getId() != null));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1713,7 +1693,7 @@ public class NodeApiTest extends AbstractBaseApiTest
|
||||
@Test
|
||||
public void testCopySite() throws Exception
|
||||
{
|
||||
setRequestContext(networkOne.getId(), userOneN1.getId(), null);
|
||||
setRequestContext(user1);
|
||||
|
||||
// create folder
|
||||
Folder folderResp = createFolder(Nodes.PATH_MY, "siteCopytarget");
|
||||
@@ -1723,14 +1703,13 @@ public class NodeApiTest extends AbstractBaseApiTest
|
||||
body.put("targetParentId", targetId);
|
||||
|
||||
//test that you can't copy a site
|
||||
HttpResponse response = getSingle("sites", userOneN1.getId(), userOneN1SiteId, null, null, 200);
|
||||
HttpResponse response = getSingle("sites", user1, tSiteId, null, null, 200);
|
||||
Site siteResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Site.class);
|
||||
String siteNodeId = siteResp.getGuid();
|
||||
post("nodes/"+siteNodeId+"/copy", userOneN1.getId(), toJsonAsStringNonNull(body), null, 422);
|
||||
post("nodes/"+siteNodeId+"/copy", user1, toJsonAsStringNonNull(body), null, 422);
|
||||
|
||||
//test that you can't copy a site doclib
|
||||
String docLibNodeId = getSiteContainerNodeId(userOneN1SiteId, "documentLibrary");
|
||||
post("nodes/"+docLibNodeId+"/copy", userOneN1.getId(), toJsonAsStringNonNull(body), null, 422);
|
||||
post("nodes/"+tDocLibNodeId+"/copy", user1, toJsonAsStringNonNull(body), null, 422);
|
||||
|
||||
}
|
||||
|
||||
@@ -1746,91 +1725,91 @@ public class NodeApiTest extends AbstractBaseApiTest
|
||||
@Test
|
||||
public void testMoveCopyBetweenSites() throws Exception
|
||||
{
|
||||
setRequestContext(networkOne.getId(), userOneN1.getId(), null);
|
||||
setRequestContext(user1);
|
||||
|
||||
/*
|
||||
* Precondition - create two sites, invite users, create folders
|
||||
*/
|
||||
|
||||
// userOneN1 creates a public site and adds userTwoN1 as a site collaborator
|
||||
// user1 creates a public site and adds user2 as a site collaborator
|
||||
String site1Title = "RandomSite1-" + System.currentTimeMillis();
|
||||
final String site1Id = createSite(site1Title, SiteVisibility.PUBLIC).getId();
|
||||
addSiteMember(site1Id, userTwoN1.getId(), SiteRole.SiteCollaborator);
|
||||
addSiteMember(site1Id, user2, SiteRole.SiteCollaborator);
|
||||
|
||||
// Get user1Site's docLib node id
|
||||
final String user1SiteDocLibNodeId = getSiteContainerNodeId(site1Id, "documentLibrary");
|
||||
final String user1SitetDocLibNodeId = getSiteContainerNodeId(site1Id, "documentLibrary");
|
||||
|
||||
// userOneN1 creates a folder in the docLib of his site (user1Site)
|
||||
// user1 creates a folder in the docLib of his site (user1Site)
|
||||
String user1Folder = "folder" + System.currentTimeMillis() + "_user1";
|
||||
String user1FolderNodeId = createFolder(user1SiteDocLibNodeId, user1Folder, null).getId();
|
||||
String user1FolderNodeId = createFolder(user1SitetDocLibNodeId, user1Folder, null).getId();
|
||||
|
||||
setRequestContext(userTwoN1.getDefaultAccount().getId(), userTwoN1.getId(), null);
|
||||
setRequestContext(user2);
|
||||
|
||||
// userTwoN1 creates a public site and adds userOneN1 as a site collaborator
|
||||
// user2 creates a public site and adds user1 as a site collaborator
|
||||
String site2Title = "RandomSite2-" + System.currentTimeMillis();
|
||||
final String site2Id = createSite(site2Title, SiteVisibility.PUBLIC).getId();
|
||||
addSiteMember(site2Id, userOneN1.getId(), SiteRole.SiteCollaborator);
|
||||
addSiteMember(site2Id, user1, SiteRole.SiteCollaborator);
|
||||
|
||||
// Get user2Site's docLib node id
|
||||
final String user2SiteDocLibNodeId = getSiteContainerNodeId(site2Id, "documentLibrary");
|
||||
final String user2SitetDocLibNodeId = getSiteContainerNodeId(site2Id, "documentLibrary");
|
||||
|
||||
// userTwoN1 creates 2 folders within the docLib of the user1Site
|
||||
// user2 creates 2 folders within the docLib of the user1Site
|
||||
String user2Folder1 = "folder1" + System.currentTimeMillis() + "_user2";
|
||||
String user2FolderNodeId = createFolder(user1SiteDocLibNodeId, user2Folder1, null).getId();
|
||||
String user2FolderNodeId = createFolder(user1SitetDocLibNodeId, user2Folder1, null).getId();
|
||||
|
||||
String user2Folder2 = "folder2" + System.currentTimeMillis() + "_user2";
|
||||
String user2Folder2NodeId = createFolder(user1SiteDocLibNodeId, user2Folder2, null).getId();
|
||||
String user2Folder2NodeId = createFolder(user1SitetDocLibNodeId, user2Folder2, null).getId();
|
||||
|
||||
/*
|
||||
* Test move between sites
|
||||
*/
|
||||
// userOneN1 moves the folder created by userTwoN1 to the user2Site's docLib
|
||||
// user1 moves the folder created by user2 to the user2Site's docLib
|
||||
|
||||
setRequestContext(networkOne.getId(), userOneN1.getId(), null);
|
||||
setRequestContext(user1);
|
||||
|
||||
NodeTarget target = new NodeTarget();
|
||||
target.setTargetParentId(user2SiteDocLibNodeId);
|
||||
HttpResponse response = post("nodes/" + user2FolderNodeId + "/move", userOneN1.getId(), toJsonAsStringNonNull(target), null, 200);
|
||||
target.setTargetParentId(user2SitetDocLibNodeId);
|
||||
HttpResponse response = post("nodes/" + user2FolderNodeId + "/move", user1, toJsonAsStringNonNull(target), null, 200);
|
||||
Folder moveFolderResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Folder.class);
|
||||
assertEquals(user2SiteDocLibNodeId, moveFolderResp.getParentId());
|
||||
assertEquals(user2SitetDocLibNodeId, moveFolderResp.getParentId());
|
||||
|
||||
// userOneN1 tries to undo the move (moves back the folder to its original place)
|
||||
// as userOneN1 is just a SiteCollaborator in the user2Site, he can't move the folder which he doesn't own - ACL access permission.
|
||||
// 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(user1SiteDocLibNodeId);
|
||||
post("nodes/" + user2FolderNodeId + "/move", userOneN1.getId(), toJsonAsStringNonNull(target), null, 403);
|
||||
target.setTargetParentId(user1SitetDocLibNodeId);
|
||||
post("nodes/" + user2FolderNodeId + "/move", user1, toJsonAsStringNonNull(target), null, 403);
|
||||
|
||||
// userOneN1 moves the folder created by himself to the docLib of the user2Site
|
||||
// user1 moves the folder created by himself to the docLib of the user2Site
|
||||
target = new NodeTarget();
|
||||
target.setTargetParentId(user2SiteDocLibNodeId);
|
||||
response = post("nodes/" + user1FolderNodeId + "/move", userOneN1.getId(), toJsonAsStringNonNull(target), null, 200);
|
||||
target.setTargetParentId(user2SitetDocLibNodeId);
|
||||
response = post("nodes/" + user1FolderNodeId + "/move", user1, toJsonAsStringNonNull(target), null, 200);
|
||||
moveFolderResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Folder.class);
|
||||
assertEquals(user2SiteDocLibNodeId, moveFolderResp.getParentId());
|
||||
assertEquals(user2SitetDocLibNodeId, moveFolderResp.getParentId());
|
||||
|
||||
// userOneN1 tries to undo the move (moves back the folder to its original place)
|
||||
// The undo should be successful as userOneN1 owns the folder
|
||||
// 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(user1SiteDocLibNodeId);
|
||||
response = post("nodes/" + user1FolderNodeId + "/move", userOneN1.getId(), toJsonAsStringNonNull(target), null, 200);
|
||||
target.setTargetParentId(user1SitetDocLibNodeId);
|
||||
response = post("nodes/" + user1FolderNodeId + "/move", user1, toJsonAsStringNonNull(target), null, 200);
|
||||
moveFolderResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Folder.class);
|
||||
assertEquals(user1SiteDocLibNodeId, moveFolderResp.getParentId());
|
||||
assertEquals(user1SitetDocLibNodeId, moveFolderResp.getParentId());
|
||||
|
||||
|
||||
/*
|
||||
* Test copy between sites
|
||||
*/
|
||||
// userOneN1 copies the folder created by userTwoN1 to the user2Site's docLib
|
||||
// user1 copies the folder created by user2 to the user2Site's docLib
|
||||
target = new NodeTarget();
|
||||
target.setTargetParentId(user2SiteDocLibNodeId);
|
||||
response = post("nodes/" + user2Folder2NodeId + "/copy", userOneN1.getId(), toJsonAsStringNonNull(target), null, 201);
|
||||
target.setTargetParentId(user2SitetDocLibNodeId);
|
||||
response = post("nodes/" + user2Folder2NodeId + "/copy", user1, toJsonAsStringNonNull(target), null, 201);
|
||||
Folder copyFolderResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Folder.class);
|
||||
assertEquals(user2SiteDocLibNodeId, copyFolderResp.getParentId());
|
||||
assertEquals(user2SitetDocLibNodeId, copyFolderResp.getParentId());
|
||||
|
||||
// userOneN1 tries to undo the copy (hard deletes the created copy)
|
||||
// user1 tries to undo the copy (hard deletes the created copy)
|
||||
deleteNode( copyFolderResp.getId(), true, 204);
|
||||
|
||||
// Check it's deleted
|
||||
getSingle("nodes", userOneN1.getId(), copyFolderResp.getId(), 404);
|
||||
getSingle("nodes", user1, copyFolderResp.getId(), 404);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -3397,11 +3376,11 @@ public class NodeApiTest extends AbstractBaseApiTest
|
||||
|
||||
publicApiClient.setRequestContext(null);
|
||||
|
||||
// as userOneN1 ...
|
||||
String userId = userOneN1.getId();
|
||||
// as user1 ...
|
||||
String userId = user1;
|
||||
setRequestContext(userId);
|
||||
|
||||
response = getSingle("sites", userId, userOneN1SiteId, null, null, 200);
|
||||
response = getSingle("sites", userId, tSiteId, null, null, 200);
|
||||
Site siteResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Site.class);
|
||||
String siteNodeId = siteResp.getGuid();
|
||||
|
||||
|
@@ -26,14 +26,13 @@
|
||||
package org.alfresco.rest.api.tests;
|
||||
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.rest.api.Nodes;
|
||||
import org.alfresco.rest.AbstractSingleNetworkSiteTest;
|
||||
import org.alfresco.rest.api.model.AssocChild;
|
||||
import org.alfresco.rest.api.model.AssocTarget;
|
||||
import org.alfresco.rest.api.nodes.NodesEntityResource;
|
||||
import org.alfresco.rest.api.tests.client.HttpResponse;
|
||||
import org.alfresco.rest.api.tests.client.PublicApiClient;
|
||||
import org.alfresco.rest.api.tests.client.PublicApiClient.Paging;
|
||||
import org.alfresco.rest.api.tests.client.RequestContext;
|
||||
import org.alfresco.rest.api.tests.client.data.Association;
|
||||
import org.alfresco.rest.api.tests.client.data.Node;
|
||||
import org.alfresco.rest.api.tests.util.RestApiUtil;
|
||||
@@ -75,7 +74,7 @@ import static org.junit.Assert.*;
|
||||
*
|
||||
* @author janv
|
||||
*/
|
||||
public class NodeAssociationsApiTest extends AbstractBaseApiTest
|
||||
public class NodeAssociationsApiTest extends AbstractSingleNetworkSiteTest
|
||||
{
|
||||
private static final String URL_DELETED_NODES = "deleted-nodes";
|
||||
|
||||
|
@@ -25,6 +25,7 @@
|
||||
*/
|
||||
package org.alfresco.rest.api.tests;
|
||||
|
||||
import org.alfresco.rest.AbstractSingleNetworkSiteTest;
|
||||
import org.alfresco.rest.api.Nodes;
|
||||
import org.alfresco.rest.api.model.VersionOptions;
|
||||
import org.alfresco.rest.api.nodes.NodesEntityResource;
|
||||
@@ -57,7 +58,7 @@ import static org.junit.Assert.*;
|
||||
*
|
||||
* @author janv
|
||||
*/
|
||||
public class NodeVersionsApiTest extends AbstractBaseApiTest
|
||||
public class NodeVersionsApiTest extends AbstractSingleNetworkSiteTest
|
||||
{
|
||||
private static final String URL_DELETED_NODES = "deleted-nodes";
|
||||
private static final String URL_VERSIONS = "versions";
|
||||
|
@@ -25,6 +25,7 @@
|
||||
*/
|
||||
package org.alfresco.rest.api.tests;
|
||||
|
||||
import org.alfresco.rest.AbstractSingleNetworkSiteTest;
|
||||
import org.alfresco.rest.api.Nodes;
|
||||
import org.alfresco.rest.api.Queries;
|
||||
import org.alfresco.rest.api.tests.client.HttpResponse;
|
||||
@@ -57,7 +58,7 @@ import static org.junit.Assert.*;
|
||||
*
|
||||
* @author janv
|
||||
*/
|
||||
public class QueriesApiTest extends AbstractBaseApiTest
|
||||
public class QueriesApiTest extends AbstractSingleNetworkSiteTest
|
||||
{
|
||||
private static final String URL_QUERIES_LSN = "queries/live-search-nodes";
|
||||
|
||||
|
Reference in New Issue
Block a user