mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
Merge changes from feature/RM-6873_RemoveActiveContentFromHold
This commit is contained in:
@@ -28,16 +28,18 @@ package org.alfresco.module.org_alfresco_module_rm.test.integration.hold;
|
|||||||
|
|
||||||
import static org.alfresco.repo.security.authentication.AuthenticationUtil.getAdminUserName;
|
import static org.alfresco.repo.security.authentication.AuthenticationUtil.getAdminUserName;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase;
|
import org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase;
|
||||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||||
import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
|
import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
|
||||||
import org.alfresco.repo.security.permissions.AccessDeniedException;
|
import org.alfresco.repo.security.permissions.AccessDeniedException;
|
||||||
import org.alfresco.repo.site.SiteModel;
|
|
||||||
import org.alfresco.service.cmr.repository.NodeRef;
|
import org.alfresco.service.cmr.repository.NodeRef;
|
||||||
import org.springframework.extensions.webscripts.GUID;
|
import org.springframework.extensions.webscripts.GUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove Active Content To Hold Integration Tests
|
* Remove active content from hold integration tests
|
||||||
*
|
*
|
||||||
* @author Ross Gale
|
* @author Ross Gale
|
||||||
* @since 3.2
|
* @since 3.2
|
||||||
@@ -114,8 +116,10 @@ public class RemoveActiveContentFromHoldTest extends BaseRMTestCase
|
|||||||
{
|
{
|
||||||
hold = holdService.createHold(filePlan, GUID.generate(), GUID.generate(), GUID.generate());
|
hold = holdService.createHold(filePlan, GUID.generate(), GUID.generate(), GUID.generate());
|
||||||
hold2 = holdService.createHold(filePlan, GUID.generate(), GUID.generate(), GUID.generate());
|
hold2 = holdService.createHold(filePlan, GUID.generate(), GUID.generate(), GUID.generate());
|
||||||
holdService.addToHold(hold, dmDocument);
|
final List<NodeRef> holds = new ArrayList<>(2);
|
||||||
holdService.addToHold(hold2, dmDocument);
|
holds.add(hold);
|
||||||
|
holds.add(hold2);
|
||||||
|
holdService.addToHolds(holds, dmDocument);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void when()
|
public void when()
|
||||||
@@ -134,7 +138,7 @@ public class RemoveActiveContentFromHoldTest extends BaseRMTestCase
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Given a piece of active content on hold
|
* Given a piece of active content on hold
|
||||||
* When I try to remove the active content to the hold without permission
|
* When I try to remove the active content from the hold without permission
|
||||||
* Then an access denied exception is thrown
|
* Then an access denied exception is thrown
|
||||||
*/
|
*/
|
||||||
public void testRemoveDocumentFromHoldFailsWithoutFilingPermission()
|
public void testRemoveDocumentFromHoldFailsWithoutFilingPermission()
|
||||||
@@ -162,7 +166,7 @@ public class RemoveActiveContentFromHoldTest extends BaseRMTestCase
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Given a piece of active content on hold
|
* Given a piece of active content on hold
|
||||||
* When I try to remove the active content to the hold without the remove hold capability
|
* When I try to remove the active content from the hold without the remove hold capability
|
||||||
* Then an access denied exception is thrown
|
* Then an access denied exception is thrown
|
||||||
*/
|
*/
|
||||||
public void testRemoveDocumentFromHoldFailsWithoutRemoveHoldPermission()
|
public void testRemoveDocumentFromHoldFailsWithoutRemoveHoldPermission()
|
||||||
@@ -173,10 +177,8 @@ public class RemoveActiveContentFromHoldTest extends BaseRMTestCase
|
|||||||
|
|
||||||
public void given()
|
public void given()
|
||||||
{
|
{
|
||||||
//add powerUserPerson as manager in collaboration site to have write permissions on dmDocument
|
|
||||||
AuthenticationUtil.runAs(
|
AuthenticationUtil.runAs(
|
||||||
(RunAsWork<Void>) () -> {
|
(RunAsWork<Void>) () -> {
|
||||||
siteService.setMembership(collabSiteId, powerUserName, SiteModel.SITE_MANAGER);
|
|
||||||
hold = holdService.createHold(filePlan, GUID.generate(), GUID.generate(), GUID.generate());
|
hold = holdService.createHold(filePlan, GUID.generate(), GUID.generate(), GUID.generate());
|
||||||
holdService.addToHold(hold, dmDocument);
|
holdService.addToHold(hold, dmDocument);
|
||||||
return null;
|
return null;
|
||||||
|
@@ -43,7 +43,6 @@ import org.alfresco.model.ContentModel;
|
|||||||
import org.alfresco.module.org_alfresco_module_rm.freeze.FreezeService;
|
import org.alfresco.module.org_alfresco_module_rm.freeze.FreezeService;
|
||||||
import org.alfresco.module.org_alfresco_module_rm.util.NodeTypeUtility;
|
import org.alfresco.module.org_alfresco_module_rm.util.NodeTypeUtility;
|
||||||
import org.alfresco.module.org_alfresco_module_rm.util.TransactionalResourceHelper;
|
import org.alfresco.module.org_alfresco_module_rm.util.TransactionalResourceHelper;
|
||||||
import org.alfresco.repo.security.permissions.AccessDeniedException;
|
|
||||||
import org.alfresco.rest.framework.core.exceptions.PermissionDeniedException;
|
import org.alfresco.rest.framework.core.exceptions.PermissionDeniedException;
|
||||||
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||||
import org.alfresco.service.cmr.repository.NodeRef;
|
import org.alfresco.service.cmr.repository.NodeRef;
|
||||||
@@ -90,9 +89,6 @@ public class FrozenAspectUnitTest
|
|||||||
@Mock
|
@Mock
|
||||||
private ChildAssociationRef mockOldRef;
|
private ChildAssociationRef mockOldRef;
|
||||||
|
|
||||||
@Mock
|
|
||||||
private ChildAssociationRef mockNewRef;
|
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private Set mockSet;
|
private Set mockSet;
|
||||||
|
|
||||||
@@ -116,11 +112,11 @@ public class FrozenAspectUnitTest
|
|||||||
when(mockNodeService.hasAspect(folder, ASPECT_HELD_CHILDREN)).thenReturn(true);
|
when(mockNodeService.hasAspect(folder, ASPECT_HELD_CHILDREN)).thenReturn(true);
|
||||||
when(mockNodeService.getProperty(folder, PROP_HELD_CHILDREN_COUNT)).thenReturn(1);
|
when(mockNodeService.getProperty(folder, PROP_HELD_CHILDREN_COUNT)).thenReturn(1);
|
||||||
when(mockApplicationContext.getBean("dbNodeService")).thenReturn(mockNodeService);
|
when(mockApplicationContext.getBean("dbNodeService")).thenReturn(mockNodeService);
|
||||||
when(mockNodeService.exists(content)).thenReturn(true);
|
|
||||||
when(mockFreezeService.isFrozen(content)).thenReturn(false);
|
when(mockFreezeService.isFrozen(content)).thenReturn(false);
|
||||||
children.add(mockChildRef);
|
children.add(mockChildRef);
|
||||||
when(mockNodeService.getChildAssocs(content)).thenReturn(children);
|
when(mockNodeService.getChildAssocs(content)).thenReturn(children);
|
||||||
when(mockChildRef.isPrimary()).thenReturn(true);
|
when(mockChildRef.isPrimary()).thenReturn(true);
|
||||||
|
when(mockNodeService.hasAspect(record, ASPECT_RECORD)).thenReturn(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -129,7 +125,6 @@ public class FrozenAspectUnitTest
|
|||||||
@Test
|
@Test
|
||||||
public void testRemoveAspectForRecords()
|
public void testRemoveAspectForRecords()
|
||||||
{
|
{
|
||||||
when(mockNodeService.hasAspect(record, ASPECT_RECORD)).thenReturn(true);
|
|
||||||
when(mockNodeService.getPrimaryParent(record)).thenReturn(mockChildAssociationRef);
|
when(mockNodeService.getPrimaryParent(record)).thenReturn(mockChildAssociationRef);
|
||||||
when(mockChildAssociationRef.getParentRef()).thenReturn(folder);
|
when(mockChildAssociationRef.getParentRef()).thenReturn(folder);
|
||||||
frozenAspect.onRemoveAspect(record, null);
|
frozenAspect.onRemoveAspect(record, null);
|
||||||
@@ -152,14 +147,14 @@ public class FrozenAspectUnitTest
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test that the remove code is only ran for records or active content
|
* Test that the remove code is only run for records or active content
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testRemoveAspectForContentDoesntUpdateForOtherTypes()
|
public void testRemoveAspectForContentDoesntUpdateForOtherTypes()
|
||||||
{
|
{
|
||||||
when(mockNodeService.hasAspect(content, ASPECT_RECORD)).thenReturn(false);
|
when(mockNodeService.hasAspect(content, ASPECT_RECORD)).thenReturn(false);
|
||||||
when(mockNodeService.getType(content)).thenReturn(ContentModel.TYPE_FOLDER);
|
when(mockNodeService.getType(content)).thenReturn(ContentModel.TYPE_FOLDER);
|
||||||
when(mockedNodeTypeUtility.instanceOf(ContentModel.TYPE_FOLDER, ContentModel.TYPE_CONTENT)).thenReturn(false);
|
when(mockedNodeTypeUtility.instanceOf(mockNodeService.getType(content), ContentModel.TYPE_CONTENT)).thenReturn(false);
|
||||||
frozenAspect.onRemoveAspect(content, null);
|
frozenAspect.onRemoveAspect(content, null);
|
||||||
verify(mockNodeService, times(0)).setProperty(folder, PROP_HELD_CHILDREN_COUNT, 0);
|
verify(mockNodeService, times(0)).setProperty(folder, PROP_HELD_CHILDREN_COUNT, 0);
|
||||||
}
|
}
|
||||||
@@ -202,29 +197,28 @@ public class FrozenAspectUnitTest
|
|||||||
@Test
|
@Test
|
||||||
public void testOnAddAspectForRecord()
|
public void testOnAddAspectForRecord()
|
||||||
{
|
{
|
||||||
when(mockNodeService.getType(record)).thenReturn(ContentModel.TYPE_CONTENT);
|
|
||||||
when(mockNodeService.getPrimaryParent(record)).thenReturn(mockParentRef);
|
when(mockNodeService.getPrimaryParent(record)).thenReturn(mockParentRef);
|
||||||
when(mockParentRef.getParentRef()).thenReturn(parent);
|
when(mockParentRef.getParentRef()).thenReturn(parent);
|
||||||
when(mockNodeService.hasAspect(parent, ASPECT_HELD_CHILDREN)).thenReturn(true);
|
when(mockNodeService.hasAspect(parent, ASPECT_HELD_CHILDREN)).thenReturn(true);
|
||||||
when(mockNodeService.getProperty(parent, PROP_HELD_CHILDREN_COUNT)).thenReturn(0);
|
when(mockNodeService.getProperty(parent, PROP_HELD_CHILDREN_COUNT)).thenReturn(0);
|
||||||
frozenAspect.onAddAspect(record,null);
|
frozenAspect.onAddAspect(record,null);
|
||||||
verify(mockNodeService, times(1)).setProperty(parent, PROP_HELD_CHILDREN_COUNT,1);
|
verify(mockNodeService, times(1)).setProperty(parent, PROP_HELD_CHILDREN_COUNT, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test on add for a content node
|
* Test on add aspect for a content node
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testOnAddAspectForContent()
|
public void testOnAddAspectForContent()
|
||||||
{
|
{
|
||||||
when(mockNodeService.getType(record)).thenReturn(ContentModel.TYPE_CONTENT);
|
when(mockNodeService.getType(content)).thenReturn(ContentModel.TYPE_CONTENT);
|
||||||
when(mockedNodeTypeUtility.instanceOf(mockNodeService.getType(record), ContentModel.TYPE_CONTENT)).thenReturn(true);
|
when(mockedNodeTypeUtility.instanceOf(mockNodeService.getType(content), ContentModel.TYPE_CONTENT)).thenReturn(true);
|
||||||
when(mockNodeService.getPrimaryParent(record)).thenReturn(mockParentRef);
|
when(mockNodeService.getPrimaryParent(content)).thenReturn(mockParentRef);
|
||||||
when(mockParentRef.getParentRef()).thenReturn(parent);
|
when(mockParentRef.getParentRef()).thenReturn(parent);
|
||||||
when(mockNodeService.hasAspect(parent, ASPECT_HELD_CHILDREN)).thenReturn(false);
|
when(mockNodeService.hasAspect(parent, ASPECT_HELD_CHILDREN)).thenReturn(false);
|
||||||
when(mockNodeService.getType(parent)).thenReturn(ContentModel.TYPE_FOLDER);
|
when(mockNodeService.getType(parent)).thenReturn(ContentModel.TYPE_FOLDER);
|
||||||
when(mockedNodeTypeUtility.instanceOf(mockNodeService.getType(parent), ContentModel.TYPE_FOLDER)).thenReturn(true);
|
when(mockedNodeTypeUtility.instanceOf(mockNodeService.getType(parent), ContentModel.TYPE_FOLDER)).thenReturn(true);
|
||||||
frozenAspect.onAddAspect(record, null);
|
frozenAspect.onAddAspect(content, null);
|
||||||
verify(mockNodeService, times(1)).addAspect(any(NodeRef.class), any(QName.class), anyMap());
|
verify(mockNodeService, times(1)).addAspect(any(NodeRef.class), any(QName.class), anyMap());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user