diff --git a/source/java/org/alfresco/util/test/junitrules/TemporarySites.java b/source/java/org/alfresco/util/test/junitrules/TemporarySites.java index eb1ce49471..8019a74236 100644 --- a/source/java/org/alfresco/util/test/junitrules/TemporarySites.java +++ b/source/java/org/alfresco/util/test/junitrules/TemporarySites.java @@ -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() - { - @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 userNames = transactionHelper.doInTransaction(new RetryingTransactionCallback>() { @@ -234,6 +229,14 @@ public class TemporarySites extends AbstractPersonRule } }); + NodeRef doclibFolder = transactionHelper.doInTransaction(new RetryingTransactionCallback() + { + public NodeRef execute() throws Throwable + { + return siteService.getContainer(siteShortName, SiteService.DOCUMENT_LIBRARY); + } + }); + AuthenticationUtil.popAuthentication(); diff --git a/source/java/org/alfresco/util/test/junitrules/TemporarySitesTest.java b/source/java/org/alfresco/util/test/junitrules/TemporarySitesTest.java index 00c357b1f5..e4e94fe54d 100644 --- a/source/java/org/alfresco/util/test/junitrules/TemporarySitesTest.java +++ b/source/java/org/alfresco/util/test/junitrules/TemporarySitesTest.java @@ -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; } });