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:
Alexandru Epure
2016-08-09 14:13:57 +00:00
parent 4498ab0a4a
commit 5cba40f420
8 changed files with 263 additions and 274 deletions

View File

@@ -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
{
authenticationService = applicationContext.getBean("authenticationService", MutableAuthenticationService.class);
personService = applicationContext.getBean("personService", PersonService.class);
jacksonUtil = new JacksonUtil(applicationContext.getBean("jsonHelper", JacksonHelper.class));
// createTestData=false
getTestFixture(false);
networkOne = getRepoService().createNetwork(this.getClass().getName().toLowerCase(), true);
networkOne.create();
u1 = networkOne.createUser();
setRequestContext(networkOne.getId(), u1.getId(), null);
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);
users.add(user1);
users.add(user2);
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();
}
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);
setRequestContext(networkOne.getId(), user1, null);
deleteSite(tSiteId, 204); // TODO permanent=true
super.tearDown();
}
}