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

128640 jvonka: V1 REST API: cleanup and rationalise new api tests (re: remotable helpers & runAs user / admin) - round 5
   REPO-113 (also relates to REPO-28, REPO-114, REPO-825)


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@129179 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Martin Muller
2016-08-05 13:47:37 +00:00
parent 3c1341e808
commit a65e2f48f1
11 changed files with 439 additions and 310 deletions

View File

@@ -27,27 +27,35 @@
package org.alfresco.rest; package org.alfresco.rest;
import org.alfresco.rest.api.tests.AbstractBaseApiTest; import org.alfresco.rest.api.tests.AbstractBaseApiTest;
import org.alfresco.rest.api.tests.util.JacksonUtil;
import org.alfresco.rest.framework.jacksonextensions.JacksonHelper;
import org.alfresco.service.cmr.security.MutableAuthenticationService;
import org.alfresco.service.cmr.security.PersonService;
import org.alfresco.service.cmr.site.SiteVisibility;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
/** /**
* Overrides AbstractBaseApiTest so that only a single network & site is created per test
* (instead of pre-creating multiple networks & sites)
*
* Can also be optionally tweaked locally to:
*
* - use the default network (ie. super tenant) => instead of creating a new tenant
*
* - re-use a single setup across test methods => although this does mean that each individual test method must either rely on uniquely created test data and/or cleanup
*
* Note: For now, these can be explicitly tweaked by a dev (do not commit)
* but in the future we could consider making these runtime options.
*
* @author Gethin James * @author Gethin James
* @author janv * @author janv
*/ */
public class AbstractSingleNetworkSiteTest extends AbstractBaseApiTest public class AbstractSingleNetworkSiteTest extends AbstractBaseApiTest
{ {
protected String tSiteId; // note: experimental - for local/dev-use only (YMMV) ;-)
protected String tDocLibNodeId; // - setting both to true should make the related tests run faster
// - if singleSetupNoTearDown=true then each individual test method should create unique data (or cleanup) to avoid interdependent test/run failures
protected JacksonUtil jacksonUtil; // - if useDefaultNetwork=true then no tenant will be created (ie. will use default/super tenant)
protected static boolean singleSetupNoTearDown = false;
// TODO make this a runtime option to allow creation of non-default network protected static boolean useDefaultNetwork = false;
protected final static boolean useDefaultNetwork = true;
private static boolean isSetup = false;
@Override @Override
public String getScope() public String getScope()
@@ -59,49 +67,30 @@ public class AbstractSingleNetworkSiteTest extends AbstractBaseApiTest
@Before @Before
public void setup() throws Exception public void setup() throws Exception
{ {
jacksonUtil = new JacksonUtil(applicationContext.getBean("jsonHelper", JacksonHelper.class)); if ((! isSetup) || (! singleSetupNoTearDown))
// createTestData=false
getTestFixture(false);
if (! useDefaultNetwork)
{ {
networkOne = getRepoService().createNetwork(this.getClass().getName().toLowerCase(), true); if (! useDefaultNetwork)
networkOne.create(); {
networkOne = getRepoService().createNetwork(this.getClass().getName().toLowerCase(), true);
networkOne.create();
}
else
{
networkOne = getRepoService().getSystemNetwork();
}
super.setup();
isSetup = true;
} }
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");
setRequestContext(null);
} }
@Override @Override
@After @After
public void tearDown() throws Exception public void tearDown() throws Exception
{ {
setRequestContext(networkOne.getId(), user1, null); if (! singleSetupNoTearDown)
deleteSite(tSiteId, 204); // TODO permanent=true {
super.tearDown();
super.tearDown(); }
} }
} }

View File

@@ -83,7 +83,7 @@ public class DeletedNodesTest extends AbstractSingleNetworkSiteTest
setRequestContext(user1); setRequestContext(user1);
Date now = new Date(); Date now = new Date();
String folder1 = "folder" + now.getTime() + "_1"; String folder1 = "folder-testCreateAndDelete-" + now.getTime() + "_1";
Folder createdFolder = createFolder(tDocLibNodeId, folder1, null); Folder createdFolder = createFolder(tDocLibNodeId, folder1, null);
assertNotNull(createdFolder); assertNotNull(createdFolder);
@@ -153,7 +153,7 @@ public class DeletedNodesTest extends AbstractSingleNetworkSiteTest
getSingle(URL_DELETED_NODES, "iddontexist", 404); getSingle(URL_DELETED_NODES, "iddontexist", 404);
//Now as admin //Now as admin
setRequestContext("admin"); setRequestContext(networkAdmin);
response = publicApiClient.get(getScope(), URL_DELETED_NODES, null, null, null, createParams(paging, null)); response = publicApiClient.get(getScope(), URL_DELETED_NODES, null, null, null, createParams(paging, null));
checkStatus(200, response.getStatusCode()); checkStatus(200, response.getStatusCode());
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);

