mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-10-08 14:51:49 +00:00
RM-1424 (Holds the user has read-only permission for are displayed in Add to Hold dialog)
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/HEAD@72241 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -18,10 +18,12 @@
|
||||
*/
|
||||
package org.alfresco.module.org_alfresco_module_rm.test.service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.module.org_alfresco_module_rm.capability.RMPermissionModel;
|
||||
import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel;
|
||||
import org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
|
||||
@@ -33,6 +35,14 @@ import org.alfresco.service.cmr.repository.NodeRef;
|
||||
*/
|
||||
public class HoldServiceImplTest extends BaseRMTestCase
|
||||
{
|
||||
/** Constants for the holds */
|
||||
private static final String HOLD1_NAME = "hold one";
|
||||
private static final String HOLD2_NAME = "hold two";
|
||||
private static final String HOLD1_REASON = "I have my reasons";
|
||||
private static final String HOLD2_REASON = "secrets are everything";
|
||||
private static final String HOLD1_DESC = "but I'll not describe them here!";
|
||||
private static final String HOLD2_DESC = "no then! that's just not on!";
|
||||
|
||||
@Override
|
||||
protected boolean isRecordTest()
|
||||
{
|
||||
@@ -45,6 +55,34 @@ public class HoldServiceImplTest extends BaseRMTestCase
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a hold and checks if the hold is null or not
|
||||
*
|
||||
* @return {@link NodeRef} Node reference of the hold.
|
||||
*/
|
||||
private NodeRef createAndCheckHold()
|
||||
{
|
||||
NodeRef hold = holdService.createHold(filePlan, HOLD1_NAME, HOLD1_REASON, HOLD1_DESC);
|
||||
assertNotNull(hold);
|
||||
return hold;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates two holds and checks them if they are null or not
|
||||
*
|
||||
* @return List of {@link NodeRef}s of the holds.
|
||||
*/
|
||||
private List<NodeRef> createAndCheckHolds()
|
||||
{
|
||||
List<NodeRef> holds = new ArrayList<NodeRef>(2);
|
||||
holds.add(createAndCheckHold());
|
||||
NodeRef hold2 = holdService.createHold(filePlan, HOLD2_NAME, HOLD2_REASON, HOLD2_DESC);
|
||||
assertNotNull(hold2);
|
||||
holds.add(hold2);
|
||||
assertEquals(2, holds.size());
|
||||
return holds;
|
||||
}
|
||||
|
||||
public void testDeleteHoldBehaviourForRecordFolder()
|
||||
{
|
||||
doTestInTransaction(new Test<Void>()
|
||||
@@ -53,8 +91,7 @@ public class HoldServiceImplTest extends BaseRMTestCase
|
||||
public Void run() throws Exception
|
||||
{
|
||||
// create test holds
|
||||
NodeRef hold1 = holdService.createHold(filePlan, "hold one", "I have my reasons", "but I'll not describe them here!");
|
||||
assertNotNull(hold1);
|
||||
NodeRef hold1 = createAndCheckHold();
|
||||
|
||||
// add the record folder to hold1
|
||||
holdService.addToHold(hold1, rmFolder);
|
||||
@@ -94,10 +131,9 @@ public class HoldServiceImplTest extends BaseRMTestCase
|
||||
public Void run() throws Exception
|
||||
{
|
||||
// create test holds
|
||||
NodeRef hold1 = holdService.createHold(filePlan, "hold one", "I have my reasons", "but I'll not describe them here!");
|
||||
assertNotNull(hold1);
|
||||
NodeRef hold2 = holdService.createHold(filePlan, "hold two", "secrets are everything", "no then! that's just not on!");
|
||||
assertNotNull(hold2);
|
||||
List<NodeRef> holds = createAndCheckHolds();
|
||||
NodeRef hold1 = holds.get(0);
|
||||
NodeRef hold2 = holds.get(1);
|
||||
|
||||
// add the record folder to hold1
|
||||
holdService.addToHold(hold1, rmFolder);
|
||||
@@ -150,8 +186,7 @@ public class HoldServiceImplTest extends BaseRMTestCase
|
||||
public void testAddRecordFolderToHoldWithoutFilingPermissionOnRecordFolder()
|
||||
{
|
||||
// Create hold
|
||||
final NodeRef hold = holdService.createHold(filePlan, "hold one", "I have my reasons", "but I'll not describe them here!");
|
||||
assertNotNull(hold);
|
||||
final NodeRef hold = createAndCheckHold();
|
||||
|
||||
doTestInTransaction(new Test<Void>()
|
||||
{
|
||||
@@ -169,7 +204,7 @@ public class HoldServiceImplTest extends BaseRMTestCase
|
||||
|
||||
return null;
|
||||
}
|
||||
}, "admin");
|
||||
});
|
||||
|
||||
doTestInTransaction(new FailureTest(AlfrescoRuntimeException.class)
|
||||
{
|
||||
@@ -184,8 +219,7 @@ public class HoldServiceImplTest extends BaseRMTestCase
|
||||
public void testAddRecordFolderToHoldWithoutFilingPermissionOnHold()
|
||||
{
|
||||
// Create hold
|
||||
final NodeRef hold = holdService.createHold(filePlan, "hold one", "I have my reasons", "but I'll not describe them here!");
|
||||
assertNotNull(hold);
|
||||
final NodeRef hold = createAndCheckHold();
|
||||
|
||||
doTestInTransaction(new Test<Void>()
|
||||
{
|
||||
@@ -203,7 +237,7 @@ public class HoldServiceImplTest extends BaseRMTestCase
|
||||
|
||||
return null;
|
||||
}
|
||||
}, "admin");
|
||||
});
|
||||
|
||||
doTestInTransaction(new FailureTest(AlfrescoRuntimeException.class)
|
||||
{
|
||||
@@ -215,4 +249,115 @@ public class HoldServiceImplTest extends BaseRMTestCase
|
||||
}, userName);
|
||||
}
|
||||
|
||||
public void testGettingHolds()
|
||||
{
|
||||
final List<NodeRef> listWithTwoHolds = new ArrayList<NodeRef>(2);
|
||||
|
||||
doTestInTransaction(new Test<Void>()
|
||||
{
|
||||
@Override
|
||||
public Void run() throws Exception
|
||||
{
|
||||
// No holds
|
||||
List<NodeRef> emptyHoldList = holdService.getHolds(filePlan);
|
||||
assertNotNull(emptyHoldList);
|
||||
assertTrue(emptyHoldList.isEmpty());
|
||||
|
||||
// Create 2 holds
|
||||
createAndCheckHolds();
|
||||
|
||||
// Check the list of holds
|
||||
listWithTwoHolds.addAll(holdService.getHolds(filePlan));
|
||||
assertNotNull(listWithTwoHolds);
|
||||
assertEquals(2, listWithTwoHolds.size());
|
||||
|
||||
// Check the first hold
|
||||
NodeRef hold1 = listWithTwoHolds.get(0);
|
||||
assertEquals(RecordsManagementModel.TYPE_HOLD, nodeService.getType(hold1));
|
||||
assertEquals(HOLD1_NAME, (String) nodeService.getProperty(hold1, PROP_NAME));
|
||||
assertEquals(HOLD1_REASON, (String) nodeService.getProperty(hold1, PROP_HOLD_REASON));
|
||||
assertEquals(HOLD1_DESC, (String) nodeService.getProperty(hold1, PROP_DESCRIPTION));
|
||||
|
||||
// Add the user to the RM Manager role
|
||||
filePlanRoleService.assignRoleToAuthority(filePlan, ROLE_NAME_RECORDS_MANAGER, userName);
|
||||
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
doTestInTransaction(new Test<Void>()
|
||||
{
|
||||
@Override
|
||||
public Void run() throws Exception
|
||||
{
|
||||
// Get the holds the test user without having any permissions on the holds
|
||||
List<NodeRef> holds = holdService.getHolds(filePlan);
|
||||
assertNotNull(holds);
|
||||
assertEquals(0, holds.size());
|
||||
|
||||
return null;
|
||||
}
|
||||
}, userName);
|
||||
|
||||
final NodeRef hold2 = listWithTwoHolds.get(1);
|
||||
doTestInTransaction(new Test<Void>()
|
||||
{
|
||||
@Override
|
||||
public Void run() throws Exception
|
||||
{
|
||||
// Give the user read permissions on the hold
|
||||
permissionService.setPermission(hold2, userName, RMPermissionModel.FILING, true);
|
||||
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
doTestInTransaction(new Test<Void>()
|
||||
{
|
||||
@Override
|
||||
public Void run() throws Exception
|
||||
{
|
||||
List<NodeRef> holds = holdService.getHolds(filePlan);
|
||||
assertNotNull(holds);
|
||||
assertEquals(1, holds.size());
|
||||
assertEquals(RecordsManagementModel.TYPE_HOLD, nodeService.getType(hold2));
|
||||
assertEquals(HOLD2_NAME, (String) nodeService.getProperty(hold2, PROP_NAME));
|
||||
assertEquals(HOLD2_REASON, (String) nodeService.getProperty(hold2, PROP_HOLD_REASON));
|
||||
assertEquals(HOLD2_DESC, (String) nodeService.getProperty(hold2, PROP_DESCRIPTION));
|
||||
|
||||
return null;
|
||||
}
|
||||
}, userName);
|
||||
}
|
||||
|
||||
public void testHeldByNothing()
|
||||
{
|
||||
doTestInTransaction(new Test<Void>()
|
||||
{
|
||||
@Override
|
||||
public Void run() throws Exception
|
||||
{
|
||||
// Create the test holds
|
||||
createAndCheckHolds();
|
||||
|
||||
// Check that the record folder isn't held by anything
|
||||
List<NodeRef> holds = new ArrayList<NodeRef>();
|
||||
holds.addAll(holdService.heldBy(rmFolder, true));
|
||||
assertTrue(holds.isEmpty());
|
||||
holds.clear();
|
||||
holds.addAll(holdService.heldBy(rmFolder, false));
|
||||
assertEquals(2, holds.size());
|
||||
|
||||
// Check that record isn't held by anything (recordOne is a child of the rmFolder)
|
||||
holds.clear();
|
||||
holds.addAll(holdService.heldBy(recordOne, true));
|
||||
assertTrue(holds.isEmpty());
|
||||
holds.clear();
|
||||
holds.addAll(holdService.heldBy(recordOne, false));
|
||||
assertEquals(2, holds.size());
|
||||
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user