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
|
// TODO improve admin-related tests, including ability to override default admin un/pw
|
||||||
protected static final String DEFAULT_ADMIN = "admin";
|
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
|
// network1 with user1, user2 and a testsite1
|
||||||
protected static TestNetwork networkOne;
|
protected static TestNetwork networkOne;
|
||||||
@@ -141,8 +141,8 @@ public abstract class AbstractBaseApiTest extends EnterpriseTestApi
|
|||||||
networkOne = getTestFixture().getRandomNetwork();
|
networkOne = getTestFixture().getRandomNetwork();
|
||||||
}
|
}
|
||||||
|
|
||||||
//userOneN1 = networkOne.createUser();
|
//userOneN1 = networkN1.createUser();
|
||||||
//userTwoN1 = networkOne.createUser();
|
//userTwoN1 = networkN1.createUser();
|
||||||
|
|
||||||
String tenantDomain = networkOne.getId();
|
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
|
// to enable admin access via test calls - eg. via PublicApiClient -> AbstractTestApi -> findUserByUserName
|
||||||
getOrCreateUser(networkAdmin, "admin", networkOne);
|
getOrCreateUser(networkAdmin, "admin", networkOne);
|
||||||
|
|
||||||
setRequestContext(networkAdmin);
|
setRequestContext(networkOne.getId(), networkAdmin, DEFAULT_ADMIN_PWD);
|
||||||
|
|
||||||
// note: createUser currently relies on repoService
|
// note: createUser currently relies on repoService
|
||||||
user1 = createUser("user1-" + RUNID, "user1Password", networkOne);
|
user1 = createUser("user1-" + RUNID, "user1Password", networkOne);
|
||||||
@@ -171,7 +171,7 @@ public abstract class AbstractBaseApiTest extends EnterpriseTestApi
|
|||||||
tSiteId = createSite("TestSite A - " + RUNID, SiteVisibility.PRIVATE).getId();
|
tSiteId = createSite("TestSite A - " + RUNID, SiteVisibility.PRIVATE).getId();
|
||||||
tDocLibNodeId = getSiteContainerNodeId(tSiteId, "documentLibrary");
|
tDocLibNodeId = getSiteContainerNodeId(tSiteId, "documentLibrary");
|
||||||
|
|
||||||
setRequestContext(null);
|
setRequestContext(null, null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
@@ -183,25 +183,24 @@ public abstract class AbstractBaseApiTest extends EnterpriseTestApi
|
|||||||
deleteSite(tSiteId, true, 204);
|
deleteSite(tSiteId, true, 204);
|
||||||
}
|
}
|
||||||
|
|
||||||
AuthenticationUtil.setAdminUserAsFullyAuthenticatedUser();
|
setRequestContext(networkAdmin);
|
||||||
for (final String user : users)
|
|
||||||
|
for (final String username : users)
|
||||||
{
|
{
|
||||||
transactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Void>()
|
transactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Void>()
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public Void execute() throws Throwable
|
public Void execute() throws Throwable
|
||||||
{
|
{
|
||||||
if (personService.personExists(user))
|
deleteUser(username, networkOne);
|
||||||
{
|
|
||||||
authenticationService.deleteAuthentication(user);
|
|
||||||
personService.deletePerson(user);
|
|
||||||
}
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
users.clear();
|
users.clear();
|
||||||
AuthenticationUtil.clearCurrentSecurityContext();
|
|
||||||
|
setRequestContext(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -505,6 +504,30 @@ public abstract class AbstractBaseApiTest extends EnterpriseTestApi
|
|||||||
}
|
}
|
||||||
}, networkAdmin);
|
}, 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
|
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)
|
protected void setRequestContext(String runAsUser)
|
||||||
{
|
{
|
||||||
String password = null;
|
String password = null;
|
||||||
@@ -579,13 +607,16 @@ public abstract class AbstractBaseApiTest extends EnterpriseTestApi
|
|||||||
// TODO improve "admin" related tests
|
// TODO improve "admin" related tests
|
||||||
password = DEFAULT_ADMIN_PWD;
|
password = DEFAULT_ADMIN_PWD;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Assume "networkOne" if set !
|
// Assume "networkN1" if set !
|
||||||
String runAsNetwork = (networkOne != null ? networkOne.getId() : null);
|
String runAsNetwork = (networkOne != null ? networkOne.getId() : null);
|
||||||
|
|
||||||
setRequestContext(runAsNetwork, runAsUser, password);
|
setRequestContext(runAsNetwork, runAsUser, password);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TODO implement as remote (login) api call
|
||||||
|
*/
|
||||||
protected void setRequestContext(String runAsNetwork, String runAsUser, String password)
|
protected void setRequestContext(String runAsNetwork, String runAsUser, String password)
|
||||||
{
|
{
|
||||||
if ((runAsNetwork == null) || TenantService.DEFAULT_DOMAIN.equals(runAsNetwork))
|
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);
|
final AuthorityService authorityService = applicationContext.getBean("authorityService", AuthorityService.class);
|
||||||
|
|
||||||
this.nonAdminUserName = createUser("nonAdminUser" + System.currentTimeMillis());
|
this.nonAdminUserName = createUser("nonAdminUser" + System.currentTimeMillis(), "password", null);
|
||||||
this.customModelAdmin = createUser("customModelAdmin" + System.currentTimeMillis());
|
this.customModelAdmin = createUser("customModelAdmin" + System.currentTimeMillis(), "password", null);
|
||||||
users.add(nonAdminUserName);
|
users.add(nonAdminUserName);
|
||||||
users.add(customModelAdmin);
|
users.add(customModelAdmin);
|
||||||
|
|
||||||
// Add 'customModelAdmin' user into 'ALFRESCO_MODEL_ADMINISTRATORS' group
|
// Add 'customModelAdmin' user into 'ALFRESCO_MODEL_ADMINISTRATORS' group
|
||||||
transactionHelper.doInTransaction(new RetryingTransactionCallback<Void>()
|
transactionHelper.doInTransaction(new RetryingTransactionCallback<Void>()
|
||||||
{
|
{
|
||||||
@@ -117,8 +118,7 @@ public class BaseCustomModelApiTest extends AbstractBaseApiTest
|
|||||||
@Override
|
@Override
|
||||||
public Void execute() throws Throwable
|
public Void execute() throws Throwable
|
||||||
{
|
{
|
||||||
authenticationService.deleteAuthentication(user);
|
deleteUser(user, null);
|
||||||
personService.deletePerson(user);
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@@ -60,19 +60,18 @@ public class ModulePackagesApiTest extends AbstractBaseApiTest
|
|||||||
@Before
|
@Before
|
||||||
public void setup() throws Exception
|
public void setup() throws Exception
|
||||||
{
|
{
|
||||||
nonAdminUserName = createUser("nonAdminUser" + System.currentTimeMillis());
|
networkOne = null; // used by setRequestContext
|
||||||
|
|
||||||
// used-by teardown to cleanup
|
nonAdminUserName = createUser("nonAdminUser" + System.currentTimeMillis(), "password", null);
|
||||||
authenticationService = applicationContext.getBean("authenticationService", MutableAuthenticationService.class);
|
|
||||||
personService = applicationContext.getBean("personService", PersonService.class);
|
// used-by teardown (deleteUser) to cleanup
|
||||||
users.add(nonAdminUserName);
|
//users.add(nonAdminUserName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
public void tearDown() throws Exception
|
public void tearDown() throws Exception
|
||||||
{
|
{
|
||||||
// TODO rationalise createUser & deleteUser
|
deleteUser(nonAdminUserName, networkOne);
|
||||||
super.tearDown();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@@ -78,7 +78,7 @@ public class RenditionsTest extends AbstractBaseApiTest
|
|||||||
/**
|
/**
|
||||||
* Test network one
|
* Test network one
|
||||||
*/
|
*/
|
||||||
TestNetwork networkOne;
|
TestNetwork networkN1;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User one from network one
|
* User one from network one
|
||||||
@@ -93,11 +93,11 @@ public class RenditionsTest extends AbstractBaseApiTest
|
|||||||
@Before
|
@Before
|
||||||
public void setup() throws Exception
|
public void setup() throws Exception
|
||||||
{
|
{
|
||||||
networkOne = repoService.createNetworkWithAlias("ping", true);
|
networkN1 = repoService.createNetworkWithAlias("ping", true);
|
||||||
networkOne.create();
|
networkN1.create();
|
||||||
userOneN1 = networkOne.createUser();
|
userOneN1 = networkN1.createUser();
|
||||||
|
|
||||||
setRequestContext(networkOne.getId(), userOneN1.getId(), null);
|
setRequestContext(networkN1.getId(), userOneN1.getId(), null);
|
||||||
|
|
||||||
String siteTitle = "RandomSite" + System.currentTimeMillis();
|
String siteTitle = "RandomSite" + System.currentTimeMillis();
|
||||||
userOneN1Site = createSite(siteTitle, SiteVisibility.PRIVATE);
|
userOneN1Site = createSite(siteTitle, SiteVisibility.PRIVATE);
|
||||||
@@ -106,7 +106,7 @@ public class RenditionsTest extends AbstractBaseApiTest
|
|||||||
@After
|
@After
|
||||||
public void tearDown() throws Exception
|
public void tearDown() throws Exception
|
||||||
{
|
{
|
||||||
setRequestContext(networkOne.getId(), userOneN1.getId(), null);
|
setRequestContext(networkN1.getId(), userOneN1.getId(), null);
|
||||||
deleteSite(userOneN1Site.getId(), true, 204);
|
deleteSite(userOneN1Site.getId(), true, 204);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -118,7 +118,7 @@ public class RenditionsTest extends AbstractBaseApiTest
|
|||||||
@Test
|
@Test
|
||||||
public void testListNodeRenditions() throws Exception
|
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
|
// Create a folder within the site document's library
|
||||||
String folderName = "folder" + System.currentTimeMillis();
|
String folderName = "folder" + System.currentTimeMillis();
|
||||||
@@ -258,7 +258,7 @@ public class RenditionsTest extends AbstractBaseApiTest
|
|||||||
@Test
|
@Test
|
||||||
public void testGetNodeRendition() throws Exception
|
public void testGetNodeRendition() throws Exception
|
||||||
{
|
{
|
||||||
setRequestContext(userOneN1.getId());
|
setRequestContext(networkN1.getId(), userOneN1.getId(), null);
|
||||||
|
|
||||||
// Create a folder within the site document's library
|
// Create a folder within the site document's library
|
||||||
String folderName = "folder" + System.currentTimeMillis();
|
String folderName = "folder" + System.currentTimeMillis();
|
||||||
@@ -342,7 +342,7 @@ public class RenditionsTest extends AbstractBaseApiTest
|
|||||||
@Test
|
@Test
|
||||||
public void testCreateRendition() throws Exception
|
public void testCreateRendition() throws Exception
|
||||||
{
|
{
|
||||||
setRequestContext(userOneN1.getId());
|
setRequestContext(networkN1.getId(), userOneN1.getId(), null);
|
||||||
|
|
||||||
// Create a folder within the site document's library
|
// Create a folder within the site document's library
|
||||||
String folderName = "folder" + System.currentTimeMillis();
|
String folderName = "folder" + System.currentTimeMillis();
|
||||||
@@ -476,7 +476,7 @@ public class RenditionsTest extends AbstractBaseApiTest
|
|||||||
public void testCreateRenditionOnUpload() throws Exception
|
public void testCreateRenditionOnUpload() throws Exception
|
||||||
{
|
{
|
||||||
String userId = userOneN1.getId();
|
String userId = userOneN1.getId();
|
||||||
setRequestContext(userId);
|
setRequestContext(networkN1.getId(), userOneN1.getId(), null);
|
||||||
|
|
||||||
// Create a folder within the site document's library
|
// Create a folder within the site document's library
|
||||||
String folderName = "folder" + System.currentTimeMillis();
|
String folderName = "folder" + System.currentTimeMillis();
|
||||||
@@ -597,7 +597,7 @@ public class RenditionsTest extends AbstractBaseApiTest
|
|||||||
@Test
|
@Test
|
||||||
public void testDownloadRendition() throws Exception
|
public void testDownloadRendition() throws Exception
|
||||||
{
|
{
|
||||||
setRequestContext(userOneN1.getId());
|
setRequestContext(networkN1.getId(), userOneN1.getId(), null);
|
||||||
|
|
||||||
// Create a folder within the site document's library
|
// Create a folder within the site document's library
|
||||||
String folderName = "folder" + System.currentTimeMillis();
|
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)
|
public TestSite createSite(TestNetwork network, final SiteInformation site)
|
||||||
{
|
{
|
||||||
SiteInfo siteInfo = null;
|
SiteInfo siteInfo = null;
|
||||||
|
Reference in New Issue
Block a user