View File

@@ -34,12 +34,12 @@ import static org.junit.Assert.fail;
import org.alfresco.repo.security.authentication.AuthenticationUtil; import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.tenant.TenantService; import org.alfresco.repo.tenant.TenantService;
import org.alfresco.repo.tenant.TenantUtil;
import org.alfresco.repo.transaction.RetryingTransactionHelper; import org.alfresco.repo.transaction.RetryingTransactionHelper;
import org.alfresco.rest.api.Nodes; import org.alfresco.rest.api.Nodes;
import org.alfresco.rest.api.model.Site; import org.alfresco.rest.api.model.Site;
import org.alfresco.rest.api.nodes.NodesEntityResource; import org.alfresco.rest.api.nodes.NodesEntityResource;
import org.alfresco.rest.api.tests.RepoService.TestNetwork; import org.alfresco.rest.api.tests.RepoService.TestNetwork;
import org.alfresco.rest.api.tests.RepoService.TestPerson;
import org.alfresco.rest.api.tests.client.HttpResponse; import org.alfresco.rest.api.tests.client.HttpResponse;
import org.alfresco.rest.api.tests.client.PublicApiClient; 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.BinaryPayload;
@@ -52,8 +52,10 @@ import org.alfresco.rest.api.tests.client.data.Node;
import org.alfresco.rest.api.tests.client.data.Rendition; import org.alfresco.rest.api.tests.client.data.Rendition;
import org.alfresco.rest.api.tests.client.data.SiteMember; 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.SiteRole;
import org.alfresco.rest.api.tests.util.JacksonUtil;
import org.alfresco.rest.api.tests.util.MultiPartBuilder; import org.alfresco.rest.api.tests.util.MultiPartBuilder;
import org.alfresco.rest.api.tests.util.RestApiUtil; import org.alfresco.rest.api.tests.util.RestApiUtil;
import org.alfresco.rest.framework.jacksonextensions.JacksonHelper;
import org.alfresco.service.cmr.security.MutableAuthenticationService; import org.alfresco.service.cmr.security.MutableAuthenticationService;
import org.alfresco.service.cmr.security.PersonService; import org.alfresco.service.cmr.security.PersonService;
import org.alfresco.service.cmr.site.SiteVisibility; import org.alfresco.service.cmr.site.SiteVisibility;
@@ -106,26 +108,24 @@ public abstract class AbstractBaseApiTest extends EnterpriseTestApi
protected static final String DEFAULT_ADMIN = "admin"; protected static final String DEFAULT_ADMIN = "admin";
private static final String DEFAULT_ADMIN_PWD = "admin"; private static final String DEFAULT_ADMIN_PWD = "admin";
protected TestNetwork networkOne; // network1 with user1, user2 and a testsite1
protected static TestNetwork networkOne;
/**
* User one from network one
*/
protected TestPerson userOneN1;
/**
* User two from network one
*/
protected TestPerson userTwoN1;
protected String userOneN1SiteId;
protected String user1;
protected String user2;
protected List<String> users = new ArrayList<>(); protected static String user1; // user1 from network1
protected static String user2; // user2 from network1
protected MutableAuthenticationService authenticationService; // network admin (or default super admin, if not running within a tenant/network)
protected PersonService personService; protected static String networkAdmin = DEFAULT_ADMIN;
protected static String tSiteId;
protected static String tDocLibNodeId;
protected static List<String> users = new ArrayList<>();
protected static JacksonUtil jacksonUtil;
protected static MutableAuthenticationService authenticationService;
protected static PersonService personService;
protected final String RUNID = System.currentTimeMillis()+""; protected final String RUNID = System.currentTimeMillis()+"";
@@ -133,12 +133,32 @@ public abstract class AbstractBaseApiTest extends EnterpriseTestApi
@Before @Before
public void setup() throws Exception public void setup() throws Exception
{ {
// note: createUser currently relies on repoService jacksonUtil = new JacksonUtil(applicationContext.getBean("jsonHelper", JacksonHelper.class));
user1 = createUser("user1-" + RUNID, "user1Password", null);
user2 = createUser("user2-" + RUNID, "user2Password", null); if (networkOne == null)
{
// note: populateTestData/createTestData will be called (which currently creates 2 tenants, 9 users per tenant, 10 sites per tenant, ...)
networkOne = getTestFixture().getRandomNetwork();
}
//userOneN1 = networkOne.createUser();
//userTwoN1 = networkOne.createUser();
String tenantDomain = networkOne.getId();
if (! TenantService.DEFAULT_DOMAIN.equals(tenantDomain))
{
networkAdmin = DEFAULT_ADMIN+"@"+tenantDomain;
}
// to enable admin access via test calls - eg. via PublicApiClient -> AbstractTestApi -> findUserByUserName // to enable admin access via test calls - eg. via PublicApiClient -> AbstractTestApi -> findUserByUserName
getOrCreateUser("admin", "admin"); getOrCreateUser(networkAdmin, "admin", networkOne);
setRequestContext(networkAdmin);
// note: createUser currently relies on repoService
user1 = createUser("user1-" + RUNID, "user1Password", networkOne);
user2 = createUser("user2-" + RUNID, "user2Password", networkOne);
// used-by teardown to cleanup // used-by teardown to cleanup
authenticationService = applicationContext.getBean("authenticationService", MutableAuthenticationService.class); authenticationService = applicationContext.getBean("authenticationService", MutableAuthenticationService.class);
@@ -146,14 +166,10 @@ public abstract class AbstractBaseApiTest extends EnterpriseTestApi
users.add(user1); users.add(user1);
users.add(user2); users.add(user2);
// TODO this causes createTestData to be called setRequestContext(networkOne.getId(), user1, null);
networkOne = getTestFixture().getRandomNetwork();
userOneN1 = networkOne.createUser();
userTwoN1 = networkOne.createUser();
setRequestContext(networkOne.getId(), userOneN1.getId(), null);
userOneN1SiteId = createSite("TestSite A - " + System.currentTimeMillis(), SiteVisibility.PRIVATE).getId(); tSiteId = createSite("TestSite A - " + RUNID, SiteVisibility.PRIVATE).getId();
tDocLibNodeId = getSiteContainerNodeId(tSiteId, "documentLibrary");
setRequestContext(null); setRequestContext(null);
} }
@@ -161,10 +177,10 @@ public abstract class AbstractBaseApiTest extends EnterpriseTestApi
@After @After
public void tearDown() throws Exception public void tearDown() throws Exception
{ {
if ((networkOne != null) && (userOneN1 != null) && (userOneN1SiteId != null)) if ((networkOne != null) && (user1 != null) && (tSiteId != null))
{ {
setRequestContext(networkOne.getId(), userOneN1.getId(), null); setRequestContext(networkOne.getId(), user1, null);
deleteSite(userOneN1SiteId, 204); deleteSite(tSiteId, true, 204);
} }
AuthenticationUtil.setAdminUserAsFullyAuthenticatedUser(); AuthenticationUtil.setAdminUserAsFullyAuthenticatedUser();
@@ -440,21 +456,54 @@ public abstract class AbstractBaseApiTest extends EnterpriseTestApi
/** /**
* TODO implement as remote api call * TODO implement as remote api call
*/ */
protected String createUser(String username, String password, TestNetwork network) protected String createUser(final String usernameIn, final String password, final TestNetwork network)
{ {
PersonInfo personInfo = new PersonInfo(username, username, username, password, null, null, null, null, null, null, null); final String tenantDomain = (network != null ? network.getId() : TenantService.DEFAULT_DOMAIN);
RepoService.TestPerson person = repoService.createUser(personInfo, username, network);
return person.getId(); return AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork<String>()
{
@Override
public String doWork() throws Exception
{
return TenantUtil.runAsTenant(new TenantUtil.TenantRunAsWork<String>()
{
public String doWork() throws Exception
{
String username = repoService.getPublicApiContext().createUserName(usernameIn, tenantDomain);
PersonInfo personInfo = new PersonInfo(username, username, username, password, null, null, null, null, null, null, null);
RepoService.TestPerson person = repoService.createUser(personInfo, username, network);
return person.getId();
}
}, tenantDomain);
}
}, networkAdmin);
} }
/** /**
* TODO implement as remote api call * TODO implement as remote api call
*/ */
protected String getOrCreateUser(String username, String password) protected String getOrCreateUser(String usernameIn, String password, TestNetwork network)
{ {
PersonInfo personInfo = new PersonInfo(username, username, username, password, null, null, null, null, null, null, null); final String tenantDomain = (network != null ? network.getId() : TenantService.DEFAULT_DOMAIN);
RepoService.TestPerson person = repoService.getOrCreateUser(personInfo, username, null);
return person.getId(); return AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork<String>()
{
@Override
public String doWork() throws Exception
{
return TenantUtil.runAsTenant(new TenantUtil.TenantRunAsWork<String>()
{
public String doWork() throws Exception
{
String username = repoService.getPublicApiContext().createUserName(usernameIn, tenantDomain);
PersonInfo personInfo = new PersonInfo(username, username, username, password, null, null, null, null, null, null, null);
RepoService.TestPerson person = repoService.getOrCreateUser(personInfo, username, network);
return person.getId();
}
}, tenantDomain);
}
}, networkAdmin);
} }
protected SiteMember addSiteMember(String siteId, String userId, final SiteRole siteRole) throws Exception protected SiteMember addSiteMember(String siteId, String userId, final SiteRole siteRole) throws Exception
@@ -481,9 +530,15 @@ public abstract class AbstractBaseApiTest extends EnterpriseTestApi
return RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Site.class); return RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Site.class);
} }
protected HttpResponse deleteSite(String siteId, int expectedStatus) throws Exception protected HttpResponse deleteSite(String siteId, boolean permanent, int expectedStatus) throws Exception
{ {
HttpResponse response = publicApiClient.delete(getScope(), "sites", siteId, null, null); Map params = null;
if (permanent == true)
{
params = Collections.singletonMap("permanent", "true");
}
HttpResponse response = publicApiClient.delete(getScope(), 1, "sites", siteId, null, null, params);
checkStatus(expectedStatus, response.getStatusCode()); checkStatus(expectedStatus, response.getStatusCode());
return response; return response;
} }
@@ -525,7 +580,10 @@ public abstract class AbstractBaseApiTest extends EnterpriseTestApi
password = DEFAULT_ADMIN_PWD; password = DEFAULT_ADMIN_PWD;
} }
setRequestContext(null, runAsUser, password); // Assume "networkOne" if set !
String runAsNetwork = (networkOne != null ? networkOne.getId() : null);
setRequestContext(runAsNetwork, runAsUser, password);
} }
protected void setRequestContext(String runAsNetwork, String runAsUser, String password) protected void setRequestContext(String runAsNetwork, String runAsUser, String password)
@@ -534,7 +592,7 @@ public abstract class AbstractBaseApiTest extends EnterpriseTestApi
{ {
runAsNetwork = "-default-"; runAsNetwork = "-default-";
} }
else if (runAsUser.equals(DEFAULT_ADMIN)) else if ((runAsUser != null) && runAsUser.equals(DEFAULT_ADMIN))
{ {
runAsUser = runAsUser+"@"+runAsNetwork; runAsUser = runAsUser+"@"+runAsNetwork;
} }

