Merged BRANCHES/DEV/V4.1-BUG-FIX to HEAD:

44188: Slight enhancement to TemporarySites JUnit Rule. Always creates doclib container for test sites if needed.



git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@44189 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Neil McErlean
2012-11-30 11:44:46 +00:00
parent 157cae8f45
commit 00b1e56708
2 changed files with 31 additions and 19 deletions

View File

@@ -161,7 +161,18 @@ public class TemporarySites extends AbstractPersonRule
{
final SiteService siteService = appContextRule.getApplicationContext().getBean("siteService", SiteService.class);
return siteService.createSite(sitePreset, siteShortName, siteTitle, siteDescription, visibility, siteType);
SiteInfo newSite = siteService.createSite(sitePreset, siteShortName, siteTitle, siteDescription, visibility, siteType);
// ensure that the Document Library folder is pre-created so that test code can start creating content straight away.
// At the time of writing HEAD does not create this folder automatically, but Thor does.
// So to be safe, I'll pre-check if the node is there.
NodeRef docLibFolder = siteService.getContainer(siteShortName, SiteService.DOCUMENT_LIBRARY);
if (docLibFolder == null)
{
docLibFolder = siteService.createContainer(siteShortName, SiteService.DOCUMENT_LIBRARY, ContentModel.TYPE_FOLDER, null);
}
return newSite;
}
});
@@ -194,22 +205,6 @@ public class TemporarySites extends AbstractPersonRule
AuthenticationUtil.pushAuthentication();
AuthenticationUtil.setFullyAuthenticatedUser(siteCreator);
// ensure that the Document Library folder is pre-created so that test code can start creating content straight away.
// At the time of writing HEAD does not create this folder automatically, but Thor does.
// So to be safe, I'll pre-check if the node is there.
NodeRef doclibFolder = transactionHelper.doInTransaction(new RetryingTransactionCallback<NodeRef>()
{
@Override public NodeRef execute() throws Throwable
{
NodeRef result = siteService.getContainer(siteShortName, SiteService.DOCUMENT_LIBRARY);
if (result == null)
{
result = siteService.createContainer(siteShortName, SiteService.DOCUMENT_LIBRARY, ContentModel.TYPE_FOLDER, null);
}
return result;
}
});
// Create users for this test site that cover the various roles.
List<String> userNames = transactionHelper.doInTransaction(new RetryingTransactionCallback<List<String>>()
{
@@ -234,6 +229,14 @@ public class TemporarySites extends AbstractPersonRule
}
});
NodeRef doclibFolder = transactionHelper.doInTransaction(new RetryingTransactionCallback<NodeRef>()
{
public NodeRef execute() throws Throwable
{
return siteService.getContainer(siteShortName, SiteService.DOCUMENT_LIBRARY);
}
});
AuthenticationUtil.popAuthentication();

View File

@@ -63,10 +63,14 @@ public class TemporarySitesTest
.around(STATIC_TEST_SITES);
// A rule to manage test sites use in each test method
@Rule public TemporarySites testSites = new TemporarySites(APP_CONTEXT_INIT);
public TemporarySites testSites = new TemporarySites(APP_CONTEXT_INIT);
// A rule to allow individual test methods all to be run as "admin".
@Rule public RunAsFullyAuthenticatedRule runAsRule = new RunAsFullyAuthenticatedRule(AuthenticationUtil.getAdminUserName());
public RunAsFullyAuthenticatedRule runAsRule = new RunAsFullyAuthenticatedRule(AuthenticationUtil.getAdminUserName());
// A non-static rule chain to ensure execution order is correct.
@Rule public RuleChain nonStaticRules = RuleChain.outerRule(runAsRule)
.around(testSites);
// Various services
private static NamespaceService NAMESPACE_SERVICE;
@@ -114,6 +118,11 @@ public class TemporarySitesTest
assertEquals("site visibility was wrong", SiteVisibility.PUBLIC, recoveredSite1.getVisibility());
for (String siteShortName : new String[] { testSite1.getShortName(), testSite2.getShortName() })
{
assertNotNull("site had no doclib container node", SITE_SERVICE.getContainer(siteShortName, SiteService.DOCUMENT_LIBRARY));
}
return null;
}
});