mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Merged BRANCHES/V4.2 to HEAD:
55206: Branch created for 4.2.x releases. 55209: Merged HEAD to BRANCHES/V4.2: 55208: Added Sharepoint config to unit test classpath to fix VtiRequestDispatcherTest. 55222: Merged HEAD-BUG-FIX to V4.2 55220: Merged V4.1-BUG-FIX (4.1.7) to HEAD-BUG-FIX (4.2) 55218: Fix for ALF-19894 Site is not displayed after restoring from Trashcan This bug was reported on 4.2, but the bug is also present on 4.1. I have added a testcase to reproduce the bug along with a fix. The problem was in SiteServiceImpl.delete where the code was writing an empty property value into the {}memberships property and therefore there was no record of which users had been members of the deleted site. 55245: Fixed javadoc while checking that ALF-19055 was fixed. ActivityService no longer uses 'format 55246: CLOUD-2050 -Content changes are not synced from Cloud to On-Premise (errors in the logs) 55249: Hazelcast: Added ability to create cache with 'read-backup-data' via property *.readBackupData 55250: Hazelcast cache builder now accepts 'async-backup-count' value and any error in setting a value logs the full exception 55251: Asynchronous cache: Better logging of in- and after-transaction processes 55252: Asynchronous cache: Better logging of in- and after-transaction processes 55266: Workflow REST API fix for variable retrieval 55276: Merged HEAD to BRANCHES/V4.2: 55274: Disabling Sharepoint unit tests until we can make them run properly in the build. 55278: ALF-19889 - String for Brazilian Portuguese 55279: Merged DEV to 4.2 ALF-17464 : Replication jobs aren't displayed until sorting by some characteristic - Changing not exact equals (!==) to not euqals (!=) 55280: Fix for ALF-19865 - Forgot password link redirects to Login page. Also cleaned up the mess that is the 'Sign in to Alfresco in the cloud' dialog. 55281: Probable fix for ALF-19225 Intermittent test failures in SubscriptionServiceActivitiesTest 55282: ALF-19865 - Cloud Sync profile area now looks like the rest of profile area. 55285: Merged BRANCHES/DEV/BELARUS/HEAD-2013_08_27 to BRANCHES/V4.2: 55068: ALF-19915 : MT and WebDAV: Content is lost when uploading non-empty document 55286: Merged BRANCHES/DEV/BELARUS/HEAD-2013_08_29 to BRANCHES/V4.2: 55207: ALF-19915 : MT and WebDAV: Content is lost when uploading non-empty document 55210: ALF-19915 : MT and WebDAV: Content is lost when uploading non-empty document 55297: As part of prep work for fixing ALF-20023 Recent Sites and Favorite Sites in copy/move pickers empty, 55299: ALF-19556: IE10 specific fix for file upload browse (impressive how IE finds more and more innovative ways to spoil things for itself) 55300: Fixed date issue when creating a new process instance 55308: Resync to HEAD@55302 git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@55309 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2012 Alfresco Software Limited.
|
||||
* Copyright (C) 2005-2013 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
@@ -19,17 +19,26 @@
|
||||
|
||||
package org.alfresco.repo.site;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.query.PagingRequest;
|
||||
import org.alfresco.query.PagingResults;
|
||||
import org.alfresco.repo.node.archive.NodeArchiveService;
|
||||
import org.alfresco.repo.node.archive.RestoreNodeReport;
|
||||
import org.alfresco.repo.node.archive.RestoreNodeReport.RestoreStatus;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
|
||||
import org.alfresco.repo.transaction.RetryingTransactionHelper;
|
||||
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.cmr.security.AuthorityService;
|
||||
import org.alfresco.service.cmr.security.AuthorityType;
|
||||
import org.alfresco.service.cmr.site.SiteInfo;
|
||||
import org.alfresco.service.cmr.site.SiteService;
|
||||
import org.alfresco.service.cmr.site.SiteVisibility;
|
||||
@@ -41,11 +50,14 @@ import org.alfresco.util.test.junitrules.RunAsFullyAuthenticatedRule;
|
||||
import org.alfresco.util.test.junitrules.TemporarySites;
|
||||
import org.alfresco.util.test.junitrules.TemporarySites.TestSiteAndMemberInfo;
|
||||
import org.alfresco.util.test.junitrules.TemporarySitesTest;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.RuleChain;
|
||||
import org.junit.rules.TestName;
|
||||
import org.springframework.extensions.webscripts.GUID;
|
||||
|
||||
/**
|
||||
@@ -59,6 +71,8 @@ import org.springframework.extensions.webscripts.GUID;
|
||||
*/
|
||||
public class SiteServiceImplMoreTest
|
||||
{
|
||||
protected static Log log = LogFactory.getLog(SiteServiceImplMoreTest.class);
|
||||
|
||||
// Rule to initialise the default Alfresco spring configuration
|
||||
public static ApplicationContextInit APP_CONTEXT_INIT = ApplicationContextInit.createStandardContextWithOverrides("classpath:sites/test-"
|
||||
+ TemporarySitesTest.class.getSimpleName() + "-context.xml");
|
||||
@@ -71,15 +85,21 @@ public class SiteServiceImplMoreTest
|
||||
.around(STATIC_TEST_SITES);
|
||||
|
||||
public RunAsFullyAuthenticatedRule runAllTestsAsAdmin = new RunAsFullyAuthenticatedRule(AuthenticationUtil.getAdminUserName());
|
||||
public TemporarySites perMethodTestSites = new TemporarySites(APP_CONTEXT_INIT);
|
||||
public AlfrescoPerson testUser = new AlfrescoPerson(APP_CONTEXT_INIT);
|
||||
|
||||
// Need to ensure the rules are in the correct order so that we're authenticated as admin before trying to create the person.
|
||||
@Rule public RuleChain ruleChain = RuleChain.outerRule(runAllTestsAsAdmin)
|
||||
.around(perMethodTestSites)
|
||||
.around(testUser);
|
||||
|
||||
@Rule public TestName testName = new TestName();
|
||||
|
||||
// Various services
|
||||
private static AuthorityService AUTHORITY_SERVICE;
|
||||
private static NamespaceService NAMESPACE_SERVICE;
|
||||
private static NodeService NODE_SERVICE;
|
||||
private static NodeArchiveService NODE_ARCHIVE_SERVICE;
|
||||
private static SiteService SITE_SERVICE;
|
||||
private static RetryingTransactionHelper TRANSACTION_HELPER;
|
||||
|
||||
@@ -88,7 +108,10 @@ public class SiteServiceImplMoreTest
|
||||
|
||||
@BeforeClass public static void initStaticData() throws Exception
|
||||
{
|
||||
AUTHORITY_SERVICE = APP_CONTEXT_INIT.getApplicationContext().getBean("AuthorityService", AuthorityService.class);
|
||||
NAMESPACE_SERVICE = APP_CONTEXT_INIT.getApplicationContext().getBean("namespaceService", NamespaceService.class);
|
||||
NODE_SERVICE = APP_CONTEXT_INIT.getApplicationContext().getBean("NodeService", NodeService.class);
|
||||
NODE_ARCHIVE_SERVICE = APP_CONTEXT_INIT.getApplicationContext().getBean("nodeArchiveService", NodeArchiveService.class);
|
||||
SITE_SERVICE = APP_CONTEXT_INIT.getApplicationContext().getBean("siteService", SiteService.class);
|
||||
TRANSACTION_HELPER = APP_CONTEXT_INIT.getApplicationContext().getBean("retryingTransactionHelper", RetryingTransactionHelper.class);
|
||||
|
||||
@@ -158,4 +181,113 @@ public class SiteServiceImplMoreTest
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* This test ensures that when sites are deleted (moved to the trashcan) and then restored, that the 4 role-based groups are
|
||||
* restored correctly and that any users who were members of those groups are made members once more.
|
||||
*
|
||||
* @see SiteServiceImpl#deleteSite(String)
|
||||
* @see SiteServiceImpl#onRestoreNode(org.alfresco.service.cmr.repository.ChildAssociationRef)
|
||||
*/
|
||||
@Test public void deleteSiteAndRestoreEnsuringSiteGroupsAreRecovered() throws Exception
|
||||
{
|
||||
// Implementation note: as of Alfresco 4.2, authorities cannot be archived and are always hard-deleted.
|
||||
// Therefore, on site restore, the SiteService *recreates* the deleted groups associated with the restored site.
|
||||
// Having recreated them, it then needs to add any old members (users, TODO what about groups?) into those newly created site groups.
|
||||
// It does this by writing the site members and their roles onto a property on the st:site node in the archive & reading them on restore.
|
||||
|
||||
// Choose a site name that will link back to this test case...
|
||||
final String siteShortName = testName.getMethodName();
|
||||
log.debug("Creating test site called: " + siteShortName);
|
||||
|
||||
// ...and create the site
|
||||
final TestSiteAndMemberInfo testSiteAndMemberInfo = perMethodTestSites.createTestSiteWithUserPerRole(siteShortName, "sitePreset", SiteVisibility.PUBLIC, AuthenticationUtil.getAdminUserName());
|
||||
|
||||
// Now get the various site-related data that we want to examine after deletion & restoration
|
||||
final Map<String, String> userNameToRoleMap =
|
||||
TRANSACTION_HELPER.doInTransaction(new RetryingTransactionCallback<Map<String, String>>()
|
||||
{
|
||||
public Map<String, String> execute() throws Throwable
|
||||
{
|
||||
final Map<String, String> userNameToRoleMap = new HashMap<String, String>();
|
||||
|
||||
// Which users are members of which groups?
|
||||
for (String role : SITE_SERVICE.getSiteRoles())
|
||||
{
|
||||
// putAll here shouldn't overwrite any keys in the above map as each authority should only have one role in a site.
|
||||
userNameToRoleMap.putAll(SITE_SERVICE.listMembers(siteShortName, null, role, 0, true));
|
||||
}
|
||||
|
||||
// Some sanity checking before we delete the site
|
||||
final String siteContributorGroup = SITE_SERVICE.getSiteRoleGroup(siteShortName, "SiteContributor");
|
||||
assertTrue("Site contributor user was not in site contributors group", AUTHORITY_SERVICE.getContainedAuthorities(AuthorityType.USER, siteContributorGroup, true).contains(testSiteAndMemberInfo.siteContributor));
|
||||
assertEquals("Site contributor user did not have expected Contributor role",
|
||||
SiteModel.SITE_CONTRIBUTOR,
|
||||
userNameToRoleMap.get(testSiteAndMemberInfo.siteContributor));
|
||||
|
||||
log.debug("About to delete site.");
|
||||
SITE_SERVICE.deleteSite(siteShortName);
|
||||
log.debug("Site deleted.");
|
||||
|
||||
return userNameToRoleMap;
|
||||
}
|
||||
});
|
||||
|
||||
TRANSACTION_HELPER.doInTransaction(new RetryingTransactionCallback<Void>()
|
||||
{
|
||||
public Void execute() throws Throwable
|
||||
{
|
||||
assertThatArchivedNodeExists(testSiteAndMemberInfo.siteInfo.getNodeRef(), "Site node not found in archive.");
|
||||
|
||||
// At this point we might assert that the groups associated with the site were gone, but that's an implementation detail really.
|
||||
|
||||
log.debug("About to restore site node from archive");
|
||||
|
||||
final NodeRef archivedSiteNode = NODE_ARCHIVE_SERVICE.getArchivedNode(testSiteAndMemberInfo.siteInfo.getNodeRef());
|
||||
RestoreNodeReport report = NODE_ARCHIVE_SERVICE.restoreArchivedNode(archivedSiteNode);
|
||||
// ...which should work
|
||||
assertEquals("Failed to restore site from archive", RestoreStatus.SUCCESS, report.getStatus());
|
||||
|
||||
log.debug("Successfully restored site from arhive.");
|
||||
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
TRANSACTION_HELPER.doInTransaction(new RetryingTransactionCallback<Void>()
|
||||
{
|
||||
public Void execute() throws Throwable
|
||||
{
|
||||
// The site itself should have been restored, of course...
|
||||
assertTrue("The site noderef was not restored as expected", NODE_SERVICE.exists(testSiteAndMemberInfo.siteInfo.getNodeRef()));
|
||||
|
||||
// But the group authority nodes should be restored (recreated) as well.
|
||||
for (String role : SITE_SERVICE.getSiteRoles())
|
||||
{
|
||||
final String siteGroup = SITE_SERVICE.getSiteRoleGroup(siteShortName, role);
|
||||
assertTrue("Site group for role " + role + " did not exist after site restoration",
|
||||
AUTHORITY_SERVICE.authorityExists(siteGroup));
|
||||
}
|
||||
|
||||
log.debug(SITE_SERVICE.listMembers(siteShortName, null, null, 0, true).size() + " members...");
|
||||
for (Map.Entry<String, String> entry : SITE_SERVICE.listMembers(siteShortName, null, null, 0, true).entrySet()) { log.debug(entry); }
|
||||
|
||||
// And finally, the original members of the site should have been given the same membership that they had before.
|
||||
for (Map.Entry<String, String> entry : userNameToRoleMap.entrySet())
|
||||
{
|
||||
assertEquals("Unexpected role for site user: " + entry.getKey(),
|
||||
entry.getValue(),
|
||||
SITE_SERVICE.getMembersRole(siteShortName, entry.getKey()));
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void assertThatArchivedNodeExists(NodeRef originalNodeRef, String failureMsg)
|
||||
{
|
||||
final NodeRef archivedNodeRef = NODE_ARCHIVE_SERVICE.getArchivedNode(originalNodeRef);
|
||||
assertTrue(failureMsg, NODE_SERVICE.exists(archivedNodeRef));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user