mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
Merged RETURN-OF-THE-API (5.2.0) to 5.2.N (5.2.1)
128642 jvonka: V1 REST API: cleanup and rationalise new api tests (re: remotable helpers & runAs user / admin) - round 5b - fix test fallout REPO-113 git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@129180 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -106,7 +106,7 @@ public abstract class AbstractBaseApiTest extends EnterpriseTestApi
|
||||
|
||||
// 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 static final String DEFAULT_ADMIN_PWD = "admin";
|
||||
|
||||
// network1 with user1, user2 and a testsite1
|
||||
protected static TestNetwork networkOne;
|
||||
@@ -141,8 +141,8 @@ public abstract class AbstractBaseApiTest extends EnterpriseTestApi
|
||||
networkOne = getTestFixture().getRandomNetwork();
|
||||
}
|
||||
|
||||
//userOneN1 = networkOne.createUser();
|
||||
//userTwoN1 = networkOne.createUser();
|
||||
//userOneN1 = networkN1.createUser();
|
||||
//userTwoN1 = networkN1.createUser();
|
||||
|
||||
String tenantDomain = networkOne.getId();
|
||||
|
||||
@@ -154,7 +154,7 @@ public abstract class AbstractBaseApiTest extends EnterpriseTestApi
|
||||
// to enable admin access via test calls - eg. via PublicApiClient -> AbstractTestApi -> findUserByUserName
|
||||
getOrCreateUser(networkAdmin, "admin", networkOne);
|
||||
|
||||
setRequestContext(networkAdmin);
|
||||
setRequestContext(networkOne.getId(), networkAdmin, DEFAULT_ADMIN_PWD);
|
||||
|
||||
// note: createUser currently relies on repoService
|
||||
user1 = createUser("user1-" + RUNID, "user1Password", networkOne);
|
||||
@@ -171,7 +171,7 @@ public abstract class AbstractBaseApiTest extends EnterpriseTestApi
|
||||
tSiteId = createSite("TestSite A - " + RUNID, SiteVisibility.PRIVATE).getId();
|
||||
tDocLibNodeId = getSiteContainerNodeId(tSiteId, "documentLibrary");
|
||||
|
||||
setRequestContext(null);
|
||||
setRequestContext(null, null, null);
|
||||
}
|
||||
|
||||
@After
|
||||
@@ -183,25 +183,24 @@ public abstract class AbstractBaseApiTest extends EnterpriseTestApi
|
||||
deleteSite(tSiteId, true, 204);
|
||||
}
|
||||
|
||||
AuthenticationUtil.setAdminUserAsFullyAuthenticatedUser();
|
||||
for (final String user : users)
|
||||
setRequestContext(networkAdmin);
|
||||
|
||||
for (final String username : users)
|
||||
{
|
||||
transactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Void>()
|
||||
{
|
||||
@Override
|
||||
public Void execute() throws Throwable
|
||||
{
|
||||
if (personService.personExists(user))
|
||||
{
|
||||
authenticationService.deleteAuthentication(user);
|
||||
personService.deletePerson(user);
|
||||
}
|
||||
deleteUser(username, networkOne);
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
users.clear();
|
||||
AuthenticationUtil.clearCurrentSecurityContext();
|
||||
|
||||
setRequestContext(null);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -505,6 +504,30 @@ public abstract class AbstractBaseApiTest extends EnterpriseTestApi
|
||||
}
|
||||
}, networkAdmin);
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO implement as remote api call
|
||||
*/
|
||||
protected String deleteUser(final String username, final TestNetwork network)
|
||||
{
|
||||
final String tenantDomain = (network != null ? network.getId() : TenantService.DEFAULT_DOMAIN);
|
||||
|
||||
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
|
||||
{
|
||||
repoService.deleteUser(username, network);
|
||||
return null;
|
||||
}
|
||||
}, tenantDomain);
|
||||
}
|
||||
}, networkAdmin);
|
||||
}
|
||||
|
||||
protected SiteMember addSiteMember(String siteId, String userId, final SiteRole siteRole) throws Exception
|
||||
{
|
||||
@@ -571,6 +594,11 @@ public abstract class AbstractBaseApiTest extends EnterpriseTestApi
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*
|
||||
* @param runAsUser
|
||||
*/
|
||||
protected void setRequestContext(String runAsUser)
|
||||
{
|
||||
String password = null;
|
||||
@@ -579,13 +607,16 @@ public abstract class AbstractBaseApiTest extends EnterpriseTestApi
|
||||
// TODO improve "admin" related tests
|
||||
password = DEFAULT_ADMIN_PWD;
|
||||
}
|
||||
|
||||
// Assume "networkOne" if set !
|
||||
|
||||
// Assume "networkN1" if set !
|
||||
String runAsNetwork = (networkOne != null ? networkOne.getId() : null);
|
||||
|
||||
|
||||
setRequestContext(runAsNetwork, runAsUser, password);
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO implement as remote (login) api call
|
||||
*/
|
||||
protected void setRequestContext(String runAsNetwork, String runAsUser, String password)
|
||||
{
|
||||
if ((runAsNetwork == null) || TenantService.DEFAULT_DOMAIN.equals(runAsNetwork))
|
||||
|
@@ -90,10 +90,11 @@ public class BaseCustomModelApiTest extends AbstractBaseApiTest
|
||||
|
||||
final AuthorityService authorityService = applicationContext.getBean("authorityService", AuthorityService.class);
|
||||
|
||||
this.nonAdminUserName = createUser("nonAdminUser" + System.currentTimeMillis());
|
||||
this.customModelAdmin = createUser("customModelAdmin" + System.currentTimeMillis());
|
||||
this.nonAdminUserName = createUser("nonAdminUser" + System.currentTimeMillis(), "password", null);
|
||||
this.customModelAdmin = createUser("customModelAdmin" + System.currentTimeMillis(), "password", null);
|
||||
users.add(nonAdminUserName);
|
||||
users.add(customModelAdmin);
|
||||
|
||||
// Add 'customModelAdmin' user into 'ALFRESCO_MODEL_ADMINISTRATORS' group
|
||||
transactionHelper.doInTransaction(new RetryingTransactionCallback<Void>()
|
||||
{
|
||||
@@ -117,8 +118,7 @@ public class BaseCustomModelApiTest extends AbstractBaseApiTest
|
||||
@Override
|
||||
public Void execute() throws Throwable
|
||||
{
|
||||
authenticationService.deleteAuthentication(user);
|
||||
personService.deletePerson(user);
|
||||
deleteUser(user, null);
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
@@ -60,19 +60,18 @@ public class ModulePackagesApiTest extends AbstractBaseApiTest
|
||||
@Before
|
||||
public void setup() throws Exception
|
||||
{
|
||||
nonAdminUserName = createUser("nonAdminUser" + System.currentTimeMillis());
|
||||
networkOne = null; // used by setRequestContext
|
||||
|
||||
// used-by teardown to cleanup
|
||||
authenticationService = applicationContext.getBean("authenticationService", MutableAuthenticationService.class);
|
||||
personService = applicationContext.getBean("personService", PersonService.class);
|
||||
users.add(nonAdminUserName);
|
||||
nonAdminUserName = createUser("nonAdminUser" + System.currentTimeMillis(), "password", null);
|
||||
|
||||
// used-by teardown (deleteUser) to cleanup
|
||||
//users.add(nonAdminUserName);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception
|
||||
{
|
||||
// TODO rationalise createUser & deleteUser
|
||||
super.tearDown();
|
||||
deleteUser(nonAdminUserName, networkOne);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@@ -78,7 +78,7 @@ public class RenditionsTest extends AbstractBaseApiTest
|
||||
/**
|
||||
* Test network one
|
||||
*/
|
||||
TestNetwork networkOne;
|
||||
TestNetwork networkN1;
|
||||
|
||||
/**
|
||||
* User one from network one
|
||||
@@ -93,11 +93,11 @@ public class RenditionsTest extends AbstractBaseApiTest
|
||||
@Before
|
||||
public void setup() throws Exception
|
||||
{
|
||||
networkOne = repoService.createNetworkWithAlias("ping", true);
|
||||
networkOne.create();
|
||||
userOneN1 = networkOne.createUser();
|
||||
networkN1 = repoService.createNetworkWithAlias("ping", true);
|
||||
networkN1.create();
|
||||
userOneN1 = networkN1.createUser();
|
||||
|
||||
setRequestContext(networkOne.getId(), userOneN1.getId(), null);
|
||||
setRequestContext(networkN1.getId(), userOneN1.getId(), null);
|
||||
|
||||
String siteTitle = "RandomSite" + System.currentTimeMillis();
|
||||
userOneN1Site = createSite(siteTitle, SiteVisibility.PRIVATE);
|
||||
@@ -106,7 +106,7 @@ public class RenditionsTest extends AbstractBaseApiTest
|
||||
@After
|
||||
public void tearDown() throws Exception
|
||||
{
|
||||
setRequestContext(networkOne.getId(), userOneN1.getId(), null);
|
||||
setRequestContext(networkN1.getId(), userOneN1.getId(), null);
|
||||
deleteSite(userOneN1Site.getId(), true, 204);
|
||||
}
|
||||
|
||||
@@ -118,7 +118,7 @@ public class RenditionsTest extends AbstractBaseApiTest
|
||||
@Test
|
||||
public void testListNodeRenditions() throws Exception
|
||||
{
|
||||
setRequestContext(networkOne.getId(), userOneN1.getId(), null);
|
||||
setRequestContext(networkN1.getId(), userOneN1.getId(), null);
|
||||
|
||||
// Create a folder within the site document's library
|
||||
String folderName = "folder" + System.currentTimeMillis();
|
||||
@@ -258,7 +258,7 @@ public class RenditionsTest extends AbstractBaseApiTest
|
||||
@Test
|
||||
public void testGetNodeRendition() throws Exception
|
||||
{
|
||||
setRequestContext(userOneN1.getId());
|
||||
setRequestContext(networkN1.getId(), userOneN1.getId(), null);
|
||||
|
||||
// Create a folder within the site document's library
|
||||
String folderName = "folder" + System.currentTimeMillis();
|
||||
@@ -342,7 +342,7 @@ public class RenditionsTest extends AbstractBaseApiTest
|
||||
@Test
|
||||
public void testCreateRendition() throws Exception
|
||||
{
|
||||
setRequestContext(userOneN1.getId());
|
||||
setRequestContext(networkN1.getId(), userOneN1.getId(), null);
|
||||
|
||||
// Create a folder within the site document's library
|
||||
String folderName = "folder" + System.currentTimeMillis();
|
||||
@@ -476,7 +476,7 @@ public class RenditionsTest extends AbstractBaseApiTest
|
||||
public void testCreateRenditionOnUpload() throws Exception
|
||||
{
|
||||
String userId = userOneN1.getId();
|
||||
setRequestContext(userId);
|
||||
setRequestContext(networkN1.getId(), userOneN1.getId(), null);
|
||||
|
||||
// Create a folder within the site document's library
|
||||
String folderName = "folder" + System.currentTimeMillis();
|
||||
@@ -597,7 +597,7 @@ public class RenditionsTest extends AbstractBaseApiTest
|
||||
@Test
|
||||
public void testDownloadRendition() throws Exception
|
||||
{
|
||||
setRequestContext(userOneN1.getId());
|
||||
setRequestContext(networkN1.getId(), userOneN1.getId(), null);
|
||||
|
||||
// Create a folder within the site document's library
|
||||
String folderName = "folder" + System.currentTimeMillis();
|
||||
|
@@ -481,6 +481,23 @@ public class RepoService
|
||||
});
|
||||
}
|
||||
|
||||
protected void deleteUser(final String username, final TestNetwork network)
|
||||
{
|
||||
AuthenticationUtil.runAsSystem(new RunAsWork<TestPerson>()
|
||||
{
|
||||
@Override
|
||||
public TestPerson doWork() throws Exception
|
||||
{
|
||||
if (personService.personExists(username))
|
||||
{
|
||||
authenticationService.deleteAuthentication(username);
|
||||
personService.deletePerson(username);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public TestSite createSite(TestNetwork network, final SiteInformation site)
|
||||
{
|
||||
SiteInfo siteInfo = null;
|
||||
|
Reference in New Issue
Block a user