View File

@@ -62,6 +62,9 @@ public class ActivitiesPostingTest extends AbstractSingleNetworkSiteTest
public void testCreateUpdate() throws Exception public void testCreateUpdate() throws Exception
{ {
setRequestContext(user1); setRequestContext(user1);
List<Activity> activities = getMyActivities();
int beforeCount = activities.size();
String folder1 = "folder" + System.currentTimeMillis() + "_1"; String folder1 = "folder" + System.currentTimeMillis() + "_1";
Folder createdFolder = createFolder(tDocLibNodeId, folder1, null); Folder createdFolder = createFolder(tDocLibNodeId, folder1, null);
@@ -83,8 +86,9 @@ public class ActivitiesPostingTest extends AbstractSingleNetworkSiteTest
deleteNode(documentResp.getId()); deleteNode(documentResp.getId());
deleteNode(createdFolder.getId()); deleteNode(createdFolder.getId());
List<Activity> activities = getMyActivities(); activities = getMyActivities();
assertEquals(activities.size(),6); assertEquals(beforeCount+6, activities.size());
Activity act = matchActivity(activities, ActivityType.FOLDER_ADDED, user1, tSiteId, tDocLibNodeId, folder1); Activity act = matchActivity(activities, ActivityType.FOLDER_ADDED, user1, tSiteId, tDocLibNodeId, folder1);
assertNotNull(act); assertNotNull(act);

View File

@@ -27,6 +27,8 @@ package org.alfresco.rest.api.tests;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import org.alfresco.rest.AbstractSingleNetworkSiteTest;
import org.alfresco.rest.api.Nodes; import org.alfresco.rest.api.Nodes;
import org.alfresco.rest.api.People; import org.alfresco.rest.api.People;
import org.alfresco.rest.api.model.LoginTicket; import org.alfresco.rest.api.model.LoginTicket;
@@ -49,7 +51,7 @@ import java.util.Map;
* *
* @author Jamal Kaabi-Mofrad * @author Jamal Kaabi-Mofrad
*/ */
public class AuthenticationsTest extends AbstractBaseApiTest public class AuthenticationsTest extends AbstractSingleNetworkSiteTest
{ {
private static final String TICKETS_URL = "tickets"; private static final String TICKETS_URL = "tickets";
private static final String TICKETS_API_NAME = "authentication"; private static final String TICKETS_API_NAME = "authentication";

File diff suppressed because it is too large Load Diff

View File

@@ -562,7 +562,7 @@ public class NodeAssociationsApiTest extends AbstractSingleNetworkSiteTest
AuthenticationUtil.setFullyAuthenticatedUser(user1); AuthenticationUtil.setFullyAuthenticatedUser(user1);
permissionService.setPermission(new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, sf1Id), user2, PermissionService.EDITOR, true); permissionService.setPermission(new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, sf1Id), user2, PermissionService.EDITOR, true);
setRequestContext(DEFAULT_ADMIN); setRequestContext(networkAdmin);
response = publicApiClient.get(getScope(), "nodes/"+sf1Id+"/targets", null, null, null, createParams(paging, null)); response = publicApiClient.get(getScope(), "nodes/"+sf1Id+"/targets", null, null, null, createParams(paging, null));
checkStatus(200, response.getStatusCode()); checkStatus(200, response.getStatusCode());
@@ -579,7 +579,7 @@ public class NodeAssociationsApiTest extends AbstractSingleNetworkSiteTest
tgt = new AssocTarget(u2o1Id, ASSOC_TYPE_CM_REFERENCES); tgt = new AssocTarget(u2o1Id, ASSOC_TYPE_CM_REFERENCES);
post(getNodeTargetsUrl(sf1Id), toJsonAsStringNonNull(tgt), 201); post(getNodeTargetsUrl(sf1Id), toJsonAsStringNonNull(tgt), 201);
setRequestContext(DEFAULT_ADMIN); setRequestContext(networkAdmin);
response = publicApiClient.get(getScope(), "nodes/"+sf1Id+"/targets", null, null, null, createParams(paging, null)); response = publicApiClient.get(getScope(), "nodes/"+sf1Id+"/targets", null, null, null, createParams(paging, null));
checkStatus(200, response.getStatusCode()); checkStatus(200, response.getStatusCode());
@@ -606,7 +606,7 @@ public class NodeAssociationsApiTest extends AbstractSingleNetworkSiteTest
AuthenticationUtil.setFullyAuthenticatedUser(user1); AuthenticationUtil.setFullyAuthenticatedUser(user1);
permissionService.setPermission(new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, sf1Id), user2, PermissionService.EDITOR, true); permissionService.setPermission(new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, sf1Id), user2, PermissionService.EDITOR, true);
setRequestContext(DEFAULT_ADMIN); setRequestContext(networkAdmin);
response = publicApiClient.get(getScope(), "nodes/"+so1Id+"/sources", null, null, null, createParams(paging, null)); response = publicApiClient.get(getScope(), "nodes/"+so1Id+"/sources", null, null, null, createParams(paging, null));
checkStatus(200, response.getStatusCode()); checkStatus(200, response.getStatusCode());
@@ -623,7 +623,7 @@ public class NodeAssociationsApiTest extends AbstractSingleNetworkSiteTest
tgt = new AssocTarget(so1Id, ASSOC_TYPE_CM_REFERENCES); tgt = new AssocTarget(so1Id, ASSOC_TYPE_CM_REFERENCES);
post(getNodeTargetsUrl(u2f1Id), toJsonAsStringNonNull(tgt), 201); post(getNodeTargetsUrl(u2f1Id), toJsonAsStringNonNull(tgt), 201);
setRequestContext(DEFAULT_ADMIN); setRequestContext(networkAdmin);
response = publicApiClient.get(getScope(), "nodes/"+so1Id+"/sources", null, null, null, createParams(paging, null)); response = publicApiClient.get(getScope(), "nodes/"+so1Id+"/sources", null, null, null, createParams(paging, null));
checkStatus(200, response.getStatusCode()); checkStatus(200, response.getStatusCode());

