Merged RETURN-OF-THE-API (5.2.0) to 5.2.N (5.2.1)

128537 jvonka: V1 REST API: Api Test cleanup and rationalisation (re: helper methods / runAs user / admin) - round 1
   REPO-113


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@129171 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Martin Muller
2016-08-05 13:47:03 +00:00
parent 6d4716b5c0
commit ebeb96f576
10 changed files with 639 additions and 749 deletions

View File

@@ -75,14 +75,15 @@ public class DeletedNodesTest extends AbstractSingleNetworkSiteTest
@Test
public void testCreateAndDelete() throws Exception
{
publicApiClient.setRequestContext(new RequestContext(u1.getId()));
setRequestContext(u1.getId());
Date now = new Date();
String folder1 = "folder" + now.getTime() + "_1";
Folder createdFolder = createFolder(u1.getId(), docLibNodeRef.getId(), folder1, null);
Folder createdFolder = createFolder(docLibNodeRef.getId(), folder1, null);
assertNotNull(createdFolder);
//Create a folder outside a site
Folder createdFolderNonSite = createFolder(u1.getId(), Nodes.PATH_MY, folder1, null);
Folder createdFolderNonSite = createFolder(Nodes.PATH_MY, folder1, null);
assertNotNull(createdFolderNonSite);
Document document = createDocument(createdFolder, "d1.txt");
@@ -160,14 +161,15 @@ public class DeletedNodesTest extends AbstractSingleNetworkSiteTest
@Test
public void testCreateAndRestore() throws Exception
{
publicApiClient.setRequestContext(new RequestContext(u1.getId()));
setRequestContext(u1.getId());
Date now = new Date();
String folder1 = "folder" + now.getTime() + "_1";
Folder createdFolder = createFolder(u1.getId(), docLibNodeRef.getId(), folder1, null);
Folder createdFolder = createFolder(docLibNodeRef.getId(), folder1, null);
assertNotNull(createdFolder);
//Create a folder outside a site
Folder createdFolderNonSite = createFolder(u1.getId(), Nodes.PATH_MY, folder1, null);
Folder createdFolderNonSite = createFolder(Nodes.PATH_MY, folder1, null);
assertNotNull(createdFolderNonSite);
Document document = createDocument(createdFolder, "restoreme.txt");
@@ -204,10 +206,11 @@ public class DeletedNodesTest extends AbstractSingleNetworkSiteTest
@Test
public void testCreateAndPurge() throws Exception
{
publicApiClient.setRequestContext(new RequestContext(u1.getId()));
setRequestContext(u1.getId());
Date now = new Date();
String folder1 = "folder" + now.getTime() + "_1";
Folder createdFolder = createFolder(u1.getId(), docLibNodeRef.getId(), folder1, null);
Folder createdFolder = createFolder(docLibNodeRef.getId(), folder1, null);
assertNotNull(createdFolder);
delete(URL_NODES, u1.getId(), createdFolder.getId(), 204);

View File

@@ -31,9 +31,11 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.fail;
import org.alfresco.repo.content.MimetypeMap;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.tenant.TenantUtil;
import org.alfresco.repo.tenant.TenantUtil.TenantRunAsWork;
import org.alfresco.repo.transaction.RetryingTransactionHelper;
import org.alfresco.rest.api.Nodes;
import org.alfresco.rest.api.model.Site;
import org.alfresco.rest.api.nodes.NodesEntityResource;
@@ -53,9 +55,12 @@ import org.alfresco.rest.api.tests.client.data.Rendition;
import org.alfresco.rest.api.tests.client.data.SiteRole;
import org.alfresco.rest.api.tests.util.MultiPartBuilder;
import org.alfresco.rest.api.tests.util.RestApiUtil;
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;
import org.alfresco.util.TempFileProvider;
import org.junit.After;
import org.junit.Before;
import org.springframework.util.ResourceUtils;
import java.io.ByteArrayInputStream;
@@ -63,7 +68,9 @@ import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
/**
@@ -91,9 +98,88 @@ public abstract class AbstractBaseApiTest extends EnterpriseTestApi
protected static final String ASSOC_TYPE_CM_CONTAINS = "cm:contains";
// TODO improve admin-related tests, including ability to override default admin un/pw
protected static final String DEFAULT_ADMIN = "admin";
private static final String DEFAULT_ADMIN_PWD = "admin";
protected TestNetwork networkOne;
/**
* User one from network one
*/
protected TestPerson userOneN1;
/**
* User two from network one
*/
protected TestPerson userTwoN1;
protected TestSite userOneN1Site;
protected String user1;
protected String user2;
private List<String> users = new ArrayList<>();
protected MutableAuthenticationService authenticationService;
protected PersonService personService;
protected final String RUNID = System.currentTimeMillis()+"";
@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);
user2 = createUser("user2-" + RUNID);
// to enable admin access via test calls - eg. after clean/purge
getOrCreateUser("admin", "admin");
// We just need to clean the on-premise-users,
// so the tests for the specific network would work.
users.add(user1);
users.add(user2);
networkOne = getTestFixture().getRandomNetwork();
userOneN1 = networkOne.createUser();
userTwoN1 = networkOne.createUser();
userOneN1Site = createSite(networkOne, userOneN1, SiteVisibility.PRIVATE);
}
@After
public void tearDown() throws Exception
{
deleteSite(networkOne.getId(), userOneN1.getId(), userOneN1Site.getSiteId(), 204);
AuthenticationUtil.setAdminUserAsFullyAuthenticatedUser();
for (final String user : users)
{
transactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Void>()
{
@Override
public Void execute() throws Throwable
{
if (personService.personExists(user))
{
authenticationService.deleteAuthentication(user);
personService.deletePerson(user);
}
return null;
}
});
}
users.clear();
AuthenticationUtil.clearCurrentSecurityContext();
}
/**
* The api scope. either public or private
*
* @return public or private
*/
public abstract String getScope();
@@ -420,16 +506,16 @@ public abstract class AbstractBaseApiTest extends EnterpriseTestApi
/**
* Helper: to get site container id (see also RepoService.getContainerNodeRef -> SiteService.getContainer)
*
* <p>
* GET /nodes/-root?relativePath=/Sites/siteId/documentLibrary
*
* <p>
* alternatively:
*
* <p>
* GET /nodes/siteNodeId?relativePath=documentLibrary
*/
protected String getSiteContainerNodeId(String networkId, String runAsUserId, String siteId, String containerNameId) throws Exception
{
Map<String, String> params = Collections.singletonMap(Nodes.PARAM_RELATIVE_PATH, "/Sites/"+siteId+"/"+containerNameId);
Map<String, String> params = Collections.singletonMap(Nodes.PARAM_RELATIVE_PATH, "/Sites/" + siteId + "/" + containerNameId);
publicApiClient.setRequestContext(new RequestContext(networkId, runAsUserId));
@@ -448,11 +534,6 @@ public abstract class AbstractBaseApiTest extends EnterpriseTestApi
}, testSite.getNetworkId());
}
protected NodeRef getSiteDocLib(final TestSite testSite)
{
return TenantUtil.runAsTenant(() -> testSite.getContainerNodeRef(("documentLibrary")), testSite.getNetworkId());
}
protected void checkStatus(int expectedStatus, int actualStatus)
{
if (expectedStatus > 0 && expectedStatus != actualStatus)
@@ -461,46 +542,60 @@ public abstract class AbstractBaseApiTest extends EnterpriseTestApi
}
}
// -root- (eg. Company Home for on-prem)
protected String getRootNodeId(String runAsUserId) throws Exception
protected void setRequestContext(String runAsUser)
{
HttpResponse response = getSingle(NodesEntityResource.class, runAsUserId, Nodes.PATH_ROOT, null, 200);
if ((runAsUser != null) && runAsUser.equals(DEFAULT_ADMIN))
{
// TODO improve "admin" related tests
publicApiClient.setRequestContext(new RequestContext("-default-", DEFAULT_ADMIN, DEFAULT_ADMIN_PWD));
}
else
{
publicApiClient.setRequestContext(new RequestContext(runAsUser));
}
}
// -root- (eg. Company Home for on-prem)
protected String getRootNodeId() throws Exception
{
HttpResponse response = getSingle(NodesEntityResource.class, publicApiClient.getRequestContext().getRunAsUser(), Nodes.PATH_ROOT, null, 200);
Node node = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
return node.getId();
}
// -my- (eg. User's Home for on-prem)
protected String getMyNodeId(String runAsUserId) throws Exception
protected String getMyNodeId() throws Exception
{
HttpResponse response = getSingle(NodesEntityResource.class, runAsUserId, Nodes.PATH_MY, null, 200);
HttpResponse response = getSingle(NodesEntityResource.class, publicApiClient.getRequestContext().getRunAsUser(), Nodes.PATH_MY, null, 200);
Node node = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
return node.getId();
}
// -shared- (eg. "Shared" folder for on-prem)
protected String getSharedNodeId(String runAsUserId) throws Exception
protected String getSharedNodeId() throws Exception
{
HttpResponse response = getSingle(NodesEntityResource.class, runAsUserId, Nodes.PATH_SHARED, null, 200);
HttpResponse response = getSingle(NodesEntityResource.class, publicApiClient.getRequestContext().getRunAsUser(), Nodes.PATH_SHARED, null, 200);
Node node = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
return node.getId();
}
protected Folder createFolder(String runAsUserId, String parentId, String folderName) throws Exception
protected Folder createFolder(String parentId, String folderName) throws Exception
{
return createFolder(runAsUserId, parentId, folderName, null);
return createFolder(parentId, folderName, null);
}
protected Folder createFolder(String runAsUserId, String parentId, String folderName, Map<String, Object> props) throws Exception
protected Folder createFolder(String parentId, String folderName, Map<String, Object> props) throws Exception
{
return createNode(runAsUserId, parentId, folderName, TYPE_CM_FOLDER, props, Folder.class);
return createNode(parentId, folderName, TYPE_CM_FOLDER, props, Folder.class);
}
protected Node createNode(String runAsUserId, String parentId, String nodeName, String nodeType, Map<String, Object> props) throws Exception
protected Node createNode(String parentId, String nodeName, String nodeType, Map<String, Object> props) throws Exception
{
return createNode(runAsUserId, parentId, nodeName, nodeType, props, Node.class);
return createNode(parentId, nodeName, nodeType, props, Node.class);
}
protected <T> T createNode(String runAsUserId, String parentId, String nodeName, String nodeType, Map<String, Object> props, Class<T> returnType)
protected <T> T createNode(String parentId, String nodeName, String nodeType, Map<String, Object> props, Class<T> returnType)
throws Exception
{
Node n = new Node();
@@ -509,22 +604,43 @@ public abstract class AbstractBaseApiTest extends EnterpriseTestApi
n.setProperties(props);
// create node
HttpResponse response = post(getNodeChildrenUrl(parentId), runAsUserId, RestApiUtil.toJsonAsStringNonNull(n), 201);
HttpResponse response = post(getNodeChildrenUrl(parentId), publicApiClient.getRequestContext().getRunAsUser(), RestApiUtil.toJsonAsStringNonNull(n), 201);
return RestApiUtil.parseRestApiEntry(response.getJsonResponse(), returnType);
}
protected Document createTextFile(String userId, String parentId, String fileName, String textContent) throws IOException, Exception
protected void deleteNode(String nodeId) throws Exception
{
return createTextFile(userId, parentId, fileName, textContent, "UTF-8", null);
deleteNode(nodeId, 204);
}
protected Document createTextFile(String userId, String parentId, String fileName, String textContent, String encoding, Map<String,String> props) throws IOException, Exception
protected void deleteNode(String nodeId, int expectedStatus) throws Exception
{
return createTextFile(userId, parentId, fileName, textContent, encoding, props, 201);
deleteNode(nodeId, false, expectedStatus);
}
protected Document createTextFile(String userId, String parentId, String fileName, String textContent, String encoding, Map<String,String> props, int expectedStatus) throws IOException, Exception
protected void deleteNode(String nodeId, boolean permanent, int expectedStatus) throws Exception
{
Map params = null;
if (permanent == true)
{
params = Collections.singletonMap("permanent", "true");
}
delete(URL_NODES, publicApiClient.getRequestContext().getRunAsUser(), nodeId, params, expectedStatus);
}
protected Document createTextFile(String parentId, String fileName, String textContent) throws IOException, Exception
{
return createTextFile(parentId, fileName, textContent, "UTF-8", null);
}
protected Document createTextFile(String parentId, String fileName, String textContent, String encoding, Map<String, String> props) throws IOException, Exception
{
return createTextFile(parentId, fileName, textContent, encoding, props, 201);
}
protected Document createTextFile(String parentId, String fileName, String textContent, String encoding, Map<String, String> props, int expectedStatus) throws IOException, Exception
{
if (props == null)
{
@@ -540,7 +656,7 @@ public abstract class AbstractBaseApiTest extends EnterpriseTestApi
.setProperties(props)
.build();
HttpResponse response = post(getNodeChildrenUrl(parentId), userId, reqBody.getBody(), null, reqBody.getContentType(), expectedStatus);
HttpResponse response = post(getNodeChildrenUrl(parentId), publicApiClient.getRequestContext().getRunAsUser(), reqBody.getBody(), null, reqBody.getContentType(), expectedStatus);
if (response.getJsonResponse().get("error") != null)
{
@@ -550,13 +666,13 @@ public abstract class AbstractBaseApiTest extends EnterpriseTestApi
return RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
}
protected Document updateTextFile(String userId, String contentId, String textContent, Map<String,String> parameters) throws IOException, Exception
protected Document updateTextFile(String contentId, String textContent, Map<String, String> parameters) throws IOException, Exception
{
ByteArrayInputStream inputStream = new ByteArrayInputStream(textContent.getBytes());
File txtFile = TempFileProvider.createTempFile(inputStream, getClass().getSimpleName(), ".txt");
BinaryPayload payload = new BinaryPayload(txtFile);
HttpResponse response = putBinary(getNodeContentUrl(contentId), userId, payload, null, parameters, 200);
HttpResponse response = putBinary(getNodeContentUrl(contentId), publicApiClient.getRequestContext().getRunAsUser(), payload, null, parameters, 200);
return RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
}
@@ -573,14 +689,14 @@ public abstract class AbstractBaseApiTest extends EnterpriseTestApi
protected static final long PAUSE_TIME = 5000; //millisecond
protected static final int MAX_RETRY = 20;
protected Rendition waitAndGetRendition(String userId, String sourceNodeId, String renditionId) throws Exception
protected Rendition waitAndGetRendition(String sourceNodeId, String renditionId) throws Exception
{
int retryCount = 0;
while (retryCount < MAX_RETRY)
{
try
{
HttpResponse response = getSingle(getNodeRenditionsUrl(sourceNodeId), userId, renditionId, 200);
HttpResponse response = getSingle(getNodeRenditionsUrl(sourceNodeId), publicApiClient.getRequestContext().getRunAsUser(), renditionId, 200);
Rendition rendition = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Rendition.class);
assertNotNull(rendition);
assertEquals(Rendition.RenditionStatus.CREATED, rendition.getStatus());
@@ -600,7 +716,7 @@ public abstract class AbstractBaseApiTest extends EnterpriseTestApi
return null;
}
protected Rendition createAndGetRendition(String userId, String sourceNodeId, String renditionId) throws Exception
protected Rendition createAndGetRendition(String sourceNodeId, String renditionId) throws Exception
{
Rendition renditionRequest = new Rendition();
renditionRequest.setId(renditionId);
@@ -610,7 +726,7 @@ public abstract class AbstractBaseApiTest extends EnterpriseTestApi
{
try
{
HttpResponse res = post(getNodeRenditionsUrl(sourceNodeId), userId, toJsonAsString(renditionRequest), 202);
HttpResponse res = post(getNodeRenditionsUrl(sourceNodeId), publicApiClient.getRequestContext().getRunAsUser(), toJsonAsString(renditionRequest), 202);
assertNull(res.getJsonResponse());
break;
}
@@ -625,7 +741,7 @@ public abstract class AbstractBaseApiTest extends EnterpriseTestApi
}
}
return waitAndGetRendition(userId, sourceNodeId, renditionId);
return waitAndGetRendition(sourceNodeId, renditionId);
}
protected String getNodeRenditionsUrl(String nodeId)

View File

@@ -60,8 +60,10 @@ public class ActivitiesPostingTest extends AbstractSingleNetworkSiteTest
@Test
public void testCreateUpdate() throws Exception
{
setRequestContext(u1.getId());
String folder1 = "folder" + System.currentTimeMillis() + "_1";
Folder createdFolder = createFolder(u1.getId(), docLibNodeRef.getId(), folder1, null);
Folder createdFolder = createFolder(docLibNodeRef.getId(), folder1, null);
assertNotNull(createdFolder);
String docName = "d1.txt";
@@ -77,8 +79,8 @@ public class ActivitiesPostingTest extends AbstractSingleNetworkSiteTest
String textContent = response.getResponse();
assertNotNull(textContent);
delete(URL_NODES, u1.getId(), documentResp.getId(), 204);
delete(URL_NODES, u1.getId(), createdFolder.getId(), 204);
deleteNode(documentResp.getId());
deleteNode(createdFolder.getId());
List<Activity> activities = getMyActivities();
assertEquals(activities.size(),6);
@@ -107,16 +109,18 @@ public class ActivitiesPostingTest extends AbstractSingleNetworkSiteTest
@Test
public void testNonFileActivities() throws Exception
{
setRequestContext(u1.getId());
String folder1 = "InSitefolder" + System.currentTimeMillis() + "_1";
Folder createdFolder = createFolder(u1.getId(), docLibNodeRef.getId(), folder1, null);
Folder createdFolder = createFolder(docLibNodeRef.getId(), folder1, null);
assertNotNull(createdFolder);
List<Activity> activities = getMyActivities();
Node aNode = createNode(u1.getId(), createdFolder.getId(), "mynode", "cm:failedThumbnail", null);
Node aNode = createNode(createdFolder.getId(), "mynode", "cm:failedThumbnail", null);
assertNotNull(aNode);
delete(URL_NODES, u1.getId(), aNode.getId(), 204);
deleteNode(aNode.getId());
List<Activity> activitiesAgain = getMyActivities();
assertEquals("No activites should be created for non-file activities", activities, activitiesAgain);
@@ -128,10 +132,12 @@ public class ActivitiesPostingTest extends AbstractSingleNetworkSiteTest
@Test
public void testNonSite() throws Exception
{
setRequestContext(u1.getId());
List<Activity> activities = getMyActivities();
String folder1 = "nonSitefolder" + System.currentTimeMillis() + "_1";
//Create a folder outside a site
Folder createdFolder = createFolder(u1.getId(), Nodes.PATH_MY, folder1, null);
Folder createdFolder = createFolder(Nodes.PATH_MY, folder1, null);
assertNotNull(createdFolder);
String docName = "nonsite_d1.txt";
@@ -156,7 +162,8 @@ public class ActivitiesPostingTest extends AbstractSingleNetworkSiteTest
{
repoService.generateFeed();
publicApiClient.setRequestContext(new RequestContext(u1.getId()));
setRequestContext(u1.getId());
Map<String, String> meParams = new HashMap<>();
meParams.put("who", String.valueOf(Activities.ActivityWho.me));
return publicApiClient.people().getActivities(u1.getId(), meParams).getList();

View File

@@ -27,8 +27,6 @@ package org.alfresco.rest.api.tests;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
import org.alfresco.rest.api.Nodes;
import org.alfresco.rest.api.People;
import org.alfresco.rest.api.model.LoginTicket;
@@ -39,14 +37,9 @@ import org.alfresco.rest.api.tests.client.PublicApiClient.Paging;
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.RestApiUtil;
import org.alfresco.service.cmr.security.MutableAuthenticationService;
import org.alfresco.service.cmr.security.PersonService;
import org.apache.commons.codec.binary.Base64;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
@@ -61,49 +54,6 @@ public class AuthenticationsTest extends AbstractBaseApiTest
private static final String TICKETS_URL = "tickets";
private static final String TICKETS_API_NAME = "authentication";
private String user1;
private String user2;
private List<String> users = new ArrayList<>();
private MutableAuthenticationService authenticationService;
private PersonService personService;
@Before
public void setup() throws Exception
{
authenticationService = applicationContext.getBean("authenticationService", MutableAuthenticationService.class);
personService = applicationContext.getBean("personService", PersonService.class);
user1 = createUser("user1" + System.currentTimeMillis(), "user1Password");
user2 = createUser("user2" + System.currentTimeMillis(), "user2Password");
users.add(user1);
users.add(user2);
AuthenticationUtil.clearCurrentSecurityContext();
}
@After
public void tearDown() throws Exception
{
AuthenticationUtil.setAdminUserAsFullyAuthenticatedUser();
for (final String user : users)
{
transactionHelper.doInTransaction(new RetryingTransactionCallback<Void>()
{
@Override
public Void execute() throws Throwable
{
if (personService.personExists(user))
{
authenticationService.deleteAuthentication(user);
personService.deletePerson(user);
}
return null;
}
});
}
users.clear();
AuthenticationUtil.clearCurrentSecurityContext();
}
/**
* Tests login (create ticket), logout (delete ticket), and validate (get ticket).
@@ -121,6 +71,7 @@ public class AuthenticationsTest extends AbstractBaseApiTest
public void testCreateValidateDeleteTicket() throws Exception
{
Paging paging = getPaging(0, 100);
// Unauthorized call
getAll(SiteEntityResource.class, null, paging, null, 401);
@@ -189,8 +140,10 @@ public class AuthenticationsTest extends AbstractBaseApiTest
* user2 login - Via Authorization header
*/
setRequestContext(user2);
// User2 create a folder within his home folder (-my-)
Folder folderResp = createFolder(user2, Nodes.PATH_MY, "F2", null);
Folder folderResp = createFolder(Nodes.PATH_MY, "F2", null);
assertNotNull(folderResp.getId());
getAll(getNodeChildrenUrl(Nodes.PATH_MY), null, paging, 401);

File diff suppressed because it is too large Load Diff

View File

@@ -26,7 +26,6 @@
package org.alfresco.rest.api.tests;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
import org.alfresco.rest.api.Nodes;
import org.alfresco.rest.api.model.AssocChild;
import org.alfresco.rest.api.model.AssocTarget;
@@ -40,10 +39,7 @@ import org.alfresco.rest.api.tests.client.data.Node;
import org.alfresco.rest.api.tests.util.RestApiUtil;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.service.cmr.security.MutableAuthenticationService;
import org.alfresco.service.cmr.security.PermissionService;
import org.alfresco.service.cmr.security.PersonService;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -101,60 +97,6 @@ public class NodeAssociationsApiTest extends AbstractBaseApiTest
private static final String URL_SECONDARY_CHILDREN = "secondary-children";
private static final String URL_PARENTS = "parents";
private String user1;
private String user2;
private List<String> users = new ArrayList<>();
protected MutableAuthenticationService authenticationService;
protected PermissionService permissionService;
protected PersonService personService;
private final String RUNID = System.currentTimeMillis()+"";
@Before
public void setup() throws Exception
{
authenticationService = applicationContext.getBean("authenticationService", MutableAuthenticationService.class);
permissionService = applicationContext.getBean("permissionService", PermissionService.class);
personService = applicationContext.getBean("personService", PersonService.class);
// note: createUser currently relies on repoService
user1 = createUser("user1-" + RUNID);
user2 = createUser("user2-" + RUNID);
// We just need to clean the on-premise-users,
// so the tests for the specific network would work.
users.add(user1);
users.add(user2);
}
@After
public void tearDown() throws Exception
{
AuthenticationUtil.setAdminUserAsFullyAuthenticatedUser();
for (final String user : users)
{
transactionHelper.doInTransaction(new RetryingTransactionCallback<Void>()
{
@Override
public Void execute() throws Throwable
{
if (personService.personExists(user))
{
authenticationService.deleteAuthentication(user);
personService.deletePerson(user);
}
return null;
}
});
}
users.clear();
AuthenticationUtil.clearCurrentSecurityContext();
}
protected String getNodeTargetsUrl(String nodeId)
{
return URL_NODES + "/" + nodeId + "/" + URL_TARGETS;
@@ -175,6 +117,16 @@ public class NodeAssociationsApiTest extends AbstractBaseApiTest
return URL_NODES + "/" + nodeId + "/" + URL_PARENTS;
}
private PermissionService permissionService;
@Before
public void setup() throws Exception
{
super.setup();
permissionService = applicationContext.getBean("permissionService", PermissionService.class);
}
/**
* Tests basic api to manage (add, list, remove) node peer associations (ie. source node -> target node)
*
@@ -191,10 +143,12 @@ public class NodeAssociationsApiTest extends AbstractBaseApiTest
@Test
public void testNodePeerAssocs() throws Exception
{
String myFolderNodeId = getMyNodeId(user1);
setRequestContext(user1);
String myFolderNodeId = getMyNodeId();
// create folder
String f1Id = createFolder(user1, myFolderNodeId, "f1").getId();
String f1Id = createFolder(myFolderNodeId, "f1").getId();
// create content node
Node n = new Node();
@@ -205,7 +159,7 @@ public class NodeAssociationsApiTest extends AbstractBaseApiTest
String o1Id = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class).getId();
// create ano' folder
String f2Id = createFolder(user1, myFolderNodeId, "f2").getId();
String f2Id = createFolder(myFolderNodeId, "f2").getId();
// create ano' content node
n = new Node();
@@ -477,11 +431,12 @@ public class NodeAssociationsApiTest extends AbstractBaseApiTest
@Test
public void testNodePeerAssocsPermissions() throws Exception
{
setRequestContext(user1);
// as user 1 - create folder in "Shared Files" area and content within the folder
String sharedFolderNodeId = getSharedNodeId();
String sharedFolderNodeId = getSharedNodeId(user1);
String sf1Id = createFolder(user1, sharedFolderNodeId, "shared folder "+RUNID).getId();
String sf1Id = createFolder(sharedFolderNodeId, "shared folder "+RUNID).getId();
Node n = new Node();
n.setName("shared content "+RUNID);
@@ -493,9 +448,9 @@ public class NodeAssociationsApiTest extends AbstractBaseApiTest
// as user 1 - create folder in user's home (My Files) area and content within the folder
String u1myNodeId = getMyNodeId(user1);
String u1myNodeId = getMyNodeId();
String u1f1Id = createFolder(user1, u1myNodeId, "f1").getId();
String u1f1Id = createFolder(u1myNodeId, "f1").getId();
n = new Node();
n.setName("o1");
@@ -506,9 +461,11 @@ public class NodeAssociationsApiTest extends AbstractBaseApiTest
// as user 2 - create folder in user's home (My Files) area and content within the folder
String u2myNodeId = getMyNodeId(user2);
setRequestContext(user2);
String u2f1Id = createFolder(user2, u2myNodeId, "f1").getId();
String u2myNodeId = getMyNodeId();
String u2f1Id = createFolder(u2myNodeId, "f1").getId();
n = new Node();
n.setName("o1");
@@ -519,6 +476,8 @@ public class NodeAssociationsApiTest extends AbstractBaseApiTest
try
{
setRequestContext(user1);
Paging paging = getPaging(0, 100);
// empty lists - before
@@ -675,7 +634,9 @@ public class NodeAssociationsApiTest extends AbstractBaseApiTest
@Test
public void testNodeSecondaryChildAssocs() throws Exception
{
String myFolderNodeId = getMyNodeId(user1);
setRequestContext(user1);
String myFolderNodeId = getMyNodeId();
// create folder
Node n = new Node();
@@ -694,7 +655,7 @@ public class NodeAssociationsApiTest extends AbstractBaseApiTest
String o1Id = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class).getId();
// create ano' folder
String f2Id = createFolder(user1, myFolderNodeId, "f2").getId();
String f2Id = createFolder(myFolderNodeId, "f2").getId();
// create ano' content node
String o2Name = "o2";
@@ -705,9 +666,9 @@ public class NodeAssociationsApiTest extends AbstractBaseApiTest
String o2Id = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class).getId();
String f3Id = createFolder(user1, myFolderNodeId, "f3").getId();
String f3Id = createFolder(myFolderNodeId, "f3").getId();
String f4Id = createFolder(user1, myFolderNodeId, "f4").getId();
String f4Id = createFolder(myFolderNodeId, "f4").getId();
try
@@ -1053,7 +1014,7 @@ public class NodeAssociationsApiTest extends AbstractBaseApiTest
for (int j = 0; j < parentCnt; j++)
{
String parentName = "parent "+j;
parentIds[j] = createFolder(user1, f4Id, parentName).getId();
parentIds[j] = createFolder(f4Id, parentName).getId();
secChild = new AssocChild(childId, ASSOC_TYPE_CM_CONTAINS);
post(getNodeSecondaryChildrenUrl(parentIds[j]), user1, toJsonAsStringNonNull(secChild), 201);
@@ -1227,6 +1188,7 @@ public class NodeAssociationsApiTest extends AbstractBaseApiTest
public void testDeleteAndRestoreNodeWithAssocs() throws Exception
{
// as user 1 ...
setRequestContext(user1);
String f1Id = null;
String f2Id = null;
@@ -1234,17 +1196,17 @@ public class NodeAssociationsApiTest extends AbstractBaseApiTest
try
{
String myFolderNodeId = getMyNodeId(user1);
String myFolderNodeId = getMyNodeId();
// create primary parent-child hierarchy
f1Id = createFolder(user1, myFolderNodeId, "f1").getId();
String f1bId = createFolder(user1, f1Id, "f1b").getId();
String f1cId = createFolder(user1, f1bId, "f1c").getId();
String f1dId = createFolder(user1, f1cId, "f1d").getId();
String c1eId = createTextFile(user1, f1dId, "c1e", "some text content").getId();
f1Id = createFolder(myFolderNodeId, "f1").getId();
String f1bId = createFolder(f1Id, "f1b").getId();
String f1cId = createFolder(f1bId, "f1c").getId();
String f1dId = createFolder(f1cId, "f1d").getId();
String c1eId = createTextFile(f1dId, "c1e", "some text content").getId();
f2Id = createFolder(user1, myFolderNodeId, "f2").getId();
f3Id = createFolder(user1, myFolderNodeId, "f3").getId();
f2Id = createFolder(myFolderNodeId, "f2").getId();
f3Id = createFolder(myFolderNodeId, "f3").getId();
HttpResponse response = getAll(getNodeParentsUrl(f1bId), user1, null, null, 200);
List<Node> nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
@@ -1446,7 +1408,9 @@ public class NodeAssociationsApiTest extends AbstractBaseApiTest
public void testCreateNodeWithAssocs() throws Exception
{
// as user 1
String myFolderNodeId = getMyNodeId(user1);
setRequestContext(user1);
String myFolderNodeId = getMyNodeId();
// create node with some assocs in a single call
@@ -1488,7 +1452,7 @@ public class NodeAssociationsApiTest extends AbstractBaseApiTest
response = post(getNodeChildrenUrl(myFolderNodeId), user1, toJsonAsStringNonNull(n), 201);
String f2Id = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class).getId();
String f3Id = createFolder(user1, myFolderNodeId, "f3").getId();
String f3Id = createFolder(myFolderNodeId, "f3").getId();
try
{

View File

@@ -25,8 +25,6 @@
*/
package org.alfresco.rest.api.tests;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
import org.alfresco.rest.api.Nodes;
import org.alfresco.rest.api.model.VersionOptions;
import org.alfresco.rest.api.nodes.NodesEntityResource;
@@ -36,20 +34,13 @@ import org.alfresco.rest.api.tests.client.PublicApiClient.Paging;
import org.alfresco.rest.api.tests.client.PublicApiHttpClient;
import org.alfresco.rest.api.tests.client.data.Document;
import org.alfresco.rest.api.tests.client.data.Node;
import org.alfresco.rest.api.tests.client.data.Rendition;
import org.alfresco.rest.api.tests.util.RestApiUtil;
import org.alfresco.service.cmr.security.MutableAuthenticationService;
import org.alfresco.service.cmr.security.PermissionService;
import org.alfresco.service.cmr.security.PersonService;
import org.alfresco.util.Pair;
import org.alfresco.util.TempFileProvider;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
@@ -70,58 +61,6 @@ public class NodeVersionsApiTest extends AbstractBaseApiTest
private static final String URL_DELETED_NODES = "deleted-nodes";
private static final String URL_VERSIONS = "versions";
private String user1;
private String user2;
private List<String> users = new ArrayList<>();
private final String RUNID = System.currentTimeMillis()+"";
protected MutableAuthenticationService authenticationService;
protected PermissionService permissionService;
protected PersonService personService;
@Before
public void setup() throws Exception
{
authenticationService = applicationContext.getBean("authenticationService", MutableAuthenticationService.class);
permissionService = applicationContext.getBean("permissionService", PermissionService.class);
personService = applicationContext.getBean("personService", PersonService.class);
// note: createUser currently relies on repoService
user1 = createUser("user1-" + RUNID);
user2 = createUser("user2-" + RUNID);
// We just need to clean the on-premise-users,
// so the tests for the specific network would work.
users.add(user1);
users.add(user2);
}
@After
public void tearDown() throws Exception
{
AuthenticationUtil.setAdminUserAsFullyAuthenticatedUser();
for (final String user : users)
{
transactionHelper.doInTransaction(new RetryingTransactionCallback<Void>()
{
@Override
public Void execute() throws Throwable
{
if (personService.personExists(user))
{
authenticationService.deleteAuthentication(user);
personService.deletePerson(user);
}
return null;
}
});
}
users.clear();
AuthenticationUtil.clearCurrentSecurityContext();
}
protected String getNodeVersionRevertUrl(String nodeId, String versionId)
{
return getNodeVersionsUrl(nodeId) + "/" + versionId + "/revert";
@@ -146,10 +85,12 @@ public class NodeVersionsApiTest extends AbstractBaseApiTest
@Test
public void testUploadFileVersionCreateWithOverwrite() throws Exception
{
String myFolderNodeId = getMyNodeId(user1);
setRequestContext(user1);
String myFolderNodeId = getMyNodeId();
// create folder
String f1Id = createFolder(user1, myFolderNodeId, "f1").getId();
String f1Id = createFolder(myFolderNodeId, "f1").getId();
try
{
@@ -164,7 +105,7 @@ public class NodeVersionsApiTest extends AbstractBaseApiTest
String content = textContentSuffix + verCnt;
// create first version (ie. 1.0)
Document documentResp = createTextFile(user1, f1Id, contentName, content, "UTF-8", null);
Document documentResp = createTextFile(f1Id, contentName, content, "UTF-8", null);
String docId = documentResp.getId();
assertTrue(documentResp.getAspectNames().contains("cm:versionable"));
assertNotNull(documentResp.getProperties());
@@ -196,7 +137,7 @@ public class NodeVersionsApiTest extends AbstractBaseApiTest
params.put(Nodes.PARAM_OVERWRITE, "true");
params.put(Nodes.PARAM_AUTO_RENAME, "true");
createTextFile(user1, myFolderNodeId, contentName, content, "UTF-8", params, 400);
createTextFile(myFolderNodeId, contentName, content, "UTF-8", params, 400);
}
// remove versionable aspect
@@ -223,7 +164,7 @@ public class NodeVersionsApiTest extends AbstractBaseApiTest
params = new HashMap<>();
params.put(Nodes.PARAM_OVERWRITE, "true");
createTextFile(user1, f1Id, contentName, content, "UTF-8", params, 409);
createTextFile(f1Id, contentName, content, "UTF-8", params, 409);
}
// we do allow update of binary content with no versioning (after removing versionable)
@@ -260,10 +201,12 @@ public class NodeVersionsApiTest extends AbstractBaseApiTest
@Test
public void testUploadFileVersionAsMinor() throws Exception
{
String myFolderNodeId = getMyNodeId(user1);
setRequestContext(user1);
String myFolderNodeId = getMyNodeId();
// create folder
String f1Id = createFolder(user1, myFolderNodeId, "f1").getId();
String f1Id = createFolder(myFolderNodeId, "f1").getId();
try
{
@@ -279,7 +222,7 @@ public class NodeVersionsApiTest extends AbstractBaseApiTest
params.put("majorVersion", "false");
// create a new file with a minor version (ie. 0.1)
Document documentResp = createTextFile(user1, f1Id, contentName, content, "UTF-8", params);
Document documentResp = createTextFile(f1Id, contentName, content, "UTF-8", params);
String docId = documentResp.getId();
assertTrue(documentResp.getAspectNames().contains("cm:versionable"));
assertNotNull(documentResp.getProperties());
@@ -319,14 +262,16 @@ public class NodeVersionsApiTest extends AbstractBaseApiTest
@Test
public void testDeleteVersion() throws Exception
{
String sharedFolderNodeId = getSharedNodeId(user1);
setRequestContext(user1);
String sharedFolderNodeId = getSharedNodeId();
// create folder
String f1Id = null;
try
{
f1Id = createFolder(user1, sharedFolderNodeId, "testDeleteVersion-f1").getId();
f1Id = createFolder(sharedFolderNodeId, "testDeleteVersion-f1").getId();
String textContentSuffix = "Amazingly few discotheques provide jukeboxes ";
String contentName = "content-1";
@@ -511,7 +456,7 @@ public class NodeVersionsApiTest extends AbstractBaseApiTest
String textContent = textContentPrefix + currentVersionCounter;
// uses upload with overwrite here ...
Document documentResp = createTextFile(userId, parentFolderNodeId, fileName, textContent, "UTF-8", params);
Document documentResp = createTextFile(parentFolderNodeId, fileName, textContent, "UTF-8", params);
docId = documentResp.getId();
assertTrue(documentResp.getAspectNames().contains("cm:versionable"));
assertNotNull(documentResp.getProperties());
@@ -628,10 +573,12 @@ public class NodeVersionsApiTest extends AbstractBaseApiTest
public void testUploadFileVersionUpdate() throws Exception
{
// As user 1 ...
String myFolderNodeId = getMyNodeId(user1);
setRequestContext(user1);
String myFolderNodeId = getMyNodeId();
// create folder
String f1Id = createFolder(user1, myFolderNodeId, "f1").getId();
String f1Id = createFolder(myFolderNodeId, "f1").getId();
try
{
@@ -646,7 +593,7 @@ public class NodeVersionsApiTest extends AbstractBaseApiTest
String contentName = "content " + System.currentTimeMillis();
String content = textContentSuffix+verCnt;
Document documentResp = createTextFile(user1, myFolderNodeId, contentName, content, "UTF-8", null);
Document documentResp = createTextFile(myFolderNodeId, contentName, content, "UTF-8", null);
String d1Id = documentResp.getId();
String versionId = majorVersion+"."+minorVersion;
@@ -762,14 +709,16 @@ public class NodeVersionsApiTest extends AbstractBaseApiTest
public void testRevert() throws Exception
{
// As user 1 ...
String sharedFolderNodeId = getSharedNodeId(user1);
setRequestContext(user1);
String sharedFolderNodeId = getSharedNodeId();
// create folder
String f1Id = null;
try
{
f1Id = createFolder(user1, sharedFolderNodeId, "testRevert-f1-"+System.currentTimeMillis()).getId();
f1Id = createFolder(sharedFolderNodeId, "testRevert-f1-"+System.currentTimeMillis()).getId();
int majorVersion = 1;
int minorVersion = 0;
@@ -784,7 +733,7 @@ public class NodeVersionsApiTest extends AbstractBaseApiTest
params.put(Nodes.PARAM_VERSION_COMMENT, updateVerCommentSuffix+verCnt);
// Upload text file - versioning is currently auto enabled on upload (create file via multi-part/form-data)
Document documentResp = createTextFile(user1, f1Id, contentName, content, "UTF-8", params);
Document documentResp = createTextFile(f1Id, contentName, content, "UTF-8", params);
String d1Id = documentResp.getId();
// Update the content
@@ -946,10 +895,12 @@ public class NodeVersionsApiTest extends AbstractBaseApiTest
public void testCreateEmptyFileVersionUpdate() throws Exception
{
// As user 1 ...
String myFolderNodeId = getMyNodeId(user1);
setRequestContext(user1);
String myFolderNodeId = getMyNodeId();
// create folder
String f1Id = createFolder(user1, myFolderNodeId, "f1").getId();
String f1Id = createFolder(myFolderNodeId, "f1").getId();
try
{
@@ -1111,7 +1062,9 @@ public class NodeVersionsApiTest extends AbstractBaseApiTest
@Test
public void testUpdateFileVersionCreate() throws Exception
{
String myNodeId = getMyNodeId(user1);
setRequestContext(user1);
String myNodeId = getMyNodeId();
Document d1 = new Document();
d1.setName("d1.txt");
@@ -1134,7 +1087,7 @@ public class NodeVersionsApiTest extends AbstractBaseApiTest
// Update the empty node's content - no version created
String content = "The quick brown fox jumps over the lazy dog " + cnt;
documentResp = updateTextFile(user1, docId, content, null);
documentResp = updateTextFile(docId, content, null);
assertFalse(documentResp.getAspectNames().contains("cm:versionable"));
assertNull(documentResp.getProperties()); // no properties (ie. no "cm:versionLabel")
}
@@ -1150,7 +1103,7 @@ public class NodeVersionsApiTest extends AbstractBaseApiTest
Map<String, String> params = new HashMap<>();
params.put("comment", "my version "+cnt);
documentResp = updateTextFile(user1, docId, content, params);
documentResp = updateTextFile(docId, content, params);
assertTrue(documentResp.getAspectNames().contains("cm:versionable"));
assertNotNull(documentResp.getProperties());
@@ -1164,7 +1117,7 @@ public class NodeVersionsApiTest extends AbstractBaseApiTest
params = new HashMap<>();
params.put("comment", "my version "+cnt);
documentResp = updateTextFile(user1, docId, content, params);
documentResp = updateTextFile(docId, content, params);
assertTrue(documentResp.getAspectNames().contains("cm:versionable"));
assertNotNull(documentResp.getProperties());
assertEquals(majorVersion+"."+minorVersion, documentResp.getProperties().get("cm:versionLabel"));
@@ -1183,7 +1136,7 @@ public class NodeVersionsApiTest extends AbstractBaseApiTest
params.put("comment", "my version "+cnt);
params.put("majorVersion", "true");
documentResp = updateTextFile(user1, docId, content, params);
documentResp = updateTextFile(docId, content, params);
assertTrue(documentResp.getAspectNames().contains("cm:versionable"));
assertNotNull(documentResp.getProperties());
assertEquals(majorVersion+"."+minorVersion, documentResp.getProperties().get("cm:versionLabel"));
@@ -1201,7 +1154,7 @@ public class NodeVersionsApiTest extends AbstractBaseApiTest
params.put("comment", "my version "+cnt);
params.put("majorVersion", "false");
documentResp = updateTextFile(user1, docId, content, params);
documentResp = updateTextFile(docId, content, params);
assertTrue(documentResp.getAspectNames().contains("cm:versionable"));
assertNotNull(documentResp.getProperties());
assertEquals(majorVersion+"."+minorVersion, documentResp.getProperties().get("cm:versionLabel"));
@@ -1218,7 +1171,7 @@ public class NodeVersionsApiTest extends AbstractBaseApiTest
params.put("comment", "my version "+cnt);
params.put("majorVersion", "true");
documentResp = updateTextFile(user1, docId, content, params);
documentResp = updateTextFile(docId, content, params);
assertTrue(documentResp.getAspectNames().contains("cm:versionable"));
assertNotNull(documentResp.getProperties());
assertEquals(majorVersion+"."+minorVersion, documentResp.getProperties().get("cm:versionLabel"));
@@ -1231,7 +1184,7 @@ public class NodeVersionsApiTest extends AbstractBaseApiTest
content = "The quick brown fox jumps over the lazy dog "+cnt;
documentResp = updateTextFile(user1, docId, content, null);
documentResp = updateTextFile(docId, content, null);
assertTrue(documentResp.getAspectNames().contains("cm:versionable"));
assertNotNull(documentResp.getProperties());
assertEquals(majorVersion+"."+minorVersion, documentResp.getProperties().get("cm:versionLabel"));
@@ -1254,7 +1207,7 @@ public class NodeVersionsApiTest extends AbstractBaseApiTest
// Update the empty node's content - no version created
content = "The quick brown fox jumps over the lazy dog " + cnt;
documentResp = updateTextFile(user1, docId, content, null);
documentResp = updateTextFile(docId, content, null);
assertFalse(documentResp.getAspectNames().contains("cm:versionable"));
assertNull(documentResp.getProperties()); // no properties (ie. no "cm:versionLabel")
}
@@ -1272,11 +1225,13 @@ public class NodeVersionsApiTest extends AbstractBaseApiTest
public void testVersionHistoryPaging() throws Exception
{
// create folder
setRequestContext(user1);
String f1Id = null;
try
{
f1Id = createFolder(user1, Nodes.PATH_MY, "testVersionHistoryPaging-f1").getId();
f1Id = createFolder(Nodes.PATH_MY, "testVersionHistoryPaging-f1").getId();
String textContentSuffix = "Amazingly few discotheques provide jukeboxes ";
String contentName = "content-1";

View File

@@ -25,8 +25,6 @@
*/
package org.alfresco.rest.api.tests;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
import org.alfresco.rest.api.Nodes;
import org.alfresco.rest.api.Queries;
import org.alfresco.rest.api.tests.client.HttpResponse;
@@ -38,10 +36,6 @@ 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.Tag;
import org.alfresco.rest.api.tests.util.RestApiUtil;
import org.alfresco.service.cmr.security.MutableAuthenticationService;
import org.alfresco.service.cmr.security.PersonService;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.util.ArrayList;
@@ -67,55 +61,6 @@ public class QueriesApiTest extends AbstractBaseApiTest
{
private static final String URL_QUERIES_LSN = "queries/live-search-nodes";
private String user1;
private String user2;
private List<String> users = new ArrayList<>();
protected MutableAuthenticationService authenticationService;
protected PersonService personService;
private final String RUNID = System.currentTimeMillis()+"";
@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);
user2 = createUser("user2-" + RUNID);
// We just need to clean the on-premise-users,
// so the tests for the specific network would work.
users.add(user1);
users.add(user2);
}
@After
public void tearDown() throws Exception
{
AuthenticationUtil.setAdminUserAsFullyAuthenticatedUser();
for (final String user : users)
{
transactionHelper.doInTransaction(new RetryingTransactionCallback<Void>()
{
@Override
public Void execute() throws Throwable
{
if (personService.personExists(user))
{
authenticationService.deleteAuthentication(user);
personService.deletePerson(user);
}
return null;
}
});
}
users.clear();
AuthenticationUtil.clearCurrentSecurityContext();
}
public static <K, V extends Comparable<? super V>> Map<K, V> sortByValue( Map<K, V> map )
{
List<Map.Entry<K, V>> list =
@@ -145,6 +90,8 @@ public class QueriesApiTest extends AbstractBaseApiTest
@Test
public void testLiveSearchNodes_FTS_and_Metadata() throws Exception
{
setRequestContext(user1);
int f1Count = 5;
List<String> f1NodeIds = new ArrayList<>(f1Count);
@@ -173,10 +120,10 @@ public class QueriesApiTest extends AbstractBaseApiTest
List<Node> nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
assertEquals(0, nodes.size());
String myFolderNodeId = getMyNodeId(user1);
String myFolderNodeId = getMyNodeId();
String f1Id = createFolder(user1, myFolderNodeId, "folder 1").getId();
String f2Id = createFolder(user1, myFolderNodeId, "folder 2").getId();
String f1Id = createFolder(myFolderNodeId, "folder 1").getId();
String f2Id = createFolder(myFolderNodeId, "folder 2").getId();
String name = "name";
String title = "title";
@@ -200,7 +147,7 @@ public class QueriesApiTest extends AbstractBaseApiTest
docProps.put("cm:title", title+num+title);
docProps.put("cm:description", descrip+num+descrip);
Document doc = createTextFile(user1, f1Id, docName, contentText, "UTF-8", docProps);
Document doc = createTextFile(f1Id, docName, contentText, "UTF-8", docProps);
f1NodeIds.add(doc.getId());
idNameMap.put(doc.getId(), docName);
@@ -221,7 +168,7 @@ public class QueriesApiTest extends AbstractBaseApiTest
props.put("cm:title", title+num+title);
props.put("cm:description", descrip+num+descrip);
Document doc = createTextFile(user1, f2Id, docName, contentText, "UTF-8", props);
Document doc = createTextFile(f2Id, docName, contentText, "UTF-8", props);
f2NodeIds.add(doc.getId());
idNameMap.put(doc.getId(), docName);
@@ -240,7 +187,7 @@ public class QueriesApiTest extends AbstractBaseApiTest
props.put("cm:title", title+num+title);
props.put("cm:description", descrip+num+descrip);
Node node = createFolder(user1, myFolderNodeId, folderName, props);
Node node = createFolder(myFolderNodeId, folderName, props);
f3NodeIds.add(node.getId());
idNameMap.put(node.getId(), folderName);
@@ -438,6 +385,8 @@ public class QueriesApiTest extends AbstractBaseApiTest
@Test
public void testLiveSearchNodes_SortPage() throws Exception
{
setRequestContext(user1);
int f1Count = 5;
List<String> f1NodeIds = new ArrayList<>(f1Count);
@@ -458,10 +407,10 @@ public class QueriesApiTest extends AbstractBaseApiTest
Map<String, String> params = new HashMap<>(1);
params.put(Queries.PARAM_TERM, testTerm);
String myFolderNodeId = getMyNodeId(user1);
String myFolderNodeId = getMyNodeId();
String f1Id = createFolder(user1, myFolderNodeId, "folder sort 1").getId();
String f2Id = createFolder(user1, myFolderNodeId, "folder sort 2").getId();
String f1Id = createFolder(myFolderNodeId, "folder sort 1").getId();
String f2Id = createFolder(myFolderNodeId, "folder sort 2").getId();
String name = "name";
@@ -476,7 +425,7 @@ public class QueriesApiTest extends AbstractBaseApiTest
String num = String.format("%05d", nameIdx);
String docName = name+num+name+".txt";
Document doc = createTextFile(user1, f1Id, docName, contentText, "UTF-8", null);
Document doc = createTextFile(f1Id, docName, contentText, "UTF-8", null);
f1NodeIds.add(doc.getId());
idNameMap.put(doc.getId(), docName);
@@ -493,7 +442,7 @@ public class QueriesApiTest extends AbstractBaseApiTest
String num = String.format("%05d", nameIdx);
String docName = name+num+name+".txt";
Document doc = createTextFile(user1, f2Id, docName, contentText, "UTF-8", null);
Document doc = createTextFile(f2Id, docName, contentText, "UTF-8", null);
f2NodeIds.add(doc.getId());
idNameMap.put(doc.getId(), docName);
@@ -625,11 +574,13 @@ public class QueriesApiTest extends AbstractBaseApiTest
getAll(URL_QUERIES_LSN, user1, paging, params, 400);
// -ve test - unauthenticated - belts-and-braces ;-)
setRequestContext(null);
getAll(URL_QUERIES_LSN, null, paging, params, 401);
}
finally
{
// some cleanup
setRequestContext(user1);
for (String docId : allIds)
{
delete(URL_NODES, user1, docId, 204);
@@ -640,6 +591,8 @@ public class QueriesApiTest extends AbstractBaseApiTest
@Test
public void testLiveSearchNodes_Tags() throws Exception
{
setRequestContext(user1);
PublicApiClient.Nodes nodesProxy = publicApiClient.nodes();
int f1Count = 5;
@@ -661,8 +614,8 @@ public class QueriesApiTest extends AbstractBaseApiTest
Paging paging = getPaging(0, 100);
String f1Id = createFolder(user1, Nodes.PATH_MY, "folder tag 1").getId();
String f2Id = createFolder(user1, Nodes.PATH_MY, "folder tag 2").getId();
String f1Id = createFolder(Nodes.PATH_MY, "folder tag 1").getId();
String f2Id = createFolder(Nodes.PATH_MY, "folder tag 2").getId();
String name = "name";
@@ -672,7 +625,7 @@ public class QueriesApiTest extends AbstractBaseApiTest
String contentText = "f1 test document " + user1 + " document " + i;
String docName = name+i;
Document doc = createTextFile(user1, f1Id, docName, contentText, "UTF-8", null);
Document doc = createTextFile(f1Id, docName, contentText, "UTF-8", null);
publicApiClient.setRequestContext(new RequestContext("", user1));
@@ -687,7 +640,7 @@ public class QueriesApiTest extends AbstractBaseApiTest
// create folder - in folder 2
String folderName = name+i;
Folder folder = createFolder(user1, f2Id, folderName, null);
Folder folder = createFolder(f2Id, folderName, null);
publicApiClient.setRequestContext(new RequestContext("", user1));
@@ -723,6 +676,7 @@ public class QueriesApiTest extends AbstractBaseApiTest
finally
{
// some cleanup
setRequestContext(user1);
for (String nodeId : allIds)
{
delete(URL_NODES, user1, nodeId, 204);

View File

@@ -114,6 +114,8 @@ public class RenditionsTest extends AbstractBaseApiTest
@Test
public void testListNodeRenditions() throws Exception
{
setRequestContext(userOneN1.getId());
// Create a folder within the site document's library
String folderName = "folder" + System.currentTimeMillis();
String folder_Id = addToDocumentLibrary(userOneN1Site, folderName, TYPE_CM_FOLDER, userOneN1.getId());
@@ -185,7 +187,7 @@ public class RenditionsTest extends AbstractBaseApiTest
assertTrue(expectedPaging.getTotalItems() >= 5);
// Create 'doclib' rendition
createAndGetRendition(userOneN1.getId(), contentNodeId, docLib.getId());
createAndGetRendition(contentNodeId, docLib.getId());
// List all available renditions (includes those that have been created and those that are yet to be created)
paging = getPaging(0, 50);
@@ -252,6 +254,8 @@ public class RenditionsTest extends AbstractBaseApiTest
@Test
public void testGetNodeRendition() throws Exception
{
setRequestContext(userOneN1.getId());
// Create a folder within the site document's library
String folderName = "folder" + System.currentTimeMillis();
String folder_Id = addToDocumentLibrary(userOneN1Site, folderName, TYPE_CM_FOLDER, userOneN1.getId());
@@ -280,7 +284,7 @@ public class RenditionsTest extends AbstractBaseApiTest
assertNull("Shouldn't have returned the size, as the rendition hasn't been created yet.", contentInfo.getSizeInBytes());
// Create and get 'doclib' rendition
rendition = createAndGetRendition(userOneN1.getId(), contentNodeId, "doclib");
rendition = createAndGetRendition(contentNodeId, "doclib");
assertNotNull(rendition);
assertEquals(RenditionStatus.CREATED, rendition.getStatus());
contentInfo = rendition.getContent();
@@ -334,6 +338,8 @@ public class RenditionsTest extends AbstractBaseApiTest
@Test
public void testCreateRendition() throws Exception
{
setRequestContext(userOneN1.getId());
// Create a folder within the site document's library
String folderName = "folder" + System.currentTimeMillis();
String folder_Id = addToDocumentLibrary(userOneN1Site, folderName, TYPE_CM_FOLDER, userOneN1.getId());
@@ -356,7 +362,7 @@ public class RenditionsTest extends AbstractBaseApiTest
assertEquals(RenditionStatus.NOT_CREATED, rendition.getStatus());
// Create and get 'imgpreview' rendition
rendition = createAndGetRendition(userOneN1.getId(), contentNodeId, "imgpreview");
rendition = createAndGetRendition(contentNodeId, "imgpreview");
assertNotNull(rendition);
assertEquals(RenditionStatus.CREATED, rendition.getStatus());
ContentInfo contentInfo = rendition.getContent();
@@ -466,6 +472,7 @@ public class RenditionsTest extends AbstractBaseApiTest
public void testCreateRenditionOnUpload() throws Exception
{
String userId = userOneN1.getId();
setRequestContext(userId);
// Create a folder within the site document's library
String folderName = "folder" + System.currentTimeMillis();
@@ -486,7 +493,7 @@ public class RenditionsTest extends AbstractBaseApiTest
String contentNodeId = document.getId();
// wait and check that rendition is created ...
Rendition rendition = waitAndGetRendition(userId, contentNodeId, renditionName);
Rendition rendition = waitAndGetRendition(contentNodeId, renditionName);
assertNotNull(rendition);
assertEquals(RenditionStatus.CREATED, rendition.getStatus());
@@ -586,6 +593,8 @@ public class RenditionsTest extends AbstractBaseApiTest
@Test
public void testDownloadRendition() throws Exception
{
setRequestContext(userOneN1.getId());
// Create a folder within the site document's library
String folderName = "folder" + System.currentTimeMillis();
String folder_Id = addToDocumentLibrary(userOneN1Site, folderName, TYPE_CM_FOLDER, userOneN1.getId());
@@ -645,7 +654,7 @@ public class RenditionsTest extends AbstractBaseApiTest
getSingle(getNodeRenditionsUrl(contentNodeId), userOneN1.getId(), "doclib/content", params, headers, 200);
// Create and get 'doclib' rendition
rendition = createAndGetRendition(userOneN1.getId(), contentNodeId, "doclib");
rendition = createAndGetRendition(contentNodeId, "doclib");
assertNotNull(rendition);
assertEquals(RenditionStatus.CREATED, rendition.getStatus());
@@ -761,7 +770,7 @@ public class RenditionsTest extends AbstractBaseApiTest
String networkId = repoService.tenantService.getUserDomain(userId);
String parentId = getSiteContainerNodeId(networkId, userId, testSite.getId(), "documentLibrary");
return createNode(userId, parentId, name, nodeType, null).getId();
return createNode(parentId, name, nodeType, null).getId();
}
private Rendition getRendition(List<Rendition> renditions, String renditionName)

View File

@@ -45,7 +45,6 @@ import org.alfresco.rest.api.tests.client.data.QuickShareLinkEmailRequest;
import org.alfresco.rest.api.tests.client.data.Rendition;
import org.alfresco.rest.api.tests.util.MultiPartBuilder;
import org.alfresco.rest.api.tests.util.RestApiUtil;
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;
@@ -80,74 +79,6 @@ public class SharedLinkApiTest extends AbstractBaseApiTest
{
private static final String URL_SHARED_LINKS = "shared-links";
TestNetwork networkOne;
/**
* User one from network one
*/
private TestPerson userOneN1;
/**
* User two from network one
*/
private TestPerson userTwoN1;
private TestSite userOneN1Site;
private String user1;
private String user2;
private List<String> users = new ArrayList<>();
protected MutableAuthenticationService authenticationService;
protected PersonService personService;
private final String RUNID = System.currentTimeMillis()+"";
@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);
user2 = createUser("user2-" + RUNID);
// We just need to clean the on-premise-users,
// so the tests for the specific network would work.
users.add(user1);
users.add(user2);
networkOne = getTestFixture().getRandomNetwork();
userOneN1 = networkOne.createUser();
userTwoN1 = networkOne.createUser();
userOneN1Site = createSite(networkOne, userOneN1, SiteVisibility.PRIVATE);
}
@After
public void tearDown() throws Exception
{
AuthenticationUtil.setAdminUserAsFullyAuthenticatedUser();
for (final String user : users)
{
transactionHelper.doInTransaction(new RetryingTransactionCallback<Void>()
{
@Override
public Void execute() throws Throwable
{
if (personService.personExists(user))
{
authenticationService.deleteAuthentication(user);
personService.deletePerson(user);
}
return null;
}
});
}
users.clear();
AuthenticationUtil.clearCurrentSecurityContext();
}
/**
* Tests shared links to file (content)
*
@@ -169,9 +100,10 @@ public class SharedLinkApiTest extends AbstractBaseApiTest
public void testSharedLinkCreateGetDelete() throws Exception
{
// As user 1 ...
setRequestContext(user1);
// create doc d1 - pdf
String sharedFolderNodeId = getSharedNodeId(user1);
String sharedFolderNodeId = getSharedNodeId();
String fileName1 = "quick"+RUNID+"_1.pdf";
File file1 = getResourceFile("quick.pdf");
@@ -190,17 +122,18 @@ public class SharedLinkApiTest extends AbstractBaseApiTest
String d1Id = doc1.getId();
// create doc d2 - plain text
String myFolderNodeId = getMyNodeId(user1);
String myFolderNodeId = getMyNodeId();
String content2Text = "The quick brown fox jumps over the lazy dog 2.";
String fileName2 = "content" + RUNID + "_2.txt";
Document doc2 = createTextFile(user1, myFolderNodeId, fileName2, content2Text);
Document doc2 = createTextFile(myFolderNodeId, fileName2, content2Text);
String d2Id = doc2.getId();
String file2_MimeType = MimetypeMap.MIMETYPE_TEXT_PLAIN;
// As user 2 ...
setRequestContext(user2);
response = getSingle(NodesEntityResource.class, user2, d1Id, null, 200);
Node nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
@@ -239,6 +172,7 @@ public class SharedLinkApiTest extends AbstractBaseApiTest
// As user 1 ...
setRequestContext(user1);
// create shared link to document 2
body = new HashMap<>();
@@ -287,6 +221,7 @@ public class SharedLinkApiTest extends AbstractBaseApiTest
resp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), QuickShareLink.class);
assertNull(resp.getAllowableOperations());
setRequestContext(null);
// unauth access to get shared link info
params = Collections.singletonMap("include", "allowableOperations"); // note: this will be ignore for unauth access
@@ -361,7 +296,7 @@ public class SharedLinkApiTest extends AbstractBaseApiTest
assertEquals(0, renditions.size());
// create rendition of pdf doc - note: for some reason create rendition of txt doc fail on build m/c (TBC) ?
Rendition rendition = createAndGetRendition(user2, d1Id, "doclib");
Rendition rendition = createAndGetRendition(d1Id, "doclib");
assertNotNull(rendition);
assertEquals(Rendition.RenditionStatus.CREATED, rendition.getStatus());
@@ -402,14 +337,17 @@ public class SharedLinkApiTest extends AbstractBaseApiTest
// -ve delete tests
{
// -ve test - user1 cannot delete shared link
delete(URL_SHARED_LINKS, user1, shared1Id, 403);
// -ve test - unauthenticated
delete(URL_SHARED_LINKS, null, shared1Id, 401);
setRequestContext(null);
deleteSharedLink(shared1Id, 401);
setRequestContext(user1);
// -ve test - user1 cannot delete shared link
deleteSharedLink(shared1Id, 403);
// -ve test - delete - cannot delete non-existent link
delete(URL_SHARED_LINKS, user1, "dummy", 404);
deleteSharedLink("dummy", 404);
}
@@ -432,7 +370,7 @@ public class SharedLinkApiTest extends AbstractBaseApiTest
post(URL_SHARED_LINKS, user1, toJsonAsStringNonNull(body), 404);
// -ve - create - try to link to folder (ie. not a file)
String f1Id = createFolder(user1, myFolderNodeId, "f1 " + RUNID).getId();
String f1Id = createFolder(myFolderNodeId, "f1 " + RUNID).getId();
body = new HashMap<>();
body.put("nodeId", f1Id);
post(URL_SHARED_LINKS, user1, toJsonAsStringNonNull(body), 400);
@@ -450,11 +388,14 @@ public class SharedLinkApiTest extends AbstractBaseApiTest
// delete shared link
delete(URL_SHARED_LINKS, user2, shared1Id, 204);
setRequestContext(user2);
deleteSharedLink(shared1Id);
// -ve test - delete - cannot delete non-existent link
delete(URL_SHARED_LINKS, user1, shared1Id, 404);
setRequestContext(user1);
deleteSharedLink(shared1Id, 404);
setRequestContext(user2);
response = getSingle(NodesEntityResource.class, user2, d1Id, null, 200);
nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
@@ -482,13 +423,15 @@ public class SharedLinkApiTest extends AbstractBaseApiTest
{
quickShareLinks.setEnabled(false);
setRequestContext(user1);
// -ve - disabled service tests
body.put("nodeId", "dummy");
post(URL_SHARED_LINKS, user1, toJsonAsStringNonNull(body), 501);
getSingle(QuickShareLinkEntityResource.class, null, "dummy", null, 501);
getSingle(QuickShareLinkEntityResource.class, null, "dummy/content", null, 501);
delete(URL_SHARED_LINKS, user1, "dummy", 501);
deleteSharedLink("dummy", 501);
}
finally
{
@@ -507,6 +450,9 @@ public class SharedLinkApiTest extends AbstractBaseApiTest
@Test
public void testSharedLinkFind() throws Exception
{
// As user 1 ...
setRequestContext(user1);
Paging paging = getPaging(0, 100);
// Get all shared links visible to user 1 (note: for now assumes clean repo)
@@ -514,25 +460,20 @@ public class SharedLinkApiTest extends AbstractBaseApiTest
List<QuickShareLink> sharedLinks = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), QuickShareLink.class);
assertEquals(0, sharedLinks.size());
// As user 1 ...
// create doc d1 - in "My" folder
String myFolderNodeId = getMyNodeId(user1);
String myFolderNodeId = getMyNodeId();
String content1Text = "The quick brown fox jumps over the lazy dog 1.";
String docName1 = "content" + RUNID + "_1.txt";
Document doc1 = createTextFile(user1, myFolderNodeId, docName1, content1Text);
Document doc1 = createTextFile(myFolderNodeId, docName1, content1Text);
String d1Id = doc1.getId();
// create doc d2 - in "Shared" folder
String sharedFolderNodeId = getSharedNodeId(user1);
String sharedFolderNodeId = getSharedNodeId();
String content2Text = "The quick brown fox jumps over the lazy dog 2.";
String docName2 = "content" + RUNID + "_2.txt";
Document doc2 = createTextFile(user1, sharedFolderNodeId, docName2, content1Text);
Document doc2 = createTextFile(sharedFolderNodeId, docName2, content1Text);
String d2Id = doc2.getId();
// As user 1 ...
// create shared link to doc 1
Map<String, String> body = new HashMap<>();
body.put("nodeId", d1Id);
@@ -541,6 +482,7 @@ public class SharedLinkApiTest extends AbstractBaseApiTest
String shared1Id = resp.getId();
// As user 2 ...
setRequestContext(user2);
// create shared link to doc 2
body = new HashMap<>();
@@ -554,6 +496,8 @@ public class SharedLinkApiTest extends AbstractBaseApiTest
// find links
//
setRequestContext(user1);
response = getAll(URL_SHARED_LINKS, user1, paging, 200);
sharedLinks = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), QuickShareLink.class);
assertEquals(2, sharedLinks.size());
@@ -562,12 +506,16 @@ public class SharedLinkApiTest extends AbstractBaseApiTest
assertEquals(shared1Id, sharedLinks.get(1).getId());
assertEquals(d1Id, sharedLinks.get(1).getNodeId());
setRequestContext(user2);
response = getAll(URL_SHARED_LINKS, user2, paging, 200);
sharedLinks = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), QuickShareLink.class);
assertEquals(1, sharedLinks.size());
assertEquals(shared2Id, sharedLinks.get(0).getId());
assertEquals(d2Id, sharedLinks.get(0).getNodeId());
setRequestContext(user1);
// find my links
Map<String, String> params = new HashMap<>();
params.put("where", "("+ QuickShareLinks.PARAM_SHAREDBY+"='"+People.DEFAULT_USER+"')");
@@ -588,19 +536,25 @@ public class SharedLinkApiTest extends AbstractBaseApiTest
assertEquals(shared2Id, sharedLinks.get(0).getId());
assertEquals(d2Id, sharedLinks.get(0).getNodeId());
setRequestContext(null);
// -ve test - unauthenticated
getAll(URL_SHARED_LINKS, null, paging, params, 401);
// delete the shared links
delete(URL_SHARED_LINKS, user1, shared1Id, 204);
delete(URL_SHARED_LINKS, user2, shared2Id, 204);
setRequestContext(user1);
deleteSharedLink(shared1Id);
setRequestContext(user2);
deleteSharedLink(shared2Id);
// TODO if and when these tests are optionally runnable via remote env then we could skip this part of the test
// (else need to verify test mechanism for enterprise admin via jmx ... etc)
setRequestContext(user1);
QuickShareLinksImpl quickShareLinks = applicationContext.getBean("quickShareLinks", QuickShareLinksImpl.class);
try
{
@@ -623,11 +577,13 @@ public class SharedLinkApiTest extends AbstractBaseApiTest
@Test
public void testEmailSharedLink() throws Exception
{
setRequestContext(user1);
// Create plain text document
String myFolderNodeId = getMyNodeId(user1);
String myFolderNodeId = getMyNodeId();
String contentText = "The quick brown fox jumps over the lazy dog.";
String fileName = "file-" + RUNID + ".txt";
Document doc = createTextFile(user1, myFolderNodeId, fileName, contentText);
Document doc = createTextFile(myFolderNodeId, fileName, contentText);
String docId = doc.getId();
// Create shared link to document
@@ -714,12 +670,12 @@ public class SharedLinkApiTest extends AbstractBaseApiTest
public void testSharedLinkCreateGetDelete_MultiTenant() throws Exception
{
// As userOneN1
AuthenticationUtil.setFullyAuthenticatedUser(userOneN1.getId());
NodeRef docLibNodeRef = userOneN1Site.getContainerNodeRef(("documentLibrary"));
String docLibNodeId = docLibNodeRef.getId();
setRequestContext(userOneN1.getId());
String docLibNodeId = getSiteContainerNodeId(userOneN1Site.getNetworkId(), userOneN1.getId(), userOneN1Site.getSiteId(), "documentLibrary");
String folderName = "folder" + System.currentTimeMillis() + "_1";
String folderId = createFolder(userOneN1.getId(), docLibNodeId, folderName, null).getId();
String folderId = createFolder(docLibNodeId, folderName, null).getId();
// create doc d1 - pdf
String fileName1 = "quick" + RUNID + "_1.pdf";
@@ -755,6 +711,8 @@ public class SharedLinkApiTest extends AbstractBaseApiTest
resp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), QuickShareLink.class);
assertNull(resp.getAllowableOperations());
setRequestContext(null);
// unauth access to get shared link info
Map<String, String> params = Collections.singletonMap("include", "allowableOperations"); // note: this will be ignore for unauth access
response = getSingle(QuickShareLinkEntityResource.class, null, shared1Id, params, 200);
@@ -805,7 +763,7 @@ public class SharedLinkApiTest extends AbstractBaseApiTest
assertEquals(0, renditions.size());
// create rendition of pdf doc - note: for some reason create rendition of txt doc fail on build m/c (TBC) ?
Rendition rendition = createAndGetRendition(userOneN1.getId(), d1Id, "doclib");
Rendition rendition = createAndGetRendition(d1Id, "doclib");
assertNotNull(rendition);
assertEquals(Rendition.RenditionStatus.CREATED, rendition.getStatus());
@@ -844,13 +802,16 @@ public class SharedLinkApiTest extends AbstractBaseApiTest
getSingle(URL_SHARED_LINKS, null, shared1Id + "/renditions/doclib/content", null, headers, 304);
// -ve test - userTwoN1 cannot delete shared link
delete(URL_SHARED_LINKS, userTwoN1.getId(), shared1Id, 403);
setRequestContext(userTwoN1.getId());
deleteSharedLink(shared1Id, 403);
// -ve test - unauthenticated
delete(URL_SHARED_LINKS, null, shared1Id, 401);
setRequestContext(null);
deleteSharedLink(shared1Id, 401);
// delete shared link
delete(URL_SHARED_LINKS, userOneN1.getId(), shared1Id, 204);
setRequestContext(userOneN1.getId());
deleteSharedLink(shared1Id);
}
@Override
@@ -863,4 +824,14 @@ public class SharedLinkApiTest extends AbstractBaseApiTest
{
return URL_SHARED_LINKS + '/' + sharedId + "/email";
}
private void deleteSharedLink(String sharedId) throws Exception
{
deleteSharedLink(sharedId, 204);
}
private void deleteSharedLink(String sharedId, int expectedStatus) throws Exception
{
delete(URL_SHARED_LINKS, publicApiClient.getRequestContext().getRunAsUser(), sharedId, expectedStatus);
}
}