View File

@@ -1,28 +1,28 @@
/* /*
* #%L * #%L
* Alfresco Remote API * Alfresco Remote API
* %% * %%
* Copyright (C) 2005 - 2016 Alfresco Software Limited * Copyright (C) 2005 - 2016 Alfresco Software Limited
* %% * %%
* This file is part of the Alfresco software. * This file is part of the Alfresco software.
* If the software was purchased under a paid Alfresco license, the terms of * If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is * the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms: * provided under the following open source license terms:
* *
* Alfresco is free software: you can redistribute it and/or modify * Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by * it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* Alfresco is distributed in the hope that it will be useful, * Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details. * GNU Lesser General Public License for more details.
* *
* You should have received a copy of the GNU Lesser General Public License * You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>. * along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L% * #L%
*/ */
package org.alfresco.rest.api.tests; package org.alfresco.rest.api.tests;
import java.util.ArrayList; import java.util.ArrayList;
@@ -90,9 +90,9 @@ public class PublicApiTestContext
{ {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append(alias); sb.append(alias);
if(tenant != null && !tenant.equals(TenantService.DEFAULT_DOMAIN)) if ((tenant != null) && (! tenant.equals(TenantService.DEFAULT_DOMAIN)) && (! alias.contains(TenantService.SEPARATOR)))
{ {
sb.append("@"); sb.append(TenantService.SEPARATOR);
sb.append(tenant); sb.append(tenant);
} }
return sb.toString(); return sb.toString();

View File

@@ -107,7 +107,7 @@ public class RenditionsTest extends AbstractBaseApiTest
public void tearDown() throws Exception public void tearDown() throws Exception
{ {
setRequestContext(networkOne.getId(), userOneN1.getId(), null); setRequestContext(networkOne.getId(), userOneN1.getId(), null);
deleteSite(userOneN1Site.getId(), 204); deleteSite(userOneN1Site.getId(), true, 204);
} }
/** /**

View File

@@ -407,8 +407,24 @@ public class RepoService
{ {
return getOrCreateUser(personInfo, username, network, false); return getOrCreateUser(personInfo, username, network, false);
} }
public final static String DEFAULT_ADMIN = "admin";
public final static String DEFAULT_ADMIN_PWD = "admin";
// TODO improve admin-related API tests (including ST vs MT)
private boolean isDefaultAdmin(String username, TestNetwork network)
{
if ((network == null) || (TenantService.DEFAULT_DOMAIN.equals(network.getId())))
{
return (DEFAULT_ADMIN.equalsIgnoreCase(username));
}
else
{
return ((DEFAULT_ADMIN+"@"+network.getId()).equalsIgnoreCase(username));
}
}
// TODO review delete person // TODO review delete person
public TestPerson getOrCreateUser(final PersonInfo personInfo, final String username, final TestNetwork network, final boolean deletePerson) public TestPerson getOrCreateUser(final PersonInfo personInfo, final String username, final TestNetwork network, final boolean deletePerson)
{ {
return AuthenticationUtil.runAsSystem(new RunAsWork<TestPerson>() return AuthenticationUtil.runAsSystem(new RunAsWork<TestPerson>()
@@ -423,8 +439,8 @@ public class RepoService
final Map<QName, Serializable> props = testPerson.getProperties(); final Map<QName, Serializable> props = testPerson.getProperties();
// short-circuit for default "admin" // short-circuit for default/tenant "admin"
if (! username.equalsIgnoreCase("admin")) if (! isDefaultAdmin(username, network))
{ {
NodeRef personNodeRef = personService.getPersonOrNull(username); NodeRef personNodeRef = personService.getPersonOrNull(username);
@@ -1331,7 +1347,7 @@ public class RepoService
{ {
if(!getId().equals(TenantService.DEFAULT_DOMAIN) && !tenantAdminService.existsTenant(getId())) if(!getId().equals(TenantService.DEFAULT_DOMAIN) && !tenantAdminService.existsTenant(getId()))
{ {
tenantAdminService.createTenant(getId(), "admin".toCharArray()); tenantAdminService.createTenant(getId(), DEFAULT_ADMIN_PWD.toCharArray());
numNetworks++; numNetworks++;
log("Created network " + getId()); log("Created network " + getId());
} }

View File

@@ -667,13 +667,14 @@ public class SharedLinkApiTest extends AbstractBaseApiTest
* {@literal <host>:<port>/alfresco/api/<networkId>/public/alfresco/versions/1/shared-links/<sharedId>/renditions/<renditionId>/content} * {@literal <host>:<port>/alfresco/api/<networkId>/public/alfresco/versions/1/shared-links/<sharedId>/renditions/<renditionId>/content}
* *
*/ */
// TODO now covered by testSharedLinkCreateGetDelete ? (since base class now uses tenant context by default)
@Test @Test
public void testSharedLinkCreateGetDelete_MultiTenant() throws Exception public void testSharedLinkCreateGetDelete_MultiTenant() throws Exception
{ {
// As userOneN1 // As user1
setRequestContext(networkOne.getId(), userOneN1.getId(), null); setRequestContext(user1);
String docLibNodeId = getSiteContainerNodeId(userOneN1SiteId, "documentLibrary"); String docLibNodeId = getSiteContainerNodeId(tSiteId, "documentLibrary");
String folderName = "folder" + System.currentTimeMillis() + "_1"; String folderName = "folder" + System.currentTimeMillis() + "_1";
String folderId = createFolder(docLibNodeId, folderName, null).getId(); String folderId = createFolder(docLibNodeId, folderName, null).getId();
@@ -705,7 +706,7 @@ public class SharedLinkApiTest extends AbstractBaseApiTest
assertEquals(d1Id, resp.getNodeId()); assertEquals(d1Id, resp.getNodeId());
assertEquals(fileName1, resp.getName()); assertEquals(fileName1, resp.getName());
assertEquals(file1_MimeType, resp.getContent().getMimeType()); assertEquals(file1_MimeType, resp.getContent().getMimeType());
assertEquals(userOneN1.getId(), resp.getSharedByUser().getId()); assertEquals(user1, resp.getSharedByUser().getId());
// allowable operations not included - no params // allowable operations not included - no params
response = getSingle(QuickShareLinkEntityResource.class, shared1Id, null, 200); response = getSingle(QuickShareLinkEntityResource.class, shared1Id, null, 200);
@@ -764,7 +765,7 @@ public class SharedLinkApiTest extends AbstractBaseApiTest
assertEquals(0, renditions.size()); assertEquals(0, renditions.size());
// create rendition of pdf doc - note: for some reason create rendition of txt doc fail on build m/c (TBC) ? // create rendition of pdf doc - note: for some reason create rendition of txt doc fail on build m/c (TBC) ?
setRequestContext(userOneN1.getId()); setRequestContext(user1);
Rendition rendition = createAndGetRendition(d1Id, "doclib"); Rendition rendition = createAndGetRendition(d1Id, "doclib");
assertNotNull(rendition); assertNotNull(rendition);
@@ -807,7 +808,7 @@ public class SharedLinkApiTest extends AbstractBaseApiTest
getSingle(URL_SHARED_LINKS, shared1Id + "/renditions/doclib/content", null, headers, 304); getSingle(URL_SHARED_LINKS, shared1Id + "/renditions/doclib/content", null, headers, 304);
// -ve test - userTwoN1 cannot delete shared link // -ve test - userTwoN1 cannot delete shared link
setRequestContext(userTwoN1.getId()); setRequestContext(user2);
deleteSharedLink(shared1Id, 403); deleteSharedLink(shared1Id, 403);
// -ve test - unauthenticated // -ve test - unauthenticated
@@ -815,7 +816,7 @@ public class SharedLinkApiTest extends AbstractBaseApiTest
deleteSharedLink(shared1Id, 401); deleteSharedLink(shared1Id, 401);
// delete shared link // delete shared link
setRequestContext(userOneN1.getId()); setRequestContext(user1);
deleteSharedLink(shared1Id); deleteSharedLink(shared1Id);
} }